blob: 820b47f9fac602ff8a24ba489b10d3391cfae289 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa6b79742017-03-09 15:40:43 -08002 * Copyright (C) 2013-2017 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Eric Laurentb23d5282013-05-14 15:27:20 -070016#define LOG_TAG "msm8974_platform"
17/*#define LOG_NDEBUG 0*/
18#define LOG_NDDEBUG 0
19
20#include <stdlib.h>
21#include <dlfcn.h>
Jiyong Park6431fe62017-06-29 15:15:58 +090022#include <pthread.h>
23#include <unistd.h>
Haynes Mathew Georgee6e2d442018-02-22 18:51:56 -080024#include <log/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070025#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070026#include <cutils/properties.h>
27#include <audio_hw.h>
28#include <platform_api.h>
vivek mehta0fb11312017-05-15 19:35:32 -070029#include "acdb.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070030#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070031#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070032#include <linux/msm_audio.h>
Alexey Polyudove920d4b2017-09-15 17:09:07 -070033#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -070034#include <sound/devdep_params.h>
35#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070036
jasmine cha270b7762018-03-30 15:41:33 +080037#include "maxxaudio.h"
jasmine chac89321b2018-04-10 21:37:01 +080038#include <resolv.h>
39
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090040#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
41#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080042#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
43#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
44
Eric Laurentb23d5282013-05-14 15:27:20 -070045#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070046#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090047#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070048
Eric Laurentf9583c32016-03-28 13:50:50 -070049#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070050
51/*
Eric Laurentb23d5282013-05-14 15:27:20 -070052 * This file will have a maximum of 38 bytes:
53 *
54 * 4 bytes: number of audio blocks
55 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
56 * Maximum 10 * 3 bytes: SAD blocks
57 */
58#define MAX_SAD_BLOCKS 10
59#define SAD_BLOCK_SIZE 3
60
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090061#define MAX_CVD_VERSION_STRING_SIZE 100
62
Eric Laurentb23d5282013-05-14 15:27:20 -070063/* EDID format ID for LPCM audio */
64#define EDID_FORMAT_LPCM 1
65
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070066#define MAX_SND_CARD_NAME_LEN 31
67
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080068#define DEFAULT_APP_TYPE_RX_PATH 69936
69#define DEFAULT_APP_TYPE_TX_PATH 69938
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070070#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
vivek mehta1a9b7c02015-06-25 11:49:38 -070071
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090072#define TOSTRING_(x) #x
73#define TOSTRING(x) TOSTRING_(x)
74
Eric Laurentb23d5282013-05-14 15:27:20 -070075struct audio_block_header
76{
77 int reserved;
78 int length;
79};
80
vivek mehta1a9b7c02015-06-25 11:49:38 -070081enum {
82 CAL_MODE_SEND = 0x1,
83 CAL_MODE_PERSIST = 0x2,
84 CAL_MODE_RTAC = 0x4
85};
86
keunhui.park2f7306a2015-07-16 16:48:06 +090087#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
88
89struct operator_info {
90 struct listnode list;
91 char *name;
92 char *mccmnc;
93};
94
95struct operator_specific_device {
96 struct listnode list;
97 char *operator;
98 char *mixer_path;
99 int acdb_id;
100};
101
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800102#define BE_DAI_NAME_MAX_LENGTH 24
103struct be_dai_name_struct {
104 unsigned int be_id;
105 char be_name[BE_DAI_NAME_MAX_LENGTH];
106};
107
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700108struct snd_device_to_mic_map {
109 struct mic_info microphones[AUDIO_MICROPHONE_MAX_COUNT];
110 size_t mic_count;
111};
112
keunhui.park2f7306a2015-07-16 16:48:06 +0900113static struct listnode operator_info_list;
114static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
115
jasmine chac89321b2018-04-10 21:37:01 +0800116#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
117
118typedef struct acdb_audio_cal_cfg {
119 uint32_t persist;
120 uint32_t snd_dev_id;
121 audio_devices_t dev_id;
122 int32_t acdb_dev_id;
123 uint32_t app_type;
124 uint32_t topo_id;
125 uint32_t sampling_rate;
126 uint32_t cal_type;
127 uint32_t module_id;
128 uint32_t param_id;
129} acdb_audio_cal_cfg_t;
130
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700131/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800132typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700133
Eric Laurentb23d5282013-05-14 15:27:20 -0700134struct platform_data {
135 struct audio_device *adev;
136 bool fluence_in_spkr_mode;
137 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700138 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700139 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700140 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
141 int fluence_type;
142 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700143 bool speaker_lr_swap;
144
Eric Laurentb23d5282013-05-14 15:27:20 -0700145 void *acdb_handle;
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700146#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700147 acdb_init_v2_cvd_t acdb_init;
148#elif defined (PLATFORM_MSM8084)
149 acdb_init_v2_t acdb_init;
150#else
151 acdb_init_t acdb_init;
152#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700153 acdb_deallocate_t acdb_deallocate;
154 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800155 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
jasmine chac89321b2018-04-10 21:37:01 +0800156 acdb_set_audio_cal_t acdb_set_audio_cal;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700157 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700158 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700159 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700160 acdb_send_custom_top_t acdb_send_custom_top;
161 bool acdb_initialized;
162
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700163 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800164 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700165
David Linee3fe402017-03-13 10:00:42 -0700166 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700167 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900168 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700169 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800170
171 void *hw_info;
jiabin8962a4d2018-03-19 18:21:24 -0700172
173 uint32_t declared_mic_count;
174 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -0700175 struct snd_device_to_mic_map mic_map[SND_DEVICE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -0700176};
177
Haynes Mathew George98c95622014-06-20 19:14:25 -0700178static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700179 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
180 DEEP_BUFFER_PCM_DEVICE},
181 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
182 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800183 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700184 MULTIMEDIA2_PCM_DEVICE},
185 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
186 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700187 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
188 MULTIMEDIA2_PCM_DEVICE},
189 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
190 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800191 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
192 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700193
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700194 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
195 AUDIO_RECORD_PCM_DEVICE},
196 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
197 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700198
Eric Laurent0e46adf2016-12-16 12:49:24 -0800199 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
200 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700201 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
202 MULTIMEDIA2_PCM_DEVICE},
203
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700204 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
205 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700206 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
207 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
208 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
209 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800210 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
211 VOICEMMODE1_CALL_PCM_DEVICE},
212 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
213 VOICEMMODE2_CALL_PCM_DEVICE},
214
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700215 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
216 AUDIO_RECORD_PCM_DEVICE},
217 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
218 AUDIO_RECORD_PCM_DEVICE},
219 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
220 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800221 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700222
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700223 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
224 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
225
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700226 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
227 AFE_PROXY_RECORD_PCM_DEVICE},
228 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
229 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800230 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700231
vivek mehtaa68fea62017-06-08 19:04:02 -0700232 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
233 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
234 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
235 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200236
237 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
238 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700239};
240
241/* Array to store sound devices */
242static const char * const device_table[SND_DEVICE_MAX] = {
243 [SND_DEVICE_NONE] = "none",
244 /* Playback sound devices */
245 [SND_DEVICE_OUT_HANDSET] = "handset",
246 [SND_DEVICE_OUT_SPEAKER] = "speaker",
247 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700248 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700249 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500250 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700251 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700252 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500253 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700254 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700255 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500256 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700257 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
258 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500259 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700260 [SND_DEVICE_OUT_HDMI] = "hdmi",
261 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
262 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700263 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800264 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
265 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700266 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = "speaker-safe-and-bt-a2dp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700267 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
268 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
269 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
270 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800271 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
272 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700273 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700274 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700275 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700276 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800277 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700278 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700279 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700280 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700281 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
282 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700283 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800284 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
juyuchen5351ea62018-05-16 10:54:37 +0800285 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800286 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
juyuchen5351ea62018-05-16 10:54:37 +0800287 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700288
289 /* Capture sound devices */
290 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700291 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700292 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
293 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
294 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
295 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
296 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
297 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
298 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
299
300 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
301 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
302 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
303 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
304 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
305 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
306 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
307 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
308 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
309
310 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500311 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700312
Eric Laurentb23d5282013-05-14 15:27:20 -0700313 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
314 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700315 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700316 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700317 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700318 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700319
320 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
321 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
322 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
323 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700324 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700325 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700326 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
327 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
328 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800329 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
330 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700331
Eric Laurentb23d5282013-05-14 15:27:20 -0700332 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700333 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700334 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700335 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700336 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
337 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700338 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700339 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
340 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
341 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
342 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700343 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700344
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700345 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700346 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
347 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
348 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
349 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800350
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700351 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700352
Prashant Malanic92c5962015-08-11 15:10:18 -0700353 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
354 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700355 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700356 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
357 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700358 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
359 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700360};
361
362/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700363static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700364 [SND_DEVICE_NONE] = -1,
365 [SND_DEVICE_OUT_HANDSET] = 7,
366 [SND_DEVICE_OUT_SPEAKER] = 15,
367 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700368 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700369 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500370 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700371 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700372 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500373 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700374 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700375 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
376 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500377 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700378 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500379 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700380 [SND_DEVICE_OUT_HDMI] = 18,
381 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
382 [SND_DEVICE_OUT_BT_SCO] = 22,
juyuchen5351ea62018-05-16 10:54:37 +0800383 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700384 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
juyuchen5351ea62018-05-16 10:54:37 +0800385 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800386 [SND_DEVICE_OUT_BT_A2DP] = 20,
387 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700388 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700389 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700390 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
391 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
392 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800393 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
394 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700395 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700396 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700397 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700398 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800399 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700400 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700401 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700402 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700403 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
404 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700405 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700406
407 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700408 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
409 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
410 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
411 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
412 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
413 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
414 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
415 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
416
417 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
418 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
419 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
420 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
421 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
422 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
423 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
424 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
425 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
426
rago90fb9612015-12-02 11:37:53 -0800427 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500428 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700429
Eric Laurentb23d5282013-05-14 15:27:20 -0700430 [SND_DEVICE_IN_HDMI_MIC] = 4,
431 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700432 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700433 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700434 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700435 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700436
437 [SND_DEVICE_IN_VOICE_DMIC] = 41,
438 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
439 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700440 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700441 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800442 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700443 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
444 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
445 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800446 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
447 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700448
rago90fb9612015-12-02 11:37:53 -0800449 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700450 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700451 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700452 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700453 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
454 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800455 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
456
457 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
458 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700459 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
460 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
461 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700462
463 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700464 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700465 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
466 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
467 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
468 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700469 [SND_DEVICE_IN_THREE_MIC] = 46,
470 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700471 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700472 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
473 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700474 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
475 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700476};
477
David Linee3fe402017-03-13 10:00:42 -0700478// Platform specific backend bit width table
479static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
480
Haynes Mathew George98c95622014-06-20 19:14:25 -0700481struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700482 char name[100];
483 unsigned int index;
484};
485
486#define TO_NAME_INDEX(X) #X, X
487
Haynes Mathew George98c95622014-06-20 19:14:25 -0700488/* Used to get index from parsed string */
489static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
490 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700491 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
492 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
493 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700494 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700495 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500496 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700497 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700498 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500499 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700500 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700501 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
502 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700503 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700504 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500505 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700506 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
507 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
508 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
juyuchen5351ea62018-05-16 10:54:37 +0800509 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700510 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
juyuchen5351ea62018-05-16 10:54:37 +0800511 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800512 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
513 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aniket Kumar Lata9723a962018-05-16 17:41:55 -0700514 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700515 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500516 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700517 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
518 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
519 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800520 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
521 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800522 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
523 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700524 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700525 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700526 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700527 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700528 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700529 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700530 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
531 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800532 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800533
534 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700535 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700536 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700537 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
538 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
539 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
540 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
541 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
542 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
544
545 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700546 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700547 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
548 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
549 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
550 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
551 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
552 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
553 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
554
555 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700556 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700557
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700558 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
559 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700560 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700561 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700562 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700563 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700564
565 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
566 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
567 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700568 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700569 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
570 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700571 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
572 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
573 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800574 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
575 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
576
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700577
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700578 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700579 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700580 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700581 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700582 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
583 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700584 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700585 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700586 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
587 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
588 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
589 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700590
rago90fb9612015-12-02 11:37:53 -0800591 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
592 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700593 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
594 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
595 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800596
Prashant Malanic92c5962015-08-11 15:10:18 -0700597 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
598 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700599 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700600 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
601 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700602 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
603 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700604};
605
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700606static char * backend_tag_table[SND_DEVICE_MAX] = {0};
607static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700608
609static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
610 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
611 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800612 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700613 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700614 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
615 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800616 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700617 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
618 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800619 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700620 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700621 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
622 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
623 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
624 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
625 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800626 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
627 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700628 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
629 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
630 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
631 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800632 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
633 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
634 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
635 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
636 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700637 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
638 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200639 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700640 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700641};
642
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800643static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
644 {TO_NAME_INDEX(PCM_PLAYBACK)},
645 {TO_NAME_INDEX(PCM_CAPTURE)},
646 {TO_NAME_INDEX(VOICE_CALL)},
647 {TO_NAME_INDEX(PCM_HFP_CALL)},
648};
649
650struct app_type_entry {
651 int uc_type;
652 int bit_width;
653 int app_type;
654 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700655 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800656 struct listnode node; // membership in app_type_entry_list;
657};
658
659static struct listnode app_type_entry_list;
660
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700661#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
662#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800663#define ULL_PLATFORM_DELAY (3*1000LL)
664#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700665
Eric Laurentb23d5282013-05-14 15:27:20 -0700666static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
667static bool is_tmus = false;
668
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800669static int init_be_dai_name_table(struct audio_device *adev);
670
Eric Laurentb23d5282013-05-14 15:27:20 -0700671static void check_operator()
672{
673 char value[PROPERTY_VALUE_MAX];
674 int mccmnc;
675 property_get("gsm.sim.operator.numeric",value,"0");
676 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700677 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700678 switch(mccmnc) {
679 /* TMUS MCC(310), MNC(490, 260, 026) */
680 case 310490:
681 case 310260:
682 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900683 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
684 case 310800:
685 case 310660:
686 case 310580:
687 case 310310:
688 case 310270:
689 case 310250:
690 case 310240:
691 case 310230:
692 case 310220:
693 case 310210:
694 case 310200:
695 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700696 is_tmus = true;
697 break;
698 }
699}
700
701bool is_operator_tmus()
702{
703 pthread_once(&check_op_once_ctl, check_operator);
704 return is_tmus;
705}
706
keunhui.park2f7306a2015-07-16 16:48:06 +0900707static char *get_current_operator()
708{
709 struct listnode *node;
710 struct operator_info *info_item;
711 char mccmnc[PROPERTY_VALUE_MAX];
712 char *ret = NULL;
713
Tom Cherry7fea2042016-11-10 18:05:59 -0800714 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900715
716 list_for_each(node, &operator_info_list) {
717 info_item = node_to_item(node, struct operator_info, list);
718 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
719 ret = info_item->name;
720 }
721 }
722
723 return ret;
724}
725
726static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
727{
728 struct listnode *node;
729 struct operator_specific_device *ret = NULL;
730 struct operator_specific_device *device_item;
731 char *operator_name;
732
733 operator_name = get_current_operator();
734 if (operator_name == NULL)
735 return ret;
736
737 list_for_each(node, operator_specific_device_table[snd_device]) {
738 device_item = node_to_item(node, struct operator_specific_device, list);
739 if (strcmp(operator_name, device_item->operator) == 0) {
740 ret = device_item;
741 }
742 }
743
744 return ret;
745}
746
747
748static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
749{
750 struct operator_specific_device *device;
751 int ret = acdb_device_table[snd_device];
752
753 device = get_operator_specific_device(snd_device);
754 if (device != NULL)
755 ret = device->acdb_id;
756
757 return ret;
758}
759
760static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
761{
762 struct operator_specific_device *device;
763 const char *ret = device_table[snd_device];
764
765 device = get_operator_specific_device(snd_device);
766 if (device != NULL)
767 ret = device->mixer_path;
768
769 return ret;
770}
771
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800772inline bool platform_supports_app_type_cfg()
773{
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700774#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800775 return true;
776#else
777 return false;
778#endif
779}
780
jasmine chac89321b2018-04-10 21:37:01 +0800781static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
782{
783 int err;
784 char value[64];
785 int ret = 0;
786
787 if (parms == NULL || cal == NULL)
788 return ret;
789
790 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
791 if (err >= 0) {
792 str_parms_del(parms, "cal_persist");
793 cal->persist = (uint32_t)strtoul(value, NULL, 0);
794 ret = ret | 0x1;
795 }
796 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
797 if (err >= 0) {
798 str_parms_del(parms, "cal_apptype");
799 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
800 ret = ret | 0x2;
801 }
802 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
803 if (err >= 0) {
804 str_parms_del(parms, "cal_caltype");
805 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
806 ret = ret | 0x4;
807 }
808 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
809 if (err >= 0) {
810 str_parms_del(parms, "cal_samplerate");
811 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
812 ret = ret | 0x8;
813 }
814 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
815 if (err >= 0) {
816 str_parms_del(parms, "cal_devid");
817 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
818 ret = ret | 0x10;
819 }
820 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
821 if (err >= 0) {
822 str_parms_del(parms, "cal_snddevid");
823 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
824 ret = ret | 0x20;
825 }
826 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
827 if (err >= 0) {
828 str_parms_del(parms, "cal_topoid");
829 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
830 ret = ret | 0x40;
831 }
832 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
833 if (err >= 0) {
834 str_parms_del(parms, "cal_moduleid");
835 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
836 ret = ret | 0x80;
837 }
838 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
839 if (err >= 0) {
840 str_parms_del(parms, "cal_paramid");
841 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
842 ret = ret | 0x100;
843 }
844 return ret;
845}
846
847static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
848{
849 struct platform_data *my_data = (struct platform_data *)platform;
850 acdb_audio_cal_cfg_t cal;
851 uint8_t *dptr = NULL;
852 int32_t dlen = 0;
853 int err ,ret;
854
855 if (value == NULL || platform == NULL || parms == NULL) {
856 ALOGE("[%s] received null pointer, failed", __func__);
857 goto done_key_audcal;
858 }
859
860 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
861 /* parse audio calibration keys */
862 ret = parse_audiocal_cfg(parms, &cal);
863
864 /* handle audio calibration data now */
865 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
866 if (err >= 0) {
867 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
868 dlen = strlen(value);
869 if (dlen <= 0) {
870 ALOGE("[%s] null data received", __func__);
871 goto done_key_audcal;
872 }
873 /*
874 The base64 encoded string is always larger than the binary data,
875 so b64_pton will always output less data than provided (around 1/3
876 less than the input data). That's why we can allocate input buffer
877 length and then get function work.
878 */
879 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
880 if (dptr == NULL) {
881 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
882 goto done_key_audcal;
883 }
884 dlen = b64_pton(value, dptr, dlen);
885 if (dlen <= 0) {
886 ALOGE("[%s] data decoding failed %d", __func__, dlen);
887 goto done_key_audcal;
888 }
889
890 if (cal.dev_id) {
891 if (audio_is_input_device(cal.dev_id)) {
892 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
893 } else {
894 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
895 }
896 }
897 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
898 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
899 cal.snd_dev_id, cal.acdb_dev_id);
900 if (cal.acdb_dev_id == -EINVAL) {
901 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
902 __func__, cal.acdb_dev_id, cal.snd_dev_id);
903 goto done_key_audcal;
904 }
905 if (my_data->acdb_set_audio_cal) {
906 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
907 }
908 }
909done_key_audcal:
910 if (dptr != NULL)
911 free(dptr);
912}
913
vivek mehta1a9b7c02015-06-25 11:49:38 -0700914bool platform_send_gain_dep_cal(void *platform, int level)
915{
916 bool ret_val = false;
917 struct platform_data *my_data = (struct platform_data *)platform;
918 struct audio_device *adev = my_data->adev;
919 int acdb_dev_id, app_type;
920 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
921 int mode = CAL_MODE_RTAC;
922 struct listnode *node;
923 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700924 bool valid_uc_type;
925 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700926
927 if (my_data->acdb_send_gain_dep_cal == NULL) {
928 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
929 return ret_val;
930 }
931
932 if (!voice_is_in_call(adev)) {
933 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
934 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700935
936 // find the current active sound device
937 list_for_each(node, &adev->usecase_list) {
938 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700939 LOG_ALWAYS_FATAL_IF(usecase == NULL,
940 "unxpected NULL usecase in usecase_list");
941 valid_uc_type = usecase->type == PCM_PLAYBACK;
942 valid_dev = false;
943 if (valid_uc_type) {
944 audio_devices_t dev = usecase->stream.out->devices;
945 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700946 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700947 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
948 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
949 }
950 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700951 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
952 if (platform_supports_app_type_cfg())
953 app_type = usecase->stream.out->app_type_cfg.app_type;
954 else
955 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700956
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700957 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700958
959 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700960 acdb_dev_type, mode, level)) {
961 // set ret_val true if at least one calibration is set successfully
962 ret_val = true;
963 } else {
964 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
965 }
966 } else {
967 ALOGW("%s: Usecase list is empty", __func__);
968 }
969 }
970 } else {
971 ALOGW("%s: Voice call in progress .. ignore setting new cal",
972 __func__);
973 }
974 return ret_val;
975}
976
Eric Laurentcefbbac2014-09-04 13:54:10 -0500977void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700978{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800979 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500980 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700981
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800982 if (strcmp(my_data->ec_ref_mixer_path, "")) {
983 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
984 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500985 }
986
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800987 if (enable) {
988 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
989 if (out_device != AUDIO_DEVICE_NONE) {
990 snd_device = platform_get_output_snd_device(adev->platform, out_device);
991 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
992 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500993
Joe Onorato188b6222016-03-01 11:02:27 -0800994 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800995 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
996 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700997}
998
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700999static struct csd_data *open_csd_client(bool i2s_ext_modem)
1000{
1001 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1002
1003 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1004 if (csd->csd_client == NULL) {
1005 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1006 goto error;
1007 } else {
1008 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1009
1010 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1011 "csd_client_deinit");
1012 if (csd->deinit == NULL) {
1013 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1014 dlerror());
1015 goto error;
1016 }
1017 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1018 "csd_client_disable_device");
1019 if (csd->disable_device == NULL) {
1020 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1021 __func__, dlerror());
1022 goto error;
1023 }
1024 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1025 "csd_client_enable_device_config");
1026 if (csd->enable_device_config == NULL) {
1027 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1028 __func__, dlerror());
1029 goto error;
1030 }
1031 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1032 "csd_client_enable_device");
1033 if (csd->enable_device == NULL) {
1034 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1035 __func__, dlerror());
1036 goto error;
1037 }
1038 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1039 "csd_client_start_voice");
1040 if (csd->start_voice == NULL) {
1041 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1042 __func__, dlerror());
1043 goto error;
1044 }
1045 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1046 "csd_client_stop_voice");
1047 if (csd->stop_voice == NULL) {
1048 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1049 __func__, dlerror());
1050 goto error;
1051 }
1052 csd->volume = (volume_t)dlsym(csd->csd_client,
1053 "csd_client_volume");
1054 if (csd->volume == NULL) {
1055 ALOGE("%s: dlsym error %s for csd_client_volume",
1056 __func__, dlerror());
1057 goto error;
1058 }
1059 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1060 "csd_client_mic_mute");
1061 if (csd->mic_mute == NULL) {
1062 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1063 __func__, dlerror());
1064 goto error;
1065 }
1066 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1067 "csd_client_slow_talk");
1068 if (csd->slow_talk == NULL) {
1069 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1070 __func__, dlerror());
1071 goto error;
1072 }
1073 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1074 "csd_client_start_playback");
1075 if (csd->start_playback == NULL) {
1076 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1077 __func__, dlerror());
1078 goto error;
1079 }
1080 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1081 "csd_client_stop_playback");
1082 if (csd->stop_playback == NULL) {
1083 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1084 __func__, dlerror());
1085 goto error;
1086 }
1087 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1088 "csd_client_start_record");
1089 if (csd->start_record == NULL) {
1090 ALOGE("%s: dlsym error %s for csd_client_start_record",
1091 __func__, dlerror());
1092 goto error;
1093 }
1094 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1095 "csd_client_stop_record");
1096 if (csd->stop_record == NULL) {
1097 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1098 __func__, dlerror());
1099 goto error;
1100 }
1101
1102 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1103 "csd_client_get_sample_rate");
1104 if (csd->get_sample_rate == NULL) {
1105 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1106 __func__, dlerror());
1107
1108 goto error;
1109 }
1110
1111 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1112
1113 if (csd->init == NULL) {
1114 ALOGE("%s: dlsym error %s for csd_client_init",
1115 __func__, dlerror());
1116 goto error;
1117 } else {
1118 csd->init(i2s_ext_modem);
1119 }
1120 }
1121 return csd;
1122
1123error:
1124 free(csd);
1125 csd = NULL;
1126 return csd;
1127}
1128
1129void close_csd_client(struct csd_data *csd)
1130{
1131 if (csd != NULL) {
1132 csd->deinit();
1133 dlclose(csd->csd_client);
1134 free(csd);
1135 csd = NULL;
1136 }
1137}
1138
1139static void platform_csd_init(struct platform_data *my_data)
1140{
1141#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001142 int32_t modems, (*count_modems)(void);
1143 const char *name = "libdetectmodem.so";
1144 const char *func = "count_modems";
1145 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001146
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001147 my_data->csd = NULL;
1148
1149 void *lib = dlopen(name, RTLD_NOW);
1150 error = dlerror();
1151 if (!lib) {
1152 ALOGE("%s: could not find %s: %s", __func__, name, error);
1153 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001154 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001155
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001156 count_modems = NULL;
1157 *(void **)(&count_modems) = dlsym(lib, func);
1158 error = dlerror();
1159 if (!count_modems) {
1160 ALOGE("%s: could not find symbol %s in %s: %s",
1161 __func__, func, name, error);
1162 goto done;
1163 }
1164
1165 modems = count_modems();
1166 if (modems < 0) {
1167 ALOGE("%s: count_modems failed\n", __func__);
1168 goto done;
1169 }
1170
Eric Laurent2bafff12016-03-17 12:17:23 -07001171 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001172 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001173 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001174
1175done:
1176 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001177#else
1178 my_data->csd = NULL;
1179#endif
1180}
1181
Eric Laurentc6333382015-09-14 12:43:44 -07001182static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001183{
1184 int32_t dev;
1185 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001186 backend_tag_table[dev] = NULL;
1187 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001188 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001189 }
1190
David Linee3fe402017-03-13 10:00:42 -07001191 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1192 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1193 }
1194
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001195 // To overwrite these go to the audio_platform_info.xml file.
1196 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001197 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001198 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1199 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1200 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1201 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1202 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001203 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001204 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1205 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001206
David Linee3fe402017-03-13 10:00:42 -07001207 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001208 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001209 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001210 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001211 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1212 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001213 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1214 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001215 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1216 strdup("speaker-safe-and-bt-sco"),
1217 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1218 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001219 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001220 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1221 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1222 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1223 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001224 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1225 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001226 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001227 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001228
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001229 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1230 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1231 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1232 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1233 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1234 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1235 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001236 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001237 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001238 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001239 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1240 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1241 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1242 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1243 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1244 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1245 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1246 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1247 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001248 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1249 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1250 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07001251 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
1252 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001253 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1254 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1255 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1256 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001257 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001258 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1259 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001260 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001261 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001262 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001263 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001264 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 -07001265 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 -07001266 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1267 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1268 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001269 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1270 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1271 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
juyuchen5351ea62018-05-16 10:54:37 +08001272 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1273 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001274 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1275 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1276 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1277 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1278 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1279 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1280 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001281 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001282 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1283 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1284 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1285 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1286 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1287 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1288 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1289 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001290 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001291 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001292 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001293 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1294 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001295 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1296 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001297 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1298 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001299 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1300 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1301 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1302 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1303 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001304 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1305 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1306 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1307 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1308 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1309 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1310 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1311 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001312 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1313 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1314 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001315 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001316 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1317 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001318 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001319 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1320 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1321 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1322 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1323 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1324 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1325 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1326 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1327 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1328 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1329 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1330 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1331 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1332 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1333 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001334 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001335}
1336
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001337void get_cvd_version(char *cvd_version, struct audio_device *adev)
1338{
1339 struct mixer_ctl *ctl;
1340 int count;
1341 int ret = 0;
1342
1343 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1344 if (!ctl) {
1345 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1346 goto done;
1347 }
1348 mixer_ctl_update(ctl);
1349
1350 count = mixer_ctl_get_num_values(ctl);
1351 if (count > MAX_CVD_VERSION_STRING_SIZE)
1352 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1353
1354 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1355 if (ret != 0) {
1356 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1357 goto done;
1358 }
1359
1360done:
1361 return;
1362}
1363
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001364static int platform_acdb_init(void *platform)
1365{
1366 struct platform_data *my_data = (struct platform_data *)platform;
1367 struct audio_device *adev = my_data->adev;
1368
1369 if (!my_data->acdb_init) {
1370 ALOGE("%s: no acdb_init fn provided", __func__);
1371 return -1;
1372 }
1373
1374 if (my_data->acdb_initialized) {
1375 ALOGW("acdb is already initialized");
1376 return 0;
1377 }
1378
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001379#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001380 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1381 if (!cvd_version)
1382 ALOGE("failed to allocate cvd_version");
1383 else {
1384 get_cvd_version(cvd_version, adev);
1385 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1386 free(cvd_version);
1387 }
1388#elif defined (PLATFORM_MSM8084)
1389 my_data->acdb_init((char *)my_data->snd_card_name);
1390#else
1391 my_data->acdb_init();
1392#endif
1393 my_data->acdb_initialized = true;
1394 return 0;
1395}
1396
David Linee3fe402017-03-13 10:00:42 -07001397static void
1398platform_backend_config_init(struct platform_data *pdata)
1399{
1400 int i;
1401
1402 /* initialize backend config */
1403 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1404 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1405 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1406 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1407
1408 if (i > MAX_RX_CODEC_BACKENDS)
1409 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1410
1411 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1412 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1413 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1414 }
1415
1416 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1417 strdup("SLIM_0_RX Format");
1418 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1419 strdup("SLIM_0_RX SampleRate");
1420
1421 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1422 strdup("SLIM_0_TX Format");
1423 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1424 strdup("SLIM_0_TX SampleRate");
1425
1426 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1427 strdup("USB_AUDIO_TX Format");
1428 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1429 strdup("USB_AUDIO_TX SampleRate");
1430 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1431 strdup("USB_AUDIO_TX Channels");
1432
1433 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1434 strdup("SLIM_6_RX Format");
1435 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1436 strdup("SLIM_6_RX SampleRate");
1437
1438 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1439 strdup("USB_AUDIO_RX Format");
1440 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1441 strdup("USB_AUDIO_RX SampleRate");
1442
1443 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1444 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1445 strdup("USB_AUDIO_RX Channels");
1446}
1447
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001448static int
1449platform_backend_app_type_cfg_init(struct platform_data *pdata,
1450 struct mixer *mixer)
1451{
1452 size_t app_type_cfg[128] = {0};
1453 int length, num_app_types = 0;
1454 struct mixer_ctl *ctl = NULL;
1455
1456 const char *mixer_ctl_name = "App Type Config";
1457 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1458 if (!ctl) {
1459 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1460 return -1;
1461 }
1462
1463 length = 1; // reserve index 0 for number of app types
1464
1465 struct listnode *node;
1466 struct app_type_entry *entry;
1467 list_for_each(node, &app_type_entry_list) {
1468 entry = node_to_item(node, struct app_type_entry, node);
1469 app_type_cfg[length++] = entry->app_type;
1470 app_type_cfg[length++] = entry->max_rate;
1471 app_type_cfg[length++] = entry->bit_width;
1472 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1473 num_app_types += 1;
1474 }
1475
1476 // default for capture
1477 int t;
1478 platform_get_default_app_type_v2(pdata,
1479 PCM_CAPTURE,
1480 &t);
1481 app_type_cfg[length++] = t;
1482 app_type_cfg[length++] = 48000;
1483 app_type_cfg[length++] = 16;
1484 num_app_types += 1;
1485
1486 if (num_app_types) {
1487 app_type_cfg[0] = num_app_types;
1488 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1489 ALOGE("Failed to set app type cfg");
1490 }
1491 }
1492 return 0;
1493}
1494
Xu Han1638fd12018-04-20 12:42:23 -07001495static void configure_flicker_sensor_input(struct mixer *mixer)
1496{
1497 struct mixer_ctl *ctl;
1498 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1499 int setting1 = 1;
1500 const char* ctl2 = "CDC_IF TX2 MUX";
1501 const char* setting2 = "DEC2";
1502 const char* ctl3 = "SLIM_1_TX Channels";
1503 const char* setting3 = "One";
1504 const char* ctl4 = "ADC MUX2";
1505 const char* setting4 = "AMIC";
1506 const char* ctl5 = "AMIC MUX2";
1507 const char* setting5 = "ADC1";
1508 const char* ctl6 = "DEC2 Volume";
1509 int setting6 = 84;
Xu Han07e07402018-05-15 14:19:25 -07001510 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
Xu Han1638fd12018-04-20 12:42:23 -07001511 int setting7 = 1;
1512 const char* ctl8 = "SLIM_1_TX SampleRate";
1513 const char* setting8 = "KHZ_8";
1514
1515 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1516 mixer_ctl_set_value(ctl, 0, setting1);
1517 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1518 mixer_ctl_set_enum_by_string(ctl, setting2);
1519 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1520 mixer_ctl_set_enum_by_string(ctl, setting3);
1521 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1522 mixer_ctl_set_enum_by_string(ctl, setting4);
1523 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1524 mixer_ctl_set_enum_by_string(ctl, setting5);
1525 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1526 mixer_ctl_set_value(ctl, 0, setting6);
1527 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1528 mixer_ctl_set_value(ctl, 0, setting7);
1529 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1530 mixer_ctl_set_enum_by_string(ctl, setting8);
1531}
1532
Eric Laurentb23d5282013-05-14 15:27:20 -07001533void *platform_init(struct audio_device *adev)
1534{
1535 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001536 struct platform_data *my_data = NULL;
1537 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1538 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001539 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001540 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001541 char *snd_internal_name = NULL;
1542 char *tmp = NULL;
1543 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001544 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1545 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001546 my_data = calloc(1, sizeof(struct platform_data));
1547
1548 my_data->adev = adev;
1549
keunhui.park2f7306a2015-07-16 16:48:06 +09001550 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001551 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001552
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001553 set_platform_defaults(my_data);
1554
vivek mehta0fb11312017-05-15 19:35:32 -07001555 // audio_extn_utils_get_snd_card_num does
1556 // - open mixer and get snd card name
1557 // - parse platform info xml file and check for valid snd card name
1558 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001559
vivek mehta0fb11312017-05-15 19:35:32 -07001560 snd_card_num = audio_extn_utils_get_snd_card_num();
1561 if (-1 == snd_card_num) {
1562 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1563 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001564 }
1565
vivek mehta0fb11312017-05-15 19:35:32 -07001566 adev->mixer = mixer_open(snd_card_num);
1567 snd_card_name = mixer_get_name(adev->mixer);
1568 my_data->hw_info = hw_info_init(snd_card_name);
1569
1570 audio_extn_set_snd_card_split(snd_card_name);
1571 snd_split_handle = audio_extn_get_snd_card_split();
1572
1573 /* Get the codec internal name from the sound card and/or form factor
1574 * name and form the mixer paths and platfor info file name dynamically.
1575 * This is generic way of picking any codec and forma factor name based
1576 * mixer and platform info files in future with no code change.
1577
1578 * current code extends and looks for any of the exteneded mixer path and
1579 * platform info file present based on codec and form factor.
1580
1581 * order of picking appropriate file is
1582 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1583 * <ii> mixer_paths_<codec_name>.xml, if file not present
1584 * <iii> mixer_paths.xml
1585
1586 * same order is followed for audio_platform_info.xml as well
1587 */
1588
1589 // need to carryforward old file name
1590 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1591 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1592 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1593 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1594 } else {
1595
1596 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1597 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1598 snd_split_handle->form_factor);
1599 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1600 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1601 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1602 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1603
1604 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1605 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1606 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1607 audio_extn_utils_resolve_config_file(mixer_xml_file);
1608 }
1609 }
1610 }
1611
1612 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1613
jiabin8962a4d2018-03-19 18:21:24 -07001614 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001615 /* Initialize platform specific ids and/or backends*/
1616 platform_info_init(platform_info_file, my_data);
1617
1618 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1619 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1620
1621 if (!adev->audio_route) {
1622 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1623 mixer_close(adev->mixer);
1624 adev->mixer = NULL;
1625 hw_info_deinit(my_data->hw_info);
1626 my_data->hw_info = NULL;
1627 goto init_failed;
1628 }
1629 adev->snd_card = snd_card_num;
1630 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1631
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001632 //set max volume step for voice call
1633 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1634 my_data->max_vol_index = atoi(value);
1635
vivek mehta65ad12d2015-08-13 18:32:48 -07001636 property_get("persist.audio.dualmic.config",value,"");
1637 if (!strcmp("endfire", value)) {
1638 dual_mic_config = true;
1639 }
1640
John Muir9e59a962018-01-10 13:30:00 -08001641 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001642
Eric Laurentb23d5282013-05-14 15:27:20 -07001643 my_data->fluence_in_spkr_mode = false;
1644 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001645 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001646 my_data->fluence_in_voice_rec = false;
1647
vivek mehta65ad12d2015-08-13 18:32:48 -07001648 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001649 if (!strcmp("fluencepro", value)) {
1650 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001651 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001652 my_data->fluence_type = FLUENCE_ENABLE;
1653 } else if (!strcmp("none", value)) {
1654 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001655 }
1656
Prashant Malanic92c5962015-08-11 15:10:18 -07001657 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001658 property_get("persist.audio.fluence.voicecall",value,"");
1659 if (!strcmp("true", value)) {
1660 my_data->fluence_in_voice_call = true;
1661 }
1662
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001663 property_get("persist.audio.fluence.voicecomm",value,"");
1664 if (!strcmp("true", value)) {
1665 my_data->fluence_in_voice_comm = true;
1666 }
1667
Eric Laurentb23d5282013-05-14 15:27:20 -07001668 property_get("persist.audio.fluence.voicerec",value,"");
1669 if (!strcmp("true", value)) {
1670 my_data->fluence_in_voice_rec = true;
1671 }
1672
1673 property_get("persist.audio.fluence.speaker",value,"");
1674 if (!strcmp("true", value)) {
1675 my_data->fluence_in_spkr_mode = true;
1676 }
1677 }
1678
Prashant Malanic92c5962015-08-11 15:10:18 -07001679 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1680 switch (my_data->max_mic_count) {
1681 case 4:
1682 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1683 case 3:
1684 my_data->source_mic_type |= SOURCE_THREE_MIC;
1685 case 2:
1686 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1687 case 1:
1688 my_data->source_mic_type |= SOURCE_MONO_MIC;
1689 break;
1690 default:
1691 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1692 __func__, my_data->max_mic_count);
1693 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1694 break;
1695 }
1696
1697 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1698 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1699 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1700 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1701 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1702
Eric Laurentb23d5282013-05-14 15:27:20 -07001703 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1704 if (my_data->acdb_handle == NULL) {
1705 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1706 } else {
1707 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1708 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1709 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001710 if (!my_data->acdb_deallocate)
1711 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1712 __func__, LIB_ACDB_LOADER);
1713
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001714 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1715 "acdb_loader_send_audio_cal_v3");
1716 if (!my_data->acdb_send_audio_cal_v3)
1717 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1718 __func__, LIB_ACDB_LOADER);
1719
Eric Laurentb23d5282013-05-14 15:27:20 -07001720 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1721 "acdb_loader_send_audio_cal");
1722 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001723 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001724 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001725
Eric Laurentb23d5282013-05-14 15:27:20 -07001726 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1727 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001728 if (!my_data->acdb_send_voice_cal)
1729 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1730 __func__, LIB_ACDB_LOADER);
1731
1732 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1733 "acdb_loader_reload_vocvoltable");
1734 if (!my_data->acdb_reload_vocvoltable)
1735 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1736 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001737
1738 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1739 "acdb_loader_send_gain_dep_cal");
1740 if (!my_data->acdb_send_gain_dep_cal)
1741 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1742 __func__, LIB_ACDB_LOADER);
1743
Xu Han1638fd12018-04-20 12:42:23 -07001744#if defined (FLICKER_SENSOR_INPUT)
1745 configure_flicker_sensor_input(adev->mixer);
1746#endif
1747
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001748#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
vivek mehta0fb11312017-05-15 19:35:32 -07001749 acdb_init_v2_cvd_t acdb_init_local;
1750 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001751 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001752 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001753 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1754 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001755
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001756#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001757 acdb_init_v2_t acdb_init_local;
1758 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001759 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001760 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001761 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1762 dlerror());
1763
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001764#else
vivek mehta0fb11312017-05-15 19:35:32 -07001765 acdb_init_t acdb_init_local;
1766 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001767 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001768 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001769 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1770 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001771#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001772 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001773
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001774 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1775 dlsym(my_data->acdb_handle,
1776 "acdb_loader_send_common_custom_topology");
1777
1778 if (!my_data->acdb_send_custom_top)
1779 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1780 __func__, LIB_ACDB_LOADER);
1781
jasmine chac89321b2018-04-10 21:37:01 +08001782 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1783 "acdb_loader_set_audio_cal_v2");
1784 if (!my_data->acdb_set_audio_cal)
1785 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1786 __func__, LIB_ACDB_LOADER);
1787
vivek mehta0fb11312017-05-15 19:35:32 -07001788 int result = acdb_init(adev->snd_card);
1789 if (!result) {
1790 my_data->acdb_initialized = true;
1791 ALOGD("ACDB initialized");
1792 } else {
1793 my_data->acdb_initialized = false;
1794 ALOGD("ACDB initialization failed");
1795 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001796 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001797
David Linee3fe402017-03-13 10:00:42 -07001798 /* init usb */
1799 audio_extn_usb_init(adev);
1800
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001801 /* init a2dp */
1802 audio_extn_a2dp_init(adev);
1803
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001804 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001805
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001806 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1807
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001808 /* load csd client */
1809 platform_csd_init(my_data);
1810
David Linee3fe402017-03-13 10:00:42 -07001811 platform_backend_config_init(my_data);
1812
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001813 init_be_dai_name_table(adev);
1814
1815 if (platform_supports_app_type_cfg())
1816 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1817
Eric Laurentb23d5282013-05-14 15:27:20 -07001818 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001819
1820init_failed:
1821 if (my_data)
1822 free(my_data);
1823 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001824}
1825
1826void platform_deinit(void *platform)
1827{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001828 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001829 struct operator_info *info_item;
1830 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001831 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001832 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001833
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001834 struct platform_data *my_data = (struct platform_data *)platform;
1835 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001836
David Lin41b4fe42018-07-08 16:14:24 -07001837 audio_extn_spkr_prot_deinit(my_data->adev);
1838
vivek mehtade4849c2016-03-03 17:23:38 -08001839 hw_info_deinit(my_data->hw_info);
1840
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001841 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1842 if (backend_tag_table[dev])
1843 free(backend_tag_table[dev]);
1844 if (hw_interface_table[dev])
1845 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001846 if (operator_specific_device_table[dev]) {
1847 while (!list_empty(operator_specific_device_table[dev])) {
1848 node = list_head(operator_specific_device_table[dev]);
1849 list_remove(node);
1850 device_item = node_to_item(node, struct operator_specific_device, list);
1851 free(device_item->operator);
1852 free(device_item->mixer_path);
1853 free(device_item);
1854 }
1855 free(operator_specific_device_table[dev]);
1856 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001857 }
1858
1859 if (my_data->snd_card_name)
1860 free(my_data->snd_card_name);
1861
keunhui.park2f7306a2015-07-16 16:48:06 +09001862 while (!list_empty(&operator_info_list)) {
1863 node = list_head(&operator_info_list);
1864 list_remove(node);
1865 info_item = node_to_item(node, struct operator_info, list);
1866 free(info_item->name);
1867 free(info_item->mccmnc);
1868 free(info_item);
1869 }
1870
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001871 while (!list_empty(&app_type_entry_list)) {
1872 node = list_head(&app_type_entry_list);
1873 list_remove(node);
1874 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001875 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001876 free(ap);
1877 }
1878
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001879 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001880 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001881
1882 /* deinit usb */
1883 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001884}
1885
1886const char *platform_get_snd_device_name(snd_device_t snd_device)
1887{
keunhui.park2f7306a2015-07-16 16:48:06 +09001888 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1889 if (operator_specific_device_table[snd_device] != NULL) {
1890 return get_operator_specific_device_mixer_path(snd_device);
1891 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001892 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001893 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001894 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001895}
1896
vivek mehtade4849c2016-03-03 17:23:38 -08001897int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1898 char *device_name)
1899{
1900 struct platform_data *my_data = (struct platform_data *)platform;
1901
David Benjamin1565f992016-09-21 12:10:34 -04001902 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001903 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001904 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1905 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001906 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1907 if (operator_specific_device_table[snd_device] != NULL) {
1908 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1909 DEVICE_NAME_MAX_SIZE);
1910 } else {
1911 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1912 }
1913 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1914 } else {
1915 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07001916 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08001917 }
1918
1919 return 0;
1920}
1921
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001922void platform_add_backend_name(void *platform, char *mixer_path,
1923 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001924{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001925 struct platform_data *my_data = (struct platform_data *)platform;
1926
Haynes Mathew George98c95622014-06-20 19:14:25 -07001927 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1928 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1929 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001930 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001931
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001932 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001933
1934 if (suffix != NULL) {
1935 strcat(mixer_path, " ");
1936 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001937 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001938}
1939
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001940bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1941{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001942 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1943 platform_get_snd_device_name(snd_device1),
1944 platform_get_snd_device_name(snd_device2));
1945
1946 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1947 ALOGE("%s: Invalid snd_device = %s", __func__,
1948 platform_get_snd_device_name(snd_device1));
1949 return false;
1950 }
1951 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1952 ALOGE("%s: Invalid snd_device = %s", __func__,
1953 platform_get_snd_device_name(snd_device2));
1954 return false;
1955 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001956
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001957 const char * be_itf1 = hw_interface_table[snd_device1];
1958 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001959 /*
1960 hw_interface_table has overrides for a snd_device.
1961 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1962 */
1963 if (be_itf1 == NULL) {
1964 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001965 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001966 if (be_itf2 == NULL) {
1967 be_itf2 = DEFAULT_RX_BACKEND;
1968 }
1969 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1970 /*
1971 this takes care of finding a device within a combo device pair as well
1972 */
1973 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001974}
1975
Eric Laurentb23d5282013-05-14 15:27:20 -07001976int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1977{
1978 int device_id;
1979 if (device_type == PCM_PLAYBACK)
1980 device_id = pcm_device_table[usecase][0];
1981 else
1982 device_id = pcm_device_table[usecase][1];
1983 return device_id;
1984}
1985
Haynes Mathew George98c95622014-06-20 19:14:25 -07001986static int find_index(const struct name_to_index * table, int32_t len,
1987 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001988{
1989 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001990 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001991
Haynes Mathew George98c95622014-06-20 19:14:25 -07001992 if (table == NULL) {
1993 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001994 ret = -ENODEV;
1995 goto done;
1996 }
1997
Haynes Mathew George98c95622014-06-20 19:14:25 -07001998 if (name == NULL) {
1999 ALOGE("null key");
2000 ret = -ENODEV;
2001 goto done;
2002 }
2003
2004 for (i=0; i < len; i++) {
2005 if (!strcmp(table[i].name, name)) {
2006 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002007 goto done;
2008 }
2009 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002010 ALOGE("%s: Could not find index for name = %s",
2011 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002012 ret = -ENODEV;
2013done:
2014 return ret;
2015}
2016
Haynes Mathew George98c95622014-06-20 19:14:25 -07002017int platform_get_snd_device_index(char *device_name)
2018{
2019 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2020}
2021
2022int platform_get_usecase_index(const char *usecase_name)
2023{
2024 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2025}
2026
keunhui.park2f7306a2015-07-16 16:48:06 +09002027void platform_add_operator_specific_device(snd_device_t snd_device,
2028 const char *operator,
2029 const char *mixer_path,
2030 unsigned int acdb_id)
2031{
2032 struct operator_specific_device *device;
2033
2034 if (operator_specific_device_table[snd_device] == NULL) {
2035 operator_specific_device_table[snd_device] =
2036 (struct listnode *)calloc(1, sizeof(struct listnode));
2037 list_init(operator_specific_device_table[snd_device]);
2038 }
2039
2040 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2041
2042 device->operator = strdup(operator);
2043 device->mixer_path = strdup(mixer_path);
2044 device->acdb_id = acdb_id;
2045
2046 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2047
Eric Laurent2bafff12016-03-17 12:17:23 -07002048 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002049 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2050
2051}
2052
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002053int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2054{
2055 int ret = 0;
2056
2057 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2058 ALOGE("%s: Invalid snd_device = %d",
2059 __func__, snd_device);
2060 ret = -EINVAL;
2061 goto done;
2062 }
2063
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002064 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2065 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002066 acdb_device_table[snd_device] = acdb_id;
2067done:
2068 return ret;
2069}
2070
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002071int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2072{
2073 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2074 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2075 return -EINVAL;
2076 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002077
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002078 /*
2079 * If speaker protection is enabled, function returns supported
2080 * sound device for speaker. Else same sound device is returned.
2081 */
2082 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2083
keunhui.park2f7306a2015-07-16 16:48:06 +09002084 if (operator_specific_device_table[snd_device] != NULL)
2085 return get_operator_specific_device_acdb_id(snd_device);
2086 else
2087 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002088}
2089
David Linee3fe402017-03-13 10:00:42 -07002090static int platform_get_backend_index(snd_device_t snd_device)
2091{
2092 int32_t port = DEFAULT_CODEC_BACKEND;
2093
2094 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2095 if (backend_tag_table[snd_device] != NULL) {
2096 if (strncmp(backend_tag_table[snd_device], "headphones",
2097 sizeof("headphones")) == 0)
2098 port = HEADPHONE_BACKEND;
2099 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2100 port = HDMI_RX_BACKEND;
2101 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2102 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2103 port = USB_AUDIO_RX_BACKEND;
2104 }
2105 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2106 port = DEFAULT_CODEC_TX_BACKEND;
2107 if (backend_tag_table[snd_device] != NULL) {
2108 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2109 port = USB_AUDIO_TX_BACKEND;
2110 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2111 port = BT_SCO_TX_BACKEND;
2112 }
2113 } else {
2114 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2115 }
2116
2117 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2118
2119 return port;
2120}
2121
Eric Laurentb23d5282013-05-14 15:27:20 -07002122int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2123{
2124 struct platform_data *my_data = (struct platform_data *)platform;
2125 int acdb_dev_id, acdb_dev_type;
2126
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002127 if (platform_supports_app_type_cfg()) // use v2 instead
2128 return -ENOSYS;
2129
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002130 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002131 if (acdb_dev_id < 0) {
2132 ALOGE("%s: Could not find acdb id for device(%d)",
2133 __func__, snd_device);
2134 return -EINVAL;
2135 }
2136 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002137 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002138 __func__, snd_device, acdb_dev_id);
2139 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2140 snd_device < SND_DEVICE_OUT_END)
2141 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2142 else
2143 acdb_dev_type = ACDB_DEV_TYPE_IN;
2144 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2145 }
2146 return 0;
2147}
2148
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002149int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2150 int app_type, int sample_rate)
2151{
2152 struct platform_data *my_data = (struct platform_data *)platform;
2153 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002154 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002155 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2156 int i, num_devices = 1;
2157
2158 if (!platform_supports_app_type_cfg()) // use v1 instead
2159 return -ENOSYS;
2160
vivek mehta7e573672018-03-13 17:41:41 -07002161 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002162 snd_device = usecase->in_snd_device;
2163
2164 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002165 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002166 if (acdb_dev_id < 0) {
2167 ALOGE("%s: Could not find acdb id for device(%d)",
2168 __func__, snd_device);
2169 return -EINVAL;
2170 }
2171
2172 if (platform_can_split_snd_device(snd_device,
2173 &num_devices, new_snd_device) < 0) {
2174 new_snd_device[0] = snd_device;
2175 }
2176
2177 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002178 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002179 if (acdb_dev_id < 0) {
2180 ALOGE("%s: Could not find acdb id for device(%d)",
2181 __func__, new_snd_device[i]);
2182 return -EINVAL;
2183 }
2184 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2185 __func__, new_snd_device[i], acdb_dev_id);
2186 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2187 new_snd_device[i] < SND_DEVICE_OUT_END)
2188 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2189 else
2190 acdb_dev_type = ACDB_DEV_TYPE_IN;
2191
2192 if (my_data->acdb_send_audio_cal_v3) {
2193 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2194 app_type, sample_rate, i);
2195 } else if (my_data->acdb_send_audio_cal) {
2196 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2197 }
2198 }
2199
2200 return 0;
2201}
2202
2203
Eric Laurentb23d5282013-05-14 15:27:20 -07002204int platform_switch_voice_call_device_pre(void *platform)
2205{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002206 struct platform_data *my_data = (struct platform_data *)platform;
2207 int ret = 0;
2208
2209 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002210 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002211 /* This must be called before disabling mixer controls on APQ side */
2212 ret = my_data->csd->disable_device();
2213 if (ret < 0) {
2214 ALOGE("%s: csd_client_disable_device, failed, error %d",
2215 __func__, ret);
2216 }
2217 }
2218 return ret;
2219}
2220
2221int platform_switch_voice_call_enable_device_config(void *platform,
2222 snd_device_t out_snd_device,
2223 snd_device_t in_snd_device)
2224{
2225 struct platform_data *my_data = (struct platform_data *)platform;
2226 int acdb_rx_id, acdb_tx_id;
2227 int ret = 0;
2228
2229 if (my_data->csd == NULL)
2230 return ret;
2231
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002232 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002233 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002234
2235 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2236 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2237 if (ret < 0) {
2238 ALOGE("%s: csd_enable_device_config, failed, error %d",
2239 __func__, ret);
2240 }
2241 } else {
2242 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2243 acdb_rx_id, acdb_tx_id);
2244 }
2245
2246 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002247}
2248
2249int platform_switch_voice_call_device_post(void *platform,
2250 snd_device_t out_snd_device,
2251 snd_device_t in_snd_device)
2252{
2253 struct platform_data *my_data = (struct platform_data *)platform;
2254 int acdb_rx_id, acdb_tx_id;
2255
2256 if (my_data->acdb_send_voice_cal == NULL) {
2257 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2258 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002259 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2260 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002261
2262 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2263 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2264 else
2265 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2266 acdb_rx_id, acdb_tx_id);
2267 }
2268
2269 return 0;
2270}
2271
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002272int platform_switch_voice_call_usecase_route_post(void *platform,
2273 snd_device_t out_snd_device,
2274 snd_device_t in_snd_device)
2275{
2276 struct platform_data *my_data = (struct platform_data *)platform;
2277 int acdb_rx_id, acdb_tx_id;
2278 int ret = 0;
2279
2280 if (my_data->csd == NULL)
2281 return ret;
2282
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002283 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002284 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002285
2286 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2287 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2288 my_data->adev->acdb_settings);
2289 if (ret < 0) {
2290 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2291 }
2292 } else {
2293 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2294 acdb_rx_id, acdb_tx_id);
2295 }
2296
2297 return ret;
2298}
2299
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002300int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002301{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002302 struct platform_data *my_data = (struct platform_data *)platform;
2303 int ret = 0;
2304
2305 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002306 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002307 if (ret < 0) {
2308 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2309 }
2310 }
2311 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002312}
2313
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002314int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002315{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002316 struct platform_data *my_data = (struct platform_data *)platform;
2317 int ret = 0;
2318
2319 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002320 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002321 if (ret < 0) {
2322 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2323 }
2324 }
2325 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002326}
2327
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002328int platform_set_mic_break_det(void *platform, bool enable)
2329{
2330 int ret = 0;
2331 struct platform_data *my_data = (struct platform_data *)platform;
2332 struct audio_device *adev = my_data->adev;
2333 const char *mixer_ctl_name = "Voice Mic Break Enable";
2334 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2335 if (!ctl) {
2336 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2337 __func__, mixer_ctl_name);
2338 return -EINVAL;
2339 }
2340
2341 ret = mixer_ctl_set_value(ctl, 0, enable);
2342 if(ret)
2343 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2344
2345 return ret;
2346}
2347
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002348int platform_get_sample_rate(void *platform, uint32_t *rate)
2349{
2350 struct platform_data *my_data = (struct platform_data *)platform;
2351 int ret = 0;
2352
2353 if (my_data->csd != NULL) {
2354 ret = my_data->csd->get_sample_rate(rate);
2355 if (ret < 0) {
2356 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2357 }
2358 }
2359 return ret;
2360}
2361
vivek mehtab6506412015-08-07 16:55:17 -07002362void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2363 snd_device_t snd_device,
2364 bool enable)
2365{
2366 const char* name;
2367 switch (snd_device) {
2368 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2369 if (enable)
2370 name = "spkr-gain-in-headphone-combo";
2371 else
2372 name = "speaker-gain-default";
2373 break;
2374 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2375 if (enable)
2376 name = "spkr-gain-in-line-combo";
2377 else
2378 name = "speaker-gain-default";
2379 break;
2380 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2381 if (enable)
2382 name = "spkr-safe-gain-in-headphone-combo";
2383 else
2384 name = "speaker-safe-gain-default";
2385 break;
2386 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2387 if (enable)
2388 name = "spkr-safe-gain-in-line-combo";
2389 else
2390 name = "speaker-safe-gain-default";
2391 break;
2392 default:
2393 return;
2394 }
2395
2396 audio_route_apply_and_update_path(adev->audio_route, name);
2397}
2398
Eric Laurentb23d5282013-05-14 15:27:20 -07002399int platform_set_voice_volume(void *platform, int volume)
2400{
2401 struct platform_data *my_data = (struct platform_data *)platform;
2402 struct audio_device *adev = my_data->adev;
2403 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002404 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002405 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002406 int vol_index = 0, ret = 0;
2407 uint32_t set_values[ ] = {0,
2408 ALL_SESSION_VSID,
2409 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002410
2411 // Voice volume levels are mapped to adsp volume levels as follows.
2412 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2413 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002414 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002415 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002416
2417 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2418 if (!ctl) {
2419 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2420 __func__, mixer_ctl_name);
2421 return -EINVAL;
2422 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002423 ALOGV("Setting voice volume index: %d", set_values[0]);
2424 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2425
Nadav Barc46d0fa2017-12-24 14:50:37 +02002426 // Send mute command in case volume index is max since indexes are inverted
2427 // for mixer controls.
2428 if (vol_index == my_data->max_vol_index) {
2429 set_values[0] = 1;
2430 }
2431 else {
2432 set_values[0] = 0;
2433 }
2434
2435 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2436 if (!ctl) {
2437 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2438 __func__, mute_mixer_ctl_name);
2439 return -EINVAL;
2440 }
2441 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2442 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2443
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002444 if (my_data->csd != NULL) {
2445 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2446 DEFAULT_VOLUME_RAMP_DURATION_MS);
2447 if (ret < 0) {
2448 ALOGE("%s: csd_volume error %d", __func__, ret);
2449 }
2450 }
2451 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002452}
2453
2454int platform_set_mic_mute(void *platform, bool state)
2455{
2456 struct platform_data *my_data = (struct platform_data *)platform;
2457 struct audio_device *adev = my_data->adev;
2458 struct mixer_ctl *ctl;
2459 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002460 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002461 uint32_t set_values[ ] = {0,
2462 ALL_SESSION_VSID,
2463 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002464
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002465 if (adev->mode != AUDIO_MODE_IN_CALL &&
2466 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002467 return 0;
2468
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002469 if (adev->enable_hfp)
2470 mixer_ctl_name = "HFP Tx Mute";
2471
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002472 set_values[0] = state;
2473 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2474 if (!ctl) {
2475 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2476 __func__, mixer_ctl_name);
2477 return -EINVAL;
2478 }
2479 ALOGV("Setting voice mute state: %d", state);
2480 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2481
2482 if (my_data->csd != NULL) {
2483 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2484 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002485 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002486 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002487 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002488 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002489 return ret;
2490}
Eric Laurentb23d5282013-05-14 15:27:20 -07002491
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002492int platform_set_device_mute(void *platform, bool state, char *dir)
2493{
2494 struct platform_data *my_data = (struct platform_data *)platform;
2495 struct audio_device *adev = my_data->adev;
2496 struct mixer_ctl *ctl;
2497 char *mixer_ctl_name = NULL;
2498 int ret = 0;
2499 uint32_t set_values[ ] = {0,
2500 ALL_SESSION_VSID,
2501 0};
2502 if(dir == NULL) {
2503 ALOGE("%s: Invalid direction:%s", __func__, dir);
2504 return -EINVAL;
2505 }
2506
2507 if (!strncmp("rx", dir, sizeof("rx"))) {
2508 mixer_ctl_name = "Voice Rx Device Mute";
2509 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2510 mixer_ctl_name = "Voice Tx Device Mute";
2511 } else {
2512 return -EINVAL;
2513 }
2514
2515 set_values[0] = state;
2516 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2517 if (!ctl) {
2518 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2519 __func__, mixer_ctl_name);
2520 return -EINVAL;
2521 }
2522
2523 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2524 __func__,state, mixer_ctl_name);
2525 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2526
2527 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002528}
2529
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002530int platform_can_split_snd_device(snd_device_t snd_device,
2531 int *num_devices,
2532 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002533{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002534 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002535 if (NULL == num_devices || NULL == new_snd_devices) {
2536 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002537 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002538 }
2539
2540 /*
2541 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002542 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002543 */
2544 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2545 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2546 *num_devices = 2;
2547 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2548 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002549 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002550 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2551 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2552 *num_devices = 2;
2553 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2554 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002555 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002556 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2557 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2558 *num_devices = 2;
2559 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2560 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002561 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002562 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2563 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2564 *num_devices = 2;
2565 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2566 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002567 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002568 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2569 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2570 SND_DEVICE_OUT_BT_SCO)) {
2571 *num_devices = 2;
2572 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2573 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2574 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002575 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2576 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2577 SND_DEVICE_OUT_BT_SCO)) {
2578 *num_devices = 2;
2579 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2580 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2581 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002582 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2583 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2584 SND_DEVICE_OUT_BT_SCO_WB)) {
2585 *num_devices = 2;
2586 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2587 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2588 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002589 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2590 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2591 SND_DEVICE_OUT_BT_SCO_WB)) {
2592 *num_devices = 2;
2593 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2594 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2595 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002596 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2597 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2598 *num_devices = 2;
2599 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2600 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2601 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002602 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2603 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2604 *num_devices = 2;
2605 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2606 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2607 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002608 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2609 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2610 SND_DEVICE_OUT_BT_A2DP)) {
2611 *num_devices = 2;
2612 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2613 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2614 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002615 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2616 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2617 SND_DEVICE_OUT_BT_A2DP)) {
2618 *num_devices = 2;
2619 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2620 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2621 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002622 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002623
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002624 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002625}
2626
Eric Laurentb23d5282013-05-14 15:27:20 -07002627snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2628{
2629 struct platform_data *my_data = (struct platform_data *)platform;
2630 struct audio_device *adev = my_data->adev;
2631 audio_mode_t mode = adev->mode;
2632 snd_device_t snd_device = SND_DEVICE_NONE;
2633
2634 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2635 if (devices == AUDIO_DEVICE_NONE ||
2636 devices & AUDIO_DEVICE_BIT_IN) {
2637 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2638 goto exit;
2639 }
2640
Eric Laurent1b491552015-09-15 17:52:41 -07002641 if (popcount(devices) == 2) {
2642 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2643 AUDIO_DEVICE_OUT_SPEAKER) ||
2644 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2645 AUDIO_DEVICE_OUT_SPEAKER)) {
2646 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2647 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2648 AUDIO_DEVICE_OUT_SPEAKER)) {
2649 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2650 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2651 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2652 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2653 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2654 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2655 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2656 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2657 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2658 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2659 AUDIO_DEVICE_OUT_SPEAKER)) {
2660 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002661 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2662 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2663 snd_device = adev->bt_wb_speech_enabled ?
2664 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2665 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002666 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2667 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2668 snd_device = adev->bt_wb_speech_enabled ?
2669 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2670 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002671 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2672 AUDIO_DEVICE_OUT_SPEAKER)) ||
2673 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2674 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002675 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002676 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2677 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2678 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2679 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002680 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002681 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2682 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2683 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002684 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2685 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2686 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002687 } else {
2688 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2689 goto exit;
2690 }
2691 if (snd_device != SND_DEVICE_NONE) {
2692 goto exit;
2693 }
2694 }
2695
2696 if (popcount(devices) != 1) {
2697 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2698 goto exit;
2699 }
2700
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302701 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002702 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002703 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2704 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002705 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002706 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002707 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002708 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002709 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002710 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002711 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002712 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002713 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002714 else {
2715 if (devices & AUDIO_DEVICE_OUT_LINE)
2716 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2717 else
2718 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2719 }
Eric Laurent99dab492017-06-17 15:19:08 -07002720 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002721 if (voice_is_in_call(adev)) {
2722 switch (adev->voice.tty_mode) {
2723 case TTY_MODE_FULL:
2724 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2725 break;
2726 case TTY_MODE_VCO:
2727 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2728 break;
2729 case TTY_MODE_HCO:
2730 // since Hearing will be on handset\speaker, use existing device
2731 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2732 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002733 case TTY_MODE_OFF:
2734 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002735 default:
2736 ALOGE("%s: Invalid TTY mode (%#x)",
2737 __func__, adev->voice.tty_mode);
2738 }
2739 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002740 if (snd_device == SND_DEVICE_NONE) {
2741 snd_device = audio_extn_usb_is_capture_supported() ?
2742 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2743 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2744 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002745 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002746 if (adev->bt_wb_speech_enabled) {
2747 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2748 } else {
2749 snd_device = SND_DEVICE_OUT_BT_SCO;
2750 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002751 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2752 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002753 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002754 if (!adev->enable_hfp) {
2755 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2756 } else {
2757 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2758 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002759 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002760 if(adev->voice.hac)
2761 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2762 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002763 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2764 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002765 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002766 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2767 snd_device = SND_DEVICE_OUT_VOICE_TX;
2768
Eric Laurentb23d5282013-05-14 15:27:20 -07002769 if (snd_device != SND_DEVICE_NONE) {
2770 goto exit;
2771 }
2772 }
2773
Eric Laurentb23d5282013-05-14 15:27:20 -07002774 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2775 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2776 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002777 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2778 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002779 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2780 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002781 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002782 /*
2783 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2784 * Or there will be a small pause while performing device switch.
2785 */
2786 if (my_data->speaker_lr_swap &&
2787 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2788 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002789 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2790 else
2791 snd_device = SND_DEVICE_OUT_SPEAKER;
2792 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002793 if (adev->bt_wb_speech_enabled) {
2794 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2795 } else {
2796 snd_device = SND_DEVICE_OUT_BT_SCO;
2797 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002798 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2799 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002800 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2801 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002802 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002803 if (audio_extn_ma_supported_usb())
2804 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2805 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002806 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2807 else
2808 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2809 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002810 /*HAC support for voice-ish audio (eg visual voicemail)*/
2811 if(adev->voice.hac)
2812 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2813 else
2814 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002815 } else {
2816 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2817 }
2818exit:
2819 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2820 return snd_device;
2821}
2822
2823snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2824{
2825 struct platform_data *my_data = (struct platform_data *)platform;
2826 struct audio_device *adev = my_data->adev;
2827 audio_source_t source = (adev->active_input == NULL) ?
2828 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2829
2830 audio_mode_t mode = adev->mode;
2831 audio_devices_t in_device = ((adev->active_input == NULL) ?
2832 AUDIO_DEVICE_NONE : adev->active_input->device)
2833 & ~AUDIO_DEVICE_BIT_IN;
2834 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2835 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2836 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002837 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002838
Prashant Malanic92c5962015-08-11 15:10:18 -07002839 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2840 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002841 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2842 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002843 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002844 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002845 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2846 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002847 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002848 case TTY_MODE_FULL:
2849 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2850 break;
2851 case TTY_MODE_VCO:
2852 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2853 break;
2854 case TTY_MODE_HCO:
2855 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2856 break;
2857 default:
2858 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2859 }
2860 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002861 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002862 switch (adev->voice.tty_mode) {
2863 case TTY_MODE_FULL:
2864 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2865 break;
2866 case TTY_MODE_VCO:
2867 // since voice will be captured from handset mic, use existing device
2868 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2869 break;
2870 case TTY_MODE_HCO:
2871 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2872 break;
2873 default:
2874 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002875 }
2876 goto exit;
2877 }
2878 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002879 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002880 if (my_data->fluence_in_voice_call == false) {
2881 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2882 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002883 if (is_operator_tmus())
2884 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002885 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002886 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002887 }
2888 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2889 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2890 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
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 Laurentb991fb02014-08-29 15:23:17 -05002902 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002903 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2904 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2905 out_device & AUDIO_DEVICE_OUT_LINE) {
2906 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2907 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2908 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2909 } else {
2910 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2911 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002912 }
vivek mehtafe121d52015-08-10 23:39:23 -07002913
2914 //select default
2915 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002916 if (!adev->enable_hfp) {
2917 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2918 } else {
2919 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2920 platform_set_echo_reference(adev, true, out_device);
2921 }
vivek mehtafe121d52015-08-10 23:39:23 -07002922 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002923 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002924 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002925 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002926 if (audio_extn_usb_is_capture_supported()) {
2927 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2928 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2929 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2930 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2931 } else {
2932 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2933 }
2934 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002935 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002936 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2937 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2938 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2939 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2940 }
2941 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2942 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002943 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2944 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2945 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002946 if (adev->active_input->enable_aec)
2947 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2948 else
2949 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002950 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2951 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002952 if (adev->active_input->enable_aec)
2953 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2954 else
2955 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002956 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2957 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2958 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002959 if (adev->active_input->enable_aec)
2960 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2961 else
2962 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002963 }
2964 platform_set_echo_reference(adev, true, out_device);
2965 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2966 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2967 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002968 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002969 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2970 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002971 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002972 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2973 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002974 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002975 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002976 if (adev->active_input->enable_aec) {
2977 if (adev->active_input->enable_ns) {
2978 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2979 } else {
2980 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2981 }
vivek mehta733c1df2016-04-04 15:09:24 -07002982 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002983 } else if (adev->active_input->enable_ns) {
2984 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2985 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002986 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002987 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002988 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002989 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2990 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002991 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002992 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002993 }
rago90fb9612015-12-02 11:37:53 -08002994 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2995 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002996 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2997 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2998 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2999 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003000 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003001 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3002 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003003 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003004 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3005 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3006 } else {
3007 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3008 }
rago90fb9612015-12-02 11:37:53 -08003009 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3010 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003011 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003012 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003013 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003014 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003015 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003016 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3017 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3018 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3019 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003020 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003021 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003022 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003023 if (adev->active_input->enable_aec &&
3024 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003025 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003026 if (my_data->fluence_in_spkr_mode &&
3027 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003028 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003029 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003030 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003031 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003032 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003033 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003034 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003035 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003036 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003037 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003038 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003039 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003040 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3041 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003042 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003043 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003044 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003045 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003046 } else if (adev->active_input->enable_aec) {
3047 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3048 if (my_data->fluence_in_spkr_mode &&
3049 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003050 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003051 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003052 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003053 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003054 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003055 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3056 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003057 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003058 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003059 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003060 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003061 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003062 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3063 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003064 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003065 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05003066 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08003067 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003068 } else if (adev->active_input->enable_ns) {
3069 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3070 if (my_data->fluence_in_spkr_mode &&
3071 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003072 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003073 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003074 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003075 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003076 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003077 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3078 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003079 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003080 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003081 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003082 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003083 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003084 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003085 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003086 }
3087 } else if (source == AUDIO_SOURCE_DEFAULT) {
3088 goto exit;
3089 }
3090
3091
3092 if (snd_device != SND_DEVICE_NONE) {
3093 goto exit;
3094 }
3095
3096 if (in_device != AUDIO_DEVICE_NONE &&
3097 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3098 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3099 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003100 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003101 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003102 snd_device = SND_DEVICE_IN_QUAD_MIC;
3103 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003104 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003105 snd_device = SND_DEVICE_IN_THREE_MIC;
3106 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3107 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003108 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003109 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3110 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003111 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003112 } else {
3113 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3114 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3115 my_data->source_mic_type, channel_count, channel_mask);
3116 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3117 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003118 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003119 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3120 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003121 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003122 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3123 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003124 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003125 } else {
3126 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3127 " no combination found .. setting to mono", __func__,
3128 my_data->source_mic_type, channel_count);
3129 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3130 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003131 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3132 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3133 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003134 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003135 if (adev->bluetooth_nrec)
3136 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3137 else
3138 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003139 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003140 if (adev->bluetooth_nrec)
3141 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3142 else
3143 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003144 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003145 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3146 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003147 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003148 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003149 } else {
3150 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3151 ALOGW("%s: Using default handset-mic", __func__);
3152 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3153 }
3154 } else {
3155 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3156 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3157 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3158 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003159 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003160 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003161 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003162 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003163 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3164 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003165 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003166 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3167 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003168 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003169 } else {
3170 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3171 " no combination found .. setting to mono", __func__,
3172 my_data->source_mic_type, channel_count);
3173 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3174 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003175 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003176 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003177 if (adev->bluetooth_nrec)
3178 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3179 else
3180 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003181 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003182 if (adev->bluetooth_nrec)
3183 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3184 else
3185 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003186 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003187 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3188 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003189 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003190 if (audio_extn_usb_is_capture_supported())
3191 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3192 else
3193 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003194 } else {
3195 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3196 ALOGW("%s: Using default handset-mic", __func__);
3197 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3198 }
3199 }
3200exit:
3201 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3202 return snd_device;
3203}
3204
3205int platform_set_hdmi_channels(void *platform, int channel_count)
3206{
3207 struct platform_data *my_data = (struct platform_data *)platform;
3208 struct audio_device *adev = my_data->adev;
3209 struct mixer_ctl *ctl;
3210 const char *channel_cnt_str = NULL;
3211 const char *mixer_ctl_name = "HDMI_RX Channels";
3212 switch (channel_count) {
3213 case 8:
3214 channel_cnt_str = "Eight"; break;
3215 case 7:
3216 channel_cnt_str = "Seven"; break;
3217 case 6:
3218 channel_cnt_str = "Six"; break;
3219 case 5:
3220 channel_cnt_str = "Five"; break;
3221 case 4:
3222 channel_cnt_str = "Four"; break;
3223 case 3:
3224 channel_cnt_str = "Three"; break;
3225 default:
3226 channel_cnt_str = "Two"; break;
3227 }
3228 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3229 if (!ctl) {
3230 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3231 __func__, mixer_ctl_name);
3232 return -EINVAL;
3233 }
3234 ALOGV("HDMI channel count: %s", channel_cnt_str);
3235 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3236 return 0;
3237}
3238
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003239int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003240{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003241 struct platform_data *my_data = (struct platform_data *)platform;
3242 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003243 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3244 char *sad = block;
3245 int num_audio_blocks;
3246 int channel_count;
3247 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003248 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003249
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003250 struct mixer_ctl *ctl;
3251
3252 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3253 if (!ctl) {
3254 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3255 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003256 return 0;
3257 }
3258
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003259 mixer_ctl_update(ctl);
3260
3261 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003262
3263 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003264 if (count > (int)sizeof(block))
3265 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003266
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003267 ret = mixer_ctl_get_array(ctl, block, count);
3268 if (ret != 0) {
3269 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3270 return 0;
3271 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003272
3273 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003274 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003275
3276 for (i = 0; i < num_audio_blocks; i++) {
3277 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003278 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3279 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003280 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003281 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003282
3283 channel_count = (sad[0] & 0x7) + 1;
3284 if (channel_count > max_channels)
3285 max_channels = channel_count;
3286
3287 /* Advance to next block */
3288 sad += 3;
3289 }
3290
3291 return max_channels;
3292}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003293
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003294int platform_set_incall_recording_session_id(void *platform,
3295 uint32_t session_id, int rec_mode)
3296{
3297 int ret = 0;
3298 struct platform_data *my_data = (struct platform_data *)platform;
3299 struct audio_device *adev = my_data->adev;
3300 struct mixer_ctl *ctl;
3301 const char *mixer_ctl_name = "Voc VSID";
3302 int num_ctl_values;
3303 int i;
3304
3305 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3306 if (!ctl) {
3307 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3308 __func__, mixer_ctl_name);
3309 ret = -EINVAL;
3310 } else {
3311 num_ctl_values = mixer_ctl_get_num_values(ctl);
3312 for (i = 0; i < num_ctl_values; i++) {
3313 if (mixer_ctl_set_value(ctl, i, session_id)) {
3314 ALOGV("Error: invalid session_id: %x", session_id);
3315 ret = -EINVAL;
3316 break;
3317 }
3318 }
3319 }
3320
3321 if (my_data->csd != NULL) {
3322 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3323 if (ret < 0) {
3324 ALOGE("%s: csd_client_start_record failed, error %d",
3325 __func__, ret);
3326 }
3327 }
3328
3329 return ret;
3330}
3331
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003332int platform_set_incall_recording_session_channels(void *platform,
3333 uint32_t channel_count)
3334{
3335 int ret = 0;
3336 struct platform_data *my_data = (struct platform_data *)platform;
3337 struct audio_device *adev = my_data->adev;
3338 const char *mixer_ctl_name = "Voc Rec Config";
3339 int num_ctl_values;
3340 int i;
3341 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3342
3343 if (!ctl) {
3344 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3345 __func__, mixer_ctl_name);
3346 ret = -EINVAL;
3347 } else {
3348 num_ctl_values = mixer_ctl_get_num_values(ctl);
3349 for (i = 0; i < num_ctl_values; i++) {
3350 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3351 ALOGE("Error: invalid channel count: %x", channel_count);
3352 ret = -EINVAL;
3353 break;
3354 }
3355 }
3356 }
3357
3358 return ret;
3359}
3360
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003361int platform_stop_incall_recording_usecase(void *platform)
3362{
3363 int ret = 0;
3364 struct platform_data *my_data = (struct platform_data *)platform;
3365
3366 if (my_data->csd != NULL) {
3367 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3368 if (ret < 0) {
3369 ALOGE("%s: csd_client_stop_record failed, error %d",
3370 __func__, ret);
3371 }
3372 }
3373
3374 return ret;
3375}
3376
3377int platform_start_incall_music_usecase(void *platform)
3378{
3379 int ret = 0;
3380 struct platform_data *my_data = (struct platform_data *)platform;
3381
3382 if (my_data->csd != NULL) {
3383 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3384 if (ret < 0) {
3385 ALOGE("%s: csd_client_start_playback failed, error %d",
3386 __func__, ret);
3387 }
3388 }
3389
3390 return ret;
3391}
3392
3393int platform_stop_incall_music_usecase(void *platform)
3394{
3395 int ret = 0;
3396 struct platform_data *my_data = (struct platform_data *)platform;
3397
3398 if (my_data->csd != NULL) {
3399 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3400 if (ret < 0) {
3401 ALOGE("%s: csd_client_stop_playback failed, error %d",
3402 __func__, ret);
3403 }
3404 }
3405
3406 return ret;
3407}
3408
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003409int platform_set_parameters(void *platform, struct str_parms *parms)
3410{
3411 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003412 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003413 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003414 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003415 int ret = 0, err;
3416
3417 if (kv_pairs == NULL) {
3418 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003419 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003420 goto done;
3421 }
3422
3423 ALOGV("%s: enter: %s", __func__, kv_pairs);
3424
jasmine chac89321b2018-04-10 21:37:01 +08003425 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003426 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003427 if (value == NULL) {
3428 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003429 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003430 goto done;
3431 }
3432
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003433 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003434 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003435 if (err >= 0) {
3436 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3437 my_data->snd_card_name = strdup(value);
3438 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3439 }
3440
keunhui.park2f7306a2015-07-16 16:48:06 +09003441 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003442 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003443 if (err >= 0) {
3444 struct operator_info *info;
3445 char *str = value;
3446 char *name;
3447
3448 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3449 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3450 name = strtok(str, ";");
3451 info->name = strdup(name);
3452 info->mccmnc = strdup(str + strlen(name) + 1);
3453
3454 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003455 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003456 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003457
Jasmine Chaa314e192018-05-09 17:46:28 +08003458 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003459 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003460 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003461 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003462 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003463 my_data->max_mic_count = atoi(value);
3464 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003465 }
3466
jasmine chac89321b2018-04-10 21:37:01 +08003467 /* handle audio calibration parameters */
3468 set_audiocal(platform, parms, value, len);
3469
vivek mehta90933872017-06-15 18:04:39 -07003470 // to-do: disable setting sidetone gain, will revist this later
3471 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003472done:
3473 ALOGV("%s: exit with code(%d)", __func__, ret);
3474 if (kv_pairs != NULL)
3475 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003476 if (value != NULL)
3477 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003478
3479 return ret;
3480}
3481
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003482/* Delay in Us */
3483int64_t platform_render_latency(audio_usecase_t usecase)
3484{
3485 switch (usecase) {
3486 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3487 return DEEP_BUFFER_PLATFORM_DELAY;
3488 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3489 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003490 case USECASE_AUDIO_PLAYBACK_ULL:
3491 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003492 case USECASE_AUDIO_PLAYBACK_MMAP:
3493 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003494 default:
3495 return 0;
3496 }
3497}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003498
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003499int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3500 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003501{
3502 int ret = 0;
3503
3504 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3505 ALOGE("%s: Invalid snd_device = %d",
3506 __func__, device);
3507 ret = -EINVAL;
3508 goto done;
3509 }
3510
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003511 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3512 platform_get_snd_device_name(device),
3513 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3514 if (backend_tag_table[device]) {
3515 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003516 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003517 backend_tag_table[device] = strdup(backend_tag);
3518
3519 if (hw_interface != NULL) {
3520 if (hw_interface_table[device])
3521 free(hw_interface_table[device]);
3522 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3523 hw_interface_table[device] = strdup(hw_interface);
3524 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003525done:
3526 return ret;
3527}
3528
3529int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3530{
3531 int ret = 0;
3532 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3533 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3534 ret = -EINVAL;
3535 goto done;
3536 }
3537
3538 if ((type != 0) && (type != 1)) {
3539 ALOGE("%s: invalid usecase type", __func__);
3540 ret = -EINVAL;
3541 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003542 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3543 use_case_table[usecase],
3544 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003545 pcm_device_table[usecase][type] = pcm_id;
3546done:
3547 return ret;
3548}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003549
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003550#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3551int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3552 // backup_gain: gain to try to set in case of an error during ramp
3553 int start_gain, end_gain, step, backup_gain, i;
3554 bool error = false;
3555 const struct mixer_ctl *ctl;
3556 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3557 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3558 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3559 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3560 if (!ctl_left || !ctl_right) {
3561 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3562 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3563 return -EINVAL;
3564 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3565 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3566 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3567 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3568 return -EINVAL;
3569 }
3570 if (ramp_up) {
3571 start_gain = 0;
3572 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3573 step = +1;
3574 backup_gain = end_gain;
3575 } else {
3576 // using same gain on left and right
3577 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3578 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3579 end_gain = 0;
3580 step = -1;
3581 backup_gain = start_gain;
3582 }
3583 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3584 //ALOGV("setting speaker gain to %d", i);
3585 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3586 ALOGE("%s: error setting %s to %d during gain ramp",
3587 __func__, mixer_ctl_name_gain_left, i);
3588 error = true;
3589 break;
3590 }
3591 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3592 ALOGE("%s: error setting %s to %d during gain ramp",
3593 __func__, mixer_ctl_name_gain_right, i);
3594 error = true;
3595 break;
3596 }
3597 usleep(1000);
3598 }
3599 if (error) {
3600 // an error occured during the ramp, let's still try to go back to a safe volume
3601 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3602 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3603 }
3604 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3605 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3606 }
3607 }
3608 return start_gain;
3609}
3610
vivek mehtae59cfb22017-06-16 15:57:11 -07003611int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3612{
3613 const char *mixer_ctl_name = "Swap channel";
3614 struct mixer_ctl *ctl;
3615 const char *mixer_path;
3616 struct platform_data *my_data = (struct platform_data *)adev->platform;
3617
3618 // forced to set to swap, but device not rotated ... ignore set
3619 if (swap_channels && !my_data->speaker_lr_swap)
3620 return 0;
3621
3622 ALOGV("%s:", __func__);
3623
3624 if (swap_channels) {
3625 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3626 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3627 } else {
3628 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3629 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3630 }
3631
3632 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3633 if (!ctl) {
3634 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3635 return -EINVAL;
3636 }
3637
3638 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3639 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3640 return -EINVAL;
3641 }
3642
3643 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3644 swap_channels?"R --> L":"L --> R");
3645
3646 return 0;
3647}
3648
3649int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003650{
3651 // only update if there is active pcm playback on speaker
3652 struct audio_usecase *usecase;
3653 struct listnode *node;
3654 struct platform_data *my_data = (struct platform_data *)adev->platform;
3655
vivek mehtae59cfb22017-06-16 15:57:11 -07003656 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003657
vivek mehtae59cfb22017-06-16 15:57:11 -07003658 return platform_set_swap_channels(adev, swap_channels);
3659}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003660
vivek mehtae59cfb22017-06-16 15:57:11 -07003661int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3662{
3663 // only update if there is active pcm playback on speaker
3664 struct audio_usecase *usecase;
3665 struct listnode *node;
3666 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003667
vivek mehtae59cfb22017-06-16 15:57:11 -07003668 // do not swap channels in audio modes with concurrent capture and playback
3669 // as this may break the echo reference
3670 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3671 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3672 return 0;
3673 }
3674
3675 list_for_each(node, &adev->usecase_list) {
3676 usecase = node_to_item(node, struct audio_usecase, list);
3677 if (usecase->type == PCM_PLAYBACK &&
3678 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3679 /*
3680 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3681 * to perform device switch to disable the current backend to
3682 * enable it with new acdb data.
3683 */
3684 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3685 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3686 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3687 select_devices(adev, usecase->id);
3688 if (initial_skpr_gain != -EINVAL)
3689 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3690
3691 } else {
3692 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003693 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003694 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003695 }
3696 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003697
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003698 return 0;
3699}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003700
3701static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3702static int num_gain_tbl_entry = 0;
3703
3704bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3705
3706 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3707 if (num_gain_tbl_entry == -1) {
3708 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3709 __func__);
3710 return false;
3711 }
3712
3713 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3714 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3715 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3716 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3717 return false;
3718 }
3719
3720 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3721 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3722 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3723 return false;
3724 }
3725
3726 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3727 ++num_gain_tbl_entry;
3728
3729 return true;
3730}
3731
3732int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3733 int table_size) {
3734 int itt = 0;
3735 ALOGV("platform_get_gain_level_mapping called ");
3736
3737 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3738 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3739 return 0;
3740 }
3741
3742 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3743 mapping_tbl[itt] = tbl_mapping[itt];
3744 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3745 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3746 }
3747
3748 return num_gain_tbl_entry;
3749}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003750
3751int platform_snd_card_update(void *platform, card_status_t status)
3752{
3753 struct platform_data *my_data = (struct platform_data *)platform;
3754 struct audio_device *adev = my_data->adev;
3755
3756 if (status == CARD_STATUS_ONLINE) {
3757 if (my_data->acdb_send_custom_top)
3758 my_data->acdb_send_custom_top();
3759 }
3760 return 0;
3761}
David Linee3fe402017-03-13 10:00:42 -07003762
3763/*
3764 * configures afe with bit width and Sample Rate
3765 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003766int platform_set_backend_cfg(const struct audio_device* adev,
3767 snd_device_t snd_device,
3768 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003769{
3770
3771 int ret = 0;
3772 const int backend_idx = platform_get_backend_index(snd_device);
3773 struct platform_data *my_data = (struct platform_data *)adev->platform;
3774 const unsigned int bit_width = backend_cfg->bit_width;
3775 const unsigned int sample_rate = backend_cfg->sample_rate;
3776 const unsigned int channels = backend_cfg->channels;
3777 const audio_format_t format = backend_cfg->format;
3778 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3779
3780
3781 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3782 ", backend_idx %d device (%s)", __func__, bit_width,
3783 sample_rate, channels, backend_idx,
3784 platform_get_snd_device_name(snd_device));
3785
3786 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3787 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3788
3789 struct mixer_ctl *ctl = NULL;
3790 ctl = mixer_get_ctl_by_name(adev->mixer,
3791 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3792 if (!ctl) {
3793 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3794 __func__,
3795 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3796 return -EINVAL;
3797 }
3798
3799 if (bit_width == 24) {
3800 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3801 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3802 else
3803 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3804 } else if (bit_width == 32) {
3805 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3806 } else {
3807 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3808 }
3809 if ( ret < 0) {
3810 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3811 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3812 } else {
3813 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3814 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3815 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3816 }
3817 /* set the ret as 0 and not pass back to upper layer */
3818 ret = 0;
3819 }
3820
3821 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3822 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3823 char *rate_str = NULL;
3824 struct mixer_ctl *ctl = NULL;
3825
3826 switch (sample_rate) {
3827 case 32000:
3828 if (passthrough_enabled) {
3829 rate_str = "KHZ_32";
3830 break;
3831 }
3832 case 8000:
3833 case 11025:
3834 case 16000:
3835 case 22050:
3836 case 48000:
3837 rate_str = "KHZ_48";
3838 break;
3839 case 44100:
3840 rate_str = "KHZ_44P1";
3841 break;
3842 case 64000:
3843 case 96000:
3844 rate_str = "KHZ_96";
3845 break;
3846 case 88200:
3847 rate_str = "KHZ_88P2";
3848 break;
3849 case 176400:
3850 rate_str = "KHZ_176P4";
3851 break;
3852 case 192000:
3853 rate_str = "KHZ_192";
3854 break;
3855 case 352800:
3856 rate_str = "KHZ_352P8";
3857 break;
3858 case 384000:
3859 rate_str = "KHZ_384";
3860 break;
3861 case 144000:
3862 if (passthrough_enabled) {
3863 rate_str = "KHZ_144";
3864 break;
3865 }
3866 default:
3867 rate_str = "KHZ_48";
3868 break;
3869 }
3870
3871 ctl = mixer_get_ctl_by_name(adev->mixer,
3872 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3873 if(!ctl) {
3874 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3875 __func__,
3876 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3877 return -EINVAL;
3878 }
3879
3880 ALOGD("%s:becf: afe: %s set to %s", __func__,
3881 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3882 mixer_ctl_set_enum_by_string(ctl, rate_str);
3883 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3884 }
3885 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3886 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3887 struct mixer_ctl *ctl = NULL;
3888 char *channel_cnt_str = NULL;
3889
3890 switch (channels) {
3891 case 8:
3892 channel_cnt_str = "Eight"; break;
3893 case 7:
3894 channel_cnt_str = "Seven"; break;
3895 case 6:
3896 channel_cnt_str = "Six"; break;
3897 case 5:
3898 channel_cnt_str = "Five"; break;
3899 case 4:
3900 channel_cnt_str = "Four"; break;
3901 case 3:
3902 channel_cnt_str = "Three"; break;
3903 case 1:
3904 channel_cnt_str = "One"; break;
3905 case 2:
3906 default:
3907 channel_cnt_str = "Two"; break;
3908 }
3909
3910 ctl = mixer_get_ctl_by_name(adev->mixer,
3911 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3912 if (!ctl) {
3913 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3914 __func__,
3915 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3916 return -EINVAL;
3917 }
3918 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3919 my_data->current_backend_cfg[backend_idx].channels = channels;
3920
3921 // skip EDID configuration for HDMI backend
3922
3923 ALOGD("%s:becf: afe: %s set to %s", __func__,
3924 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3925 channel_cnt_str);
3926 }
3927
3928 // skip set ext_display format mixer control
3929 return ret;
3930}
3931
3932static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3933{
3934 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3935 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3936 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3937 }
3938
3939 return backend_bit_width_table[snd_device];
3940}
3941
3942/*
3943 * return backend_idx on which voice call is active
3944 */
3945static int platform_get_voice_call_backend(struct audio_device* adev)
3946{
3947 struct audio_usecase *uc = NULL;
3948 struct listnode *node;
3949 snd_device_t out_snd_device = SND_DEVICE_NONE;
3950
3951 int backend_idx = -1;
3952
3953 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3954 list_for_each(node, &adev->usecase_list) {
3955 uc = node_to_item(node, struct audio_usecase, list);
3956 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3957 out_snd_device = platform_get_output_snd_device(adev->platform,
3958 uc->stream.out->devices);
3959 backend_idx = platform_get_backend_index(out_snd_device);
3960 break;
3961 }
3962 }
3963 }
3964 return backend_idx;
3965}
3966
3967/*
3968 * goes through all the current usecases and picks the highest
3969 * bitwidth & samplerate
3970 */
3971static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3972 int backend_idx,
3973 struct audio_backend_cfg *backend_cfg)
3974{
3975 bool backend_change = false;
3976 unsigned int bit_width;
3977 unsigned int sample_rate;
3978 unsigned int channels;
3979 struct platform_data *my_data = (struct platform_data *)adev->platform;
3980
3981 bit_width = backend_cfg->bit_width;
3982 sample_rate = backend_cfg->sample_rate;
3983 channels = backend_cfg->channels;
3984
3985 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3986 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3987 sample_rate, channels);
3988
3989 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3990 // default backend
3991 // force routing is not required here, caller will do it anyway
3992 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3993 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3994 "for unprocessed/camera source", __func__);
3995 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3996 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3997 }
3998
3999 if (backend_idx == USB_AUDIO_TX_BACKEND) {
4000 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
4001 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4002 __func__, bit_width, sample_rate, channels);
4003 }
4004
4005 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4006 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4007
4008 // Force routing if the expected bitwdith or samplerate
4009 // is not same as current backend comfiguration
4010 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4011 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4012 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4013 backend_cfg->bit_width = bit_width;
4014 backend_cfg->sample_rate= sample_rate;
4015 backend_cfg->channels = channels;
4016 backend_change = true;
4017 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4018 "new sample rate: %d new channel: %d",
4019 __func__, backend_cfg->bit_width,
4020 backend_cfg->sample_rate, backend_cfg->channels);
4021 }
4022
4023 return backend_change;
4024}
4025
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004026static void pick_playback_cfg_for_uc(struct audio_device *adev,
4027 struct audio_usecase *usecase,
4028 snd_device_t snd_device,
4029 unsigned int *bit_width,
4030 unsigned int *sample_rate,
4031 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004032{
4033 int i =0;
4034 struct listnode *node;
4035 list_for_each(node, &adev->usecase_list) {
4036 struct audio_usecase *uc;
4037 uc = node_to_item(node, struct audio_usecase, list);
4038 struct stream_out *out = (struct stream_out*) uc->stream.out;
4039 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4040 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4041 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4042 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4043 uc->id, out->sample_rate,
4044 pcm_format_to_bits(out->config.format), out_channels,
4045 platform_get_snd_device_name(uc->out_snd_device));
4046
4047 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4048 if (*bit_width < pcm_format_to_bits(out->config.format))
4049 *bit_width = pcm_format_to_bits(out->config.format);
4050 if (*sample_rate < out->sample_rate)
4051 *sample_rate = out->sample_rate;
4052 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4053 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4054 if (*channels < out_channels)
4055 *channels = out_channels;
4056 }
4057 }
4058 }
4059 return;
4060}
4061
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004062static void headset_is_config_supported(unsigned int *bit_width,
4063 unsigned int *sample_rate,
4064 unsigned int *channels) {
4065 switch (*bit_width) {
4066 case 16:
4067 case 24:
4068 break;
4069 default:
4070 *bit_width = 16;
4071 break;
4072 }
4073
4074 if (*sample_rate > 192000) {
4075 *sample_rate = 192000;
4076 }
4077
4078 if (*channels > 2) {
4079 *channels = 2;
4080 }
4081}
4082
David Linee3fe402017-03-13 10:00:42 -07004083static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4084 struct audio_usecase* usecase,
4085 snd_device_t snd_device,
4086 struct audio_backend_cfg *backend_cfg)
4087{
4088 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004089 unsigned int bit_width;
4090 unsigned int sample_rate;
4091 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004092 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004093 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004094 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004095
4096 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4097 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4098 backend_change = false;
4099 return backend_change;
4100 }
4101
4102 backend_idx = platform_get_backend_index(snd_device);
4103 bit_width = backend_cfg->bit_width;
4104 sample_rate = backend_cfg->sample_rate;
4105 channels = backend_cfg->channels;
4106
4107 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4108 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4109 sample_rate, channels, backend_idx, usecase->id,
4110 platform_get_snd_device_name(snd_device));
4111
4112 if (backend_idx == platform_get_voice_call_backend(adev)) {
4113 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4114 __func__);
4115 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4116 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4117 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4118 } else {
4119 /*
4120 * The backend should be configured at highest bit width and/or
4121 * sample rate amongst all playback usecases.
4122 * If the selected sample rate and/or bit width differ with
4123 * current backend sample rate and/or bit width, then, we set the
4124 * backend re-configuration flag.
4125 *
4126 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4127 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004128 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4129 &bit_width,
4130 &sample_rate,
4131 &channels);
David Linee3fe402017-03-13 10:00:42 -07004132 }
4133
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004134 switch (backend_idx) {
4135 case USB_AUDIO_RX_BACKEND:
4136 audio_extn_usb_is_config_supported(&bit_width,
4137 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004138 if (platform_get_usb_service_interval(adev->platform, true,
4139 &service_interval) == 0) {
4140 /* overwrite with best altset for this service interval */
4141 int ret =
4142 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4143 service_interval,
4144 &bit_width,
4145 &sample_rate,
4146 &channels);
4147 if (ret < 0) {
4148 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4149 service_interval);
4150 return false;
4151 }
4152 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004153 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4154 __func__, bit_width, sample_rate, channels);
4155 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004156 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004157 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4158 break;
4159 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004160 default:
4161 bit_width = platform_get_snd_device_bit_width(snd_device);
4162 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4163 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4164 break;
David Linee3fe402017-03-13 10:00:42 -07004165 }
4166
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004167 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4168 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004169 __func__, backend_idx , bit_width, sample_rate);
4170
4171 // Force routing if the expected bitwdith or samplerate
4172 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004173 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4174 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4175 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004176 backend_cfg->bit_width = bit_width;
4177 backend_cfg->sample_rate = sample_rate;
4178 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004179 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004180 backend_change = true;
4181 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4182 "new sample rate: %d new channels: %d",
4183 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4184 }
4185
4186 return backend_change;
4187}
4188
4189bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4190 struct audio_usecase *usecase, snd_device_t snd_device)
4191{
4192 int backend_idx = DEFAULT_CODEC_BACKEND;
4193 int new_snd_devices[SND_DEVICE_OUT_END];
4194 int i, num_devices = 1;
4195 bool ret = false;
4196 struct platform_data *my_data = (struct platform_data *)adev->platform;
4197 struct audio_backend_cfg backend_cfg;
4198
4199 backend_idx = platform_get_backend_index(snd_device);
4200
4201 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4202 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4203 backend_cfg.format = usecase->stream.out->format;
4204 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4205 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4206 backend_cfg.passthrough_enabled = false;
4207
4208 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4209 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4210 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4211 platform_get_snd_device_name(snd_device));
4212
4213 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4214 new_snd_devices[0] = snd_device;
4215
4216 for (i = 0; i < num_devices; i++) {
4217 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4218 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4219 &backend_cfg))) {
4220 platform_set_backend_cfg(adev, new_snd_devices[i],
4221 &backend_cfg);
4222 ret = true;
4223 }
4224 }
4225 return ret;
4226}
4227
4228bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4229 struct audio_usecase *usecase, snd_device_t snd_device)
4230{
4231 int backend_idx = platform_get_backend_index(snd_device);
4232 int ret = 0;
4233 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004234 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004235
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004236 if (usecase->type == PCM_CAPTURE) {
4237 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004238 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4239 } else {
4240 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4241 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4242 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4243 backend_cfg.channels = 1;
4244 }
4245
4246 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4247 ", backend_idx %d usecase = %d device (%s)", __func__,
4248 backend_cfg.bit_width,
4249 backend_cfg.sample_rate,
4250 backend_cfg.channels,
4251 backend_idx, usecase->id,
4252 platform_get_snd_device_name(snd_device));
4253
4254 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4255 ret = platform_set_backend_cfg(adev, snd_device,
4256 &backend_cfg);
4257 if(!ret)
4258 return true;
4259 }
4260
4261 return false;
4262}
4263
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004264static int max_be_dai_names = 0;
4265static const struct be_dai_name_struct *be_dai_name_table;
4266
4267/*
4268 * Retrieves the be_dai_name_table from kernel to enable a mapping
4269 * between sound device hw interfaces and backend IDs. This allows HAL to
4270 * specify the backend a specific calibration is needed for.
4271 */
4272static int init_be_dai_name_table(struct audio_device *adev)
4273{
4274 const char *mixer_ctl_name = "Backend DAI Name Table";
4275 struct mixer_ctl *ctl;
4276 int i, j, ret, size;
4277 bool valid_hw_interface;
4278
4279 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4280 if (!ctl) {
4281 ALOGE("%s: Could not get ctl for mixer name %s\n",
4282 __func__, mixer_ctl_name);
4283 ret = -EINVAL;
4284 goto done;
4285 }
4286
4287 mixer_ctl_update(ctl);
4288
4289 size = mixer_ctl_get_num_values(ctl);
4290 if (size <= 0){
4291 ALOGE("%s: Failed to get %s size %d\n",
4292 __func__, mixer_ctl_name, size);
4293 ret = -EFAULT;
4294 goto done;
4295 }
4296
vivek mehtaa68fea62017-06-08 19:04:02 -07004297 be_dai_name_table =
4298 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004299 if (be_dai_name_table == NULL) {
4300 ALOGE("%s: Failed to allocate memory for %s\n",
4301 __func__, mixer_ctl_name);
4302 ret = -ENOMEM;
4303 goto freeMem;
4304 }
4305
4306 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4307 if (ret) {
4308 ALOGE("%s: Failed to get %s, ret %d\n",
4309 __func__, mixer_ctl_name, ret);
4310 ret = -EFAULT;
4311 goto freeMem;
4312 }
4313
4314 if (be_dai_name_table != NULL) {
4315 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4316 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4317 __func__, mixer_ctl_name, max_be_dai_names);
4318 ret = 0;
4319 } else {
4320 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4321 ret = -EFAULT;
4322 goto freeMem;
4323 }
4324
4325 /*
4326 * Validate all sound devices have a valid backend set to catch
4327 * errors for uncommon sound devices
4328 */
4329 for (i = 0; i < SND_DEVICE_MAX; i++) {
4330 valid_hw_interface = false;
4331
4332 if (hw_interface_table[i] == NULL) {
4333 ALOGW("%s: sound device %s has no hw interface set\n",
4334 __func__, platform_get_snd_device_name(i));
4335 continue;
4336 }
4337
4338 for (j = 0; j < max_be_dai_names; j++) {
4339 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4340 == 0) {
4341 valid_hw_interface = true;
4342 break;
4343 }
4344 }
4345 if (!valid_hw_interface)
4346 ALOGD("%s: sound device %s does not have a valid hw interface set "
4347 "(disregard for combo devices) %s\n",
4348 __func__, platform_get_snd_device_name(i),
4349 hw_interface_table[i]);
4350 }
4351
4352 goto done;
4353
4354freeMem:
4355 if (be_dai_name_table) {
4356 free((void *)be_dai_name_table);
4357 be_dai_name_table = NULL;
4358 }
4359
4360done:
4361 return ret;
4362}
4363
4364int platform_get_snd_device_backend_index(snd_device_t device)
4365{
4366 int i, be_dai_id;
4367 const char * hw_interface_name = NULL;
4368
4369 ALOGV("%s: enter with device %d\n", __func__, device);
4370
vivek mehtaa68fea62017-06-08 19:04:02 -07004371 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004372 ALOGE("%s: Invalid snd_device = %d",
4373 __func__, device);
4374 be_dai_id = -EINVAL;
4375 goto done;
4376 }
4377
4378 /* Get string value of necessary backend for device */
4379 hw_interface_name = hw_interface_table[device];
4380 if (hw_interface_name == NULL) {
4381 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4382 be_dai_id = -EINVAL;
4383 goto done;
4384 }
4385
4386 /* Check if be dai name table was retrieved successfully */
4387 if (be_dai_name_table == NULL) {
4388 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4389 be_dai_id = -EFAULT;
4390 goto done;
4391 }
4392
4393 /* Get backend ID for device specified */
4394 for (i = 0; i < max_be_dai_names; i++) {
4395 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4396 be_dai_id = be_dai_name_table[i].be_id;
4397 goto done;
4398 }
4399 }
4400 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4401 be_dai_id = -EINVAL;
4402 goto done;
4403
4404done:
4405 return be_dai_id;
4406}
4407
4408void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4409 unsigned int stream_sr, int* sample_rate)
4410{
4411 struct platform_data* my_data = (struct platform_data *)platform;
4412 int backend_idx = platform_get_backend_index(snd_device);
4413 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4414 /*
4415 *Check if device SR is multiple of 8K or 11.025 Khz
4416 *check if the stream SR is multiple of same base, if yes
4417 *then have copp SR equal to stream SR, this ensures that
4418 *post processing happens at stream SR, else have
4419 *copp SR equal to device SR.
4420 */
4421 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4422 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4423 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4424 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4425 *sample_rate = device_sr;
4426 } else
4427 *sample_rate = stream_sr;
4428
4429 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4430 , *sample_rate);
4431
4432}
4433
4434// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004435void platform_add_app_type(const char *uc_type,
4436 const char *mode,
4437 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004438 int app_type, int max_rate) {
4439 struct app_type_entry *ap =
4440 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4441
4442 if (!ap) {
4443 ALOGE("%s failed to allocate mem for app type", __func__);
4444 return;
4445 }
4446
4447 ap->uc_type = -1;
4448 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4449 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4450 ap->uc_type = usecase_type_index[i].index;
4451 break;
4452 }
4453 }
4454
4455 if (ap->uc_type == -1) {
4456 free(ap);
4457 return;
4458 }
4459
vivek mehtaa68fea62017-06-08 19:04:02 -07004460 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4461 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004462 ap->bit_width = bw;
4463 ap->app_type = app_type;
4464 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004465 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004466 list_add_tail(&app_type_entry_list, &ap->node);
4467}
4468
4469
4470int platform_get_default_app_type_v2(void *platform __unused,
4471 usecase_type_t type,
4472 int *app_type )
4473{
4474 if (type == PCM_PLAYBACK)
4475 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4476 else
4477 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4478 return 0;
4479}
4480
vivek mehtaa68fea62017-06-08 19:04:02 -07004481int platform_get_app_type_v2(void *platform,
4482 usecase_type_t uc_type,
4483 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004484 int bw, int sr __unused,
4485 int *app_type)
4486{
4487 struct listnode *node;
4488 struct app_type_entry *entry;
4489 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004490
4491 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4492 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004493 list_for_each(node, &app_type_entry_list) {
4494 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004495 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4496 __func__, entry->uc_type, entry->mode, entry->bit_width,
4497 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004498 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004499 entry->uc_type == uc_type &&
4500 sr <= entry->max_rate &&
4501 entry->mode && !strcmp(mode, entry->mode)) {
4502 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004503 *app_type = entry->app_type;
4504 break;
4505 }
4506 }
4507
4508 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004509 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004510 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4511 }
4512 return 0;
4513}
vivek mehta90933872017-06-15 18:04:39 -07004514
4515int platform_set_sidetone(struct audio_device *adev,
4516 snd_device_t out_snd_device,
4517 bool enable, char *str)
4518{
4519 int ret;
4520 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4521 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4522 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4523 if (ret)
4524 ALOGI("%s: usb device %d does not support device sidetone\n",
4525 __func__, out_snd_device);
4526 } else {
4527 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4528 __func__, out_snd_device, str);
4529 if (enable)
4530 audio_route_apply_and_update_path(adev->audio_route, str);
4531 else
4532 audio_route_reset_and_update_path(adev->audio_route, str);
4533 }
4534 return 0;
4535}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004536
4537int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4538 int *fd __unused, uint32_t *size __unused)
4539{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004540#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004541 struct platform_data *my_data = (struct platform_data *)platform;
4542 struct audio_device *adev = my_data->adev;
4543 int hw_fd = -1;
4544 char dev_name[128];
4545 struct snd_pcm_mmap_fd mmap_fd;
4546 memset(&mmap_fd, 0, sizeof(mmap_fd));
4547 mmap_fd.dir = dir;
4548 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4549 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4550 hw_fd = open(dev_name, O_RDONLY);
4551 if (hw_fd < 0) {
4552 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4553 return -1;
4554 }
4555 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4556 ALOGE("fe hw dep node ioctl failed");
4557 close(hw_fd);
4558 return -1;
4559 }
4560 *fd = mmap_fd.fd;
4561 *size = mmap_fd.size;
4562 close(hw_fd); // mmap_fd should still be valid
4563 return 0;
4564#else
4565 return -1;
4566#endif
4567}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004568
4569bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4570{
4571 bool needs_event = false;
4572
4573 switch (uc_id) {
4574 /* concurrent capture usecases which needs event */
4575 case USECASE_AUDIO_RECORD:
4576 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4577 case USECASE_AUDIO_RECORD_MMAP:
4578 case USECASE_AUDIO_RECORD_HIFI:
4579 case USECASE_AUDIO_RECORD_VOIP:
4580 case USECASE_VOICEMMODE1_CALL:
4581 case USECASE_VOICEMMODE2_CALL:
4582 /* concurrent playback usecases that needs event */
4583 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4584 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4585 needs_event = true;
4586 break;
4587 default:
4588 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4589 }
4590 return needs_event;
4591}
4592
4593bool platform_snd_device_has_speaker(snd_device_t dev) {
4594 int num_devs = 2;
4595 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4596 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4597 return platform_snd_device_has_speaker(split_devs[0]) ||
4598 platform_snd_device_has_speaker(split_devs[1]);
4599 }
4600
4601 switch (dev) {
4602 case SND_DEVICE_OUT_SPEAKER:
4603 case SND_DEVICE_OUT_SPEAKER_SAFE:
4604 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4605 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4606 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4607 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4608 return true;
4609 default:
4610 break;
4611 }
4612 return false;
4613}
jiabin8962a4d2018-03-19 18:21:24 -07004614
4615bool platform_set_microphone_characteristic(void *platform,
4616 struct audio_microphone_characteristic_t mic) {
4617 struct platform_data *my_data = (struct platform_data *)platform;
4618 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4619 ALOGE("mic number is more than maximum number");
4620 return false;
4621 }
4622 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4623 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4624 }
4625 my_data->microphones[my_data->declared_mic_count++] = mic;
4626 return true;
4627}
4628
4629int platform_get_microphones(void *platform,
4630 struct audio_microphone_characteristic_t *mic_array,
4631 size_t *mic_count) {
4632 struct platform_data *my_data = (struct platform_data *)platform;
4633 if (mic_count == NULL) {
4634 return -EINVAL;
4635 }
4636 if (mic_array == NULL) {
4637 return -EINVAL;
4638 }
4639
4640 if (*mic_count == 0) {
4641 *mic_count = my_data->declared_mic_count;
4642 return 0;
4643 }
4644
4645 size_t max_mic_count = *mic_count;
4646 size_t actual_mic_count = 0;
4647 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4648 mic_array[i] = my_data->microphones[i];
4649 actual_mic_count++;
4650 }
4651 *mic_count = actual_mic_count;
4652 return 0;
4653}
4654
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004655bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4656 const struct mic_info *info) {
4657 struct platform_data *my_data = (struct platform_data *)platform;
4658 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4659 ALOGE("%s: Sound device not valid", __func__);
4660 return false;
4661 }
4662 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4663 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4664 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4665 my_data->mic_map[in_snd_device].mic_count--;
4666 return false;
4667 }
4668 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4669 return true;
4670}
4671
4672int platform_get_active_microphones(void *platform, unsigned int channels,
4673 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004674 struct audio_microphone_characteristic_t *mic_array,
4675 size_t *mic_count) {
4676 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004677 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4678 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004679 return -EINVAL;
4680 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004681 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004682 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004683
4684 snd_device_t active_input_snd_device =
4685 platform_get_input_snd_device(platform, usecase->stream.in->device);
4686 if (active_input_snd_device == SND_DEVICE_NONE) {
4687 ALOGI("%s: No active microphones found", __func__);
4688 goto end;
4689 }
4690
4691 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4692 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4693
4694 for (size_t i = 0; i < active_mic_count; i++) {
4695 unsigned int channels_for_active_mic = channels;
4696 if (channels_for_active_mic > m_info[i].channel_count) {
4697 channels_for_active_mic = m_info[i].channel_count;
4698 }
4699 for (size_t j = 0; j < max_mic_count; j++) {
4700 if (strcmp(my_data->microphones[j].device_id,
4701 m_info[i].device_id) == 0) {
4702 mic_array[actual_mic_count] = my_data->microphones[j];
4703 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4704 mic_array[actual_mic_count].channel_mapping[ch] =
4705 m_info[i].channel_mapping[ch];
4706 }
4707 actual_mic_count++;
4708 break;
jiabin8962a4d2018-03-19 18:21:24 -07004709 }
jiabin8962a4d2018-03-19 18:21:24 -07004710 }
4711 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004712end:
jiabin8962a4d2018-03-19 18:21:24 -07004713 *mic_count = actual_mic_count;
4714 return 0;
4715}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004716
4717int platform_set_usb_service_interval(void *platform,
4718 bool playback,
4719 unsigned long service_interval,
4720 bool *reconfig)
4721{
4722#if defined (USB_SERVICE_INTERVAL_ENABLED)
4723 struct platform_data *_platform = (struct platform_data *)platform;
4724 *reconfig = false;
4725 if (!playback) {
4726 ALOGE("%s not valid for capture", __func__);
4727 return -1;
4728 }
4729 const char *ctl_name = "USB_AUDIO_RX service_interval";
4730 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4731 ctl_name);
4732 if (!ctl) {
4733 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4734 return -1;
4735 }
4736 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4737 mixer_ctl_set_value(ctl, 0, service_interval);
4738 *reconfig = true;
4739 }
4740 return 0;
4741#else
4742 *reconfig = false;
4743 (void)platform;
4744 (void)playback;
4745 (void)service_interval;
4746 return -1;
4747#endif
4748}
4749
4750int platform_get_usb_service_interval(void *platform,
4751 bool playback,
4752 unsigned long *service_interval)
4753{
4754#if defined (USB_SERVICE_INTERVAL_ENABLED)
4755 struct platform_data *_platform = (struct platform_data *)platform;
4756 if (!playback) {
4757 ALOGE("%s not valid for capture", __func__);
4758 return -1;
4759 }
4760 const char *ctl_name = "USB_AUDIO_RX service_interval";
4761 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4762 ctl_name);
4763 if (!ctl) {
4764 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4765 return -1;
4766 }
4767 *service_interval = mixer_ctl_get_value(ctl, 0);
4768 return 0;
4769#else
4770 (void)platform;
4771 (void)playback;
4772 (void)service_interval;
4773 return -1;
4774#endif
4775}
Ashish Jain1c849702018-05-11 20:11:55 +05304776
4777int platform_set_acdb_metainfo_key(void *platform __unused,
4778 char *name __unused,
4779 int key __unused)
4780{
4781 return -ENOSYS;
4782}