blob: 429291cfb6d310b48428940757da77d11d1c5e89 [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
vivek mehtade4849c2016-03-03 17:23:38 -08001837 hw_info_deinit(my_data->hw_info);
1838
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001839 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1840 if (backend_tag_table[dev])
1841 free(backend_tag_table[dev]);
1842 if (hw_interface_table[dev])
1843 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001844 if (operator_specific_device_table[dev]) {
1845 while (!list_empty(operator_specific_device_table[dev])) {
1846 node = list_head(operator_specific_device_table[dev]);
1847 list_remove(node);
1848 device_item = node_to_item(node, struct operator_specific_device, list);
1849 free(device_item->operator);
1850 free(device_item->mixer_path);
1851 free(device_item);
1852 }
1853 free(operator_specific_device_table[dev]);
1854 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001855 }
1856
1857 if (my_data->snd_card_name)
1858 free(my_data->snd_card_name);
1859
keunhui.park2f7306a2015-07-16 16:48:06 +09001860 while (!list_empty(&operator_info_list)) {
1861 node = list_head(&operator_info_list);
1862 list_remove(node);
1863 info_item = node_to_item(node, struct operator_info, list);
1864 free(info_item->name);
1865 free(info_item->mccmnc);
1866 free(info_item);
1867 }
1868
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001869 while (!list_empty(&app_type_entry_list)) {
1870 node = list_head(&app_type_entry_list);
1871 list_remove(node);
1872 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001873 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001874 free(ap);
1875 }
1876
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001877 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001878 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001879
1880 /* deinit usb */
1881 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001882}
1883
1884const char *platform_get_snd_device_name(snd_device_t snd_device)
1885{
keunhui.park2f7306a2015-07-16 16:48:06 +09001886 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1887 if (operator_specific_device_table[snd_device] != NULL) {
1888 return get_operator_specific_device_mixer_path(snd_device);
1889 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001890 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001891 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001892 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001893}
1894
vivek mehtade4849c2016-03-03 17:23:38 -08001895int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1896 char *device_name)
1897{
1898 struct platform_data *my_data = (struct platform_data *)platform;
1899
David Benjamin1565f992016-09-21 12:10:34 -04001900 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001901 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001902 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1903 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001904 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1905 if (operator_specific_device_table[snd_device] != NULL) {
1906 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1907 DEVICE_NAME_MAX_SIZE);
1908 } else {
1909 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1910 }
1911 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1912 } else {
1913 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
Aniket Kumar Lataa158e862018-05-11 17:28:40 -07001914 return -EINVAL;
vivek mehtade4849c2016-03-03 17:23:38 -08001915 }
1916
1917 return 0;
1918}
1919
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001920void platform_add_backend_name(void *platform, char *mixer_path,
1921 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001922{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001923 struct platform_data *my_data = (struct platform_data *)platform;
1924
Haynes Mathew George98c95622014-06-20 19:14:25 -07001925 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1926 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1927 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001928 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001929
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001930 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001931
1932 if (suffix != NULL) {
1933 strcat(mixer_path, " ");
1934 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001935 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001936}
1937
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001938bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1939{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001940 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1941 platform_get_snd_device_name(snd_device1),
1942 platform_get_snd_device_name(snd_device2));
1943
1944 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1945 ALOGE("%s: Invalid snd_device = %s", __func__,
1946 platform_get_snd_device_name(snd_device1));
1947 return false;
1948 }
1949 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1950 ALOGE("%s: Invalid snd_device = %s", __func__,
1951 platform_get_snd_device_name(snd_device2));
1952 return false;
1953 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001954
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001955 const char * be_itf1 = hw_interface_table[snd_device1];
1956 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001957 /*
1958 hw_interface_table has overrides for a snd_device.
1959 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1960 */
1961 if (be_itf1 == NULL) {
1962 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001963 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001964 if (be_itf2 == NULL) {
1965 be_itf2 = DEFAULT_RX_BACKEND;
1966 }
1967 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1968 /*
1969 this takes care of finding a device within a combo device pair as well
1970 */
1971 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001972}
1973
Eric Laurentb23d5282013-05-14 15:27:20 -07001974int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1975{
1976 int device_id;
1977 if (device_type == PCM_PLAYBACK)
1978 device_id = pcm_device_table[usecase][0];
1979 else
1980 device_id = pcm_device_table[usecase][1];
1981 return device_id;
1982}
1983
Haynes Mathew George98c95622014-06-20 19:14:25 -07001984static int find_index(const struct name_to_index * table, int32_t len,
1985 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001986{
1987 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001988 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001989
Haynes Mathew George98c95622014-06-20 19:14:25 -07001990 if (table == NULL) {
1991 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001992 ret = -ENODEV;
1993 goto done;
1994 }
1995
Haynes Mathew George98c95622014-06-20 19:14:25 -07001996 if (name == NULL) {
1997 ALOGE("null key");
1998 ret = -ENODEV;
1999 goto done;
2000 }
2001
2002 for (i=0; i < len; i++) {
2003 if (!strcmp(table[i].name, name)) {
2004 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002005 goto done;
2006 }
2007 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002008 ALOGE("%s: Could not find index for name = %s",
2009 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002010 ret = -ENODEV;
2011done:
2012 return ret;
2013}
2014
Haynes Mathew George98c95622014-06-20 19:14:25 -07002015int platform_get_snd_device_index(char *device_name)
2016{
2017 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2018}
2019
2020int platform_get_usecase_index(const char *usecase_name)
2021{
2022 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2023}
2024
keunhui.park2f7306a2015-07-16 16:48:06 +09002025void platform_add_operator_specific_device(snd_device_t snd_device,
2026 const char *operator,
2027 const char *mixer_path,
2028 unsigned int acdb_id)
2029{
2030 struct operator_specific_device *device;
2031
2032 if (operator_specific_device_table[snd_device] == NULL) {
2033 operator_specific_device_table[snd_device] =
2034 (struct listnode *)calloc(1, sizeof(struct listnode));
2035 list_init(operator_specific_device_table[snd_device]);
2036 }
2037
2038 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2039
2040 device->operator = strdup(operator);
2041 device->mixer_path = strdup(mixer_path);
2042 device->acdb_id = acdb_id;
2043
2044 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2045
Eric Laurent2bafff12016-03-17 12:17:23 -07002046 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002047 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2048
2049}
2050
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002051int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2052{
2053 int ret = 0;
2054
2055 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2056 ALOGE("%s: Invalid snd_device = %d",
2057 __func__, snd_device);
2058 ret = -EINVAL;
2059 goto done;
2060 }
2061
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002062 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2063 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002064 acdb_device_table[snd_device] = acdb_id;
2065done:
2066 return ret;
2067}
2068
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002069int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2070{
2071 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2072 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2073 return -EINVAL;
2074 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002075
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002076 /*
2077 * If speaker protection is enabled, function returns supported
2078 * sound device for speaker. Else same sound device is returned.
2079 */
2080 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2081
keunhui.park2f7306a2015-07-16 16:48:06 +09002082 if (operator_specific_device_table[snd_device] != NULL)
2083 return get_operator_specific_device_acdb_id(snd_device);
2084 else
2085 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002086}
2087
David Linee3fe402017-03-13 10:00:42 -07002088static int platform_get_backend_index(snd_device_t snd_device)
2089{
2090 int32_t port = DEFAULT_CODEC_BACKEND;
2091
2092 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2093 if (backend_tag_table[snd_device] != NULL) {
2094 if (strncmp(backend_tag_table[snd_device], "headphones",
2095 sizeof("headphones")) == 0)
2096 port = HEADPHONE_BACKEND;
2097 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2098 port = HDMI_RX_BACKEND;
2099 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2100 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2101 port = USB_AUDIO_RX_BACKEND;
2102 }
2103 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2104 port = DEFAULT_CODEC_TX_BACKEND;
2105 if (backend_tag_table[snd_device] != NULL) {
2106 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2107 port = USB_AUDIO_TX_BACKEND;
2108 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2109 port = BT_SCO_TX_BACKEND;
2110 }
2111 } else {
2112 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2113 }
2114
2115 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2116
2117 return port;
2118}
2119
Eric Laurentb23d5282013-05-14 15:27:20 -07002120int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2121{
2122 struct platform_data *my_data = (struct platform_data *)platform;
2123 int acdb_dev_id, acdb_dev_type;
2124
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002125 if (platform_supports_app_type_cfg()) // use v2 instead
2126 return -ENOSYS;
2127
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002128 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002129 if (acdb_dev_id < 0) {
2130 ALOGE("%s: Could not find acdb id for device(%d)",
2131 __func__, snd_device);
2132 return -EINVAL;
2133 }
2134 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002135 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002136 __func__, snd_device, acdb_dev_id);
2137 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2138 snd_device < SND_DEVICE_OUT_END)
2139 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2140 else
2141 acdb_dev_type = ACDB_DEV_TYPE_IN;
2142 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2143 }
2144 return 0;
2145}
2146
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002147int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2148 int app_type, int sample_rate)
2149{
2150 struct platform_data *my_data = (struct platform_data *)platform;
2151 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002152 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002153 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2154 int i, num_devices = 1;
2155
2156 if (!platform_supports_app_type_cfg()) // use v1 instead
2157 return -ENOSYS;
2158
vivek mehta7e573672018-03-13 17:41:41 -07002159 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002160 snd_device = usecase->in_snd_device;
2161
2162 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002163 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002164 if (acdb_dev_id < 0) {
2165 ALOGE("%s: Could not find acdb id for device(%d)",
2166 __func__, snd_device);
2167 return -EINVAL;
2168 }
2169
2170 if (platform_can_split_snd_device(snd_device,
2171 &num_devices, new_snd_device) < 0) {
2172 new_snd_device[0] = snd_device;
2173 }
2174
2175 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002176 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002177 if (acdb_dev_id < 0) {
2178 ALOGE("%s: Could not find acdb id for device(%d)",
2179 __func__, new_snd_device[i]);
2180 return -EINVAL;
2181 }
2182 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2183 __func__, new_snd_device[i], acdb_dev_id);
2184 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2185 new_snd_device[i] < SND_DEVICE_OUT_END)
2186 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2187 else
2188 acdb_dev_type = ACDB_DEV_TYPE_IN;
2189
2190 if (my_data->acdb_send_audio_cal_v3) {
2191 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2192 app_type, sample_rate, i);
2193 } else if (my_data->acdb_send_audio_cal) {
2194 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2195 }
2196 }
2197
2198 return 0;
2199}
2200
2201
Eric Laurentb23d5282013-05-14 15:27:20 -07002202int platform_switch_voice_call_device_pre(void *platform)
2203{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002204 struct platform_data *my_data = (struct platform_data *)platform;
2205 int ret = 0;
2206
2207 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002208 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002209 /* This must be called before disabling mixer controls on APQ side */
2210 ret = my_data->csd->disable_device();
2211 if (ret < 0) {
2212 ALOGE("%s: csd_client_disable_device, failed, error %d",
2213 __func__, ret);
2214 }
2215 }
2216 return ret;
2217}
2218
2219int platform_switch_voice_call_enable_device_config(void *platform,
2220 snd_device_t out_snd_device,
2221 snd_device_t in_snd_device)
2222{
2223 struct platform_data *my_data = (struct platform_data *)platform;
2224 int acdb_rx_id, acdb_tx_id;
2225 int ret = 0;
2226
2227 if (my_data->csd == NULL)
2228 return ret;
2229
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002230 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002231 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002232
2233 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2234 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2235 if (ret < 0) {
2236 ALOGE("%s: csd_enable_device_config, failed, error %d",
2237 __func__, ret);
2238 }
2239 } else {
2240 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2241 acdb_rx_id, acdb_tx_id);
2242 }
2243
2244 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002245}
2246
2247int platform_switch_voice_call_device_post(void *platform,
2248 snd_device_t out_snd_device,
2249 snd_device_t in_snd_device)
2250{
2251 struct platform_data *my_data = (struct platform_data *)platform;
2252 int acdb_rx_id, acdb_tx_id;
2253
2254 if (my_data->acdb_send_voice_cal == NULL) {
2255 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2256 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002257 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2258 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002259
2260 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2261 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2262 else
2263 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2264 acdb_rx_id, acdb_tx_id);
2265 }
2266
2267 return 0;
2268}
2269
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002270int platform_switch_voice_call_usecase_route_post(void *platform,
2271 snd_device_t out_snd_device,
2272 snd_device_t in_snd_device)
2273{
2274 struct platform_data *my_data = (struct platform_data *)platform;
2275 int acdb_rx_id, acdb_tx_id;
2276 int ret = 0;
2277
2278 if (my_data->csd == NULL)
2279 return ret;
2280
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002281 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002282 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002283
2284 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2285 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2286 my_data->adev->acdb_settings);
2287 if (ret < 0) {
2288 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2289 }
2290 } else {
2291 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2292 acdb_rx_id, acdb_tx_id);
2293 }
2294
2295 return ret;
2296}
2297
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002298int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002299{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002300 struct platform_data *my_data = (struct platform_data *)platform;
2301 int ret = 0;
2302
2303 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002304 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002305 if (ret < 0) {
2306 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2307 }
2308 }
2309 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002310}
2311
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002312int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002313{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002314 struct platform_data *my_data = (struct platform_data *)platform;
2315 int ret = 0;
2316
2317 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002318 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002319 if (ret < 0) {
2320 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2321 }
2322 }
2323 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002324}
2325
Vignesh Kulothunganb6f0a9c2018-03-22 13:50:22 -07002326int platform_set_mic_break_det(void *platform, bool enable)
2327{
2328 int ret = 0;
2329 struct platform_data *my_data = (struct platform_data *)platform;
2330 struct audio_device *adev = my_data->adev;
2331 const char *mixer_ctl_name = "Voice Mic Break Enable";
2332 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2333 if (!ctl) {
2334 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2335 __func__, mixer_ctl_name);
2336 return -EINVAL;
2337 }
2338
2339 ret = mixer_ctl_set_value(ctl, 0, enable);
2340 if(ret)
2341 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
2342
2343 return ret;
2344}
2345
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002346int platform_get_sample_rate(void *platform, uint32_t *rate)
2347{
2348 struct platform_data *my_data = (struct platform_data *)platform;
2349 int ret = 0;
2350
2351 if (my_data->csd != NULL) {
2352 ret = my_data->csd->get_sample_rate(rate);
2353 if (ret < 0) {
2354 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2355 }
2356 }
2357 return ret;
2358}
2359
vivek mehtab6506412015-08-07 16:55:17 -07002360void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2361 snd_device_t snd_device,
2362 bool enable)
2363{
2364 const char* name;
2365 switch (snd_device) {
2366 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2367 if (enable)
2368 name = "spkr-gain-in-headphone-combo";
2369 else
2370 name = "speaker-gain-default";
2371 break;
2372 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2373 if (enable)
2374 name = "spkr-gain-in-line-combo";
2375 else
2376 name = "speaker-gain-default";
2377 break;
2378 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2379 if (enable)
2380 name = "spkr-safe-gain-in-headphone-combo";
2381 else
2382 name = "speaker-safe-gain-default";
2383 break;
2384 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2385 if (enable)
2386 name = "spkr-safe-gain-in-line-combo";
2387 else
2388 name = "speaker-safe-gain-default";
2389 break;
2390 default:
2391 return;
2392 }
2393
2394 audio_route_apply_and_update_path(adev->audio_route, name);
2395}
2396
Eric Laurentb23d5282013-05-14 15:27:20 -07002397int platform_set_voice_volume(void *platform, int volume)
2398{
2399 struct platform_data *my_data = (struct platform_data *)platform;
2400 struct audio_device *adev = my_data->adev;
2401 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002402 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002403 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002404 int vol_index = 0, ret = 0;
2405 uint32_t set_values[ ] = {0,
2406 ALL_SESSION_VSID,
2407 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002408
2409 // Voice volume levels are mapped to adsp volume levels as follows.
2410 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2411 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002412 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002413 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002414
2415 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2416 if (!ctl) {
2417 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2418 __func__, mixer_ctl_name);
2419 return -EINVAL;
2420 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002421 ALOGV("Setting voice volume index: %d", set_values[0]);
2422 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2423
Nadav Barc46d0fa2017-12-24 14:50:37 +02002424 // Send mute command in case volume index is max since indexes are inverted
2425 // for mixer controls.
2426 if (vol_index == my_data->max_vol_index) {
2427 set_values[0] = 1;
2428 }
2429 else {
2430 set_values[0] = 0;
2431 }
2432
2433 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2434 if (!ctl) {
2435 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2436 __func__, mute_mixer_ctl_name);
2437 return -EINVAL;
2438 }
2439 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2440 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2441
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002442 if (my_data->csd != NULL) {
2443 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2444 DEFAULT_VOLUME_RAMP_DURATION_MS);
2445 if (ret < 0) {
2446 ALOGE("%s: csd_volume error %d", __func__, ret);
2447 }
2448 }
2449 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002450}
2451
2452int platform_set_mic_mute(void *platform, bool state)
2453{
2454 struct platform_data *my_data = (struct platform_data *)platform;
2455 struct audio_device *adev = my_data->adev;
2456 struct mixer_ctl *ctl;
2457 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002458 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002459 uint32_t set_values[ ] = {0,
2460 ALL_SESSION_VSID,
2461 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002462
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002463 if (adev->mode != AUDIO_MODE_IN_CALL &&
2464 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002465 return 0;
2466
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002467 if (adev->enable_hfp)
2468 mixer_ctl_name = "HFP Tx Mute";
2469
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002470 set_values[0] = state;
2471 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2472 if (!ctl) {
2473 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2474 __func__, mixer_ctl_name);
2475 return -EINVAL;
2476 }
2477 ALOGV("Setting voice mute state: %d", state);
2478 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2479
2480 if (my_data->csd != NULL) {
2481 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2482 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002483 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002484 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002485 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002486 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002487 return ret;
2488}
Eric Laurentb23d5282013-05-14 15:27:20 -07002489
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002490int platform_set_device_mute(void *platform, bool state, char *dir)
2491{
2492 struct platform_data *my_data = (struct platform_data *)platform;
2493 struct audio_device *adev = my_data->adev;
2494 struct mixer_ctl *ctl;
2495 char *mixer_ctl_name = NULL;
2496 int ret = 0;
2497 uint32_t set_values[ ] = {0,
2498 ALL_SESSION_VSID,
2499 0};
2500 if(dir == NULL) {
2501 ALOGE("%s: Invalid direction:%s", __func__, dir);
2502 return -EINVAL;
2503 }
2504
2505 if (!strncmp("rx", dir, sizeof("rx"))) {
2506 mixer_ctl_name = "Voice Rx Device Mute";
2507 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2508 mixer_ctl_name = "Voice Tx Device Mute";
2509 } else {
2510 return -EINVAL;
2511 }
2512
2513 set_values[0] = state;
2514 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2515 if (!ctl) {
2516 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2517 __func__, mixer_ctl_name);
2518 return -EINVAL;
2519 }
2520
2521 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2522 __func__,state, mixer_ctl_name);
2523 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2524
2525 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002526}
2527
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002528int platform_can_split_snd_device(snd_device_t snd_device,
2529 int *num_devices,
2530 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002531{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002532 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002533 if (NULL == num_devices || NULL == new_snd_devices) {
2534 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002535 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002536 }
2537
2538 /*
2539 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002540 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002541 */
2542 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2543 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2544 *num_devices = 2;
2545 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2546 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002547 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002548 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2549 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2550 *num_devices = 2;
2551 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2552 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002553 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002554 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2555 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2556 *num_devices = 2;
2557 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2558 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002559 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002560 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2561 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2562 *num_devices = 2;
2563 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2564 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002565 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002566 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2567 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2568 SND_DEVICE_OUT_BT_SCO)) {
2569 *num_devices = 2;
2570 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2571 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2572 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002573 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2574 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2575 SND_DEVICE_OUT_BT_SCO)) {
2576 *num_devices = 2;
2577 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2578 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2579 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002580 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2581 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2582 SND_DEVICE_OUT_BT_SCO_WB)) {
2583 *num_devices = 2;
2584 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2585 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2586 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002587 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2588 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2589 SND_DEVICE_OUT_BT_SCO_WB)) {
2590 *num_devices = 2;
2591 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2592 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2593 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002594 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2595 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2596 *num_devices = 2;
2597 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2598 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2599 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002600 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2601 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2602 *num_devices = 2;
2603 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2604 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2605 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002606 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2607 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2608 SND_DEVICE_OUT_BT_A2DP)) {
2609 *num_devices = 2;
2610 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2611 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2612 ret = 0;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002613 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
2614 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2615 SND_DEVICE_OUT_BT_A2DP)) {
2616 *num_devices = 2;
2617 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2618 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2619 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002620 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002621
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002622 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002623}
2624
Eric Laurentb23d5282013-05-14 15:27:20 -07002625snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2626{
2627 struct platform_data *my_data = (struct platform_data *)platform;
2628 struct audio_device *adev = my_data->adev;
2629 audio_mode_t mode = adev->mode;
2630 snd_device_t snd_device = SND_DEVICE_NONE;
2631
2632 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2633 if (devices == AUDIO_DEVICE_NONE ||
2634 devices & AUDIO_DEVICE_BIT_IN) {
2635 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2636 goto exit;
2637 }
2638
Eric Laurent1b491552015-09-15 17:52:41 -07002639 if (popcount(devices) == 2) {
2640 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2641 AUDIO_DEVICE_OUT_SPEAKER) ||
2642 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2643 AUDIO_DEVICE_OUT_SPEAKER)) {
2644 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2645 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2646 AUDIO_DEVICE_OUT_SPEAKER)) {
2647 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2648 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2649 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2650 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2651 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2652 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2653 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2654 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2655 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2656 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2657 AUDIO_DEVICE_OUT_SPEAKER)) {
2658 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002659 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2660 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2661 snd_device = adev->bt_wb_speech_enabled ?
2662 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2663 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002664 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2665 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2666 snd_device = adev->bt_wb_speech_enabled ?
2667 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2668 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002669 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2670 AUDIO_DEVICE_OUT_SPEAKER)) ||
2671 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2672 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002673 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002674 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2675 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2676 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2677 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002678 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002679 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2680 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2681 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aniket Kumar Lata9723a962018-05-16 17:41:55 -07002682 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
2683 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2684 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002685 } else {
2686 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2687 goto exit;
2688 }
2689 if (snd_device != SND_DEVICE_NONE) {
2690 goto exit;
2691 }
2692 }
2693
2694 if (popcount(devices) != 1) {
2695 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2696 goto exit;
2697 }
2698
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302699 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002700 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002701 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2702 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002703 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002704 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002705 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002706 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002707 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002708 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002709 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002710 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002711 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002712 else {
2713 if (devices & AUDIO_DEVICE_OUT_LINE)
2714 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2715 else
2716 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2717 }
Eric Laurent99dab492017-06-17 15:19:08 -07002718 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002719 if (voice_is_in_call(adev)) {
2720 switch (adev->voice.tty_mode) {
2721 case TTY_MODE_FULL:
2722 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2723 break;
2724 case TTY_MODE_VCO:
2725 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2726 break;
2727 case TTY_MODE_HCO:
2728 // since Hearing will be on handset\speaker, use existing device
2729 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2730 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002731 case TTY_MODE_OFF:
2732 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002733 default:
2734 ALOGE("%s: Invalid TTY mode (%#x)",
2735 __func__, adev->voice.tty_mode);
2736 }
2737 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002738 if (snd_device == SND_DEVICE_NONE) {
2739 snd_device = audio_extn_usb_is_capture_supported() ?
2740 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2741 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2742 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002743 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002744 if (adev->bt_wb_speech_enabled) {
2745 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2746 } else {
2747 snd_device = SND_DEVICE_OUT_BT_SCO;
2748 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002749 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2750 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002751 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002752 if (!adev->enable_hfp) {
2753 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2754 } else {
2755 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2756 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002757 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002758 if(adev->voice.hac)
2759 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2760 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002761 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2762 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002763 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002764 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2765 snd_device = SND_DEVICE_OUT_VOICE_TX;
2766
Eric Laurentb23d5282013-05-14 15:27:20 -07002767 if (snd_device != SND_DEVICE_NONE) {
2768 goto exit;
2769 }
2770 }
2771
Eric Laurentb23d5282013-05-14 15:27:20 -07002772 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2773 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2774 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002775 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2776 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002777 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2778 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002779 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002780 /*
2781 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2782 * Or there will be a small pause while performing device switch.
2783 */
2784 if (my_data->speaker_lr_swap &&
2785 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2786 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002787 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2788 else
2789 snd_device = SND_DEVICE_OUT_SPEAKER;
2790 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002791 if (adev->bt_wb_speech_enabled) {
2792 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2793 } else {
2794 snd_device = SND_DEVICE_OUT_BT_SCO;
2795 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002796 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2797 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002798 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2799 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002800 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002801 if (audio_extn_ma_supported_usb())
2802 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2803 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002804 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2805 else
2806 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2807 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002808 /*HAC support for voice-ish audio (eg visual voicemail)*/
2809 if(adev->voice.hac)
2810 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2811 else
2812 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002813 } else {
2814 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2815 }
2816exit:
2817 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2818 return snd_device;
2819}
2820
2821snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2822{
2823 struct platform_data *my_data = (struct platform_data *)platform;
2824 struct audio_device *adev = my_data->adev;
2825 audio_source_t source = (adev->active_input == NULL) ?
2826 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2827
2828 audio_mode_t mode = adev->mode;
2829 audio_devices_t in_device = ((adev->active_input == NULL) ?
2830 AUDIO_DEVICE_NONE : adev->active_input->device)
2831 & ~AUDIO_DEVICE_BIT_IN;
2832 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2833 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2834 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002835 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002836
Prashant Malanic92c5962015-08-11 15:10:18 -07002837 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2838 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002839 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2840 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002841 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002842 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002843 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2844 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002845 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002846 case TTY_MODE_FULL:
2847 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2848 break;
2849 case TTY_MODE_VCO:
2850 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2851 break;
2852 case TTY_MODE_HCO:
2853 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2854 break;
2855 default:
2856 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2857 }
2858 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002859 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002860 switch (adev->voice.tty_mode) {
2861 case TTY_MODE_FULL:
2862 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2863 break;
2864 case TTY_MODE_VCO:
2865 // since voice will be captured from handset mic, use existing device
2866 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2867 break;
2868 case TTY_MODE_HCO:
2869 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2870 break;
2871 default:
2872 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002873 }
2874 goto exit;
2875 }
2876 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002877 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002878 if (my_data->fluence_in_voice_call == false) {
2879 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2880 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002881 if (is_operator_tmus())
2882 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002883 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002884 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002885 }
2886 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2887 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2888 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002889 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002890 if (adev->bluetooth_nrec)
2891 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2892 else
2893 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002894 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002895 if (adev->bluetooth_nrec)
2896 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2897 else
2898 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002899 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002900 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002901 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2902 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2903 out_device & AUDIO_DEVICE_OUT_LINE) {
2904 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2905 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2906 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2907 } else {
2908 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2909 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002910 }
vivek mehtafe121d52015-08-10 23:39:23 -07002911
2912 //select default
2913 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002914 if (!adev->enable_hfp) {
2915 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2916 } else {
2917 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2918 platform_set_echo_reference(adev, true, out_device);
2919 }
vivek mehtafe121d52015-08-10 23:39:23 -07002920 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002921 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002922 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002923 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002924 if (audio_extn_usb_is_capture_supported()) {
2925 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2926 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2927 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2928 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2929 } else {
2930 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2931 }
2932 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002933 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002934 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2935 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2936 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2937 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2938 }
2939 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2940 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002941 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2942 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2943 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002944 if (adev->active_input->enable_aec)
2945 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2946 else
2947 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002948 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2949 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002950 if (adev->active_input->enable_aec)
2951 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2952 else
2953 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002954 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2955 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2956 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002957 if (adev->active_input->enable_aec)
2958 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2959 else
2960 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002961 }
2962 platform_set_echo_reference(adev, true, out_device);
2963 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2964 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2965 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002966 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002967 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2968 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002969 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002970 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2971 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002972 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002973 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002974 if (adev->active_input->enable_aec) {
2975 if (adev->active_input->enable_ns) {
2976 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2977 } else {
2978 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2979 }
vivek mehta733c1df2016-04-04 15:09:24 -07002980 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002981 } else if (adev->active_input->enable_ns) {
2982 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2983 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002984 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002985 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002986 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002987 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2988 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002989 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002990 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002991 }
rago90fb9612015-12-02 11:37:53 -08002992 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2993 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002994 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2995 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2996 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2997 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002998 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002999 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3000 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003001 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07003002 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3003 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3004 } else {
3005 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3006 }
rago90fb9612015-12-02 11:37:53 -08003007 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3008 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003009 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003010 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08003011 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07003012 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08003013 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07003014 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
3015 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3016 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
3017 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003018 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07003019 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003020 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003021 if (adev->active_input->enable_aec &&
3022 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07003023 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003024 if (my_data->fluence_in_spkr_mode &&
3025 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003026 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003027 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003028 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003029 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003030 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003031 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003032 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003033 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003034 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003035 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003036 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003037 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003038 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3039 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003040 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003041 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003042 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003043 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003044 } else if (adev->active_input->enable_aec) {
3045 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3046 if (my_data->fluence_in_spkr_mode &&
3047 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003048 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003049 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003050 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003051 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003052 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003053 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3054 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003055 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003056 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003057 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003058 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003059 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003060 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3061 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003062 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003063 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05003064 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08003065 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003066 } else if (adev->active_input->enable_ns) {
3067 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3068 if (my_data->fluence_in_spkr_mode &&
3069 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003070 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003071 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003072 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003073 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003074 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003075 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3076 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003077 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003078 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003079 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003080 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003081 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003082 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003083 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003084 }
3085 } else if (source == AUDIO_SOURCE_DEFAULT) {
3086 goto exit;
3087 }
3088
3089
3090 if (snd_device != SND_DEVICE_NONE) {
3091 goto exit;
3092 }
3093
3094 if (in_device != AUDIO_DEVICE_NONE &&
3095 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3096 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3097 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003098 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003099 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003100 snd_device = SND_DEVICE_IN_QUAD_MIC;
3101 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003102 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003103 snd_device = SND_DEVICE_IN_THREE_MIC;
3104 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3105 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003106 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003107 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3108 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003109 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003110 } else {
3111 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3112 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3113 my_data->source_mic_type, channel_count, channel_mask);
3114 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3115 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003116 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003117 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3118 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003119 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003120 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3121 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003122 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003123 } else {
3124 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3125 " no combination found .. setting to mono", __func__,
3126 my_data->source_mic_type, channel_count);
3127 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3128 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003129 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3130 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3131 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003132 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003133 if (adev->bluetooth_nrec)
3134 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3135 else
3136 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003137 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003138 if (adev->bluetooth_nrec)
3139 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3140 else
3141 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003142 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003143 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3144 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003145 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003146 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003147 } else {
3148 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3149 ALOGW("%s: Using default handset-mic", __func__);
3150 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3151 }
3152 } else {
3153 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3154 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3155 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3156 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003157 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003158 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003159 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003160 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003161 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3162 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003163 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003164 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3165 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003166 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003167 } else {
3168 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3169 " no combination found .. setting to mono", __func__,
3170 my_data->source_mic_type, channel_count);
3171 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3172 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003173 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003174 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003175 if (adev->bluetooth_nrec)
3176 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3177 else
3178 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003179 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003180 if (adev->bluetooth_nrec)
3181 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3182 else
3183 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003184 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003185 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3186 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003187 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003188 if (audio_extn_usb_is_capture_supported())
3189 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3190 else
3191 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003192 } else {
3193 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3194 ALOGW("%s: Using default handset-mic", __func__);
3195 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3196 }
3197 }
3198exit:
3199 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3200 return snd_device;
3201}
3202
3203int platform_set_hdmi_channels(void *platform, int channel_count)
3204{
3205 struct platform_data *my_data = (struct platform_data *)platform;
3206 struct audio_device *adev = my_data->adev;
3207 struct mixer_ctl *ctl;
3208 const char *channel_cnt_str = NULL;
3209 const char *mixer_ctl_name = "HDMI_RX Channels";
3210 switch (channel_count) {
3211 case 8:
3212 channel_cnt_str = "Eight"; break;
3213 case 7:
3214 channel_cnt_str = "Seven"; break;
3215 case 6:
3216 channel_cnt_str = "Six"; break;
3217 case 5:
3218 channel_cnt_str = "Five"; break;
3219 case 4:
3220 channel_cnt_str = "Four"; break;
3221 case 3:
3222 channel_cnt_str = "Three"; break;
3223 default:
3224 channel_cnt_str = "Two"; break;
3225 }
3226 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3227 if (!ctl) {
3228 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3229 __func__, mixer_ctl_name);
3230 return -EINVAL;
3231 }
3232 ALOGV("HDMI channel count: %s", channel_cnt_str);
3233 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3234 return 0;
3235}
3236
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003237int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003238{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003239 struct platform_data *my_data = (struct platform_data *)platform;
3240 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003241 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3242 char *sad = block;
3243 int num_audio_blocks;
3244 int channel_count;
3245 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003246 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003247
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003248 struct mixer_ctl *ctl;
3249
3250 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3251 if (!ctl) {
3252 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3253 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003254 return 0;
3255 }
3256
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003257 mixer_ctl_update(ctl);
3258
3259 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003260
3261 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003262 if (count > (int)sizeof(block))
3263 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003264
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003265 ret = mixer_ctl_get_array(ctl, block, count);
3266 if (ret != 0) {
3267 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3268 return 0;
3269 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003270
3271 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003272 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003273
3274 for (i = 0; i < num_audio_blocks; i++) {
3275 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003276 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3277 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003278 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003279 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003280
3281 channel_count = (sad[0] & 0x7) + 1;
3282 if (channel_count > max_channels)
3283 max_channels = channel_count;
3284
3285 /* Advance to next block */
3286 sad += 3;
3287 }
3288
3289 return max_channels;
3290}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003291
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003292int platform_set_incall_recording_session_id(void *platform,
3293 uint32_t session_id, int rec_mode)
3294{
3295 int ret = 0;
3296 struct platform_data *my_data = (struct platform_data *)platform;
3297 struct audio_device *adev = my_data->adev;
3298 struct mixer_ctl *ctl;
3299 const char *mixer_ctl_name = "Voc VSID";
3300 int num_ctl_values;
3301 int i;
3302
3303 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3304 if (!ctl) {
3305 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3306 __func__, mixer_ctl_name);
3307 ret = -EINVAL;
3308 } else {
3309 num_ctl_values = mixer_ctl_get_num_values(ctl);
3310 for (i = 0; i < num_ctl_values; i++) {
3311 if (mixer_ctl_set_value(ctl, i, session_id)) {
3312 ALOGV("Error: invalid session_id: %x", session_id);
3313 ret = -EINVAL;
3314 break;
3315 }
3316 }
3317 }
3318
3319 if (my_data->csd != NULL) {
3320 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3321 if (ret < 0) {
3322 ALOGE("%s: csd_client_start_record failed, error %d",
3323 __func__, ret);
3324 }
3325 }
3326
3327 return ret;
3328}
3329
Arun Mirpuriba2749a2018-04-17 14:32:24 -07003330int platform_set_incall_recording_session_channels(void *platform,
3331 uint32_t channel_count)
3332{
3333 int ret = 0;
3334 struct platform_data *my_data = (struct platform_data *)platform;
3335 struct audio_device *adev = my_data->adev;
3336 const char *mixer_ctl_name = "Voc Rec Config";
3337 int num_ctl_values;
3338 int i;
3339 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3340
3341 if (!ctl) {
3342 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3343 __func__, mixer_ctl_name);
3344 ret = -EINVAL;
3345 } else {
3346 num_ctl_values = mixer_ctl_get_num_values(ctl);
3347 for (i = 0; i < num_ctl_values; i++) {
3348 if (mixer_ctl_set_value(ctl, i, channel_count)) {
3349 ALOGE("Error: invalid channel count: %x", channel_count);
3350 ret = -EINVAL;
3351 break;
3352 }
3353 }
3354 }
3355
3356 return ret;
3357}
3358
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003359int platform_stop_incall_recording_usecase(void *platform)
3360{
3361 int ret = 0;
3362 struct platform_data *my_data = (struct platform_data *)platform;
3363
3364 if (my_data->csd != NULL) {
3365 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3366 if (ret < 0) {
3367 ALOGE("%s: csd_client_stop_record failed, error %d",
3368 __func__, ret);
3369 }
3370 }
3371
3372 return ret;
3373}
3374
3375int platform_start_incall_music_usecase(void *platform)
3376{
3377 int ret = 0;
3378 struct platform_data *my_data = (struct platform_data *)platform;
3379
3380 if (my_data->csd != NULL) {
3381 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3382 if (ret < 0) {
3383 ALOGE("%s: csd_client_start_playback failed, error %d",
3384 __func__, ret);
3385 }
3386 }
3387
3388 return ret;
3389}
3390
3391int platform_stop_incall_music_usecase(void *platform)
3392{
3393 int ret = 0;
3394 struct platform_data *my_data = (struct platform_data *)platform;
3395
3396 if (my_data->csd != NULL) {
3397 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3398 if (ret < 0) {
3399 ALOGE("%s: csd_client_stop_playback failed, error %d",
3400 __func__, ret);
3401 }
3402 }
3403
3404 return ret;
3405}
3406
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003407int platform_set_parameters(void *platform, struct str_parms *parms)
3408{
3409 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003410 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003411 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003412 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003413 int ret = 0, err;
3414
3415 if (kv_pairs == NULL) {
3416 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003417 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003418 goto done;
3419 }
3420
3421 ALOGV("%s: enter: %s", __func__, kv_pairs);
3422
jasmine chac89321b2018-04-10 21:37:01 +08003423 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003424 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003425 if (value == NULL) {
3426 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003427 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003428 goto done;
3429 }
3430
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003431 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003432 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003433 if (err >= 0) {
3434 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3435 my_data->snd_card_name = strdup(value);
3436 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3437 }
3438
keunhui.park2f7306a2015-07-16 16:48:06 +09003439 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003440 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003441 if (err >= 0) {
3442 struct operator_info *info;
3443 char *str = value;
3444 char *name;
3445
3446 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3447 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3448 name = strtok(str, ";");
3449 info->name = strdup(name);
3450 info->mccmnc = strdup(str + strlen(name) + 1);
3451
3452 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003453 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003454 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003455
Jasmine Chaa314e192018-05-09 17:46:28 +08003456 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003457 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003458 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003459 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003460 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003461 my_data->max_mic_count = atoi(value);
3462 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003463 }
3464
jasmine chac89321b2018-04-10 21:37:01 +08003465 /* handle audio calibration parameters */
3466 set_audiocal(platform, parms, value, len);
3467
vivek mehta90933872017-06-15 18:04:39 -07003468 // to-do: disable setting sidetone gain, will revist this later
3469 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003470done:
3471 ALOGV("%s: exit with code(%d)", __func__, ret);
3472 if (kv_pairs != NULL)
3473 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003474 if (value != NULL)
3475 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003476
3477 return ret;
3478}
3479
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003480/* Delay in Us */
3481int64_t platform_render_latency(audio_usecase_t usecase)
3482{
3483 switch (usecase) {
3484 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3485 return DEEP_BUFFER_PLATFORM_DELAY;
3486 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3487 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003488 case USECASE_AUDIO_PLAYBACK_ULL:
3489 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003490 case USECASE_AUDIO_PLAYBACK_MMAP:
3491 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003492 default:
3493 return 0;
3494 }
3495}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003496
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003497int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3498 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003499{
3500 int ret = 0;
3501
3502 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3503 ALOGE("%s: Invalid snd_device = %d",
3504 __func__, device);
3505 ret = -EINVAL;
3506 goto done;
3507 }
3508
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003509 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3510 platform_get_snd_device_name(device),
3511 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3512 if (backend_tag_table[device]) {
3513 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003514 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003515 backend_tag_table[device] = strdup(backend_tag);
3516
3517 if (hw_interface != NULL) {
3518 if (hw_interface_table[device])
3519 free(hw_interface_table[device]);
3520 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3521 hw_interface_table[device] = strdup(hw_interface);
3522 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003523done:
3524 return ret;
3525}
3526
3527int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3528{
3529 int ret = 0;
3530 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3531 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3532 ret = -EINVAL;
3533 goto done;
3534 }
3535
3536 if ((type != 0) && (type != 1)) {
3537 ALOGE("%s: invalid usecase type", __func__);
3538 ret = -EINVAL;
3539 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003540 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3541 use_case_table[usecase],
3542 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003543 pcm_device_table[usecase][type] = pcm_id;
3544done:
3545 return ret;
3546}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003547
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003548#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3549int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3550 // backup_gain: gain to try to set in case of an error during ramp
3551 int start_gain, end_gain, step, backup_gain, i;
3552 bool error = false;
3553 const struct mixer_ctl *ctl;
3554 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3555 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3556 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3557 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3558 if (!ctl_left || !ctl_right) {
3559 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3560 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3561 return -EINVAL;
3562 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3563 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3564 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3565 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3566 return -EINVAL;
3567 }
3568 if (ramp_up) {
3569 start_gain = 0;
3570 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3571 step = +1;
3572 backup_gain = end_gain;
3573 } else {
3574 // using same gain on left and right
3575 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3576 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3577 end_gain = 0;
3578 step = -1;
3579 backup_gain = start_gain;
3580 }
3581 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3582 //ALOGV("setting speaker gain to %d", i);
3583 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3584 ALOGE("%s: error setting %s to %d during gain ramp",
3585 __func__, mixer_ctl_name_gain_left, i);
3586 error = true;
3587 break;
3588 }
3589 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3590 ALOGE("%s: error setting %s to %d during gain ramp",
3591 __func__, mixer_ctl_name_gain_right, i);
3592 error = true;
3593 break;
3594 }
3595 usleep(1000);
3596 }
3597 if (error) {
3598 // an error occured during the ramp, let's still try to go back to a safe volume
3599 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3600 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3601 }
3602 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3603 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3604 }
3605 }
3606 return start_gain;
3607}
3608
vivek mehtae59cfb22017-06-16 15:57:11 -07003609int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3610{
3611 const char *mixer_ctl_name = "Swap channel";
3612 struct mixer_ctl *ctl;
3613 const char *mixer_path;
3614 struct platform_data *my_data = (struct platform_data *)adev->platform;
3615
3616 // forced to set to swap, but device not rotated ... ignore set
3617 if (swap_channels && !my_data->speaker_lr_swap)
3618 return 0;
3619
3620 ALOGV("%s:", __func__);
3621
3622 if (swap_channels) {
3623 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3624 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3625 } else {
3626 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3627 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3628 }
3629
3630 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3631 if (!ctl) {
3632 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3633 return -EINVAL;
3634 }
3635
3636 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3637 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3638 return -EINVAL;
3639 }
3640
3641 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3642 swap_channels?"R --> L":"L --> R");
3643
3644 return 0;
3645}
3646
3647int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003648{
3649 // only update if there is active pcm playback on speaker
3650 struct audio_usecase *usecase;
3651 struct listnode *node;
3652 struct platform_data *my_data = (struct platform_data *)adev->platform;
3653
vivek mehtae59cfb22017-06-16 15:57:11 -07003654 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003655
vivek mehtae59cfb22017-06-16 15:57:11 -07003656 return platform_set_swap_channels(adev, swap_channels);
3657}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003658
vivek mehtae59cfb22017-06-16 15:57:11 -07003659int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3660{
3661 // only update if there is active pcm playback on speaker
3662 struct audio_usecase *usecase;
3663 struct listnode *node;
3664 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003665
vivek mehtae59cfb22017-06-16 15:57:11 -07003666 // do not swap channels in audio modes with concurrent capture and playback
3667 // as this may break the echo reference
3668 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3669 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3670 return 0;
3671 }
3672
3673 list_for_each(node, &adev->usecase_list) {
3674 usecase = node_to_item(node, struct audio_usecase, list);
3675 if (usecase->type == PCM_PLAYBACK &&
3676 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3677 /*
3678 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3679 * to perform device switch to disable the current backend to
3680 * enable it with new acdb data.
3681 */
3682 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3683 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3684 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3685 select_devices(adev, usecase->id);
3686 if (initial_skpr_gain != -EINVAL)
3687 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3688
3689 } else {
3690 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003691 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003692 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003693 }
3694 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003695
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003696 return 0;
3697}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003698
3699static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3700static int num_gain_tbl_entry = 0;
3701
3702bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3703
3704 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3705 if (num_gain_tbl_entry == -1) {
3706 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3707 __func__);
3708 return false;
3709 }
3710
3711 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3712 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3713 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3714 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3715 return false;
3716 }
3717
3718 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3719 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3720 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3721 return false;
3722 }
3723
3724 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3725 ++num_gain_tbl_entry;
3726
3727 return true;
3728}
3729
3730int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3731 int table_size) {
3732 int itt = 0;
3733 ALOGV("platform_get_gain_level_mapping called ");
3734
3735 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3736 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3737 return 0;
3738 }
3739
3740 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3741 mapping_tbl[itt] = tbl_mapping[itt];
3742 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3743 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3744 }
3745
3746 return num_gain_tbl_entry;
3747}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003748
3749int platform_snd_card_update(void *platform, card_status_t status)
3750{
3751 struct platform_data *my_data = (struct platform_data *)platform;
3752 struct audio_device *adev = my_data->adev;
3753
3754 if (status == CARD_STATUS_ONLINE) {
3755 if (my_data->acdb_send_custom_top)
3756 my_data->acdb_send_custom_top();
3757 }
3758 return 0;
3759}
David Linee3fe402017-03-13 10:00:42 -07003760
3761/*
3762 * configures afe with bit width and Sample Rate
3763 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003764int platform_set_backend_cfg(const struct audio_device* adev,
3765 snd_device_t snd_device,
3766 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003767{
3768
3769 int ret = 0;
3770 const int backend_idx = platform_get_backend_index(snd_device);
3771 struct platform_data *my_data = (struct platform_data *)adev->platform;
3772 const unsigned int bit_width = backend_cfg->bit_width;
3773 const unsigned int sample_rate = backend_cfg->sample_rate;
3774 const unsigned int channels = backend_cfg->channels;
3775 const audio_format_t format = backend_cfg->format;
3776 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3777
3778
3779 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3780 ", backend_idx %d device (%s)", __func__, bit_width,
3781 sample_rate, channels, backend_idx,
3782 platform_get_snd_device_name(snd_device));
3783
3784 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3785 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3786
3787 struct mixer_ctl *ctl = NULL;
3788 ctl = mixer_get_ctl_by_name(adev->mixer,
3789 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3790 if (!ctl) {
3791 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3792 __func__,
3793 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3794 return -EINVAL;
3795 }
3796
3797 if (bit_width == 24) {
3798 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3799 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3800 else
3801 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3802 } else if (bit_width == 32) {
3803 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3804 } else {
3805 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3806 }
3807 if ( ret < 0) {
3808 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3809 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3810 } else {
3811 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3812 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3813 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3814 }
3815 /* set the ret as 0 and not pass back to upper layer */
3816 ret = 0;
3817 }
3818
3819 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3820 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3821 char *rate_str = NULL;
3822 struct mixer_ctl *ctl = NULL;
3823
3824 switch (sample_rate) {
3825 case 32000:
3826 if (passthrough_enabled) {
3827 rate_str = "KHZ_32";
3828 break;
3829 }
3830 case 8000:
3831 case 11025:
3832 case 16000:
3833 case 22050:
3834 case 48000:
3835 rate_str = "KHZ_48";
3836 break;
3837 case 44100:
3838 rate_str = "KHZ_44P1";
3839 break;
3840 case 64000:
3841 case 96000:
3842 rate_str = "KHZ_96";
3843 break;
3844 case 88200:
3845 rate_str = "KHZ_88P2";
3846 break;
3847 case 176400:
3848 rate_str = "KHZ_176P4";
3849 break;
3850 case 192000:
3851 rate_str = "KHZ_192";
3852 break;
3853 case 352800:
3854 rate_str = "KHZ_352P8";
3855 break;
3856 case 384000:
3857 rate_str = "KHZ_384";
3858 break;
3859 case 144000:
3860 if (passthrough_enabled) {
3861 rate_str = "KHZ_144";
3862 break;
3863 }
3864 default:
3865 rate_str = "KHZ_48";
3866 break;
3867 }
3868
3869 ctl = mixer_get_ctl_by_name(adev->mixer,
3870 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3871 if(!ctl) {
3872 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3873 __func__,
3874 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3875 return -EINVAL;
3876 }
3877
3878 ALOGD("%s:becf: afe: %s set to %s", __func__,
3879 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3880 mixer_ctl_set_enum_by_string(ctl, rate_str);
3881 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3882 }
3883 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3884 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3885 struct mixer_ctl *ctl = NULL;
3886 char *channel_cnt_str = NULL;
3887
3888 switch (channels) {
3889 case 8:
3890 channel_cnt_str = "Eight"; break;
3891 case 7:
3892 channel_cnt_str = "Seven"; break;
3893 case 6:
3894 channel_cnt_str = "Six"; break;
3895 case 5:
3896 channel_cnt_str = "Five"; break;
3897 case 4:
3898 channel_cnt_str = "Four"; break;
3899 case 3:
3900 channel_cnt_str = "Three"; break;
3901 case 1:
3902 channel_cnt_str = "One"; break;
3903 case 2:
3904 default:
3905 channel_cnt_str = "Two"; break;
3906 }
3907
3908 ctl = mixer_get_ctl_by_name(adev->mixer,
3909 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3910 if (!ctl) {
3911 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3912 __func__,
3913 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3914 return -EINVAL;
3915 }
3916 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3917 my_data->current_backend_cfg[backend_idx].channels = channels;
3918
3919 // skip EDID configuration for HDMI backend
3920
3921 ALOGD("%s:becf: afe: %s set to %s", __func__,
3922 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3923 channel_cnt_str);
3924 }
3925
3926 // skip set ext_display format mixer control
3927 return ret;
3928}
3929
3930static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3931{
3932 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3933 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3934 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3935 }
3936
3937 return backend_bit_width_table[snd_device];
3938}
3939
3940/*
3941 * return backend_idx on which voice call is active
3942 */
3943static int platform_get_voice_call_backend(struct audio_device* adev)
3944{
3945 struct audio_usecase *uc = NULL;
3946 struct listnode *node;
3947 snd_device_t out_snd_device = SND_DEVICE_NONE;
3948
3949 int backend_idx = -1;
3950
3951 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3952 list_for_each(node, &adev->usecase_list) {
3953 uc = node_to_item(node, struct audio_usecase, list);
3954 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3955 out_snd_device = platform_get_output_snd_device(adev->platform,
3956 uc->stream.out->devices);
3957 backend_idx = platform_get_backend_index(out_snd_device);
3958 break;
3959 }
3960 }
3961 }
3962 return backend_idx;
3963}
3964
3965/*
3966 * goes through all the current usecases and picks the highest
3967 * bitwidth & samplerate
3968 */
3969static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3970 int backend_idx,
3971 struct audio_backend_cfg *backend_cfg)
3972{
3973 bool backend_change = false;
3974 unsigned int bit_width;
3975 unsigned int sample_rate;
3976 unsigned int channels;
3977 struct platform_data *my_data = (struct platform_data *)adev->platform;
3978
3979 bit_width = backend_cfg->bit_width;
3980 sample_rate = backend_cfg->sample_rate;
3981 channels = backend_cfg->channels;
3982
3983 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3984 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3985 sample_rate, channels);
3986
3987 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3988 // default backend
3989 // force routing is not required here, caller will do it anyway
3990 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3991 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3992 "for unprocessed/camera source", __func__);
3993 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3994 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3995 }
3996
3997 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3998 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3999 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4000 __func__, bit_width, sample_rate, channels);
4001 }
4002
4003 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4004 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4005
4006 // Force routing if the expected bitwdith or samplerate
4007 // is not same as current backend comfiguration
4008 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4009 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
4010 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
4011 backend_cfg->bit_width = bit_width;
4012 backend_cfg->sample_rate= sample_rate;
4013 backend_cfg->channels = channels;
4014 backend_change = true;
4015 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4016 "new sample rate: %d new channel: %d",
4017 __func__, backend_cfg->bit_width,
4018 backend_cfg->sample_rate, backend_cfg->channels);
4019 }
4020
4021 return backend_change;
4022}
4023
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004024static void pick_playback_cfg_for_uc(struct audio_device *adev,
4025 struct audio_usecase *usecase,
4026 snd_device_t snd_device,
4027 unsigned int *bit_width,
4028 unsigned int *sample_rate,
4029 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004030{
4031 int i =0;
4032 struct listnode *node;
4033 list_for_each(node, &adev->usecase_list) {
4034 struct audio_usecase *uc;
4035 uc = node_to_item(node, struct audio_usecase, list);
4036 struct stream_out *out = (struct stream_out*) uc->stream.out;
4037 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
4038 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
4039 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4040 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
4041 uc->id, out->sample_rate,
4042 pcm_format_to_bits(out->config.format), out_channels,
4043 platform_get_snd_device_name(uc->out_snd_device));
4044
4045 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
4046 if (*bit_width < pcm_format_to_bits(out->config.format))
4047 *bit_width = pcm_format_to_bits(out->config.format);
4048 if (*sample_rate < out->sample_rate)
4049 *sample_rate = out->sample_rate;
4050 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4051 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4052 if (*channels < out_channels)
4053 *channels = out_channels;
4054 }
4055 }
4056 }
4057 return;
4058}
4059
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004060static void headset_is_config_supported(unsigned int *bit_width,
4061 unsigned int *sample_rate,
4062 unsigned int *channels) {
4063 switch (*bit_width) {
4064 case 16:
4065 case 24:
4066 break;
4067 default:
4068 *bit_width = 16;
4069 break;
4070 }
4071
4072 if (*sample_rate > 192000) {
4073 *sample_rate = 192000;
4074 }
4075
4076 if (*channels > 2) {
4077 *channels = 2;
4078 }
4079}
4080
David Linee3fe402017-03-13 10:00:42 -07004081static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4082 struct audio_usecase* usecase,
4083 snd_device_t snd_device,
4084 struct audio_backend_cfg *backend_cfg)
4085{
4086 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004087 unsigned int bit_width;
4088 unsigned int sample_rate;
4089 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004090 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004091 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004092 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004093
4094 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4095 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4096 backend_change = false;
4097 return backend_change;
4098 }
4099
4100 backend_idx = platform_get_backend_index(snd_device);
4101 bit_width = backend_cfg->bit_width;
4102 sample_rate = backend_cfg->sample_rate;
4103 channels = backend_cfg->channels;
4104
4105 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4106 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4107 sample_rate, channels, backend_idx, usecase->id,
4108 platform_get_snd_device_name(snd_device));
4109
4110 if (backend_idx == platform_get_voice_call_backend(adev)) {
4111 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4112 __func__);
4113 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4114 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4115 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4116 } else {
4117 /*
4118 * The backend should be configured at highest bit width and/or
4119 * sample rate amongst all playback usecases.
4120 * If the selected sample rate and/or bit width differ with
4121 * current backend sample rate and/or bit width, then, we set the
4122 * backend re-configuration flag.
4123 *
4124 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4125 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004126 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4127 &bit_width,
4128 &sample_rate,
4129 &channels);
David Linee3fe402017-03-13 10:00:42 -07004130 }
4131
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004132 switch (backend_idx) {
4133 case USB_AUDIO_RX_BACKEND:
4134 audio_extn_usb_is_config_supported(&bit_width,
4135 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004136 if (platform_get_usb_service_interval(adev->platform, true,
4137 &service_interval) == 0) {
4138 /* overwrite with best altset for this service interval */
4139 int ret =
4140 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4141 service_interval,
4142 &bit_width,
4143 &sample_rate,
4144 &channels);
4145 if (ret < 0) {
4146 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4147 service_interval);
4148 return false;
4149 }
4150 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004151 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4152 __func__, bit_width, sample_rate, channels);
4153 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004154 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004155 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4156 break;
4157 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004158 default:
4159 bit_width = platform_get_snd_device_bit_width(snd_device);
4160 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4161 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4162 break;
David Linee3fe402017-03-13 10:00:42 -07004163 }
4164
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004165 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4166 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004167 __func__, backend_idx , bit_width, sample_rate);
4168
4169 // Force routing if the expected bitwdith or samplerate
4170 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004171 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4172 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4173 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004174 backend_cfg->bit_width = bit_width;
4175 backend_cfg->sample_rate = sample_rate;
4176 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004177 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004178 backend_change = true;
4179 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4180 "new sample rate: %d new channels: %d",
4181 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4182 }
4183
4184 return backend_change;
4185}
4186
4187bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4188 struct audio_usecase *usecase, snd_device_t snd_device)
4189{
4190 int backend_idx = DEFAULT_CODEC_BACKEND;
4191 int new_snd_devices[SND_DEVICE_OUT_END];
4192 int i, num_devices = 1;
4193 bool ret = false;
4194 struct platform_data *my_data = (struct platform_data *)adev->platform;
4195 struct audio_backend_cfg backend_cfg;
4196
4197 backend_idx = platform_get_backend_index(snd_device);
4198
4199 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4200 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4201 backend_cfg.format = usecase->stream.out->format;
4202 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4203 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4204 backend_cfg.passthrough_enabled = false;
4205
4206 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4207 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4208 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4209 platform_get_snd_device_name(snd_device));
4210
4211 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4212 new_snd_devices[0] = snd_device;
4213
4214 for (i = 0; i < num_devices; i++) {
4215 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4216 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4217 &backend_cfg))) {
4218 platform_set_backend_cfg(adev, new_snd_devices[i],
4219 &backend_cfg);
4220 ret = true;
4221 }
4222 }
4223 return ret;
4224}
4225
4226bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4227 struct audio_usecase *usecase, snd_device_t snd_device)
4228{
4229 int backend_idx = platform_get_backend_index(snd_device);
4230 int ret = 0;
4231 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004232 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004233
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004234 if (usecase->type == PCM_CAPTURE) {
4235 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004236 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4237 } else {
4238 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4239 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4240 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4241 backend_cfg.channels = 1;
4242 }
4243
4244 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4245 ", backend_idx %d usecase = %d device (%s)", __func__,
4246 backend_cfg.bit_width,
4247 backend_cfg.sample_rate,
4248 backend_cfg.channels,
4249 backend_idx, usecase->id,
4250 platform_get_snd_device_name(snd_device));
4251
4252 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4253 ret = platform_set_backend_cfg(adev, snd_device,
4254 &backend_cfg);
4255 if(!ret)
4256 return true;
4257 }
4258
4259 return false;
4260}
4261
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004262static int max_be_dai_names = 0;
4263static const struct be_dai_name_struct *be_dai_name_table;
4264
4265/*
4266 * Retrieves the be_dai_name_table from kernel to enable a mapping
4267 * between sound device hw interfaces and backend IDs. This allows HAL to
4268 * specify the backend a specific calibration is needed for.
4269 */
4270static int init_be_dai_name_table(struct audio_device *adev)
4271{
4272 const char *mixer_ctl_name = "Backend DAI Name Table";
4273 struct mixer_ctl *ctl;
4274 int i, j, ret, size;
4275 bool valid_hw_interface;
4276
4277 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4278 if (!ctl) {
4279 ALOGE("%s: Could not get ctl for mixer name %s\n",
4280 __func__, mixer_ctl_name);
4281 ret = -EINVAL;
4282 goto done;
4283 }
4284
4285 mixer_ctl_update(ctl);
4286
4287 size = mixer_ctl_get_num_values(ctl);
4288 if (size <= 0){
4289 ALOGE("%s: Failed to get %s size %d\n",
4290 __func__, mixer_ctl_name, size);
4291 ret = -EFAULT;
4292 goto done;
4293 }
4294
vivek mehtaa68fea62017-06-08 19:04:02 -07004295 be_dai_name_table =
4296 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004297 if (be_dai_name_table == NULL) {
4298 ALOGE("%s: Failed to allocate memory for %s\n",
4299 __func__, mixer_ctl_name);
4300 ret = -ENOMEM;
4301 goto freeMem;
4302 }
4303
4304 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4305 if (ret) {
4306 ALOGE("%s: Failed to get %s, ret %d\n",
4307 __func__, mixer_ctl_name, ret);
4308 ret = -EFAULT;
4309 goto freeMem;
4310 }
4311
4312 if (be_dai_name_table != NULL) {
4313 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4314 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4315 __func__, mixer_ctl_name, max_be_dai_names);
4316 ret = 0;
4317 } else {
4318 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4319 ret = -EFAULT;
4320 goto freeMem;
4321 }
4322
4323 /*
4324 * Validate all sound devices have a valid backend set to catch
4325 * errors for uncommon sound devices
4326 */
4327 for (i = 0; i < SND_DEVICE_MAX; i++) {
4328 valid_hw_interface = false;
4329
4330 if (hw_interface_table[i] == NULL) {
4331 ALOGW("%s: sound device %s has no hw interface set\n",
4332 __func__, platform_get_snd_device_name(i));
4333 continue;
4334 }
4335
4336 for (j = 0; j < max_be_dai_names; j++) {
4337 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4338 == 0) {
4339 valid_hw_interface = true;
4340 break;
4341 }
4342 }
4343 if (!valid_hw_interface)
4344 ALOGD("%s: sound device %s does not have a valid hw interface set "
4345 "(disregard for combo devices) %s\n",
4346 __func__, platform_get_snd_device_name(i),
4347 hw_interface_table[i]);
4348 }
4349
4350 goto done;
4351
4352freeMem:
4353 if (be_dai_name_table) {
4354 free((void *)be_dai_name_table);
4355 be_dai_name_table = NULL;
4356 }
4357
4358done:
4359 return ret;
4360}
4361
4362int platform_get_snd_device_backend_index(snd_device_t device)
4363{
4364 int i, be_dai_id;
4365 const char * hw_interface_name = NULL;
4366
4367 ALOGV("%s: enter with device %d\n", __func__, device);
4368
vivek mehtaa68fea62017-06-08 19:04:02 -07004369 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004370 ALOGE("%s: Invalid snd_device = %d",
4371 __func__, device);
4372 be_dai_id = -EINVAL;
4373 goto done;
4374 }
4375
4376 /* Get string value of necessary backend for device */
4377 hw_interface_name = hw_interface_table[device];
4378 if (hw_interface_name == NULL) {
4379 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4380 be_dai_id = -EINVAL;
4381 goto done;
4382 }
4383
4384 /* Check if be dai name table was retrieved successfully */
4385 if (be_dai_name_table == NULL) {
4386 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4387 be_dai_id = -EFAULT;
4388 goto done;
4389 }
4390
4391 /* Get backend ID for device specified */
4392 for (i = 0; i < max_be_dai_names; i++) {
4393 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4394 be_dai_id = be_dai_name_table[i].be_id;
4395 goto done;
4396 }
4397 }
4398 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4399 be_dai_id = -EINVAL;
4400 goto done;
4401
4402done:
4403 return be_dai_id;
4404}
4405
4406void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4407 unsigned int stream_sr, int* sample_rate)
4408{
4409 struct platform_data* my_data = (struct platform_data *)platform;
4410 int backend_idx = platform_get_backend_index(snd_device);
4411 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4412 /*
4413 *Check if device SR is multiple of 8K or 11.025 Khz
4414 *check if the stream SR is multiple of same base, if yes
4415 *then have copp SR equal to stream SR, this ensures that
4416 *post processing happens at stream SR, else have
4417 *copp SR equal to device SR.
4418 */
4419 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4420 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4421 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4422 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4423 *sample_rate = device_sr;
4424 } else
4425 *sample_rate = stream_sr;
4426
4427 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4428 , *sample_rate);
4429
4430}
4431
4432// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004433void platform_add_app_type(const char *uc_type,
4434 const char *mode,
4435 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004436 int app_type, int max_rate) {
4437 struct app_type_entry *ap =
4438 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4439
4440 if (!ap) {
4441 ALOGE("%s failed to allocate mem for app type", __func__);
4442 return;
4443 }
4444
4445 ap->uc_type = -1;
4446 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4447 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4448 ap->uc_type = usecase_type_index[i].index;
4449 break;
4450 }
4451 }
4452
4453 if (ap->uc_type == -1) {
4454 free(ap);
4455 return;
4456 }
4457
vivek mehtaa68fea62017-06-08 19:04:02 -07004458 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4459 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004460 ap->bit_width = bw;
4461 ap->app_type = app_type;
4462 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004463 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004464 list_add_tail(&app_type_entry_list, &ap->node);
4465}
4466
4467
4468int platform_get_default_app_type_v2(void *platform __unused,
4469 usecase_type_t type,
4470 int *app_type )
4471{
4472 if (type == PCM_PLAYBACK)
4473 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4474 else
4475 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4476 return 0;
4477}
4478
vivek mehtaa68fea62017-06-08 19:04:02 -07004479int platform_get_app_type_v2(void *platform,
4480 usecase_type_t uc_type,
4481 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004482 int bw, int sr __unused,
4483 int *app_type)
4484{
4485 struct listnode *node;
4486 struct app_type_entry *entry;
4487 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004488
4489 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4490 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004491 list_for_each(node, &app_type_entry_list) {
4492 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004493 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4494 __func__, entry->uc_type, entry->mode, entry->bit_width,
4495 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004496 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004497 entry->uc_type == uc_type &&
4498 sr <= entry->max_rate &&
4499 entry->mode && !strcmp(mode, entry->mode)) {
4500 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004501 *app_type = entry->app_type;
4502 break;
4503 }
4504 }
4505
4506 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004507 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004508 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4509 }
4510 return 0;
4511}
vivek mehta90933872017-06-15 18:04:39 -07004512
4513int platform_set_sidetone(struct audio_device *adev,
4514 snd_device_t out_snd_device,
4515 bool enable, char *str)
4516{
4517 int ret;
4518 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4519 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4520 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4521 if (ret)
4522 ALOGI("%s: usb device %d does not support device sidetone\n",
4523 __func__, out_snd_device);
4524 } else {
4525 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4526 __func__, out_snd_device, str);
4527 if (enable)
4528 audio_route_apply_and_update_path(adev->audio_route, str);
4529 else
4530 audio_route_reset_and_update_path(adev->audio_route, str);
4531 }
4532 return 0;
4533}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004534
4535int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4536 int *fd __unused, uint32_t *size __unused)
4537{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004538#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004539 struct platform_data *my_data = (struct platform_data *)platform;
4540 struct audio_device *adev = my_data->adev;
4541 int hw_fd = -1;
4542 char dev_name[128];
4543 struct snd_pcm_mmap_fd mmap_fd;
4544 memset(&mmap_fd, 0, sizeof(mmap_fd));
4545 mmap_fd.dir = dir;
4546 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4547 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4548 hw_fd = open(dev_name, O_RDONLY);
4549 if (hw_fd < 0) {
4550 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4551 return -1;
4552 }
4553 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4554 ALOGE("fe hw dep node ioctl failed");
4555 close(hw_fd);
4556 return -1;
4557 }
4558 *fd = mmap_fd.fd;
4559 *size = mmap_fd.size;
4560 close(hw_fd); // mmap_fd should still be valid
4561 return 0;
4562#else
4563 return -1;
4564#endif
4565}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004566
4567bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4568{
4569 bool needs_event = false;
4570
4571 switch (uc_id) {
4572 /* concurrent capture usecases which needs event */
4573 case USECASE_AUDIO_RECORD:
4574 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4575 case USECASE_AUDIO_RECORD_MMAP:
4576 case USECASE_AUDIO_RECORD_HIFI:
4577 case USECASE_AUDIO_RECORD_VOIP:
4578 case USECASE_VOICEMMODE1_CALL:
4579 case USECASE_VOICEMMODE2_CALL:
4580 /* concurrent playback usecases that needs event */
4581 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4582 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4583 needs_event = true;
4584 break;
4585 default:
4586 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4587 }
4588 return needs_event;
4589}
4590
4591bool platform_snd_device_has_speaker(snd_device_t dev) {
4592 int num_devs = 2;
4593 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4594 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4595 return platform_snd_device_has_speaker(split_devs[0]) ||
4596 platform_snd_device_has_speaker(split_devs[1]);
4597 }
4598
4599 switch (dev) {
4600 case SND_DEVICE_OUT_SPEAKER:
4601 case SND_DEVICE_OUT_SPEAKER_SAFE:
4602 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4603 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4604 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4605 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4606 return true;
4607 default:
4608 break;
4609 }
4610 return false;
4611}
jiabin8962a4d2018-03-19 18:21:24 -07004612
4613bool platform_set_microphone_characteristic(void *platform,
4614 struct audio_microphone_characteristic_t mic) {
4615 struct platform_data *my_data = (struct platform_data *)platform;
4616 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4617 ALOGE("mic number is more than maximum number");
4618 return false;
4619 }
4620 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4621 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4622 }
4623 my_data->microphones[my_data->declared_mic_count++] = mic;
4624 return true;
4625}
4626
4627int platform_get_microphones(void *platform,
4628 struct audio_microphone_characteristic_t *mic_array,
4629 size_t *mic_count) {
4630 struct platform_data *my_data = (struct platform_data *)platform;
4631 if (mic_count == NULL) {
4632 return -EINVAL;
4633 }
4634 if (mic_array == NULL) {
4635 return -EINVAL;
4636 }
4637
4638 if (*mic_count == 0) {
4639 *mic_count = my_data->declared_mic_count;
4640 return 0;
4641 }
4642
4643 size_t max_mic_count = *mic_count;
4644 size_t actual_mic_count = 0;
4645 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4646 mic_array[i] = my_data->microphones[i];
4647 actual_mic_count++;
4648 }
4649 *mic_count = actual_mic_count;
4650 return 0;
4651}
4652
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004653bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4654 const struct mic_info *info) {
4655 struct platform_data *my_data = (struct platform_data *)platform;
4656 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4657 ALOGE("%s: Sound device not valid", __func__);
4658 return false;
4659 }
4660 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4661 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4662 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4663 my_data->mic_map[in_snd_device].mic_count--;
4664 return false;
4665 }
4666 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4667 return true;
4668}
4669
4670int platform_get_active_microphones(void *platform, unsigned int channels,
4671 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004672 struct audio_microphone_characteristic_t *mic_array,
4673 size_t *mic_count) {
4674 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004675 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4676 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004677 return -EINVAL;
4678 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004679 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004680 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004681
4682 snd_device_t active_input_snd_device =
4683 platform_get_input_snd_device(platform, usecase->stream.in->device);
4684 if (active_input_snd_device == SND_DEVICE_NONE) {
4685 ALOGI("%s: No active microphones found", __func__);
4686 goto end;
4687 }
4688
4689 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4690 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4691
4692 for (size_t i = 0; i < active_mic_count; i++) {
4693 unsigned int channels_for_active_mic = channels;
4694 if (channels_for_active_mic > m_info[i].channel_count) {
4695 channels_for_active_mic = m_info[i].channel_count;
4696 }
4697 for (size_t j = 0; j < max_mic_count; j++) {
4698 if (strcmp(my_data->microphones[j].device_id,
4699 m_info[i].device_id) == 0) {
4700 mic_array[actual_mic_count] = my_data->microphones[j];
4701 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4702 mic_array[actual_mic_count].channel_mapping[ch] =
4703 m_info[i].channel_mapping[ch];
4704 }
4705 actual_mic_count++;
4706 break;
jiabin8962a4d2018-03-19 18:21:24 -07004707 }
jiabin8962a4d2018-03-19 18:21:24 -07004708 }
4709 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004710end:
jiabin8962a4d2018-03-19 18:21:24 -07004711 *mic_count = actual_mic_count;
4712 return 0;
4713}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004714
4715int platform_set_usb_service_interval(void *platform,
4716 bool playback,
4717 unsigned long service_interval,
4718 bool *reconfig)
4719{
4720#if defined (USB_SERVICE_INTERVAL_ENABLED)
4721 struct platform_data *_platform = (struct platform_data *)platform;
4722 *reconfig = false;
4723 if (!playback) {
4724 ALOGE("%s not valid for capture", __func__);
4725 return -1;
4726 }
4727 const char *ctl_name = "USB_AUDIO_RX service_interval";
4728 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4729 ctl_name);
4730 if (!ctl) {
4731 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4732 return -1;
4733 }
4734 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4735 mixer_ctl_set_value(ctl, 0, service_interval);
4736 *reconfig = true;
4737 }
4738 return 0;
4739#else
4740 *reconfig = false;
4741 (void)platform;
4742 (void)playback;
4743 (void)service_interval;
4744 return -1;
4745#endif
4746}
4747
4748int platform_get_usb_service_interval(void *platform,
4749 bool playback,
4750 unsigned long *service_interval)
4751{
4752#if defined (USB_SERVICE_INTERVAL_ENABLED)
4753 struct platform_data *_platform = (struct platform_data *)platform;
4754 if (!playback) {
4755 ALOGE("%s not valid for capture", __func__);
4756 return -1;
4757 }
4758 const char *ctl_name = "USB_AUDIO_RX service_interval";
4759 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4760 ctl_name);
4761 if (!ctl) {
4762 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4763 return -1;
4764 }
4765 *service_interval = mixer_ctl_get_value(ctl, 0);
4766 return 0;
4767#else
4768 (void)platform;
4769 (void)playback;
4770 (void)service_interval;
4771 return -1;
4772#endif
4773}
Ashish Jain1c849702018-05-11 20:11:55 +05304774
4775int platform_set_acdb_metainfo_key(void *platform __unused,
4776 char *name __unused,
4777 int key __unused)
4778{
4779 return -ENOSYS;
4780}