blob: b8755b8f80b161a9af04d5e72d9c1735001111f0 [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 chac89321b2018-04-10 21:37:01 +080037#include <resolv.h>
38
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090039#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
40#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080041#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
42#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
43
Eric Laurentb23d5282013-05-14 15:27:20 -070044#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070045#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090046#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070047
Eric Laurentf9583c32016-03-28 13:50:50 -070048#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070049
50/*
Eric Laurentb23d5282013-05-14 15:27:20 -070051 * This file will have a maximum of 38 bytes:
52 *
53 * 4 bytes: number of audio blocks
54 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
55 * Maximum 10 * 3 bytes: SAD blocks
56 */
57#define MAX_SAD_BLOCKS 10
58#define SAD_BLOCK_SIZE 3
59
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090060#define MAX_CVD_VERSION_STRING_SIZE 100
61
Eric Laurentb23d5282013-05-14 15:27:20 -070062/* EDID format ID for LPCM audio */
63#define EDID_FORMAT_LPCM 1
64
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070065#define MAX_SND_CARD_NAME_LEN 31
66
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080067#define DEFAULT_APP_TYPE_RX_PATH 69936
68#define DEFAULT_APP_TYPE_TX_PATH 69938
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070069#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
vivek mehta1a9b7c02015-06-25 11:49:38 -070070
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090071#define TOSTRING_(x) #x
72#define TOSTRING(x) TOSTRING_(x)
73
Eric Laurentb23d5282013-05-14 15:27:20 -070074struct audio_block_header
75{
76 int reserved;
77 int length;
78};
79
vivek mehta1a9b7c02015-06-25 11:49:38 -070080enum {
81 CAL_MODE_SEND = 0x1,
82 CAL_MODE_PERSIST = 0x2,
83 CAL_MODE_RTAC = 0x4
84};
85
keunhui.park2f7306a2015-07-16 16:48:06 +090086#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
87
88struct operator_info {
89 struct listnode list;
90 char *name;
91 char *mccmnc;
92};
93
94struct operator_specific_device {
95 struct listnode list;
96 char *operator;
97 char *mixer_path;
98 int acdb_id;
99};
100
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800101#define BE_DAI_NAME_MAX_LENGTH 24
102struct be_dai_name_struct {
103 unsigned int be_id;
104 char be_name[BE_DAI_NAME_MAX_LENGTH];
105};
106
keunhui.park2f7306a2015-07-16 16:48:06 +0900107static struct listnode operator_info_list;
108static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
109
jasmine chac89321b2018-04-10 21:37:01 +0800110#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
111
112typedef struct acdb_audio_cal_cfg {
113 uint32_t persist;
114 uint32_t snd_dev_id;
115 audio_devices_t dev_id;
116 int32_t acdb_dev_id;
117 uint32_t app_type;
118 uint32_t topo_id;
119 uint32_t sampling_rate;
120 uint32_t cal_type;
121 uint32_t module_id;
122 uint32_t param_id;
123} acdb_audio_cal_cfg_t;
124
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700125/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800126typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700127
Eric Laurentb23d5282013-05-14 15:27:20 -0700128struct platform_data {
129 struct audio_device *adev;
130 bool fluence_in_spkr_mode;
131 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700132 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700133 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700134 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
135 int fluence_type;
136 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700137 bool speaker_lr_swap;
138
Eric Laurentb23d5282013-05-14 15:27:20 -0700139 void *acdb_handle;
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700140#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700141 acdb_init_v2_cvd_t acdb_init;
142#elif defined (PLATFORM_MSM8084)
143 acdb_init_v2_t acdb_init;
144#else
145 acdb_init_t acdb_init;
146#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700147 acdb_deallocate_t acdb_deallocate;
148 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800149 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
jasmine chac89321b2018-04-10 21:37:01 +0800150 acdb_set_audio_cal_t acdb_set_audio_cal;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700151 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700152 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700153 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700154 acdb_send_custom_top_t acdb_send_custom_top;
155 bool acdb_initialized;
156
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700157 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800158 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700159
David Linee3fe402017-03-13 10:00:42 -0700160 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700161 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900162 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700163 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800164
165 void *hw_info;
jiabin8962a4d2018-03-19 18:21:24 -0700166
167 uint32_t declared_mic_count;
168 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
Eric Laurentb23d5282013-05-14 15:27:20 -0700169};
170
Haynes Mathew George98c95622014-06-20 19:14:25 -0700171static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700172 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
173 DEEP_BUFFER_PCM_DEVICE},
174 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
175 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800176 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700177 MULTIMEDIA2_PCM_DEVICE},
178 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
179 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700180 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
181 MULTIMEDIA2_PCM_DEVICE},
182 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
183 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800184 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
185 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700186
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700187 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
188 AUDIO_RECORD_PCM_DEVICE},
189 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
190 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700191
Eric Laurent0e46adf2016-12-16 12:49:24 -0800192 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
193 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700194 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
195 MULTIMEDIA2_PCM_DEVICE},
196
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700197 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
198 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700199 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
200 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
201 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
202 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800203 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
204 VOICEMMODE1_CALL_PCM_DEVICE},
205 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
206 VOICEMMODE2_CALL_PCM_DEVICE},
207
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700208 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
209 AUDIO_RECORD_PCM_DEVICE},
210 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
211 AUDIO_RECORD_PCM_DEVICE},
212 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
213 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800214 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700215
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700216 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
217 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
218
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700219 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
220 AFE_PROXY_RECORD_PCM_DEVICE},
221 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
222 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800223 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700224
vivek mehtaa68fea62017-06-08 19:04:02 -0700225 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
226 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
227 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
228 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200229
230 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
231 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700232};
233
234/* Array to store sound devices */
235static const char * const device_table[SND_DEVICE_MAX] = {
236 [SND_DEVICE_NONE] = "none",
237 /* Playback sound devices */
238 [SND_DEVICE_OUT_HANDSET] = "handset",
239 [SND_DEVICE_OUT_SPEAKER] = "speaker",
240 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700241 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700242 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500243 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700244 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700245 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500246 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700247 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700248 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500249 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700250 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
251 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500252 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700253 [SND_DEVICE_OUT_HDMI] = "hdmi",
254 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
255 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700256 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800257 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
258 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700259 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
260 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
261 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
262 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800263 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
264 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700265 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700266 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700267 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700268 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700269 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700270 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700271 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700272 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
273 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700274 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800275 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
276 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700277
278 /* Capture sound devices */
279 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700280 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700281 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
282 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
283 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
284 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
285 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
286 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
287 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
288
289 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
290 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
291 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
292 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
293 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
294 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
295 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
296 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
297 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
298
299 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500300 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700301
Eric Laurentb23d5282013-05-14 15:27:20 -0700302 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
303 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700304 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700305 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700306 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700307 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700308
309 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
310 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
311 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
312 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700313 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700314 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700315 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
316 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
317 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800318 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
319 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700320
Eric Laurentb23d5282013-05-14 15:27:20 -0700321 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700322 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700323 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700324 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700325 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
326 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700327 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700328 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
329 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
330 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
331 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700332 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700333
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700334 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700335 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
336 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
337 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
338 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800339
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700340 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700341
Prashant Malanic92c5962015-08-11 15:10:18 -0700342 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
343 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700344 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700345 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
346 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700347 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
348 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700349};
350
351/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700352static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700353 [SND_DEVICE_NONE] = -1,
354 [SND_DEVICE_OUT_HANDSET] = 7,
355 [SND_DEVICE_OUT_SPEAKER] = 15,
356 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700357 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700358 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500359 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700360 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700361 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500362 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700363 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700364 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
365 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500366 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700367 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500368 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700369 [SND_DEVICE_OUT_HDMI] = 18,
370 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
371 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700372 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800373 [SND_DEVICE_OUT_BT_A2DP] = 20,
374 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700375 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700376 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
377 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
378 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800379 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
380 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700381 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700382 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700383 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700384 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700385 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700386 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700387 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700388 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
389 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700390 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700391
392 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700393 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
394 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
395 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
396 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
397 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
398 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
399 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
400 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
401
402 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
403 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
404 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
405 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
406 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
407 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
408 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
409 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
410 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
411
rago90fb9612015-12-02 11:37:53 -0800412 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500413 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700414
Eric Laurentb23d5282013-05-14 15:27:20 -0700415 [SND_DEVICE_IN_HDMI_MIC] = 4,
416 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700417 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700418 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700419 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700420 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700421
422 [SND_DEVICE_IN_VOICE_DMIC] = 41,
423 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
424 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700425 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700426 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800427 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700428 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
429 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
430 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800431 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
432 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700433
rago90fb9612015-12-02 11:37:53 -0800434 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700435 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700436 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700437 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700438 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
439 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800440 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
441
442 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
443 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700444 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
445 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
446 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700447
448 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700449 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700450 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
451 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
452 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
453 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700454 [SND_DEVICE_IN_THREE_MIC] = 46,
455 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700456 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700457 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
458 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700459 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
460 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700461};
462
David Linee3fe402017-03-13 10:00:42 -0700463// Platform specific backend bit width table
464static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
465
Haynes Mathew George98c95622014-06-20 19:14:25 -0700466struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700467 char name[100];
468 unsigned int index;
469};
470
471#define TO_NAME_INDEX(X) #X, X
472
Haynes Mathew George98c95622014-06-20 19:14:25 -0700473/* Used to get index from parsed string */
474static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
475 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700476 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
477 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
478 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700479 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700480 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500481 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700482 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700483 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500484 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700485 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700486 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
487 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700488 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700489 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500490 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700491 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
492 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
493 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
494 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800495 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
496 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700497 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500498 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700499 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
500 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
501 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800502 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
503 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800504 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
505 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700506 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700507 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700508 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700509 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700510 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700511 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700512 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
513 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800514
515 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700516 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700517 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700518 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
519 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
520 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
521 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
522 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
523 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
524 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
525
526 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700527 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700528 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
529 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
530 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
531 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
532 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
533 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
534 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
535
536 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700537 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700538
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700539 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
540 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700541 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700542 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700543 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700544 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700545
546 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
547 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
548 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700549 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700550 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
551 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700552 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
553 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
554 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800555 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
556 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
557
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700558
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700559 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700560 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700561 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700562 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700563 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
564 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700565 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700566 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700567 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
568 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
569 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
570 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700571
rago90fb9612015-12-02 11:37:53 -0800572 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
573 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700574 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
575 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
576 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800577
Prashant Malanic92c5962015-08-11 15:10:18 -0700578 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
579 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700580 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700581 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
582 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700583 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
584 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700585};
586
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700587static char * backend_tag_table[SND_DEVICE_MAX] = {0};
588static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700589
590static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
591 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
592 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800593 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700594 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700595 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
596 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800597 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700598 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
599 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800600 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700601 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700602 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
603 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
604 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
605 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
606 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800607 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
608 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700609 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
610 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
611 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
612 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800613 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
614 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
615 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
616 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
617 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700618 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
619 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200620 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700621 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700622};
623
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800624static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
625 {TO_NAME_INDEX(PCM_PLAYBACK)},
626 {TO_NAME_INDEX(PCM_CAPTURE)},
627 {TO_NAME_INDEX(VOICE_CALL)},
628 {TO_NAME_INDEX(PCM_HFP_CALL)},
629};
630
631struct app_type_entry {
632 int uc_type;
633 int bit_width;
634 int app_type;
635 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700636 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800637 struct listnode node; // membership in app_type_entry_list;
638};
639
640static struct listnode app_type_entry_list;
641
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700642#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
643#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800644#define ULL_PLATFORM_DELAY (3*1000LL)
645#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700646
Eric Laurentb23d5282013-05-14 15:27:20 -0700647static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
648static bool is_tmus = false;
649
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800650static int init_be_dai_name_table(struct audio_device *adev);
651
Eric Laurentb23d5282013-05-14 15:27:20 -0700652static void check_operator()
653{
654 char value[PROPERTY_VALUE_MAX];
655 int mccmnc;
656 property_get("gsm.sim.operator.numeric",value,"0");
657 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700658 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700659 switch(mccmnc) {
660 /* TMUS MCC(310), MNC(490, 260, 026) */
661 case 310490:
662 case 310260:
663 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900664 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
665 case 310800:
666 case 310660:
667 case 310580:
668 case 310310:
669 case 310270:
670 case 310250:
671 case 310240:
672 case 310230:
673 case 310220:
674 case 310210:
675 case 310200:
676 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700677 is_tmus = true;
678 break;
679 }
680}
681
682bool is_operator_tmus()
683{
684 pthread_once(&check_op_once_ctl, check_operator);
685 return is_tmus;
686}
687
keunhui.park2f7306a2015-07-16 16:48:06 +0900688static char *get_current_operator()
689{
690 struct listnode *node;
691 struct operator_info *info_item;
692 char mccmnc[PROPERTY_VALUE_MAX];
693 char *ret = NULL;
694
Tom Cherry7fea2042016-11-10 18:05:59 -0800695 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900696
697 list_for_each(node, &operator_info_list) {
698 info_item = node_to_item(node, struct operator_info, list);
699 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
700 ret = info_item->name;
701 }
702 }
703
704 return ret;
705}
706
707static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
708{
709 struct listnode *node;
710 struct operator_specific_device *ret = NULL;
711 struct operator_specific_device *device_item;
712 char *operator_name;
713
714 operator_name = get_current_operator();
715 if (operator_name == NULL)
716 return ret;
717
718 list_for_each(node, operator_specific_device_table[snd_device]) {
719 device_item = node_to_item(node, struct operator_specific_device, list);
720 if (strcmp(operator_name, device_item->operator) == 0) {
721 ret = device_item;
722 }
723 }
724
725 return ret;
726}
727
728
729static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
730{
731 struct operator_specific_device *device;
732 int ret = acdb_device_table[snd_device];
733
734 device = get_operator_specific_device(snd_device);
735 if (device != NULL)
736 ret = device->acdb_id;
737
738 return ret;
739}
740
741static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
742{
743 struct operator_specific_device *device;
744 const char *ret = device_table[snd_device];
745
746 device = get_operator_specific_device(snd_device);
747 if (device != NULL)
748 ret = device->mixer_path;
749
750 return ret;
751}
752
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800753inline bool platform_supports_app_type_cfg()
754{
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700755#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800756 return true;
757#else
758 return false;
759#endif
760}
761
jasmine chac89321b2018-04-10 21:37:01 +0800762static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
763{
764 int err;
765 char value[64];
766 int ret = 0;
767
768 if (parms == NULL || cal == NULL)
769 return ret;
770
771 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
772 if (err >= 0) {
773 str_parms_del(parms, "cal_persist");
774 cal->persist = (uint32_t)strtoul(value, NULL, 0);
775 ret = ret | 0x1;
776 }
777 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
778 if (err >= 0) {
779 str_parms_del(parms, "cal_apptype");
780 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
781 ret = ret | 0x2;
782 }
783 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
784 if (err >= 0) {
785 str_parms_del(parms, "cal_caltype");
786 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
787 ret = ret | 0x4;
788 }
789 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
790 if (err >= 0) {
791 str_parms_del(parms, "cal_samplerate");
792 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
793 ret = ret | 0x8;
794 }
795 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
796 if (err >= 0) {
797 str_parms_del(parms, "cal_devid");
798 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
799 ret = ret | 0x10;
800 }
801 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
802 if (err >= 0) {
803 str_parms_del(parms, "cal_snddevid");
804 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
805 ret = ret | 0x20;
806 }
807 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
808 if (err >= 0) {
809 str_parms_del(parms, "cal_topoid");
810 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
811 ret = ret | 0x40;
812 }
813 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
814 if (err >= 0) {
815 str_parms_del(parms, "cal_moduleid");
816 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
817 ret = ret | 0x80;
818 }
819 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
820 if (err >= 0) {
821 str_parms_del(parms, "cal_paramid");
822 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
823 ret = ret | 0x100;
824 }
825 return ret;
826}
827
828static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
829{
830 struct platform_data *my_data = (struct platform_data *)platform;
831 acdb_audio_cal_cfg_t cal;
832 uint8_t *dptr = NULL;
833 int32_t dlen = 0;
834 int err ,ret;
835
836 if (value == NULL || platform == NULL || parms == NULL) {
837 ALOGE("[%s] received null pointer, failed", __func__);
838 goto done_key_audcal;
839 }
840
841 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
842 /* parse audio calibration keys */
843 ret = parse_audiocal_cfg(parms, &cal);
844
845 /* handle audio calibration data now */
846 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
847 if (err >= 0) {
848 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
849 dlen = strlen(value);
850 if (dlen <= 0) {
851 ALOGE("[%s] null data received", __func__);
852 goto done_key_audcal;
853 }
854 /*
855 The base64 encoded string is always larger than the binary data,
856 so b64_pton will always output less data than provided (around 1/3
857 less than the input data). That's why we can allocate input buffer
858 length and then get function work.
859 */
860 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
861 if (dptr == NULL) {
862 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
863 goto done_key_audcal;
864 }
865 dlen = b64_pton(value, dptr, dlen);
866 if (dlen <= 0) {
867 ALOGE("[%s] data decoding failed %d", __func__, dlen);
868 goto done_key_audcal;
869 }
870
871 if (cal.dev_id) {
872 if (audio_is_input_device(cal.dev_id)) {
873 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
874 } else {
875 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
876 }
877 }
878 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
879 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
880 cal.snd_dev_id, cal.acdb_dev_id);
881 if (cal.acdb_dev_id == -EINVAL) {
882 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
883 __func__, cal.acdb_dev_id, cal.snd_dev_id);
884 goto done_key_audcal;
885 }
886 if (my_data->acdb_set_audio_cal) {
887 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
888 }
889 }
890done_key_audcal:
891 if (dptr != NULL)
892 free(dptr);
893}
894
vivek mehta1a9b7c02015-06-25 11:49:38 -0700895bool platform_send_gain_dep_cal(void *platform, int level)
896{
897 bool ret_val = false;
898 struct platform_data *my_data = (struct platform_data *)platform;
899 struct audio_device *adev = my_data->adev;
900 int acdb_dev_id, app_type;
901 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
902 int mode = CAL_MODE_RTAC;
903 struct listnode *node;
904 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700905 bool valid_uc_type;
906 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700907
908 if (my_data->acdb_send_gain_dep_cal == NULL) {
909 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
910 return ret_val;
911 }
912
913 if (!voice_is_in_call(adev)) {
914 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
915 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700916
917 // find the current active sound device
918 list_for_each(node, &adev->usecase_list) {
919 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700920 LOG_ALWAYS_FATAL_IF(usecase == NULL,
921 "unxpected NULL usecase in usecase_list");
922 valid_uc_type = usecase->type == PCM_PLAYBACK;
923 valid_dev = false;
924 if (valid_uc_type) {
925 audio_devices_t dev = usecase->stream.out->devices;
926 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700927 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700928 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
929 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
930 }
931 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700932 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
933 if (platform_supports_app_type_cfg())
934 app_type = usecase->stream.out->app_type_cfg.app_type;
935 else
936 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700937
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700938 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700939
940 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700941 acdb_dev_type, mode, level)) {
942 // set ret_val true if at least one calibration is set successfully
943 ret_val = true;
944 } else {
945 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
946 }
947 } else {
948 ALOGW("%s: Usecase list is empty", __func__);
949 }
950 }
951 } else {
952 ALOGW("%s: Voice call in progress .. ignore setting new cal",
953 __func__);
954 }
955 return ret_val;
956}
957
Eric Laurentcefbbac2014-09-04 13:54:10 -0500958void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700959{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800960 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500961 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700962
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800963 if (strcmp(my_data->ec_ref_mixer_path, "")) {
964 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
965 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500966 }
967
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800968 if (enable) {
969 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
970 if (out_device != AUDIO_DEVICE_NONE) {
971 snd_device = platform_get_output_snd_device(adev->platform, out_device);
972 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
973 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500974
Joe Onorato188b6222016-03-01 11:02:27 -0800975 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800976 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
977 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700978}
979
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700980static struct csd_data *open_csd_client(bool i2s_ext_modem)
981{
982 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
983
984 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
985 if (csd->csd_client == NULL) {
986 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
987 goto error;
988 } else {
989 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
990
991 csd->deinit = (deinit_t)dlsym(csd->csd_client,
992 "csd_client_deinit");
993 if (csd->deinit == NULL) {
994 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
995 dlerror());
996 goto error;
997 }
998 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
999 "csd_client_disable_device");
1000 if (csd->disable_device == NULL) {
1001 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1002 __func__, dlerror());
1003 goto error;
1004 }
1005 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1006 "csd_client_enable_device_config");
1007 if (csd->enable_device_config == NULL) {
1008 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1009 __func__, dlerror());
1010 goto error;
1011 }
1012 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1013 "csd_client_enable_device");
1014 if (csd->enable_device == NULL) {
1015 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1016 __func__, dlerror());
1017 goto error;
1018 }
1019 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1020 "csd_client_start_voice");
1021 if (csd->start_voice == NULL) {
1022 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1023 __func__, dlerror());
1024 goto error;
1025 }
1026 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1027 "csd_client_stop_voice");
1028 if (csd->stop_voice == NULL) {
1029 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1030 __func__, dlerror());
1031 goto error;
1032 }
1033 csd->volume = (volume_t)dlsym(csd->csd_client,
1034 "csd_client_volume");
1035 if (csd->volume == NULL) {
1036 ALOGE("%s: dlsym error %s for csd_client_volume",
1037 __func__, dlerror());
1038 goto error;
1039 }
1040 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1041 "csd_client_mic_mute");
1042 if (csd->mic_mute == NULL) {
1043 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1044 __func__, dlerror());
1045 goto error;
1046 }
1047 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1048 "csd_client_slow_talk");
1049 if (csd->slow_talk == NULL) {
1050 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1051 __func__, dlerror());
1052 goto error;
1053 }
1054 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1055 "csd_client_start_playback");
1056 if (csd->start_playback == NULL) {
1057 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1058 __func__, dlerror());
1059 goto error;
1060 }
1061 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1062 "csd_client_stop_playback");
1063 if (csd->stop_playback == NULL) {
1064 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1065 __func__, dlerror());
1066 goto error;
1067 }
1068 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1069 "csd_client_start_record");
1070 if (csd->start_record == NULL) {
1071 ALOGE("%s: dlsym error %s for csd_client_start_record",
1072 __func__, dlerror());
1073 goto error;
1074 }
1075 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1076 "csd_client_stop_record");
1077 if (csd->stop_record == NULL) {
1078 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1079 __func__, dlerror());
1080 goto error;
1081 }
1082
1083 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1084 "csd_client_get_sample_rate");
1085 if (csd->get_sample_rate == NULL) {
1086 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1087 __func__, dlerror());
1088
1089 goto error;
1090 }
1091
1092 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1093
1094 if (csd->init == NULL) {
1095 ALOGE("%s: dlsym error %s for csd_client_init",
1096 __func__, dlerror());
1097 goto error;
1098 } else {
1099 csd->init(i2s_ext_modem);
1100 }
1101 }
1102 return csd;
1103
1104error:
1105 free(csd);
1106 csd = NULL;
1107 return csd;
1108}
1109
1110void close_csd_client(struct csd_data *csd)
1111{
1112 if (csd != NULL) {
1113 csd->deinit();
1114 dlclose(csd->csd_client);
1115 free(csd);
1116 csd = NULL;
1117 }
1118}
1119
1120static void platform_csd_init(struct platform_data *my_data)
1121{
1122#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001123 int32_t modems, (*count_modems)(void);
1124 const char *name = "libdetectmodem.so";
1125 const char *func = "count_modems";
1126 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001127
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001128 my_data->csd = NULL;
1129
1130 void *lib = dlopen(name, RTLD_NOW);
1131 error = dlerror();
1132 if (!lib) {
1133 ALOGE("%s: could not find %s: %s", __func__, name, error);
1134 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001135 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001136
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001137 count_modems = NULL;
1138 *(void **)(&count_modems) = dlsym(lib, func);
1139 error = dlerror();
1140 if (!count_modems) {
1141 ALOGE("%s: could not find symbol %s in %s: %s",
1142 __func__, func, name, error);
1143 goto done;
1144 }
1145
1146 modems = count_modems();
1147 if (modems < 0) {
1148 ALOGE("%s: count_modems failed\n", __func__);
1149 goto done;
1150 }
1151
Eric Laurent2bafff12016-03-17 12:17:23 -07001152 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001153 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001154 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001155
1156done:
1157 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001158#else
1159 my_data->csd = NULL;
1160#endif
1161}
1162
Eric Laurentc6333382015-09-14 12:43:44 -07001163static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001164{
1165 int32_t dev;
1166 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001167 backend_tag_table[dev] = NULL;
1168 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001169 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001170 }
1171
David Linee3fe402017-03-13 10:00:42 -07001172 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1173 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1174 }
1175
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001176 // To overwrite these go to the audio_platform_info.xml file.
1177 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001178 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001179 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1180 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1181 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1182 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1183 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001184 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001185 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1186 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001187
David Linee3fe402017-03-13 10:00:42 -07001188 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001189 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001190 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001191 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001192 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1193 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001194 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1195 strdup("speaker-safe-and-usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001196 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001197 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1198 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1199 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1200 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001201 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1202 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
1203
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001204 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1205 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1206 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1207 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1208 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1209 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1210 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001211 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001212 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001213 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001214 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1215 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1216 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1217 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1218 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1219 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1220 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1221 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1222 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001223 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1224 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1225 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001226 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1227 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1228 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1229 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001230 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001231 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1232 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001233 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001234 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001235 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001236 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 -07001237 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 -07001238 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1239 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1240 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001241 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1242 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1243 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 -07001244 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1245 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1246 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1247 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1248 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1249 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1250 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001251 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001252 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1253 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1254 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1255 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1256 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1257 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1258 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1259 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001260 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001261 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001262 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001263 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1264 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001265 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1266 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001267 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1268 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001269 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1270 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1271 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1272 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1273 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001274 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1275 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1276 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1277 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1278 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1279 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1280 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1281 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001282 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1283 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1284 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001285 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001286 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1287 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001288 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001289 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1290 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1291 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1292 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1293 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1294 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1295 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1296 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1297 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1298 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1299 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1300 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1301 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1302 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1303 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001304 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001305}
1306
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001307void get_cvd_version(char *cvd_version, struct audio_device *adev)
1308{
1309 struct mixer_ctl *ctl;
1310 int count;
1311 int ret = 0;
1312
1313 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1314 if (!ctl) {
1315 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1316 goto done;
1317 }
1318 mixer_ctl_update(ctl);
1319
1320 count = mixer_ctl_get_num_values(ctl);
1321 if (count > MAX_CVD_VERSION_STRING_SIZE)
1322 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1323
1324 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1325 if (ret != 0) {
1326 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1327 goto done;
1328 }
1329
1330done:
1331 return;
1332}
1333
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001334static int platform_acdb_init(void *platform)
1335{
1336 struct platform_data *my_data = (struct platform_data *)platform;
1337 struct audio_device *adev = my_data->adev;
1338
1339 if (!my_data->acdb_init) {
1340 ALOGE("%s: no acdb_init fn provided", __func__);
1341 return -1;
1342 }
1343
1344 if (my_data->acdb_initialized) {
1345 ALOGW("acdb is already initialized");
1346 return 0;
1347 }
1348
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001349#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001350 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1351 if (!cvd_version)
1352 ALOGE("failed to allocate cvd_version");
1353 else {
1354 get_cvd_version(cvd_version, adev);
1355 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1356 free(cvd_version);
1357 }
1358#elif defined (PLATFORM_MSM8084)
1359 my_data->acdb_init((char *)my_data->snd_card_name);
1360#else
1361 my_data->acdb_init();
1362#endif
1363 my_data->acdb_initialized = true;
1364 return 0;
1365}
1366
David Linee3fe402017-03-13 10:00:42 -07001367static void
1368platform_backend_config_init(struct platform_data *pdata)
1369{
1370 int i;
1371
1372 /* initialize backend config */
1373 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1374 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1375 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1376 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1377
1378 if (i > MAX_RX_CODEC_BACKENDS)
1379 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1380
1381 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1382 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1383 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1384 }
1385
1386 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1387 strdup("SLIM_0_RX Format");
1388 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1389 strdup("SLIM_0_RX SampleRate");
1390
1391 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1392 strdup("SLIM_0_TX Format");
1393 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1394 strdup("SLIM_0_TX SampleRate");
1395
1396 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1397 strdup("USB_AUDIO_TX Format");
1398 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1399 strdup("USB_AUDIO_TX SampleRate");
1400 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1401 strdup("USB_AUDIO_TX Channels");
1402
1403 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1404 strdup("SLIM_6_RX Format");
1405 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1406 strdup("SLIM_6_RX SampleRate");
1407
1408 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1409 strdup("USB_AUDIO_RX Format");
1410 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1411 strdup("USB_AUDIO_RX SampleRate");
1412
1413 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1414 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1415 strdup("USB_AUDIO_RX Channels");
1416}
1417
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001418static int
1419platform_backend_app_type_cfg_init(struct platform_data *pdata,
1420 struct mixer *mixer)
1421{
1422 size_t app_type_cfg[128] = {0};
1423 int length, num_app_types = 0;
1424 struct mixer_ctl *ctl = NULL;
1425
1426 const char *mixer_ctl_name = "App Type Config";
1427 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1428 if (!ctl) {
1429 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1430 return -1;
1431 }
1432
1433 length = 1; // reserve index 0 for number of app types
1434
1435 struct listnode *node;
1436 struct app_type_entry *entry;
1437 list_for_each(node, &app_type_entry_list) {
1438 entry = node_to_item(node, struct app_type_entry, node);
1439 app_type_cfg[length++] = entry->app_type;
1440 app_type_cfg[length++] = entry->max_rate;
1441 app_type_cfg[length++] = entry->bit_width;
1442 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1443 num_app_types += 1;
1444 }
1445
1446 // default for capture
1447 int t;
1448 platform_get_default_app_type_v2(pdata,
1449 PCM_CAPTURE,
1450 &t);
1451 app_type_cfg[length++] = t;
1452 app_type_cfg[length++] = 48000;
1453 app_type_cfg[length++] = 16;
1454 num_app_types += 1;
1455
1456 if (num_app_types) {
1457 app_type_cfg[0] = num_app_types;
1458 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1459 ALOGE("Failed to set app type cfg");
1460 }
1461 }
1462 return 0;
1463}
1464
Xu Han1638fd12018-04-20 12:42:23 -07001465static void configure_flicker_sensor_input(struct mixer *mixer)
1466{
1467 struct mixer_ctl *ctl;
1468 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1469 int setting1 = 1;
1470 const char* ctl2 = "CDC_IF TX2 MUX";
1471 const char* setting2 = "DEC2";
1472 const char* ctl3 = "SLIM_1_TX Channels";
1473 const char* setting3 = "One";
1474 const char* ctl4 = "ADC MUX2";
1475 const char* setting4 = "AMIC";
1476 const char* ctl5 = "AMIC MUX2";
1477 const char* setting5 = "ADC1";
1478 const char* ctl6 = "DEC2 Volume";
1479 int setting6 = 84;
1480 const char* ctl7 = "MultiMedia2 Mixer SLIM_1_TX";
1481 int setting7 = 1;
1482 const char* ctl8 = "SLIM_1_TX SampleRate";
1483 const char* setting8 = "KHZ_8";
1484
1485 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1486 mixer_ctl_set_value(ctl, 0, setting1);
1487 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1488 mixer_ctl_set_enum_by_string(ctl, setting2);
1489 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1490 mixer_ctl_set_enum_by_string(ctl, setting3);
1491 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1492 mixer_ctl_set_enum_by_string(ctl, setting4);
1493 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1494 mixer_ctl_set_enum_by_string(ctl, setting5);
1495 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1496 mixer_ctl_set_value(ctl, 0, setting6);
1497 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1498 mixer_ctl_set_value(ctl, 0, setting7);
1499 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1500 mixer_ctl_set_enum_by_string(ctl, setting8);
1501}
1502
Eric Laurentb23d5282013-05-14 15:27:20 -07001503void *platform_init(struct audio_device *adev)
1504{
1505 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001506 struct platform_data *my_data = NULL;
1507 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1508 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001509 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001510 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001511 char *snd_internal_name = NULL;
1512 char *tmp = NULL;
1513 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001514 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1515 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001516 my_data = calloc(1, sizeof(struct platform_data));
1517
1518 my_data->adev = adev;
1519
keunhui.park2f7306a2015-07-16 16:48:06 +09001520 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001521 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001522
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001523 set_platform_defaults(my_data);
1524
vivek mehta0fb11312017-05-15 19:35:32 -07001525 // audio_extn_utils_get_snd_card_num does
1526 // - open mixer and get snd card name
1527 // - parse platform info xml file and check for valid snd card name
1528 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001529
vivek mehta0fb11312017-05-15 19:35:32 -07001530 snd_card_num = audio_extn_utils_get_snd_card_num();
1531 if (-1 == snd_card_num) {
1532 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1533 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001534 }
1535
vivek mehta0fb11312017-05-15 19:35:32 -07001536 adev->mixer = mixer_open(snd_card_num);
1537 snd_card_name = mixer_get_name(adev->mixer);
1538 my_data->hw_info = hw_info_init(snd_card_name);
1539
1540 audio_extn_set_snd_card_split(snd_card_name);
1541 snd_split_handle = audio_extn_get_snd_card_split();
1542
1543 /* Get the codec internal name from the sound card and/or form factor
1544 * name and form the mixer paths and platfor info file name dynamically.
1545 * This is generic way of picking any codec and forma factor name based
1546 * mixer and platform info files in future with no code change.
1547
1548 * current code extends and looks for any of the exteneded mixer path and
1549 * platform info file present based on codec and form factor.
1550
1551 * order of picking appropriate file is
1552 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1553 * <ii> mixer_paths_<codec_name>.xml, if file not present
1554 * <iii> mixer_paths.xml
1555
1556 * same order is followed for audio_platform_info.xml as well
1557 */
1558
1559 // need to carryforward old file name
1560 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1561 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1562 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1563 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1564 } else {
1565
1566 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1567 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1568 snd_split_handle->form_factor);
1569 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1570 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1571 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1572 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1573
1574 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1575 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1576 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1577 audio_extn_utils_resolve_config_file(mixer_xml_file);
1578 }
1579 }
1580 }
1581
1582 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1583
jiabin8962a4d2018-03-19 18:21:24 -07001584 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001585 /* Initialize platform specific ids and/or backends*/
1586 platform_info_init(platform_info_file, my_data);
1587
1588 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1589 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1590
1591 if (!adev->audio_route) {
1592 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1593 mixer_close(adev->mixer);
1594 adev->mixer = NULL;
1595 hw_info_deinit(my_data->hw_info);
1596 my_data->hw_info = NULL;
1597 goto init_failed;
1598 }
1599 adev->snd_card = snd_card_num;
1600 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1601
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001602 //set max volume step for voice call
1603 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1604 my_data->max_vol_index = atoi(value);
1605
vivek mehta65ad12d2015-08-13 18:32:48 -07001606 property_get("persist.audio.dualmic.config",value,"");
1607 if (!strcmp("endfire", value)) {
1608 dual_mic_config = true;
1609 }
1610
John Muir9e59a962018-01-10 13:30:00 -08001611 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001612
Eric Laurentb23d5282013-05-14 15:27:20 -07001613 my_data->fluence_in_spkr_mode = false;
1614 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001615 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001616 my_data->fluence_in_voice_rec = false;
1617
vivek mehta65ad12d2015-08-13 18:32:48 -07001618 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001619 if (!strcmp("fluencepro", value)) {
1620 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001621 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001622 my_data->fluence_type = FLUENCE_ENABLE;
1623 } else if (!strcmp("none", value)) {
1624 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001625 }
1626
Prashant Malanic92c5962015-08-11 15:10:18 -07001627 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001628 property_get("persist.audio.fluence.voicecall",value,"");
1629 if (!strcmp("true", value)) {
1630 my_data->fluence_in_voice_call = true;
1631 }
1632
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001633 property_get("persist.audio.fluence.voicecomm",value,"");
1634 if (!strcmp("true", value)) {
1635 my_data->fluence_in_voice_comm = true;
1636 }
1637
Eric Laurentb23d5282013-05-14 15:27:20 -07001638 property_get("persist.audio.fluence.voicerec",value,"");
1639 if (!strcmp("true", value)) {
1640 my_data->fluence_in_voice_rec = true;
1641 }
1642
1643 property_get("persist.audio.fluence.speaker",value,"");
1644 if (!strcmp("true", value)) {
1645 my_data->fluence_in_spkr_mode = true;
1646 }
1647 }
1648
Prashant Malanic92c5962015-08-11 15:10:18 -07001649 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1650 switch (my_data->max_mic_count) {
1651 case 4:
1652 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1653 case 3:
1654 my_data->source_mic_type |= SOURCE_THREE_MIC;
1655 case 2:
1656 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1657 case 1:
1658 my_data->source_mic_type |= SOURCE_MONO_MIC;
1659 break;
1660 default:
1661 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1662 __func__, my_data->max_mic_count);
1663 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1664 break;
1665 }
1666
1667 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1668 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1669 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1670 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1671 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1672
Eric Laurentb23d5282013-05-14 15:27:20 -07001673 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1674 if (my_data->acdb_handle == NULL) {
1675 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1676 } else {
1677 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1678 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1679 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001680 if (!my_data->acdb_deallocate)
1681 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1682 __func__, LIB_ACDB_LOADER);
1683
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001684 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1685 "acdb_loader_send_audio_cal_v3");
1686 if (!my_data->acdb_send_audio_cal_v3)
1687 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1688 __func__, LIB_ACDB_LOADER);
1689
Eric Laurentb23d5282013-05-14 15:27:20 -07001690 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1691 "acdb_loader_send_audio_cal");
1692 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001693 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001694 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001695
Eric Laurentb23d5282013-05-14 15:27:20 -07001696 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1697 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001698 if (!my_data->acdb_send_voice_cal)
1699 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1700 __func__, LIB_ACDB_LOADER);
1701
1702 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1703 "acdb_loader_reload_vocvoltable");
1704 if (!my_data->acdb_reload_vocvoltable)
1705 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1706 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001707
1708 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1709 "acdb_loader_send_gain_dep_cal");
1710 if (!my_data->acdb_send_gain_dep_cal)
1711 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1712 __func__, LIB_ACDB_LOADER);
1713
Xu Han1638fd12018-04-20 12:42:23 -07001714#if defined (FLICKER_SENSOR_INPUT)
1715 configure_flicker_sensor_input(adev->mixer);
1716#endif
1717
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001718#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
vivek mehta0fb11312017-05-15 19:35:32 -07001719 acdb_init_v2_cvd_t acdb_init_local;
1720 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001721 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001722 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001723 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1724 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001725
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001726#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001727 acdb_init_v2_t acdb_init_local;
1728 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001729 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001730 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001731 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1732 dlerror());
1733
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001734#else
vivek mehta0fb11312017-05-15 19:35:32 -07001735 acdb_init_t acdb_init_local;
1736 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001737 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001738 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001739 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1740 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001741#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001742 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001743
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001744 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1745 dlsym(my_data->acdb_handle,
1746 "acdb_loader_send_common_custom_topology");
1747
1748 if (!my_data->acdb_send_custom_top)
1749 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1750 __func__, LIB_ACDB_LOADER);
1751
jasmine chac89321b2018-04-10 21:37:01 +08001752 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1753 "acdb_loader_set_audio_cal_v2");
1754 if (!my_data->acdb_set_audio_cal)
1755 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1756 __func__, LIB_ACDB_LOADER);
1757
vivek mehta0fb11312017-05-15 19:35:32 -07001758 int result = acdb_init(adev->snd_card);
1759 if (!result) {
1760 my_data->acdb_initialized = true;
1761 ALOGD("ACDB initialized");
1762 } else {
1763 my_data->acdb_initialized = false;
1764 ALOGD("ACDB initialization failed");
1765 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001766 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001767
David Linee3fe402017-03-13 10:00:42 -07001768 /* init usb */
1769 audio_extn_usb_init(adev);
1770
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001771 /* init a2dp */
1772 audio_extn_a2dp_init(adev);
1773
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001774 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001775
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001776 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1777
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001778 /* load csd client */
1779 platform_csd_init(my_data);
1780
David Linee3fe402017-03-13 10:00:42 -07001781 platform_backend_config_init(my_data);
1782
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001783 init_be_dai_name_table(adev);
1784
1785 if (platform_supports_app_type_cfg())
1786 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1787
Eric Laurentb23d5282013-05-14 15:27:20 -07001788 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001789
1790init_failed:
1791 if (my_data)
1792 free(my_data);
1793 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001794}
1795
1796void platform_deinit(void *platform)
1797{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001798 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001799 struct operator_info *info_item;
1800 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001801 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001802 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001803
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001804 struct platform_data *my_data = (struct platform_data *)platform;
1805 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001806
vivek mehtade4849c2016-03-03 17:23:38 -08001807 hw_info_deinit(my_data->hw_info);
1808
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001809 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1810 if (backend_tag_table[dev])
1811 free(backend_tag_table[dev]);
1812 if (hw_interface_table[dev])
1813 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001814 if (operator_specific_device_table[dev]) {
1815 while (!list_empty(operator_specific_device_table[dev])) {
1816 node = list_head(operator_specific_device_table[dev]);
1817 list_remove(node);
1818 device_item = node_to_item(node, struct operator_specific_device, list);
1819 free(device_item->operator);
1820 free(device_item->mixer_path);
1821 free(device_item);
1822 }
1823 free(operator_specific_device_table[dev]);
1824 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001825 }
1826
1827 if (my_data->snd_card_name)
1828 free(my_data->snd_card_name);
1829
keunhui.park2f7306a2015-07-16 16:48:06 +09001830 while (!list_empty(&operator_info_list)) {
1831 node = list_head(&operator_info_list);
1832 list_remove(node);
1833 info_item = node_to_item(node, struct operator_info, list);
1834 free(info_item->name);
1835 free(info_item->mccmnc);
1836 free(info_item);
1837 }
1838
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001839 while (!list_empty(&app_type_entry_list)) {
1840 node = list_head(&app_type_entry_list);
1841 list_remove(node);
1842 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001843 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001844 free(ap);
1845 }
1846
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001847 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001848 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001849
1850 /* deinit usb */
1851 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001852}
1853
1854const char *platform_get_snd_device_name(snd_device_t snd_device)
1855{
keunhui.park2f7306a2015-07-16 16:48:06 +09001856 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1857 if (operator_specific_device_table[snd_device] != NULL) {
1858 return get_operator_specific_device_mixer_path(snd_device);
1859 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001860 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001861 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001862 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001863}
1864
vivek mehtade4849c2016-03-03 17:23:38 -08001865int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1866 char *device_name)
1867{
1868 struct platform_data *my_data = (struct platform_data *)platform;
1869
David Benjamin1565f992016-09-21 12:10:34 -04001870 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001871 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001872 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1873 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001874 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1875 if (operator_specific_device_table[snd_device] != NULL) {
1876 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1877 DEVICE_NAME_MAX_SIZE);
1878 } else {
1879 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1880 }
1881 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1882 } else {
1883 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1884 }
1885
1886 return 0;
1887}
1888
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001889void platform_add_backend_name(void *platform, char *mixer_path,
1890 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001891{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001892 struct platform_data *my_data = (struct platform_data *)platform;
1893
Haynes Mathew George98c95622014-06-20 19:14:25 -07001894 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1895 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1896 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001897 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001898
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001899 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001900
1901 if (suffix != NULL) {
1902 strcat(mixer_path, " ");
1903 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001904 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001905}
1906
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001907bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1908{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001909 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1910 platform_get_snd_device_name(snd_device1),
1911 platform_get_snd_device_name(snd_device2));
1912
1913 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1914 ALOGE("%s: Invalid snd_device = %s", __func__,
1915 platform_get_snd_device_name(snd_device1));
1916 return false;
1917 }
1918 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1919 ALOGE("%s: Invalid snd_device = %s", __func__,
1920 platform_get_snd_device_name(snd_device2));
1921 return false;
1922 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001923
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001924 const char * be_itf1 = hw_interface_table[snd_device1];
1925 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001926 /*
1927 hw_interface_table has overrides for a snd_device.
1928 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1929 */
1930 if (be_itf1 == NULL) {
1931 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001932 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001933 if (be_itf2 == NULL) {
1934 be_itf2 = DEFAULT_RX_BACKEND;
1935 }
1936 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1937 /*
1938 this takes care of finding a device within a combo device pair as well
1939 */
1940 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001941}
1942
Eric Laurentb23d5282013-05-14 15:27:20 -07001943int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1944{
1945 int device_id;
1946 if (device_type == PCM_PLAYBACK)
1947 device_id = pcm_device_table[usecase][0];
1948 else
1949 device_id = pcm_device_table[usecase][1];
1950 return device_id;
1951}
1952
Haynes Mathew George98c95622014-06-20 19:14:25 -07001953static int find_index(const struct name_to_index * table, int32_t len,
1954 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001955{
1956 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001957 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001958
Haynes Mathew George98c95622014-06-20 19:14:25 -07001959 if (table == NULL) {
1960 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001961 ret = -ENODEV;
1962 goto done;
1963 }
1964
Haynes Mathew George98c95622014-06-20 19:14:25 -07001965 if (name == NULL) {
1966 ALOGE("null key");
1967 ret = -ENODEV;
1968 goto done;
1969 }
1970
1971 for (i=0; i < len; i++) {
1972 if (!strcmp(table[i].name, name)) {
1973 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001974 goto done;
1975 }
1976 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001977 ALOGE("%s: Could not find index for name = %s",
1978 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001979 ret = -ENODEV;
1980done:
1981 return ret;
1982}
1983
Haynes Mathew George98c95622014-06-20 19:14:25 -07001984int platform_get_snd_device_index(char *device_name)
1985{
1986 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1987}
1988
1989int platform_get_usecase_index(const char *usecase_name)
1990{
1991 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1992}
1993
keunhui.park2f7306a2015-07-16 16:48:06 +09001994void platform_add_operator_specific_device(snd_device_t snd_device,
1995 const char *operator,
1996 const char *mixer_path,
1997 unsigned int acdb_id)
1998{
1999 struct operator_specific_device *device;
2000
2001 if (operator_specific_device_table[snd_device] == NULL) {
2002 operator_specific_device_table[snd_device] =
2003 (struct listnode *)calloc(1, sizeof(struct listnode));
2004 list_init(operator_specific_device_table[snd_device]);
2005 }
2006
2007 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2008
2009 device->operator = strdup(operator);
2010 device->mixer_path = strdup(mixer_path);
2011 device->acdb_id = acdb_id;
2012
2013 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2014
Eric Laurent2bafff12016-03-17 12:17:23 -07002015 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002016 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2017
2018}
2019
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002020int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2021{
2022 int ret = 0;
2023
2024 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2025 ALOGE("%s: Invalid snd_device = %d",
2026 __func__, snd_device);
2027 ret = -EINVAL;
2028 goto done;
2029 }
2030
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002031 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2032 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002033 acdb_device_table[snd_device] = acdb_id;
2034done:
2035 return ret;
2036}
2037
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002038int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2039{
2040 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2041 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2042 return -EINVAL;
2043 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002044
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002045 /*
2046 * If speaker protection is enabled, function returns supported
2047 * sound device for speaker. Else same sound device is returned.
2048 */
2049 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2050
keunhui.park2f7306a2015-07-16 16:48:06 +09002051 if (operator_specific_device_table[snd_device] != NULL)
2052 return get_operator_specific_device_acdb_id(snd_device);
2053 else
2054 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002055}
2056
David Linee3fe402017-03-13 10:00:42 -07002057static int platform_get_backend_index(snd_device_t snd_device)
2058{
2059 int32_t port = DEFAULT_CODEC_BACKEND;
2060
2061 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2062 if (backend_tag_table[snd_device] != NULL) {
2063 if (strncmp(backend_tag_table[snd_device], "headphones",
2064 sizeof("headphones")) == 0)
2065 port = HEADPHONE_BACKEND;
2066 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2067 port = HDMI_RX_BACKEND;
2068 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2069 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2070 port = USB_AUDIO_RX_BACKEND;
2071 }
2072 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2073 port = DEFAULT_CODEC_TX_BACKEND;
2074 if (backend_tag_table[snd_device] != NULL) {
2075 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2076 port = USB_AUDIO_TX_BACKEND;
2077 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2078 port = BT_SCO_TX_BACKEND;
2079 }
2080 } else {
2081 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2082 }
2083
2084 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2085
2086 return port;
2087}
2088
Eric Laurentb23d5282013-05-14 15:27:20 -07002089int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2090{
2091 struct platform_data *my_data = (struct platform_data *)platform;
2092 int acdb_dev_id, acdb_dev_type;
2093
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002094 if (platform_supports_app_type_cfg()) // use v2 instead
2095 return -ENOSYS;
2096
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002097 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002098 if (acdb_dev_id < 0) {
2099 ALOGE("%s: Could not find acdb id for device(%d)",
2100 __func__, snd_device);
2101 return -EINVAL;
2102 }
2103 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002104 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002105 __func__, snd_device, acdb_dev_id);
2106 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2107 snd_device < SND_DEVICE_OUT_END)
2108 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2109 else
2110 acdb_dev_type = ACDB_DEV_TYPE_IN;
2111 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2112 }
2113 return 0;
2114}
2115
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002116int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2117 int app_type, int sample_rate)
2118{
2119 struct platform_data *my_data = (struct platform_data *)platform;
2120 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002121 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002122 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2123 int i, num_devices = 1;
2124
2125 if (!platform_supports_app_type_cfg()) // use v1 instead
2126 return -ENOSYS;
2127
vivek mehta7e573672018-03-13 17:41:41 -07002128 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002129 snd_device = usecase->in_snd_device;
2130
2131 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002132 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002133 if (acdb_dev_id < 0) {
2134 ALOGE("%s: Could not find acdb id for device(%d)",
2135 __func__, snd_device);
2136 return -EINVAL;
2137 }
2138
2139 if (platform_can_split_snd_device(snd_device,
2140 &num_devices, new_snd_device) < 0) {
2141 new_snd_device[0] = snd_device;
2142 }
2143
2144 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002145 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002146 if (acdb_dev_id < 0) {
2147 ALOGE("%s: Could not find acdb id for device(%d)",
2148 __func__, new_snd_device[i]);
2149 return -EINVAL;
2150 }
2151 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2152 __func__, new_snd_device[i], acdb_dev_id);
2153 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2154 new_snd_device[i] < SND_DEVICE_OUT_END)
2155 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2156 else
2157 acdb_dev_type = ACDB_DEV_TYPE_IN;
2158
2159 if (my_data->acdb_send_audio_cal_v3) {
2160 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2161 app_type, sample_rate, i);
2162 } else if (my_data->acdb_send_audio_cal) {
2163 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2164 }
2165 }
2166
2167 return 0;
2168}
2169
2170
Eric Laurentb23d5282013-05-14 15:27:20 -07002171int platform_switch_voice_call_device_pre(void *platform)
2172{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002173 struct platform_data *my_data = (struct platform_data *)platform;
2174 int ret = 0;
2175
2176 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002177 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002178 /* This must be called before disabling mixer controls on APQ side */
2179 ret = my_data->csd->disable_device();
2180 if (ret < 0) {
2181 ALOGE("%s: csd_client_disable_device, failed, error %d",
2182 __func__, ret);
2183 }
2184 }
2185 return ret;
2186}
2187
2188int platform_switch_voice_call_enable_device_config(void *platform,
2189 snd_device_t out_snd_device,
2190 snd_device_t in_snd_device)
2191{
2192 struct platform_data *my_data = (struct platform_data *)platform;
2193 int acdb_rx_id, acdb_tx_id;
2194 int ret = 0;
2195
2196 if (my_data->csd == NULL)
2197 return ret;
2198
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002199 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002200 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002201
2202 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2203 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2204 if (ret < 0) {
2205 ALOGE("%s: csd_enable_device_config, failed, error %d",
2206 __func__, ret);
2207 }
2208 } else {
2209 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2210 acdb_rx_id, acdb_tx_id);
2211 }
2212
2213 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002214}
2215
2216int platform_switch_voice_call_device_post(void *platform,
2217 snd_device_t out_snd_device,
2218 snd_device_t in_snd_device)
2219{
2220 struct platform_data *my_data = (struct platform_data *)platform;
2221 int acdb_rx_id, acdb_tx_id;
2222
2223 if (my_data->acdb_send_voice_cal == NULL) {
2224 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2225 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002226 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2227 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002228
2229 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2230 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2231 else
2232 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2233 acdb_rx_id, acdb_tx_id);
2234 }
2235
2236 return 0;
2237}
2238
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002239int platform_switch_voice_call_usecase_route_post(void *platform,
2240 snd_device_t out_snd_device,
2241 snd_device_t in_snd_device)
2242{
2243 struct platform_data *my_data = (struct platform_data *)platform;
2244 int acdb_rx_id, acdb_tx_id;
2245 int ret = 0;
2246
2247 if (my_data->csd == NULL)
2248 return ret;
2249
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002250 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002251 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002252
2253 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2254 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2255 my_data->adev->acdb_settings);
2256 if (ret < 0) {
2257 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2258 }
2259 } else {
2260 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2261 acdb_rx_id, acdb_tx_id);
2262 }
2263
2264 return ret;
2265}
2266
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002267int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002268{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002269 struct platform_data *my_data = (struct platform_data *)platform;
2270 int ret = 0;
2271
2272 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002273 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002274 if (ret < 0) {
2275 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2276 }
2277 }
2278 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002279}
2280
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002281int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002282{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002283 struct platform_data *my_data = (struct platform_data *)platform;
2284 int ret = 0;
2285
2286 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002287 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002288 if (ret < 0) {
2289 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2290 }
2291 }
2292 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002293}
2294
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002295int platform_get_sample_rate(void *platform, uint32_t *rate)
2296{
2297 struct platform_data *my_data = (struct platform_data *)platform;
2298 int ret = 0;
2299
2300 if (my_data->csd != NULL) {
2301 ret = my_data->csd->get_sample_rate(rate);
2302 if (ret < 0) {
2303 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2304 }
2305 }
2306 return ret;
2307}
2308
vivek mehtab6506412015-08-07 16:55:17 -07002309void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2310 snd_device_t snd_device,
2311 bool enable)
2312{
2313 const char* name;
2314 switch (snd_device) {
2315 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2316 if (enable)
2317 name = "spkr-gain-in-headphone-combo";
2318 else
2319 name = "speaker-gain-default";
2320 break;
2321 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2322 if (enable)
2323 name = "spkr-gain-in-line-combo";
2324 else
2325 name = "speaker-gain-default";
2326 break;
2327 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2328 if (enable)
2329 name = "spkr-safe-gain-in-headphone-combo";
2330 else
2331 name = "speaker-safe-gain-default";
2332 break;
2333 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2334 if (enable)
2335 name = "spkr-safe-gain-in-line-combo";
2336 else
2337 name = "speaker-safe-gain-default";
2338 break;
2339 default:
2340 return;
2341 }
2342
2343 audio_route_apply_and_update_path(adev->audio_route, name);
2344}
2345
Eric Laurentb23d5282013-05-14 15:27:20 -07002346int platform_set_voice_volume(void *platform, int volume)
2347{
2348 struct platform_data *my_data = (struct platform_data *)platform;
2349 struct audio_device *adev = my_data->adev;
2350 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002351 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002352 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002353 int vol_index = 0, ret = 0;
2354 uint32_t set_values[ ] = {0,
2355 ALL_SESSION_VSID,
2356 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002357
2358 // Voice volume levels are mapped to adsp volume levels as follows.
2359 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2360 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002361 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002362 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002363
2364 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2365 if (!ctl) {
2366 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2367 __func__, mixer_ctl_name);
2368 return -EINVAL;
2369 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002370 ALOGV("Setting voice volume index: %d", set_values[0]);
2371 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2372
Nadav Barc46d0fa2017-12-24 14:50:37 +02002373 // Send mute command in case volume index is max since indexes are inverted
2374 // for mixer controls.
2375 if (vol_index == my_data->max_vol_index) {
2376 set_values[0] = 1;
2377 }
2378 else {
2379 set_values[0] = 0;
2380 }
2381
2382 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2383 if (!ctl) {
2384 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2385 __func__, mute_mixer_ctl_name);
2386 return -EINVAL;
2387 }
2388 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2389 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2390
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002391 if (my_data->csd != NULL) {
2392 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2393 DEFAULT_VOLUME_RAMP_DURATION_MS);
2394 if (ret < 0) {
2395 ALOGE("%s: csd_volume error %d", __func__, ret);
2396 }
2397 }
2398 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002399}
2400
2401int platform_set_mic_mute(void *platform, bool state)
2402{
2403 struct platform_data *my_data = (struct platform_data *)platform;
2404 struct audio_device *adev = my_data->adev;
2405 struct mixer_ctl *ctl;
2406 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002407 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002408 uint32_t set_values[ ] = {0,
2409 ALL_SESSION_VSID,
2410 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002411
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002412 if (adev->mode != AUDIO_MODE_IN_CALL &&
2413 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002414 return 0;
2415
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002416 if (adev->enable_hfp)
2417 mixer_ctl_name = "HFP Tx Mute";
2418
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002419 set_values[0] = state;
2420 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2421 if (!ctl) {
2422 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2423 __func__, mixer_ctl_name);
2424 return -EINVAL;
2425 }
2426 ALOGV("Setting voice mute state: %d", state);
2427 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2428
2429 if (my_data->csd != NULL) {
2430 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2431 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002432 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002433 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002434 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002435 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002436 return ret;
2437}
Eric Laurentb23d5282013-05-14 15:27:20 -07002438
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002439int platform_set_device_mute(void *platform, bool state, char *dir)
2440{
2441 struct platform_data *my_data = (struct platform_data *)platform;
2442 struct audio_device *adev = my_data->adev;
2443 struct mixer_ctl *ctl;
2444 char *mixer_ctl_name = NULL;
2445 int ret = 0;
2446 uint32_t set_values[ ] = {0,
2447 ALL_SESSION_VSID,
2448 0};
2449 if(dir == NULL) {
2450 ALOGE("%s: Invalid direction:%s", __func__, dir);
2451 return -EINVAL;
2452 }
2453
2454 if (!strncmp("rx", dir, sizeof("rx"))) {
2455 mixer_ctl_name = "Voice Rx Device Mute";
2456 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2457 mixer_ctl_name = "Voice Tx Device Mute";
2458 } else {
2459 return -EINVAL;
2460 }
2461
2462 set_values[0] = state;
2463 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2464 if (!ctl) {
2465 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2466 __func__, mixer_ctl_name);
2467 return -EINVAL;
2468 }
2469
2470 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2471 __func__,state, mixer_ctl_name);
2472 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2473
2474 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002475}
2476
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002477int platform_can_split_snd_device(snd_device_t snd_device,
2478 int *num_devices,
2479 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002480{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002481 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002482 if (NULL == num_devices || NULL == new_snd_devices) {
2483 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002484 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002485 }
2486
2487 /*
2488 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002489 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002490 */
2491 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2492 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2493 *num_devices = 2;
2494 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2495 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002496 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002497 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2498 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2499 *num_devices = 2;
2500 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2501 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002502 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002503 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2504 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2505 *num_devices = 2;
2506 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2507 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002508 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002509 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2510 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2511 *num_devices = 2;
2512 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2513 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002514 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002515 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2516 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2517 SND_DEVICE_OUT_BT_SCO)) {
2518 *num_devices = 2;
2519 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2520 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2521 ret = 0;
2522 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2523 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2524 SND_DEVICE_OUT_BT_SCO_WB)) {
2525 *num_devices = 2;
2526 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2527 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2528 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002529 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2530 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2531 *num_devices = 2;
2532 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2533 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2534 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002535 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2536 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2537 *num_devices = 2;
2538 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2539 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2540 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002541 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2542 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2543 SND_DEVICE_OUT_BT_A2DP)) {
2544 *num_devices = 2;
2545 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2546 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2547 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002548 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002549
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002550 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002551}
2552
Eric Laurentb23d5282013-05-14 15:27:20 -07002553snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2554{
2555 struct platform_data *my_data = (struct platform_data *)platform;
2556 struct audio_device *adev = my_data->adev;
2557 audio_mode_t mode = adev->mode;
2558 snd_device_t snd_device = SND_DEVICE_NONE;
2559
2560 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2561 if (devices == AUDIO_DEVICE_NONE ||
2562 devices & AUDIO_DEVICE_BIT_IN) {
2563 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2564 goto exit;
2565 }
2566
Eric Laurent1b491552015-09-15 17:52:41 -07002567 if (popcount(devices) == 2) {
2568 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2569 AUDIO_DEVICE_OUT_SPEAKER) ||
2570 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2571 AUDIO_DEVICE_OUT_SPEAKER)) {
2572 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2573 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2574 AUDIO_DEVICE_OUT_SPEAKER)) {
2575 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2576 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2577 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2578 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2579 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2580 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2581 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2582 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2583 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2584 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2585 AUDIO_DEVICE_OUT_SPEAKER)) {
2586 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002587 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2588 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2589 snd_device = adev->bt_wb_speech_enabled ?
2590 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2591 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002592 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2593 AUDIO_DEVICE_OUT_SPEAKER)) ||
2594 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2595 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002596 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002597 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2598 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2599 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2600 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002601 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002602 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2603 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2604 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002605 } else {
2606 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2607 goto exit;
2608 }
2609 if (snd_device != SND_DEVICE_NONE) {
2610 goto exit;
2611 }
2612 }
2613
2614 if (popcount(devices) != 1) {
2615 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2616 goto exit;
2617 }
2618
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302619 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002620 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002621 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2622 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002623 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002624 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002625 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002626 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002627 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002628 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002629 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002630 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002631 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002632 else {
2633 if (devices & AUDIO_DEVICE_OUT_LINE)
2634 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2635 else
2636 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2637 }
Eric Laurent99dab492017-06-17 15:19:08 -07002638 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002639 if (voice_is_in_call(adev)) {
2640 switch (adev->voice.tty_mode) {
2641 case TTY_MODE_FULL:
2642 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2643 break;
2644 case TTY_MODE_VCO:
2645 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2646 break;
2647 case TTY_MODE_HCO:
2648 // since Hearing will be on handset\speaker, use existing device
2649 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2650 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002651 case TTY_MODE_OFF:
2652 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002653 default:
2654 ALOGE("%s: Invalid TTY mode (%#x)",
2655 __func__, adev->voice.tty_mode);
2656 }
2657 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002658 if (snd_device == SND_DEVICE_NONE) {
2659 snd_device = audio_extn_usb_is_capture_supported() ?
2660 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2661 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2662 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002663 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002664 if (adev->bt_wb_speech_enabled) {
2665 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2666 } else {
2667 snd_device = SND_DEVICE_OUT_BT_SCO;
2668 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002669 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2670 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002671 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002672 if (!adev->enable_hfp) {
2673 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2674 } else {
2675 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2676 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002677 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002678 if(adev->voice.hac)
2679 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2680 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002681 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2682 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002683 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002684 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2685 snd_device = SND_DEVICE_OUT_VOICE_TX;
2686
Eric Laurentb23d5282013-05-14 15:27:20 -07002687 if (snd_device != SND_DEVICE_NONE) {
2688 goto exit;
2689 }
2690 }
2691
Eric Laurentb23d5282013-05-14 15:27:20 -07002692 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2693 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2694 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002695 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2696 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002697 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2698 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002699 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002700 /*
2701 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2702 * Or there will be a small pause while performing device switch.
2703 */
2704 if (my_data->speaker_lr_swap &&
2705 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2706 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002707 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2708 else
2709 snd_device = SND_DEVICE_OUT_SPEAKER;
2710 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002711 if (adev->bt_wb_speech_enabled) {
2712 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2713 } else {
2714 snd_device = SND_DEVICE_OUT_BT_SCO;
2715 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002716 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2717 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002718 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2719 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002720 } else if (audio_is_usb_out_device(devices)) {
David Linee3fe402017-03-13 10:00:42 -07002721 if (audio_extn_usb_is_capture_supported())
2722 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2723 else
2724 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2725 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002726 /*HAC support for voice-ish audio (eg visual voicemail)*/
2727 if(adev->voice.hac)
2728 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2729 else
2730 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002731 } else {
2732 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2733 }
2734exit:
2735 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2736 return snd_device;
2737}
2738
2739snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2740{
2741 struct platform_data *my_data = (struct platform_data *)platform;
2742 struct audio_device *adev = my_data->adev;
2743 audio_source_t source = (adev->active_input == NULL) ?
2744 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2745
2746 audio_mode_t mode = adev->mode;
2747 audio_devices_t in_device = ((adev->active_input == NULL) ?
2748 AUDIO_DEVICE_NONE : adev->active_input->device)
2749 & ~AUDIO_DEVICE_BIT_IN;
2750 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2751 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2752 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002753 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002754
Prashant Malanic92c5962015-08-11 15:10:18 -07002755 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2756 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002757 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2758 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002759 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002760 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002761 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2762 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002763 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002764 case TTY_MODE_FULL:
2765 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2766 break;
2767 case TTY_MODE_VCO:
2768 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2769 break;
2770 case TTY_MODE_HCO:
2771 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2772 break;
2773 default:
2774 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2775 }
2776 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002777 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002778 switch (adev->voice.tty_mode) {
2779 case TTY_MODE_FULL:
2780 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2781 break;
2782 case TTY_MODE_VCO:
2783 // since voice will be captured from handset mic, use existing device
2784 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2785 break;
2786 case TTY_MODE_HCO:
2787 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2788 break;
2789 default:
2790 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002791 }
2792 goto exit;
2793 }
2794 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002795 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002796 if (my_data->fluence_in_voice_call == false) {
2797 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2798 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002799 if (is_operator_tmus())
2800 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002801 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002802 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002803 }
2804 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2805 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2806 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002807 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002808 if (adev->bluetooth_nrec)
2809 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2810 else
2811 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002812 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002813 if (adev->bluetooth_nrec)
2814 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2815 else
2816 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002817 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002818 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002819 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2820 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2821 out_device & AUDIO_DEVICE_OUT_LINE) {
2822 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2823 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2824 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2825 } else {
2826 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2827 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002828 }
vivek mehtafe121d52015-08-10 23:39:23 -07002829
2830 //select default
2831 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002832 if (!adev->enable_hfp) {
2833 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2834 } else {
2835 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2836 platform_set_echo_reference(adev, true, out_device);
2837 }
vivek mehtafe121d52015-08-10 23:39:23 -07002838 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002839 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002840 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002841 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002842 if (audio_extn_usb_is_capture_supported()) {
2843 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2844 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2845 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2846 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2847 } else {
2848 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2849 }
2850 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002851 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002852 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2853 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2854 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2855 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2856 }
2857 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2858 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002859 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2860 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2861 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002862 if (adev->active_input->enable_aec)
2863 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2864 else
2865 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002866 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2867 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002868 if (adev->active_input->enable_aec)
2869 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2870 else
2871 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002872 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2873 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2874 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002875 if (adev->active_input->enable_aec)
2876 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2877 else
2878 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002879 }
2880 platform_set_echo_reference(adev, true, out_device);
2881 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2882 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2883 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002884 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002885 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2886 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002887 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002888 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2889 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002890 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002891 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002892 if (adev->active_input->enable_aec) {
2893 if (adev->active_input->enable_ns) {
2894 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2895 } else {
2896 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2897 }
vivek mehta733c1df2016-04-04 15:09:24 -07002898 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002899 } else if (adev->active_input->enable_ns) {
2900 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2901 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002902 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002903 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002904 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002905 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2906 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002907 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002908 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002909 }
rago90fb9612015-12-02 11:37:53 -08002910 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2911 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002912 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2913 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2914 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2915 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002916 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002917 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2918 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002919 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002920 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2921 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2922 } else {
2923 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2924 }
rago90fb9612015-12-02 11:37:53 -08002925 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2926 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002927 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002928 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002929 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002930 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002931 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002932 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2933 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2934 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2935 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002936 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002937 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002938 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002939 if (adev->active_input->enable_aec &&
2940 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002941 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002942 if (my_data->fluence_in_spkr_mode &&
2943 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002944 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002945 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002946 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002947 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002948 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002949 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002950 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002951 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002952 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002953 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002954 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002955 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002956 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2957 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
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_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002960 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002961 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002962 } else if (adev->active_input->enable_aec) {
2963 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2964 if (my_data->fluence_in_spkr_mode &&
2965 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002966 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002967 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002968 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002969 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002970 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002971 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2972 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002973 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002974 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002975 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002976 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002977 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002978 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2979 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002980 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002981 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002982 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002983 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002984 } else if (adev->active_input->enable_ns) {
2985 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2986 if (my_data->fluence_in_spkr_mode &&
2987 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002988 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002989 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002990 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002991 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002992 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002993 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2994 if (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_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002997 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002998 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002999 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003000 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003001 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003002 }
3003 } else if (source == AUDIO_SOURCE_DEFAULT) {
3004 goto exit;
3005 }
3006
3007
3008 if (snd_device != SND_DEVICE_NONE) {
3009 goto exit;
3010 }
3011
3012 if (in_device != AUDIO_DEVICE_NONE &&
3013 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3014 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3015 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003016 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003017 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003018 snd_device = SND_DEVICE_IN_QUAD_MIC;
3019 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003020 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003021 snd_device = SND_DEVICE_IN_THREE_MIC;
3022 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3023 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003024 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003025 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3026 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003027 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003028 } else {
3029 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3030 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3031 my_data->source_mic_type, channel_count, channel_mask);
3032 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3033 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003034 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003035 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3036 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003037 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003038 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3039 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003040 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003041 } else {
3042 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3043 " no combination found .. setting to mono", __func__,
3044 my_data->source_mic_type, channel_count);
3045 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3046 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003047 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3048 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3049 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003050 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003051 if (adev->bluetooth_nrec)
3052 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3053 else
3054 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003055 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003056 if (adev->bluetooth_nrec)
3057 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3058 else
3059 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003060 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003061 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3062 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003063 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003064 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003065 } else {
3066 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3067 ALOGW("%s: Using default handset-mic", __func__);
3068 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3069 }
3070 } else {
3071 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3072 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3073 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3074 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003075 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003076 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003077 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003078 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003079 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3080 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003081 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003082 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3083 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003084 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003085 } else {
3086 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3087 " no combination found .. setting to mono", __func__,
3088 my_data->source_mic_type, channel_count);
3089 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3090 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003091 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003092 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003093 if (adev->bluetooth_nrec)
3094 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3095 else
3096 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003097 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003098 if (adev->bluetooth_nrec)
3099 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3100 else
3101 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003102 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003103 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3104 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003105 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003106 if (audio_extn_usb_is_capture_supported())
3107 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3108 else
3109 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003110 } else {
3111 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3112 ALOGW("%s: Using default handset-mic", __func__);
3113 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3114 }
3115 }
3116exit:
3117 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3118 return snd_device;
3119}
3120
3121int platform_set_hdmi_channels(void *platform, int channel_count)
3122{
3123 struct platform_data *my_data = (struct platform_data *)platform;
3124 struct audio_device *adev = my_data->adev;
3125 struct mixer_ctl *ctl;
3126 const char *channel_cnt_str = NULL;
3127 const char *mixer_ctl_name = "HDMI_RX Channels";
3128 switch (channel_count) {
3129 case 8:
3130 channel_cnt_str = "Eight"; break;
3131 case 7:
3132 channel_cnt_str = "Seven"; break;
3133 case 6:
3134 channel_cnt_str = "Six"; break;
3135 case 5:
3136 channel_cnt_str = "Five"; break;
3137 case 4:
3138 channel_cnt_str = "Four"; break;
3139 case 3:
3140 channel_cnt_str = "Three"; break;
3141 default:
3142 channel_cnt_str = "Two"; break;
3143 }
3144 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3145 if (!ctl) {
3146 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3147 __func__, mixer_ctl_name);
3148 return -EINVAL;
3149 }
3150 ALOGV("HDMI channel count: %s", channel_cnt_str);
3151 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3152 return 0;
3153}
3154
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003155int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003156{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003157 struct platform_data *my_data = (struct platform_data *)platform;
3158 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003159 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3160 char *sad = block;
3161 int num_audio_blocks;
3162 int channel_count;
3163 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003164 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003165
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003166 struct mixer_ctl *ctl;
3167
3168 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3169 if (!ctl) {
3170 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3171 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003172 return 0;
3173 }
3174
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003175 mixer_ctl_update(ctl);
3176
3177 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003178
3179 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003180 if (count > (int)sizeof(block))
3181 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003182
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003183 ret = mixer_ctl_get_array(ctl, block, count);
3184 if (ret != 0) {
3185 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3186 return 0;
3187 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003188
3189 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003190 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003191
3192 for (i = 0; i < num_audio_blocks; i++) {
3193 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003194 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3195 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003196 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003197 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003198
3199 channel_count = (sad[0] & 0x7) + 1;
3200 if (channel_count > max_channels)
3201 max_channels = channel_count;
3202
3203 /* Advance to next block */
3204 sad += 3;
3205 }
3206
3207 return max_channels;
3208}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003209
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003210int platform_set_incall_recording_session_id(void *platform,
3211 uint32_t session_id, int rec_mode)
3212{
3213 int ret = 0;
3214 struct platform_data *my_data = (struct platform_data *)platform;
3215 struct audio_device *adev = my_data->adev;
3216 struct mixer_ctl *ctl;
3217 const char *mixer_ctl_name = "Voc VSID";
3218 int num_ctl_values;
3219 int i;
3220
3221 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3222 if (!ctl) {
3223 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3224 __func__, mixer_ctl_name);
3225 ret = -EINVAL;
3226 } else {
3227 num_ctl_values = mixer_ctl_get_num_values(ctl);
3228 for (i = 0; i < num_ctl_values; i++) {
3229 if (mixer_ctl_set_value(ctl, i, session_id)) {
3230 ALOGV("Error: invalid session_id: %x", session_id);
3231 ret = -EINVAL;
3232 break;
3233 }
3234 }
3235 }
3236
3237 if (my_data->csd != NULL) {
3238 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3239 if (ret < 0) {
3240 ALOGE("%s: csd_client_start_record failed, error %d",
3241 __func__, ret);
3242 }
3243 }
3244
3245 return ret;
3246}
3247
3248int platform_stop_incall_recording_usecase(void *platform)
3249{
3250 int ret = 0;
3251 struct platform_data *my_data = (struct platform_data *)platform;
3252
3253 if (my_data->csd != NULL) {
3254 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3255 if (ret < 0) {
3256 ALOGE("%s: csd_client_stop_record failed, error %d",
3257 __func__, ret);
3258 }
3259 }
3260
3261 return ret;
3262}
3263
3264int platform_start_incall_music_usecase(void *platform)
3265{
3266 int ret = 0;
3267 struct platform_data *my_data = (struct platform_data *)platform;
3268
3269 if (my_data->csd != NULL) {
3270 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3271 if (ret < 0) {
3272 ALOGE("%s: csd_client_start_playback failed, error %d",
3273 __func__, ret);
3274 }
3275 }
3276
3277 return ret;
3278}
3279
3280int platform_stop_incall_music_usecase(void *platform)
3281{
3282 int ret = 0;
3283 struct platform_data *my_data = (struct platform_data *)platform;
3284
3285 if (my_data->csd != NULL) {
3286 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3287 if (ret < 0) {
3288 ALOGE("%s: csd_client_stop_playback failed, error %d",
3289 __func__, ret);
3290 }
3291 }
3292
3293 return ret;
3294}
3295
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003296int platform_set_parameters(void *platform, struct str_parms *parms)
3297{
3298 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003299 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003300 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003301 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003302 int ret = 0, err;
3303
3304 if (kv_pairs == NULL) {
3305 ret = -EINVAL;
3306 ALOGE("%s: key-value pair is NULL",__func__);
3307 goto done;
3308 }
3309
3310 ALOGV("%s: enter: %s", __func__, kv_pairs);
3311
jasmine chac89321b2018-04-10 21:37:01 +08003312 len = strlen(kv_pairs);
3313 value = (char*)calloc(len+1, sizeof(char));
3314 if (value == NULL) {
3315 ret = -ENOMEM;
3316 ALOGE("[%s] failed to allocate memory",__func__);
3317 goto done;
3318 }
3319
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003320 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003321 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003322 if (err >= 0) {
3323 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3324 my_data->snd_card_name = strdup(value);
3325 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3326 }
3327
keunhui.park2f7306a2015-07-16 16:48:06 +09003328 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003329 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003330 if (err >= 0) {
3331 struct operator_info *info;
3332 char *str = value;
3333 char *name;
3334
3335 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3336 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3337 name = strtok(str, ";");
3338 info->name = strdup(name);
3339 info->mccmnc = strdup(str + strlen(name) + 1);
3340
3341 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003342 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003343 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003344
3345 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07003346 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003347 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003348 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003349 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003350 my_data->max_mic_count = atoi(value);
3351 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003352 }
3353
jasmine chac89321b2018-04-10 21:37:01 +08003354 /* handle audio calibration parameters */
3355 set_audiocal(platform, parms, value, len);
3356
vivek mehta90933872017-06-15 18:04:39 -07003357 // to-do: disable setting sidetone gain, will revist this later
3358 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003359done:
3360 ALOGV("%s: exit with code(%d)", __func__, ret);
3361 if (kv_pairs != NULL)
3362 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003363 if (value != NULL)
3364 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003365
3366 return ret;
3367}
3368
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003369/* Delay in Us */
3370int64_t platform_render_latency(audio_usecase_t usecase)
3371{
3372 switch (usecase) {
3373 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3374 return DEEP_BUFFER_PLATFORM_DELAY;
3375 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3376 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003377 case USECASE_AUDIO_PLAYBACK_ULL:
3378 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003379 case USECASE_AUDIO_PLAYBACK_MMAP:
3380 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003381 default:
3382 return 0;
3383 }
3384}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003385
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003386int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3387 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003388{
3389 int ret = 0;
3390
3391 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3392 ALOGE("%s: Invalid snd_device = %d",
3393 __func__, device);
3394 ret = -EINVAL;
3395 goto done;
3396 }
3397
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003398 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3399 platform_get_snd_device_name(device),
3400 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3401 if (backend_tag_table[device]) {
3402 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003403 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003404 backend_tag_table[device] = strdup(backend_tag);
3405
3406 if (hw_interface != NULL) {
3407 if (hw_interface_table[device])
3408 free(hw_interface_table[device]);
3409 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3410 hw_interface_table[device] = strdup(hw_interface);
3411 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003412done:
3413 return ret;
3414}
3415
3416int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3417{
3418 int ret = 0;
3419 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3420 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3421 ret = -EINVAL;
3422 goto done;
3423 }
3424
3425 if ((type != 0) && (type != 1)) {
3426 ALOGE("%s: invalid usecase type", __func__);
3427 ret = -EINVAL;
3428 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003429 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3430 use_case_table[usecase],
3431 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003432 pcm_device_table[usecase][type] = pcm_id;
3433done:
3434 return ret;
3435}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003436
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003437#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3438int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3439 // backup_gain: gain to try to set in case of an error during ramp
3440 int start_gain, end_gain, step, backup_gain, i;
3441 bool error = false;
3442 const struct mixer_ctl *ctl;
3443 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3444 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3445 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3446 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3447 if (!ctl_left || !ctl_right) {
3448 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3449 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3450 return -EINVAL;
3451 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3452 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3453 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3454 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3455 return -EINVAL;
3456 }
3457 if (ramp_up) {
3458 start_gain = 0;
3459 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3460 step = +1;
3461 backup_gain = end_gain;
3462 } else {
3463 // using same gain on left and right
3464 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3465 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3466 end_gain = 0;
3467 step = -1;
3468 backup_gain = start_gain;
3469 }
3470 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3471 //ALOGV("setting speaker gain to %d", i);
3472 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3473 ALOGE("%s: error setting %s to %d during gain ramp",
3474 __func__, mixer_ctl_name_gain_left, i);
3475 error = true;
3476 break;
3477 }
3478 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3479 ALOGE("%s: error setting %s to %d during gain ramp",
3480 __func__, mixer_ctl_name_gain_right, i);
3481 error = true;
3482 break;
3483 }
3484 usleep(1000);
3485 }
3486 if (error) {
3487 // an error occured during the ramp, let's still try to go back to a safe volume
3488 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3489 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3490 }
3491 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3492 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3493 }
3494 }
3495 return start_gain;
3496}
3497
vivek mehtae59cfb22017-06-16 15:57:11 -07003498int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3499{
3500 const char *mixer_ctl_name = "Swap channel";
3501 struct mixer_ctl *ctl;
3502 const char *mixer_path;
3503 struct platform_data *my_data = (struct platform_data *)adev->platform;
3504
3505 // forced to set to swap, but device not rotated ... ignore set
3506 if (swap_channels && !my_data->speaker_lr_swap)
3507 return 0;
3508
3509 ALOGV("%s:", __func__);
3510
3511 if (swap_channels) {
3512 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3513 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3514 } else {
3515 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3516 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3517 }
3518
3519 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3520 if (!ctl) {
3521 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3522 return -EINVAL;
3523 }
3524
3525 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3526 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3527 return -EINVAL;
3528 }
3529
3530 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3531 swap_channels?"R --> L":"L --> R");
3532
3533 return 0;
3534}
3535
3536int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003537{
3538 // only update if there is active pcm playback on speaker
3539 struct audio_usecase *usecase;
3540 struct listnode *node;
3541 struct platform_data *my_data = (struct platform_data *)adev->platform;
3542
vivek mehtae59cfb22017-06-16 15:57:11 -07003543 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003544
vivek mehtae59cfb22017-06-16 15:57:11 -07003545 return platform_set_swap_channels(adev, swap_channels);
3546}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003547
vivek mehtae59cfb22017-06-16 15:57:11 -07003548int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3549{
3550 // only update if there is active pcm playback on speaker
3551 struct audio_usecase *usecase;
3552 struct listnode *node;
3553 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003554
vivek mehtae59cfb22017-06-16 15:57:11 -07003555 // do not swap channels in audio modes with concurrent capture and playback
3556 // as this may break the echo reference
3557 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3558 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3559 return 0;
3560 }
3561
3562 list_for_each(node, &adev->usecase_list) {
3563 usecase = node_to_item(node, struct audio_usecase, list);
3564 if (usecase->type == PCM_PLAYBACK &&
3565 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3566 /*
3567 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3568 * to perform device switch to disable the current backend to
3569 * enable it with new acdb data.
3570 */
3571 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3572 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3573 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3574 select_devices(adev, usecase->id);
3575 if (initial_skpr_gain != -EINVAL)
3576 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3577
3578 } else {
3579 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003580 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003581 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003582 }
3583 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003584
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003585 return 0;
3586}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003587
3588static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3589static int num_gain_tbl_entry = 0;
3590
3591bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3592
3593 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3594 if (num_gain_tbl_entry == -1) {
3595 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3596 __func__);
3597 return false;
3598 }
3599
3600 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3601 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3602 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3603 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3604 return false;
3605 }
3606
3607 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3608 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3609 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3610 return false;
3611 }
3612
3613 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3614 ++num_gain_tbl_entry;
3615
3616 return true;
3617}
3618
3619int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3620 int table_size) {
3621 int itt = 0;
3622 ALOGV("platform_get_gain_level_mapping called ");
3623
3624 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3625 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3626 return 0;
3627 }
3628
3629 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3630 mapping_tbl[itt] = tbl_mapping[itt];
3631 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3632 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3633 }
3634
3635 return num_gain_tbl_entry;
3636}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003637
3638int platform_snd_card_update(void *platform, card_status_t status)
3639{
3640 struct platform_data *my_data = (struct platform_data *)platform;
3641 struct audio_device *adev = my_data->adev;
3642
3643 if (status == CARD_STATUS_ONLINE) {
3644 if (my_data->acdb_send_custom_top)
3645 my_data->acdb_send_custom_top();
3646 }
3647 return 0;
3648}
David Linee3fe402017-03-13 10:00:42 -07003649
3650/*
3651 * configures afe with bit width and Sample Rate
3652 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003653int platform_set_backend_cfg(const struct audio_device* adev,
3654 snd_device_t snd_device,
3655 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003656{
3657
3658 int ret = 0;
3659 const int backend_idx = platform_get_backend_index(snd_device);
3660 struct platform_data *my_data = (struct platform_data *)adev->platform;
3661 const unsigned int bit_width = backend_cfg->bit_width;
3662 const unsigned int sample_rate = backend_cfg->sample_rate;
3663 const unsigned int channels = backend_cfg->channels;
3664 const audio_format_t format = backend_cfg->format;
3665 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3666
3667
3668 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3669 ", backend_idx %d device (%s)", __func__, bit_width,
3670 sample_rate, channels, backend_idx,
3671 platform_get_snd_device_name(snd_device));
3672
3673 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3674 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3675
3676 struct mixer_ctl *ctl = NULL;
3677 ctl = mixer_get_ctl_by_name(adev->mixer,
3678 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3679 if (!ctl) {
3680 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3681 __func__,
3682 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3683 return -EINVAL;
3684 }
3685
3686 if (bit_width == 24) {
3687 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3688 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3689 else
3690 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3691 } else if (bit_width == 32) {
3692 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3693 } else {
3694 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3695 }
3696 if ( ret < 0) {
3697 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3698 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3699 } else {
3700 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3701 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3702 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3703 }
3704 /* set the ret as 0 and not pass back to upper layer */
3705 ret = 0;
3706 }
3707
3708 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3709 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3710 char *rate_str = NULL;
3711 struct mixer_ctl *ctl = NULL;
3712
3713 switch (sample_rate) {
3714 case 32000:
3715 if (passthrough_enabled) {
3716 rate_str = "KHZ_32";
3717 break;
3718 }
3719 case 8000:
3720 case 11025:
3721 case 16000:
3722 case 22050:
3723 case 48000:
3724 rate_str = "KHZ_48";
3725 break;
3726 case 44100:
3727 rate_str = "KHZ_44P1";
3728 break;
3729 case 64000:
3730 case 96000:
3731 rate_str = "KHZ_96";
3732 break;
3733 case 88200:
3734 rate_str = "KHZ_88P2";
3735 break;
3736 case 176400:
3737 rate_str = "KHZ_176P4";
3738 break;
3739 case 192000:
3740 rate_str = "KHZ_192";
3741 break;
3742 case 352800:
3743 rate_str = "KHZ_352P8";
3744 break;
3745 case 384000:
3746 rate_str = "KHZ_384";
3747 break;
3748 case 144000:
3749 if (passthrough_enabled) {
3750 rate_str = "KHZ_144";
3751 break;
3752 }
3753 default:
3754 rate_str = "KHZ_48";
3755 break;
3756 }
3757
3758 ctl = mixer_get_ctl_by_name(adev->mixer,
3759 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3760 if(!ctl) {
3761 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3762 __func__,
3763 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3764 return -EINVAL;
3765 }
3766
3767 ALOGD("%s:becf: afe: %s set to %s", __func__,
3768 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3769 mixer_ctl_set_enum_by_string(ctl, rate_str);
3770 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3771 }
3772 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3773 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3774 struct mixer_ctl *ctl = NULL;
3775 char *channel_cnt_str = NULL;
3776
3777 switch (channels) {
3778 case 8:
3779 channel_cnt_str = "Eight"; break;
3780 case 7:
3781 channel_cnt_str = "Seven"; break;
3782 case 6:
3783 channel_cnt_str = "Six"; break;
3784 case 5:
3785 channel_cnt_str = "Five"; break;
3786 case 4:
3787 channel_cnt_str = "Four"; break;
3788 case 3:
3789 channel_cnt_str = "Three"; break;
3790 case 1:
3791 channel_cnt_str = "One"; break;
3792 case 2:
3793 default:
3794 channel_cnt_str = "Two"; break;
3795 }
3796
3797 ctl = mixer_get_ctl_by_name(adev->mixer,
3798 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3799 if (!ctl) {
3800 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3801 __func__,
3802 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3803 return -EINVAL;
3804 }
3805 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3806 my_data->current_backend_cfg[backend_idx].channels = channels;
3807
3808 // skip EDID configuration for HDMI backend
3809
3810 ALOGD("%s:becf: afe: %s set to %s", __func__,
3811 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3812 channel_cnt_str);
3813 }
3814
3815 // skip set ext_display format mixer control
3816 return ret;
3817}
3818
3819static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3820{
3821 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3822 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3823 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3824 }
3825
3826 return backend_bit_width_table[snd_device];
3827}
3828
3829/*
3830 * return backend_idx on which voice call is active
3831 */
3832static int platform_get_voice_call_backend(struct audio_device* adev)
3833{
3834 struct audio_usecase *uc = NULL;
3835 struct listnode *node;
3836 snd_device_t out_snd_device = SND_DEVICE_NONE;
3837
3838 int backend_idx = -1;
3839
3840 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3841 list_for_each(node, &adev->usecase_list) {
3842 uc = node_to_item(node, struct audio_usecase, list);
3843 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3844 out_snd_device = platform_get_output_snd_device(adev->platform,
3845 uc->stream.out->devices);
3846 backend_idx = platform_get_backend_index(out_snd_device);
3847 break;
3848 }
3849 }
3850 }
3851 return backend_idx;
3852}
3853
3854/*
3855 * goes through all the current usecases and picks the highest
3856 * bitwidth & samplerate
3857 */
3858static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3859 int backend_idx,
3860 struct audio_backend_cfg *backend_cfg)
3861{
3862 bool backend_change = false;
3863 unsigned int bit_width;
3864 unsigned int sample_rate;
3865 unsigned int channels;
3866 struct platform_data *my_data = (struct platform_data *)adev->platform;
3867
3868 bit_width = backend_cfg->bit_width;
3869 sample_rate = backend_cfg->sample_rate;
3870 channels = backend_cfg->channels;
3871
3872 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3873 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3874 sample_rate, channels);
3875
3876 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3877 // default backend
3878 // force routing is not required here, caller will do it anyway
3879 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3880 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3881 "for unprocessed/camera source", __func__);
3882 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3883 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3884 }
3885
3886 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3887 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3888 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3889 __func__, bit_width, sample_rate, channels);
3890 }
3891
3892 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3893 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3894
3895 // Force routing if the expected bitwdith or samplerate
3896 // is not same as current backend comfiguration
3897 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3898 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3899 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3900 backend_cfg->bit_width = bit_width;
3901 backend_cfg->sample_rate= sample_rate;
3902 backend_cfg->channels = channels;
3903 backend_change = true;
3904 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3905 "new sample rate: %d new channel: %d",
3906 __func__, backend_cfg->bit_width,
3907 backend_cfg->sample_rate, backend_cfg->channels);
3908 }
3909
3910 return backend_change;
3911}
3912
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003913static void pick_playback_cfg_for_uc(struct audio_device *adev,
3914 struct audio_usecase *usecase,
3915 snd_device_t snd_device,
3916 unsigned int *bit_width,
3917 unsigned int *sample_rate,
3918 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003919{
3920 int i =0;
3921 struct listnode *node;
3922 list_for_each(node, &adev->usecase_list) {
3923 struct audio_usecase *uc;
3924 uc = node_to_item(node, struct audio_usecase, list);
3925 struct stream_out *out = (struct stream_out*) uc->stream.out;
3926 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3927 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3928 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3929 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3930 uc->id, out->sample_rate,
3931 pcm_format_to_bits(out->config.format), out_channels,
3932 platform_get_snd_device_name(uc->out_snd_device));
3933
3934 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3935 if (*bit_width < pcm_format_to_bits(out->config.format))
3936 *bit_width = pcm_format_to_bits(out->config.format);
3937 if (*sample_rate < out->sample_rate)
3938 *sample_rate = out->sample_rate;
3939 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3940 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3941 if (*channels < out_channels)
3942 *channels = out_channels;
3943 }
3944 }
3945 }
3946 return;
3947}
3948
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003949static void headset_is_config_supported(unsigned int *bit_width,
3950 unsigned int *sample_rate,
3951 unsigned int *channels) {
3952 switch (*bit_width) {
3953 case 16:
3954 case 24:
3955 break;
3956 default:
3957 *bit_width = 16;
3958 break;
3959 }
3960
3961 if (*sample_rate > 192000) {
3962 *sample_rate = 192000;
3963 }
3964
3965 if (*channels > 2) {
3966 *channels = 2;
3967 }
3968}
3969
David Linee3fe402017-03-13 10:00:42 -07003970static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3971 struct audio_usecase* usecase,
3972 snd_device_t snd_device,
3973 struct audio_backend_cfg *backend_cfg)
3974{
3975 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003976 unsigned int bit_width;
3977 unsigned int sample_rate;
3978 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003979 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003980 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07003981 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003982
3983 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3984 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3985 backend_change = false;
3986 return backend_change;
3987 }
3988
3989 backend_idx = platform_get_backend_index(snd_device);
3990 bit_width = backend_cfg->bit_width;
3991 sample_rate = backend_cfg->sample_rate;
3992 channels = backend_cfg->channels;
3993
3994 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3995 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3996 sample_rate, channels, backend_idx, usecase->id,
3997 platform_get_snd_device_name(snd_device));
3998
3999 if (backend_idx == platform_get_voice_call_backend(adev)) {
4000 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4001 __func__);
4002 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4003 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4004 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4005 } else {
4006 /*
4007 * The backend should be configured at highest bit width and/or
4008 * sample rate amongst all playback usecases.
4009 * If the selected sample rate and/or bit width differ with
4010 * current backend sample rate and/or bit width, then, we set the
4011 * backend re-configuration flag.
4012 *
4013 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4014 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004015 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4016 &bit_width,
4017 &sample_rate,
4018 &channels);
David Linee3fe402017-03-13 10:00:42 -07004019 }
4020
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004021 switch (backend_idx) {
4022 case USB_AUDIO_RX_BACKEND:
4023 audio_extn_usb_is_config_supported(&bit_width,
4024 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004025 if (platform_get_usb_service_interval(adev->platform, true,
4026 &service_interval) == 0) {
4027 /* overwrite with best altset for this service interval */
4028 int ret =
4029 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4030 service_interval,
4031 &bit_width,
4032 &sample_rate,
4033 &channels);
4034 if (ret < 0) {
4035 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4036 service_interval);
4037 return false;
4038 }
4039 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004040 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4041 __func__, bit_width, sample_rate, channels);
4042 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004043 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004044 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4045 break;
4046 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004047 default:
4048 bit_width = platform_get_snd_device_bit_width(snd_device);
4049 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4050 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4051 break;
David Linee3fe402017-03-13 10:00:42 -07004052 }
4053
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004054 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4055 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004056 __func__, backend_idx , bit_width, sample_rate);
4057
4058 // Force routing if the expected bitwdith or samplerate
4059 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004060 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4061 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4062 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004063 backend_cfg->bit_width = bit_width;
4064 backend_cfg->sample_rate = sample_rate;
4065 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004066 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004067 backend_change = true;
4068 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4069 "new sample rate: %d new channels: %d",
4070 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4071 }
4072
4073 return backend_change;
4074}
4075
4076bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4077 struct audio_usecase *usecase, snd_device_t snd_device)
4078{
4079 int backend_idx = DEFAULT_CODEC_BACKEND;
4080 int new_snd_devices[SND_DEVICE_OUT_END];
4081 int i, num_devices = 1;
4082 bool ret = false;
4083 struct platform_data *my_data = (struct platform_data *)adev->platform;
4084 struct audio_backend_cfg backend_cfg;
4085
4086 backend_idx = platform_get_backend_index(snd_device);
4087
4088 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4089 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4090 backend_cfg.format = usecase->stream.out->format;
4091 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4092 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4093 backend_cfg.passthrough_enabled = false;
4094
4095 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4096 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4097 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4098 platform_get_snd_device_name(snd_device));
4099
4100 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4101 new_snd_devices[0] = snd_device;
4102
4103 for (i = 0; i < num_devices; i++) {
4104 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4105 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4106 &backend_cfg))) {
4107 platform_set_backend_cfg(adev, new_snd_devices[i],
4108 &backend_cfg);
4109 ret = true;
4110 }
4111 }
4112 return ret;
4113}
4114
4115bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4116 struct audio_usecase *usecase, snd_device_t snd_device)
4117{
4118 int backend_idx = platform_get_backend_index(snd_device);
4119 int ret = 0;
4120 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004121 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004122
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004123 if (usecase->type == PCM_CAPTURE) {
4124 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004125 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4126 } else {
4127 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4128 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4129 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4130 backend_cfg.channels = 1;
4131 }
4132
4133 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4134 ", backend_idx %d usecase = %d device (%s)", __func__,
4135 backend_cfg.bit_width,
4136 backend_cfg.sample_rate,
4137 backend_cfg.channels,
4138 backend_idx, usecase->id,
4139 platform_get_snd_device_name(snd_device));
4140
4141 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4142 ret = platform_set_backend_cfg(adev, snd_device,
4143 &backend_cfg);
4144 if(!ret)
4145 return true;
4146 }
4147
4148 return false;
4149}
4150
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004151static int max_be_dai_names = 0;
4152static const struct be_dai_name_struct *be_dai_name_table;
4153
4154/*
4155 * Retrieves the be_dai_name_table from kernel to enable a mapping
4156 * between sound device hw interfaces and backend IDs. This allows HAL to
4157 * specify the backend a specific calibration is needed for.
4158 */
4159static int init_be_dai_name_table(struct audio_device *adev)
4160{
4161 const char *mixer_ctl_name = "Backend DAI Name Table";
4162 struct mixer_ctl *ctl;
4163 int i, j, ret, size;
4164 bool valid_hw_interface;
4165
4166 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4167 if (!ctl) {
4168 ALOGE("%s: Could not get ctl for mixer name %s\n",
4169 __func__, mixer_ctl_name);
4170 ret = -EINVAL;
4171 goto done;
4172 }
4173
4174 mixer_ctl_update(ctl);
4175
4176 size = mixer_ctl_get_num_values(ctl);
4177 if (size <= 0){
4178 ALOGE("%s: Failed to get %s size %d\n",
4179 __func__, mixer_ctl_name, size);
4180 ret = -EFAULT;
4181 goto done;
4182 }
4183
vivek mehtaa68fea62017-06-08 19:04:02 -07004184 be_dai_name_table =
4185 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004186 if (be_dai_name_table == NULL) {
4187 ALOGE("%s: Failed to allocate memory for %s\n",
4188 __func__, mixer_ctl_name);
4189 ret = -ENOMEM;
4190 goto freeMem;
4191 }
4192
4193 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4194 if (ret) {
4195 ALOGE("%s: Failed to get %s, ret %d\n",
4196 __func__, mixer_ctl_name, ret);
4197 ret = -EFAULT;
4198 goto freeMem;
4199 }
4200
4201 if (be_dai_name_table != NULL) {
4202 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4203 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4204 __func__, mixer_ctl_name, max_be_dai_names);
4205 ret = 0;
4206 } else {
4207 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4208 ret = -EFAULT;
4209 goto freeMem;
4210 }
4211
4212 /*
4213 * Validate all sound devices have a valid backend set to catch
4214 * errors for uncommon sound devices
4215 */
4216 for (i = 0; i < SND_DEVICE_MAX; i++) {
4217 valid_hw_interface = false;
4218
4219 if (hw_interface_table[i] == NULL) {
4220 ALOGW("%s: sound device %s has no hw interface set\n",
4221 __func__, platform_get_snd_device_name(i));
4222 continue;
4223 }
4224
4225 for (j = 0; j < max_be_dai_names; j++) {
4226 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4227 == 0) {
4228 valid_hw_interface = true;
4229 break;
4230 }
4231 }
4232 if (!valid_hw_interface)
4233 ALOGD("%s: sound device %s does not have a valid hw interface set "
4234 "(disregard for combo devices) %s\n",
4235 __func__, platform_get_snd_device_name(i),
4236 hw_interface_table[i]);
4237 }
4238
4239 goto done;
4240
4241freeMem:
4242 if (be_dai_name_table) {
4243 free((void *)be_dai_name_table);
4244 be_dai_name_table = NULL;
4245 }
4246
4247done:
4248 return ret;
4249}
4250
4251int platform_get_snd_device_backend_index(snd_device_t device)
4252{
4253 int i, be_dai_id;
4254 const char * hw_interface_name = NULL;
4255
4256 ALOGV("%s: enter with device %d\n", __func__, device);
4257
vivek mehtaa68fea62017-06-08 19:04:02 -07004258 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004259 ALOGE("%s: Invalid snd_device = %d",
4260 __func__, device);
4261 be_dai_id = -EINVAL;
4262 goto done;
4263 }
4264
4265 /* Get string value of necessary backend for device */
4266 hw_interface_name = hw_interface_table[device];
4267 if (hw_interface_name == NULL) {
4268 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4269 be_dai_id = -EINVAL;
4270 goto done;
4271 }
4272
4273 /* Check if be dai name table was retrieved successfully */
4274 if (be_dai_name_table == NULL) {
4275 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4276 be_dai_id = -EFAULT;
4277 goto done;
4278 }
4279
4280 /* Get backend ID for device specified */
4281 for (i = 0; i < max_be_dai_names; i++) {
4282 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4283 be_dai_id = be_dai_name_table[i].be_id;
4284 goto done;
4285 }
4286 }
4287 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4288 be_dai_id = -EINVAL;
4289 goto done;
4290
4291done:
4292 return be_dai_id;
4293}
4294
4295void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4296 unsigned int stream_sr, int* sample_rate)
4297{
4298 struct platform_data* my_data = (struct platform_data *)platform;
4299 int backend_idx = platform_get_backend_index(snd_device);
4300 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4301 /*
4302 *Check if device SR is multiple of 8K or 11.025 Khz
4303 *check if the stream SR is multiple of same base, if yes
4304 *then have copp SR equal to stream SR, this ensures that
4305 *post processing happens at stream SR, else have
4306 *copp SR equal to device SR.
4307 */
4308 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4309 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4310 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4311 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4312 *sample_rate = device_sr;
4313 } else
4314 *sample_rate = stream_sr;
4315
4316 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4317 , *sample_rate);
4318
4319}
4320
4321// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004322void platform_add_app_type(const char *uc_type,
4323 const char *mode,
4324 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004325 int app_type, int max_rate) {
4326 struct app_type_entry *ap =
4327 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4328
4329 if (!ap) {
4330 ALOGE("%s failed to allocate mem for app type", __func__);
4331 return;
4332 }
4333
4334 ap->uc_type = -1;
4335 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4336 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4337 ap->uc_type = usecase_type_index[i].index;
4338 break;
4339 }
4340 }
4341
4342 if (ap->uc_type == -1) {
4343 free(ap);
4344 return;
4345 }
4346
vivek mehtaa68fea62017-06-08 19:04:02 -07004347 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4348 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004349 ap->bit_width = bw;
4350 ap->app_type = app_type;
4351 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004352 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004353 list_add_tail(&app_type_entry_list, &ap->node);
4354}
4355
4356
4357int platform_get_default_app_type_v2(void *platform __unused,
4358 usecase_type_t type,
4359 int *app_type )
4360{
4361 if (type == PCM_PLAYBACK)
4362 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4363 else
4364 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4365 return 0;
4366}
4367
vivek mehtaa68fea62017-06-08 19:04:02 -07004368int platform_get_app_type_v2(void *platform,
4369 usecase_type_t uc_type,
4370 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004371 int bw, int sr __unused,
4372 int *app_type)
4373{
4374 struct listnode *node;
4375 struct app_type_entry *entry;
4376 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004377
4378 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4379 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004380 list_for_each(node, &app_type_entry_list) {
4381 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004382 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4383 __func__, entry->uc_type, entry->mode, entry->bit_width,
4384 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004385 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004386 entry->uc_type == uc_type &&
4387 sr <= entry->max_rate &&
4388 entry->mode && !strcmp(mode, entry->mode)) {
4389 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004390 *app_type = entry->app_type;
4391 break;
4392 }
4393 }
4394
4395 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004396 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004397 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4398 }
4399 return 0;
4400}
vivek mehta90933872017-06-15 18:04:39 -07004401
4402int platform_set_sidetone(struct audio_device *adev,
4403 snd_device_t out_snd_device,
4404 bool enable, char *str)
4405{
4406 int ret;
4407 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4408 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4409 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4410 if (ret)
4411 ALOGI("%s: usb device %d does not support device sidetone\n",
4412 __func__, out_snd_device);
4413 } else {
4414 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4415 __func__, out_snd_device, str);
4416 if (enable)
4417 audio_route_apply_and_update_path(adev->audio_route, str);
4418 else
4419 audio_route_reset_and_update_path(adev->audio_route, str);
4420 }
4421 return 0;
4422}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004423
4424int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4425 int *fd __unused, uint32_t *size __unused)
4426{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004427#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004428 struct platform_data *my_data = (struct platform_data *)platform;
4429 struct audio_device *adev = my_data->adev;
4430 int hw_fd = -1;
4431 char dev_name[128];
4432 struct snd_pcm_mmap_fd mmap_fd;
4433 memset(&mmap_fd, 0, sizeof(mmap_fd));
4434 mmap_fd.dir = dir;
4435 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4436 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4437 hw_fd = open(dev_name, O_RDONLY);
4438 if (hw_fd < 0) {
4439 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4440 return -1;
4441 }
4442 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4443 ALOGE("fe hw dep node ioctl failed");
4444 close(hw_fd);
4445 return -1;
4446 }
4447 *fd = mmap_fd.fd;
4448 *size = mmap_fd.size;
4449 close(hw_fd); // mmap_fd should still be valid
4450 return 0;
4451#else
4452 return -1;
4453#endif
4454}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004455
4456bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4457{
4458 bool needs_event = false;
4459
4460 switch (uc_id) {
4461 /* concurrent capture usecases which needs event */
4462 case USECASE_AUDIO_RECORD:
4463 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4464 case USECASE_AUDIO_RECORD_MMAP:
4465 case USECASE_AUDIO_RECORD_HIFI:
4466 case USECASE_AUDIO_RECORD_VOIP:
4467 case USECASE_VOICEMMODE1_CALL:
4468 case USECASE_VOICEMMODE2_CALL:
4469 /* concurrent playback usecases that needs event */
4470 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4471 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4472 needs_event = true;
4473 break;
4474 default:
4475 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4476 }
4477 return needs_event;
4478}
4479
4480bool platform_snd_device_has_speaker(snd_device_t dev) {
4481 int num_devs = 2;
4482 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4483 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4484 return platform_snd_device_has_speaker(split_devs[0]) ||
4485 platform_snd_device_has_speaker(split_devs[1]);
4486 }
4487
4488 switch (dev) {
4489 case SND_DEVICE_OUT_SPEAKER:
4490 case SND_DEVICE_OUT_SPEAKER_SAFE:
4491 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4492 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4493 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4494 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4495 return true;
4496 default:
4497 break;
4498 }
4499 return false;
4500}
jiabin8962a4d2018-03-19 18:21:24 -07004501
4502bool platform_set_microphone_characteristic(void *platform,
4503 struct audio_microphone_characteristic_t mic) {
4504 struct platform_data *my_data = (struct platform_data *)platform;
4505 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4506 ALOGE("mic number is more than maximum number");
4507 return false;
4508 }
4509 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4510 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4511 }
4512 my_data->microphones[my_data->declared_mic_count++] = mic;
4513 return true;
4514}
4515
4516int platform_get_microphones(void *platform,
4517 struct audio_microphone_characteristic_t *mic_array,
4518 size_t *mic_count) {
4519 struct platform_data *my_data = (struct platform_data *)platform;
4520 if (mic_count == NULL) {
4521 return -EINVAL;
4522 }
4523 if (mic_array == NULL) {
4524 return -EINVAL;
4525 }
4526
4527 if (*mic_count == 0) {
4528 *mic_count = my_data->declared_mic_count;
4529 return 0;
4530 }
4531
4532 size_t max_mic_count = *mic_count;
4533 size_t actual_mic_count = 0;
4534 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4535 mic_array[i] = my_data->microphones[i];
4536 actual_mic_count++;
4537 }
4538 *mic_count = actual_mic_count;
4539 return 0;
4540}
4541
4542int platform_get_active_microphones(void *platform, audio_devices_t device, unsigned int channels,
4543 int source __unused, audio_usecase_t usecase __unused,
4544 struct audio_microphone_characteristic_t *mic_array,
4545 size_t *mic_count) {
4546 struct platform_data *my_data = (struct platform_data *)platform;
4547 if (mic_count == NULL) {
4548 return -EINVAL;
4549 }
4550 if (mic_array == NULL) {
4551 return -EINVAL;
4552 }
4553
4554 if (*mic_count == 0) {
4555 // TODO: return declared mic count as a preliminary implementation, the final
4556 // implementation will derive mic count and channel mapping from use case, source and device
4557 *mic_count = my_data->declared_mic_count;
4558 return 0;
4559 }
4560
4561 size_t max_mic_count = *mic_count;
4562 size_t actual_mic_count = 0;
4563 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4564 // TODO: get actual microphone and channel mapping type.
4565 if ((my_data->microphones[i].device & device) == device) {
4566 mic_array[actual_mic_count] = my_data->microphones[i];
4567 for (size_t ch = 0; ch < channels; ch++) {
4568 mic_array[actual_mic_count].channel_mapping[ch] =
4569 AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT;
4570 }
4571 actual_mic_count++;
4572 }
4573 }
4574 *mic_count = actual_mic_count;
4575 return 0;
4576}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004577
4578int platform_set_usb_service_interval(void *platform,
4579 bool playback,
4580 unsigned long service_interval,
4581 bool *reconfig)
4582{
4583#if defined (USB_SERVICE_INTERVAL_ENABLED)
4584 struct platform_data *_platform = (struct platform_data *)platform;
4585 *reconfig = false;
4586 if (!playback) {
4587 ALOGE("%s not valid for capture", __func__);
4588 return -1;
4589 }
4590 const char *ctl_name = "USB_AUDIO_RX service_interval";
4591 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4592 ctl_name);
4593 if (!ctl) {
4594 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4595 return -1;
4596 }
4597 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4598 mixer_ctl_set_value(ctl, 0, service_interval);
4599 *reconfig = true;
4600 }
4601 return 0;
4602#else
4603 *reconfig = false;
4604 (void)platform;
4605 (void)playback;
4606 (void)service_interval;
4607 return -1;
4608#endif
4609}
4610
4611int platform_get_usb_service_interval(void *platform,
4612 bool playback,
4613 unsigned long *service_interval)
4614{
4615#if defined (USB_SERVICE_INTERVAL_ENABLED)
4616 struct platform_data *_platform = (struct platform_data *)platform;
4617 if (!playback) {
4618 ALOGE("%s not valid for capture", __func__);
4619 return -1;
4620 }
4621 const char *ctl_name = "USB_AUDIO_RX service_interval";
4622 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4623 ctl_name);
4624 if (!ctl) {
4625 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4626 return -1;
4627 }
4628 *service_interval = mixer_ctl_get_value(ctl, 0);
4629 return 0;
4630#else
4631 (void)platform;
4632 (void)playback;
4633 (void)service_interval;
4634 return -1;
4635#endif
4636}