blob: cbc8a09817aeef142f16b330c6d0079d6c935d3c [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",
Eric Laurentb23d5282013-05-14 15:27:20 -0700266 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
267 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
268 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
269 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800270 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
271 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700272 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700273 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700274 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700275 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
jasmine cha270b7762018-03-30 15:41:33 +0800276 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700277 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700278 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700279 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700280 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
281 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700282 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800283 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
juyuchen5351ea62018-05-16 10:54:37 +0800284 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800285 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
juyuchen5351ea62018-05-16 10:54:37 +0800286 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700287
288 /* Capture sound devices */
289 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700290 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700291 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
292 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
293 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
294 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
295 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
296 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
297 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
298
299 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
300 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
301 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
302 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
303 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
304 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
305 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
306 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
307 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
308
309 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500310 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700311
Eric Laurentb23d5282013-05-14 15:27:20 -0700312 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
313 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700314 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700315 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700316 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700317 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700318
319 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
320 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
321 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
322 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700323 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700324 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700325 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
326 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
327 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800328 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
329 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700330
Eric Laurentb23d5282013-05-14 15:27:20 -0700331 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700332 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700333 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700334 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700335 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
336 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700337 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700338 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
339 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
340 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
341 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700342 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700343
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700344 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700345 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
346 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
347 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
348 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800349
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700350 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700351
Prashant Malanic92c5962015-08-11 15:10:18 -0700352 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
353 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700354 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700355 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
356 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700357 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
358 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700359};
360
361/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700362static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700363 [SND_DEVICE_NONE] = -1,
364 [SND_DEVICE_OUT_HANDSET] = 7,
365 [SND_DEVICE_OUT_SPEAKER] = 15,
366 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700367 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700368 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500369 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700370 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700371 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500372 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700373 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700374 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
375 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500376 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700377 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500378 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700379 [SND_DEVICE_OUT_HDMI] = 18,
380 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
381 [SND_DEVICE_OUT_BT_SCO] = 22,
juyuchen5351ea62018-05-16 10:54:37 +0800382 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700383 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
juyuchen5351ea62018-05-16 10:54:37 +0800384 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800385 [SND_DEVICE_OUT_BT_A2DP] = 20,
386 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700387 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700388 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
389 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
390 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800391 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
392 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700393 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700394 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700395 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700396 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
jasmine cha270b7762018-03-30 15:41:33 +0800397 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700398 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700399 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700400 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700401 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
402 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700403 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700404
405 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700406 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
407 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
408 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
409 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
410 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
411 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
412 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
413 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
414
415 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
416 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
417 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
418 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
419 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
420 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
421 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
422 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
423 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
424
rago90fb9612015-12-02 11:37:53 -0800425 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500426 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700427
Eric Laurentb23d5282013-05-14 15:27:20 -0700428 [SND_DEVICE_IN_HDMI_MIC] = 4,
429 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700430 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700431 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700432 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700433 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700434
435 [SND_DEVICE_IN_VOICE_DMIC] = 41,
436 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
437 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700438 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700439 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800440 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700441 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
442 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
443 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800444 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
445 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700446
rago90fb9612015-12-02 11:37:53 -0800447 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700448 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700449 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700450 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700451 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
452 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800453 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
454
455 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
456 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700457 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
458 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
459 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700460
461 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700462 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700463 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
464 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
465 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
466 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700467 [SND_DEVICE_IN_THREE_MIC] = 46,
468 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700469 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700470 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
471 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700472 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
473 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700474};
475
David Linee3fe402017-03-13 10:00:42 -0700476// Platform specific backend bit width table
477static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
478
Haynes Mathew George98c95622014-06-20 19:14:25 -0700479struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700480 char name[100];
481 unsigned int index;
482};
483
484#define TO_NAME_INDEX(X) #X, X
485
Haynes Mathew George98c95622014-06-20 19:14:25 -0700486/* Used to get index from parsed string */
487static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
488 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700489 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
490 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
491 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700492 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700493 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500494 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700495 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700496 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500497 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700498 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700499 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
500 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700501 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700502 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500503 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700504 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
505 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
506 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
juyuchen5351ea62018-05-16 10:54:37 +0800507 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700508 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
juyuchen5351ea62018-05-16 10:54:37 +0800509 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Aniket Kumar Lata26483012018-01-31 20:21:42 -0800510 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
511 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700512 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500513 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700514 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
515 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
516 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800517 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
518 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800519 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
520 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700521 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700522 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700523 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700524 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700525 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700526 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700527 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
528 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
jasmine cha270b7762018-03-30 15:41:33 +0800529 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800530
531 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700532 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700533 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700534 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
535 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
536 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
537 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
538 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
539 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
540 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
541
542 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700543 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700544 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
545 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
546 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
547 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
548 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
549 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
550 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
551
552 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700553 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700554
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700555 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
556 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700557 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700558 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700559 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700560 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700561
562 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
563 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
564 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700565 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700566 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
567 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700568 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
569 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
570 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800571 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
572 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
573
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700574
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700575 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700576 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700577 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700578 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700579 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
580 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700581 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700582 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700583 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
584 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
585 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
586 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700587
rago90fb9612015-12-02 11:37:53 -0800588 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
589 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700590 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
591 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
592 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800593
Prashant Malanic92c5962015-08-11 15:10:18 -0700594 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
595 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700596 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700597 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
598 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700599 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
600 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700601};
602
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700603static char * backend_tag_table[SND_DEVICE_MAX] = {0};
604static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700605
606static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
607 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
608 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800609 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700610 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700611 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
612 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800613 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700614 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
615 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800616 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700617 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700618 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
619 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
620 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
621 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
622 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800623 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
624 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700625 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
626 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
627 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
628 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800629 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
630 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
631 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
632 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
633 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700634 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
635 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200636 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Aniket Kumar Lata99546312018-03-19 21:38:38 -0700637 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700638};
639
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800640static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
641 {TO_NAME_INDEX(PCM_PLAYBACK)},
642 {TO_NAME_INDEX(PCM_CAPTURE)},
643 {TO_NAME_INDEX(VOICE_CALL)},
644 {TO_NAME_INDEX(PCM_HFP_CALL)},
645};
646
647struct app_type_entry {
648 int uc_type;
649 int bit_width;
650 int app_type;
651 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700652 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800653 struct listnode node; // membership in app_type_entry_list;
654};
655
656static struct listnode app_type_entry_list;
657
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700658#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
659#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800660#define ULL_PLATFORM_DELAY (3*1000LL)
661#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700662
Eric Laurentb23d5282013-05-14 15:27:20 -0700663static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
664static bool is_tmus = false;
665
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800666static int init_be_dai_name_table(struct audio_device *adev);
667
Eric Laurentb23d5282013-05-14 15:27:20 -0700668static void check_operator()
669{
670 char value[PROPERTY_VALUE_MAX];
671 int mccmnc;
672 property_get("gsm.sim.operator.numeric",value,"0");
673 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700674 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700675 switch(mccmnc) {
676 /* TMUS MCC(310), MNC(490, 260, 026) */
677 case 310490:
678 case 310260:
679 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900680 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
681 case 310800:
682 case 310660:
683 case 310580:
684 case 310310:
685 case 310270:
686 case 310250:
687 case 310240:
688 case 310230:
689 case 310220:
690 case 310210:
691 case 310200:
692 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700693 is_tmus = true;
694 break;
695 }
696}
697
698bool is_operator_tmus()
699{
700 pthread_once(&check_op_once_ctl, check_operator);
701 return is_tmus;
702}
703
keunhui.park2f7306a2015-07-16 16:48:06 +0900704static char *get_current_operator()
705{
706 struct listnode *node;
707 struct operator_info *info_item;
708 char mccmnc[PROPERTY_VALUE_MAX];
709 char *ret = NULL;
710
Tom Cherry7fea2042016-11-10 18:05:59 -0800711 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900712
713 list_for_each(node, &operator_info_list) {
714 info_item = node_to_item(node, struct operator_info, list);
715 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
716 ret = info_item->name;
717 }
718 }
719
720 return ret;
721}
722
723static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
724{
725 struct listnode *node;
726 struct operator_specific_device *ret = NULL;
727 struct operator_specific_device *device_item;
728 char *operator_name;
729
730 operator_name = get_current_operator();
731 if (operator_name == NULL)
732 return ret;
733
734 list_for_each(node, operator_specific_device_table[snd_device]) {
735 device_item = node_to_item(node, struct operator_specific_device, list);
736 if (strcmp(operator_name, device_item->operator) == 0) {
737 ret = device_item;
738 }
739 }
740
741 return ret;
742}
743
744
745static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
746{
747 struct operator_specific_device *device;
748 int ret = acdb_device_table[snd_device];
749
750 device = get_operator_specific_device(snd_device);
751 if (device != NULL)
752 ret = device->acdb_id;
753
754 return ret;
755}
756
757static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
758{
759 struct operator_specific_device *device;
760 const char *ret = device_table[snd_device];
761
762 device = get_operator_specific_device(snd_device);
763 if (device != NULL)
764 ret = device->mixer_path;
765
766 return ret;
767}
768
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800769inline bool platform_supports_app_type_cfg()
770{
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700771#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800772 return true;
773#else
774 return false;
775#endif
776}
777
jasmine chac89321b2018-04-10 21:37:01 +0800778static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
779{
780 int err;
781 char value[64];
782 int ret = 0;
783
784 if (parms == NULL || cal == NULL)
785 return ret;
786
787 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
788 if (err >= 0) {
789 str_parms_del(parms, "cal_persist");
790 cal->persist = (uint32_t)strtoul(value, NULL, 0);
791 ret = ret | 0x1;
792 }
793 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
794 if (err >= 0) {
795 str_parms_del(parms, "cal_apptype");
796 cal->app_type = (uint32_t)strtoul(value, NULL, 0);
797 ret = ret | 0x2;
798 }
799 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
800 if (err >= 0) {
801 str_parms_del(parms, "cal_caltype");
802 cal->cal_type = (uint32_t)strtoul(value, NULL, 0);
803 ret = ret | 0x4;
804 }
805 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
806 if (err >= 0) {
807 str_parms_del(parms, "cal_samplerate");
808 cal->sampling_rate = (uint32_t)strtoul(value, NULL, 0);
809 ret = ret | 0x8;
810 }
811 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
812 if (err >= 0) {
813 str_parms_del(parms, "cal_devid");
814 cal->dev_id = (uint32_t)strtoul(value, NULL, 0);
815 ret = ret | 0x10;
816 }
817 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
818 if (err >= 0) {
819 str_parms_del(parms, "cal_snddevid");
820 cal->snd_dev_id = (uint32_t)strtoul(value, NULL, 0);
821 ret = ret | 0x20;
822 }
823 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
824 if (err >= 0) {
825 str_parms_del(parms, "cal_topoid");
826 cal->topo_id = (uint32_t)strtoul(value, NULL, 0);
827 ret = ret | 0x40;
828 }
829 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
830 if (err >= 0) {
831 str_parms_del(parms, "cal_moduleid");
832 cal->module_id = (uint32_t)strtoul(value, NULL, 0);
833 ret = ret | 0x80;
834 }
835 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
836 if (err >= 0) {
837 str_parms_del(parms, "cal_paramid");
838 cal->param_id = (uint32_t)strtoul(value, NULL, 0);
839 ret = ret | 0x100;
840 }
841 return ret;
842}
843
844static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len)
845{
846 struct platform_data *my_data = (struct platform_data *)platform;
847 acdb_audio_cal_cfg_t cal;
848 uint8_t *dptr = NULL;
849 int32_t dlen = 0;
850 int err ,ret;
851
852 if (value == NULL || platform == NULL || parms == NULL) {
853 ALOGE("[%s] received null pointer, failed", __func__);
854 goto done_key_audcal;
855 }
856
857 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
858 /* parse audio calibration keys */
859 ret = parse_audiocal_cfg(parms, &cal);
860
861 /* handle audio calibration data now */
862 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
863 if (err >= 0) {
864 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
865 dlen = strlen(value);
866 if (dlen <= 0) {
867 ALOGE("[%s] null data received", __func__);
868 goto done_key_audcal;
869 }
870 /*
871 The base64 encoded string is always larger than the binary data,
872 so b64_pton will always output less data than provided (around 1/3
873 less than the input data). That's why we can allocate input buffer
874 length and then get function work.
875 */
876 dptr = (uint8_t *)calloc(dlen, sizeof(uint8_t));
877 if (dptr == NULL) {
878 ALOGE("[%s] memory allocation failed for %d", __func__, dlen);
879 goto done_key_audcal;
880 }
881 dlen = b64_pton(value, dptr, dlen);
882 if (dlen <= 0) {
883 ALOGE("[%s] data decoding failed %d", __func__, dlen);
884 goto done_key_audcal;
885 }
886
887 if (cal.dev_id) {
888 if (audio_is_input_device(cal.dev_id)) {
889 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
890 } else {
891 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
892 }
893 }
894 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
895 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
896 cal.snd_dev_id, cal.acdb_dev_id);
897 if (cal.acdb_dev_id == -EINVAL) {
898 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
899 __func__, cal.acdb_dev_id, cal.snd_dev_id);
900 goto done_key_audcal;
901 }
902 if (my_data->acdb_set_audio_cal) {
903 ret = my_data->acdb_set_audio_cal((void *)&cal, (void *)dptr, dlen);
904 }
905 }
906done_key_audcal:
907 if (dptr != NULL)
908 free(dptr);
909}
910
vivek mehta1a9b7c02015-06-25 11:49:38 -0700911bool platform_send_gain_dep_cal(void *platform, int level)
912{
913 bool ret_val = false;
914 struct platform_data *my_data = (struct platform_data *)platform;
915 struct audio_device *adev = my_data->adev;
916 int acdb_dev_id, app_type;
917 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
918 int mode = CAL_MODE_RTAC;
919 struct listnode *node;
920 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700921 bool valid_uc_type;
922 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700923
924 if (my_data->acdb_send_gain_dep_cal == NULL) {
925 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
926 return ret_val;
927 }
928
929 if (!voice_is_in_call(adev)) {
930 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
931 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700932
933 // find the current active sound device
934 list_for_each(node, &adev->usecase_list) {
935 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700936 LOG_ALWAYS_FATAL_IF(usecase == NULL,
937 "unxpected NULL usecase in usecase_list");
938 valid_uc_type = usecase->type == PCM_PLAYBACK;
939 valid_dev = false;
940 if (valid_uc_type) {
941 audio_devices_t dev = usecase->stream.out->devices;
942 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700943 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700944 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
945 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
946 }
947 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700948 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
949 if (platform_supports_app_type_cfg())
950 app_type = usecase->stream.out->app_type_cfg.app_type;
951 else
952 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700953
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -0700954 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta40125092017-08-21 18:48:51 -0700955
956 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700957 acdb_dev_type, mode, level)) {
958 // set ret_val true if at least one calibration is set successfully
959 ret_val = true;
960 } else {
961 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
962 }
963 } else {
964 ALOGW("%s: Usecase list is empty", __func__);
965 }
966 }
967 } else {
968 ALOGW("%s: Voice call in progress .. ignore setting new cal",
969 __func__);
970 }
971 return ret_val;
972}
973
Eric Laurentcefbbac2014-09-04 13:54:10 -0500974void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700975{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800976 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500977 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700978
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800979 if (strcmp(my_data->ec_ref_mixer_path, "")) {
980 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
981 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500982 }
983
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800984 if (enable) {
985 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
986 if (out_device != AUDIO_DEVICE_NONE) {
987 snd_device = platform_get_output_snd_device(adev->platform, out_device);
988 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
989 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500990
Joe Onorato188b6222016-03-01 11:02:27 -0800991 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800992 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
993 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700994}
995
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700996static struct csd_data *open_csd_client(bool i2s_ext_modem)
997{
998 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
999
1000 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1001 if (csd->csd_client == NULL) {
1002 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1003 goto error;
1004 } else {
1005 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1006
1007 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1008 "csd_client_deinit");
1009 if (csd->deinit == NULL) {
1010 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1011 dlerror());
1012 goto error;
1013 }
1014 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1015 "csd_client_disable_device");
1016 if (csd->disable_device == NULL) {
1017 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1018 __func__, dlerror());
1019 goto error;
1020 }
1021 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1022 "csd_client_enable_device_config");
1023 if (csd->enable_device_config == NULL) {
1024 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1025 __func__, dlerror());
1026 goto error;
1027 }
1028 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1029 "csd_client_enable_device");
1030 if (csd->enable_device == NULL) {
1031 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1032 __func__, dlerror());
1033 goto error;
1034 }
1035 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1036 "csd_client_start_voice");
1037 if (csd->start_voice == NULL) {
1038 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1039 __func__, dlerror());
1040 goto error;
1041 }
1042 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1043 "csd_client_stop_voice");
1044 if (csd->stop_voice == NULL) {
1045 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1046 __func__, dlerror());
1047 goto error;
1048 }
1049 csd->volume = (volume_t)dlsym(csd->csd_client,
1050 "csd_client_volume");
1051 if (csd->volume == NULL) {
1052 ALOGE("%s: dlsym error %s for csd_client_volume",
1053 __func__, dlerror());
1054 goto error;
1055 }
1056 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1057 "csd_client_mic_mute");
1058 if (csd->mic_mute == NULL) {
1059 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1060 __func__, dlerror());
1061 goto error;
1062 }
1063 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1064 "csd_client_slow_talk");
1065 if (csd->slow_talk == NULL) {
1066 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1067 __func__, dlerror());
1068 goto error;
1069 }
1070 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1071 "csd_client_start_playback");
1072 if (csd->start_playback == NULL) {
1073 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1074 __func__, dlerror());
1075 goto error;
1076 }
1077 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1078 "csd_client_stop_playback");
1079 if (csd->stop_playback == NULL) {
1080 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1081 __func__, dlerror());
1082 goto error;
1083 }
1084 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1085 "csd_client_start_record");
1086 if (csd->start_record == NULL) {
1087 ALOGE("%s: dlsym error %s for csd_client_start_record",
1088 __func__, dlerror());
1089 goto error;
1090 }
1091 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1092 "csd_client_stop_record");
1093 if (csd->stop_record == NULL) {
1094 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1095 __func__, dlerror());
1096 goto error;
1097 }
1098
1099 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1100 "csd_client_get_sample_rate");
1101 if (csd->get_sample_rate == NULL) {
1102 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1103 __func__, dlerror());
1104
1105 goto error;
1106 }
1107
1108 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1109
1110 if (csd->init == NULL) {
1111 ALOGE("%s: dlsym error %s for csd_client_init",
1112 __func__, dlerror());
1113 goto error;
1114 } else {
1115 csd->init(i2s_ext_modem);
1116 }
1117 }
1118 return csd;
1119
1120error:
1121 free(csd);
1122 csd = NULL;
1123 return csd;
1124}
1125
1126void close_csd_client(struct csd_data *csd)
1127{
1128 if (csd != NULL) {
1129 csd->deinit();
1130 dlclose(csd->csd_client);
1131 free(csd);
1132 csd = NULL;
1133 }
1134}
1135
1136static void platform_csd_init(struct platform_data *my_data)
1137{
1138#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001139 int32_t modems, (*count_modems)(void);
1140 const char *name = "libdetectmodem.so";
1141 const char *func = "count_modems";
1142 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001143
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001144 my_data->csd = NULL;
1145
1146 void *lib = dlopen(name, RTLD_NOW);
1147 error = dlerror();
1148 if (!lib) {
1149 ALOGE("%s: could not find %s: %s", __func__, name, error);
1150 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001151 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001152
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001153 count_modems = NULL;
1154 *(void **)(&count_modems) = dlsym(lib, func);
1155 error = dlerror();
1156 if (!count_modems) {
1157 ALOGE("%s: could not find symbol %s in %s: %s",
1158 __func__, func, name, error);
1159 goto done;
1160 }
1161
1162 modems = count_modems();
1163 if (modems < 0) {
1164 ALOGE("%s: count_modems failed\n", __func__);
1165 goto done;
1166 }
1167
Eric Laurent2bafff12016-03-17 12:17:23 -07001168 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001169 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001170 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -07001171
1172done:
1173 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001174#else
1175 my_data->csd = NULL;
1176#endif
1177}
1178
Eric Laurentc6333382015-09-14 12:43:44 -07001179static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001180{
1181 int32_t dev;
1182 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001183 backend_tag_table[dev] = NULL;
1184 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001185 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001186 }
1187
David Linee3fe402017-03-13 10:00:42 -07001188 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1189 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1190 }
1191
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001192 // To overwrite these go to the audio_platform_info.xml file.
1193 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001194 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001195 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1196 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1197 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1198 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1199 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001200 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001201 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1202 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001203
David Linee3fe402017-03-13 10:00:42 -07001204 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001205 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001206 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001207 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001208 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1209 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001210 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1211 strdup("speaker-safe-and-usb-headphones");
juyuchen5351ea62018-05-16 10:54:37 +08001212 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
1213 strdup("speaker-safe-and-bt-sco"),
1214 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
1215 strdup("speaker-safe-and-bt-sco-wb"),
David Linee3fe402017-03-13 10:00:42 -07001216 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001217 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1218 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1219 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1220 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001221 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
1222 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
jasmine cha270b7762018-03-30 15:41:33 +08001223 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001224
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001225 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1226 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1227 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1228 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1229 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1230 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1231 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001232 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001233 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001234 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001235 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1236 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1237 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1238 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1239 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1240 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1241 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1242 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1243 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001244 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
1245 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] =
1246 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001247 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1248 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1249 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1250 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001251 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001252 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1253 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001254 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001255 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001256 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
jasmine cha270b7762018-03-30 15:41:33 +08001257 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001258 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 -07001259 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 -07001260 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1261 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1262 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
jasmine cha52284622018-03-23 17:21:35 +08001263 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
1264 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
1265 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 +08001266 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX"),
1267 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 -07001268 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1269 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1270 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1271 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1272 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1273 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1274 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001275 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001276 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
1277 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
1278 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1279 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
1280 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1281 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
1282 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1283 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001284 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001285 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001286 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001287 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1288 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001289 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
1290 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001291 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1292 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001293 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1294 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1295 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1296 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1297 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001298 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1299 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1300 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1301 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1302 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1303 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1304 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1305 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001306 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1307 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
1308 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001309 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001310 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1311 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001312 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
jasmine cha52284622018-03-23 17:21:35 +08001313 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1314 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1315 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1316 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1317 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SEC_AUX_PCM_TX");
1318 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SEC_AUX_PCM_TX");
1319 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SEC_AUX_PCM_TX");
1320 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SEC_AUX_PCM_TX");
1321 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("AFE_PCM_TX");
1322 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
1323 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
1324 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
1325 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
1326 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
1327 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001328 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001329}
1330
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001331void get_cvd_version(char *cvd_version, struct audio_device *adev)
1332{
1333 struct mixer_ctl *ctl;
1334 int count;
1335 int ret = 0;
1336
1337 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1338 if (!ctl) {
1339 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1340 goto done;
1341 }
1342 mixer_ctl_update(ctl);
1343
1344 count = mixer_ctl_get_num_values(ctl);
1345 if (count > MAX_CVD_VERSION_STRING_SIZE)
1346 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1347
1348 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1349 if (ret != 0) {
1350 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1351 goto done;
1352 }
1353
1354done:
1355 return;
1356}
1357
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001358static int platform_acdb_init(void *platform)
1359{
1360 struct platform_data *my_data = (struct platform_data *)platform;
1361 struct audio_device *adev = my_data->adev;
1362
1363 if (!my_data->acdb_init) {
1364 ALOGE("%s: no acdb_init fn provided", __func__);
1365 return -1;
1366 }
1367
1368 if (my_data->acdb_initialized) {
1369 ALOGW("acdb is already initialized");
1370 return 0;
1371 }
1372
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001373#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001374 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1375 if (!cvd_version)
1376 ALOGE("failed to allocate cvd_version");
1377 else {
1378 get_cvd_version(cvd_version, adev);
1379 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1380 free(cvd_version);
1381 }
1382#elif defined (PLATFORM_MSM8084)
1383 my_data->acdb_init((char *)my_data->snd_card_name);
1384#else
1385 my_data->acdb_init();
1386#endif
1387 my_data->acdb_initialized = true;
1388 return 0;
1389}
1390
David Linee3fe402017-03-13 10:00:42 -07001391static void
1392platform_backend_config_init(struct platform_data *pdata)
1393{
1394 int i;
1395
1396 /* initialize backend config */
1397 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1398 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1399 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1400 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1401
1402 if (i > MAX_RX_CODEC_BACKENDS)
1403 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1404
1405 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1406 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1407 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1408 }
1409
1410 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1411 strdup("SLIM_0_RX Format");
1412 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1413 strdup("SLIM_0_RX SampleRate");
1414
1415 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1416 strdup("SLIM_0_TX Format");
1417 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1418 strdup("SLIM_0_TX SampleRate");
1419
1420 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1421 strdup("USB_AUDIO_TX Format");
1422 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1423 strdup("USB_AUDIO_TX SampleRate");
1424 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1425 strdup("USB_AUDIO_TX Channels");
1426
1427 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1428 strdup("SLIM_6_RX Format");
1429 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1430 strdup("SLIM_6_RX SampleRate");
1431
1432 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1433 strdup("USB_AUDIO_RX Format");
1434 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1435 strdup("USB_AUDIO_RX SampleRate");
1436
1437 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1438 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1439 strdup("USB_AUDIO_RX Channels");
1440}
1441
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001442static int
1443platform_backend_app_type_cfg_init(struct platform_data *pdata,
1444 struct mixer *mixer)
1445{
1446 size_t app_type_cfg[128] = {0};
1447 int length, num_app_types = 0;
1448 struct mixer_ctl *ctl = NULL;
1449
1450 const char *mixer_ctl_name = "App Type Config";
1451 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1452 if (!ctl) {
1453 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1454 return -1;
1455 }
1456
1457 length = 1; // reserve index 0 for number of app types
1458
1459 struct listnode *node;
1460 struct app_type_entry *entry;
1461 list_for_each(node, &app_type_entry_list) {
1462 entry = node_to_item(node, struct app_type_entry, node);
1463 app_type_cfg[length++] = entry->app_type;
1464 app_type_cfg[length++] = entry->max_rate;
1465 app_type_cfg[length++] = entry->bit_width;
1466 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1467 num_app_types += 1;
1468 }
1469
1470 // default for capture
1471 int t;
1472 platform_get_default_app_type_v2(pdata,
1473 PCM_CAPTURE,
1474 &t);
1475 app_type_cfg[length++] = t;
1476 app_type_cfg[length++] = 48000;
1477 app_type_cfg[length++] = 16;
1478 num_app_types += 1;
1479
1480 if (num_app_types) {
1481 app_type_cfg[0] = num_app_types;
1482 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1483 ALOGE("Failed to set app type cfg");
1484 }
1485 }
1486 return 0;
1487}
1488
Xu Han1638fd12018-04-20 12:42:23 -07001489static void configure_flicker_sensor_input(struct mixer *mixer)
1490{
1491 struct mixer_ctl *ctl;
1492 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
1493 int setting1 = 1;
1494 const char* ctl2 = "CDC_IF TX2 MUX";
1495 const char* setting2 = "DEC2";
1496 const char* ctl3 = "SLIM_1_TX Channels";
1497 const char* setting3 = "One";
1498 const char* ctl4 = "ADC MUX2";
1499 const char* setting4 = "AMIC";
1500 const char* ctl5 = "AMIC MUX2";
1501 const char* setting5 = "ADC1";
1502 const char* ctl6 = "DEC2 Volume";
1503 int setting6 = 84;
1504 const char* ctl7 = "MultiMedia2 Mixer SLIM_1_TX";
1505 int setting7 = 1;
1506 const char* ctl8 = "SLIM_1_TX SampleRate";
1507 const char* setting8 = "KHZ_8";
1508
1509 ctl = mixer_get_ctl_by_name(mixer, ctl1);
1510 mixer_ctl_set_value(ctl, 0, setting1);
1511 ctl = mixer_get_ctl_by_name(mixer, ctl2);
1512 mixer_ctl_set_enum_by_string(ctl, setting2);
1513 ctl = mixer_get_ctl_by_name(mixer, ctl3);
1514 mixer_ctl_set_enum_by_string(ctl, setting3);
1515 ctl = mixer_get_ctl_by_name(mixer, ctl4);
1516 mixer_ctl_set_enum_by_string(ctl, setting4);
1517 ctl = mixer_get_ctl_by_name(mixer, ctl5);
1518 mixer_ctl_set_enum_by_string(ctl, setting5);
1519 ctl = mixer_get_ctl_by_name(mixer, ctl6);
1520 mixer_ctl_set_value(ctl, 0, setting6);
1521 ctl = mixer_get_ctl_by_name(mixer, ctl7);
1522 mixer_ctl_set_value(ctl, 0, setting7);
1523 ctl = mixer_get_ctl_by_name(mixer, ctl8);
1524 mixer_ctl_set_enum_by_string(ctl, setting8);
1525}
1526
Eric Laurentb23d5282013-05-14 15:27:20 -07001527void *platform_init(struct audio_device *adev)
1528{
1529 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001530 struct platform_data *my_data = NULL;
1531 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1532 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001533 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001534 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001535 char *snd_internal_name = NULL;
1536 char *tmp = NULL;
1537 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001538 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1539 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001540 my_data = calloc(1, sizeof(struct platform_data));
1541
1542 my_data->adev = adev;
1543
keunhui.park2f7306a2015-07-16 16:48:06 +09001544 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001545 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001546
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001547 set_platform_defaults(my_data);
1548
vivek mehta0fb11312017-05-15 19:35:32 -07001549 // audio_extn_utils_get_snd_card_num does
1550 // - open mixer and get snd card name
1551 // - parse platform info xml file and check for valid snd card name
1552 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001553
vivek mehta0fb11312017-05-15 19:35:32 -07001554 snd_card_num = audio_extn_utils_get_snd_card_num();
1555 if (-1 == snd_card_num) {
1556 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1557 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001558 }
1559
vivek mehta0fb11312017-05-15 19:35:32 -07001560 adev->mixer = mixer_open(snd_card_num);
1561 snd_card_name = mixer_get_name(adev->mixer);
1562 my_data->hw_info = hw_info_init(snd_card_name);
1563
1564 audio_extn_set_snd_card_split(snd_card_name);
1565 snd_split_handle = audio_extn_get_snd_card_split();
1566
1567 /* Get the codec internal name from the sound card and/or form factor
1568 * name and form the mixer paths and platfor info file name dynamically.
1569 * This is generic way of picking any codec and forma factor name based
1570 * mixer and platform info files in future with no code change.
1571
1572 * current code extends and looks for any of the exteneded mixer path and
1573 * platform info file present based on codec and form factor.
1574
1575 * order of picking appropriate file is
1576 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1577 * <ii> mixer_paths_<codec_name>.xml, if file not present
1578 * <iii> mixer_paths.xml
1579
1580 * same order is followed for audio_platform_info.xml as well
1581 */
1582
1583 // need to carryforward old file name
1584 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1585 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1586 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1587 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1588 } else {
1589
1590 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1591 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1592 snd_split_handle->form_factor);
1593 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1594 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1595 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1596 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1597
1598 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1599 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1600 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1601 audio_extn_utils_resolve_config_file(mixer_xml_file);
1602 }
1603 }
1604 }
1605
1606 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1607
jiabin8962a4d2018-03-19 18:21:24 -07001608 my_data->declared_mic_count = 0;
vivek mehta0fb11312017-05-15 19:35:32 -07001609 /* Initialize platform specific ids and/or backends*/
1610 platform_info_init(platform_info_file, my_data);
1611
1612 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1613 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1614
1615 if (!adev->audio_route) {
1616 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1617 mixer_close(adev->mixer);
1618 adev->mixer = NULL;
1619 hw_info_deinit(my_data->hw_info);
1620 my_data->hw_info = NULL;
1621 goto init_failed;
1622 }
1623 adev->snd_card = snd_card_num;
1624 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1625
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001626 //set max volume step for voice call
1627 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1628 my_data->max_vol_index = atoi(value);
1629
vivek mehta65ad12d2015-08-13 18:32:48 -07001630 property_get("persist.audio.dualmic.config",value,"");
1631 if (!strcmp("endfire", value)) {
1632 dual_mic_config = true;
1633 }
1634
John Muir9e59a962018-01-10 13:30:00 -08001635 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001636
Eric Laurentb23d5282013-05-14 15:27:20 -07001637 my_data->fluence_in_spkr_mode = false;
1638 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001639 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001640 my_data->fluence_in_voice_rec = false;
1641
vivek mehta65ad12d2015-08-13 18:32:48 -07001642 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001643 if (!strcmp("fluencepro", value)) {
1644 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001645 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001646 my_data->fluence_type = FLUENCE_ENABLE;
1647 } else if (!strcmp("none", value)) {
1648 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001649 }
1650
Prashant Malanic92c5962015-08-11 15:10:18 -07001651 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001652 property_get("persist.audio.fluence.voicecall",value,"");
1653 if (!strcmp("true", value)) {
1654 my_data->fluence_in_voice_call = true;
1655 }
1656
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001657 property_get("persist.audio.fluence.voicecomm",value,"");
1658 if (!strcmp("true", value)) {
1659 my_data->fluence_in_voice_comm = true;
1660 }
1661
Eric Laurentb23d5282013-05-14 15:27:20 -07001662 property_get("persist.audio.fluence.voicerec",value,"");
1663 if (!strcmp("true", value)) {
1664 my_data->fluence_in_voice_rec = true;
1665 }
1666
1667 property_get("persist.audio.fluence.speaker",value,"");
1668 if (!strcmp("true", value)) {
1669 my_data->fluence_in_spkr_mode = true;
1670 }
1671 }
1672
Prashant Malanic92c5962015-08-11 15:10:18 -07001673 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1674 switch (my_data->max_mic_count) {
1675 case 4:
1676 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1677 case 3:
1678 my_data->source_mic_type |= SOURCE_THREE_MIC;
1679 case 2:
1680 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1681 case 1:
1682 my_data->source_mic_type |= SOURCE_MONO_MIC;
1683 break;
1684 default:
1685 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1686 __func__, my_data->max_mic_count);
1687 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1688 break;
1689 }
1690
1691 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1692 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1693 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1694 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1695 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1696
Eric Laurentb23d5282013-05-14 15:27:20 -07001697 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1698 if (my_data->acdb_handle == NULL) {
1699 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1700 } else {
1701 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1702 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1703 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001704 if (!my_data->acdb_deallocate)
1705 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1706 __func__, LIB_ACDB_LOADER);
1707
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001708 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1709 "acdb_loader_send_audio_cal_v3");
1710 if (!my_data->acdb_send_audio_cal_v3)
1711 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1712 __func__, LIB_ACDB_LOADER);
1713
Eric Laurentb23d5282013-05-14 15:27:20 -07001714 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1715 "acdb_loader_send_audio_cal");
1716 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001717 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001718 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001719
Eric Laurentb23d5282013-05-14 15:27:20 -07001720 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1721 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001722 if (!my_data->acdb_send_voice_cal)
1723 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1724 __func__, LIB_ACDB_LOADER);
1725
1726 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1727 "acdb_loader_reload_vocvoltable");
1728 if (!my_data->acdb_reload_vocvoltable)
1729 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1730 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001731
1732 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1733 "acdb_loader_send_gain_dep_cal");
1734 if (!my_data->acdb_send_gain_dep_cal)
1735 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1736 __func__, LIB_ACDB_LOADER);
1737
Xu Han1638fd12018-04-20 12:42:23 -07001738#if defined (FLICKER_SENSOR_INPUT)
1739 configure_flicker_sensor_input(adev->mixer);
1740#endif
1741
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001742#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
vivek mehta0fb11312017-05-15 19:35:32 -07001743 acdb_init_v2_cvd_t acdb_init_local;
1744 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001745 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001746 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001747 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1748 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001749
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001750#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001751 acdb_init_v2_t acdb_init_local;
1752 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001753 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001754 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001755 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1756 dlerror());
1757
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001758#else
vivek mehta0fb11312017-05-15 19:35:32 -07001759 acdb_init_t acdb_init_local;
1760 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001761 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001762 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001763 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1764 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001765#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001766 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001767
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001768 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1769 dlsym(my_data->acdb_handle,
1770 "acdb_loader_send_common_custom_topology");
1771
1772 if (!my_data->acdb_send_custom_top)
1773 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1774 __func__, LIB_ACDB_LOADER);
1775
jasmine chac89321b2018-04-10 21:37:01 +08001776 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1777 "acdb_loader_set_audio_cal_v2");
1778 if (!my_data->acdb_set_audio_cal)
1779 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1780 __func__, LIB_ACDB_LOADER);
1781
vivek mehta0fb11312017-05-15 19:35:32 -07001782 int result = acdb_init(adev->snd_card);
1783 if (!result) {
1784 my_data->acdb_initialized = true;
1785 ALOGD("ACDB initialized");
1786 } else {
1787 my_data->acdb_initialized = false;
1788 ALOGD("ACDB initialization failed");
1789 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001790 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001791
David Linee3fe402017-03-13 10:00:42 -07001792 /* init usb */
1793 audio_extn_usb_init(adev);
1794
Aniket Kumar Lata26483012018-01-31 20:21:42 -08001795 /* init a2dp */
1796 audio_extn_a2dp_init(adev);
1797
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001798 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001799
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001800 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1801
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001802 /* load csd client */
1803 platform_csd_init(my_data);
1804
David Linee3fe402017-03-13 10:00:42 -07001805 platform_backend_config_init(my_data);
1806
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001807 init_be_dai_name_table(adev);
1808
1809 if (platform_supports_app_type_cfg())
1810 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1811
Eric Laurentb23d5282013-05-14 15:27:20 -07001812 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001813
1814init_failed:
1815 if (my_data)
1816 free(my_data);
1817 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001818}
1819
1820void platform_deinit(void *platform)
1821{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001822 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001823 struct operator_info *info_item;
1824 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001825 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001826 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001827
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001828 struct platform_data *my_data = (struct platform_data *)platform;
1829 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001830
vivek mehtade4849c2016-03-03 17:23:38 -08001831 hw_info_deinit(my_data->hw_info);
1832
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001833 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1834 if (backend_tag_table[dev])
1835 free(backend_tag_table[dev]);
1836 if (hw_interface_table[dev])
1837 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001838 if (operator_specific_device_table[dev]) {
1839 while (!list_empty(operator_specific_device_table[dev])) {
1840 node = list_head(operator_specific_device_table[dev]);
1841 list_remove(node);
1842 device_item = node_to_item(node, struct operator_specific_device, list);
1843 free(device_item->operator);
1844 free(device_item->mixer_path);
1845 free(device_item);
1846 }
1847 free(operator_specific_device_table[dev]);
1848 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001849 }
1850
1851 if (my_data->snd_card_name)
1852 free(my_data->snd_card_name);
1853
keunhui.park2f7306a2015-07-16 16:48:06 +09001854 while (!list_empty(&operator_info_list)) {
1855 node = list_head(&operator_info_list);
1856 list_remove(node);
1857 info_item = node_to_item(node, struct operator_info, list);
1858 free(info_item->name);
1859 free(info_item->mccmnc);
1860 free(info_item);
1861 }
1862
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001863 while (!list_empty(&app_type_entry_list)) {
1864 node = list_head(&app_type_entry_list);
1865 list_remove(node);
1866 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001867 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001868 free(ap);
1869 }
1870
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001871 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001872 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001873
1874 /* deinit usb */
1875 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001876}
1877
1878const char *platform_get_snd_device_name(snd_device_t snd_device)
1879{
keunhui.park2f7306a2015-07-16 16:48:06 +09001880 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1881 if (operator_specific_device_table[snd_device] != NULL) {
1882 return get_operator_specific_device_mixer_path(snd_device);
1883 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001884 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001885 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001886 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001887}
1888
vivek mehtade4849c2016-03-03 17:23:38 -08001889int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1890 char *device_name)
1891{
1892 struct platform_data *my_data = (struct platform_data *)platform;
1893
David Benjamin1565f992016-09-21 12:10:34 -04001894 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001895 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001896 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1897 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001898 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1899 if (operator_specific_device_table[snd_device] != NULL) {
1900 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1901 DEVICE_NAME_MAX_SIZE);
1902 } else {
1903 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1904 }
1905 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1906 } else {
1907 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1908 }
1909
1910 return 0;
1911}
1912
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001913void platform_add_backend_name(void *platform, char *mixer_path,
1914 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001915{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001916 struct platform_data *my_data = (struct platform_data *)platform;
1917
Haynes Mathew George98c95622014-06-20 19:14:25 -07001918 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1919 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1920 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001921 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001922
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001923 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001924
1925 if (suffix != NULL) {
1926 strcat(mixer_path, " ");
1927 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001928 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001929}
1930
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001931bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1932{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001933 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1934 platform_get_snd_device_name(snd_device1),
1935 platform_get_snd_device_name(snd_device2));
1936
1937 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1938 ALOGE("%s: Invalid snd_device = %s", __func__,
1939 platform_get_snd_device_name(snd_device1));
1940 return false;
1941 }
1942 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1943 ALOGE("%s: Invalid snd_device = %s", __func__,
1944 platform_get_snd_device_name(snd_device2));
1945 return false;
1946 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001947
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001948 const char * be_itf1 = hw_interface_table[snd_device1];
1949 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001950 /*
1951 hw_interface_table has overrides for a snd_device.
1952 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1953 */
1954 if (be_itf1 == NULL) {
1955 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001956 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001957 if (be_itf2 == NULL) {
1958 be_itf2 = DEFAULT_RX_BACKEND;
1959 }
1960 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1961 /*
1962 this takes care of finding a device within a combo device pair as well
1963 */
1964 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001965}
1966
Eric Laurentb23d5282013-05-14 15:27:20 -07001967int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1968{
1969 int device_id;
1970 if (device_type == PCM_PLAYBACK)
1971 device_id = pcm_device_table[usecase][0];
1972 else
1973 device_id = pcm_device_table[usecase][1];
1974 return device_id;
1975}
1976
Haynes Mathew George98c95622014-06-20 19:14:25 -07001977static int find_index(const struct name_to_index * table, int32_t len,
1978 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001979{
1980 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001981 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001982
Haynes Mathew George98c95622014-06-20 19:14:25 -07001983 if (table == NULL) {
1984 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001985 ret = -ENODEV;
1986 goto done;
1987 }
1988
Haynes Mathew George98c95622014-06-20 19:14:25 -07001989 if (name == NULL) {
1990 ALOGE("null key");
1991 ret = -ENODEV;
1992 goto done;
1993 }
1994
1995 for (i=0; i < len; i++) {
1996 if (!strcmp(table[i].name, name)) {
1997 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001998 goto done;
1999 }
2000 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002001 ALOGE("%s: Could not find index for name = %s",
2002 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002003 ret = -ENODEV;
2004done:
2005 return ret;
2006}
2007
Haynes Mathew George98c95622014-06-20 19:14:25 -07002008int platform_get_snd_device_index(char *device_name)
2009{
2010 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2011}
2012
2013int platform_get_usecase_index(const char *usecase_name)
2014{
2015 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2016}
2017
keunhui.park2f7306a2015-07-16 16:48:06 +09002018void platform_add_operator_specific_device(snd_device_t snd_device,
2019 const char *operator,
2020 const char *mixer_path,
2021 unsigned int acdb_id)
2022{
2023 struct operator_specific_device *device;
2024
2025 if (operator_specific_device_table[snd_device] == NULL) {
2026 operator_specific_device_table[snd_device] =
2027 (struct listnode *)calloc(1, sizeof(struct listnode));
2028 list_init(operator_specific_device_table[snd_device]);
2029 }
2030
2031 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
2032
2033 device->operator = strdup(operator);
2034 device->mixer_path = strdup(mixer_path);
2035 device->acdb_id = acdb_id;
2036
2037 list_add_tail(operator_specific_device_table[snd_device], &device->list);
2038
Eric Laurent2bafff12016-03-17 12:17:23 -07002039 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09002040 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
2041
2042}
2043
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002044int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2045{
2046 int ret = 0;
2047
2048 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2049 ALOGE("%s: Invalid snd_device = %d",
2050 __func__, snd_device);
2051 ret = -EINVAL;
2052 goto done;
2053 }
2054
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002055 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2056 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07002057 acdb_device_table[snd_device] = acdb_id;
2058done:
2059 return ret;
2060}
2061
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002062int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2063{
2064 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2065 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2066 return -EINVAL;
2067 }
keunhui.park2f7306a2015-07-16 16:48:06 +09002068
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002069 /*
2070 * If speaker protection is enabled, function returns supported
2071 * sound device for speaker. Else same sound device is returned.
2072 */
2073 snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
2074
keunhui.park2f7306a2015-07-16 16:48:06 +09002075 if (operator_specific_device_table[snd_device] != NULL)
2076 return get_operator_specific_device_acdb_id(snd_device);
2077 else
2078 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002079}
2080
David Linee3fe402017-03-13 10:00:42 -07002081static int platform_get_backend_index(snd_device_t snd_device)
2082{
2083 int32_t port = DEFAULT_CODEC_BACKEND;
2084
2085 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
2086 if (backend_tag_table[snd_device] != NULL) {
2087 if (strncmp(backend_tag_table[snd_device], "headphones",
2088 sizeof("headphones")) == 0)
2089 port = HEADPHONE_BACKEND;
2090 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2091 port = HDMI_RX_BACKEND;
2092 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
2093 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
2094 port = USB_AUDIO_RX_BACKEND;
2095 }
2096 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
2097 port = DEFAULT_CODEC_TX_BACKEND;
2098 if (backend_tag_table[snd_device] != NULL) {
2099 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
2100 port = USB_AUDIO_TX_BACKEND;
2101 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
2102 port = BT_SCO_TX_BACKEND;
2103 }
2104 } else {
2105 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
2106 }
2107
2108 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
2109
2110 return port;
2111}
2112
Eric Laurentb23d5282013-05-14 15:27:20 -07002113int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
2114{
2115 struct platform_data *my_data = (struct platform_data *)platform;
2116 int acdb_dev_id, acdb_dev_type;
2117
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002118 if (platform_supports_app_type_cfg()) // use v2 instead
2119 return -ENOSYS;
2120
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002121 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002122 if (acdb_dev_id < 0) {
2123 ALOGE("%s: Could not find acdb id for device(%d)",
2124 __func__, snd_device);
2125 return -EINVAL;
2126 }
2127 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08002128 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07002129 __func__, snd_device, acdb_dev_id);
2130 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
2131 snd_device < SND_DEVICE_OUT_END)
2132 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2133 else
2134 acdb_dev_type = ACDB_DEV_TYPE_IN;
2135 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
2136 }
2137 return 0;
2138}
2139
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002140int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
2141 int app_type, int sample_rate)
2142{
2143 struct platform_data *my_data = (struct platform_data *)platform;
2144 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07002145 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002146 int new_snd_device[SND_DEVICE_OUT_END] = {0};
2147 int i, num_devices = 1;
2148
2149 if (!platform_supports_app_type_cfg()) // use v1 instead
2150 return -ENOSYS;
2151
vivek mehta7e573672018-03-13 17:41:41 -07002152 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002153 snd_device = usecase->in_snd_device;
2154
2155 // skipped over get_spkr_prot_device
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002156 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002157 if (acdb_dev_id < 0) {
2158 ALOGE("%s: Could not find acdb id for device(%d)",
2159 __func__, snd_device);
2160 return -EINVAL;
2161 }
2162
2163 if (platform_can_split_snd_device(snd_device,
2164 &num_devices, new_snd_device) < 0) {
2165 new_snd_device[0] = snd_device;
2166 }
2167
2168 for (i = 0; i < num_devices; i++) {
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002169 acdb_dev_id = platform_get_snd_device_acdb_id(new_snd_device[i]);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08002170 if (acdb_dev_id < 0) {
2171 ALOGE("%s: Could not find acdb id for device(%d)",
2172 __func__, new_snd_device[i]);
2173 return -EINVAL;
2174 }
2175 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2176 __func__, new_snd_device[i], acdb_dev_id);
2177 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2178 new_snd_device[i] < SND_DEVICE_OUT_END)
2179 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2180 else
2181 acdb_dev_type = ACDB_DEV_TYPE_IN;
2182
2183 if (my_data->acdb_send_audio_cal_v3) {
2184 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
2185 app_type, sample_rate, i);
2186 } else if (my_data->acdb_send_audio_cal) {
2187 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
2188 }
2189 }
2190
2191 return 0;
2192}
2193
2194
Eric Laurentb23d5282013-05-14 15:27:20 -07002195int platform_switch_voice_call_device_pre(void *platform)
2196{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002197 struct platform_data *my_data = (struct platform_data *)platform;
2198 int ret = 0;
2199
2200 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002201 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002202 /* This must be called before disabling mixer controls on APQ side */
2203 ret = my_data->csd->disable_device();
2204 if (ret < 0) {
2205 ALOGE("%s: csd_client_disable_device, failed, error %d",
2206 __func__, ret);
2207 }
2208 }
2209 return ret;
2210}
2211
2212int platform_switch_voice_call_enable_device_config(void *platform,
2213 snd_device_t out_snd_device,
2214 snd_device_t in_snd_device)
2215{
2216 struct platform_data *my_data = (struct platform_data *)platform;
2217 int acdb_rx_id, acdb_tx_id;
2218 int ret = 0;
2219
2220 if (my_data->csd == NULL)
2221 return ret;
2222
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002223 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002224 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002225
2226 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2227 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2228 if (ret < 0) {
2229 ALOGE("%s: csd_enable_device_config, failed, error %d",
2230 __func__, ret);
2231 }
2232 } else {
2233 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2234 acdb_rx_id, acdb_tx_id);
2235 }
2236
2237 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002238}
2239
2240int platform_switch_voice_call_device_post(void *platform,
2241 snd_device_t out_snd_device,
2242 snd_device_t in_snd_device)
2243{
2244 struct platform_data *my_data = (struct platform_data *)platform;
2245 int acdb_rx_id, acdb_tx_id;
2246
2247 if (my_data->acdb_send_voice_cal == NULL) {
2248 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2249 } else {
keunhui.park2f7306a2015-07-16 16:48:06 +09002250 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
2251 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002252
2253 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2254 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2255 else
2256 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2257 acdb_rx_id, acdb_tx_id);
2258 }
2259
2260 return 0;
2261}
2262
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002263int platform_switch_voice_call_usecase_route_post(void *platform,
2264 snd_device_t out_snd_device,
2265 snd_device_t in_snd_device)
2266{
2267 struct platform_data *my_data = (struct platform_data *)platform;
2268 int acdb_rx_id, acdb_tx_id;
2269 int ret = 0;
2270
2271 if (my_data->csd == NULL)
2272 return ret;
2273
Aniket Kumar Lata9d6679a2018-04-11 18:13:23 -07002274 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
keunhui.park2f7306a2015-07-16 16:48:06 +09002275 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002276
2277 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2278 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2279 my_data->adev->acdb_settings);
2280 if (ret < 0) {
2281 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2282 }
2283 } else {
2284 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2285 acdb_rx_id, acdb_tx_id);
2286 }
2287
2288 return ret;
2289}
2290
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002291int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002292{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002293 struct platform_data *my_data = (struct platform_data *)platform;
2294 int ret = 0;
2295
2296 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002297 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002298 if (ret < 0) {
2299 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2300 }
2301 }
2302 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002303}
2304
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002305int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002306{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002307 struct platform_data *my_data = (struct platform_data *)platform;
2308 int ret = 0;
2309
2310 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002311 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002312 if (ret < 0) {
2313 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2314 }
2315 }
2316 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002317}
2318
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002319int platform_get_sample_rate(void *platform, uint32_t *rate)
2320{
2321 struct platform_data *my_data = (struct platform_data *)platform;
2322 int ret = 0;
2323
2324 if (my_data->csd != NULL) {
2325 ret = my_data->csd->get_sample_rate(rate);
2326 if (ret < 0) {
2327 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2328 }
2329 }
2330 return ret;
2331}
2332
vivek mehtab6506412015-08-07 16:55:17 -07002333void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2334 snd_device_t snd_device,
2335 bool enable)
2336{
2337 const char* name;
2338 switch (snd_device) {
2339 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2340 if (enable)
2341 name = "spkr-gain-in-headphone-combo";
2342 else
2343 name = "speaker-gain-default";
2344 break;
2345 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2346 if (enable)
2347 name = "spkr-gain-in-line-combo";
2348 else
2349 name = "speaker-gain-default";
2350 break;
2351 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2352 if (enable)
2353 name = "spkr-safe-gain-in-headphone-combo";
2354 else
2355 name = "speaker-safe-gain-default";
2356 break;
2357 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2358 if (enable)
2359 name = "spkr-safe-gain-in-line-combo";
2360 else
2361 name = "speaker-safe-gain-default";
2362 break;
2363 default:
2364 return;
2365 }
2366
2367 audio_route_apply_and_update_path(adev->audio_route, name);
2368}
2369
Eric Laurentb23d5282013-05-14 15:27:20 -07002370int platform_set_voice_volume(void *platform, int volume)
2371{
2372 struct platform_data *my_data = (struct platform_data *)platform;
2373 struct audio_device *adev = my_data->adev;
2374 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002375 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002376 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002377 int vol_index = 0, ret = 0;
2378 uint32_t set_values[ ] = {0,
2379 ALL_SESSION_VSID,
2380 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002381
2382 // Voice volume levels are mapped to adsp volume levels as follows.
2383 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2384 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002385 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002386 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002387
2388 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2389 if (!ctl) {
2390 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2391 __func__, mixer_ctl_name);
2392 return -EINVAL;
2393 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002394 ALOGV("Setting voice volume index: %d", set_values[0]);
2395 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2396
Nadav Barc46d0fa2017-12-24 14:50:37 +02002397 // Send mute command in case volume index is max since indexes are inverted
2398 // for mixer controls.
2399 if (vol_index == my_data->max_vol_index) {
2400 set_values[0] = 1;
2401 }
2402 else {
2403 set_values[0] = 0;
2404 }
2405
2406 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2407 if (!ctl) {
2408 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2409 __func__, mute_mixer_ctl_name);
2410 return -EINVAL;
2411 }
2412 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2413 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2414
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002415 if (my_data->csd != NULL) {
2416 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2417 DEFAULT_VOLUME_RAMP_DURATION_MS);
2418 if (ret < 0) {
2419 ALOGE("%s: csd_volume error %d", __func__, ret);
2420 }
2421 }
2422 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002423}
2424
2425int platform_set_mic_mute(void *platform, bool state)
2426{
2427 struct platform_data *my_data = (struct platform_data *)platform;
2428 struct audio_device *adev = my_data->adev;
2429 struct mixer_ctl *ctl;
2430 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002431 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002432 uint32_t set_values[ ] = {0,
2433 ALL_SESSION_VSID,
2434 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002435
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002436 if (adev->mode != AUDIO_MODE_IN_CALL &&
2437 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002438 return 0;
2439
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002440 if (adev->enable_hfp)
2441 mixer_ctl_name = "HFP Tx Mute";
2442
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002443 set_values[0] = state;
2444 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2445 if (!ctl) {
2446 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2447 __func__, mixer_ctl_name);
2448 return -EINVAL;
2449 }
2450 ALOGV("Setting voice mute state: %d", state);
2451 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2452
2453 if (my_data->csd != NULL) {
2454 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2455 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002456 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002457 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002458 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002459 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002460 return ret;
2461}
Eric Laurentb23d5282013-05-14 15:27:20 -07002462
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002463int platform_set_device_mute(void *platform, bool state, char *dir)
2464{
2465 struct platform_data *my_data = (struct platform_data *)platform;
2466 struct audio_device *adev = my_data->adev;
2467 struct mixer_ctl *ctl;
2468 char *mixer_ctl_name = NULL;
2469 int ret = 0;
2470 uint32_t set_values[ ] = {0,
2471 ALL_SESSION_VSID,
2472 0};
2473 if(dir == NULL) {
2474 ALOGE("%s: Invalid direction:%s", __func__, dir);
2475 return -EINVAL;
2476 }
2477
2478 if (!strncmp("rx", dir, sizeof("rx"))) {
2479 mixer_ctl_name = "Voice Rx Device Mute";
2480 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2481 mixer_ctl_name = "Voice Tx Device Mute";
2482 } else {
2483 return -EINVAL;
2484 }
2485
2486 set_values[0] = state;
2487 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2488 if (!ctl) {
2489 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2490 __func__, mixer_ctl_name);
2491 return -EINVAL;
2492 }
2493
2494 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2495 __func__,state, mixer_ctl_name);
2496 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2497
2498 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002499}
2500
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002501int platform_can_split_snd_device(snd_device_t snd_device,
2502 int *num_devices,
2503 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002504{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002505 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002506 if (NULL == num_devices || NULL == new_snd_devices) {
2507 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002508 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002509 }
2510
2511 /*
2512 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002513 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002514 */
2515 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2516 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2517 *num_devices = 2;
2518 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2519 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002520 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002521 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2522 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2523 *num_devices = 2;
2524 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2525 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002526 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002527 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2528 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2529 *num_devices = 2;
2530 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2531 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002532 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002533 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2534 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2535 *num_devices = 2;
2536 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2537 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002538 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002539 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2540 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2541 SND_DEVICE_OUT_BT_SCO)) {
2542 *num_devices = 2;
2543 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2544 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2545 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002546 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
2547 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2548 SND_DEVICE_OUT_BT_SCO)) {
2549 *num_devices = 2;
2550 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2551 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2552 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002553 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2554 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2555 SND_DEVICE_OUT_BT_SCO_WB)) {
2556 *num_devices = 2;
2557 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2558 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2559 ret = 0;
juyuchen5351ea62018-05-16 10:54:37 +08002560 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
2561 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
2562 SND_DEVICE_OUT_BT_SCO_WB)) {
2563 *num_devices = 2;
2564 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2565 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2566 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002567 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2568 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2569 *num_devices = 2;
2570 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2571 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2572 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002573 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2574 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2575 *num_devices = 2;
2576 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2577 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2578 ret = 0;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002579 } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device &&
2580 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2581 SND_DEVICE_OUT_BT_A2DP)) {
2582 *num_devices = 2;
2583 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2584 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
2585 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002586 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002587
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002588 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002589}
2590
Eric Laurentb23d5282013-05-14 15:27:20 -07002591snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2592{
2593 struct platform_data *my_data = (struct platform_data *)platform;
2594 struct audio_device *adev = my_data->adev;
2595 audio_mode_t mode = adev->mode;
2596 snd_device_t snd_device = SND_DEVICE_NONE;
2597
2598 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2599 if (devices == AUDIO_DEVICE_NONE ||
2600 devices & AUDIO_DEVICE_BIT_IN) {
2601 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2602 goto exit;
2603 }
2604
Eric Laurent1b491552015-09-15 17:52:41 -07002605 if (popcount(devices) == 2) {
2606 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2607 AUDIO_DEVICE_OUT_SPEAKER) ||
2608 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2609 AUDIO_DEVICE_OUT_SPEAKER)) {
2610 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2611 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2612 AUDIO_DEVICE_OUT_SPEAKER)) {
2613 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2614 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2615 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2616 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2617 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2618 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2619 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2620 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2621 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2622 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2623 AUDIO_DEVICE_OUT_SPEAKER)) {
2624 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002625 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2626 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2627 snd_device = adev->bt_wb_speech_enabled ?
2628 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2629 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
juyuchen5351ea62018-05-16 10:54:37 +08002630 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2631 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2632 snd_device = adev->bt_wb_speech_enabled ?
2633 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
2634 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002635 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2636 AUDIO_DEVICE_OUT_SPEAKER)) ||
2637 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2638 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002639 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002640 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2641 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2642 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2643 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002644 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002645 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
2646 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
2647 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Eric Laurent1b491552015-09-15 17:52:41 -07002648 } else {
2649 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2650 goto exit;
2651 }
2652 if (snd_device != SND_DEVICE_NONE) {
2653 goto exit;
2654 }
2655 }
2656
2657 if (popcount(devices) != 1) {
2658 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2659 goto exit;
2660 }
2661
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302662 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002663 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002664 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2665 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002666 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002667 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002668 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002669 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002670 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002671 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002672 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002673 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002674 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002675 else {
2676 if (devices & AUDIO_DEVICE_OUT_LINE)
2677 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2678 else
2679 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2680 }
Eric Laurent99dab492017-06-17 15:19:08 -07002681 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002682 if (voice_is_in_call(adev)) {
2683 switch (adev->voice.tty_mode) {
2684 case TTY_MODE_FULL:
2685 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2686 break;
2687 case TTY_MODE_VCO:
2688 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2689 break;
2690 case TTY_MODE_HCO:
2691 // since Hearing will be on handset\speaker, use existing device
2692 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2693 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002694 case TTY_MODE_OFF:
2695 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002696 default:
2697 ALOGE("%s: Invalid TTY mode (%#x)",
2698 __func__, adev->voice.tty_mode);
2699 }
2700 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002701 if (snd_device == SND_DEVICE_NONE) {
2702 snd_device = audio_extn_usb_is_capture_supported() ?
2703 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2704 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2705 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002706 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002707 if (adev->bt_wb_speech_enabled) {
2708 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2709 } else {
2710 snd_device = SND_DEVICE_OUT_BT_SCO;
2711 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002712 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2713 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002714 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002715 if (!adev->enable_hfp) {
2716 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2717 } else {
2718 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2719 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002720 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002721 if(adev->voice.hac)
2722 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2723 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002724 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2725 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002726 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002727 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2728 snd_device = SND_DEVICE_OUT_VOICE_TX;
2729
Eric Laurentb23d5282013-05-14 15:27:20 -07002730 if (snd_device != SND_DEVICE_NONE) {
2731 goto exit;
2732 }
2733 }
2734
Eric Laurentb23d5282013-05-14 15:27:20 -07002735 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2736 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2737 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002738 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2739 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002740 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2741 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002742 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
andysu5b30b062018-04-20 16:34:06 +08002743 /*
2744 * Perform device switch only if acdb tuning is different between SPEAKER & SPEAKER_REVERSE,
2745 * Or there will be a small pause while performing device switch.
2746 */
2747 if (my_data->speaker_lr_swap &&
2748 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2749 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]))
Eric Laurentb23d5282013-05-14 15:27:20 -07002750 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2751 else
2752 snd_device = SND_DEVICE_OUT_SPEAKER;
2753 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002754 if (adev->bt_wb_speech_enabled) {
2755 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2756 } else {
2757 snd_device = SND_DEVICE_OUT_BT_SCO;
2758 }
Aniket Kumar Lata26483012018-01-31 20:21:42 -08002759 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
2760 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07002761 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2762 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002763 } else if (audio_is_usb_out_device(devices)) {
jasmine cha270b7762018-03-30 15:41:33 +08002764 if (audio_extn_ma_supported_usb())
2765 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
2766 else if (audio_extn_usb_is_capture_supported())
David Linee3fe402017-03-13 10:00:42 -07002767 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2768 else
2769 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2770 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002771 /*HAC support for voice-ish audio (eg visual voicemail)*/
2772 if(adev->voice.hac)
2773 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2774 else
2775 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002776 } else {
2777 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2778 }
2779exit:
2780 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2781 return snd_device;
2782}
2783
2784snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2785{
2786 struct platform_data *my_data = (struct platform_data *)platform;
2787 struct audio_device *adev = my_data->adev;
2788 audio_source_t source = (adev->active_input == NULL) ?
2789 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2790
2791 audio_mode_t mode = adev->mode;
2792 audio_devices_t in_device = ((adev->active_input == NULL) ?
2793 AUDIO_DEVICE_NONE : adev->active_input->device)
2794 & ~AUDIO_DEVICE_BIT_IN;
2795 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2796 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2797 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002798 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002799
Prashant Malanic92c5962015-08-11 15:10:18 -07002800 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2801 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002802 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2803 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002804 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002805 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002806 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2807 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002808 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002809 case TTY_MODE_FULL:
2810 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2811 break;
2812 case TTY_MODE_VCO:
2813 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2814 break;
2815 case TTY_MODE_HCO:
2816 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2817 break;
2818 default:
2819 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2820 }
2821 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002822 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002823 switch (adev->voice.tty_mode) {
2824 case TTY_MODE_FULL:
2825 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2826 break;
2827 case TTY_MODE_VCO:
2828 // since voice will be captured from handset mic, use existing device
2829 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2830 break;
2831 case TTY_MODE_HCO:
2832 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2833 break;
2834 default:
2835 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002836 }
2837 goto exit;
2838 }
2839 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002840 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002841 if (my_data->fluence_in_voice_call == false) {
2842 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2843 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002844 if (is_operator_tmus())
2845 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002846 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002847 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002848 }
2849 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2850 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2851 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002852 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002853 if (adev->bluetooth_nrec)
2854 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2855 else
2856 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002857 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002858 if (adev->bluetooth_nrec)
2859 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2860 else
2861 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002862 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002863 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002864 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2865 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2866 out_device & AUDIO_DEVICE_OUT_LINE) {
2867 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2868 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2869 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2870 } else {
2871 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2872 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002873 }
vivek mehtafe121d52015-08-10 23:39:23 -07002874
2875 //select default
2876 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002877 if (!adev->enable_hfp) {
2878 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2879 } else {
2880 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2881 platform_set_echo_reference(adev, true, out_device);
2882 }
vivek mehtafe121d52015-08-10 23:39:23 -07002883 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002884 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002885 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002886 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002887 if (audio_extn_usb_is_capture_supported()) {
2888 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2889 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2890 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2891 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2892 } else {
2893 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2894 }
2895 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002896 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002897 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2898 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2899 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2900 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2901 }
2902 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2903 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002904 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2905 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2906 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002907 if (adev->active_input->enable_aec)
2908 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2909 else
2910 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002911 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2912 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002913 if (adev->active_input->enable_aec)
2914 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2915 else
2916 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002917 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2918 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2919 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002920 if (adev->active_input->enable_aec)
2921 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2922 else
2923 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002924 }
2925 platform_set_echo_reference(adev, true, out_device);
2926 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2927 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2928 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002929 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002930 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2931 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002932 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002933 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2934 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002935 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002936 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002937 if (adev->active_input->enable_aec) {
2938 if (adev->active_input->enable_ns) {
2939 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2940 } else {
2941 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2942 }
vivek mehta733c1df2016-04-04 15:09:24 -07002943 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002944 } else if (adev->active_input->enable_ns) {
2945 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2946 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002947 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002948 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002949 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002950 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2951 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002952 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002953 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002954 }
rago90fb9612015-12-02 11:37:53 -08002955 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2956 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002957 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2958 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2959 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2960 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002961 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002962 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2963 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002964 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002965 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2966 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2967 } else {
2968 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2969 }
rago90fb9612015-12-02 11:37:53 -08002970 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2971 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002972 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002973 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002974 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002975 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002976 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002977 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2978 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2979 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2980 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002981 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002982 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002983 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002984 if (adev->active_input->enable_aec &&
2985 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002986 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002987 if (my_data->fluence_in_spkr_mode &&
2988 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002989 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002990 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002991 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002992 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002993 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002994 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002995 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002996 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002997 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002998 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002999 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003000 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003001 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3002 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003003 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003004 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003005 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003006 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003007 } else if (adev->active_input->enable_aec) {
3008 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3009 if (my_data->fluence_in_spkr_mode &&
3010 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003011 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003012 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003013 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003014 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003015 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003016 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3017 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003018 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003019 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003020 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003021 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003022 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003023 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3024 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07003025 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07003026 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05003027 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08003028 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003029 } else if (adev->active_input->enable_ns) {
3030 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3031 if (my_data->fluence_in_spkr_mode &&
3032 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_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003035 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003036 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003037 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003038 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3039 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07003040 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003041 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003042 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003043 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07003044 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003045 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05003046 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003047 }
3048 } else if (source == AUDIO_SOURCE_DEFAULT) {
3049 goto exit;
3050 }
3051
3052
3053 if (snd_device != SND_DEVICE_NONE) {
3054 goto exit;
3055 }
3056
3057 if (in_device != AUDIO_DEVICE_NONE &&
3058 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3059 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3060 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003061 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003062 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003063 snd_device = SND_DEVICE_IN_QUAD_MIC;
3064 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08003065 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003066 snd_device = SND_DEVICE_IN_THREE_MIC;
3067 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3068 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003069 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003070 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3071 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003072 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003073 } else {
3074 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
3075 " channel mask (0x%x) no combination found .. setting to mono", __func__,
3076 my_data->source_mic_type, channel_count, channel_mask);
3077 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3078 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003079 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003080 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3081 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003082 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003083 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3084 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003085 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003086 } else {
3087 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
3088 " no combination found .. setting to mono", __func__,
3089 my_data->source_mic_type, channel_count);
3090 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3091 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003092 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3093 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3094 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003095 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003096 if (adev->bluetooth_nrec)
3097 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3098 else
3099 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003100 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003101 if (adev->bluetooth_nrec)
3102 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3103 else
3104 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003105 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003106 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3107 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003108 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07003109 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003110 } else {
3111 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3112 ALOGW("%s: Using default handset-mic", __func__);
3113 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3114 }
3115 } else {
3116 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3117 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3118 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3119 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003120 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07003121 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003122 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05003123 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07003124 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3125 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003126 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07003127 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
3128 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07003129 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07003130 } else {
3131 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
3132 " no combination found .. setting to mono", __func__,
3133 my_data->source_mic_type, channel_count);
3134 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3135 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003136 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003137 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003138 if (adev->bluetooth_nrec)
3139 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3140 else
3141 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003142 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07003143 if (adev->bluetooth_nrec)
3144 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3145 else
3146 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07003147 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003148 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3149 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07003150 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07003151 if (audio_extn_usb_is_capture_supported())
3152 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
3153 else
3154 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07003155 } else {
3156 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3157 ALOGW("%s: Using default handset-mic", __func__);
3158 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3159 }
3160 }
3161exit:
3162 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3163 return snd_device;
3164}
3165
3166int platform_set_hdmi_channels(void *platform, int channel_count)
3167{
3168 struct platform_data *my_data = (struct platform_data *)platform;
3169 struct audio_device *adev = my_data->adev;
3170 struct mixer_ctl *ctl;
3171 const char *channel_cnt_str = NULL;
3172 const char *mixer_ctl_name = "HDMI_RX Channels";
3173 switch (channel_count) {
3174 case 8:
3175 channel_cnt_str = "Eight"; break;
3176 case 7:
3177 channel_cnt_str = "Seven"; break;
3178 case 6:
3179 channel_cnt_str = "Six"; break;
3180 case 5:
3181 channel_cnt_str = "Five"; break;
3182 case 4:
3183 channel_cnt_str = "Four"; break;
3184 case 3:
3185 channel_cnt_str = "Three"; break;
3186 default:
3187 channel_cnt_str = "Two"; break;
3188 }
3189 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3190 if (!ctl) {
3191 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3192 __func__, mixer_ctl_name);
3193 return -EINVAL;
3194 }
3195 ALOGV("HDMI channel count: %s", channel_cnt_str);
3196 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3197 return 0;
3198}
3199
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003200int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07003201{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003202 struct platform_data *my_data = (struct platform_data *)platform;
3203 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003204 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3205 char *sad = block;
3206 int num_audio_blocks;
3207 int channel_count;
3208 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003209 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07003210
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003211 struct mixer_ctl *ctl;
3212
3213 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3214 if (!ctl) {
3215 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3216 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07003217 return 0;
3218 }
3219
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003220 mixer_ctl_update(ctl);
3221
3222 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07003223
3224 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003225 if (count > (int)sizeof(block))
3226 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07003227
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003228 ret = mixer_ctl_get_array(ctl, block, count);
3229 if (ret != 0) {
3230 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3231 return 0;
3232 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003233
3234 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003235 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07003236
3237 for (i = 0; i < num_audio_blocks; i++) {
3238 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003239 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
3240 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07003241 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07003242 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003243
3244 channel_count = (sad[0] & 0x7) + 1;
3245 if (channel_count > max_channels)
3246 max_channels = channel_count;
3247
3248 /* Advance to next block */
3249 sad += 3;
3250 }
3251
3252 return max_channels;
3253}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003254
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07003255int platform_set_incall_recording_session_id(void *platform,
3256 uint32_t session_id, int rec_mode)
3257{
3258 int ret = 0;
3259 struct platform_data *my_data = (struct platform_data *)platform;
3260 struct audio_device *adev = my_data->adev;
3261 struct mixer_ctl *ctl;
3262 const char *mixer_ctl_name = "Voc VSID";
3263 int num_ctl_values;
3264 int i;
3265
3266 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3267 if (!ctl) {
3268 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3269 __func__, mixer_ctl_name);
3270 ret = -EINVAL;
3271 } else {
3272 num_ctl_values = mixer_ctl_get_num_values(ctl);
3273 for (i = 0; i < num_ctl_values; i++) {
3274 if (mixer_ctl_set_value(ctl, i, session_id)) {
3275 ALOGV("Error: invalid session_id: %x", session_id);
3276 ret = -EINVAL;
3277 break;
3278 }
3279 }
3280 }
3281
3282 if (my_data->csd != NULL) {
3283 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3284 if (ret < 0) {
3285 ALOGE("%s: csd_client_start_record failed, error %d",
3286 __func__, ret);
3287 }
3288 }
3289
3290 return ret;
3291}
3292
3293int platform_stop_incall_recording_usecase(void *platform)
3294{
3295 int ret = 0;
3296 struct platform_data *my_data = (struct platform_data *)platform;
3297
3298 if (my_data->csd != NULL) {
3299 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3300 if (ret < 0) {
3301 ALOGE("%s: csd_client_stop_record failed, error %d",
3302 __func__, ret);
3303 }
3304 }
3305
3306 return ret;
3307}
3308
3309int platform_start_incall_music_usecase(void *platform)
3310{
3311 int ret = 0;
3312 struct platform_data *my_data = (struct platform_data *)platform;
3313
3314 if (my_data->csd != NULL) {
3315 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3316 if (ret < 0) {
3317 ALOGE("%s: csd_client_start_playback failed, error %d",
3318 __func__, ret);
3319 }
3320 }
3321
3322 return ret;
3323}
3324
3325int platform_stop_incall_music_usecase(void *platform)
3326{
3327 int ret = 0;
3328 struct platform_data *my_data = (struct platform_data *)platform;
3329
3330 if (my_data->csd != NULL) {
3331 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3332 if (ret < 0) {
3333 ALOGE("%s: csd_client_stop_playback failed, error %d",
3334 __func__, ret);
3335 }
3336 }
3337
3338 return ret;
3339}
3340
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003341int platform_set_parameters(void *platform, struct str_parms *parms)
3342{
3343 struct platform_data *my_data = (struct platform_data *)platform;
jasmine chac89321b2018-04-10 21:37:01 +08003344 char *value = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003345 char *kv_pairs = str_parms_to_str(parms);
jasmine chac89321b2018-04-10 21:37:01 +08003346 int len;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003347 int ret = 0, err;
3348
3349 if (kv_pairs == NULL) {
3350 ret = -EINVAL;
Jasmine Chaa314e192018-05-09 17:46:28 +08003351 ALOGE("%s: key-value pair is NULL", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003352 goto done;
3353 }
3354
3355 ALOGV("%s: enter: %s", __func__, kv_pairs);
3356
jasmine chac89321b2018-04-10 21:37:01 +08003357 len = strlen(kv_pairs);
Jasmine Chaa314e192018-05-09 17:46:28 +08003358 value = (char*)calloc(len + 1, sizeof(char));
jasmine chac89321b2018-04-10 21:37:01 +08003359 if (value == NULL) {
3360 ret = -ENOMEM;
Jasmine Chaa314e192018-05-09 17:46:28 +08003361 ALOGE("[%s] failed to allocate memory", __func__);
jasmine chac89321b2018-04-10 21:37:01 +08003362 goto done;
3363 }
3364
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003365 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
jasmine chac89321b2018-04-10 21:37:01 +08003366 value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003367 if (err >= 0) {
3368 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3369 my_data->snd_card_name = strdup(value);
3370 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3371 }
3372
keunhui.park2f7306a2015-07-16 16:48:06 +09003373 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
jasmine chac89321b2018-04-10 21:37:01 +08003374 value, len);
keunhui.park2f7306a2015-07-16 16:48:06 +09003375 if (err >= 0) {
3376 struct operator_info *info;
3377 char *str = value;
3378 char *name;
3379
3380 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3381 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3382 name = strtok(str, ";");
3383 info->name = strdup(name);
3384 info->mccmnc = strdup(str + strlen(name) + 1);
3385
3386 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003387 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003388 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003389
Jasmine Chaa314e192018-05-09 17:46:28 +08003390 memset(value, 0, len + 1);
Eric Laurentc6333382015-09-14 12:43:44 -07003391 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
jasmine chac89321b2018-04-10 21:37:01 +08003392 value, len);
Prashant Malanic92c5962015-08-11 15:10:18 -07003393 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003394 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003395 my_data->max_mic_count = atoi(value);
3396 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003397 }
3398
jasmine chac89321b2018-04-10 21:37:01 +08003399 /* handle audio calibration parameters */
3400 set_audiocal(platform, parms, value, len);
3401
vivek mehta90933872017-06-15 18:04:39 -07003402 // to-do: disable setting sidetone gain, will revist this later
3403 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003404done:
3405 ALOGV("%s: exit with code(%d)", __func__, ret);
3406 if (kv_pairs != NULL)
3407 free(kv_pairs);
jasmine chac89321b2018-04-10 21:37:01 +08003408 if (value != NULL)
3409 free(value);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003410
3411 return ret;
3412}
3413
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003414/* Delay in Us */
3415int64_t platform_render_latency(audio_usecase_t usecase)
3416{
3417 switch (usecase) {
3418 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3419 return DEEP_BUFFER_PLATFORM_DELAY;
3420 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3421 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003422 case USECASE_AUDIO_PLAYBACK_ULL:
3423 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003424 case USECASE_AUDIO_PLAYBACK_MMAP:
3425 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003426 default:
3427 return 0;
3428 }
3429}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003430
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003431int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3432 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003433{
3434 int ret = 0;
3435
3436 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3437 ALOGE("%s: Invalid snd_device = %d",
3438 __func__, device);
3439 ret = -EINVAL;
3440 goto done;
3441 }
3442
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003443 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3444 platform_get_snd_device_name(device),
3445 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3446 if (backend_tag_table[device]) {
3447 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003448 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003449 backend_tag_table[device] = strdup(backend_tag);
3450
3451 if (hw_interface != NULL) {
3452 if (hw_interface_table[device])
3453 free(hw_interface_table[device]);
3454 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3455 hw_interface_table[device] = strdup(hw_interface);
3456 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003457done:
3458 return ret;
3459}
3460
3461int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3462{
3463 int ret = 0;
3464 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3465 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3466 ret = -EINVAL;
3467 goto done;
3468 }
3469
3470 if ((type != 0) && (type != 1)) {
3471 ALOGE("%s: invalid usecase type", __func__);
3472 ret = -EINVAL;
3473 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003474 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3475 use_case_table[usecase],
3476 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003477 pcm_device_table[usecase][type] = pcm_id;
3478done:
3479 return ret;
3480}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003481
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003482#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3483int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3484 // backup_gain: gain to try to set in case of an error during ramp
3485 int start_gain, end_gain, step, backup_gain, i;
3486 bool error = false;
3487 const struct mixer_ctl *ctl;
3488 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3489 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3490 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3491 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3492 if (!ctl_left || !ctl_right) {
3493 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3494 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3495 return -EINVAL;
3496 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3497 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3498 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3499 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3500 return -EINVAL;
3501 }
3502 if (ramp_up) {
3503 start_gain = 0;
3504 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3505 step = +1;
3506 backup_gain = end_gain;
3507 } else {
3508 // using same gain on left and right
3509 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3510 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3511 end_gain = 0;
3512 step = -1;
3513 backup_gain = start_gain;
3514 }
3515 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3516 //ALOGV("setting speaker gain to %d", i);
3517 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3518 ALOGE("%s: error setting %s to %d during gain ramp",
3519 __func__, mixer_ctl_name_gain_left, i);
3520 error = true;
3521 break;
3522 }
3523 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3524 ALOGE("%s: error setting %s to %d during gain ramp",
3525 __func__, mixer_ctl_name_gain_right, i);
3526 error = true;
3527 break;
3528 }
3529 usleep(1000);
3530 }
3531 if (error) {
3532 // an error occured during the ramp, let's still try to go back to a safe volume
3533 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3534 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3535 }
3536 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3537 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3538 }
3539 }
3540 return start_gain;
3541}
3542
vivek mehtae59cfb22017-06-16 15:57:11 -07003543int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3544{
3545 const char *mixer_ctl_name = "Swap channel";
3546 struct mixer_ctl *ctl;
3547 const char *mixer_path;
3548 struct platform_data *my_data = (struct platform_data *)adev->platform;
3549
3550 // forced to set to swap, but device not rotated ... ignore set
3551 if (swap_channels && !my_data->speaker_lr_swap)
3552 return 0;
3553
3554 ALOGV("%s:", __func__);
3555
3556 if (swap_channels) {
3557 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3558 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3559 } else {
3560 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3561 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3562 }
3563
3564 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3565 if (!ctl) {
3566 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3567 return -EINVAL;
3568 }
3569
3570 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3571 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3572 return -EINVAL;
3573 }
3574
3575 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3576 swap_channels?"R --> L":"L --> R");
3577
3578 return 0;
3579}
3580
3581int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003582{
3583 // only update if there is active pcm playback on speaker
3584 struct audio_usecase *usecase;
3585 struct listnode *node;
3586 struct platform_data *my_data = (struct platform_data *)adev->platform;
3587
vivek mehtae59cfb22017-06-16 15:57:11 -07003588 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003589
vivek mehtae59cfb22017-06-16 15:57:11 -07003590 return platform_set_swap_channels(adev, swap_channels);
3591}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003592
vivek mehtae59cfb22017-06-16 15:57:11 -07003593int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3594{
3595 // only update if there is active pcm playback on speaker
3596 struct audio_usecase *usecase;
3597 struct listnode *node;
3598 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003599
vivek mehtae59cfb22017-06-16 15:57:11 -07003600 // do not swap channels in audio modes with concurrent capture and playback
3601 // as this may break the echo reference
3602 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3603 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3604 return 0;
3605 }
3606
3607 list_for_each(node, &adev->usecase_list) {
3608 usecase = node_to_item(node, struct audio_usecase, list);
3609 if (usecase->type == PCM_PLAYBACK &&
3610 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3611 /*
3612 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3613 * to perform device switch to disable the current backend to
3614 * enable it with new acdb data.
3615 */
3616 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3617 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3618 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3619 select_devices(adev, usecase->id);
3620 if (initial_skpr_gain != -EINVAL)
3621 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3622
3623 } else {
3624 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003625 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003626 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003627 }
3628 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003629
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003630 return 0;
3631}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003632
3633static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3634static int num_gain_tbl_entry = 0;
3635
3636bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3637
3638 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3639 if (num_gain_tbl_entry == -1) {
3640 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3641 __func__);
3642 return false;
3643 }
3644
3645 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3646 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3647 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3648 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3649 return false;
3650 }
3651
3652 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3653 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3654 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3655 return false;
3656 }
3657
3658 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3659 ++num_gain_tbl_entry;
3660
3661 return true;
3662}
3663
3664int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3665 int table_size) {
3666 int itt = 0;
3667 ALOGV("platform_get_gain_level_mapping called ");
3668
3669 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3670 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3671 return 0;
3672 }
3673
3674 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3675 mapping_tbl[itt] = tbl_mapping[itt];
3676 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3677 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3678 }
3679
3680 return num_gain_tbl_entry;
3681}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003682
3683int platform_snd_card_update(void *platform, card_status_t status)
3684{
3685 struct platform_data *my_data = (struct platform_data *)platform;
3686 struct audio_device *adev = my_data->adev;
3687
3688 if (status == CARD_STATUS_ONLINE) {
3689 if (my_data->acdb_send_custom_top)
3690 my_data->acdb_send_custom_top();
3691 }
3692 return 0;
3693}
David Linee3fe402017-03-13 10:00:42 -07003694
3695/*
3696 * configures afe with bit width and Sample Rate
3697 */
Haynes Mathew George65f6b432018-02-27 17:44:55 -08003698int platform_set_backend_cfg(const struct audio_device* adev,
3699 snd_device_t snd_device,
3700 const struct audio_backend_cfg *backend_cfg)
David Linee3fe402017-03-13 10:00:42 -07003701{
3702
3703 int ret = 0;
3704 const int backend_idx = platform_get_backend_index(snd_device);
3705 struct platform_data *my_data = (struct platform_data *)adev->platform;
3706 const unsigned int bit_width = backend_cfg->bit_width;
3707 const unsigned int sample_rate = backend_cfg->sample_rate;
3708 const unsigned int channels = backend_cfg->channels;
3709 const audio_format_t format = backend_cfg->format;
3710 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3711
3712
3713 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3714 ", backend_idx %d device (%s)", __func__, bit_width,
3715 sample_rate, channels, backend_idx,
3716 platform_get_snd_device_name(snd_device));
3717
3718 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3719 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3720
3721 struct mixer_ctl *ctl = NULL;
3722 ctl = mixer_get_ctl_by_name(adev->mixer,
3723 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3724 if (!ctl) {
3725 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3726 __func__,
3727 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3728 return -EINVAL;
3729 }
3730
3731 if (bit_width == 24) {
3732 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3733 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3734 else
3735 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3736 } else if (bit_width == 32) {
3737 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3738 } else {
3739 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3740 }
3741 if ( ret < 0) {
3742 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3743 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3744 } else {
3745 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3746 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3747 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3748 }
3749 /* set the ret as 0 and not pass back to upper layer */
3750 ret = 0;
3751 }
3752
3753 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3754 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3755 char *rate_str = NULL;
3756 struct mixer_ctl *ctl = NULL;
3757
3758 switch (sample_rate) {
3759 case 32000:
3760 if (passthrough_enabled) {
3761 rate_str = "KHZ_32";
3762 break;
3763 }
3764 case 8000:
3765 case 11025:
3766 case 16000:
3767 case 22050:
3768 case 48000:
3769 rate_str = "KHZ_48";
3770 break;
3771 case 44100:
3772 rate_str = "KHZ_44P1";
3773 break;
3774 case 64000:
3775 case 96000:
3776 rate_str = "KHZ_96";
3777 break;
3778 case 88200:
3779 rate_str = "KHZ_88P2";
3780 break;
3781 case 176400:
3782 rate_str = "KHZ_176P4";
3783 break;
3784 case 192000:
3785 rate_str = "KHZ_192";
3786 break;
3787 case 352800:
3788 rate_str = "KHZ_352P8";
3789 break;
3790 case 384000:
3791 rate_str = "KHZ_384";
3792 break;
3793 case 144000:
3794 if (passthrough_enabled) {
3795 rate_str = "KHZ_144";
3796 break;
3797 }
3798 default:
3799 rate_str = "KHZ_48";
3800 break;
3801 }
3802
3803 ctl = mixer_get_ctl_by_name(adev->mixer,
3804 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3805 if(!ctl) {
3806 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3807 __func__,
3808 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3809 return -EINVAL;
3810 }
3811
3812 ALOGD("%s:becf: afe: %s set to %s", __func__,
3813 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3814 mixer_ctl_set_enum_by_string(ctl, rate_str);
3815 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3816 }
3817 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3818 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3819 struct mixer_ctl *ctl = NULL;
3820 char *channel_cnt_str = NULL;
3821
3822 switch (channels) {
3823 case 8:
3824 channel_cnt_str = "Eight"; break;
3825 case 7:
3826 channel_cnt_str = "Seven"; break;
3827 case 6:
3828 channel_cnt_str = "Six"; break;
3829 case 5:
3830 channel_cnt_str = "Five"; break;
3831 case 4:
3832 channel_cnt_str = "Four"; break;
3833 case 3:
3834 channel_cnt_str = "Three"; break;
3835 case 1:
3836 channel_cnt_str = "One"; break;
3837 case 2:
3838 default:
3839 channel_cnt_str = "Two"; break;
3840 }
3841
3842 ctl = mixer_get_ctl_by_name(adev->mixer,
3843 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3844 if (!ctl) {
3845 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3846 __func__,
3847 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3848 return -EINVAL;
3849 }
3850 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3851 my_data->current_backend_cfg[backend_idx].channels = channels;
3852
3853 // skip EDID configuration for HDMI backend
3854
3855 ALOGD("%s:becf: afe: %s set to %s", __func__,
3856 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3857 channel_cnt_str);
3858 }
3859
3860 // skip set ext_display format mixer control
3861 return ret;
3862}
3863
3864static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3865{
3866 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3867 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3868 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3869 }
3870
3871 return backend_bit_width_table[snd_device];
3872}
3873
3874/*
3875 * return backend_idx on which voice call is active
3876 */
3877static int platform_get_voice_call_backend(struct audio_device* adev)
3878{
3879 struct audio_usecase *uc = NULL;
3880 struct listnode *node;
3881 snd_device_t out_snd_device = SND_DEVICE_NONE;
3882
3883 int backend_idx = -1;
3884
3885 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3886 list_for_each(node, &adev->usecase_list) {
3887 uc = node_to_item(node, struct audio_usecase, list);
3888 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3889 out_snd_device = platform_get_output_snd_device(adev->platform,
3890 uc->stream.out->devices);
3891 backend_idx = platform_get_backend_index(out_snd_device);
3892 break;
3893 }
3894 }
3895 }
3896 return backend_idx;
3897}
3898
3899/*
3900 * goes through all the current usecases and picks the highest
3901 * bitwidth & samplerate
3902 */
3903static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3904 int backend_idx,
3905 struct audio_backend_cfg *backend_cfg)
3906{
3907 bool backend_change = false;
3908 unsigned int bit_width;
3909 unsigned int sample_rate;
3910 unsigned int channels;
3911 struct platform_data *my_data = (struct platform_data *)adev->platform;
3912
3913 bit_width = backend_cfg->bit_width;
3914 sample_rate = backend_cfg->sample_rate;
3915 channels = backend_cfg->channels;
3916
3917 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3918 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3919 sample_rate, channels);
3920
3921 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3922 // default backend
3923 // force routing is not required here, caller will do it anyway
3924 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3925 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3926 "for unprocessed/camera source", __func__);
3927 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3928 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3929 }
3930
3931 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3932 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3933 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3934 __func__, bit_width, sample_rate, channels);
3935 }
3936
3937 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3938 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3939
3940 // Force routing if the expected bitwdith or samplerate
3941 // is not same as current backend comfiguration
3942 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3943 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3944 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3945 backend_cfg->bit_width = bit_width;
3946 backend_cfg->sample_rate= sample_rate;
3947 backend_cfg->channels = channels;
3948 backend_change = true;
3949 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3950 "new sample rate: %d new channel: %d",
3951 __func__, backend_cfg->bit_width,
3952 backend_cfg->sample_rate, backend_cfg->channels);
3953 }
3954
3955 return backend_change;
3956}
3957
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003958static void pick_playback_cfg_for_uc(struct audio_device *adev,
3959 struct audio_usecase *usecase,
3960 snd_device_t snd_device,
3961 unsigned int *bit_width,
3962 unsigned int *sample_rate,
3963 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003964{
3965 int i =0;
3966 struct listnode *node;
3967 list_for_each(node, &adev->usecase_list) {
3968 struct audio_usecase *uc;
3969 uc = node_to_item(node, struct audio_usecase, list);
3970 struct stream_out *out = (struct stream_out*) uc->stream.out;
3971 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3972 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3973 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3974 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3975 uc->id, out->sample_rate,
3976 pcm_format_to_bits(out->config.format), out_channels,
3977 platform_get_snd_device_name(uc->out_snd_device));
3978
3979 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3980 if (*bit_width < pcm_format_to_bits(out->config.format))
3981 *bit_width = pcm_format_to_bits(out->config.format);
3982 if (*sample_rate < out->sample_rate)
3983 *sample_rate = out->sample_rate;
3984 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3985 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3986 if (*channels < out_channels)
3987 *channels = out_channels;
3988 }
3989 }
3990 }
3991 return;
3992}
3993
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003994static void headset_is_config_supported(unsigned int *bit_width,
3995 unsigned int *sample_rate,
3996 unsigned int *channels) {
3997 switch (*bit_width) {
3998 case 16:
3999 case 24:
4000 break;
4001 default:
4002 *bit_width = 16;
4003 break;
4004 }
4005
4006 if (*sample_rate > 192000) {
4007 *sample_rate = 192000;
4008 }
4009
4010 if (*channels > 2) {
4011 *channels = 2;
4012 }
4013}
4014
David Linee3fe402017-03-13 10:00:42 -07004015static bool platform_check_playback_backend_cfg(struct audio_device* adev,
4016 struct audio_usecase* usecase,
4017 snd_device_t snd_device,
4018 struct audio_backend_cfg *backend_cfg)
4019{
4020 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07004021 unsigned int bit_width;
4022 unsigned int sample_rate;
4023 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07004024 int backend_idx = DEFAULT_CODEC_BACKEND;
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004025 unsigned long service_interval = 0; // 0 is invalid
David Linee3fe402017-03-13 10:00:42 -07004026 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07004027
4028 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
4029 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
4030 backend_change = false;
4031 return backend_change;
4032 }
4033
4034 backend_idx = platform_get_backend_index(snd_device);
4035 bit_width = backend_cfg->bit_width;
4036 sample_rate = backend_cfg->sample_rate;
4037 channels = backend_cfg->channels;
4038
4039 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4040 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
4041 sample_rate, channels, backend_idx, usecase->id,
4042 platform_get_snd_device_name(snd_device));
4043
4044 if (backend_idx == platform_get_voice_call_backend(adev)) {
4045 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4046 __func__);
4047 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4048 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4049 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4050 } else {
4051 /*
4052 * The backend should be configured at highest bit width and/or
4053 * sample rate amongst all playback usecases.
4054 * If the selected sample rate and/or bit width differ with
4055 * current backend sample rate and/or bit width, then, we set the
4056 * backend re-configuration flag.
4057 *
4058 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
4059 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004060 pick_playback_cfg_for_uc(adev, usecase, snd_device,
4061 &bit_width,
4062 &sample_rate,
4063 &channels);
David Linee3fe402017-03-13 10:00:42 -07004064 }
4065
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004066 switch (backend_idx) {
4067 case USB_AUDIO_RX_BACKEND:
4068 audio_extn_usb_is_config_supported(&bit_width,
4069 &sample_rate, &channels, true);
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004070 if (platform_get_usb_service_interval(adev->platform, true,
4071 &service_interval) == 0) {
4072 /* overwrite with best altset for this service interval */
4073 int ret =
4074 audio_extn_usb_altset_for_service_interval(true /*playback*/,
4075 service_interval,
4076 &bit_width,
4077 &sample_rate,
4078 &channels);
4079 if (ret < 0) {
4080 ALOGE("Failed to find altset for service interval %lu, skip reconfig",
4081 service_interval);
4082 return false;
4083 }
4084 }
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004085 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
4086 __func__, bit_width, sample_rate, channels);
4087 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004088 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004089 headset_is_config_supported(&bit_width, &sample_rate, &channels);
4090 break;
4091 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004092 default:
4093 bit_width = platform_get_snd_device_bit_width(snd_device);
4094 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4095 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
4096 break;
David Linee3fe402017-03-13 10:00:42 -07004097 }
4098
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004099 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
4100 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07004101 __func__, backend_idx , bit_width, sample_rate);
4102
4103 // Force routing if the expected bitwdith or samplerate
4104 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004105 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
4106 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
4107 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07004108 backend_cfg->bit_width = bit_width;
4109 backend_cfg->sample_rate = sample_rate;
4110 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004111 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07004112 backend_change = true;
4113 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
4114 "new sample rate: %d new channels: %d",
4115 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
4116 }
4117
4118 return backend_change;
4119}
4120
4121bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
4122 struct audio_usecase *usecase, snd_device_t snd_device)
4123{
4124 int backend_idx = DEFAULT_CODEC_BACKEND;
4125 int new_snd_devices[SND_DEVICE_OUT_END];
4126 int i, num_devices = 1;
4127 bool ret = false;
4128 struct platform_data *my_data = (struct platform_data *)adev->platform;
4129 struct audio_backend_cfg backend_cfg;
4130
4131 backend_idx = platform_get_backend_index(snd_device);
4132
4133 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
4134 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
4135 backend_cfg.format = usecase->stream.out->format;
4136 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
4137 /*this is populated by check_codec_backend_cfg hence set default value to false*/
4138 backend_cfg.passthrough_enabled = false;
4139
4140 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
4141 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
4142 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
4143 platform_get_snd_device_name(snd_device));
4144
4145 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
4146 new_snd_devices[0] = snd_device;
4147
4148 for (i = 0; i < num_devices; i++) {
4149 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
4150 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
4151 &backend_cfg))) {
4152 platform_set_backend_cfg(adev, new_snd_devices[i],
4153 &backend_cfg);
4154 ret = true;
4155 }
4156 }
4157 return ret;
4158}
4159
4160bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
4161 struct audio_usecase *usecase, snd_device_t snd_device)
4162{
4163 int backend_idx = platform_get_backend_index(snd_device);
4164 int ret = 0;
4165 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004166 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07004167
Haynes Mathew George4bd47992017-03-09 17:59:38 -08004168 if (usecase->type == PCM_CAPTURE) {
4169 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07004170 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
4171 } else {
4172 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4173 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4174 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
4175 backend_cfg.channels = 1;
4176 }
4177
4178 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
4179 ", backend_idx %d usecase = %d device (%s)", __func__,
4180 backend_cfg.bit_width,
4181 backend_cfg.sample_rate,
4182 backend_cfg.channels,
4183 backend_idx, usecase->id,
4184 platform_get_snd_device_name(snd_device));
4185
4186 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
4187 ret = platform_set_backend_cfg(adev, snd_device,
4188 &backend_cfg);
4189 if(!ret)
4190 return true;
4191 }
4192
4193 return false;
4194}
4195
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004196static int max_be_dai_names = 0;
4197static const struct be_dai_name_struct *be_dai_name_table;
4198
4199/*
4200 * Retrieves the be_dai_name_table from kernel to enable a mapping
4201 * between sound device hw interfaces and backend IDs. This allows HAL to
4202 * specify the backend a specific calibration is needed for.
4203 */
4204static int init_be_dai_name_table(struct audio_device *adev)
4205{
4206 const char *mixer_ctl_name = "Backend DAI Name Table";
4207 struct mixer_ctl *ctl;
4208 int i, j, ret, size;
4209 bool valid_hw_interface;
4210
4211 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4212 if (!ctl) {
4213 ALOGE("%s: Could not get ctl for mixer name %s\n",
4214 __func__, mixer_ctl_name);
4215 ret = -EINVAL;
4216 goto done;
4217 }
4218
4219 mixer_ctl_update(ctl);
4220
4221 size = mixer_ctl_get_num_values(ctl);
4222 if (size <= 0){
4223 ALOGE("%s: Failed to get %s size %d\n",
4224 __func__, mixer_ctl_name, size);
4225 ret = -EFAULT;
4226 goto done;
4227 }
4228
vivek mehtaa68fea62017-06-08 19:04:02 -07004229 be_dai_name_table =
4230 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004231 if (be_dai_name_table == NULL) {
4232 ALOGE("%s: Failed to allocate memory for %s\n",
4233 __func__, mixer_ctl_name);
4234 ret = -ENOMEM;
4235 goto freeMem;
4236 }
4237
4238 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
4239 if (ret) {
4240 ALOGE("%s: Failed to get %s, ret %d\n",
4241 __func__, mixer_ctl_name, ret);
4242 ret = -EFAULT;
4243 goto freeMem;
4244 }
4245
4246 if (be_dai_name_table != NULL) {
4247 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
4248 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
4249 __func__, mixer_ctl_name, max_be_dai_names);
4250 ret = 0;
4251 } else {
4252 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
4253 ret = -EFAULT;
4254 goto freeMem;
4255 }
4256
4257 /*
4258 * Validate all sound devices have a valid backend set to catch
4259 * errors for uncommon sound devices
4260 */
4261 for (i = 0; i < SND_DEVICE_MAX; i++) {
4262 valid_hw_interface = false;
4263
4264 if (hw_interface_table[i] == NULL) {
4265 ALOGW("%s: sound device %s has no hw interface set\n",
4266 __func__, platform_get_snd_device_name(i));
4267 continue;
4268 }
4269
4270 for (j = 0; j < max_be_dai_names; j++) {
4271 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
4272 == 0) {
4273 valid_hw_interface = true;
4274 break;
4275 }
4276 }
4277 if (!valid_hw_interface)
4278 ALOGD("%s: sound device %s does not have a valid hw interface set "
4279 "(disregard for combo devices) %s\n",
4280 __func__, platform_get_snd_device_name(i),
4281 hw_interface_table[i]);
4282 }
4283
4284 goto done;
4285
4286freeMem:
4287 if (be_dai_name_table) {
4288 free((void *)be_dai_name_table);
4289 be_dai_name_table = NULL;
4290 }
4291
4292done:
4293 return ret;
4294}
4295
4296int platform_get_snd_device_backend_index(snd_device_t device)
4297{
4298 int i, be_dai_id;
4299 const char * hw_interface_name = NULL;
4300
4301 ALOGV("%s: enter with device %d\n", __func__, device);
4302
vivek mehtaa68fea62017-06-08 19:04:02 -07004303 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004304 ALOGE("%s: Invalid snd_device = %d",
4305 __func__, device);
4306 be_dai_id = -EINVAL;
4307 goto done;
4308 }
4309
4310 /* Get string value of necessary backend for device */
4311 hw_interface_name = hw_interface_table[device];
4312 if (hw_interface_name == NULL) {
4313 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
4314 be_dai_id = -EINVAL;
4315 goto done;
4316 }
4317
4318 /* Check if be dai name table was retrieved successfully */
4319 if (be_dai_name_table == NULL) {
4320 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
4321 be_dai_id = -EFAULT;
4322 goto done;
4323 }
4324
4325 /* Get backend ID for device specified */
4326 for (i = 0; i < max_be_dai_names; i++) {
4327 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
4328 be_dai_id = be_dai_name_table[i].be_id;
4329 goto done;
4330 }
4331 }
4332 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
4333 be_dai_id = -EINVAL;
4334 goto done;
4335
4336done:
4337 return be_dai_id;
4338}
4339
4340void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4341 unsigned int stream_sr, int* sample_rate)
4342{
4343 struct platform_data* my_data = (struct platform_data *)platform;
4344 int backend_idx = platform_get_backend_index(snd_device);
4345 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4346 /*
4347 *Check if device SR is multiple of 8K or 11.025 Khz
4348 *check if the stream SR is multiple of same base, if yes
4349 *then have copp SR equal to stream SR, this ensures that
4350 *post processing happens at stream SR, else have
4351 *copp SR equal to device SR.
4352 */
4353 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4354 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4355 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4356 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4357 *sample_rate = device_sr;
4358 } else
4359 *sample_rate = stream_sr;
4360
4361 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4362 , *sample_rate);
4363
4364}
4365
4366// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004367void platform_add_app_type(const char *uc_type,
4368 const char *mode,
4369 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004370 int app_type, int max_rate) {
4371 struct app_type_entry *ap =
4372 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4373
4374 if (!ap) {
4375 ALOGE("%s failed to allocate mem for app type", __func__);
4376 return;
4377 }
4378
4379 ap->uc_type = -1;
4380 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4381 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4382 ap->uc_type = usecase_type_index[i].index;
4383 break;
4384 }
4385 }
4386
4387 if (ap->uc_type == -1) {
4388 free(ap);
4389 return;
4390 }
4391
vivek mehtaa68fea62017-06-08 19:04:02 -07004392 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4393 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004394 ap->bit_width = bw;
4395 ap->app_type = app_type;
4396 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004397 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004398 list_add_tail(&app_type_entry_list, &ap->node);
4399}
4400
4401
4402int platform_get_default_app_type_v2(void *platform __unused,
4403 usecase_type_t type,
4404 int *app_type )
4405{
4406 if (type == PCM_PLAYBACK)
4407 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4408 else
4409 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4410 return 0;
4411}
4412
vivek mehtaa68fea62017-06-08 19:04:02 -07004413int platform_get_app_type_v2(void *platform,
4414 usecase_type_t uc_type,
4415 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004416 int bw, int sr __unused,
4417 int *app_type)
4418{
4419 struct listnode *node;
4420 struct app_type_entry *entry;
4421 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004422
4423 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4424 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004425 list_for_each(node, &app_type_entry_list) {
4426 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004427 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4428 __func__, entry->uc_type, entry->mode, entry->bit_width,
4429 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004430 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004431 entry->uc_type == uc_type &&
4432 sr <= entry->max_rate &&
4433 entry->mode && !strcmp(mode, entry->mode)) {
4434 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004435 *app_type = entry->app_type;
4436 break;
4437 }
4438 }
4439
4440 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004441 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004442 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4443 }
4444 return 0;
4445}
vivek mehta90933872017-06-15 18:04:39 -07004446
4447int platform_set_sidetone(struct audio_device *adev,
4448 snd_device_t out_snd_device,
4449 bool enable, char *str)
4450{
4451 int ret;
4452 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4453 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4454 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4455 if (ret)
4456 ALOGI("%s: usb device %d does not support device sidetone\n",
4457 __func__, out_snd_device);
4458 } else {
4459 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4460 __func__, out_snd_device, str);
4461 if (enable)
4462 audio_route_apply_and_update_path(adev->audio_route, str);
4463 else
4464 audio_route_reset_and_update_path(adev->audio_route, str);
4465 }
4466 return 0;
4467}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004468
4469int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4470 int *fd __unused, uint32_t *size __unused)
4471{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004472#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004473 struct platform_data *my_data = (struct platform_data *)platform;
4474 struct audio_device *adev = my_data->adev;
4475 int hw_fd = -1;
4476 char dev_name[128];
4477 struct snd_pcm_mmap_fd mmap_fd;
4478 memset(&mmap_fd, 0, sizeof(mmap_fd));
4479 mmap_fd.dir = dir;
4480 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4481 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4482 hw_fd = open(dev_name, O_RDONLY);
4483 if (hw_fd < 0) {
4484 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4485 return -1;
4486 }
4487 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4488 ALOGE("fe hw dep node ioctl failed");
4489 close(hw_fd);
4490 return -1;
4491 }
4492 *fd = mmap_fd.fd;
4493 *size = mmap_fd.size;
4494 close(hw_fd); // mmap_fd should still be valid
4495 return 0;
4496#else
4497 return -1;
4498#endif
4499}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +00004500
4501bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
4502{
4503 bool needs_event = false;
4504
4505 switch (uc_id) {
4506 /* concurrent capture usecases which needs event */
4507 case USECASE_AUDIO_RECORD:
4508 case USECASE_AUDIO_RECORD_LOW_LATENCY:
4509 case USECASE_AUDIO_RECORD_MMAP:
4510 case USECASE_AUDIO_RECORD_HIFI:
4511 case USECASE_AUDIO_RECORD_VOIP:
4512 case USECASE_VOICEMMODE1_CALL:
4513 case USECASE_VOICEMMODE2_CALL:
4514 /* concurrent playback usecases that needs event */
4515 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
4516 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
4517 needs_event = true;
4518 break;
4519 default:
4520 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
4521 }
4522 return needs_event;
4523}
4524
4525bool platform_snd_device_has_speaker(snd_device_t dev) {
4526 int num_devs = 2;
4527 snd_device_t split_devs[2] = {SND_DEVICE_NONE, SND_DEVICE_NONE};
4528 if (platform_can_split_snd_device(dev, &num_devs, split_devs) == 0) {
4529 return platform_snd_device_has_speaker(split_devs[0]) ||
4530 platform_snd_device_has_speaker(split_devs[1]);
4531 }
4532
4533 switch (dev) {
4534 case SND_DEVICE_OUT_SPEAKER:
4535 case SND_DEVICE_OUT_SPEAKER_SAFE:
4536 case SND_DEVICE_OUT_SPEAKER_REVERSE:
4537 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
4538 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
4539 case SND_DEVICE_OUT_VOICE_SPEAKER_HFP:
4540 return true;
4541 default:
4542 break;
4543 }
4544 return false;
4545}
jiabin8962a4d2018-03-19 18:21:24 -07004546
4547bool platform_set_microphone_characteristic(void *platform,
4548 struct audio_microphone_characteristic_t mic) {
4549 struct platform_data *my_data = (struct platform_data *)platform;
4550 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4551 ALOGE("mic number is more than maximum number");
4552 return false;
4553 }
4554 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
4555 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
4556 }
4557 my_data->microphones[my_data->declared_mic_count++] = mic;
4558 return true;
4559}
4560
4561int platform_get_microphones(void *platform,
4562 struct audio_microphone_characteristic_t *mic_array,
4563 size_t *mic_count) {
4564 struct platform_data *my_data = (struct platform_data *)platform;
4565 if (mic_count == NULL) {
4566 return -EINVAL;
4567 }
4568 if (mic_array == NULL) {
4569 return -EINVAL;
4570 }
4571
4572 if (*mic_count == 0) {
4573 *mic_count = my_data->declared_mic_count;
4574 return 0;
4575 }
4576
4577 size_t max_mic_count = *mic_count;
4578 size_t actual_mic_count = 0;
4579 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
4580 mic_array[i] = my_data->microphones[i];
4581 actual_mic_count++;
4582 }
4583 *mic_count = actual_mic_count;
4584 return 0;
4585}
4586
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004587bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
4588 const struct mic_info *info) {
4589 struct platform_data *my_data = (struct platform_data *)platform;
4590 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
4591 ALOGE("%s: Sound device not valid", __func__);
4592 return false;
4593 }
4594 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
4595 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
4596 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
4597 my_data->mic_map[in_snd_device].mic_count--;
4598 return false;
4599 }
4600 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
4601 return true;
4602}
4603
4604int platform_get_active_microphones(void *platform, unsigned int channels,
4605 audio_usecase_t uc_id,
jiabin8962a4d2018-03-19 18:21:24 -07004606 struct audio_microphone_characteristic_t *mic_array,
4607 size_t *mic_count) {
4608 struct platform_data *my_data = (struct platform_data *)platform;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004609 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
4610 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
jiabin8962a4d2018-03-19 18:21:24 -07004611 return -EINVAL;
4612 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004613 size_t max_mic_count = my_data->declared_mic_count;
jiabin8962a4d2018-03-19 18:21:24 -07004614 size_t actual_mic_count = 0;
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004615
4616 snd_device_t active_input_snd_device =
4617 platform_get_input_snd_device(platform, usecase->stream.in->device);
4618 if (active_input_snd_device == SND_DEVICE_NONE) {
4619 ALOGI("%s: No active microphones found", __func__);
4620 goto end;
4621 }
4622
4623 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
4624 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
4625
4626 for (size_t i = 0; i < active_mic_count; i++) {
4627 unsigned int channels_for_active_mic = channels;
4628 if (channels_for_active_mic > m_info[i].channel_count) {
4629 channels_for_active_mic = m_info[i].channel_count;
4630 }
4631 for (size_t j = 0; j < max_mic_count; j++) {
4632 if (strcmp(my_data->microphones[j].device_id,
4633 m_info[i].device_id) == 0) {
4634 mic_array[actual_mic_count] = my_data->microphones[j];
4635 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
4636 mic_array[actual_mic_count].channel_mapping[ch] =
4637 m_info[i].channel_mapping[ch];
4638 }
4639 actual_mic_count++;
4640 break;
jiabin8962a4d2018-03-19 18:21:24 -07004641 }
jiabin8962a4d2018-03-19 18:21:24 -07004642 }
4643 }
Aniket Kumar Latadebab2b2018-04-30 20:20:25 -07004644end:
jiabin8962a4d2018-03-19 18:21:24 -07004645 *mic_count = actual_mic_count;
4646 return 0;
4647}
Haynes Mathew George65f6b432018-02-27 17:44:55 -08004648
4649int platform_set_usb_service_interval(void *platform,
4650 bool playback,
4651 unsigned long service_interval,
4652 bool *reconfig)
4653{
4654#if defined (USB_SERVICE_INTERVAL_ENABLED)
4655 struct platform_data *_platform = (struct platform_data *)platform;
4656 *reconfig = false;
4657 if (!playback) {
4658 ALOGE("%s not valid for capture", __func__);
4659 return -1;
4660 }
4661 const char *ctl_name = "USB_AUDIO_RX service_interval";
4662 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4663 ctl_name);
4664 if (!ctl) {
4665 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4666 return -1;
4667 }
4668 if (mixer_ctl_get_value(ctl, 0) != (int)service_interval) {
4669 mixer_ctl_set_value(ctl, 0, service_interval);
4670 *reconfig = true;
4671 }
4672 return 0;
4673#else
4674 *reconfig = false;
4675 (void)platform;
4676 (void)playback;
4677 (void)service_interval;
4678 return -1;
4679#endif
4680}
4681
4682int platform_get_usb_service_interval(void *platform,
4683 bool playback,
4684 unsigned long *service_interval)
4685{
4686#if defined (USB_SERVICE_INTERVAL_ENABLED)
4687 struct platform_data *_platform = (struct platform_data *)platform;
4688 if (!playback) {
4689 ALOGE("%s not valid for capture", __func__);
4690 return -1;
4691 }
4692 const char *ctl_name = "USB_AUDIO_RX service_interval";
4693 struct mixer_ctl *ctl = mixer_get_ctl_by_name(_platform->adev->mixer,
4694 ctl_name);
4695 if (!ctl) {
4696 ALOGV("%s: could not get mixer %s", __func__, ctl_name);
4697 return -1;
4698 }
4699 *service_interval = mixer_ctl_get_value(ctl, 0);
4700 return 0;
4701#else
4702 (void)platform;
4703 (void)playback;
4704 (void)service_interval;
4705 return -1;
4706#endif
4707}