blob: 6560d148b30d4ea3908e69510d08076ff56e8f4e [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>
Eric Laurentb23d5282013-05-14 15:27:20 -070024#include <cutils/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>
Haynes Mathew George96483a22017-03-28 14:52:47 -070033#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
34#include <sound/devdep_params.h>
35#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070036
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090037#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
38#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080039#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
40#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
41
Eric Laurentb23d5282013-05-14 15:27:20 -070042#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070043#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090044#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070045
Eric Laurentf9583c32016-03-28 13:50:50 -070046#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070047
48/*
Eric Laurentb23d5282013-05-14 15:27:20 -070049 * This file will have a maximum of 38 bytes:
50 *
51 * 4 bytes: number of audio blocks
52 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
53 * Maximum 10 * 3 bytes: SAD blocks
54 */
55#define MAX_SAD_BLOCKS 10
56#define SAD_BLOCK_SIZE 3
57
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090058#define MAX_CVD_VERSION_STRING_SIZE 100
59
Eric Laurentb23d5282013-05-14 15:27:20 -070060/* EDID format ID for LPCM audio */
61#define EDID_FORMAT_LPCM 1
62
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070063#define MAX_SND_CARD_NAME_LEN 31
64
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080065#define DEFAULT_APP_TYPE_RX_PATH 69936
66#define DEFAULT_APP_TYPE_TX_PATH 69938
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070067#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
vivek mehta1a9b7c02015-06-25 11:49:38 -070068
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090069#define TOSTRING_(x) #x
70#define TOSTRING(x) TOSTRING_(x)
71
Eric Laurentb23d5282013-05-14 15:27:20 -070072struct audio_block_header
73{
74 int reserved;
75 int length;
76};
77
vivek mehta1a9b7c02015-06-25 11:49:38 -070078enum {
79 CAL_MODE_SEND = 0x1,
80 CAL_MODE_PERSIST = 0x2,
81 CAL_MODE_RTAC = 0x4
82};
83
keunhui.park2f7306a2015-07-16 16:48:06 +090084#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
85
86struct operator_info {
87 struct listnode list;
88 char *name;
89 char *mccmnc;
90};
91
92struct operator_specific_device {
93 struct listnode list;
94 char *operator;
95 char *mixer_path;
96 int acdb_id;
97};
98
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080099#define BE_DAI_NAME_MAX_LENGTH 24
100struct be_dai_name_struct {
101 unsigned int be_id;
102 char be_name[BE_DAI_NAME_MAX_LENGTH];
103};
104
keunhui.park2f7306a2015-07-16 16:48:06 +0900105static struct listnode operator_info_list;
106static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
107
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700108/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800109typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700110
Eric Laurentb23d5282013-05-14 15:27:20 -0700111struct platform_data {
112 struct audio_device *adev;
113 bool fluence_in_spkr_mode;
114 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700115 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700116 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700117 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
118 int fluence_type;
119 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700120 bool speaker_lr_swap;
121
Eric Laurentb23d5282013-05-14 15:27:20 -0700122 void *acdb_handle;
Thierry Strudel92232b42017-01-26 10:51:48 -0800123#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700124 acdb_init_v2_cvd_t acdb_init;
125#elif defined (PLATFORM_MSM8084)
126 acdb_init_v2_t acdb_init;
127#else
128 acdb_init_t acdb_init;
129#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700130 acdb_deallocate_t acdb_deallocate;
131 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800132 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700133 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700134 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700135 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700136 acdb_send_custom_top_t acdb_send_custom_top;
137 bool acdb_initialized;
138
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700139 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800140 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700141
David Linee3fe402017-03-13 10:00:42 -0700142 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700143 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900144 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700145 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800146
147 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700148};
149
Haynes Mathew George98c95622014-06-20 19:14:25 -0700150static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700151 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
152 DEEP_BUFFER_PCM_DEVICE},
153 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
154 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800155 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700156 MULTIMEDIA2_PCM_DEVICE},
157 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
158 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700159 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
160 MULTIMEDIA2_PCM_DEVICE},
161 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
162 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800163 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
164 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700165
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700166 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
167 AUDIO_RECORD_PCM_DEVICE},
168 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
169 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700170
Eric Laurent0e46adf2016-12-16 12:49:24 -0800171 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
172 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700173 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
174 MULTIMEDIA2_PCM_DEVICE},
175
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700176 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
177 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700178 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
179 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
180 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
181 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800182 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
183 VOICEMMODE1_CALL_PCM_DEVICE},
184 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
185 VOICEMMODE2_CALL_PCM_DEVICE},
186
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700187 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
188 AUDIO_RECORD_PCM_DEVICE},
189 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
190 AUDIO_RECORD_PCM_DEVICE},
191 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
192 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800193 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700194
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700195 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
196 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
197
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700198 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
199 AFE_PROXY_RECORD_PCM_DEVICE},
200 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
201 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800202 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700203
vivek mehtaa68fea62017-06-08 19:04:02 -0700204 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
205 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
206 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
207 AUDIO_RECORD_VOIP_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700208};
209
210/* Array to store sound devices */
211static const char * const device_table[SND_DEVICE_MAX] = {
212 [SND_DEVICE_NONE] = "none",
213 /* Playback sound devices */
214 [SND_DEVICE_OUT_HANDSET] = "handset",
215 [SND_DEVICE_OUT_SPEAKER] = "speaker",
216 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700217 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700218 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500219 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700220 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700221 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500222 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700223 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700224 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500225 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700226 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
227 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500228 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700229 [SND_DEVICE_OUT_HDMI] = "hdmi",
230 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
231 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700232 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700233 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
234 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
235 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
236 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800237 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
238 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700239 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700240 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700241 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700242 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700243 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700244 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700245 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700246 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
247 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700248 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800249 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
250 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700251
252 /* Capture sound devices */
253 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700254 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700255 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
256 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
257 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
258 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
259 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
260 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
261 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
262
263 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
264 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
265 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
266 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
267 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
268 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
269 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
270 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
271 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
272
273 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500274 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700275
Eric Laurentb23d5282013-05-14 15:27:20 -0700276 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
277 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700278 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700279 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700280 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700281 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700282
283 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
284 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
285 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
286 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700287 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700288 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700289 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
290 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
291 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800292 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
293 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700294
Eric Laurentb23d5282013-05-14 15:27:20 -0700295 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700296 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700297 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700298 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700299 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
300 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700301 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700302 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
303 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
304 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
305 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700306 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700307
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700308 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700309 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
310 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
311 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
312 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800313
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700314 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700315
Prashant Malanic92c5962015-08-11 15:10:18 -0700316 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
317 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700318 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700319 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
320 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700321 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
322 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700323};
324
325/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700326static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700327 [SND_DEVICE_NONE] = -1,
328 [SND_DEVICE_OUT_HANDSET] = 7,
329 [SND_DEVICE_OUT_SPEAKER] = 15,
330 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700331 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700332 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500333 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700334 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700335 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500336 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700337 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700338 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
339 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500340 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700341 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500342 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700343 [SND_DEVICE_OUT_HDMI] = 18,
344 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
345 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700346 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700347 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700348 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
349 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
350 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800351 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
352 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700353 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700354 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700355 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700356 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700357 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700358 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700359 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700360 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
361 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700362 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700363
364 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700365 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
366 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
367 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
368 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
369 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
370 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
371 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
372 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
373
374 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
375 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
376 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
377 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
378 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
379 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
380 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
381 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
382 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
383
rago90fb9612015-12-02 11:37:53 -0800384 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500385 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700386
Eric Laurentb23d5282013-05-14 15:27:20 -0700387 [SND_DEVICE_IN_HDMI_MIC] = 4,
388 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700389 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700390 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700391 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700392 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700393
394 [SND_DEVICE_IN_VOICE_DMIC] = 41,
395 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
396 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700397 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700398 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800399 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700400 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
401 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
402 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800403 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
404 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700405
rago90fb9612015-12-02 11:37:53 -0800406 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700407 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700408 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700409 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700410 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
411 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800412 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
413
414 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
415 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700416 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
417 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
418 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700419
420 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700421 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700422 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
423 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
424 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
425 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700426 [SND_DEVICE_IN_THREE_MIC] = 46,
427 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700428 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700429 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
430 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700431 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
432 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700433};
434
David Linee3fe402017-03-13 10:00:42 -0700435// Platform specific backend bit width table
436static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
437
Haynes Mathew George98c95622014-06-20 19:14:25 -0700438struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700439 char name[100];
440 unsigned int index;
441};
442
443#define TO_NAME_INDEX(X) #X, X
444
Haynes Mathew George98c95622014-06-20 19:14:25 -0700445/* Used to get index from parsed string */
446static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
447 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700448 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
449 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
450 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700451 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700452 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500453 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700454 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700455 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500456 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700457 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700458 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
459 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700460 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700461 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500462 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700463 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
464 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
465 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
466 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700467 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500468 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700469 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
470 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
471 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800472 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
473 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800474 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
475 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700476 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700477 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700478 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700479 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700480 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700481 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700482 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
483 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800484
485 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700486 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700487 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700488 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
489 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
490 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
491 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
492 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
493 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
494 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
495
496 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700497 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700498 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
499 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
500 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
501 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
502 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
503 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
504 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
505
506 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700507 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700508
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700509 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
510 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700511 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700512 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700513 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700514 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700515
516 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
517 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
518 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700519 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700520 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
521 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700522 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
523 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
524 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800525 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
526 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
527
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700528
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700529 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700530 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700531 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700532 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700533 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
534 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700535 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700536 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700537 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
538 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
539 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
540 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700541
rago90fb9612015-12-02 11:37:53 -0800542 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700544 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
545 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
546 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800547
Prashant Malanic92c5962015-08-11 15:10:18 -0700548 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
549 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700550 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700551 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
552 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700553 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
554 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700555};
556
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700557static char * backend_tag_table[SND_DEVICE_MAX] = {0};
558static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700559
560static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
561 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
562 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800563 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700564 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700565 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
566 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800567 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700568 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
569 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800570 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700571 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700572 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
573 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
574 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
575 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
576 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800577 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
578 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700579 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
580 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
581 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
582 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800583 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
584 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
585 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
586 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
587 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700588 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
589 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700590};
591
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800592static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
593 {TO_NAME_INDEX(PCM_PLAYBACK)},
594 {TO_NAME_INDEX(PCM_CAPTURE)},
595 {TO_NAME_INDEX(VOICE_CALL)},
596 {TO_NAME_INDEX(PCM_HFP_CALL)},
597};
598
599struct app_type_entry {
600 int uc_type;
601 int bit_width;
602 int app_type;
603 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700604 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800605 struct listnode node; // membership in app_type_entry_list;
606};
607
608static struct listnode app_type_entry_list;
609
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700610#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
611#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800612#define ULL_PLATFORM_DELAY (3*1000LL)
613#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700614
Eric Laurentb23d5282013-05-14 15:27:20 -0700615static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
616static bool is_tmus = false;
617
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800618static int init_be_dai_name_table(struct audio_device *adev);
619
Eric Laurentb23d5282013-05-14 15:27:20 -0700620static void check_operator()
621{
622 char value[PROPERTY_VALUE_MAX];
623 int mccmnc;
624 property_get("gsm.sim.operator.numeric",value,"0");
625 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700626 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700627 switch(mccmnc) {
628 /* TMUS MCC(310), MNC(490, 260, 026) */
629 case 310490:
630 case 310260:
631 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900632 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
633 case 310800:
634 case 310660:
635 case 310580:
636 case 310310:
637 case 310270:
638 case 310250:
639 case 310240:
640 case 310230:
641 case 310220:
642 case 310210:
643 case 310200:
644 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700645 is_tmus = true;
646 break;
647 }
648}
649
650bool is_operator_tmus()
651{
652 pthread_once(&check_op_once_ctl, check_operator);
653 return is_tmus;
654}
655
keunhui.park2f7306a2015-07-16 16:48:06 +0900656static char *get_current_operator()
657{
658 struct listnode *node;
659 struct operator_info *info_item;
660 char mccmnc[PROPERTY_VALUE_MAX];
661 char *ret = NULL;
662
Tom Cherry7fea2042016-11-10 18:05:59 -0800663 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900664
665 list_for_each(node, &operator_info_list) {
666 info_item = node_to_item(node, struct operator_info, list);
667 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
668 ret = info_item->name;
669 }
670 }
671
672 return ret;
673}
674
675static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
676{
677 struct listnode *node;
678 struct operator_specific_device *ret = NULL;
679 struct operator_specific_device *device_item;
680 char *operator_name;
681
682 operator_name = get_current_operator();
683 if (operator_name == NULL)
684 return ret;
685
686 list_for_each(node, operator_specific_device_table[snd_device]) {
687 device_item = node_to_item(node, struct operator_specific_device, list);
688 if (strcmp(operator_name, device_item->operator) == 0) {
689 ret = device_item;
690 }
691 }
692
693 return ret;
694}
695
696
697static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
698{
699 struct operator_specific_device *device;
700 int ret = acdb_device_table[snd_device];
701
702 device = get_operator_specific_device(snd_device);
703 if (device != NULL)
704 ret = device->acdb_id;
705
706 return ret;
707}
708
709static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
710{
711 struct operator_specific_device *device;
712 const char *ret = device_table[snd_device];
713
714 device = get_operator_specific_device(snd_device);
715 if (device != NULL)
716 ret = device->mixer_path;
717
718 return ret;
719}
720
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800721inline bool platform_supports_app_type_cfg()
722{
723#ifdef PLATFORM_MSM8998
724 return true;
725#else
726 return false;
727#endif
728}
729
vivek mehta1a9b7c02015-06-25 11:49:38 -0700730bool platform_send_gain_dep_cal(void *platform, int level)
731{
732 bool ret_val = false;
733 struct platform_data *my_data = (struct platform_data *)platform;
734 struct audio_device *adev = my_data->adev;
735 int acdb_dev_id, app_type;
736 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
737 int mode = CAL_MODE_RTAC;
738 struct listnode *node;
739 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700740 bool valid_uc_type;
741 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700742
743 if (my_data->acdb_send_gain_dep_cal == NULL) {
744 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
745 return ret_val;
746 }
747
748 if (!voice_is_in_call(adev)) {
749 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
750 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700751
752 // find the current active sound device
753 list_for_each(node, &adev->usecase_list) {
754 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700755 LOG_ALWAYS_FATAL_IF(usecase == NULL,
756 "unxpected NULL usecase in usecase_list");
757 valid_uc_type = usecase->type == PCM_PLAYBACK;
758 valid_dev = false;
759 if (valid_uc_type) {
760 audio_devices_t dev = usecase->stream.out->devices;
761 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700762 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700763 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
764 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
765 }
766 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700767 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
768 if (platform_supports_app_type_cfg())
769 app_type = usecase->stream.out->app_type_cfg.app_type;
770 else
771 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700772
vivek mehta40125092017-08-21 18:48:51 -0700773 if (audio_extn_spkr_prot_is_enabled())
774 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
775 else
776 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
777
778 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700779 acdb_dev_type, mode, level)) {
780 // set ret_val true if at least one calibration is set successfully
781 ret_val = true;
782 } else {
783 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
784 }
785 } else {
786 ALOGW("%s: Usecase list is empty", __func__);
787 }
788 }
789 } else {
790 ALOGW("%s: Voice call in progress .. ignore setting new cal",
791 __func__);
792 }
793 return ret_val;
794}
795
Eric Laurentcefbbac2014-09-04 13:54:10 -0500796void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700797{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800798 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500799 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700800
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800801 if (strcmp(my_data->ec_ref_mixer_path, "")) {
802 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
803 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500804 }
805
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800806 if (enable) {
807 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
808 if (out_device != AUDIO_DEVICE_NONE) {
809 snd_device = platform_get_output_snd_device(adev->platform, out_device);
810 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
811 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500812
Joe Onorato188b6222016-03-01 11:02:27 -0800813 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800814 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
815 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700816}
817
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700818static struct csd_data *open_csd_client(bool i2s_ext_modem)
819{
820 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
821
822 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
823 if (csd->csd_client == NULL) {
824 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
825 goto error;
826 } else {
827 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
828
829 csd->deinit = (deinit_t)dlsym(csd->csd_client,
830 "csd_client_deinit");
831 if (csd->deinit == NULL) {
832 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
833 dlerror());
834 goto error;
835 }
836 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
837 "csd_client_disable_device");
838 if (csd->disable_device == NULL) {
839 ALOGE("%s: dlsym error %s for csd_client_disable_device",
840 __func__, dlerror());
841 goto error;
842 }
843 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
844 "csd_client_enable_device_config");
845 if (csd->enable_device_config == NULL) {
846 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
847 __func__, dlerror());
848 goto error;
849 }
850 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
851 "csd_client_enable_device");
852 if (csd->enable_device == NULL) {
853 ALOGE("%s: dlsym error %s for csd_client_enable_device",
854 __func__, dlerror());
855 goto error;
856 }
857 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
858 "csd_client_start_voice");
859 if (csd->start_voice == NULL) {
860 ALOGE("%s: dlsym error %s for csd_client_start_voice",
861 __func__, dlerror());
862 goto error;
863 }
864 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
865 "csd_client_stop_voice");
866 if (csd->stop_voice == NULL) {
867 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
868 __func__, dlerror());
869 goto error;
870 }
871 csd->volume = (volume_t)dlsym(csd->csd_client,
872 "csd_client_volume");
873 if (csd->volume == NULL) {
874 ALOGE("%s: dlsym error %s for csd_client_volume",
875 __func__, dlerror());
876 goto error;
877 }
878 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
879 "csd_client_mic_mute");
880 if (csd->mic_mute == NULL) {
881 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
882 __func__, dlerror());
883 goto error;
884 }
885 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
886 "csd_client_slow_talk");
887 if (csd->slow_talk == NULL) {
888 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
889 __func__, dlerror());
890 goto error;
891 }
892 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
893 "csd_client_start_playback");
894 if (csd->start_playback == NULL) {
895 ALOGE("%s: dlsym error %s for csd_client_start_playback",
896 __func__, dlerror());
897 goto error;
898 }
899 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
900 "csd_client_stop_playback");
901 if (csd->stop_playback == NULL) {
902 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
903 __func__, dlerror());
904 goto error;
905 }
906 csd->start_record = (start_record_t)dlsym(csd->csd_client,
907 "csd_client_start_record");
908 if (csd->start_record == NULL) {
909 ALOGE("%s: dlsym error %s for csd_client_start_record",
910 __func__, dlerror());
911 goto error;
912 }
913 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
914 "csd_client_stop_record");
915 if (csd->stop_record == NULL) {
916 ALOGE("%s: dlsym error %s for csd_client_stop_record",
917 __func__, dlerror());
918 goto error;
919 }
920
921 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
922 "csd_client_get_sample_rate");
923 if (csd->get_sample_rate == NULL) {
924 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
925 __func__, dlerror());
926
927 goto error;
928 }
929
930 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
931
932 if (csd->init == NULL) {
933 ALOGE("%s: dlsym error %s for csd_client_init",
934 __func__, dlerror());
935 goto error;
936 } else {
937 csd->init(i2s_ext_modem);
938 }
939 }
940 return csd;
941
942error:
943 free(csd);
944 csd = NULL;
945 return csd;
946}
947
948void close_csd_client(struct csd_data *csd)
949{
950 if (csd != NULL) {
951 csd->deinit();
952 dlclose(csd->csd_client);
953 free(csd);
954 csd = NULL;
955 }
956}
957
958static void platform_csd_init(struct platform_data *my_data)
959{
960#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700961 int32_t modems, (*count_modems)(void);
962 const char *name = "libdetectmodem.so";
963 const char *func = "count_modems";
964 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700965
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700966 my_data->csd = NULL;
967
968 void *lib = dlopen(name, RTLD_NOW);
969 error = dlerror();
970 if (!lib) {
971 ALOGE("%s: could not find %s: %s", __func__, name, error);
972 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700973 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700974
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700975 count_modems = NULL;
976 *(void **)(&count_modems) = dlsym(lib, func);
977 error = dlerror();
978 if (!count_modems) {
979 ALOGE("%s: could not find symbol %s in %s: %s",
980 __func__, func, name, error);
981 goto done;
982 }
983
984 modems = count_modems();
985 if (modems < 0) {
986 ALOGE("%s: count_modems failed\n", __func__);
987 goto done;
988 }
989
Eric Laurent2bafff12016-03-17 12:17:23 -0700990 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700991 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700992 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700993
994done:
995 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700996#else
997 my_data->csd = NULL;
998#endif
999}
1000
Eric Laurentc6333382015-09-14 12:43:44 -07001001static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001002{
1003 int32_t dev;
1004 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001005 backend_tag_table[dev] = NULL;
1006 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001007 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001008 }
1009
David Linee3fe402017-03-13 10:00:42 -07001010 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1011 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1012 }
1013
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001014 // To overwrite these go to the audio_platform_info.xml file.
1015 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001016 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001017 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1018 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1019 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1020 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1021 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001022 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001023 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1024 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001025
David Linee3fe402017-03-13 10:00:42 -07001026 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001027 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001028 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001029 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001030 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1031 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001032 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1033 strdup("speaker-safe-and-usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001034 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001035 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1036 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1037 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1038 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001039 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1040 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1041 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1042 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1043 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1044 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1045 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001046 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001047 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001048 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001049 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1050 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1051 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1052 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1053 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1054 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1055 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1056 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1057 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
1058 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1059 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1060 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1061 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001062 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001063 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1064 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001065 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001066 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001067 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001068 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 -07001069 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 -07001070 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1071 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1072 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001073 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1074 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1075 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1076 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1077 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1078 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1079 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
1080 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1081 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1082 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1083 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1084 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001085 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1086 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
1087 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1088 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001089 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1090 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1091 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1092 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1093 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001094 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1095 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1096 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1097 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1098 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1099 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1100 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1101 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1102 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1103 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001104 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001105}
1106
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001107void get_cvd_version(char *cvd_version, struct audio_device *adev)
1108{
1109 struct mixer_ctl *ctl;
1110 int count;
1111 int ret = 0;
1112
1113 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1114 if (!ctl) {
1115 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1116 goto done;
1117 }
1118 mixer_ctl_update(ctl);
1119
1120 count = mixer_ctl_get_num_values(ctl);
1121 if (count > MAX_CVD_VERSION_STRING_SIZE)
1122 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1123
1124 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1125 if (ret != 0) {
1126 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1127 goto done;
1128 }
1129
1130done:
1131 return;
1132}
1133
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001134static int platform_acdb_init(void *platform)
1135{
1136 struct platform_data *my_data = (struct platform_data *)platform;
1137 struct audio_device *adev = my_data->adev;
1138
1139 if (!my_data->acdb_init) {
1140 ALOGE("%s: no acdb_init fn provided", __func__);
1141 return -1;
1142 }
1143
1144 if (my_data->acdb_initialized) {
1145 ALOGW("acdb is already initialized");
1146 return 0;
1147 }
1148
Thierry Strudel92232b42017-01-26 10:51:48 -08001149#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001150 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1151 if (!cvd_version)
1152 ALOGE("failed to allocate cvd_version");
1153 else {
1154 get_cvd_version(cvd_version, adev);
1155 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1156 free(cvd_version);
1157 }
1158#elif defined (PLATFORM_MSM8084)
1159 my_data->acdb_init((char *)my_data->snd_card_name);
1160#else
1161 my_data->acdb_init();
1162#endif
1163 my_data->acdb_initialized = true;
1164 return 0;
1165}
1166
David Linee3fe402017-03-13 10:00:42 -07001167static void
1168platform_backend_config_init(struct platform_data *pdata)
1169{
1170 int i;
1171
1172 /* initialize backend config */
1173 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1174 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1175 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1176 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1177
1178 if (i > MAX_RX_CODEC_BACKENDS)
1179 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1180
1181 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1182 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1183 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1184 }
1185
1186 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1187 strdup("SLIM_0_RX Format");
1188 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1189 strdup("SLIM_0_RX SampleRate");
1190
1191 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1192 strdup("SLIM_0_TX Format");
1193 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1194 strdup("SLIM_0_TX SampleRate");
1195
1196 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1197 strdup("USB_AUDIO_TX Format");
1198 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1199 strdup("USB_AUDIO_TX SampleRate");
1200 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1201 strdup("USB_AUDIO_TX Channels");
1202
1203 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1204 strdup("SLIM_6_RX Format");
1205 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1206 strdup("SLIM_6_RX SampleRate");
1207
1208 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1209 strdup("USB_AUDIO_RX Format");
1210 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1211 strdup("USB_AUDIO_RX SampleRate");
1212
1213 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1214 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1215 strdup("USB_AUDIO_RX Channels");
1216}
1217
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001218static int
1219platform_backend_app_type_cfg_init(struct platform_data *pdata,
1220 struct mixer *mixer)
1221{
1222 size_t app_type_cfg[128] = {0};
1223 int length, num_app_types = 0;
1224 struct mixer_ctl *ctl = NULL;
1225
1226 const char *mixer_ctl_name = "App Type Config";
1227 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1228 if (!ctl) {
1229 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1230 return -1;
1231 }
1232
1233 length = 1; // reserve index 0 for number of app types
1234
1235 struct listnode *node;
1236 struct app_type_entry *entry;
1237 list_for_each(node, &app_type_entry_list) {
1238 entry = node_to_item(node, struct app_type_entry, node);
1239 app_type_cfg[length++] = entry->app_type;
1240 app_type_cfg[length++] = entry->max_rate;
1241 app_type_cfg[length++] = entry->bit_width;
1242 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1243 num_app_types += 1;
1244 }
1245
1246 // default for capture
1247 int t;
1248 platform_get_default_app_type_v2(pdata,
1249 PCM_CAPTURE,
1250 &t);
1251 app_type_cfg[length++] = t;
1252 app_type_cfg[length++] = 48000;
1253 app_type_cfg[length++] = 16;
1254 num_app_types += 1;
1255
1256 if (num_app_types) {
1257 app_type_cfg[0] = num_app_types;
1258 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1259 ALOGE("Failed to set app type cfg");
1260 }
1261 }
1262 return 0;
1263}
1264
Eric Laurentb23d5282013-05-14 15:27:20 -07001265void *platform_init(struct audio_device *adev)
1266{
1267 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001268 struct platform_data *my_data = NULL;
1269 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1270 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001271 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001272 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001273 char *snd_internal_name = NULL;
1274 char *tmp = NULL;
1275 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001276 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1277 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001278 my_data = calloc(1, sizeof(struct platform_data));
1279
1280 my_data->adev = adev;
1281
keunhui.park2f7306a2015-07-16 16:48:06 +09001282 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001283 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001284
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001285 set_platform_defaults(my_data);
1286
vivek mehta0fb11312017-05-15 19:35:32 -07001287 // audio_extn_utils_get_snd_card_num does
1288 // - open mixer and get snd card name
1289 // - parse platform info xml file and check for valid snd card name
1290 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001291
vivek mehta0fb11312017-05-15 19:35:32 -07001292 snd_card_num = audio_extn_utils_get_snd_card_num();
1293 if (-1 == snd_card_num) {
1294 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1295 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001296 }
1297
vivek mehta0fb11312017-05-15 19:35:32 -07001298 adev->mixer = mixer_open(snd_card_num);
1299 snd_card_name = mixer_get_name(adev->mixer);
1300 my_data->hw_info = hw_info_init(snd_card_name);
1301
1302 audio_extn_set_snd_card_split(snd_card_name);
1303 snd_split_handle = audio_extn_get_snd_card_split();
1304
1305 /* Get the codec internal name from the sound card and/or form factor
1306 * name and form the mixer paths and platfor info file name dynamically.
1307 * This is generic way of picking any codec and forma factor name based
1308 * mixer and platform info files in future with no code change.
1309
1310 * current code extends and looks for any of the exteneded mixer path and
1311 * platform info file present based on codec and form factor.
1312
1313 * order of picking appropriate file is
1314 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1315 * <ii> mixer_paths_<codec_name>.xml, if file not present
1316 * <iii> mixer_paths.xml
1317
1318 * same order is followed for audio_platform_info.xml as well
1319 */
1320
1321 // need to carryforward old file name
1322 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1323 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1324 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1325 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1326 } else {
1327
1328 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1329 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1330 snd_split_handle->form_factor);
1331 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1332 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1333 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1334 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1335
1336 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1337 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1338 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1339 audio_extn_utils_resolve_config_file(mixer_xml_file);
1340 }
1341 }
1342 }
1343
1344 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1345
1346 /* Initialize platform specific ids and/or backends*/
1347 platform_info_init(platform_info_file, my_data);
1348
1349 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1350 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1351
1352 if (!adev->audio_route) {
1353 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1354 mixer_close(adev->mixer);
1355 adev->mixer = NULL;
1356 hw_info_deinit(my_data->hw_info);
1357 my_data->hw_info = NULL;
1358 goto init_failed;
1359 }
1360 adev->snd_card = snd_card_num;
1361 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1362
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001363 //set max volume step for voice call
1364 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1365 my_data->max_vol_index = atoi(value);
1366
vivek mehta65ad12d2015-08-13 18:32:48 -07001367 property_get("persist.audio.dualmic.config",value,"");
1368 if (!strcmp("endfire", value)) {
1369 dual_mic_config = true;
1370 }
1371
Prashant Malanic92c5962015-08-11 15:10:18 -07001372 my_data->source_mic_type = SOURCE_DUAL_MIC;
1373
Eric Laurentb23d5282013-05-14 15:27:20 -07001374 my_data->fluence_in_spkr_mode = false;
1375 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001376 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001377 my_data->fluence_in_voice_rec = false;
1378
vivek mehta65ad12d2015-08-13 18:32:48 -07001379 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001380 if (!strcmp("fluencepro", value)) {
1381 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001382 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001383 my_data->fluence_type = FLUENCE_ENABLE;
1384 } else if (!strcmp("none", value)) {
1385 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001386 }
1387
Prashant Malanic92c5962015-08-11 15:10:18 -07001388 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001389 property_get("persist.audio.fluence.voicecall",value,"");
1390 if (!strcmp("true", value)) {
1391 my_data->fluence_in_voice_call = true;
1392 }
1393
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001394 property_get("persist.audio.fluence.voicecomm",value,"");
1395 if (!strcmp("true", value)) {
1396 my_data->fluence_in_voice_comm = true;
1397 }
1398
Eric Laurentb23d5282013-05-14 15:27:20 -07001399 property_get("persist.audio.fluence.voicerec",value,"");
1400 if (!strcmp("true", value)) {
1401 my_data->fluence_in_voice_rec = true;
1402 }
1403
1404 property_get("persist.audio.fluence.speaker",value,"");
1405 if (!strcmp("true", value)) {
1406 my_data->fluence_in_spkr_mode = true;
1407 }
1408 }
1409
Prashant Malanic92c5962015-08-11 15:10:18 -07001410 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1411 switch (my_data->max_mic_count) {
1412 case 4:
1413 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1414 case 3:
1415 my_data->source_mic_type |= SOURCE_THREE_MIC;
1416 case 2:
1417 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1418 case 1:
1419 my_data->source_mic_type |= SOURCE_MONO_MIC;
1420 break;
1421 default:
1422 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1423 __func__, my_data->max_mic_count);
1424 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1425 break;
1426 }
1427
1428 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1429 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1430 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1431 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1432 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1433
Eric Laurentb23d5282013-05-14 15:27:20 -07001434 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1435 if (my_data->acdb_handle == NULL) {
1436 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1437 } else {
1438 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1439 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1440 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001441 if (!my_data->acdb_deallocate)
1442 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1443 __func__, LIB_ACDB_LOADER);
1444
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001445 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1446 "acdb_loader_send_audio_cal_v3");
1447 if (!my_data->acdb_send_audio_cal_v3)
1448 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1449 __func__, LIB_ACDB_LOADER);
1450
Eric Laurentb23d5282013-05-14 15:27:20 -07001451 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1452 "acdb_loader_send_audio_cal");
1453 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001454 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001455 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001456
Eric Laurentb23d5282013-05-14 15:27:20 -07001457 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1458 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001459 if (!my_data->acdb_send_voice_cal)
1460 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1461 __func__, LIB_ACDB_LOADER);
1462
1463 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1464 "acdb_loader_reload_vocvoltable");
1465 if (!my_data->acdb_reload_vocvoltable)
1466 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1467 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001468
1469 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1470 "acdb_loader_send_gain_dep_cal");
1471 if (!my_data->acdb_send_gain_dep_cal)
1472 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1473 __func__, LIB_ACDB_LOADER);
1474
Thierry Strudel92232b42017-01-26 10:51:48 -08001475#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
vivek mehta0fb11312017-05-15 19:35:32 -07001476 acdb_init_v2_cvd_t acdb_init_local;
1477 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001478 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001479 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001480 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1481 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001482
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001483#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001484 acdb_init_v2_t acdb_init_local;
1485 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001486 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001487 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001488 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1489 dlerror());
1490
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001491#else
vivek mehta0fb11312017-05-15 19:35:32 -07001492 acdb_init_t acdb_init_local;
1493 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001494 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001495 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001496 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1497 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001498#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001499 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001500
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001501 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1502 dlsym(my_data->acdb_handle,
1503 "acdb_loader_send_common_custom_topology");
1504
1505 if (!my_data->acdb_send_custom_top)
1506 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1507 __func__, LIB_ACDB_LOADER);
1508
vivek mehta0fb11312017-05-15 19:35:32 -07001509 int result = acdb_init(adev->snd_card);
1510 if (!result) {
1511 my_data->acdb_initialized = true;
1512 ALOGD("ACDB initialized");
1513 } else {
1514 my_data->acdb_initialized = false;
1515 ALOGD("ACDB initialization failed");
1516 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001517 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001518
David Linee3fe402017-03-13 10:00:42 -07001519 /* init usb */
1520 audio_extn_usb_init(adev);
1521
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001522 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001523
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001524 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1525
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001526 /* load csd client */
1527 platform_csd_init(my_data);
1528
David Linee3fe402017-03-13 10:00:42 -07001529 platform_backend_config_init(my_data);
1530
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001531 init_be_dai_name_table(adev);
1532
1533 if (platform_supports_app_type_cfg())
1534 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1535
Eric Laurentb23d5282013-05-14 15:27:20 -07001536 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001537
1538init_failed:
1539 if (my_data)
1540 free(my_data);
1541 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001542}
1543
1544void platform_deinit(void *platform)
1545{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001546 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001547 struct operator_info *info_item;
1548 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001549 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001550 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001551
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001552 struct platform_data *my_data = (struct platform_data *)platform;
1553 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001554
vivek mehtade4849c2016-03-03 17:23:38 -08001555 hw_info_deinit(my_data->hw_info);
1556
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001557 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1558 if (backend_tag_table[dev])
1559 free(backend_tag_table[dev]);
1560 if (hw_interface_table[dev])
1561 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001562 if (operator_specific_device_table[dev]) {
1563 while (!list_empty(operator_specific_device_table[dev])) {
1564 node = list_head(operator_specific_device_table[dev]);
1565 list_remove(node);
1566 device_item = node_to_item(node, struct operator_specific_device, list);
1567 free(device_item->operator);
1568 free(device_item->mixer_path);
1569 free(device_item);
1570 }
1571 free(operator_specific_device_table[dev]);
1572 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001573 }
1574
1575 if (my_data->snd_card_name)
1576 free(my_data->snd_card_name);
1577
keunhui.park2f7306a2015-07-16 16:48:06 +09001578 while (!list_empty(&operator_info_list)) {
1579 node = list_head(&operator_info_list);
1580 list_remove(node);
1581 info_item = node_to_item(node, struct operator_info, list);
1582 free(info_item->name);
1583 free(info_item->mccmnc);
1584 free(info_item);
1585 }
1586
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001587 while (!list_empty(&app_type_entry_list)) {
1588 node = list_head(&app_type_entry_list);
1589 list_remove(node);
1590 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001591 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001592 free(ap);
1593 }
1594
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001595 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001596 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001597
1598 /* deinit usb */
1599 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001600}
1601
1602const char *platform_get_snd_device_name(snd_device_t snd_device)
1603{
keunhui.park2f7306a2015-07-16 16:48:06 +09001604 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1605 if (operator_specific_device_table[snd_device] != NULL) {
1606 return get_operator_specific_device_mixer_path(snd_device);
1607 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001608 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001609 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001610 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001611}
1612
vivek mehtade4849c2016-03-03 17:23:38 -08001613int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1614 char *device_name)
1615{
1616 struct platform_data *my_data = (struct platform_data *)platform;
1617
David Benjamin1565f992016-09-21 12:10:34 -04001618 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001619 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001620 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1621 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001622 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1623 if (operator_specific_device_table[snd_device] != NULL) {
1624 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1625 DEVICE_NAME_MAX_SIZE);
1626 } else {
1627 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1628 }
1629 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1630 } else {
1631 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1632 }
1633
1634 return 0;
1635}
1636
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001637void platform_add_backend_name(void *platform, char *mixer_path,
1638 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001639{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001640 struct platform_data *my_data = (struct platform_data *)platform;
1641
Haynes Mathew George98c95622014-06-20 19:14:25 -07001642 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1643 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1644 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001645 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001646
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001647 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001648
1649 if (suffix != NULL) {
1650 strcat(mixer_path, " ");
1651 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001652 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001653}
1654
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001655bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1656{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001657 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1658 platform_get_snd_device_name(snd_device1),
1659 platform_get_snd_device_name(snd_device2));
1660
1661 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1662 ALOGE("%s: Invalid snd_device = %s", __func__,
1663 platform_get_snd_device_name(snd_device1));
1664 return false;
1665 }
1666 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1667 ALOGE("%s: Invalid snd_device = %s", __func__,
1668 platform_get_snd_device_name(snd_device2));
1669 return false;
1670 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001671
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001672 const char * be_itf1 = hw_interface_table[snd_device1];
1673 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001674 /*
1675 hw_interface_table has overrides for a snd_device.
1676 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1677 */
1678 if (be_itf1 == NULL) {
1679 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001680 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001681 if (be_itf2 == NULL) {
1682 be_itf2 = DEFAULT_RX_BACKEND;
1683 }
1684 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1685 /*
1686 this takes care of finding a device within a combo device pair as well
1687 */
1688 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001689}
1690
Eric Laurentb23d5282013-05-14 15:27:20 -07001691int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1692{
1693 int device_id;
1694 if (device_type == PCM_PLAYBACK)
1695 device_id = pcm_device_table[usecase][0];
1696 else
1697 device_id = pcm_device_table[usecase][1];
1698 return device_id;
1699}
1700
Haynes Mathew George98c95622014-06-20 19:14:25 -07001701static int find_index(const struct name_to_index * table, int32_t len,
1702 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001703{
1704 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001705 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001706
Haynes Mathew George98c95622014-06-20 19:14:25 -07001707 if (table == NULL) {
1708 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001709 ret = -ENODEV;
1710 goto done;
1711 }
1712
Haynes Mathew George98c95622014-06-20 19:14:25 -07001713 if (name == NULL) {
1714 ALOGE("null key");
1715 ret = -ENODEV;
1716 goto done;
1717 }
1718
1719 for (i=0; i < len; i++) {
1720 if (!strcmp(table[i].name, name)) {
1721 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001722 goto done;
1723 }
1724 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001725 ALOGE("%s: Could not find index for name = %s",
1726 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001727 ret = -ENODEV;
1728done:
1729 return ret;
1730}
1731
Haynes Mathew George98c95622014-06-20 19:14:25 -07001732int platform_get_snd_device_index(char *device_name)
1733{
1734 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1735}
1736
1737int platform_get_usecase_index(const char *usecase_name)
1738{
1739 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1740}
1741
keunhui.park2f7306a2015-07-16 16:48:06 +09001742void platform_add_operator_specific_device(snd_device_t snd_device,
1743 const char *operator,
1744 const char *mixer_path,
1745 unsigned int acdb_id)
1746{
1747 struct operator_specific_device *device;
1748
1749 if (operator_specific_device_table[snd_device] == NULL) {
1750 operator_specific_device_table[snd_device] =
1751 (struct listnode *)calloc(1, sizeof(struct listnode));
1752 list_init(operator_specific_device_table[snd_device]);
1753 }
1754
1755 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1756
1757 device->operator = strdup(operator);
1758 device->mixer_path = strdup(mixer_path);
1759 device->acdb_id = acdb_id;
1760
1761 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1762
Eric Laurent2bafff12016-03-17 12:17:23 -07001763 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001764 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1765
1766}
1767
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001768int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1769{
1770 int ret = 0;
1771
1772 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1773 ALOGE("%s: Invalid snd_device = %d",
1774 __func__, snd_device);
1775 ret = -EINVAL;
1776 goto done;
1777 }
1778
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001779 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1780 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001781 acdb_device_table[snd_device] = acdb_id;
1782done:
1783 return ret;
1784}
1785
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001786int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1787{
1788 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1789 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1790 return -EINVAL;
1791 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001792
1793 if (operator_specific_device_table[snd_device] != NULL)
1794 return get_operator_specific_device_acdb_id(snd_device);
1795 else
1796 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001797}
1798
David Linee3fe402017-03-13 10:00:42 -07001799static int platform_get_backend_index(snd_device_t snd_device)
1800{
1801 int32_t port = DEFAULT_CODEC_BACKEND;
1802
1803 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1804 if (backend_tag_table[snd_device] != NULL) {
1805 if (strncmp(backend_tag_table[snd_device], "headphones",
1806 sizeof("headphones")) == 0)
1807 port = HEADPHONE_BACKEND;
1808 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1809 port = HDMI_RX_BACKEND;
1810 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1811 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1812 port = USB_AUDIO_RX_BACKEND;
1813 }
1814 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1815 port = DEFAULT_CODEC_TX_BACKEND;
1816 if (backend_tag_table[snd_device] != NULL) {
1817 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1818 port = USB_AUDIO_TX_BACKEND;
1819 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1820 port = BT_SCO_TX_BACKEND;
1821 }
1822 } else {
1823 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1824 }
1825
1826 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1827
1828 return port;
1829}
1830
Eric Laurentb23d5282013-05-14 15:27:20 -07001831int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1832{
1833 struct platform_data *my_data = (struct platform_data *)platform;
1834 int acdb_dev_id, acdb_dev_type;
1835
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001836 if (platform_supports_app_type_cfg()) // use v2 instead
1837 return -ENOSYS;
1838
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001839 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001840 if (acdb_dev_id < 0) {
1841 ALOGE("%s: Could not find acdb id for device(%d)",
1842 __func__, snd_device);
1843 return -EINVAL;
1844 }
1845 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001846 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001847 __func__, snd_device, acdb_dev_id);
1848 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1849 snd_device < SND_DEVICE_OUT_END)
1850 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1851 else
1852 acdb_dev_type = ACDB_DEV_TYPE_IN;
1853 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1854 }
1855 return 0;
1856}
1857
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001858int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1859 int app_type, int sample_rate)
1860{
1861 struct platform_data *my_data = (struct platform_data *)platform;
1862 int acdb_dev_id, acdb_dev_type;
1863 int snd_device = SND_DEVICE_OUT_SPEAKER;
1864 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1865 int i, num_devices = 1;
1866
1867 if (!platform_supports_app_type_cfg()) // use v1 instead
1868 return -ENOSYS;
1869
1870 if (usecase->type == PCM_PLAYBACK)
1871 snd_device = usecase->out_snd_device;
1872 else if (usecase->type == PCM_CAPTURE)
1873 snd_device = usecase->in_snd_device;
1874
1875 // skipped over get_spkr_prot_device
1876 acdb_dev_id = acdb_device_table[snd_device];
1877 if (acdb_dev_id < 0) {
1878 ALOGE("%s: Could not find acdb id for device(%d)",
1879 __func__, snd_device);
1880 return -EINVAL;
1881 }
1882
1883 if (platform_can_split_snd_device(snd_device,
1884 &num_devices, new_snd_device) < 0) {
1885 new_snd_device[0] = snd_device;
1886 }
1887
1888 for (i = 0; i < num_devices; i++) {
1889 acdb_dev_id = acdb_device_table[new_snd_device[i]];
1890 if (acdb_dev_id < 0) {
1891 ALOGE("%s: Could not find acdb id for device(%d)",
1892 __func__, new_snd_device[i]);
1893 return -EINVAL;
1894 }
1895 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1896 __func__, new_snd_device[i], acdb_dev_id);
1897 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1898 new_snd_device[i] < SND_DEVICE_OUT_END)
1899 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1900 else
1901 acdb_dev_type = ACDB_DEV_TYPE_IN;
1902
1903 if (my_data->acdb_send_audio_cal_v3) {
1904 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1905 app_type, sample_rate, i);
1906 } else if (my_data->acdb_send_audio_cal) {
1907 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
1908 }
1909 }
1910
1911 return 0;
1912}
1913
1914
Eric Laurentb23d5282013-05-14 15:27:20 -07001915int platform_switch_voice_call_device_pre(void *platform)
1916{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001917 struct platform_data *my_data = (struct platform_data *)platform;
1918 int ret = 0;
1919
1920 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001921 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001922 /* This must be called before disabling mixer controls on APQ side */
1923 ret = my_data->csd->disable_device();
1924 if (ret < 0) {
1925 ALOGE("%s: csd_client_disable_device, failed, error %d",
1926 __func__, ret);
1927 }
1928 }
1929 return ret;
1930}
1931
1932int platform_switch_voice_call_enable_device_config(void *platform,
1933 snd_device_t out_snd_device,
1934 snd_device_t in_snd_device)
1935{
1936 struct platform_data *my_data = (struct platform_data *)platform;
1937 int acdb_rx_id, acdb_tx_id;
1938 int ret = 0;
1939
1940 if (my_data->csd == NULL)
1941 return ret;
1942
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001943 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1944 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001945 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001946 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001947 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001948
keunhui.park2f7306a2015-07-16 16:48:06 +09001949 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001950
1951 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1952 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1953 if (ret < 0) {
1954 ALOGE("%s: csd_enable_device_config, failed, error %d",
1955 __func__, ret);
1956 }
1957 } else {
1958 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1959 acdb_rx_id, acdb_tx_id);
1960 }
1961
1962 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001963}
1964
1965int platform_switch_voice_call_device_post(void *platform,
1966 snd_device_t out_snd_device,
1967 snd_device_t in_snd_device)
1968{
1969 struct platform_data *my_data = (struct platform_data *)platform;
1970 int acdb_rx_id, acdb_tx_id;
1971
1972 if (my_data->acdb_send_voice_cal == NULL) {
1973 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1974 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001975 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1976 audio_extn_spkr_prot_is_enabled())
1977 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1978
keunhui.park2f7306a2015-07-16 16:48:06 +09001979 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1980 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001981
1982 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1983 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1984 else
1985 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1986 acdb_rx_id, acdb_tx_id);
1987 }
1988
1989 return 0;
1990}
1991
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001992int platform_switch_voice_call_usecase_route_post(void *platform,
1993 snd_device_t out_snd_device,
1994 snd_device_t in_snd_device)
1995{
1996 struct platform_data *my_data = (struct platform_data *)platform;
1997 int acdb_rx_id, acdb_tx_id;
1998 int ret = 0;
1999
2000 if (my_data->csd == NULL)
2001 return ret;
2002
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002003 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2004 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09002005 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002006 else
keunhui.park2f7306a2015-07-16 16:48:06 +09002007 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002008
keunhui.park2f7306a2015-07-16 16:48:06 +09002009 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002010
2011 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2012 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2013 my_data->adev->acdb_settings);
2014 if (ret < 0) {
2015 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2016 }
2017 } else {
2018 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2019 acdb_rx_id, acdb_tx_id);
2020 }
2021
2022 return ret;
2023}
2024
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002025int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002026{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002027 struct platform_data *my_data = (struct platform_data *)platform;
2028 int ret = 0;
2029
2030 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002031 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002032 if (ret < 0) {
2033 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2034 }
2035 }
2036 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002037}
2038
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002039int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002040{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002041 struct platform_data *my_data = (struct platform_data *)platform;
2042 int ret = 0;
2043
2044 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002045 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002046 if (ret < 0) {
2047 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2048 }
2049 }
2050 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002051}
2052
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002053int platform_get_sample_rate(void *platform, uint32_t *rate)
2054{
2055 struct platform_data *my_data = (struct platform_data *)platform;
2056 int ret = 0;
2057
2058 if (my_data->csd != NULL) {
2059 ret = my_data->csd->get_sample_rate(rate);
2060 if (ret < 0) {
2061 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2062 }
2063 }
2064 return ret;
2065}
2066
vivek mehtab6506412015-08-07 16:55:17 -07002067void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2068 snd_device_t snd_device,
2069 bool enable)
2070{
2071 const char* name;
2072 switch (snd_device) {
2073 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2074 if (enable)
2075 name = "spkr-gain-in-headphone-combo";
2076 else
2077 name = "speaker-gain-default";
2078 break;
2079 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2080 if (enable)
2081 name = "spkr-gain-in-line-combo";
2082 else
2083 name = "speaker-gain-default";
2084 break;
2085 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2086 if (enable)
2087 name = "spkr-safe-gain-in-headphone-combo";
2088 else
2089 name = "speaker-safe-gain-default";
2090 break;
2091 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2092 if (enable)
2093 name = "spkr-safe-gain-in-line-combo";
2094 else
2095 name = "speaker-safe-gain-default";
2096 break;
2097 default:
2098 return;
2099 }
2100
2101 audio_route_apply_and_update_path(adev->audio_route, name);
2102}
2103
Eric Laurentb23d5282013-05-14 15:27:20 -07002104int platform_set_voice_volume(void *platform, int volume)
2105{
2106 struct platform_data *my_data = (struct platform_data *)platform;
2107 struct audio_device *adev = my_data->adev;
2108 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002109 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002110 int vol_index = 0, ret = 0;
2111 uint32_t set_values[ ] = {0,
2112 ALL_SESSION_VSID,
2113 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002114
2115 // Voice volume levels are mapped to adsp volume levels as follows.
2116 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2117 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002118 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002119 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002120
2121 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2122 if (!ctl) {
2123 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2124 __func__, mixer_ctl_name);
2125 return -EINVAL;
2126 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002127 ALOGV("Setting voice volume index: %d", set_values[0]);
2128 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2129
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002130 if (my_data->csd != NULL) {
2131 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2132 DEFAULT_VOLUME_RAMP_DURATION_MS);
2133 if (ret < 0) {
2134 ALOGE("%s: csd_volume error %d", __func__, ret);
2135 }
2136 }
2137 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002138}
2139
2140int platform_set_mic_mute(void *platform, bool state)
2141{
2142 struct platform_data *my_data = (struct platform_data *)platform;
2143 struct audio_device *adev = my_data->adev;
2144 struct mixer_ctl *ctl;
2145 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002146 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002147 uint32_t set_values[ ] = {0,
2148 ALL_SESSION_VSID,
2149 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002150
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002151 if (adev->mode != AUDIO_MODE_IN_CALL &&
2152 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002153 return 0;
2154
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002155 if (adev->enable_hfp)
2156 mixer_ctl_name = "HFP Tx Mute";
2157
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002158 set_values[0] = state;
2159 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2160 if (!ctl) {
2161 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2162 __func__, mixer_ctl_name);
2163 return -EINVAL;
2164 }
2165 ALOGV("Setting voice mute state: %d", state);
2166 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2167
2168 if (my_data->csd != NULL) {
2169 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2170 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002171 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002172 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002173 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002174 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002175 return ret;
2176}
Eric Laurentb23d5282013-05-14 15:27:20 -07002177
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002178int platform_set_device_mute(void *platform, bool state, char *dir)
2179{
2180 struct platform_data *my_data = (struct platform_data *)platform;
2181 struct audio_device *adev = my_data->adev;
2182 struct mixer_ctl *ctl;
2183 char *mixer_ctl_name = NULL;
2184 int ret = 0;
2185 uint32_t set_values[ ] = {0,
2186 ALL_SESSION_VSID,
2187 0};
2188 if(dir == NULL) {
2189 ALOGE("%s: Invalid direction:%s", __func__, dir);
2190 return -EINVAL;
2191 }
2192
2193 if (!strncmp("rx", dir, sizeof("rx"))) {
2194 mixer_ctl_name = "Voice Rx Device Mute";
2195 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2196 mixer_ctl_name = "Voice Tx Device Mute";
2197 } else {
2198 return -EINVAL;
2199 }
2200
2201 set_values[0] = state;
2202 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2203 if (!ctl) {
2204 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2205 __func__, mixer_ctl_name);
2206 return -EINVAL;
2207 }
2208
2209 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2210 __func__,state, mixer_ctl_name);
2211 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2212
2213 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002214}
2215
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002216int platform_can_split_snd_device(snd_device_t snd_device,
2217 int *num_devices,
2218 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002219{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002220 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002221 if (NULL == num_devices || NULL == new_snd_devices) {
2222 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002223 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002224 }
2225
2226 /*
2227 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002228 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002229 */
2230 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2231 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2232 *num_devices = 2;
2233 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2234 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002235 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002236 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2237 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2238 *num_devices = 2;
2239 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2240 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002241 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002242 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2243 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2244 *num_devices = 2;
2245 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2246 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002247 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002248 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2249 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2250 *num_devices = 2;
2251 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2252 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002253 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002254 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2255 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2256 SND_DEVICE_OUT_BT_SCO)) {
2257 *num_devices = 2;
2258 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2259 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2260 ret = 0;
2261 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2262 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2263 SND_DEVICE_OUT_BT_SCO_WB)) {
2264 *num_devices = 2;
2265 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2266 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2267 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002268 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2269 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2270 *num_devices = 2;
2271 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2272 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2273 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002274 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2275 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2276 *num_devices = 2;
2277 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2278 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2279 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002280 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002281 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002282}
2283
Eric Laurentb23d5282013-05-14 15:27:20 -07002284snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2285{
2286 struct platform_data *my_data = (struct platform_data *)platform;
2287 struct audio_device *adev = my_data->adev;
2288 audio_mode_t mode = adev->mode;
2289 snd_device_t snd_device = SND_DEVICE_NONE;
2290
2291 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2292 if (devices == AUDIO_DEVICE_NONE ||
2293 devices & AUDIO_DEVICE_BIT_IN) {
2294 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2295 goto exit;
2296 }
2297
Eric Laurent1b491552015-09-15 17:52:41 -07002298 if (popcount(devices) == 2) {
2299 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2300 AUDIO_DEVICE_OUT_SPEAKER) ||
2301 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2302 AUDIO_DEVICE_OUT_SPEAKER)) {
2303 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2304 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2305 AUDIO_DEVICE_OUT_SPEAKER)) {
2306 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2307 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2308 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2309 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2310 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2311 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2312 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2313 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2314 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2315 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2316 AUDIO_DEVICE_OUT_SPEAKER)) {
2317 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002318 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2319 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2320 snd_device = adev->bt_wb_speech_enabled ?
2321 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2322 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002323 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2324 AUDIO_DEVICE_OUT_SPEAKER)) ||
2325 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2326 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002327 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002328 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2329 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2330 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2331 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002332 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002333 } else {
2334 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2335 goto exit;
2336 }
2337 if (snd_device != SND_DEVICE_NONE) {
2338 goto exit;
2339 }
2340 }
2341
2342 if (popcount(devices) != 1) {
2343 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2344 goto exit;
2345 }
2346
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302347 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002348 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002349 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2350 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002351 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002352 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002353 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002354 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002355 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002356 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002357 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002358 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002359 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002360 else {
2361 if (devices & AUDIO_DEVICE_OUT_LINE)
2362 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2363 else
2364 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2365 }
Eric Laurent99dab492017-06-17 15:19:08 -07002366 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002367 if (voice_is_in_call(adev)) {
2368 switch (adev->voice.tty_mode) {
2369 case TTY_MODE_FULL:
2370 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2371 break;
2372 case TTY_MODE_VCO:
2373 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2374 break;
2375 case TTY_MODE_HCO:
2376 // since Hearing will be on handset\speaker, use existing device
2377 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2378 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002379 case TTY_MODE_OFF:
2380 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002381 default:
2382 ALOGE("%s: Invalid TTY mode (%#x)",
2383 __func__, adev->voice.tty_mode);
2384 }
2385 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002386 if (snd_device == SND_DEVICE_NONE) {
2387 snd_device = audio_extn_usb_is_capture_supported() ?
2388 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2389 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2390 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002391 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002392 if (adev->bt_wb_speech_enabled) {
2393 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2394 } else {
2395 snd_device = SND_DEVICE_OUT_BT_SCO;
2396 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002397 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002398 if (!adev->enable_hfp) {
2399 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2400 } else {
2401 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2402 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002403 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002404 if(adev->voice.hac)
2405 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2406 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002407 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2408 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002409 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002410 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2411 snd_device = SND_DEVICE_OUT_VOICE_TX;
2412
Eric Laurentb23d5282013-05-14 15:27:20 -07002413 if (snd_device != SND_DEVICE_NONE) {
2414 goto exit;
2415 }
2416 }
2417
Eric Laurentb23d5282013-05-14 15:27:20 -07002418 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2419 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2420 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002421 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2422 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002423 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2424 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002425 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002426 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002427 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2428 else
2429 snd_device = SND_DEVICE_OUT_SPEAKER;
2430 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002431 if (adev->bt_wb_speech_enabled) {
2432 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2433 } else {
2434 snd_device = SND_DEVICE_OUT_BT_SCO;
2435 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002436 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2437 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002438 } else if (audio_is_usb_out_device(devices)) {
David Linee3fe402017-03-13 10:00:42 -07002439 if (audio_extn_usb_is_capture_supported())
2440 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2441 else
2442 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2443 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002444 /*HAC support for voice-ish audio (eg visual voicemail)*/
2445 if(adev->voice.hac)
2446 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2447 else
2448 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002449 } else {
2450 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2451 }
2452exit:
2453 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2454 return snd_device;
2455}
2456
2457snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2458{
2459 struct platform_data *my_data = (struct platform_data *)platform;
2460 struct audio_device *adev = my_data->adev;
2461 audio_source_t source = (adev->active_input == NULL) ?
2462 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2463
2464 audio_mode_t mode = adev->mode;
2465 audio_devices_t in_device = ((adev->active_input == NULL) ?
2466 AUDIO_DEVICE_NONE : adev->active_input->device)
2467 & ~AUDIO_DEVICE_BIT_IN;
2468 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2469 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2470 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002471 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002472
Prashant Malanic92c5962015-08-11 15:10:18 -07002473 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2474 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002475 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2476 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002477 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002478 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002479 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2480 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002481 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002482 case TTY_MODE_FULL:
2483 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2484 break;
2485 case TTY_MODE_VCO:
2486 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2487 break;
2488 case TTY_MODE_HCO:
2489 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2490 break;
2491 default:
2492 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2493 }
2494 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002495 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002496 switch (adev->voice.tty_mode) {
2497 case TTY_MODE_FULL:
2498 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2499 break;
2500 case TTY_MODE_VCO:
2501 // since voice will be captured from handset mic, use existing device
2502 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2503 break;
2504 case TTY_MODE_HCO:
2505 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2506 break;
2507 default:
2508 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002509 }
2510 goto exit;
2511 }
2512 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002513 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002514 if (my_data->fluence_in_voice_call == false) {
2515 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2516 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002517 if (is_operator_tmus())
2518 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002519 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002520 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002521 }
2522 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2523 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2524 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002525 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002526 if (adev->bluetooth_nrec)
2527 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2528 else
2529 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002530 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002531 if (adev->bluetooth_nrec)
2532 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2533 else
2534 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002535 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002536 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002537 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2538 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2539 out_device & AUDIO_DEVICE_OUT_LINE) {
2540 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2541 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2542 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2543 } else {
2544 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2545 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002546 }
vivek mehtafe121d52015-08-10 23:39:23 -07002547
2548 //select default
2549 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002550 if (!adev->enable_hfp) {
2551 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2552 } else {
2553 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2554 platform_set_echo_reference(adev, true, out_device);
2555 }
vivek mehtafe121d52015-08-10 23:39:23 -07002556 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002557 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002558 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002559 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002560 if (audio_extn_usb_is_capture_supported()) {
2561 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2562 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2563 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2564 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2565 } else {
2566 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2567 }
2568 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002569 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002570 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2571 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2572 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2573 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2574 }
2575 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2576 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002577 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2578 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2579 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002580 if (adev->active_input->enable_aec)
2581 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2582 else
2583 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002584 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2585 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002586 if (adev->active_input->enable_aec)
2587 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2588 else
2589 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002590 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2591 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2592 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002593 if (adev->active_input->enable_aec)
2594 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2595 else
2596 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002597 }
2598 platform_set_echo_reference(adev, true, out_device);
2599 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2600 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2601 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002602 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002603 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2604 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002605 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002606 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2607 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002608 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002609 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002610 if (adev->active_input->enable_aec) {
2611 if (adev->active_input->enable_ns) {
2612 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2613 } else {
2614 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2615 }
vivek mehta733c1df2016-04-04 15:09:24 -07002616 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002617 } else if (adev->active_input->enable_ns) {
2618 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2619 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002620 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002621 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002622 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002623 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2624 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002625 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002626 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002627 }
rago90fb9612015-12-02 11:37:53 -08002628 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2629 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002630 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2631 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2632 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2633 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002634 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002635 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2636 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002637 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002638 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2639 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2640 } else {
2641 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2642 }
rago90fb9612015-12-02 11:37:53 -08002643 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2644 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002645 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002646 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002647 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002648 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002649 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002650 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2651 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2652 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2653 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002654 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002655 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002656 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002657 if (adev->active_input->enable_aec &&
2658 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002659 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002660 if (my_data->fluence_in_spkr_mode &&
2661 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002662 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002663 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002664 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002665 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002666 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002667 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002668 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002669 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002670 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002671 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002672 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002673 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002674 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2675 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002676 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002677 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002678 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002679 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002680 } else if (adev->active_input->enable_aec) {
2681 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2682 if (my_data->fluence_in_spkr_mode &&
2683 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002684 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002685 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002686 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002687 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002688 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002689 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2690 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002691 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002692 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002693 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002694 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002695 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002696 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2697 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002698 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002699 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002700 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002701 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002702 } else if (adev->active_input->enable_ns) {
2703 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2704 if (my_data->fluence_in_spkr_mode &&
2705 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002706 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002707 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002708 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002709 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002710 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002711 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2712 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002713 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002714 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002715 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002716 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002717 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002718 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002719 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002720 }
2721 } else if (source == AUDIO_SOURCE_DEFAULT) {
2722 goto exit;
2723 }
2724
2725
2726 if (snd_device != SND_DEVICE_NONE) {
2727 goto exit;
2728 }
2729
2730 if (in_device != AUDIO_DEVICE_NONE &&
2731 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2732 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2733 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002734 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002735 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002736 snd_device = SND_DEVICE_IN_QUAD_MIC;
2737 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002738 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002739 snd_device = SND_DEVICE_IN_THREE_MIC;
2740 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2741 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002742 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002743 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2744 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002745 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002746 } else {
2747 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2748 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2749 my_data->source_mic_type, channel_count, channel_mask);
2750 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2751 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002752 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002753 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2754 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002755 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002756 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2757 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002758 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002759 } else {
2760 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2761 " no combination found .. setting to mono", __func__,
2762 my_data->source_mic_type, channel_count);
2763 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2764 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002765 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2766 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2767 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002768 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002769 if (adev->bluetooth_nrec)
2770 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2771 else
2772 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002773 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002774 if (adev->bluetooth_nrec)
2775 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2776 else
2777 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002778 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002779 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2780 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002781 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07002782 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002783 } else {
2784 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2785 ALOGW("%s: Using default handset-mic", __func__);
2786 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2787 }
2788 } else {
2789 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2790 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2791 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2792 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002793 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002794 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002795 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002796 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002797 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2798 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002799 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002800 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2801 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002802 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002803 } else {
2804 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2805 " no combination found .. setting to mono", __func__,
2806 my_data->source_mic_type, channel_count);
2807 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2808 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002809 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002810 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002811 if (adev->bluetooth_nrec)
2812 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2813 else
2814 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002815 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002816 if (adev->bluetooth_nrec)
2817 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2818 else
2819 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002820 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002821 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2822 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002823 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07002824 if (audio_extn_usb_is_capture_supported())
2825 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2826 else
2827 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002828 } else {
2829 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2830 ALOGW("%s: Using default handset-mic", __func__);
2831 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2832 }
2833 }
2834exit:
2835 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2836 return snd_device;
2837}
2838
2839int platform_set_hdmi_channels(void *platform, int channel_count)
2840{
2841 struct platform_data *my_data = (struct platform_data *)platform;
2842 struct audio_device *adev = my_data->adev;
2843 struct mixer_ctl *ctl;
2844 const char *channel_cnt_str = NULL;
2845 const char *mixer_ctl_name = "HDMI_RX Channels";
2846 switch (channel_count) {
2847 case 8:
2848 channel_cnt_str = "Eight"; break;
2849 case 7:
2850 channel_cnt_str = "Seven"; break;
2851 case 6:
2852 channel_cnt_str = "Six"; break;
2853 case 5:
2854 channel_cnt_str = "Five"; break;
2855 case 4:
2856 channel_cnt_str = "Four"; break;
2857 case 3:
2858 channel_cnt_str = "Three"; break;
2859 default:
2860 channel_cnt_str = "Two"; break;
2861 }
2862 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2863 if (!ctl) {
2864 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2865 __func__, mixer_ctl_name);
2866 return -EINVAL;
2867 }
2868 ALOGV("HDMI channel count: %s", channel_cnt_str);
2869 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2870 return 0;
2871}
2872
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002873int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002874{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002875 struct platform_data *my_data = (struct platform_data *)platform;
2876 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002877 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2878 char *sad = block;
2879 int num_audio_blocks;
2880 int channel_count;
2881 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002882 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002883
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002884 struct mixer_ctl *ctl;
2885
2886 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2887 if (!ctl) {
2888 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2889 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002890 return 0;
2891 }
2892
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002893 mixer_ctl_update(ctl);
2894
2895 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002896
2897 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002898 if (count > (int)sizeof(block))
2899 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002900
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002901 ret = mixer_ctl_get_array(ctl, block, count);
2902 if (ret != 0) {
2903 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2904 return 0;
2905 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002906
2907 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002908 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002909
2910 for (i = 0; i < num_audio_blocks; i++) {
2911 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002912 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2913 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002914 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002915 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002916
2917 channel_count = (sad[0] & 0x7) + 1;
2918 if (channel_count > max_channels)
2919 max_channels = channel_count;
2920
2921 /* Advance to next block */
2922 sad += 3;
2923 }
2924
2925 return max_channels;
2926}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002927
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002928int platform_set_incall_recording_session_id(void *platform,
2929 uint32_t session_id, int rec_mode)
2930{
2931 int ret = 0;
2932 struct platform_data *my_data = (struct platform_data *)platform;
2933 struct audio_device *adev = my_data->adev;
2934 struct mixer_ctl *ctl;
2935 const char *mixer_ctl_name = "Voc VSID";
2936 int num_ctl_values;
2937 int i;
2938
2939 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2940 if (!ctl) {
2941 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2942 __func__, mixer_ctl_name);
2943 ret = -EINVAL;
2944 } else {
2945 num_ctl_values = mixer_ctl_get_num_values(ctl);
2946 for (i = 0; i < num_ctl_values; i++) {
2947 if (mixer_ctl_set_value(ctl, i, session_id)) {
2948 ALOGV("Error: invalid session_id: %x", session_id);
2949 ret = -EINVAL;
2950 break;
2951 }
2952 }
2953 }
2954
2955 if (my_data->csd != NULL) {
2956 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2957 if (ret < 0) {
2958 ALOGE("%s: csd_client_start_record failed, error %d",
2959 __func__, ret);
2960 }
2961 }
2962
2963 return ret;
2964}
2965
2966int platform_stop_incall_recording_usecase(void *platform)
2967{
2968 int ret = 0;
2969 struct platform_data *my_data = (struct platform_data *)platform;
2970
2971 if (my_data->csd != NULL) {
2972 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2973 if (ret < 0) {
2974 ALOGE("%s: csd_client_stop_record failed, error %d",
2975 __func__, ret);
2976 }
2977 }
2978
2979 return ret;
2980}
2981
2982int platform_start_incall_music_usecase(void *platform)
2983{
2984 int ret = 0;
2985 struct platform_data *my_data = (struct platform_data *)platform;
2986
2987 if (my_data->csd != NULL) {
2988 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2989 if (ret < 0) {
2990 ALOGE("%s: csd_client_start_playback failed, error %d",
2991 __func__, ret);
2992 }
2993 }
2994
2995 return ret;
2996}
2997
2998int platform_stop_incall_music_usecase(void *platform)
2999{
3000 int ret = 0;
3001 struct platform_data *my_data = (struct platform_data *)platform;
3002
3003 if (my_data->csd != NULL) {
3004 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3005 if (ret < 0) {
3006 ALOGE("%s: csd_client_stop_playback failed, error %d",
3007 __func__, ret);
3008 }
3009 }
3010
3011 return ret;
3012}
3013
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003014int platform_set_parameters(void *platform, struct str_parms *parms)
3015{
3016 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09003017 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003018 char *kv_pairs = str_parms_to_str(parms);
3019 int ret = 0, err;
3020
3021 if (kv_pairs == NULL) {
3022 ret = -EINVAL;
3023 ALOGE("%s: key-value pair is NULL",__func__);
3024 goto done;
3025 }
3026
3027 ALOGV("%s: enter: %s", __func__, kv_pairs);
3028
3029 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
3030 value, sizeof(value));
3031 if (err >= 0) {
3032 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3033 my_data->snd_card_name = strdup(value);
3034 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3035 }
3036
keunhui.park2f7306a2015-07-16 16:48:06 +09003037 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
3038 value, sizeof(value));
3039 if (err >= 0) {
3040 struct operator_info *info;
3041 char *str = value;
3042 char *name;
3043
3044 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3045 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3046 name = strtok(str, ";");
3047 info->name = strdup(name);
3048 info->mccmnc = strdup(str + strlen(name) + 1);
3049
3050 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003051 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003052 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003053
3054 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07003055 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07003056 value, sizeof(value));
3057 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003058 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003059 my_data->max_mic_count = atoi(value);
3060 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003061 }
3062
vivek mehta90933872017-06-15 18:04:39 -07003063 // to-do: disable setting sidetone gain, will revist this later
3064 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003065done:
3066 ALOGV("%s: exit with code(%d)", __func__, ret);
3067 if (kv_pairs != NULL)
3068 free(kv_pairs);
3069
3070 return ret;
3071}
3072
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003073/* Delay in Us */
3074int64_t platform_render_latency(audio_usecase_t usecase)
3075{
3076 switch (usecase) {
3077 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3078 return DEEP_BUFFER_PLATFORM_DELAY;
3079 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3080 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003081 case USECASE_AUDIO_PLAYBACK_ULL:
3082 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003083 case USECASE_AUDIO_PLAYBACK_MMAP:
3084 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003085 default:
3086 return 0;
3087 }
3088}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003089
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003090int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3091 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003092{
3093 int ret = 0;
3094
3095 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3096 ALOGE("%s: Invalid snd_device = %d",
3097 __func__, device);
3098 ret = -EINVAL;
3099 goto done;
3100 }
3101
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003102 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3103 platform_get_snd_device_name(device),
3104 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3105 if (backend_tag_table[device]) {
3106 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003107 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003108 backend_tag_table[device] = strdup(backend_tag);
3109
3110 if (hw_interface != NULL) {
3111 if (hw_interface_table[device])
3112 free(hw_interface_table[device]);
3113 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3114 hw_interface_table[device] = strdup(hw_interface);
3115 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003116done:
3117 return ret;
3118}
3119
3120int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3121{
3122 int ret = 0;
3123 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3124 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3125 ret = -EINVAL;
3126 goto done;
3127 }
3128
3129 if ((type != 0) && (type != 1)) {
3130 ALOGE("%s: invalid usecase type", __func__);
3131 ret = -EINVAL;
3132 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003133 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3134 use_case_table[usecase],
3135 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003136 pcm_device_table[usecase][type] = pcm_id;
3137done:
3138 return ret;
3139}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003140
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003141#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3142int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3143 // backup_gain: gain to try to set in case of an error during ramp
3144 int start_gain, end_gain, step, backup_gain, i;
3145 bool error = false;
3146 const struct mixer_ctl *ctl;
3147 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3148 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3149 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3150 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3151 if (!ctl_left || !ctl_right) {
3152 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3153 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3154 return -EINVAL;
3155 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3156 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3157 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3158 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3159 return -EINVAL;
3160 }
3161 if (ramp_up) {
3162 start_gain = 0;
3163 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3164 step = +1;
3165 backup_gain = end_gain;
3166 } else {
3167 // using same gain on left and right
3168 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3169 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3170 end_gain = 0;
3171 step = -1;
3172 backup_gain = start_gain;
3173 }
3174 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3175 //ALOGV("setting speaker gain to %d", i);
3176 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3177 ALOGE("%s: error setting %s to %d during gain ramp",
3178 __func__, mixer_ctl_name_gain_left, i);
3179 error = true;
3180 break;
3181 }
3182 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3183 ALOGE("%s: error setting %s to %d during gain ramp",
3184 __func__, mixer_ctl_name_gain_right, i);
3185 error = true;
3186 break;
3187 }
3188 usleep(1000);
3189 }
3190 if (error) {
3191 // an error occured during the ramp, let's still try to go back to a safe volume
3192 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3193 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3194 }
3195 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3196 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3197 }
3198 }
3199 return start_gain;
3200}
3201
vivek mehtae59cfb22017-06-16 15:57:11 -07003202int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3203{
3204 const char *mixer_ctl_name = "Swap channel";
3205 struct mixer_ctl *ctl;
3206 const char *mixer_path;
3207 struct platform_data *my_data = (struct platform_data *)adev->platform;
3208
3209 // forced to set to swap, but device not rotated ... ignore set
3210 if (swap_channels && !my_data->speaker_lr_swap)
3211 return 0;
3212
3213 ALOGV("%s:", __func__);
3214
3215 if (swap_channels) {
3216 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3217 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3218 } else {
3219 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3220 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3221 }
3222
3223 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3224 if (!ctl) {
3225 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3226 return -EINVAL;
3227 }
3228
3229 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3230 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3231 return -EINVAL;
3232 }
3233
3234 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3235 swap_channels?"R --> L":"L --> R");
3236
3237 return 0;
3238}
3239
3240int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003241{
3242 // only update if there is active pcm playback on speaker
3243 struct audio_usecase *usecase;
3244 struct listnode *node;
3245 struct platform_data *my_data = (struct platform_data *)adev->platform;
3246
vivek mehtae59cfb22017-06-16 15:57:11 -07003247 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003248
vivek mehtae59cfb22017-06-16 15:57:11 -07003249 return platform_set_swap_channels(adev, swap_channels);
3250}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003251
vivek mehtae59cfb22017-06-16 15:57:11 -07003252int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3253{
3254 // only update if there is active pcm playback on speaker
3255 struct audio_usecase *usecase;
3256 struct listnode *node;
3257 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003258
vivek mehtae59cfb22017-06-16 15:57:11 -07003259 // do not swap channels in audio modes with concurrent capture and playback
3260 // as this may break the echo reference
3261 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3262 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3263 return 0;
3264 }
3265
3266 list_for_each(node, &adev->usecase_list) {
3267 usecase = node_to_item(node, struct audio_usecase, list);
3268 if (usecase->type == PCM_PLAYBACK &&
3269 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3270 /*
3271 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3272 * to perform device switch to disable the current backend to
3273 * enable it with new acdb data.
3274 */
3275 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3276 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3277 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3278 select_devices(adev, usecase->id);
3279 if (initial_skpr_gain != -EINVAL)
3280 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3281
3282 } else {
3283 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003284 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003285 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003286 }
3287 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003288
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003289 return 0;
3290}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003291
3292static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3293static int num_gain_tbl_entry = 0;
3294
3295bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3296
3297 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3298 if (num_gain_tbl_entry == -1) {
3299 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3300 __func__);
3301 return false;
3302 }
3303
3304 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3305 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3306 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3307 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3308 return false;
3309 }
3310
3311 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3312 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3313 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3314 return false;
3315 }
3316
3317 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3318 ++num_gain_tbl_entry;
3319
3320 return true;
3321}
3322
3323int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3324 int table_size) {
3325 int itt = 0;
3326 ALOGV("platform_get_gain_level_mapping called ");
3327
3328 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3329 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3330 return 0;
3331 }
3332
3333 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3334 mapping_tbl[itt] = tbl_mapping[itt];
3335 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3336 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3337 }
3338
3339 return num_gain_tbl_entry;
3340}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003341
3342int platform_snd_card_update(void *platform, card_status_t status)
3343{
3344 struct platform_data *my_data = (struct platform_data *)platform;
3345 struct audio_device *adev = my_data->adev;
3346
3347 if (status == CARD_STATUS_ONLINE) {
3348 if (my_data->acdb_send_custom_top)
3349 my_data->acdb_send_custom_top();
3350 }
3351 return 0;
3352}
David Linee3fe402017-03-13 10:00:42 -07003353
3354/*
3355 * configures afe with bit width and Sample Rate
3356 */
3357static int platform_set_backend_cfg(const struct audio_device* adev,
3358 snd_device_t snd_device,
3359 const struct audio_backend_cfg *backend_cfg)
3360{
3361
3362 int ret = 0;
3363 const int backend_idx = platform_get_backend_index(snd_device);
3364 struct platform_data *my_data = (struct platform_data *)adev->platform;
3365 const unsigned int bit_width = backend_cfg->bit_width;
3366 const unsigned int sample_rate = backend_cfg->sample_rate;
3367 const unsigned int channels = backend_cfg->channels;
3368 const audio_format_t format = backend_cfg->format;
3369 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3370
3371
3372 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3373 ", backend_idx %d device (%s)", __func__, bit_width,
3374 sample_rate, channels, backend_idx,
3375 platform_get_snd_device_name(snd_device));
3376
3377 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3378 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3379
3380 struct mixer_ctl *ctl = NULL;
3381 ctl = mixer_get_ctl_by_name(adev->mixer,
3382 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3383 if (!ctl) {
3384 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3385 __func__,
3386 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3387 return -EINVAL;
3388 }
3389
3390 if (bit_width == 24) {
3391 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3392 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3393 else
3394 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3395 } else if (bit_width == 32) {
3396 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3397 } else {
3398 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3399 }
3400 if ( ret < 0) {
3401 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3402 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3403 } else {
3404 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3405 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3406 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3407 }
3408 /* set the ret as 0 and not pass back to upper layer */
3409 ret = 0;
3410 }
3411
3412 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3413 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3414 char *rate_str = NULL;
3415 struct mixer_ctl *ctl = NULL;
3416
3417 switch (sample_rate) {
3418 case 32000:
3419 if (passthrough_enabled) {
3420 rate_str = "KHZ_32";
3421 break;
3422 }
3423 case 8000:
3424 case 11025:
3425 case 16000:
3426 case 22050:
3427 case 48000:
3428 rate_str = "KHZ_48";
3429 break;
3430 case 44100:
3431 rate_str = "KHZ_44P1";
3432 break;
3433 case 64000:
3434 case 96000:
3435 rate_str = "KHZ_96";
3436 break;
3437 case 88200:
3438 rate_str = "KHZ_88P2";
3439 break;
3440 case 176400:
3441 rate_str = "KHZ_176P4";
3442 break;
3443 case 192000:
3444 rate_str = "KHZ_192";
3445 break;
3446 case 352800:
3447 rate_str = "KHZ_352P8";
3448 break;
3449 case 384000:
3450 rate_str = "KHZ_384";
3451 break;
3452 case 144000:
3453 if (passthrough_enabled) {
3454 rate_str = "KHZ_144";
3455 break;
3456 }
3457 default:
3458 rate_str = "KHZ_48";
3459 break;
3460 }
3461
3462 ctl = mixer_get_ctl_by_name(adev->mixer,
3463 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3464 if(!ctl) {
3465 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3466 __func__,
3467 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3468 return -EINVAL;
3469 }
3470
3471 ALOGD("%s:becf: afe: %s set to %s", __func__,
3472 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3473 mixer_ctl_set_enum_by_string(ctl, rate_str);
3474 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3475 }
3476 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3477 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3478 struct mixer_ctl *ctl = NULL;
3479 char *channel_cnt_str = NULL;
3480
3481 switch (channels) {
3482 case 8:
3483 channel_cnt_str = "Eight"; break;
3484 case 7:
3485 channel_cnt_str = "Seven"; break;
3486 case 6:
3487 channel_cnt_str = "Six"; break;
3488 case 5:
3489 channel_cnt_str = "Five"; break;
3490 case 4:
3491 channel_cnt_str = "Four"; break;
3492 case 3:
3493 channel_cnt_str = "Three"; break;
3494 case 1:
3495 channel_cnt_str = "One"; break;
3496 case 2:
3497 default:
3498 channel_cnt_str = "Two"; break;
3499 }
3500
3501 ctl = mixer_get_ctl_by_name(adev->mixer,
3502 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3503 if (!ctl) {
3504 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3505 __func__,
3506 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3507 return -EINVAL;
3508 }
3509 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3510 my_data->current_backend_cfg[backend_idx].channels = channels;
3511
3512 // skip EDID configuration for HDMI backend
3513
3514 ALOGD("%s:becf: afe: %s set to %s", __func__,
3515 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3516 channel_cnt_str);
3517 }
3518
3519 // skip set ext_display format mixer control
3520 return ret;
3521}
3522
3523static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3524{
3525 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3526 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3527 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3528 }
3529
3530 return backend_bit_width_table[snd_device];
3531}
3532
3533/*
3534 * return backend_idx on which voice call is active
3535 */
3536static int platform_get_voice_call_backend(struct audio_device* adev)
3537{
3538 struct audio_usecase *uc = NULL;
3539 struct listnode *node;
3540 snd_device_t out_snd_device = SND_DEVICE_NONE;
3541
3542 int backend_idx = -1;
3543
3544 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3545 list_for_each(node, &adev->usecase_list) {
3546 uc = node_to_item(node, struct audio_usecase, list);
3547 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3548 out_snd_device = platform_get_output_snd_device(adev->platform,
3549 uc->stream.out->devices);
3550 backend_idx = platform_get_backend_index(out_snd_device);
3551 break;
3552 }
3553 }
3554 }
3555 return backend_idx;
3556}
3557
3558/*
3559 * goes through all the current usecases and picks the highest
3560 * bitwidth & samplerate
3561 */
3562static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3563 int backend_idx,
3564 struct audio_backend_cfg *backend_cfg)
3565{
3566 bool backend_change = false;
3567 unsigned int bit_width;
3568 unsigned int sample_rate;
3569 unsigned int channels;
3570 struct platform_data *my_data = (struct platform_data *)adev->platform;
3571
3572 bit_width = backend_cfg->bit_width;
3573 sample_rate = backend_cfg->sample_rate;
3574 channels = backend_cfg->channels;
3575
3576 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3577 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3578 sample_rate, channels);
3579
3580 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3581 // default backend
3582 // force routing is not required here, caller will do it anyway
3583 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3584 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3585 "for unprocessed/camera source", __func__);
3586 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3587 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3588 }
3589
3590 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3591 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3592 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3593 __func__, bit_width, sample_rate, channels);
3594 }
3595
3596 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3597 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3598
3599 // Force routing if the expected bitwdith or samplerate
3600 // is not same as current backend comfiguration
3601 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3602 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3603 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3604 backend_cfg->bit_width = bit_width;
3605 backend_cfg->sample_rate= sample_rate;
3606 backend_cfg->channels = channels;
3607 backend_change = true;
3608 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3609 "new sample rate: %d new channel: %d",
3610 __func__, backend_cfg->bit_width,
3611 backend_cfg->sample_rate, backend_cfg->channels);
3612 }
3613
3614 return backend_change;
3615}
3616
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003617static void pick_playback_cfg_for_uc(struct audio_device *adev,
3618 struct audio_usecase *usecase,
3619 snd_device_t snd_device,
3620 unsigned int *bit_width,
3621 unsigned int *sample_rate,
3622 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003623{
3624 int i =0;
3625 struct listnode *node;
3626 list_for_each(node, &adev->usecase_list) {
3627 struct audio_usecase *uc;
3628 uc = node_to_item(node, struct audio_usecase, list);
3629 struct stream_out *out = (struct stream_out*) uc->stream.out;
3630 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3631 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3632 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3633 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3634 uc->id, out->sample_rate,
3635 pcm_format_to_bits(out->config.format), out_channels,
3636 platform_get_snd_device_name(uc->out_snd_device));
3637
3638 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3639 if (*bit_width < pcm_format_to_bits(out->config.format))
3640 *bit_width = pcm_format_to_bits(out->config.format);
3641 if (*sample_rate < out->sample_rate)
3642 *sample_rate = out->sample_rate;
3643 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3644 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3645 if (*channels < out_channels)
3646 *channels = out_channels;
3647 }
3648 }
3649 }
3650 return;
3651}
3652
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003653static void headset_is_config_supported(unsigned int *bit_width,
3654 unsigned int *sample_rate,
3655 unsigned int *channels) {
3656 switch (*bit_width) {
3657 case 16:
3658 case 24:
3659 break;
3660 default:
3661 *bit_width = 16;
3662 break;
3663 }
3664
3665 if (*sample_rate > 192000) {
3666 *sample_rate = 192000;
3667 }
3668
3669 if (*channels > 2) {
3670 *channels = 2;
3671 }
3672}
3673
David Linee3fe402017-03-13 10:00:42 -07003674static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3675 struct audio_usecase* usecase,
3676 snd_device_t snd_device,
3677 struct audio_backend_cfg *backend_cfg)
3678{
3679 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003680 unsigned int bit_width;
3681 unsigned int sample_rate;
3682 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003683 int backend_idx = DEFAULT_CODEC_BACKEND;
3684 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003685
3686 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3687 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3688 backend_change = false;
3689 return backend_change;
3690 }
3691
3692 backend_idx = platform_get_backend_index(snd_device);
3693 bit_width = backend_cfg->bit_width;
3694 sample_rate = backend_cfg->sample_rate;
3695 channels = backend_cfg->channels;
3696
3697 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3698 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3699 sample_rate, channels, backend_idx, usecase->id,
3700 platform_get_snd_device_name(snd_device));
3701
3702 if (backend_idx == platform_get_voice_call_backend(adev)) {
3703 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3704 __func__);
3705 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3706 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3707 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3708 } else {
3709 /*
3710 * The backend should be configured at highest bit width and/or
3711 * sample rate amongst all playback usecases.
3712 * If the selected sample rate and/or bit width differ with
3713 * current backend sample rate and/or bit width, then, we set the
3714 * backend re-configuration flag.
3715 *
3716 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3717 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003718 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3719 &bit_width,
3720 &sample_rate,
3721 &channels);
David Linee3fe402017-03-13 10:00:42 -07003722 }
3723
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003724 switch (backend_idx) {
3725 case USB_AUDIO_RX_BACKEND:
3726 audio_extn_usb_is_config_supported(&bit_width,
3727 &sample_rate, &channels, true);
3728 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3729 __func__, bit_width, sample_rate, channels);
3730 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003731 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003732 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3733 break;
3734 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003735 default:
3736 bit_width = platform_get_snd_device_bit_width(snd_device);
3737 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3738 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3739 break;
David Linee3fe402017-03-13 10:00:42 -07003740 }
3741
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003742 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3743 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003744 __func__, backend_idx , bit_width, sample_rate);
3745
3746 // Force routing if the expected bitwdith or samplerate
3747 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003748 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3749 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3750 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003751 backend_cfg->bit_width = bit_width;
3752 backend_cfg->sample_rate = sample_rate;
3753 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003754 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003755 backend_change = true;
3756 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3757 "new sample rate: %d new channels: %d",
3758 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3759 }
3760
3761 return backend_change;
3762}
3763
3764bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3765 struct audio_usecase *usecase, snd_device_t snd_device)
3766{
3767 int backend_idx = DEFAULT_CODEC_BACKEND;
3768 int new_snd_devices[SND_DEVICE_OUT_END];
3769 int i, num_devices = 1;
3770 bool ret = false;
3771 struct platform_data *my_data = (struct platform_data *)adev->platform;
3772 struct audio_backend_cfg backend_cfg;
3773
3774 backend_idx = platform_get_backend_index(snd_device);
3775
3776 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3777 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3778 backend_cfg.format = usecase->stream.out->format;
3779 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3780 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3781 backend_cfg.passthrough_enabled = false;
3782
3783 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3784 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3785 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3786 platform_get_snd_device_name(snd_device));
3787
3788 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3789 new_snd_devices[0] = snd_device;
3790
3791 for (i = 0; i < num_devices; i++) {
3792 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3793 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3794 &backend_cfg))) {
3795 platform_set_backend_cfg(adev, new_snd_devices[i],
3796 &backend_cfg);
3797 ret = true;
3798 }
3799 }
3800 return ret;
3801}
3802
3803bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3804 struct audio_usecase *usecase, snd_device_t snd_device)
3805{
3806 int backend_idx = platform_get_backend_index(snd_device);
3807 int ret = 0;
3808 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003809 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003810
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003811 if (usecase->type == PCM_CAPTURE) {
3812 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003813 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3814 } else {
3815 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3816 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3817 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3818 backend_cfg.channels = 1;
3819 }
3820
3821 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3822 ", backend_idx %d usecase = %d device (%s)", __func__,
3823 backend_cfg.bit_width,
3824 backend_cfg.sample_rate,
3825 backend_cfg.channels,
3826 backend_idx, usecase->id,
3827 platform_get_snd_device_name(snd_device));
3828
3829 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3830 ret = platform_set_backend_cfg(adev, snd_device,
3831 &backend_cfg);
3832 if(!ret)
3833 return true;
3834 }
3835
3836 return false;
3837}
3838
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003839static int max_be_dai_names = 0;
3840static const struct be_dai_name_struct *be_dai_name_table;
3841
3842/*
3843 * Retrieves the be_dai_name_table from kernel to enable a mapping
3844 * between sound device hw interfaces and backend IDs. This allows HAL to
3845 * specify the backend a specific calibration is needed for.
3846 */
3847static int init_be_dai_name_table(struct audio_device *adev)
3848{
3849 const char *mixer_ctl_name = "Backend DAI Name Table";
3850 struct mixer_ctl *ctl;
3851 int i, j, ret, size;
3852 bool valid_hw_interface;
3853
3854 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3855 if (!ctl) {
3856 ALOGE("%s: Could not get ctl for mixer name %s\n",
3857 __func__, mixer_ctl_name);
3858 ret = -EINVAL;
3859 goto done;
3860 }
3861
3862 mixer_ctl_update(ctl);
3863
3864 size = mixer_ctl_get_num_values(ctl);
3865 if (size <= 0){
3866 ALOGE("%s: Failed to get %s size %d\n",
3867 __func__, mixer_ctl_name, size);
3868 ret = -EFAULT;
3869 goto done;
3870 }
3871
vivek mehtaa68fea62017-06-08 19:04:02 -07003872 be_dai_name_table =
3873 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003874 if (be_dai_name_table == NULL) {
3875 ALOGE("%s: Failed to allocate memory for %s\n",
3876 __func__, mixer_ctl_name);
3877 ret = -ENOMEM;
3878 goto freeMem;
3879 }
3880
3881 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
3882 if (ret) {
3883 ALOGE("%s: Failed to get %s, ret %d\n",
3884 __func__, mixer_ctl_name, ret);
3885 ret = -EFAULT;
3886 goto freeMem;
3887 }
3888
3889 if (be_dai_name_table != NULL) {
3890 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
3891 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
3892 __func__, mixer_ctl_name, max_be_dai_names);
3893 ret = 0;
3894 } else {
3895 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
3896 ret = -EFAULT;
3897 goto freeMem;
3898 }
3899
3900 /*
3901 * Validate all sound devices have a valid backend set to catch
3902 * errors for uncommon sound devices
3903 */
3904 for (i = 0; i < SND_DEVICE_MAX; i++) {
3905 valid_hw_interface = false;
3906
3907 if (hw_interface_table[i] == NULL) {
3908 ALOGW("%s: sound device %s has no hw interface set\n",
3909 __func__, platform_get_snd_device_name(i));
3910 continue;
3911 }
3912
3913 for (j = 0; j < max_be_dai_names; j++) {
3914 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
3915 == 0) {
3916 valid_hw_interface = true;
3917 break;
3918 }
3919 }
3920 if (!valid_hw_interface)
3921 ALOGD("%s: sound device %s does not have a valid hw interface set "
3922 "(disregard for combo devices) %s\n",
3923 __func__, platform_get_snd_device_name(i),
3924 hw_interface_table[i]);
3925 }
3926
3927 goto done;
3928
3929freeMem:
3930 if (be_dai_name_table) {
3931 free((void *)be_dai_name_table);
3932 be_dai_name_table = NULL;
3933 }
3934
3935done:
3936 return ret;
3937}
3938
3939int platform_get_snd_device_backend_index(snd_device_t device)
3940{
3941 int i, be_dai_id;
3942 const char * hw_interface_name = NULL;
3943
3944 ALOGV("%s: enter with device %d\n", __func__, device);
3945
vivek mehtaa68fea62017-06-08 19:04:02 -07003946 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003947 ALOGE("%s: Invalid snd_device = %d",
3948 __func__, device);
3949 be_dai_id = -EINVAL;
3950 goto done;
3951 }
3952
3953 /* Get string value of necessary backend for device */
3954 hw_interface_name = hw_interface_table[device];
3955 if (hw_interface_name == NULL) {
3956 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
3957 be_dai_id = -EINVAL;
3958 goto done;
3959 }
3960
3961 /* Check if be dai name table was retrieved successfully */
3962 if (be_dai_name_table == NULL) {
3963 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
3964 be_dai_id = -EFAULT;
3965 goto done;
3966 }
3967
3968 /* Get backend ID for device specified */
3969 for (i = 0; i < max_be_dai_names; i++) {
3970 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
3971 be_dai_id = be_dai_name_table[i].be_id;
3972 goto done;
3973 }
3974 }
3975 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
3976 be_dai_id = -EINVAL;
3977 goto done;
3978
3979done:
3980 return be_dai_id;
3981}
3982
3983void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
3984 unsigned int stream_sr, int* sample_rate)
3985{
3986 struct platform_data* my_data = (struct platform_data *)platform;
3987 int backend_idx = platform_get_backend_index(snd_device);
3988 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
3989 /*
3990 *Check if device SR is multiple of 8K or 11.025 Khz
3991 *check if the stream SR is multiple of same base, if yes
3992 *then have copp SR equal to stream SR, this ensures that
3993 *post processing happens at stream SR, else have
3994 *copp SR equal to device SR.
3995 */
3996 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
3997 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
3998 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
3999 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4000 *sample_rate = device_sr;
4001 } else
4002 *sample_rate = stream_sr;
4003
4004 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4005 , *sample_rate);
4006
4007}
4008
4009// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004010void platform_add_app_type(const char *uc_type,
4011 const char *mode,
4012 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004013 int app_type, int max_rate) {
4014 struct app_type_entry *ap =
4015 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4016
4017 if (!ap) {
4018 ALOGE("%s failed to allocate mem for app type", __func__);
4019 return;
4020 }
4021
4022 ap->uc_type = -1;
4023 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4024 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4025 ap->uc_type = usecase_type_index[i].index;
4026 break;
4027 }
4028 }
4029
4030 if (ap->uc_type == -1) {
4031 free(ap);
4032 return;
4033 }
4034
vivek mehtaa68fea62017-06-08 19:04:02 -07004035 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4036 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004037 ap->bit_width = bw;
4038 ap->app_type = app_type;
4039 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004040 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004041 list_add_tail(&app_type_entry_list, &ap->node);
4042}
4043
4044
4045int platform_get_default_app_type_v2(void *platform __unused,
4046 usecase_type_t type,
4047 int *app_type )
4048{
4049 if (type == PCM_PLAYBACK)
4050 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4051 else
4052 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4053 return 0;
4054}
4055
vivek mehtaa68fea62017-06-08 19:04:02 -07004056int platform_get_app_type_v2(void *platform,
4057 usecase_type_t uc_type,
4058 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004059 int bw, int sr __unused,
4060 int *app_type)
4061{
4062 struct listnode *node;
4063 struct app_type_entry *entry;
4064 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004065
4066 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4067 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004068 list_for_each(node, &app_type_entry_list) {
4069 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004070 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4071 __func__, entry->uc_type, entry->mode, entry->bit_width,
4072 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004073 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004074 entry->uc_type == uc_type &&
4075 sr <= entry->max_rate &&
4076 entry->mode && !strcmp(mode, entry->mode)) {
4077 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004078 *app_type = entry->app_type;
4079 break;
4080 }
4081 }
4082
4083 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004084 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004085 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4086 }
4087 return 0;
4088}
vivek mehta90933872017-06-15 18:04:39 -07004089
4090int platform_set_sidetone(struct audio_device *adev,
4091 snd_device_t out_snd_device,
4092 bool enable, char *str)
4093{
4094 int ret;
4095 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4096 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4097 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4098 if (ret)
4099 ALOGI("%s: usb device %d does not support device sidetone\n",
4100 __func__, out_snd_device);
4101 } else {
4102 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4103 __func__, out_snd_device, str);
4104 if (enable)
4105 audio_route_apply_and_update_path(adev->audio_route, str);
4106 else
4107 audio_route_reset_and_update_path(adev->audio_route, str);
4108 }
4109 return 0;
4110}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004111
4112int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4113 int *fd __unused, uint32_t *size __unused)
4114{
4115#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
4116 struct platform_data *my_data = (struct platform_data *)platform;
4117 struct audio_device *adev = my_data->adev;
4118 int hw_fd = -1;
4119 char dev_name[128];
4120 struct snd_pcm_mmap_fd mmap_fd;
4121 memset(&mmap_fd, 0, sizeof(mmap_fd));
4122 mmap_fd.dir = dir;
4123 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4124 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4125 hw_fd = open(dev_name, O_RDONLY);
4126 if (hw_fd < 0) {
4127 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4128 return -1;
4129 }
4130 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4131 ALOGE("fe hw dep node ioctl failed");
4132 close(hw_fd);
4133 return -1;
4134 }
4135 *fd = mmap_fd.fd;
4136 *size = mmap_fd.size;
4137 close(hw_fd); // mmap_fd should still be valid
4138 return 0;
4139#else
4140 return -1;
4141#endif
4142}