blob: 778eca98cf5b4d272cec9c18d4c4ab2ca47996dd [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
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090037#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
38#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080039#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
40#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
41
Eric Laurentb23d5282013-05-14 15:27:20 -070042#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070043#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090044#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070045
Eric Laurentf9583c32016-03-28 13:50:50 -070046#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070047
48/*
Eric Laurentb23d5282013-05-14 15:27:20 -070049 * This file will have a maximum of 38 bytes:
50 *
51 * 4 bytes: number of audio blocks
52 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
53 * Maximum 10 * 3 bytes: SAD blocks
54 */
55#define MAX_SAD_BLOCKS 10
56#define SAD_BLOCK_SIZE 3
57
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090058#define MAX_CVD_VERSION_STRING_SIZE 100
59
Eric Laurentb23d5282013-05-14 15:27:20 -070060/* EDID format ID for LPCM audio */
61#define EDID_FORMAT_LPCM 1
62
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070063#define MAX_SND_CARD_NAME_LEN 31
64
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080065#define DEFAULT_APP_TYPE_RX_PATH 69936
66#define DEFAULT_APP_TYPE_TX_PATH 69938
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070067#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
vivek mehta1a9b7c02015-06-25 11:49:38 -070068
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090069#define TOSTRING_(x) #x
70#define TOSTRING(x) TOSTRING_(x)
71
Eric Laurentb23d5282013-05-14 15:27:20 -070072struct audio_block_header
73{
74 int reserved;
75 int length;
76};
77
vivek mehta1a9b7c02015-06-25 11:49:38 -070078enum {
79 CAL_MODE_SEND = 0x1,
80 CAL_MODE_PERSIST = 0x2,
81 CAL_MODE_RTAC = 0x4
82};
83
keunhui.park2f7306a2015-07-16 16:48:06 +090084#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
85
86struct operator_info {
87 struct listnode list;
88 char *name;
89 char *mccmnc;
90};
91
92struct operator_specific_device {
93 struct listnode list;
94 char *operator;
95 char *mixer_path;
96 int acdb_id;
97};
98
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080099#define BE_DAI_NAME_MAX_LENGTH 24
100struct be_dai_name_struct {
101 unsigned int be_id;
102 char be_name[BE_DAI_NAME_MAX_LENGTH];
103};
104
keunhui.park2f7306a2015-07-16 16:48:06 +0900105static struct listnode operator_info_list;
106static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
107
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700108/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800109typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700110
Eric Laurentb23d5282013-05-14 15:27:20 -0700111struct platform_data {
112 struct audio_device *adev;
113 bool fluence_in_spkr_mode;
114 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700115 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700116 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700117 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
118 int fluence_type;
119 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700120 bool speaker_lr_swap;
121
Eric Laurentb23d5282013-05-14 15:27:20 -0700122 void *acdb_handle;
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700123#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700124 acdb_init_v2_cvd_t acdb_init;
125#elif defined (PLATFORM_MSM8084)
126 acdb_init_v2_t acdb_init;
127#else
128 acdb_init_t acdb_init;
129#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700130 acdb_deallocate_t acdb_deallocate;
131 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800132 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700133 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700134 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700135 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700136 acdb_send_custom_top_t acdb_send_custom_top;
137 bool acdb_initialized;
138
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700139 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800140 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700141
David Linee3fe402017-03-13 10:00:42 -0700142 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700143 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900144 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700145 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800146
147 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700148};
149
Haynes Mathew George98c95622014-06-20 19:14:25 -0700150static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700151 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
152 DEEP_BUFFER_PCM_DEVICE},
153 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
154 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800155 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700156 MULTIMEDIA2_PCM_DEVICE},
157 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
158 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700159 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
160 MULTIMEDIA2_PCM_DEVICE},
161 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
162 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800163 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
164 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700165
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700166 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
167 AUDIO_RECORD_PCM_DEVICE},
168 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
169 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700170
Eric Laurent0e46adf2016-12-16 12:49:24 -0800171 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
172 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700173 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
174 MULTIMEDIA2_PCM_DEVICE},
175
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700176 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
177 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700178 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
179 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
180 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
181 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800182 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
183 VOICEMMODE1_CALL_PCM_DEVICE},
184 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
185 VOICEMMODE2_CALL_PCM_DEVICE},
186
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700187 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
188 AUDIO_RECORD_PCM_DEVICE},
189 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
190 AUDIO_RECORD_PCM_DEVICE},
191 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
192 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800193 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700194
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700195 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
196 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
197
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700198 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
199 AFE_PROXY_RECORD_PCM_DEVICE},
200 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
201 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800202 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700203
vivek mehtaa68fea62017-06-08 19:04:02 -0700204 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
205 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
206 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
207 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200208
209 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
210 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700211};
212
213/* Array to store sound devices */
214static const char * const device_table[SND_DEVICE_MAX] = {
215 [SND_DEVICE_NONE] = "none",
216 /* Playback sound devices */
217 [SND_DEVICE_OUT_HANDSET] = "handset",
218 [SND_DEVICE_OUT_SPEAKER] = "speaker",
219 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700220 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700221 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500222 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700223 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700224 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500225 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700226 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700227 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500228 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700229 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
230 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500231 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700232 [SND_DEVICE_OUT_HDMI] = "hdmi",
233 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
234 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700235 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800236 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
237 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700238 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
239 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
240 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
241 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800242 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
243 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700244 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700245 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700246 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700247 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700248 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700249 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700250 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700251 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
252 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700253 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800254 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
255 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700256
257 /* Capture sound devices */
258 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700259 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700260 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
261 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
262 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
263 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
264 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
265 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
266 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
267
268 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
269 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
270 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
271 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
272 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
273 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
274 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
275 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
276 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
277
278 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500279 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700280
Eric Laurentb23d5282013-05-14 15:27:20 -0700281 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
282 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700283 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700284 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700285 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700286 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700287
288 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
289 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
290 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
291 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700292 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700293 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700294 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
295 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
296 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800297 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
298 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700299
Eric Laurentb23d5282013-05-14 15:27:20 -0700300 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700301 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700302 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700303 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700304 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
305 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700306 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700307 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
308 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
309 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
310 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700311 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700312
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700313 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700314 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
315 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
316 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
317 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800318
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700319 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700320
Prashant Malanic92c5962015-08-11 15:10:18 -0700321 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
322 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700323 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700324 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
325 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700326 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
327 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700328};
329
330/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700331static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700332 [SND_DEVICE_NONE] = -1,
333 [SND_DEVICE_OUT_HANDSET] = 7,
334 [SND_DEVICE_OUT_SPEAKER] = 15,
335 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700336 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700337 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500338 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700339 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700340 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500341 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700342 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700343 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
344 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500345 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700346 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500347 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700348 [SND_DEVICE_OUT_HDMI] = 18,
349 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
350 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700351 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800352 [SND_DEVICE_OUT_BT_A2DP] = 20,
353 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700354 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700355 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
356 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
357 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800358 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
359 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700360 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700361 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700362 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700363 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700364 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700365 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700366 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700367 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
368 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700369 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700370
371 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700372 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
373 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
374 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
375 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
376 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
377 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
378 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
379 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
380
381 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
382 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
383 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
384 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
385 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
386 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
387 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
388 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
389 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
390
rago90fb9612015-12-02 11:37:53 -0800391 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500392 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700393
Eric Laurentb23d5282013-05-14 15:27:20 -0700394 [SND_DEVICE_IN_HDMI_MIC] = 4,
395 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700396 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700397 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700398 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700399 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700400
401 [SND_DEVICE_IN_VOICE_DMIC] = 41,
402 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
403 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700404 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700405 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800406 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700407 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
408 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
409 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800410 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
411 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700412
rago90fb9612015-12-02 11:37:53 -0800413 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700414 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700415 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700416 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700417 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
418 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800419 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
420
421 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
422 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700423 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
424 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
425 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700426
427 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700428 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700429 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
430 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
431 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
432 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700433 [SND_DEVICE_IN_THREE_MIC] = 46,
434 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700435 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700436 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
437 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700438 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
439 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700440};
441
David Linee3fe402017-03-13 10:00:42 -0700442// Platform specific backend bit width table
443static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
444
Haynes Mathew George98c95622014-06-20 19:14:25 -0700445struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700446 char name[100];
447 unsigned int index;
448};
449
450#define TO_NAME_INDEX(X) #X, X
451
Haynes Mathew George98c95622014-06-20 19:14:25 -0700452/* Used to get index from parsed string */
453static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
454 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700455 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
456 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
457 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700458 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700459 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500460 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700461 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700462 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500463 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700464 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700465 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
466 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700467 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700468 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500469 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700470 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
471 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
472 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
473 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800474 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
475 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700476 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500477 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700478 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
479 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
480 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800481 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
482 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800483 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
484 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700485 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700486 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700487 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700488 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700489 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700490 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700491 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
492 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800493
494 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700495 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700496 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700497 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
498 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
499 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
500 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
501 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
502 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
503 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
504
505 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700506 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700507 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
508 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
509 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
510 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
511 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
512 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
513 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
514
515 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700516 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700517
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700518 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
519 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700520 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700521 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700522 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700523 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700524
525 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
526 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
527 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700528 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700529 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
530 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700531 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
532 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
533 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800534 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
535 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
536
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700537
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700538 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700539 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700540 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700541 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700542 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700544 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700545 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700546 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
547 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
548 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
549 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700550
rago90fb9612015-12-02 11:37:53 -0800551 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
552 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700553 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
554 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
555 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800556
Prashant Malanic92c5962015-08-11 15:10:18 -0700557 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
558 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700559 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700560 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
561 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700562 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
563 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700564};
565
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700566static char * backend_tag_table[SND_DEVICE_MAX] = {0};
567static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700568
569static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
570 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
571 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800572 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700573 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700574 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
575 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800576 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700577 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
578 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800579 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700580 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700581 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
582 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
583 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
584 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
585 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800586 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
587 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700588 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
589 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
590 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
591 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800592 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
593 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
594 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
595 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
596 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700597 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
598 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200599 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700600};
601
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800602static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
603 {TO_NAME_INDEX(PCM_PLAYBACK)},
604 {TO_NAME_INDEX(PCM_CAPTURE)},
605 {TO_NAME_INDEX(VOICE_CALL)},
606 {TO_NAME_INDEX(PCM_HFP_CALL)},
607};
608
609struct app_type_entry {
610 int uc_type;
611 int bit_width;
612 int app_type;
613 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700614 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800615 struct listnode node; // membership in app_type_entry_list;
616};
617
618static struct listnode app_type_entry_list;
619
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700620#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
621#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800622#define ULL_PLATFORM_DELAY (3*1000LL)
623#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700624
Eric Laurentb23d5282013-05-14 15:27:20 -0700625static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
626static bool is_tmus = false;
627
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800628static int init_be_dai_name_table(struct audio_device *adev);
629
Eric Laurentb23d5282013-05-14 15:27:20 -0700630static void check_operator()
631{
632 char value[PROPERTY_VALUE_MAX];
633 int mccmnc;
634 property_get("gsm.sim.operator.numeric",value,"0");
635 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700636 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700637 switch(mccmnc) {
638 /* TMUS MCC(310), MNC(490, 260, 026) */
639 case 310490:
640 case 310260:
641 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900642 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
643 case 310800:
644 case 310660:
645 case 310580:
646 case 310310:
647 case 310270:
648 case 310250:
649 case 310240:
650 case 310230:
651 case 310220:
652 case 310210:
653 case 310200:
654 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700655 is_tmus = true;
656 break;
657 }
658}
659
660bool is_operator_tmus()
661{
662 pthread_once(&check_op_once_ctl, check_operator);
663 return is_tmus;
664}
665
keunhui.park2f7306a2015-07-16 16:48:06 +0900666static char *get_current_operator()
667{
668 struct listnode *node;
669 struct operator_info *info_item;
670 char mccmnc[PROPERTY_VALUE_MAX];
671 char *ret = NULL;
672
Tom Cherry7fea2042016-11-10 18:05:59 -0800673 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900674
675 list_for_each(node, &operator_info_list) {
676 info_item = node_to_item(node, struct operator_info, list);
677 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
678 ret = info_item->name;
679 }
680 }
681
682 return ret;
683}
684
685static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
686{
687 struct listnode *node;
688 struct operator_specific_device *ret = NULL;
689 struct operator_specific_device *device_item;
690 char *operator_name;
691
692 operator_name = get_current_operator();
693 if (operator_name == NULL)
694 return ret;
695
696 list_for_each(node, operator_specific_device_table[snd_device]) {
697 device_item = node_to_item(node, struct operator_specific_device, list);
698 if (strcmp(operator_name, device_item->operator) == 0) {
699 ret = device_item;
700 }
701 }
702
703 return ret;
704}
705
706
707static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
708{
709 struct operator_specific_device *device;
710 int ret = acdb_device_table[snd_device];
711
712 device = get_operator_specific_device(snd_device);
713 if (device != NULL)
714 ret = device->acdb_id;
715
716 return ret;
717}
718
719static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
720{
721 struct operator_specific_device *device;
722 const char *ret = device_table[snd_device];
723
724 device = get_operator_specific_device(snd_device);
725 if (device != NULL)
726 ret = device->mixer_path;
727
728 return ret;
729}
730
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800731inline bool platform_supports_app_type_cfg()
732{
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700733#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800734 return true;
735#else
736 return false;
737#endif
738}
739
vivek mehta1a9b7c02015-06-25 11:49:38 -0700740bool platform_send_gain_dep_cal(void *platform, int level)
741{
742 bool ret_val = false;
743 struct platform_data *my_data = (struct platform_data *)platform;
744 struct audio_device *adev = my_data->adev;
745 int acdb_dev_id, app_type;
746 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
747 int mode = CAL_MODE_RTAC;
748 struct listnode *node;
749 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700750 bool valid_uc_type;
751 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700752
753 if (my_data->acdb_send_gain_dep_cal == NULL) {
754 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
755 return ret_val;
756 }
757
758 if (!voice_is_in_call(adev)) {
759 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
760 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700761
762 // find the current active sound device
763 list_for_each(node, &adev->usecase_list) {
764 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700765 LOG_ALWAYS_FATAL_IF(usecase == NULL,
766 "unxpected NULL usecase in usecase_list");
767 valid_uc_type = usecase->type == PCM_PLAYBACK;
768 valid_dev = false;
769 if (valid_uc_type) {
770 audio_devices_t dev = usecase->stream.out->devices;
771 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700772 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700773 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
774 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
775 }
776 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700777 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
778 if (platform_supports_app_type_cfg())
779 app_type = usecase->stream.out->app_type_cfg.app_type;
780 else
781 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700782
vivek mehta7e573672018-03-13 17:41:41 -0700783 acdb_dev_id =
784 acdb_device_table[audio_extn_get_spkr_prot_snd_device(usecase->out_snd_device)];
vivek mehta40125092017-08-21 18:48:51 -0700785
786 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700787 acdb_dev_type, mode, level)) {
788 // set ret_val true if at least one calibration is set successfully
789 ret_val = true;
790 } else {
791 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
792 }
793 } else {
794 ALOGW("%s: Usecase list is empty", __func__);
795 }
796 }
797 } else {
798 ALOGW("%s: Voice call in progress .. ignore setting new cal",
799 __func__);
800 }
801 return ret_val;
802}
803
Eric Laurentcefbbac2014-09-04 13:54:10 -0500804void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700805{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800806 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500807 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700808
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800809 if (strcmp(my_data->ec_ref_mixer_path, "")) {
810 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
811 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500812 }
813
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800814 if (enable) {
815 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
816 if (out_device != AUDIO_DEVICE_NONE) {
817 snd_device = platform_get_output_snd_device(adev->platform, out_device);
818 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
819 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500820
Joe Onorato188b6222016-03-01 11:02:27 -0800821 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800822 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
823 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700824}
825
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700826static struct csd_data *open_csd_client(bool i2s_ext_modem)
827{
828 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
829
830 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
831 if (csd->csd_client == NULL) {
832 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
833 goto error;
834 } else {
835 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
836
837 csd->deinit = (deinit_t)dlsym(csd->csd_client,
838 "csd_client_deinit");
839 if (csd->deinit == NULL) {
840 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
841 dlerror());
842 goto error;
843 }
844 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
845 "csd_client_disable_device");
846 if (csd->disable_device == NULL) {
847 ALOGE("%s: dlsym error %s for csd_client_disable_device",
848 __func__, dlerror());
849 goto error;
850 }
851 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
852 "csd_client_enable_device_config");
853 if (csd->enable_device_config == NULL) {
854 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
855 __func__, dlerror());
856 goto error;
857 }
858 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
859 "csd_client_enable_device");
860 if (csd->enable_device == NULL) {
861 ALOGE("%s: dlsym error %s for csd_client_enable_device",
862 __func__, dlerror());
863 goto error;
864 }
865 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
866 "csd_client_start_voice");
867 if (csd->start_voice == NULL) {
868 ALOGE("%s: dlsym error %s for csd_client_start_voice",
869 __func__, dlerror());
870 goto error;
871 }
872 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
873 "csd_client_stop_voice");
874 if (csd->stop_voice == NULL) {
875 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
876 __func__, dlerror());
877 goto error;
878 }
879 csd->volume = (volume_t)dlsym(csd->csd_client,
880 "csd_client_volume");
881 if (csd->volume == NULL) {
882 ALOGE("%s: dlsym error %s for csd_client_volume",
883 __func__, dlerror());
884 goto error;
885 }
886 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
887 "csd_client_mic_mute");
888 if (csd->mic_mute == NULL) {
889 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
890 __func__, dlerror());
891 goto error;
892 }
893 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
894 "csd_client_slow_talk");
895 if (csd->slow_talk == NULL) {
896 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
897 __func__, dlerror());
898 goto error;
899 }
900 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
901 "csd_client_start_playback");
902 if (csd->start_playback == NULL) {
903 ALOGE("%s: dlsym error %s for csd_client_start_playback",
904 __func__, dlerror());
905 goto error;
906 }
907 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
908 "csd_client_stop_playback");
909 if (csd->stop_playback == NULL) {
910 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
911 __func__, dlerror());
912 goto error;
913 }
914 csd->start_record = (start_record_t)dlsym(csd->csd_client,
915 "csd_client_start_record");
916 if (csd->start_record == NULL) {
917 ALOGE("%s: dlsym error %s for csd_client_start_record",
918 __func__, dlerror());
919 goto error;
920 }
921 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
922 "csd_client_stop_record");
923 if (csd->stop_record == NULL) {
924 ALOGE("%s: dlsym error %s for csd_client_stop_record",
925 __func__, dlerror());
926 goto error;
927 }
928
929 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
930 "csd_client_get_sample_rate");
931 if (csd->get_sample_rate == NULL) {
932 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
933 __func__, dlerror());
934
935 goto error;
936 }
937
938 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
939
940 if (csd->init == NULL) {
941 ALOGE("%s: dlsym error %s for csd_client_init",
942 __func__, dlerror());
943 goto error;
944 } else {
945 csd->init(i2s_ext_modem);
946 }
947 }
948 return csd;
949
950error:
951 free(csd);
952 csd = NULL;
953 return csd;
954}
955
956void close_csd_client(struct csd_data *csd)
957{
958 if (csd != NULL) {
959 csd->deinit();
960 dlclose(csd->csd_client);
961 free(csd);
962 csd = NULL;
963 }
964}
965
966static void platform_csd_init(struct platform_data *my_data)
967{
968#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700969 int32_t modems, (*count_modems)(void);
970 const char *name = "libdetectmodem.so";
971 const char *func = "count_modems";
972 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700973
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700974 my_data->csd = NULL;
975
976 void *lib = dlopen(name, RTLD_NOW);
977 error = dlerror();
978 if (!lib) {
979 ALOGE("%s: could not find %s: %s", __func__, name, error);
980 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700981 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700982
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700983 count_modems = NULL;
984 *(void **)(&count_modems) = dlsym(lib, func);
985 error = dlerror();
986 if (!count_modems) {
987 ALOGE("%s: could not find symbol %s in %s: %s",
988 __func__, func, name, error);
989 goto done;
990 }
991
992 modems = count_modems();
993 if (modems < 0) {
994 ALOGE("%s: count_modems failed\n", __func__);
995 goto done;
996 }
997
Eric Laurent2bafff12016-03-17 12:17:23 -0700998 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700999 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001000 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001001
1002done:
1003 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001004#else
1005 my_data->csd = NULL;
1006#endif
1007}
1008
Eric Laurentc6333382015-09-14 12:43:44 -07001009static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001010{
1011 int32_t dev;
1012 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001013 backend_tag_table[dev] = NULL;
1014 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001015 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001016 }
1017
David Linee3fe402017-03-13 10:00:42 -07001018 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1019 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1020 }
1021
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001022 // To overwrite these go to the audio_platform_info.xml file.
1023 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001024 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001025 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1026 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1027 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1028 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1029 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001030 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001031 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1032 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001033
David Linee3fe402017-03-13 10:00:42 -07001034 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001035 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001036 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001037 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001038 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1039 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001040 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1041 strdup("speaker-safe-and-usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001042 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001043 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1044 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1045 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1046 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001047 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1048 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
1049
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001050 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1051 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1052 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1053 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1054 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1055 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1056 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001057 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001058 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001059 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001060 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1061 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1062 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1063 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1064 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1065 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1066 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1067 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1068 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001069 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1070 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1071 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001072 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1073 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1074 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1075 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001076 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001077 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1078 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001079 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001080 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001081 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001082 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 -07001083 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 -07001084 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1085 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1086 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001087 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1088 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1089 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 -07001090 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1091 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1092 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1093 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1094 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1095 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1096 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001097 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001098 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1099 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1100 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1101 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1102 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1103 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1104 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1105 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001106 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001107 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001108 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001109 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1110 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001111 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1112 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001113 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1114 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001115 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1116 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1117 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1118 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1119 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001120 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1121 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1122 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1123 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1124 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1125 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1126 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1127 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001128 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1129 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1130 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001131 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001132 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1133 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001134 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001135 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1136 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1137 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1138 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1139 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1140 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1141 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1142 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1143 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1144 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1145 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1146 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1147 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1148 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1149 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001150 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001151}
1152
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001153void get_cvd_version(char *cvd_version, struct audio_device *adev)
1154{
1155 struct mixer_ctl *ctl;
1156 int count;
1157 int ret = 0;
1158
1159 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1160 if (!ctl) {
1161 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1162 goto done;
1163 }
1164 mixer_ctl_update(ctl);
1165
1166 count = mixer_ctl_get_num_values(ctl);
1167 if (count > MAX_CVD_VERSION_STRING_SIZE)
1168 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1169
1170 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1171 if (ret != 0) {
1172 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1173 goto done;
1174 }
1175
1176done:
1177 return;
1178}
1179
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001180static int platform_acdb_init(void *platform)
1181{
1182 struct platform_data *my_data = (struct platform_data *)platform;
1183 struct audio_device *adev = my_data->adev;
1184
1185 if (!my_data->acdb_init) {
1186 ALOGE("%s: no acdb_init fn provided", __func__);
1187 return -1;
1188 }
1189
1190 if (my_data->acdb_initialized) {
1191 ALOGW("acdb is already initialized");
1192 return 0;
1193 }
1194
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001195#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001196 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1197 if (!cvd_version)
1198 ALOGE("failed to allocate cvd_version");
1199 else {
1200 get_cvd_version(cvd_version, adev);
1201 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1202 free(cvd_version);
1203 }
1204#elif defined (PLATFORM_MSM8084)
1205 my_data->acdb_init((char *)my_data->snd_card_name);
1206#else
1207 my_data->acdb_init();
1208#endif
1209 my_data->acdb_initialized = true;
1210 return 0;
1211}
1212
David Linee3fe402017-03-13 10:00:42 -07001213static void
1214platform_backend_config_init(struct platform_data *pdata)
1215{
1216 int i;
1217
1218 /* initialize backend config */
1219 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1220 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1221 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1222 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1223
1224 if (i > MAX_RX_CODEC_BACKENDS)
1225 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1226
1227 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1228 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1229 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1230 }
1231
1232 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1233 strdup("SLIM_0_RX Format");
1234 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1235 strdup("SLIM_0_RX SampleRate");
1236
1237 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1238 strdup("SLIM_0_TX Format");
1239 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1240 strdup("SLIM_0_TX SampleRate");
1241
1242 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1243 strdup("USB_AUDIO_TX Format");
1244 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1245 strdup("USB_AUDIO_TX SampleRate");
1246 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1247 strdup("USB_AUDIO_TX Channels");
1248
1249 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1250 strdup("SLIM_6_RX Format");
1251 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1252 strdup("SLIM_6_RX SampleRate");
1253
1254 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1255 strdup("USB_AUDIO_RX Format");
1256 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1257 strdup("USB_AUDIO_RX SampleRate");
1258
1259 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1260 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1261 strdup("USB_AUDIO_RX Channels");
1262}
1263
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001264static int
1265platform_backend_app_type_cfg_init(struct platform_data *pdata,
1266 struct mixer *mixer)
1267{
1268 size_t app_type_cfg[128] = {0};
1269 int length, num_app_types = 0;
1270 struct mixer_ctl *ctl = NULL;
1271
1272 const char *mixer_ctl_name = "App Type Config";
1273 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1274 if (!ctl) {
1275 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1276 return -1;
1277 }
1278
1279 length = 1; // reserve index 0 for number of app types
1280
1281 struct listnode *node;
1282 struct app_type_entry *entry;
1283 list_for_each(node, &app_type_entry_list) {
1284 entry = node_to_item(node, struct app_type_entry, node);
1285 app_type_cfg[length++] = entry->app_type;
1286 app_type_cfg[length++] = entry->max_rate;
1287 app_type_cfg[length++] = entry->bit_width;
1288 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1289 num_app_types += 1;
1290 }
1291
1292 // default for capture
1293 int t;
1294 platform_get_default_app_type_v2(pdata,
1295 PCM_CAPTURE,
1296 &t);
1297 app_type_cfg[length++] = t;
1298 app_type_cfg[length++] = 48000;
1299 app_type_cfg[length++] = 16;
1300 num_app_types += 1;
1301
1302 if (num_app_types) {
1303 app_type_cfg[0] = num_app_types;
1304 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1305 ALOGE("Failed to set app type cfg");
1306 }
1307 }
1308 return 0;
1309}
1310
Eric Laurentb23d5282013-05-14 15:27:20 -07001311void *platform_init(struct audio_device *adev)
1312{
1313 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001314 struct platform_data *my_data = NULL;
1315 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1316 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001317 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001318 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001319 char *snd_internal_name = NULL;
1320 char *tmp = NULL;
1321 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001322 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1323 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001324 my_data = calloc(1, sizeof(struct platform_data));
1325
1326 my_data->adev = adev;
1327
keunhui.park2f7306a2015-07-16 16:48:06 +09001328 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001329 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001330
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001331 set_platform_defaults(my_data);
1332
vivek mehta0fb11312017-05-15 19:35:32 -07001333 // audio_extn_utils_get_snd_card_num does
1334 // - open mixer and get snd card name
1335 // - parse platform info xml file and check for valid snd card name
1336 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001337
vivek mehta0fb11312017-05-15 19:35:32 -07001338 snd_card_num = audio_extn_utils_get_snd_card_num();
1339 if (-1 == snd_card_num) {
1340 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1341 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001342 }
1343
vivek mehta0fb11312017-05-15 19:35:32 -07001344 adev->mixer = mixer_open(snd_card_num);
1345 snd_card_name = mixer_get_name(adev->mixer);
1346 my_data->hw_info = hw_info_init(snd_card_name);
1347
1348 audio_extn_set_snd_card_split(snd_card_name);
1349 snd_split_handle = audio_extn_get_snd_card_split();
1350
1351 /* Get the codec internal name from the sound card and/or form factor
1352 * name and form the mixer paths and platfor info file name dynamically.
1353 * This is generic way of picking any codec and forma factor name based
1354 * mixer and platform info files in future with no code change.
1355
1356 * current code extends and looks for any of the exteneded mixer path and
1357 * platform info file present based on codec and form factor.
1358
1359 * order of picking appropriate file is
1360 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1361 * <ii> mixer_paths_<codec_name>.xml, if file not present
1362 * <iii> mixer_paths.xml
1363
1364 * same order is followed for audio_platform_info.xml as well
1365 */
1366
1367 // need to carryforward old file name
1368 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1369 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1370 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1371 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1372 } else {
1373
1374 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1375 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1376 snd_split_handle->form_factor);
1377 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1378 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1379 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1380 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1381
1382 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1383 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1384 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1385 audio_extn_utils_resolve_config_file(mixer_xml_file);
1386 }
1387 }
1388 }
1389
1390 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1391
1392 /* Initialize platform specific ids and/or backends*/
1393 platform_info_init(platform_info_file, my_data);
1394
1395 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1396 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1397
1398 if (!adev->audio_route) {
1399 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1400 mixer_close(adev->mixer);
1401 adev->mixer = NULL;
1402 hw_info_deinit(my_data->hw_info);
1403 my_data->hw_info = NULL;
1404 goto init_failed;
1405 }
1406 adev->snd_card = snd_card_num;
1407 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1408
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001409 //set max volume step for voice call
1410 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1411 my_data->max_vol_index = atoi(value);
1412
vivek mehta65ad12d2015-08-13 18:32:48 -07001413 property_get("persist.audio.dualmic.config",value,"");
1414 if (!strcmp("endfire", value)) {
1415 dual_mic_config = true;
1416 }
1417
John Muir9e59a962018-01-10 13:30:00 -08001418 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001419
Eric Laurentb23d5282013-05-14 15:27:20 -07001420 my_data->fluence_in_spkr_mode = false;
1421 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001422 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001423 my_data->fluence_in_voice_rec = false;
1424
vivek mehta65ad12d2015-08-13 18:32:48 -07001425 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001426 if (!strcmp("fluencepro", value)) {
1427 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001428 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001429 my_data->fluence_type = FLUENCE_ENABLE;
1430 } else if (!strcmp("none", value)) {
1431 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001432 }
1433
Prashant Malanic92c5962015-08-11 15:10:18 -07001434 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001435 property_get("persist.audio.fluence.voicecall",value,"");
1436 if (!strcmp("true", value)) {
1437 my_data->fluence_in_voice_call = true;
1438 }
1439
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001440 property_get("persist.audio.fluence.voicecomm",value,"");
1441 if (!strcmp("true", value)) {
1442 my_data->fluence_in_voice_comm = true;
1443 }
1444
Eric Laurentb23d5282013-05-14 15:27:20 -07001445 property_get("persist.audio.fluence.voicerec",value,"");
1446 if (!strcmp("true", value)) {
1447 my_data->fluence_in_voice_rec = true;
1448 }
1449
1450 property_get("persist.audio.fluence.speaker",value,"");
1451 if (!strcmp("true", value)) {
1452 my_data->fluence_in_spkr_mode = true;
1453 }
1454 }
1455
Prashant Malanic92c5962015-08-11 15:10:18 -07001456 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1457 switch (my_data->max_mic_count) {
1458 case 4:
1459 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1460 case 3:
1461 my_data->source_mic_type |= SOURCE_THREE_MIC;
1462 case 2:
1463 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1464 case 1:
1465 my_data->source_mic_type |= SOURCE_MONO_MIC;
1466 break;
1467 default:
1468 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1469 __func__, my_data->max_mic_count);
1470 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1471 break;
1472 }
1473
1474 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1475 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1476 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1477 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1478 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1479
Eric Laurentb23d5282013-05-14 15:27:20 -07001480 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1481 if (my_data->acdb_handle == NULL) {
1482 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1483 } else {
1484 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1485 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1486 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001487 if (!my_data->acdb_deallocate)
1488 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1489 __func__, LIB_ACDB_LOADER);
1490
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001491 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1492 "acdb_loader_send_audio_cal_v3");
1493 if (!my_data->acdb_send_audio_cal_v3)
1494 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1495 __func__, LIB_ACDB_LOADER);
1496
Eric Laurentb23d5282013-05-14 15:27:20 -07001497 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1498 "acdb_loader_send_audio_cal");
1499 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001500 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001501 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001502
Eric Laurentb23d5282013-05-14 15:27:20 -07001503 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1504 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001505 if (!my_data->acdb_send_voice_cal)
1506 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1507 __func__, LIB_ACDB_LOADER);
1508
1509 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1510 "acdb_loader_reload_vocvoltable");
1511 if (!my_data->acdb_reload_vocvoltable)
1512 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1513 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001514
1515 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1516 "acdb_loader_send_gain_dep_cal");
1517 if (!my_data->acdb_send_gain_dep_cal)
1518 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1519 __func__, LIB_ACDB_LOADER);
1520
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001521#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
vivek mehta0fb11312017-05-15 19:35:32 -07001522 acdb_init_v2_cvd_t acdb_init_local;
1523 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001524 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001525 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001526 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1527 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001528
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001529#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001530 acdb_init_v2_t acdb_init_local;
1531 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001532 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001533 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001534 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1535 dlerror());
1536
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001537#else
vivek mehta0fb11312017-05-15 19:35:32 -07001538 acdb_init_t acdb_init_local;
1539 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001540 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001541 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001542 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1543 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001544#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001545 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001546
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001547 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1548 dlsym(my_data->acdb_handle,
1549 "acdb_loader_send_common_custom_topology");
1550
1551 if (!my_data->acdb_send_custom_top)
1552 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1553 __func__, LIB_ACDB_LOADER);
1554
vivek mehta0fb11312017-05-15 19:35:32 -07001555 int result = acdb_init(adev->snd_card);
1556 if (!result) {
1557 my_data->acdb_initialized = true;
1558 ALOGD("ACDB initialized");
1559 } else {
1560 my_data->acdb_initialized = false;
1561 ALOGD("ACDB initialization failed");
1562 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001563 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001564
David Linee3fe402017-03-13 10:00:42 -07001565 /* init usb */
1566 audio_extn_usb_init(adev);
1567
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001568 /* init a2dp */
1569 audio_extn_a2dp_init(adev);
1570
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001571 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001572
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001573 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1574
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001575 /* load csd client */
1576 platform_csd_init(my_data);
1577
David Linee3fe402017-03-13 10:00:42 -07001578 platform_backend_config_init(my_data);
1579
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001580 init_be_dai_name_table(adev);
1581
1582 if (platform_supports_app_type_cfg())
1583 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1584
Eric Laurentb23d5282013-05-14 15:27:20 -07001585 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001586
1587init_failed:
1588 if (my_data)
1589 free(my_data);
1590 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001591}
1592
1593void platform_deinit(void *platform)
1594{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001595 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001596 struct operator_info *info_item;
1597 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001598 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001599 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001600
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001601 struct platform_data *my_data = (struct platform_data *)platform;
1602 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001603
vivek mehtade4849c2016-03-03 17:23:38 -08001604 hw_info_deinit(my_data->hw_info);
1605
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001606 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1607 if (backend_tag_table[dev])
1608 free(backend_tag_table[dev]);
1609 if (hw_interface_table[dev])
1610 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001611 if (operator_specific_device_table[dev]) {
1612 while (!list_empty(operator_specific_device_table[dev])) {
1613 node = list_head(operator_specific_device_table[dev]);
1614 list_remove(node);
1615 device_item = node_to_item(node, struct operator_specific_device, list);
1616 free(device_item->operator);
1617 free(device_item->mixer_path);
1618 free(device_item);
1619 }
1620 free(operator_specific_device_table[dev]);
1621 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001622 }
1623
1624 if (my_data->snd_card_name)
1625 free(my_data->snd_card_name);
1626
keunhui.park2f7306a2015-07-16 16:48:06 +09001627 while (!list_empty(&operator_info_list)) {
1628 node = list_head(&operator_info_list);
1629 list_remove(node);
1630 info_item = node_to_item(node, struct operator_info, list);
1631 free(info_item->name);
1632 free(info_item->mccmnc);
1633 free(info_item);
1634 }
1635
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001636 while (!list_empty(&app_type_entry_list)) {
1637 node = list_head(&app_type_entry_list);
1638 list_remove(node);
1639 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001640 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001641 free(ap);
1642 }
1643
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001644 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001645 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001646
1647 /* deinit usb */
1648 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001649}
1650
1651const char *platform_get_snd_device_name(snd_device_t snd_device)
1652{
keunhui.park2f7306a2015-07-16 16:48:06 +09001653 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1654 if (operator_specific_device_table[snd_device] != NULL) {
1655 return get_operator_specific_device_mixer_path(snd_device);
1656 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001657 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001658 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001659 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001660}
1661
vivek mehtade4849c2016-03-03 17:23:38 -08001662int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1663 char *device_name)
1664{
1665 struct platform_data *my_data = (struct platform_data *)platform;
1666
David Benjamin1565f992016-09-21 12:10:34 -04001667 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001668 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001669 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1670 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001671 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1672 if (operator_specific_device_table[snd_device] != NULL) {
1673 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1674 DEVICE_NAME_MAX_SIZE);
1675 } else {
1676 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1677 }
1678 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1679 } else {
1680 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1681 }
1682
1683 return 0;
1684}
1685
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001686void platform_add_backend_name(void *platform, char *mixer_path,
1687 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001688{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001689 struct platform_data *my_data = (struct platform_data *)platform;
1690
Haynes Mathew George98c95622014-06-20 19:14:25 -07001691 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1692 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1693 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001694 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001695
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001696 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001697
1698 if (suffix != NULL) {
1699 strcat(mixer_path, " ");
1700 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001701 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001702}
1703
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001704bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1705{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001706 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1707 platform_get_snd_device_name(snd_device1),
1708 platform_get_snd_device_name(snd_device2));
1709
1710 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1711 ALOGE("%s: Invalid snd_device = %s", __func__,
1712 platform_get_snd_device_name(snd_device1));
1713 return false;
1714 }
1715 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1716 ALOGE("%s: Invalid snd_device = %s", __func__,
1717 platform_get_snd_device_name(snd_device2));
1718 return false;
1719 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001720
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001721 const char * be_itf1 = hw_interface_table[snd_device1];
1722 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001723 /*
1724 hw_interface_table has overrides for a snd_device.
1725 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1726 */
1727 if (be_itf1 == NULL) {
1728 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001729 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001730 if (be_itf2 == NULL) {
1731 be_itf2 = DEFAULT_RX_BACKEND;
1732 }
1733 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1734 /*
1735 this takes care of finding a device within a combo device pair as well
1736 */
1737 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001738}
1739
Eric Laurentb23d5282013-05-14 15:27:20 -07001740int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1741{
1742 int device_id;
1743 if (device_type == PCM_PLAYBACK)
1744 device_id = pcm_device_table[usecase][0];
1745 else
1746 device_id = pcm_device_table[usecase][1];
1747 return device_id;
1748}
1749
Haynes Mathew George98c95622014-06-20 19:14:25 -07001750static int find_index(const struct name_to_index * table, int32_t len,
1751 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001752{
1753 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001754 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001755
Haynes Mathew George98c95622014-06-20 19:14:25 -07001756 if (table == NULL) {
1757 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001758 ret = -ENODEV;
1759 goto done;
1760 }
1761
Haynes Mathew George98c95622014-06-20 19:14:25 -07001762 if (name == NULL) {
1763 ALOGE("null key");
1764 ret = -ENODEV;
1765 goto done;
1766 }
1767
1768 for (i=0; i < len; i++) {
1769 if (!strcmp(table[i].name, name)) {
1770 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001771 goto done;
1772 }
1773 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001774 ALOGE("%s: Could not find index for name = %s",
1775 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001776 ret = -ENODEV;
1777done:
1778 return ret;
1779}
1780
Haynes Mathew George98c95622014-06-20 19:14:25 -07001781int platform_get_snd_device_index(char *device_name)
1782{
1783 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1784}
1785
1786int platform_get_usecase_index(const char *usecase_name)
1787{
1788 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1789}
1790
keunhui.park2f7306a2015-07-16 16:48:06 +09001791void platform_add_operator_specific_device(snd_device_t snd_device,
1792 const char *operator,
1793 const char *mixer_path,
1794 unsigned int acdb_id)
1795{
1796 struct operator_specific_device *device;
1797
1798 if (operator_specific_device_table[snd_device] == NULL) {
1799 operator_specific_device_table[snd_device] =
1800 (struct listnode *)calloc(1, sizeof(struct listnode));
1801 list_init(operator_specific_device_table[snd_device]);
1802 }
1803
1804 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1805
1806 device->operator = strdup(operator);
1807 device->mixer_path = strdup(mixer_path);
1808 device->acdb_id = acdb_id;
1809
1810 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1811
Eric Laurent2bafff12016-03-17 12:17:23 -07001812 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001813 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1814
1815}
1816
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001817int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1818{
1819 int ret = 0;
1820
1821 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1822 ALOGE("%s: Invalid snd_device = %d",
1823 __func__, snd_device);
1824 ret = -EINVAL;
1825 goto done;
1826 }
1827
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001828 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1829 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001830 acdb_device_table[snd_device] = acdb_id;
1831done:
1832 return ret;
1833}
1834
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001835int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1836{
1837 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1838 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1839 return -EINVAL;
1840 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001841
1842 if (operator_specific_device_table[snd_device] != NULL)
1843 return get_operator_specific_device_acdb_id(snd_device);
1844 else
1845 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001846}
1847
David Linee3fe402017-03-13 10:00:42 -07001848static int platform_get_backend_index(snd_device_t snd_device)
1849{
1850 int32_t port = DEFAULT_CODEC_BACKEND;
1851
1852 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1853 if (backend_tag_table[snd_device] != NULL) {
1854 if (strncmp(backend_tag_table[snd_device], "headphones",
1855 sizeof("headphones")) == 0)
1856 port = HEADPHONE_BACKEND;
1857 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1858 port = HDMI_RX_BACKEND;
1859 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1860 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1861 port = USB_AUDIO_RX_BACKEND;
1862 }
1863 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1864 port = DEFAULT_CODEC_TX_BACKEND;
1865 if (backend_tag_table[snd_device] != NULL) {
1866 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1867 port = USB_AUDIO_TX_BACKEND;
1868 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1869 port = BT_SCO_TX_BACKEND;
1870 }
1871 } else {
1872 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1873 }
1874
1875 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1876
1877 return port;
1878}
1879
Eric Laurentb23d5282013-05-14 15:27:20 -07001880int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1881{
1882 struct platform_data *my_data = (struct platform_data *)platform;
1883 int acdb_dev_id, acdb_dev_type;
1884
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001885 if (platform_supports_app_type_cfg()) // use v2 instead
1886 return -ENOSYS;
1887
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001888 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001889 if (acdb_dev_id < 0) {
1890 ALOGE("%s: Could not find acdb id for device(%d)",
1891 __func__, snd_device);
1892 return -EINVAL;
1893 }
1894 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001895 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001896 __func__, snd_device, acdb_dev_id);
1897 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1898 snd_device < SND_DEVICE_OUT_END)
1899 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1900 else
1901 acdb_dev_type = ACDB_DEV_TYPE_IN;
1902 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1903 }
1904 return 0;
1905}
1906
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001907int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1908 int app_type, int sample_rate)
1909{
1910 struct platform_data *my_data = (struct platform_data *)platform;
1911 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07001912 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001913 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1914 int i, num_devices = 1;
1915
1916 if (!platform_supports_app_type_cfg()) // use v1 instead
1917 return -ENOSYS;
1918
vivek mehta7e573672018-03-13 17:41:41 -07001919 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001920 snd_device = usecase->in_snd_device;
1921
1922 // skipped over get_spkr_prot_device
vivek mehta7e573672018-03-13 17:41:41 -07001923 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001924 if (acdb_dev_id < 0) {
1925 ALOGE("%s: Could not find acdb id for device(%d)",
1926 __func__, snd_device);
1927 return -EINVAL;
1928 }
1929
1930 if (platform_can_split_snd_device(snd_device,
1931 &num_devices, new_snd_device) < 0) {
1932 new_snd_device[0] = snd_device;
1933 }
1934
1935 for (i = 0; i < num_devices; i++) {
vivek mehta7e573672018-03-13 17:41:41 -07001936 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(new_snd_device[i])];
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001937 if (acdb_dev_id < 0) {
1938 ALOGE("%s: Could not find acdb id for device(%d)",
1939 __func__, new_snd_device[i]);
1940 return -EINVAL;
1941 }
1942 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1943 __func__, new_snd_device[i], acdb_dev_id);
1944 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1945 new_snd_device[i] < SND_DEVICE_OUT_END)
1946 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1947 else
1948 acdb_dev_type = ACDB_DEV_TYPE_IN;
1949
1950 if (my_data->acdb_send_audio_cal_v3) {
1951 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1952 app_type, sample_rate, i);
1953 } else if (my_data->acdb_send_audio_cal) {
1954 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
1955 }
1956 }
1957
1958 return 0;
1959}
1960
1961
Eric Laurentb23d5282013-05-14 15:27:20 -07001962int platform_switch_voice_call_device_pre(void *platform)
1963{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001964 struct platform_data *my_data = (struct platform_data *)platform;
1965 int ret = 0;
1966
1967 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001968 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001969 /* This must be called before disabling mixer controls on APQ side */
1970 ret = my_data->csd->disable_device();
1971 if (ret < 0) {
1972 ALOGE("%s: csd_client_disable_device, failed, error %d",
1973 __func__, ret);
1974 }
1975 }
1976 return ret;
1977}
1978
1979int platform_switch_voice_call_enable_device_config(void *platform,
1980 snd_device_t out_snd_device,
1981 snd_device_t in_snd_device)
1982{
1983 struct platform_data *my_data = (struct platform_data *)platform;
1984 int acdb_rx_id, acdb_tx_id;
1985 int ret = 0;
1986
1987 if (my_data->csd == NULL)
1988 return ret;
1989
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001990 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1991 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001992 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001993 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001994 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001995
keunhui.park2f7306a2015-07-16 16:48:06 +09001996 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001997
1998 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1999 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2000 if (ret < 0) {
2001 ALOGE("%s: csd_enable_device_config, failed, error %d",
2002 __func__, ret);
2003 }
2004 } else {
2005 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2006 acdb_rx_id, acdb_tx_id);
2007 }
2008
2009 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002010}
2011
2012int platform_switch_voice_call_device_post(void *platform,
2013 snd_device_t out_snd_device,
2014 snd_device_t in_snd_device)
2015{
2016 struct platform_data *my_data = (struct platform_data *)platform;
2017 int acdb_rx_id, acdb_tx_id;
2018
2019 if (my_data->acdb_send_voice_cal == NULL) {
2020 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2021 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002022 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2023 audio_extn_spkr_prot_is_enabled())
2024 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
2025
keunhui.park2f7306a2015-07-16 16:48:06 +09002026 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2027 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002028
2029 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2030 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2031 else
2032 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2033 acdb_rx_id, acdb_tx_id);
2034 }
2035
2036 return 0;
2037}
2038
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002039int platform_switch_voice_call_usecase_route_post(void *platform,
2040 snd_device_t out_snd_device,
2041 snd_device_t in_snd_device)
2042{
2043 struct platform_data *my_data = (struct platform_data *)platform;
2044 int acdb_rx_id, acdb_tx_id;
2045 int ret = 0;
2046
2047 if (my_data->csd == NULL)
2048 return ret;
2049
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002050 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2051 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09002052 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002053 else
keunhui.park2f7306a2015-07-16 16:48:06 +09002054 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002055
keunhui.park2f7306a2015-07-16 16:48:06 +09002056 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002057
2058 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2059 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2060 my_data->adev->acdb_settings);
2061 if (ret < 0) {
2062 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2063 }
2064 } else {
2065 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2066 acdb_rx_id, acdb_tx_id);
2067 }
2068
2069 return ret;
2070}
2071
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002072int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002073{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002074 struct platform_data *my_data = (struct platform_data *)platform;
2075 int ret = 0;
2076
2077 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002078 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002079 if (ret < 0) {
2080 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2081 }
2082 }
2083 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002084}
2085
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002086int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002087{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002088 struct platform_data *my_data = (struct platform_data *)platform;
2089 int ret = 0;
2090
2091 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002092 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002093 if (ret < 0) {
2094 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2095 }
2096 }
2097 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002098}
2099
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002100int platform_get_sample_rate(void *platform, uint32_t *rate)
2101{
2102 struct platform_data *my_data = (struct platform_data *)platform;
2103 int ret = 0;
2104
2105 if (my_data->csd != NULL) {
2106 ret = my_data->csd->get_sample_rate(rate);
2107 if (ret < 0) {
2108 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2109 }
2110 }
2111 return ret;
2112}
2113
vivek mehtab6506412015-08-07 16:55:17 -07002114void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2115 snd_device_t snd_device,
2116 bool enable)
2117{
2118 const char* name;
2119 switch (snd_device) {
2120 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2121 if (enable)
2122 name = "spkr-gain-in-headphone-combo";
2123 else
2124 name = "speaker-gain-default";
2125 break;
2126 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2127 if (enable)
2128 name = "spkr-gain-in-line-combo";
2129 else
2130 name = "speaker-gain-default";
2131 break;
2132 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2133 if (enable)
2134 name = "spkr-safe-gain-in-headphone-combo";
2135 else
2136 name = "speaker-safe-gain-default";
2137 break;
2138 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2139 if (enable)
2140 name = "spkr-safe-gain-in-line-combo";
2141 else
2142 name = "speaker-safe-gain-default";
2143 break;
2144 default:
2145 return;
2146 }
2147
2148 audio_route_apply_and_update_path(adev->audio_route, name);
2149}
2150
Eric Laurentb23d5282013-05-14 15:27:20 -07002151int platform_set_voice_volume(void *platform, int volume)
2152{
2153 struct platform_data *my_data = (struct platform_data *)platform;
2154 struct audio_device *adev = my_data->adev;
2155 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002156 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002157 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002158 int vol_index = 0, ret = 0;
2159 uint32_t set_values[ ] = {0,
2160 ALL_SESSION_VSID,
2161 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002162
2163 // Voice volume levels are mapped to adsp volume levels as follows.
2164 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2165 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002166 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002167 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002168
2169 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2170 if (!ctl) {
2171 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2172 __func__, mixer_ctl_name);
2173 return -EINVAL;
2174 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002175 ALOGV("Setting voice volume index: %d", set_values[0]);
2176 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2177
Nadav Barc46d0fa2017-12-24 14:50:37 +02002178 // Send mute command in case volume index is max since indexes are inverted
2179 // for mixer controls.
2180 if (vol_index == my_data->max_vol_index) {
2181 set_values[0] = 1;
2182 }
2183 else {
2184 set_values[0] = 0;
2185 }
2186
2187 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2188 if (!ctl) {
2189 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2190 __func__, mute_mixer_ctl_name);
2191 return -EINVAL;
2192 }
2193 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2194 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2195
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002196 if (my_data->csd != NULL) {
2197 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2198 DEFAULT_VOLUME_RAMP_DURATION_MS);
2199 if (ret < 0) {
2200 ALOGE("%s: csd_volume error %d", __func__, ret);
2201 }
2202 }
2203 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002204}
2205
2206int platform_set_mic_mute(void *platform, bool state)
2207{
2208 struct platform_data *my_data = (struct platform_data *)platform;
2209 struct audio_device *adev = my_data->adev;
2210 struct mixer_ctl *ctl;
2211 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002212 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002213 uint32_t set_values[ ] = {0,
2214 ALL_SESSION_VSID,
2215 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002216
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002217 if (adev->mode != AUDIO_MODE_IN_CALL &&
2218 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002219 return 0;
2220
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002221 if (adev->enable_hfp)
2222 mixer_ctl_name = "HFP Tx Mute";
2223
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002224 set_values[0] = state;
2225 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2226 if (!ctl) {
2227 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2228 __func__, mixer_ctl_name);
2229 return -EINVAL;
2230 }
2231 ALOGV("Setting voice mute state: %d", state);
2232 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2233
2234 if (my_data->csd != NULL) {
2235 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2236 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002237 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002238 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002239 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002240 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002241 return ret;
2242}
Eric Laurentb23d5282013-05-14 15:27:20 -07002243
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002244int platform_set_device_mute(void *platform, bool state, char *dir)
2245{
2246 struct platform_data *my_data = (struct platform_data *)platform;
2247 struct audio_device *adev = my_data->adev;
2248 struct mixer_ctl *ctl;
2249 char *mixer_ctl_name = NULL;
2250 int ret = 0;
2251 uint32_t set_values[ ] = {0,
2252 ALL_SESSION_VSID,
2253 0};
2254 if(dir == NULL) {
2255 ALOGE("%s: Invalid direction:%s", __func__, dir);
2256 return -EINVAL;
2257 }
2258
2259 if (!strncmp("rx", dir, sizeof("rx"))) {
2260 mixer_ctl_name = "Voice Rx Device Mute";
2261 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2262 mixer_ctl_name = "Voice Tx Device Mute";
2263 } else {
2264 return -EINVAL;
2265 }
2266
2267 set_values[0] = state;
2268 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2269 if (!ctl) {
2270 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2271 __func__, mixer_ctl_name);
2272 return -EINVAL;
2273 }
2274
2275 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2276 __func__,state, mixer_ctl_name);
2277 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2278
2279 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002280}
2281
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002282int platform_can_split_snd_device(snd_device_t snd_device,
2283 int *num_devices,
2284 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002285{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002286 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002287 if (NULL == num_devices || NULL == new_snd_devices) {
2288 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002289 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002290 }
2291
2292 /*
2293 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002294 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002295 */
2296 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2297 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2298 *num_devices = 2;
2299 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2300 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002301 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002302 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2303 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2304 *num_devices = 2;
2305 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2306 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002307 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002308 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2309 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2310 *num_devices = 2;
2311 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2312 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002313 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002314 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2315 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2316 *num_devices = 2;
2317 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2318 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002319 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002320 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2321 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2322 SND_DEVICE_OUT_BT_SCO)) {
2323 *num_devices = 2;
2324 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2325 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2326 ret = 0;
2327 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2328 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2329 SND_DEVICE_OUT_BT_SCO_WB)) {
2330 *num_devices = 2;
2331 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2332 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2333 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002334 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2335 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2336 *num_devices = 2;
2337 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2338 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2339 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002340 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2341 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2342 *num_devices = 2;
2343 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2344 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2345 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002346 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2347 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2348 SND_DEVICE_OUT_BT_A2DP)) {
2349 *num_devices = 2;
2350 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2351 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2352 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002353 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002354
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002355 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002356}
2357
Eric Laurentb23d5282013-05-14 15:27:20 -07002358snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2359{
2360 struct platform_data *my_data = (struct platform_data *)platform;
2361 struct audio_device *adev = my_data->adev;
2362 audio_mode_t mode = adev->mode;
2363 snd_device_t snd_device = SND_DEVICE_NONE;
2364
2365 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2366 if (devices == AUDIO_DEVICE_NONE ||
2367 devices & AUDIO_DEVICE_BIT_IN) {
2368 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2369 goto exit;
2370 }
2371
Eric Laurent1b491552015-09-15 17:52:41 -07002372 if (popcount(devices) == 2) {
2373 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2374 AUDIO_DEVICE_OUT_SPEAKER) ||
2375 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2376 AUDIO_DEVICE_OUT_SPEAKER)) {
2377 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2378 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2379 AUDIO_DEVICE_OUT_SPEAKER)) {
2380 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2381 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2382 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2383 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2384 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2385 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2386 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2387 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2388 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2389 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2390 AUDIO_DEVICE_OUT_SPEAKER)) {
2391 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002392 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2393 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2394 snd_device = adev->bt_wb_speech_enabled ?
2395 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2396 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002397 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2398 AUDIO_DEVICE_OUT_SPEAKER)) ||
2399 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2400 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002401 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002402 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2403 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2404 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2405 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002406 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002407 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2408 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2409 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002410 } else {
2411 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2412 goto exit;
2413 }
2414 if (snd_device != SND_DEVICE_NONE) {
2415 goto exit;
2416 }
2417 }
2418
2419 if (popcount(devices) != 1) {
2420 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2421 goto exit;
2422 }
2423
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302424 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002425 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002426 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2427 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002428 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002429 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002430 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002431 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002432 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002433 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002434 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002435 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002436 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002437 else {
2438 if (devices & AUDIO_DEVICE_OUT_LINE)
2439 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2440 else
2441 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2442 }
Eric Laurent99dab492017-06-17 15:19:08 -07002443 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002444 if (voice_is_in_call(adev)) {
2445 switch (adev->voice.tty_mode) {
2446 case TTY_MODE_FULL:
2447 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2448 break;
2449 case TTY_MODE_VCO:
2450 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2451 break;
2452 case TTY_MODE_HCO:
2453 // since Hearing will be on handset\speaker, use existing device
2454 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2455 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002456 case TTY_MODE_OFF:
2457 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002458 default:
2459 ALOGE("%s: Invalid TTY mode (%#x)",
2460 __func__, adev->voice.tty_mode);
2461 }
2462 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002463 if (snd_device == SND_DEVICE_NONE) {
2464 snd_device = audio_extn_usb_is_capture_supported() ?
2465 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2466 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2467 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002468 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002469 if (adev->bt_wb_speech_enabled) {
2470 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2471 } else {
2472 snd_device = SND_DEVICE_OUT_BT_SCO;
2473 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002474 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2475 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002476 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002477 if (!adev->enable_hfp) {
2478 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2479 } else {
2480 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2481 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002482 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002483 if(adev->voice.hac)
2484 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2485 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002486 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2487 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002488 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002489 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2490 snd_device = SND_DEVICE_OUT_VOICE_TX;
2491
Eric Laurentb23d5282013-05-14 15:27:20 -07002492 if (snd_device != SND_DEVICE_NONE) {
2493 goto exit;
2494 }
2495 }
2496
Eric Laurentb23d5282013-05-14 15:27:20 -07002497 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2498 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2499 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002500 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2501 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002502 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2503 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002504 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002505 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002506 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2507 else
2508 snd_device = SND_DEVICE_OUT_SPEAKER;
2509 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002510 if (adev->bt_wb_speech_enabled) {
2511 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2512 } else {
2513 snd_device = SND_DEVICE_OUT_BT_SCO;
2514 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002515 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2516 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002517 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2518 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002519 } else if (audio_is_usb_out_device(devices)) {
David Linee3fe402017-03-13 10:00:42 -07002520 if (audio_extn_usb_is_capture_supported())
2521 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2522 else
2523 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2524 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002525 /*HAC support for voice-ish audio (eg visual voicemail)*/
2526 if(adev->voice.hac)
2527 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2528 else
2529 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002530 } else {
2531 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2532 }
2533exit:
2534 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2535 return snd_device;
2536}
2537
2538snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2539{
2540 struct platform_data *my_data = (struct platform_data *)platform;
2541 struct audio_device *adev = my_data->adev;
2542 audio_source_t source = (adev->active_input == NULL) ?
2543 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2544
2545 audio_mode_t mode = adev->mode;
2546 audio_devices_t in_device = ((adev->active_input == NULL) ?
2547 AUDIO_DEVICE_NONE : adev->active_input->device)
2548 & ~AUDIO_DEVICE_BIT_IN;
2549 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2550 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2551 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002552 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002553
Prashant Malanic92c5962015-08-11 15:10:18 -07002554 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2555 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002556 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2557 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002558 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002559 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002560 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2561 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002562 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002563 case TTY_MODE_FULL:
2564 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2565 break;
2566 case TTY_MODE_VCO:
2567 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2568 break;
2569 case TTY_MODE_HCO:
2570 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2571 break;
2572 default:
2573 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2574 }
2575 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002576 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002577 switch (adev->voice.tty_mode) {
2578 case TTY_MODE_FULL:
2579 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2580 break;
2581 case TTY_MODE_VCO:
2582 // since voice will be captured from handset mic, use existing device
2583 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2584 break;
2585 case TTY_MODE_HCO:
2586 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2587 break;
2588 default:
2589 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002590 }
2591 goto exit;
2592 }
2593 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002594 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002595 if (my_data->fluence_in_voice_call == false) {
2596 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2597 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002598 if (is_operator_tmus())
2599 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002600 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002601 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002602 }
2603 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2604 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2605 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002606 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002607 if (adev->bluetooth_nrec)
2608 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2609 else
2610 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002611 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002612 if (adev->bluetooth_nrec)
2613 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2614 else
2615 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002616 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002617 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002618 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2619 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2620 out_device & AUDIO_DEVICE_OUT_LINE) {
2621 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2622 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2623 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2624 } else {
2625 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2626 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002627 }
vivek mehtafe121d52015-08-10 23:39:23 -07002628
2629 //select default
2630 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002631 if (!adev->enable_hfp) {
2632 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2633 } else {
2634 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2635 platform_set_echo_reference(adev, true, out_device);
2636 }
vivek mehtafe121d52015-08-10 23:39:23 -07002637 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002638 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002639 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002640 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002641 if (audio_extn_usb_is_capture_supported()) {
2642 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2643 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2644 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2645 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2646 } else {
2647 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2648 }
2649 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002650 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002651 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2652 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2653 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2654 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2655 }
2656 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2657 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002658 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2659 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2660 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002661 if (adev->active_input->enable_aec)
2662 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2663 else
2664 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002665 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2666 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002667 if (adev->active_input->enable_aec)
2668 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2669 else
2670 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002671 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2672 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2673 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002674 if (adev->active_input->enable_aec)
2675 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2676 else
2677 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002678 }
2679 platform_set_echo_reference(adev, true, out_device);
2680 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2681 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2682 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002683 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002684 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2685 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002686 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002687 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2688 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002689 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002690 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002691 if (adev->active_input->enable_aec) {
2692 if (adev->active_input->enable_ns) {
2693 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2694 } else {
2695 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2696 }
vivek mehta733c1df2016-04-04 15:09:24 -07002697 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002698 } else if (adev->active_input->enable_ns) {
2699 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2700 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002701 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002702 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002703 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002704 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2705 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002706 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002707 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002708 }
rago90fb9612015-12-02 11:37:53 -08002709 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2710 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002711 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2712 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2713 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2714 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002715 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002716 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2717 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002718 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002719 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2720 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2721 } else {
2722 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2723 }
rago90fb9612015-12-02 11:37:53 -08002724 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2725 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002726 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002727 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002728 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002729 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002730 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002731 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2732 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2733 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2734 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002735 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002736 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002737 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002738 if (adev->active_input->enable_aec &&
2739 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002740 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002741 if (my_data->fluence_in_spkr_mode &&
2742 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002743 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002744 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002745 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002746 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002747 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002748 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002749 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002750 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002751 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002752 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002753 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002754 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002755 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2756 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002757 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002758 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002759 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002760 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002761 } else if (adev->active_input->enable_aec) {
2762 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2763 if (my_data->fluence_in_spkr_mode &&
2764 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002765 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002766 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002767 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002768 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002769 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002770 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2771 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002772 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002773 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002774 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002775 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002776 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002777 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2778 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002779 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002780 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002781 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002782 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002783 } else if (adev->active_input->enable_ns) {
2784 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2785 if (my_data->fluence_in_spkr_mode &&
2786 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002787 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002788 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002789 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002790 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002791 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002792 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2793 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002794 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002795 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002796 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002797 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002798 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002799 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002800 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002801 }
2802 } else if (source == AUDIO_SOURCE_DEFAULT) {
2803 goto exit;
2804 }
2805
2806
2807 if (snd_device != SND_DEVICE_NONE) {
2808 goto exit;
2809 }
2810
2811 if (in_device != AUDIO_DEVICE_NONE &&
2812 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2813 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2814 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002815 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002816 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002817 snd_device = SND_DEVICE_IN_QUAD_MIC;
2818 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002819 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002820 snd_device = SND_DEVICE_IN_THREE_MIC;
2821 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2822 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002823 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002824 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2825 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002826 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002827 } else {
2828 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2829 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2830 my_data->source_mic_type, channel_count, channel_mask);
2831 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2832 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002833 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002834 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2835 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002836 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002837 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2838 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002839 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002840 } else {
2841 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2842 " no combination found .. setting to mono", __func__,
2843 my_data->source_mic_type, channel_count);
2844 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2845 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002846 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2847 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2848 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002849 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002850 if (adev->bluetooth_nrec)
2851 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2852 else
2853 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002854 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002855 if (adev->bluetooth_nrec)
2856 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2857 else
2858 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002859 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002860 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2861 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002862 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07002863 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002864 } else {
2865 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2866 ALOGW("%s: Using default handset-mic", __func__);
2867 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2868 }
2869 } else {
2870 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2871 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2872 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2873 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002874 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002875 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002876 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002877 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002878 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2879 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002880 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002881 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2882 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002883 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002884 } else {
2885 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2886 " no combination found .. setting to mono", __func__,
2887 my_data->source_mic_type, channel_count);
2888 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2889 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002890 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002891 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002892 if (adev->bluetooth_nrec)
2893 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2894 else
2895 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002896 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002897 if (adev->bluetooth_nrec)
2898 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2899 else
2900 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002901 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002902 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2903 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002904 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07002905 if (audio_extn_usb_is_capture_supported())
2906 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2907 else
2908 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002909 } else {
2910 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2911 ALOGW("%s: Using default handset-mic", __func__);
2912 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2913 }
2914 }
2915exit:
2916 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2917 return snd_device;
2918}
2919
2920int platform_set_hdmi_channels(void *platform, int channel_count)
2921{
2922 struct platform_data *my_data = (struct platform_data *)platform;
2923 struct audio_device *adev = my_data->adev;
2924 struct mixer_ctl *ctl;
2925 const char *channel_cnt_str = NULL;
2926 const char *mixer_ctl_name = "HDMI_RX Channels";
2927 switch (channel_count) {
2928 case 8:
2929 channel_cnt_str = "Eight"; break;
2930 case 7:
2931 channel_cnt_str = "Seven"; break;
2932 case 6:
2933 channel_cnt_str = "Six"; break;
2934 case 5:
2935 channel_cnt_str = "Five"; break;
2936 case 4:
2937 channel_cnt_str = "Four"; break;
2938 case 3:
2939 channel_cnt_str = "Three"; break;
2940 default:
2941 channel_cnt_str = "Two"; break;
2942 }
2943 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2944 if (!ctl) {
2945 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2946 __func__, mixer_ctl_name);
2947 return -EINVAL;
2948 }
2949 ALOGV("HDMI channel count: %s", channel_cnt_str);
2950 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2951 return 0;
2952}
2953
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002954int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002955{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002956 struct platform_data *my_data = (struct platform_data *)platform;
2957 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002958 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2959 char *sad = block;
2960 int num_audio_blocks;
2961 int channel_count;
2962 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002963 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002964
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002965 struct mixer_ctl *ctl;
2966
2967 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2968 if (!ctl) {
2969 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2970 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002971 return 0;
2972 }
2973
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002974 mixer_ctl_update(ctl);
2975
2976 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002977
2978 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002979 if (count > (int)sizeof(block))
2980 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002981
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002982 ret = mixer_ctl_get_array(ctl, block, count);
2983 if (ret != 0) {
2984 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2985 return 0;
2986 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002987
2988 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002989 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002990
2991 for (i = 0; i < num_audio_blocks; i++) {
2992 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002993 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2994 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002995 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002996 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002997
2998 channel_count = (sad[0] & 0x7) + 1;
2999 if (channel_count > max_channels)
3000 max_channels = channel_count;
3001
3002 /* Advance to next block */
3003 sad += 3;
3004 }
3005
3006 return max_channels;
3007}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003008
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003009int platform_set_incall_recording_session_id(void *platform,
3010 uint32_t session_id, int rec_mode)
3011{
3012 int ret = 0;
3013 struct platform_data *my_data = (struct platform_data *)platform;
3014 struct audio_device *adev = my_data->adev;
3015 struct mixer_ctl *ctl;
3016 const char *mixer_ctl_name = "Voc VSID";
3017 int num_ctl_values;
3018 int i;
3019
3020 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3021 if (!ctl) {
3022 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3023 __func__, mixer_ctl_name);
3024 ret = -EINVAL;
3025 } else {
3026 num_ctl_values = mixer_ctl_get_num_values(ctl);
3027 for (i = 0; i < num_ctl_values; i++) {
3028 if (mixer_ctl_set_value(ctl, i, session_id)) {
3029 ALOGV("Error: invalid session_id: %x", session_id);
3030 ret = -EINVAL;
3031 break;
3032 }
3033 }
3034 }
3035
3036 if (my_data->csd != NULL) {
3037 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3038 if (ret < 0) {
3039 ALOGE("%s: csd_client_start_record failed, error %d",
3040 __func__, ret);
3041 }
3042 }
3043
3044 return ret;
3045}
3046
3047int platform_stop_incall_recording_usecase(void *platform)
3048{
3049 int ret = 0;
3050 struct platform_data *my_data = (struct platform_data *)platform;
3051
3052 if (my_data->csd != NULL) {
3053 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3054 if (ret < 0) {
3055 ALOGE("%s: csd_client_stop_record failed, error %d",
3056 __func__, ret);
3057 }
3058 }
3059
3060 return ret;
3061}
3062
3063int platform_start_incall_music_usecase(void *platform)
3064{
3065 int ret = 0;
3066 struct platform_data *my_data = (struct platform_data *)platform;
3067
3068 if (my_data->csd != NULL) {
3069 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3070 if (ret < 0) {
3071 ALOGE("%s: csd_client_start_playback failed, error %d",
3072 __func__, ret);
3073 }
3074 }
3075
3076 return ret;
3077}
3078
3079int platform_stop_incall_music_usecase(void *platform)
3080{
3081 int ret = 0;
3082 struct platform_data *my_data = (struct platform_data *)platform;
3083
3084 if (my_data->csd != NULL) {
3085 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3086 if (ret < 0) {
3087 ALOGE("%s: csd_client_stop_playback failed, error %d",
3088 __func__, ret);
3089 }
3090 }
3091
3092 return ret;
3093}
3094
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003095int platform_set_parameters(void *platform, struct str_parms *parms)
3096{
3097 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09003098 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003099 char *kv_pairs = str_parms_to_str(parms);
3100 int ret = 0, err;
3101
3102 if (kv_pairs == NULL) {
3103 ret = -EINVAL;
3104 ALOGE("%s: key-value pair is NULL",__func__);
3105 goto done;
3106 }
3107
3108 ALOGV("%s: enter: %s", __func__, kv_pairs);
3109
3110 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
3111 value, sizeof(value));
3112 if (err >= 0) {
3113 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3114 my_data->snd_card_name = strdup(value);
3115 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3116 }
3117
keunhui.park2f7306a2015-07-16 16:48:06 +09003118 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
3119 value, sizeof(value));
3120 if (err >= 0) {
3121 struct operator_info *info;
3122 char *str = value;
3123 char *name;
3124
3125 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3126 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3127 name = strtok(str, ";");
3128 info->name = strdup(name);
3129 info->mccmnc = strdup(str + strlen(name) + 1);
3130
3131 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003132 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003133 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003134
3135 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07003136 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07003137 value, sizeof(value));
3138 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003139 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003140 my_data->max_mic_count = atoi(value);
3141 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003142 }
3143
vivek mehta90933872017-06-15 18:04:39 -07003144 // to-do: disable setting sidetone gain, will revist this later
3145 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003146done:
3147 ALOGV("%s: exit with code(%d)", __func__, ret);
3148 if (kv_pairs != NULL)
3149 free(kv_pairs);
3150
3151 return ret;
3152}
3153
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003154/* Delay in Us */
3155int64_t platform_render_latency(audio_usecase_t usecase)
3156{
3157 switch (usecase) {
3158 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3159 return DEEP_BUFFER_PLATFORM_DELAY;
3160 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3161 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003162 case USECASE_AUDIO_PLAYBACK_ULL:
3163 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003164 case USECASE_AUDIO_PLAYBACK_MMAP:
3165 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003166 default:
3167 return 0;
3168 }
3169}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003170
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003171int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3172 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003173{
3174 int ret = 0;
3175
3176 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3177 ALOGE("%s: Invalid snd_device = %d",
3178 __func__, device);
3179 ret = -EINVAL;
3180 goto done;
3181 }
3182
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003183 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3184 platform_get_snd_device_name(device),
3185 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3186 if (backend_tag_table[device]) {
3187 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003188 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003189 backend_tag_table[device] = strdup(backend_tag);
3190
3191 if (hw_interface != NULL) {
3192 if (hw_interface_table[device])
3193 free(hw_interface_table[device]);
3194 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3195 hw_interface_table[device] = strdup(hw_interface);
3196 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003197done:
3198 return ret;
3199}
3200
3201int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3202{
3203 int ret = 0;
3204 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3205 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3206 ret = -EINVAL;
3207 goto done;
3208 }
3209
3210 if ((type != 0) && (type != 1)) {
3211 ALOGE("%s: invalid usecase type", __func__);
3212 ret = -EINVAL;
3213 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003214 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3215 use_case_table[usecase],
3216 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003217 pcm_device_table[usecase][type] = pcm_id;
3218done:
3219 return ret;
3220}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003221
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003222#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3223int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3224 // backup_gain: gain to try to set in case of an error during ramp
3225 int start_gain, end_gain, step, backup_gain, i;
3226 bool error = false;
3227 const struct mixer_ctl *ctl;
3228 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3229 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3230 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3231 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3232 if (!ctl_left || !ctl_right) {
3233 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3234 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3235 return -EINVAL;
3236 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3237 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3238 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3239 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3240 return -EINVAL;
3241 }
3242 if (ramp_up) {
3243 start_gain = 0;
3244 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3245 step = +1;
3246 backup_gain = end_gain;
3247 } else {
3248 // using same gain on left and right
3249 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3250 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3251 end_gain = 0;
3252 step = -1;
3253 backup_gain = start_gain;
3254 }
3255 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3256 //ALOGV("setting speaker gain to %d", i);
3257 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3258 ALOGE("%s: error setting %s to %d during gain ramp",
3259 __func__, mixer_ctl_name_gain_left, i);
3260 error = true;
3261 break;
3262 }
3263 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3264 ALOGE("%s: error setting %s to %d during gain ramp",
3265 __func__, mixer_ctl_name_gain_right, i);
3266 error = true;
3267 break;
3268 }
3269 usleep(1000);
3270 }
3271 if (error) {
3272 // an error occured during the ramp, let's still try to go back to a safe volume
3273 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3274 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3275 }
3276 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3277 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3278 }
3279 }
3280 return start_gain;
3281}
3282
vivek mehtae59cfb22017-06-16 15:57:11 -07003283int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3284{
3285 const char *mixer_ctl_name = "Swap channel";
3286 struct mixer_ctl *ctl;
3287 const char *mixer_path;
3288 struct platform_data *my_data = (struct platform_data *)adev->platform;
3289
3290 // forced to set to swap, but device not rotated ... ignore set
3291 if (swap_channels && !my_data->speaker_lr_swap)
3292 return 0;
3293
3294 ALOGV("%s:", __func__);
3295
3296 if (swap_channels) {
3297 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3298 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3299 } else {
3300 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3301 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3302 }
3303
3304 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3305 if (!ctl) {
3306 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3307 return -EINVAL;
3308 }
3309
3310 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3311 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3312 return -EINVAL;
3313 }
3314
3315 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3316 swap_channels?"R --> L":"L --> R");
3317
3318 return 0;
3319}
3320
3321int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003322{
3323 // only update if there is active pcm playback on speaker
3324 struct audio_usecase *usecase;
3325 struct listnode *node;
3326 struct platform_data *my_data = (struct platform_data *)adev->platform;
3327
vivek mehtae59cfb22017-06-16 15:57:11 -07003328 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003329
vivek mehtae59cfb22017-06-16 15:57:11 -07003330 return platform_set_swap_channels(adev, swap_channels);
3331}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003332
vivek mehtae59cfb22017-06-16 15:57:11 -07003333int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3334{
3335 // only update if there is active pcm playback on speaker
3336 struct audio_usecase *usecase;
3337 struct listnode *node;
3338 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003339
vivek mehtae59cfb22017-06-16 15:57:11 -07003340 // do not swap channels in audio modes with concurrent capture and playback
3341 // as this may break the echo reference
3342 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3343 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3344 return 0;
3345 }
3346
3347 list_for_each(node, &adev->usecase_list) {
3348 usecase = node_to_item(node, struct audio_usecase, list);
3349 if (usecase->type == PCM_PLAYBACK &&
3350 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3351 /*
3352 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3353 * to perform device switch to disable the current backend to
3354 * enable it with new acdb data.
3355 */
3356 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3357 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3358 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3359 select_devices(adev, usecase->id);
3360 if (initial_skpr_gain != -EINVAL)
3361 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3362
3363 } else {
3364 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003365 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003366 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003367 }
3368 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003369
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003370 return 0;
3371}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003372
3373static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3374static int num_gain_tbl_entry = 0;
3375
3376bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3377
3378 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3379 if (num_gain_tbl_entry == -1) {
3380 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3381 __func__);
3382 return false;
3383 }
3384
3385 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3386 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3387 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3388 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3389 return false;
3390 }
3391
3392 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3393 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3394 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3395 return false;
3396 }
3397
3398 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3399 ++num_gain_tbl_entry;
3400
3401 return true;
3402}
3403
3404int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3405 int table_size) {
3406 int itt = 0;
3407 ALOGV("platform_get_gain_level_mapping called ");
3408
3409 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3410 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3411 return 0;
3412 }
3413
3414 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3415 mapping_tbl[itt] = tbl_mapping[itt];
3416 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3417 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3418 }
3419
3420 return num_gain_tbl_entry;
3421}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003422
3423int platform_snd_card_update(void *platform, card_status_t status)
3424{
3425 struct platform_data *my_data = (struct platform_data *)platform;
3426 struct audio_device *adev = my_data->adev;
3427
3428 if (status == CARD_STATUS_ONLINE) {
3429 if (my_data->acdb_send_custom_top)
3430 my_data->acdb_send_custom_top();
3431 }
3432 return 0;
3433}
David Linee3fe402017-03-13 10:00:42 -07003434
3435/*
3436 * configures afe with bit width and Sample Rate
3437 */
3438static int platform_set_backend_cfg(const struct audio_device* adev,
3439 snd_device_t snd_device,
3440 const struct audio_backend_cfg *backend_cfg)
3441{
3442
3443 int ret = 0;
3444 const int backend_idx = platform_get_backend_index(snd_device);
3445 struct platform_data *my_data = (struct platform_data *)adev->platform;
3446 const unsigned int bit_width = backend_cfg->bit_width;
3447 const unsigned int sample_rate = backend_cfg->sample_rate;
3448 const unsigned int channels = backend_cfg->channels;
3449 const audio_format_t format = backend_cfg->format;
3450 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3451
3452
3453 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3454 ", backend_idx %d device (%s)", __func__, bit_width,
3455 sample_rate, channels, backend_idx,
3456 platform_get_snd_device_name(snd_device));
3457
3458 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3459 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3460
3461 struct mixer_ctl *ctl = NULL;
3462 ctl = mixer_get_ctl_by_name(adev->mixer,
3463 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3464 if (!ctl) {
3465 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3466 __func__,
3467 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3468 return -EINVAL;
3469 }
3470
3471 if (bit_width == 24) {
3472 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3473 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3474 else
3475 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3476 } else if (bit_width == 32) {
3477 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3478 } else {
3479 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3480 }
3481 if ( ret < 0) {
3482 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3483 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3484 } else {
3485 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3486 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3487 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3488 }
3489 /* set the ret as 0 and not pass back to upper layer */
3490 ret = 0;
3491 }
3492
3493 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3494 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3495 char *rate_str = NULL;
3496 struct mixer_ctl *ctl = NULL;
3497
3498 switch (sample_rate) {
3499 case 32000:
3500 if (passthrough_enabled) {
3501 rate_str = "KHZ_32";
3502 break;
3503 }
3504 case 8000:
3505 case 11025:
3506 case 16000:
3507 case 22050:
3508 case 48000:
3509 rate_str = "KHZ_48";
3510 break;
3511 case 44100:
3512 rate_str = "KHZ_44P1";
3513 break;
3514 case 64000:
3515 case 96000:
3516 rate_str = "KHZ_96";
3517 break;
3518 case 88200:
3519 rate_str = "KHZ_88P2";
3520 break;
3521 case 176400:
3522 rate_str = "KHZ_176P4";
3523 break;
3524 case 192000:
3525 rate_str = "KHZ_192";
3526 break;
3527 case 352800:
3528 rate_str = "KHZ_352P8";
3529 break;
3530 case 384000:
3531 rate_str = "KHZ_384";
3532 break;
3533 case 144000:
3534 if (passthrough_enabled) {
3535 rate_str = "KHZ_144";
3536 break;
3537 }
3538 default:
3539 rate_str = "KHZ_48";
3540 break;
3541 }
3542
3543 ctl = mixer_get_ctl_by_name(adev->mixer,
3544 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3545 if(!ctl) {
3546 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3547 __func__,
3548 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3549 return -EINVAL;
3550 }
3551
3552 ALOGD("%s:becf: afe: %s set to %s", __func__,
3553 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3554 mixer_ctl_set_enum_by_string(ctl, rate_str);
3555 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3556 }
3557 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3558 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3559 struct mixer_ctl *ctl = NULL;
3560 char *channel_cnt_str = NULL;
3561
3562 switch (channels) {
3563 case 8:
3564 channel_cnt_str = "Eight"; break;
3565 case 7:
3566 channel_cnt_str = "Seven"; break;
3567 case 6:
3568 channel_cnt_str = "Six"; break;
3569 case 5:
3570 channel_cnt_str = "Five"; break;
3571 case 4:
3572 channel_cnt_str = "Four"; break;
3573 case 3:
3574 channel_cnt_str = "Three"; break;
3575 case 1:
3576 channel_cnt_str = "One"; break;
3577 case 2:
3578 default:
3579 channel_cnt_str = "Two"; break;
3580 }
3581
3582 ctl = mixer_get_ctl_by_name(adev->mixer,
3583 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3584 if (!ctl) {
3585 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3586 __func__,
3587 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3588 return -EINVAL;
3589 }
3590 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3591 my_data->current_backend_cfg[backend_idx].channels = channels;
3592
3593 // skip EDID configuration for HDMI backend
3594
3595 ALOGD("%s:becf: afe: %s set to %s", __func__,
3596 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3597 channel_cnt_str);
3598 }
3599
3600 // skip set ext_display format mixer control
3601 return ret;
3602}
3603
3604static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3605{
3606 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3607 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3608 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3609 }
3610
3611 return backend_bit_width_table[snd_device];
3612}
3613
3614/*
3615 * return backend_idx on which voice call is active
3616 */
3617static int platform_get_voice_call_backend(struct audio_device* adev)
3618{
3619 struct audio_usecase *uc = NULL;
3620 struct listnode *node;
3621 snd_device_t out_snd_device = SND_DEVICE_NONE;
3622
3623 int backend_idx = -1;
3624
3625 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3626 list_for_each(node, &adev->usecase_list) {
3627 uc = node_to_item(node, struct audio_usecase, list);
3628 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3629 out_snd_device = platform_get_output_snd_device(adev->platform,
3630 uc->stream.out->devices);
3631 backend_idx = platform_get_backend_index(out_snd_device);
3632 break;
3633 }
3634 }
3635 }
3636 return backend_idx;
3637}
3638
3639/*
3640 * goes through all the current usecases and picks the highest
3641 * bitwidth & samplerate
3642 */
3643static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3644 int backend_idx,
3645 struct audio_backend_cfg *backend_cfg)
3646{
3647 bool backend_change = false;
3648 unsigned int bit_width;
3649 unsigned int sample_rate;
3650 unsigned int channels;
3651 struct platform_data *my_data = (struct platform_data *)adev->platform;
3652
3653 bit_width = backend_cfg->bit_width;
3654 sample_rate = backend_cfg->sample_rate;
3655 channels = backend_cfg->channels;
3656
3657 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3658 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3659 sample_rate, channels);
3660
3661 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3662 // default backend
3663 // force routing is not required here, caller will do it anyway
3664 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3665 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3666 "for unprocessed/camera source", __func__);
3667 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3668 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3669 }
3670
3671 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3672 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3673 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3674 __func__, bit_width, sample_rate, channels);
3675 }
3676
3677 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3678 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3679
3680 // Force routing if the expected bitwdith or samplerate
3681 // is not same as current backend comfiguration
3682 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3683 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3684 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3685 backend_cfg->bit_width = bit_width;
3686 backend_cfg->sample_rate= sample_rate;
3687 backend_cfg->channels = channels;
3688 backend_change = true;
3689 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3690 "new sample rate: %d new channel: %d",
3691 __func__, backend_cfg->bit_width,
3692 backend_cfg->sample_rate, backend_cfg->channels);
3693 }
3694
3695 return backend_change;
3696}
3697
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003698static void pick_playback_cfg_for_uc(struct audio_device *adev,
3699 struct audio_usecase *usecase,
3700 snd_device_t snd_device,
3701 unsigned int *bit_width,
3702 unsigned int *sample_rate,
3703 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003704{
3705 int i =0;
3706 struct listnode *node;
3707 list_for_each(node, &adev->usecase_list) {
3708 struct audio_usecase *uc;
3709 uc = node_to_item(node, struct audio_usecase, list);
3710 struct stream_out *out = (struct stream_out*) uc->stream.out;
3711 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3712 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3713 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3714 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3715 uc->id, out->sample_rate,
3716 pcm_format_to_bits(out->config.format), out_channels,
3717 platform_get_snd_device_name(uc->out_snd_device));
3718
3719 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3720 if (*bit_width < pcm_format_to_bits(out->config.format))
3721 *bit_width = pcm_format_to_bits(out->config.format);
3722 if (*sample_rate < out->sample_rate)
3723 *sample_rate = out->sample_rate;
3724 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3725 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3726 if (*channels < out_channels)
3727 *channels = out_channels;
3728 }
3729 }
3730 }
3731 return;
3732}
3733
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003734static void headset_is_config_supported(unsigned int *bit_width,
3735 unsigned int *sample_rate,
3736 unsigned int *channels) {
3737 switch (*bit_width) {
3738 case 16:
3739 case 24:
3740 break;
3741 default:
3742 *bit_width = 16;
3743 break;
3744 }
3745
3746 if (*sample_rate > 192000) {
3747 *sample_rate = 192000;
3748 }
3749
3750 if (*channels > 2) {
3751 *channels = 2;
3752 }
3753}
3754
David Linee3fe402017-03-13 10:00:42 -07003755static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3756 struct audio_usecase* usecase,
3757 snd_device_t snd_device,
3758 struct audio_backend_cfg *backend_cfg)
3759{
3760 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003761 unsigned int bit_width;
3762 unsigned int sample_rate;
3763 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003764 int backend_idx = DEFAULT_CODEC_BACKEND;
3765 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003766
3767 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3768 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3769 backend_change = false;
3770 return backend_change;
3771 }
3772
3773 backend_idx = platform_get_backend_index(snd_device);
3774 bit_width = backend_cfg->bit_width;
3775 sample_rate = backend_cfg->sample_rate;
3776 channels = backend_cfg->channels;
3777
3778 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3779 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3780 sample_rate, channels, backend_idx, usecase->id,
3781 platform_get_snd_device_name(snd_device));
3782
3783 if (backend_idx == platform_get_voice_call_backend(adev)) {
3784 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3785 __func__);
3786 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3787 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3788 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3789 } else {
3790 /*
3791 * The backend should be configured at highest bit width and/or
3792 * sample rate amongst all playback usecases.
3793 * If the selected sample rate and/or bit width differ with
3794 * current backend sample rate and/or bit width, then, we set the
3795 * backend re-configuration flag.
3796 *
3797 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3798 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003799 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3800 &bit_width,
3801 &sample_rate,
3802 &channels);
David Linee3fe402017-03-13 10:00:42 -07003803 }
3804
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003805 switch (backend_idx) {
3806 case USB_AUDIO_RX_BACKEND:
3807 audio_extn_usb_is_config_supported(&bit_width,
3808 &sample_rate, &channels, true);
3809 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3810 __func__, bit_width, sample_rate, channels);
3811 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003812 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003813 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3814 break;
3815 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003816 default:
3817 bit_width = platform_get_snd_device_bit_width(snd_device);
3818 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3819 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3820 break;
David Linee3fe402017-03-13 10:00:42 -07003821 }
3822
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003823 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3824 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003825 __func__, backend_idx , bit_width, sample_rate);
3826
3827 // Force routing if the expected bitwdith or samplerate
3828 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003829 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3830 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3831 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003832 backend_cfg->bit_width = bit_width;
3833 backend_cfg->sample_rate = sample_rate;
3834 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003835 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003836 backend_change = true;
3837 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3838 "new sample rate: %d new channels: %d",
3839 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3840 }
3841
3842 return backend_change;
3843}
3844
3845bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3846 struct audio_usecase *usecase, snd_device_t snd_device)
3847{
3848 int backend_idx = DEFAULT_CODEC_BACKEND;
3849 int new_snd_devices[SND_DEVICE_OUT_END];
3850 int i, num_devices = 1;
3851 bool ret = false;
3852 struct platform_data *my_data = (struct platform_data *)adev->platform;
3853 struct audio_backend_cfg backend_cfg;
3854
3855 backend_idx = platform_get_backend_index(snd_device);
3856
3857 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3858 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3859 backend_cfg.format = usecase->stream.out->format;
3860 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3861 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3862 backend_cfg.passthrough_enabled = false;
3863
3864 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3865 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3866 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3867 platform_get_snd_device_name(snd_device));
3868
3869 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3870 new_snd_devices[0] = snd_device;
3871
3872 for (i = 0; i < num_devices; i++) {
3873 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3874 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3875 &backend_cfg))) {
3876 platform_set_backend_cfg(adev, new_snd_devices[i],
3877 &backend_cfg);
3878 ret = true;
3879 }
3880 }
3881 return ret;
3882}
3883
3884bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3885 struct audio_usecase *usecase, snd_device_t snd_device)
3886{
3887 int backend_idx = platform_get_backend_index(snd_device);
3888 int ret = 0;
3889 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003890 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003891
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003892 if (usecase->type == PCM_CAPTURE) {
3893 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003894 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3895 } else {
3896 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3897 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3898 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3899 backend_cfg.channels = 1;
3900 }
3901
3902 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3903 ", backend_idx %d usecase = %d device (%s)", __func__,
3904 backend_cfg.bit_width,
3905 backend_cfg.sample_rate,
3906 backend_cfg.channels,
3907 backend_idx, usecase->id,
3908 platform_get_snd_device_name(snd_device));
3909
3910 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3911 ret = platform_set_backend_cfg(adev, snd_device,
3912 &backend_cfg);
3913 if(!ret)
3914 return true;
3915 }
3916
3917 return false;
3918}
3919
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003920static int max_be_dai_names = 0;
3921static const struct be_dai_name_struct *be_dai_name_table;
3922
3923/*
3924 * Retrieves the be_dai_name_table from kernel to enable a mapping
3925 * between sound device hw interfaces and backend IDs. This allows HAL to
3926 * specify the backend a specific calibration is needed for.
3927 */
3928static int init_be_dai_name_table(struct audio_device *adev)
3929{
3930 const char *mixer_ctl_name = "Backend DAI Name Table";
3931 struct mixer_ctl *ctl;
3932 int i, j, ret, size;
3933 bool valid_hw_interface;
3934
3935 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3936 if (!ctl) {
3937 ALOGE("%s: Could not get ctl for mixer name %s\n",
3938 __func__, mixer_ctl_name);
3939 ret = -EINVAL;
3940 goto done;
3941 }
3942
3943 mixer_ctl_update(ctl);
3944
3945 size = mixer_ctl_get_num_values(ctl);
3946 if (size <= 0){
3947 ALOGE("%s: Failed to get %s size %d\n",
3948 __func__, mixer_ctl_name, size);
3949 ret = -EFAULT;
3950 goto done;
3951 }
3952
vivek mehtaa68fea62017-06-08 19:04:02 -07003953 be_dai_name_table =
3954 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003955 if (be_dai_name_table == NULL) {
3956 ALOGE("%s: Failed to allocate memory for %s\n",
3957 __func__, mixer_ctl_name);
3958 ret = -ENOMEM;
3959 goto freeMem;
3960 }
3961
3962 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
3963 if (ret) {
3964 ALOGE("%s: Failed to get %s, ret %d\n",
3965 __func__, mixer_ctl_name, ret);
3966 ret = -EFAULT;
3967 goto freeMem;
3968 }
3969
3970 if (be_dai_name_table != NULL) {
3971 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
3972 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
3973 __func__, mixer_ctl_name, max_be_dai_names);
3974 ret = 0;
3975 } else {
3976 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
3977 ret = -EFAULT;
3978 goto freeMem;
3979 }
3980
3981 /*
3982 * Validate all sound devices have a valid backend set to catch
3983 * errors for uncommon sound devices
3984 */
3985 for (i = 0; i < SND_DEVICE_MAX; i++) {
3986 valid_hw_interface = false;
3987
3988 if (hw_interface_table[i] == NULL) {
3989 ALOGW("%s: sound device %s has no hw interface set\n",
3990 __func__, platform_get_snd_device_name(i));
3991 continue;
3992 }
3993
3994 for (j = 0; j < max_be_dai_names; j++) {
3995 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
3996 == 0) {
3997 valid_hw_interface = true;
3998 break;
3999 }
4000 }
4001 if (!valid_hw_interface)
4002 ALOGD("%s: sound device %s does not have a valid hw interface set "
4003 "(disregard for combo devices) %s\n",
4004 __func__, platform_get_snd_device_name(i),
4005 hw_interface_table[i]);
4006 }
4007
4008 goto done;
4009
4010freeMem:
4011 if (be_dai_name_table) {
4012 free((void *)be_dai_name_table);
4013 be_dai_name_table = NULL;
4014 }
4015
4016done:
4017 return ret;
4018}
4019
4020int platform_get_snd_device_backend_index(snd_device_t device)
4021{
4022 int i, be_dai_id;
4023 const char * hw_interface_name = NULL;
4024
4025 ALOGV("%s: enter with device %d\n", __func__, device);
4026
vivek mehtaa68fea62017-06-08 19:04:02 -07004027 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004028 ALOGE("%s: Invalid snd_device = %d",
4029 __func__, device);
4030 be_dai_id = -EINVAL;
4031 goto done;
4032 }
4033
4034 /* Get string value of necessary backend for device */
4035 hw_interface_name = hw_interface_table[device];
4036 if (hw_interface_name == NULL) {
4037 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4038 be_dai_id = -EINVAL;
4039 goto done;
4040 }
4041
4042 /* Check if be dai name table was retrieved successfully */
4043 if (be_dai_name_table == NULL) {
4044 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4045 be_dai_id = -EFAULT;
4046 goto done;
4047 }
4048
4049 /* Get backend ID for device specified */
4050 for (i = 0; i < max_be_dai_names; i++) {
4051 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4052 be_dai_id = be_dai_name_table[i].be_id;
4053 goto done;
4054 }
4055 }
4056 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4057 be_dai_id = -EINVAL;
4058 goto done;
4059
4060done:
4061 return be_dai_id;
4062}
4063
4064void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4065 unsigned int stream_sr, int* sample_rate)
4066{
4067 struct platform_data* my_data = (struct platform_data *)platform;
4068 int backend_idx = platform_get_backend_index(snd_device);
4069 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4070 /*
4071 *Check if device SR is multiple of 8K or 11.025 Khz
4072 *check if the stream SR is multiple of same base, if yes
4073 *then have copp SR equal to stream SR, this ensures that
4074 *post processing happens at stream SR, else have
4075 *copp SR equal to device SR.
4076 */
4077 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4078 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4079 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4080 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4081 *sample_rate = device_sr;
4082 } else
4083 *sample_rate = stream_sr;
4084
4085 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4086 , *sample_rate);
4087
4088}
4089
4090// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004091void platform_add_app_type(const char *uc_type,
4092 const char *mode,
4093 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004094 int app_type, int max_rate) {
4095 struct app_type_entry *ap =
4096 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4097
4098 if (!ap) {
4099 ALOGE("%s failed to allocate mem for app type", __func__);
4100 return;
4101 }
4102
4103 ap->uc_type = -1;
4104 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4105 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4106 ap->uc_type = usecase_type_index[i].index;
4107 break;
4108 }
4109 }
4110
4111 if (ap->uc_type == -1) {
4112 free(ap);
4113 return;
4114 }
4115
vivek mehtaa68fea62017-06-08 19:04:02 -07004116 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4117 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004118 ap->bit_width = bw;
4119 ap->app_type = app_type;
4120 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004121 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004122 list_add_tail(&app_type_entry_list, &ap->node);
4123}
4124
4125
4126int platform_get_default_app_type_v2(void *platform __unused,
4127 usecase_type_t type,
4128 int *app_type )
4129{
4130 if (type == PCM_PLAYBACK)
4131 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4132 else
4133 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4134 return 0;
4135}
4136
vivek mehtaa68fea62017-06-08 19:04:02 -07004137int platform_get_app_type_v2(void *platform,
4138 usecase_type_t uc_type,
4139 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004140 int bw, int sr __unused,
4141 int *app_type)
4142{
4143 struct listnode *node;
4144 struct app_type_entry *entry;
4145 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004146
4147 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4148 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004149 list_for_each(node, &app_type_entry_list) {
4150 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004151 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4152 __func__, entry->uc_type, entry->mode, entry->bit_width,
4153 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004154 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004155 entry->uc_type == uc_type &&
4156 sr <= entry->max_rate &&
4157 entry->mode && !strcmp(mode, entry->mode)) {
4158 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004159 *app_type = entry->app_type;
4160 break;
4161 }
4162 }
4163
4164 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004165 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004166 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4167 }
4168 return 0;
4169}
vivek mehta90933872017-06-15 18:04:39 -07004170
4171int platform_set_sidetone(struct audio_device *adev,
4172 snd_device_t out_snd_device,
4173 bool enable, char *str)
4174{
4175 int ret;
4176 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4177 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4178 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4179 if (ret)
4180 ALOGI("%s: usb device %d does not support device sidetone\n",
4181 __func__, out_snd_device);
4182 } else {
4183 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4184 __func__, out_snd_device, str);
4185 if (enable)
4186 audio_route_apply_and_update_path(adev->audio_route, str);
4187 else
4188 audio_route_reset_and_update_path(adev->audio_route, str);
4189 }
4190 return 0;
4191}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004192
4193int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4194 int *fd __unused, uint32_t *size __unused)
4195{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004196#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004197 struct platform_data *my_data = (struct platform_data *)platform;
4198 struct audio_device *adev = my_data->adev;
4199 int hw_fd = -1;
4200 char dev_name[128];
4201 struct snd_pcm_mmap_fd mmap_fd;
4202 memset(&mmap_fd, 0, sizeof(mmap_fd));
4203 mmap_fd.dir = dir;
4204 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4205 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4206 hw_fd = open(dev_name, O_RDONLY);
4207 if (hw_fd < 0) {
4208 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4209 return -1;
4210 }
4211 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4212 ALOGE("fe hw dep node ioctl failed");
4213 close(hw_fd);
4214 return -1;
4215 }
4216 *fd = mmap_fd.fd;
4217 *size = mmap_fd.size;
4218 close(hw_fd); // mmap_fd should still be valid
4219 return 0;
4220#else
4221 return -1;
4222#endif
4223}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004224
4225bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4226{
4227 bool needs_event = false;
4228
4229 switch (uc_id) {
4230 /* concurrent capture usecases which needs event */
4231 case USECASE_AUDIO_RECORD:
4232 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4233 case USECASE_AUDIO_RECORD_MMAP:
4234 case USECASE_AUDIO_RECORD_HIFI:
4235 case USECASE_AUDIO_RECORD_VOIP:
4236 case USECASE_VOICEMMODE1_CALL:
4237 case USECASE_VOICEMMODE2_CALL:
4238 /* concurrent playback usecases that needs event */
4239 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4240 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4241 needs_event = true;
4242 break;
4243 default:
4244 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4245 }
4246 return needs_event;
4247}
4248
4249bool platform_snd_device_has_speaker(snd_device_t dev) {
4250 int num_devs = 2;
4251 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4252 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4253 return platform_snd_device_has_speaker(split_devs[0]) ||
4254 platform_snd_device_has_speaker(split_devs[1]);
4255 }
4256
4257 switch (dev) {
4258 case SND_DEVICE_OUT_SPEAKER:
4259 case SND_DEVICE_OUT_SPEAKER_SAFE:
4260 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4261 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4262 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4263 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4264 return true;
4265 default:
4266 break;
4267 }
4268 return false;
4269}