blob: 3b1d4d52074f5159b99d27ac4660661705c0097d [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");
1089 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1090 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1091 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1092 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1093 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1094 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1095 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1096 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1097 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1098 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001099 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001100}
1101
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001102void get_cvd_version(char *cvd_version, struct audio_device *adev)
1103{
1104 struct mixer_ctl *ctl;
1105 int count;
1106 int ret = 0;
1107
1108 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1109 if (!ctl) {
1110 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1111 goto done;
1112 }
1113 mixer_ctl_update(ctl);
1114
1115 count = mixer_ctl_get_num_values(ctl);
1116 if (count > MAX_CVD_VERSION_STRING_SIZE)
1117 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1118
1119 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1120 if (ret != 0) {
1121 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1122 goto done;
1123 }
1124
1125done:
1126 return;
1127}
1128
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001129static int platform_acdb_init(void *platform)
1130{
1131 struct platform_data *my_data = (struct platform_data *)platform;
1132 struct audio_device *adev = my_data->adev;
1133
1134 if (!my_data->acdb_init) {
1135 ALOGE("%s: no acdb_init fn provided", __func__);
1136 return -1;
1137 }
1138
1139 if (my_data->acdb_initialized) {
1140 ALOGW("acdb is already initialized");
1141 return 0;
1142 }
1143
Thierry Strudel92232b42017-01-26 10:51:48 -08001144#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001145 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1146 if (!cvd_version)
1147 ALOGE("failed to allocate cvd_version");
1148 else {
1149 get_cvd_version(cvd_version, adev);
1150 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1151 free(cvd_version);
1152 }
1153#elif defined (PLATFORM_MSM8084)
1154 my_data->acdb_init((char *)my_data->snd_card_name);
1155#else
1156 my_data->acdb_init();
1157#endif
1158 my_data->acdb_initialized = true;
1159 return 0;
1160}
1161
David Linee3fe402017-03-13 10:00:42 -07001162static void
1163platform_backend_config_init(struct platform_data *pdata)
1164{
1165 int i;
1166
1167 /* initialize backend config */
1168 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1169 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1170 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1171 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1172
1173 if (i > MAX_RX_CODEC_BACKENDS)
1174 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1175
1176 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1177 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1178 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1179 }
1180
1181 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1182 strdup("SLIM_0_RX Format");
1183 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1184 strdup("SLIM_0_RX SampleRate");
1185
1186 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1187 strdup("SLIM_0_TX Format");
1188 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1189 strdup("SLIM_0_TX SampleRate");
1190
1191 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1192 strdup("USB_AUDIO_TX Format");
1193 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1194 strdup("USB_AUDIO_TX SampleRate");
1195 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1196 strdup("USB_AUDIO_TX Channels");
1197
1198 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1199 strdup("SLIM_6_RX Format");
1200 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1201 strdup("SLIM_6_RX SampleRate");
1202
1203 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1204 strdup("USB_AUDIO_RX Format");
1205 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1206 strdup("USB_AUDIO_RX SampleRate");
1207
1208 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1209 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1210 strdup("USB_AUDIO_RX Channels");
1211}
1212
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001213static int
1214platform_backend_app_type_cfg_init(struct platform_data *pdata,
1215 struct mixer *mixer)
1216{
1217 size_t app_type_cfg[128] = {0};
1218 int length, num_app_types = 0;
1219 struct mixer_ctl *ctl = NULL;
1220
1221 const char *mixer_ctl_name = "App Type Config";
1222 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1223 if (!ctl) {
1224 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1225 return -1;
1226 }
1227
1228 length = 1; // reserve index 0 for number of app types
1229
1230 struct listnode *node;
1231 struct app_type_entry *entry;
1232 list_for_each(node, &app_type_entry_list) {
1233 entry = node_to_item(node, struct app_type_entry, node);
1234 app_type_cfg[length++] = entry->app_type;
1235 app_type_cfg[length++] = entry->max_rate;
1236 app_type_cfg[length++] = entry->bit_width;
1237 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1238 num_app_types += 1;
1239 }
1240
1241 // default for capture
1242 int t;
1243 platform_get_default_app_type_v2(pdata,
1244 PCM_CAPTURE,
1245 &t);
1246 app_type_cfg[length++] = t;
1247 app_type_cfg[length++] = 48000;
1248 app_type_cfg[length++] = 16;
1249 num_app_types += 1;
1250
1251 if (num_app_types) {
1252 app_type_cfg[0] = num_app_types;
1253 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1254 ALOGE("Failed to set app type cfg");
1255 }
1256 }
1257 return 0;
1258}
1259
Eric Laurentb23d5282013-05-14 15:27:20 -07001260void *platform_init(struct audio_device *adev)
1261{
1262 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001263 struct platform_data *my_data = NULL;
1264 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1265 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001266 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001267 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001268 char *snd_internal_name = NULL;
1269 char *tmp = NULL;
1270 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001271 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1272 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001273 my_data = calloc(1, sizeof(struct platform_data));
1274
1275 my_data->adev = adev;
1276
keunhui.park2f7306a2015-07-16 16:48:06 +09001277 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001278 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001279
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001280 set_platform_defaults(my_data);
1281
vivek mehta0fb11312017-05-15 19:35:32 -07001282 // audio_extn_utils_get_snd_card_num does
1283 // - open mixer and get snd card name
1284 // - parse platform info xml file and check for valid snd card name
1285 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001286
vivek mehta0fb11312017-05-15 19:35:32 -07001287 snd_card_num = audio_extn_utils_get_snd_card_num();
1288 if (-1 == snd_card_num) {
1289 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1290 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001291 }
1292
vivek mehta0fb11312017-05-15 19:35:32 -07001293 adev->mixer = mixer_open(snd_card_num);
1294 snd_card_name = mixer_get_name(adev->mixer);
1295 my_data->hw_info = hw_info_init(snd_card_name);
1296
1297 audio_extn_set_snd_card_split(snd_card_name);
1298 snd_split_handle = audio_extn_get_snd_card_split();
1299
1300 /* Get the codec internal name from the sound card and/or form factor
1301 * name and form the mixer paths and platfor info file name dynamically.
1302 * This is generic way of picking any codec and forma factor name based
1303 * mixer and platform info files in future with no code change.
1304
1305 * current code extends and looks for any of the exteneded mixer path and
1306 * platform info file present based on codec and form factor.
1307
1308 * order of picking appropriate file is
1309 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1310 * <ii> mixer_paths_<codec_name>.xml, if file not present
1311 * <iii> mixer_paths.xml
1312
1313 * same order is followed for audio_platform_info.xml as well
1314 */
1315
1316 // need to carryforward old file name
1317 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1318 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1319 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1320 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1321 } else {
1322
1323 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1324 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1325 snd_split_handle->form_factor);
1326 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1327 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1328 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1329 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1330
1331 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1332 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1333 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1334 audio_extn_utils_resolve_config_file(mixer_xml_file);
1335 }
1336 }
1337 }
1338
1339 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1340
1341 /* Initialize platform specific ids and/or backends*/
1342 platform_info_init(platform_info_file, my_data);
1343
1344 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1345 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1346
1347 if (!adev->audio_route) {
1348 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1349 mixer_close(adev->mixer);
1350 adev->mixer = NULL;
1351 hw_info_deinit(my_data->hw_info);
1352 my_data->hw_info = NULL;
1353 goto init_failed;
1354 }
1355 adev->snd_card = snd_card_num;
1356 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1357
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001358 //set max volume step for voice call
1359 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1360 my_data->max_vol_index = atoi(value);
1361
vivek mehta65ad12d2015-08-13 18:32:48 -07001362 property_get("persist.audio.dualmic.config",value,"");
1363 if (!strcmp("endfire", value)) {
1364 dual_mic_config = true;
1365 }
1366
Prashant Malanic92c5962015-08-11 15:10:18 -07001367 my_data->source_mic_type = SOURCE_DUAL_MIC;
1368
Eric Laurentb23d5282013-05-14 15:27:20 -07001369 my_data->fluence_in_spkr_mode = false;
1370 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001371 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001372 my_data->fluence_in_voice_rec = false;
1373
vivek mehta65ad12d2015-08-13 18:32:48 -07001374 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001375 if (!strcmp("fluencepro", value)) {
1376 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001377 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001378 my_data->fluence_type = FLUENCE_ENABLE;
1379 } else if (!strcmp("none", value)) {
1380 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001381 }
1382
Prashant Malanic92c5962015-08-11 15:10:18 -07001383 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001384 property_get("persist.audio.fluence.voicecall",value,"");
1385 if (!strcmp("true", value)) {
1386 my_data->fluence_in_voice_call = true;
1387 }
1388
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001389 property_get("persist.audio.fluence.voicecomm",value,"");
1390 if (!strcmp("true", value)) {
1391 my_data->fluence_in_voice_comm = true;
1392 }
1393
Eric Laurentb23d5282013-05-14 15:27:20 -07001394 property_get("persist.audio.fluence.voicerec",value,"");
1395 if (!strcmp("true", value)) {
1396 my_data->fluence_in_voice_rec = true;
1397 }
1398
1399 property_get("persist.audio.fluence.speaker",value,"");
1400 if (!strcmp("true", value)) {
1401 my_data->fluence_in_spkr_mode = true;
1402 }
1403 }
1404
Prashant Malanic92c5962015-08-11 15:10:18 -07001405 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1406 switch (my_data->max_mic_count) {
1407 case 4:
1408 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1409 case 3:
1410 my_data->source_mic_type |= SOURCE_THREE_MIC;
1411 case 2:
1412 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1413 case 1:
1414 my_data->source_mic_type |= SOURCE_MONO_MIC;
1415 break;
1416 default:
1417 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1418 __func__, my_data->max_mic_count);
1419 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1420 break;
1421 }
1422
1423 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1424 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1425 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1426 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1427 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1428
Eric Laurentb23d5282013-05-14 15:27:20 -07001429 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1430 if (my_data->acdb_handle == NULL) {
1431 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1432 } else {
1433 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1434 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1435 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001436 if (!my_data->acdb_deallocate)
1437 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1438 __func__, LIB_ACDB_LOADER);
1439
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001440 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1441 "acdb_loader_send_audio_cal_v3");
1442 if (!my_data->acdb_send_audio_cal_v3)
1443 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1444 __func__, LIB_ACDB_LOADER);
1445
Eric Laurentb23d5282013-05-14 15:27:20 -07001446 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1447 "acdb_loader_send_audio_cal");
1448 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001449 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001450 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001451
Eric Laurentb23d5282013-05-14 15:27:20 -07001452 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1453 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001454 if (!my_data->acdb_send_voice_cal)
1455 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1456 __func__, LIB_ACDB_LOADER);
1457
1458 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1459 "acdb_loader_reload_vocvoltable");
1460 if (!my_data->acdb_reload_vocvoltable)
1461 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1462 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001463
1464 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1465 "acdb_loader_send_gain_dep_cal");
1466 if (!my_data->acdb_send_gain_dep_cal)
1467 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1468 __func__, LIB_ACDB_LOADER);
1469
Thierry Strudel92232b42017-01-26 10:51:48 -08001470#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
vivek mehta0fb11312017-05-15 19:35:32 -07001471 acdb_init_v2_cvd_t acdb_init_local;
1472 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001473 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001474 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001475 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1476 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001477
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001478#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001479 acdb_init_v2_t acdb_init_local;
1480 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001481 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001482 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001483 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1484 dlerror());
1485
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001486#else
vivek mehta0fb11312017-05-15 19:35:32 -07001487 acdb_init_t acdb_init_local;
1488 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001489 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001490 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001491 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1492 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001493#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001494 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001495
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001496 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1497 dlsym(my_data->acdb_handle,
1498 "acdb_loader_send_common_custom_topology");
1499
1500 if (!my_data->acdb_send_custom_top)
1501 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1502 __func__, LIB_ACDB_LOADER);
1503
vivek mehta0fb11312017-05-15 19:35:32 -07001504 int result = acdb_init(adev->snd_card);
1505 if (!result) {
1506 my_data->acdb_initialized = true;
1507 ALOGD("ACDB initialized");
1508 } else {
1509 my_data->acdb_initialized = false;
1510 ALOGD("ACDB initialization failed");
1511 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001512 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001513
David Linee3fe402017-03-13 10:00:42 -07001514 /* init usb */
1515 audio_extn_usb_init(adev);
1516
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001517 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001518
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001519 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1520
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001521 /* load csd client */
1522 platform_csd_init(my_data);
1523
David Linee3fe402017-03-13 10:00:42 -07001524 platform_backend_config_init(my_data);
1525
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001526 init_be_dai_name_table(adev);
1527
1528 if (platform_supports_app_type_cfg())
1529 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1530
Eric Laurentb23d5282013-05-14 15:27:20 -07001531 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001532
1533init_failed:
1534 if (my_data)
1535 free(my_data);
1536 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001537}
1538
1539void platform_deinit(void *platform)
1540{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001541 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001542 struct operator_info *info_item;
1543 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001544 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001545 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001546
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001547 struct platform_data *my_data = (struct platform_data *)platform;
1548 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001549
vivek mehtade4849c2016-03-03 17:23:38 -08001550 hw_info_deinit(my_data->hw_info);
1551
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001552 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1553 if (backend_tag_table[dev])
1554 free(backend_tag_table[dev]);
1555 if (hw_interface_table[dev])
1556 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001557 if (operator_specific_device_table[dev]) {
1558 while (!list_empty(operator_specific_device_table[dev])) {
1559 node = list_head(operator_specific_device_table[dev]);
1560 list_remove(node);
1561 device_item = node_to_item(node, struct operator_specific_device, list);
1562 free(device_item->operator);
1563 free(device_item->mixer_path);
1564 free(device_item);
1565 }
1566 free(operator_specific_device_table[dev]);
1567 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001568 }
1569
1570 if (my_data->snd_card_name)
1571 free(my_data->snd_card_name);
1572
keunhui.park2f7306a2015-07-16 16:48:06 +09001573 while (!list_empty(&operator_info_list)) {
1574 node = list_head(&operator_info_list);
1575 list_remove(node);
1576 info_item = node_to_item(node, struct operator_info, list);
1577 free(info_item->name);
1578 free(info_item->mccmnc);
1579 free(info_item);
1580 }
1581
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001582 while (!list_empty(&app_type_entry_list)) {
1583 node = list_head(&app_type_entry_list);
1584 list_remove(node);
1585 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001586 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001587 free(ap);
1588 }
1589
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001590 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001591 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001592
1593 /* deinit usb */
1594 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001595}
1596
1597const char *platform_get_snd_device_name(snd_device_t snd_device)
1598{
keunhui.park2f7306a2015-07-16 16:48:06 +09001599 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1600 if (operator_specific_device_table[snd_device] != NULL) {
1601 return get_operator_specific_device_mixer_path(snd_device);
1602 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001603 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001604 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001605 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001606}
1607
vivek mehtade4849c2016-03-03 17:23:38 -08001608int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1609 char *device_name)
1610{
1611 struct platform_data *my_data = (struct platform_data *)platform;
1612
David Benjamin1565f992016-09-21 12:10:34 -04001613 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001614 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001615 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1616 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001617 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1618 if (operator_specific_device_table[snd_device] != NULL) {
1619 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1620 DEVICE_NAME_MAX_SIZE);
1621 } else {
1622 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1623 }
1624 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1625 } else {
1626 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1627 }
1628
1629 return 0;
1630}
1631
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001632void platform_add_backend_name(void *platform, char *mixer_path,
1633 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001634{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001635 struct platform_data *my_data = (struct platform_data *)platform;
1636
Haynes Mathew George98c95622014-06-20 19:14:25 -07001637 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1638 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1639 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001640 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001641
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001642 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001643
1644 if (suffix != NULL) {
1645 strcat(mixer_path, " ");
1646 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001647 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001648}
1649
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001650bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1651{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001652 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1653 platform_get_snd_device_name(snd_device1),
1654 platform_get_snd_device_name(snd_device2));
1655
1656 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1657 ALOGE("%s: Invalid snd_device = %s", __func__,
1658 platform_get_snd_device_name(snd_device1));
1659 return false;
1660 }
1661 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1662 ALOGE("%s: Invalid snd_device = %s", __func__,
1663 platform_get_snd_device_name(snd_device2));
1664 return false;
1665 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001666
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001667 const char * be_itf1 = hw_interface_table[snd_device1];
1668 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001669 /*
1670 hw_interface_table has overrides for a snd_device.
1671 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1672 */
1673 if (be_itf1 == NULL) {
1674 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001675 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001676 if (be_itf2 == NULL) {
1677 be_itf2 = DEFAULT_RX_BACKEND;
1678 }
1679 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1680 /*
1681 this takes care of finding a device within a combo device pair as well
1682 */
1683 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001684}
1685
Eric Laurentb23d5282013-05-14 15:27:20 -07001686int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1687{
1688 int device_id;
1689 if (device_type == PCM_PLAYBACK)
1690 device_id = pcm_device_table[usecase][0];
1691 else
1692 device_id = pcm_device_table[usecase][1];
1693 return device_id;
1694}
1695
Haynes Mathew George98c95622014-06-20 19:14:25 -07001696static int find_index(const struct name_to_index * table, int32_t len,
1697 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001698{
1699 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001700 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001701
Haynes Mathew George98c95622014-06-20 19:14:25 -07001702 if (table == NULL) {
1703 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001704 ret = -ENODEV;
1705 goto done;
1706 }
1707
Haynes Mathew George98c95622014-06-20 19:14:25 -07001708 if (name == NULL) {
1709 ALOGE("null key");
1710 ret = -ENODEV;
1711 goto done;
1712 }
1713
1714 for (i=0; i < len; i++) {
1715 if (!strcmp(table[i].name, name)) {
1716 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001717 goto done;
1718 }
1719 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001720 ALOGE("%s: Could not find index for name = %s",
1721 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001722 ret = -ENODEV;
1723done:
1724 return ret;
1725}
1726
Haynes Mathew George98c95622014-06-20 19:14:25 -07001727int platform_get_snd_device_index(char *device_name)
1728{
1729 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1730}
1731
1732int platform_get_usecase_index(const char *usecase_name)
1733{
1734 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1735}
1736
keunhui.park2f7306a2015-07-16 16:48:06 +09001737void platform_add_operator_specific_device(snd_device_t snd_device,
1738 const char *operator,
1739 const char *mixer_path,
1740 unsigned int acdb_id)
1741{
1742 struct operator_specific_device *device;
1743
1744 if (operator_specific_device_table[snd_device] == NULL) {
1745 operator_specific_device_table[snd_device] =
1746 (struct listnode *)calloc(1, sizeof(struct listnode));
1747 list_init(operator_specific_device_table[snd_device]);
1748 }
1749
1750 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1751
1752 device->operator = strdup(operator);
1753 device->mixer_path = strdup(mixer_path);
1754 device->acdb_id = acdb_id;
1755
1756 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1757
Eric Laurent2bafff12016-03-17 12:17:23 -07001758 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001759 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1760
1761}
1762
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001763int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1764{
1765 int ret = 0;
1766
1767 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1768 ALOGE("%s: Invalid snd_device = %d",
1769 __func__, snd_device);
1770 ret = -EINVAL;
1771 goto done;
1772 }
1773
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001774 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1775 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001776 acdb_device_table[snd_device] = acdb_id;
1777done:
1778 return ret;
1779}
1780
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001781int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1782{
1783 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1784 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1785 return -EINVAL;
1786 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001787
1788 if (operator_specific_device_table[snd_device] != NULL)
1789 return get_operator_specific_device_acdb_id(snd_device);
1790 else
1791 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001792}
1793
David Linee3fe402017-03-13 10:00:42 -07001794static int platform_get_backend_index(snd_device_t snd_device)
1795{
1796 int32_t port = DEFAULT_CODEC_BACKEND;
1797
1798 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1799 if (backend_tag_table[snd_device] != NULL) {
1800 if (strncmp(backend_tag_table[snd_device], "headphones",
1801 sizeof("headphones")) == 0)
1802 port = HEADPHONE_BACKEND;
1803 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1804 port = HDMI_RX_BACKEND;
1805 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1806 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1807 port = USB_AUDIO_RX_BACKEND;
1808 }
1809 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1810 port = DEFAULT_CODEC_TX_BACKEND;
1811 if (backend_tag_table[snd_device] != NULL) {
1812 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1813 port = USB_AUDIO_TX_BACKEND;
1814 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1815 port = BT_SCO_TX_BACKEND;
1816 }
1817 } else {
1818 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1819 }
1820
1821 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1822
1823 return port;
1824}
1825
Eric Laurentb23d5282013-05-14 15:27:20 -07001826int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1827{
1828 struct platform_data *my_data = (struct platform_data *)platform;
1829 int acdb_dev_id, acdb_dev_type;
1830
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001831 if (platform_supports_app_type_cfg()) // use v2 instead
1832 return -ENOSYS;
1833
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001834 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001835 if (acdb_dev_id < 0) {
1836 ALOGE("%s: Could not find acdb id for device(%d)",
1837 __func__, snd_device);
1838 return -EINVAL;
1839 }
1840 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001841 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001842 __func__, snd_device, acdb_dev_id);
1843 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1844 snd_device < SND_DEVICE_OUT_END)
1845 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1846 else
1847 acdb_dev_type = ACDB_DEV_TYPE_IN;
1848 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1849 }
1850 return 0;
1851}
1852
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001853int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1854 int app_type, int sample_rate)
1855{
1856 struct platform_data *my_data = (struct platform_data *)platform;
1857 int acdb_dev_id, acdb_dev_type;
1858 int snd_device = SND_DEVICE_OUT_SPEAKER;
1859 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1860 int i, num_devices = 1;
1861
1862 if (!platform_supports_app_type_cfg()) // use v1 instead
1863 return -ENOSYS;
1864
1865 if (usecase->type == PCM_PLAYBACK)
1866 snd_device = usecase->out_snd_device;
1867 else if (usecase->type == PCM_CAPTURE)
1868 snd_device = usecase->in_snd_device;
1869
1870 // skipped over get_spkr_prot_device
1871 acdb_dev_id = acdb_device_table[snd_device];
1872 if (acdb_dev_id < 0) {
1873 ALOGE("%s: Could not find acdb id for device(%d)",
1874 __func__, snd_device);
1875 return -EINVAL;
1876 }
1877
1878 if (platform_can_split_snd_device(snd_device,
1879 &num_devices, new_snd_device) < 0) {
1880 new_snd_device[0] = snd_device;
1881 }
1882
1883 for (i = 0; i < num_devices; i++) {
1884 acdb_dev_id = acdb_device_table[new_snd_device[i]];
1885 if (acdb_dev_id < 0) {
1886 ALOGE("%s: Could not find acdb id for device(%d)",
1887 __func__, new_snd_device[i]);
1888 return -EINVAL;
1889 }
1890 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1891 __func__, new_snd_device[i], acdb_dev_id);
1892 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1893 new_snd_device[i] < SND_DEVICE_OUT_END)
1894 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1895 else
1896 acdb_dev_type = ACDB_DEV_TYPE_IN;
1897
1898 if (my_data->acdb_send_audio_cal_v3) {
1899 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1900 app_type, sample_rate, i);
1901 } else if (my_data->acdb_send_audio_cal) {
1902 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
1903 }
1904 }
1905
1906 return 0;
1907}
1908
1909
Eric Laurentb23d5282013-05-14 15:27:20 -07001910int platform_switch_voice_call_device_pre(void *platform)
1911{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001912 struct platform_data *my_data = (struct platform_data *)platform;
1913 int ret = 0;
1914
1915 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001916 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001917 /* This must be called before disabling mixer controls on APQ side */
1918 ret = my_data->csd->disable_device();
1919 if (ret < 0) {
1920 ALOGE("%s: csd_client_disable_device, failed, error %d",
1921 __func__, ret);
1922 }
1923 }
1924 return ret;
1925}
1926
1927int platform_switch_voice_call_enable_device_config(void *platform,
1928 snd_device_t out_snd_device,
1929 snd_device_t in_snd_device)
1930{
1931 struct platform_data *my_data = (struct platform_data *)platform;
1932 int acdb_rx_id, acdb_tx_id;
1933 int ret = 0;
1934
1935 if (my_data->csd == NULL)
1936 return ret;
1937
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001938 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1939 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001940 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001941 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001942 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001943
keunhui.park2f7306a2015-07-16 16:48:06 +09001944 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001945
1946 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1947 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1948 if (ret < 0) {
1949 ALOGE("%s: csd_enable_device_config, failed, error %d",
1950 __func__, ret);
1951 }
1952 } else {
1953 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1954 acdb_rx_id, acdb_tx_id);
1955 }
1956
1957 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001958}
1959
1960int platform_switch_voice_call_device_post(void *platform,
1961 snd_device_t out_snd_device,
1962 snd_device_t in_snd_device)
1963{
1964 struct platform_data *my_data = (struct platform_data *)platform;
1965 int acdb_rx_id, acdb_tx_id;
1966
1967 if (my_data->acdb_send_voice_cal == NULL) {
1968 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1969 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001970 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1971 audio_extn_spkr_prot_is_enabled())
1972 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1973
keunhui.park2f7306a2015-07-16 16:48:06 +09001974 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1975 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001976
1977 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1978 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1979 else
1980 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1981 acdb_rx_id, acdb_tx_id);
1982 }
1983
1984 return 0;
1985}
1986
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001987int platform_switch_voice_call_usecase_route_post(void *platform,
1988 snd_device_t out_snd_device,
1989 snd_device_t in_snd_device)
1990{
1991 struct platform_data *my_data = (struct platform_data *)platform;
1992 int acdb_rx_id, acdb_tx_id;
1993 int ret = 0;
1994
1995 if (my_data->csd == NULL)
1996 return ret;
1997
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001998 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1999 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09002000 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002001 else
keunhui.park2f7306a2015-07-16 16:48:06 +09002002 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002003
keunhui.park2f7306a2015-07-16 16:48:06 +09002004 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002005
2006 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2007 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2008 my_data->adev->acdb_settings);
2009 if (ret < 0) {
2010 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2011 }
2012 } else {
2013 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2014 acdb_rx_id, acdb_tx_id);
2015 }
2016
2017 return ret;
2018}
2019
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002020int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002021{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002022 struct platform_data *my_data = (struct platform_data *)platform;
2023 int ret = 0;
2024
2025 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002026 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002027 if (ret < 0) {
2028 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2029 }
2030 }
2031 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002032}
2033
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002034int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002035{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002036 struct platform_data *my_data = (struct platform_data *)platform;
2037 int ret = 0;
2038
2039 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002040 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002041 if (ret < 0) {
2042 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2043 }
2044 }
2045 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002046}
2047
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002048int platform_get_sample_rate(void *platform, uint32_t *rate)
2049{
2050 struct platform_data *my_data = (struct platform_data *)platform;
2051 int ret = 0;
2052
2053 if (my_data->csd != NULL) {
2054 ret = my_data->csd->get_sample_rate(rate);
2055 if (ret < 0) {
2056 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2057 }
2058 }
2059 return ret;
2060}
2061
vivek mehtab6506412015-08-07 16:55:17 -07002062void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2063 snd_device_t snd_device,
2064 bool enable)
2065{
2066 const char* name;
2067 switch (snd_device) {
2068 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2069 if (enable)
2070 name = "spkr-gain-in-headphone-combo";
2071 else
2072 name = "speaker-gain-default";
2073 break;
2074 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2075 if (enable)
2076 name = "spkr-gain-in-line-combo";
2077 else
2078 name = "speaker-gain-default";
2079 break;
2080 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2081 if (enable)
2082 name = "spkr-safe-gain-in-headphone-combo";
2083 else
2084 name = "speaker-safe-gain-default";
2085 break;
2086 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2087 if (enable)
2088 name = "spkr-safe-gain-in-line-combo";
2089 else
2090 name = "speaker-safe-gain-default";
2091 break;
2092 default:
2093 return;
2094 }
2095
2096 audio_route_apply_and_update_path(adev->audio_route, name);
2097}
2098
Eric Laurentb23d5282013-05-14 15:27:20 -07002099int platform_set_voice_volume(void *platform, int volume)
2100{
2101 struct platform_data *my_data = (struct platform_data *)platform;
2102 struct audio_device *adev = my_data->adev;
2103 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002104 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002105 int vol_index = 0, ret = 0;
2106 uint32_t set_values[ ] = {0,
2107 ALL_SESSION_VSID,
2108 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002109
2110 // Voice volume levels are mapped to adsp volume levels as follows.
2111 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2112 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002113 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002114 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002115
2116 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2117 if (!ctl) {
2118 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2119 __func__, mixer_ctl_name);
2120 return -EINVAL;
2121 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002122 ALOGV("Setting voice volume index: %d", set_values[0]);
2123 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2124
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002125 if (my_data->csd != NULL) {
2126 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2127 DEFAULT_VOLUME_RAMP_DURATION_MS);
2128 if (ret < 0) {
2129 ALOGE("%s: csd_volume error %d", __func__, ret);
2130 }
2131 }
2132 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002133}
2134
2135int platform_set_mic_mute(void *platform, bool state)
2136{
2137 struct platform_data *my_data = (struct platform_data *)platform;
2138 struct audio_device *adev = my_data->adev;
2139 struct mixer_ctl *ctl;
2140 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002141 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002142 uint32_t set_values[ ] = {0,
2143 ALL_SESSION_VSID,
2144 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002145
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002146 if (adev->mode != AUDIO_MODE_IN_CALL &&
2147 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002148 return 0;
2149
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002150 if (adev->enable_hfp)
2151 mixer_ctl_name = "HFP Tx Mute";
2152
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002153 set_values[0] = state;
2154 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2155 if (!ctl) {
2156 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2157 __func__, mixer_ctl_name);
2158 return -EINVAL;
2159 }
2160 ALOGV("Setting voice mute state: %d", state);
2161 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2162
2163 if (my_data->csd != NULL) {
2164 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2165 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002166 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002167 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002168 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002169 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002170 return ret;
2171}
Eric Laurentb23d5282013-05-14 15:27:20 -07002172
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002173int platform_set_device_mute(void *platform, bool state, char *dir)
2174{
2175 struct platform_data *my_data = (struct platform_data *)platform;
2176 struct audio_device *adev = my_data->adev;
2177 struct mixer_ctl *ctl;
2178 char *mixer_ctl_name = NULL;
2179 int ret = 0;
2180 uint32_t set_values[ ] = {0,
2181 ALL_SESSION_VSID,
2182 0};
2183 if(dir == NULL) {
2184 ALOGE("%s: Invalid direction:%s", __func__, dir);
2185 return -EINVAL;
2186 }
2187
2188 if (!strncmp("rx", dir, sizeof("rx"))) {
2189 mixer_ctl_name = "Voice Rx Device Mute";
2190 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2191 mixer_ctl_name = "Voice Tx Device Mute";
2192 } else {
2193 return -EINVAL;
2194 }
2195
2196 set_values[0] = state;
2197 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2198 if (!ctl) {
2199 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2200 __func__, mixer_ctl_name);
2201 return -EINVAL;
2202 }
2203
2204 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2205 __func__,state, mixer_ctl_name);
2206 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2207
2208 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002209}
2210
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002211int platform_can_split_snd_device(snd_device_t snd_device,
2212 int *num_devices,
2213 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002214{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002215 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002216 if (NULL == num_devices || NULL == new_snd_devices) {
2217 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002218 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002219 }
2220
2221 /*
2222 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002223 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002224 */
2225 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2226 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2227 *num_devices = 2;
2228 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2229 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002230 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002231 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2232 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2233 *num_devices = 2;
2234 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2235 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002236 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002237 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2238 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2239 *num_devices = 2;
2240 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2241 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002242 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002243 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2244 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2245 *num_devices = 2;
2246 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2247 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002248 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002249 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2250 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2251 SND_DEVICE_OUT_BT_SCO)) {
2252 *num_devices = 2;
2253 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2254 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2255 ret = 0;
2256 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2257 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2258 SND_DEVICE_OUT_BT_SCO_WB)) {
2259 *num_devices = 2;
2260 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2261 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2262 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002263 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2264 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2265 *num_devices = 2;
2266 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2267 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2268 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002269 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2270 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2271 *num_devices = 2;
2272 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2273 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2274 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002275 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002276 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002277}
2278
Eric Laurentb23d5282013-05-14 15:27:20 -07002279snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2280{
2281 struct platform_data *my_data = (struct platform_data *)platform;
2282 struct audio_device *adev = my_data->adev;
2283 audio_mode_t mode = adev->mode;
2284 snd_device_t snd_device = SND_DEVICE_NONE;
2285
2286 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2287 if (devices == AUDIO_DEVICE_NONE ||
2288 devices & AUDIO_DEVICE_BIT_IN) {
2289 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2290 goto exit;
2291 }
2292
Eric Laurent1b491552015-09-15 17:52:41 -07002293 if (popcount(devices) == 2) {
2294 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2295 AUDIO_DEVICE_OUT_SPEAKER) ||
2296 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2297 AUDIO_DEVICE_OUT_SPEAKER)) {
2298 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2299 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2300 AUDIO_DEVICE_OUT_SPEAKER)) {
2301 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2302 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2303 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2304 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2305 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2306 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2307 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2308 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2309 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2310 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2311 AUDIO_DEVICE_OUT_SPEAKER)) {
2312 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002313 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2314 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2315 snd_device = adev->bt_wb_speech_enabled ?
2316 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2317 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002318 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2319 AUDIO_DEVICE_OUT_SPEAKER)) ||
2320 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2321 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002322 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002323 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2324 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2325 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2326 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002327 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002328 } else {
2329 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2330 goto exit;
2331 }
2332 if (snd_device != SND_DEVICE_NONE) {
2333 goto exit;
2334 }
2335 }
2336
2337 if (popcount(devices) != 1) {
2338 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2339 goto exit;
2340 }
2341
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302342 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002343 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002344 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2345 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002346 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002347 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002348 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002349 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002350 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002351 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002352 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002353 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002354 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002355 else {
2356 if (devices & AUDIO_DEVICE_OUT_LINE)
2357 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2358 else
2359 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2360 }
Eric Laurent99dab492017-06-17 15:19:08 -07002361 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002362 if (voice_is_in_call(adev)) {
2363 switch (adev->voice.tty_mode) {
2364 case TTY_MODE_FULL:
2365 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2366 break;
2367 case TTY_MODE_VCO:
2368 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2369 break;
2370 case TTY_MODE_HCO:
2371 // since Hearing will be on handset\speaker, use existing device
2372 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2373 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002374 case TTY_MODE_OFF:
2375 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002376 default:
2377 ALOGE("%s: Invalid TTY mode (%#x)",
2378 __func__, adev->voice.tty_mode);
2379 }
2380 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002381 if (snd_device == SND_DEVICE_NONE) {
2382 snd_device = audio_extn_usb_is_capture_supported() ?
2383 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2384 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2385 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002386 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002387 if (adev->bt_wb_speech_enabled) {
2388 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2389 } else {
2390 snd_device = SND_DEVICE_OUT_BT_SCO;
2391 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002392 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002393 if (!adev->enable_hfp) {
2394 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2395 } else {
2396 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2397 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002398 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002399 if(adev->voice.hac)
2400 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2401 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002402 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2403 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002404 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002405 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2406 snd_device = SND_DEVICE_OUT_VOICE_TX;
2407
Eric Laurentb23d5282013-05-14 15:27:20 -07002408 if (snd_device != SND_DEVICE_NONE) {
2409 goto exit;
2410 }
2411 }
2412
Eric Laurentb23d5282013-05-14 15:27:20 -07002413 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2414 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2415 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002416 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2417 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002418 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2419 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002420 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002421 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002422 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2423 else
2424 snd_device = SND_DEVICE_OUT_SPEAKER;
2425 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002426 if (adev->bt_wb_speech_enabled) {
2427 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2428 } else {
2429 snd_device = SND_DEVICE_OUT_BT_SCO;
2430 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002431 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2432 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002433 } else if (audio_is_usb_out_device(devices)) {
David Linee3fe402017-03-13 10:00:42 -07002434 if (audio_extn_usb_is_capture_supported())
2435 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2436 else
2437 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2438 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002439 /*HAC support for voice-ish audio (eg visual voicemail)*/
2440 if(adev->voice.hac)
2441 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2442 else
2443 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002444 } else {
2445 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2446 }
2447exit:
2448 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2449 return snd_device;
2450}
2451
2452snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2453{
2454 struct platform_data *my_data = (struct platform_data *)platform;
2455 struct audio_device *adev = my_data->adev;
2456 audio_source_t source = (adev->active_input == NULL) ?
2457 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2458
2459 audio_mode_t mode = adev->mode;
2460 audio_devices_t in_device = ((adev->active_input == NULL) ?
2461 AUDIO_DEVICE_NONE : adev->active_input->device)
2462 & ~AUDIO_DEVICE_BIT_IN;
2463 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2464 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2465 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002466 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002467
Prashant Malanic92c5962015-08-11 15:10:18 -07002468 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2469 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002470 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2471 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002472 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002473 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002474 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2475 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002476 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002477 case TTY_MODE_FULL:
2478 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2479 break;
2480 case TTY_MODE_VCO:
2481 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2482 break;
2483 case TTY_MODE_HCO:
2484 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2485 break;
2486 default:
2487 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2488 }
2489 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002490 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002491 switch (adev->voice.tty_mode) {
2492 case TTY_MODE_FULL:
2493 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2494 break;
2495 case TTY_MODE_VCO:
2496 // since voice will be captured from handset mic, use existing device
2497 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2498 break;
2499 case TTY_MODE_HCO:
2500 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2501 break;
2502 default:
2503 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002504 }
2505 goto exit;
2506 }
2507 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002508 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002509 if (my_data->fluence_in_voice_call == false) {
2510 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2511 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002512 if (is_operator_tmus())
2513 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002514 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002515 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002516 }
2517 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2518 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2519 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002520 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002521 if (adev->bluetooth_nrec)
2522 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2523 else
2524 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002525 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002526 if (adev->bluetooth_nrec)
2527 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2528 else
2529 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002530 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002531 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002532 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2533 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2534 out_device & AUDIO_DEVICE_OUT_LINE) {
2535 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2536 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2537 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2538 } else {
2539 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2540 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002541 }
vivek mehtafe121d52015-08-10 23:39:23 -07002542
2543 //select default
2544 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002545 if (!adev->enable_hfp) {
2546 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2547 } else {
2548 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2549 platform_set_echo_reference(adev, true, out_device);
2550 }
vivek mehtafe121d52015-08-10 23:39:23 -07002551 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002552 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002553 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002554 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002555 if (audio_extn_usb_is_capture_supported()) {
2556 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2557 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2558 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2559 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2560 } else {
2561 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2562 }
2563 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002564 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002565 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2566 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2567 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2568 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2569 }
2570 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2571 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002572 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2573 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2574 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002575 if (adev->active_input->enable_aec)
2576 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2577 else
2578 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002579 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2580 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002581 if (adev->active_input->enable_aec)
2582 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2583 else
2584 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002585 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2586 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2587 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002588 if (adev->active_input->enable_aec)
2589 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2590 else
2591 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002592 }
2593 platform_set_echo_reference(adev, true, out_device);
2594 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2595 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2596 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002597 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002598 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2599 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002600 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002601 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2602 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002603 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002604 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002605 if (adev->active_input->enable_aec) {
2606 if (adev->active_input->enable_ns) {
2607 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2608 } else {
2609 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2610 }
vivek mehta733c1df2016-04-04 15:09:24 -07002611 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002612 } else if (adev->active_input->enable_ns) {
2613 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2614 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002615 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002616 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002617 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002618 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2619 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002620 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002621 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002622 }
rago90fb9612015-12-02 11:37:53 -08002623 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2624 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002625 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2626 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2627 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2628 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002629 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002630 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2631 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002632 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002633 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2634 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2635 } else {
2636 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2637 }
rago90fb9612015-12-02 11:37:53 -08002638 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2639 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002640 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002641 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002642 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002643 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002644 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002645 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2646 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2647 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2648 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002649 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002650 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002651 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002652 if (adev->active_input->enable_aec &&
2653 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002654 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002655 if (my_data->fluence_in_spkr_mode &&
2656 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002657 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002658 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002659 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002660 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002661 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002662 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002663 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002664 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002665 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002666 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002667 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002668 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002669 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2670 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002671 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002672 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002673 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002674 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002675 } else if (adev->active_input->enable_aec) {
2676 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2677 if (my_data->fluence_in_spkr_mode &&
2678 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002679 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002680 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002681 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002682 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002683 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002684 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2685 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002686 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002687 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002688 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002689 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002690 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002691 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2692 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002693 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002694 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002695 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002696 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002697 } else if (adev->active_input->enable_ns) {
2698 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2699 if (my_data->fluence_in_spkr_mode &&
2700 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002701 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002702 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002703 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002704 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002705 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002706 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2707 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002708 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002709 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002710 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002711 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002712 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002713 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002714 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002715 }
2716 } else if (source == AUDIO_SOURCE_DEFAULT) {
2717 goto exit;
2718 }
2719
2720
2721 if (snd_device != SND_DEVICE_NONE) {
2722 goto exit;
2723 }
2724
2725 if (in_device != AUDIO_DEVICE_NONE &&
2726 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2727 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2728 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002729 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002730 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002731 snd_device = SND_DEVICE_IN_QUAD_MIC;
2732 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002733 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002734 snd_device = SND_DEVICE_IN_THREE_MIC;
2735 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2736 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002737 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002738 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2739 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002740 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002741 } else {
2742 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2743 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2744 my_data->source_mic_type, channel_count, channel_mask);
2745 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2746 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002747 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002748 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2749 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002750 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002751 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2752 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002753 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002754 } else {
2755 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2756 " no combination found .. setting to mono", __func__,
2757 my_data->source_mic_type, channel_count);
2758 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2759 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002760 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2761 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2762 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002763 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002764 if (adev->bluetooth_nrec)
2765 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2766 else
2767 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002768 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002769 if (adev->bluetooth_nrec)
2770 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2771 else
2772 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002773 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002774 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2775 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002776 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07002777 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002778 } else {
2779 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2780 ALOGW("%s: Using default handset-mic", __func__);
2781 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2782 }
2783 } else {
2784 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2785 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2786 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2787 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002788 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002789 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002790 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002791 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002792 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2793 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002794 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002795 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2796 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002797 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002798 } else {
2799 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2800 " no combination found .. setting to mono", __func__,
2801 my_data->source_mic_type, channel_count);
2802 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2803 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002804 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002805 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002806 if (adev->bluetooth_nrec)
2807 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2808 else
2809 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002810 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002811 if (adev->bluetooth_nrec)
2812 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2813 else
2814 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002815 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002816 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2817 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002818 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07002819 if (audio_extn_usb_is_capture_supported())
2820 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2821 else
2822 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002823 } else {
2824 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2825 ALOGW("%s: Using default handset-mic", __func__);
2826 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2827 }
2828 }
2829exit:
2830 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2831 return snd_device;
2832}
2833
2834int platform_set_hdmi_channels(void *platform, int channel_count)
2835{
2836 struct platform_data *my_data = (struct platform_data *)platform;
2837 struct audio_device *adev = my_data->adev;
2838 struct mixer_ctl *ctl;
2839 const char *channel_cnt_str = NULL;
2840 const char *mixer_ctl_name = "HDMI_RX Channels";
2841 switch (channel_count) {
2842 case 8:
2843 channel_cnt_str = "Eight"; break;
2844 case 7:
2845 channel_cnt_str = "Seven"; break;
2846 case 6:
2847 channel_cnt_str = "Six"; break;
2848 case 5:
2849 channel_cnt_str = "Five"; break;
2850 case 4:
2851 channel_cnt_str = "Four"; break;
2852 case 3:
2853 channel_cnt_str = "Three"; break;
2854 default:
2855 channel_cnt_str = "Two"; break;
2856 }
2857 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2858 if (!ctl) {
2859 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2860 __func__, mixer_ctl_name);
2861 return -EINVAL;
2862 }
2863 ALOGV("HDMI channel count: %s", channel_cnt_str);
2864 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2865 return 0;
2866}
2867
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002868int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002869{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002870 struct platform_data *my_data = (struct platform_data *)platform;
2871 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002872 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2873 char *sad = block;
2874 int num_audio_blocks;
2875 int channel_count;
2876 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002877 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002878
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002879 struct mixer_ctl *ctl;
2880
2881 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2882 if (!ctl) {
2883 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2884 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002885 return 0;
2886 }
2887
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002888 mixer_ctl_update(ctl);
2889
2890 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002891
2892 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002893 if (count > (int)sizeof(block))
2894 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002895
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002896 ret = mixer_ctl_get_array(ctl, block, count);
2897 if (ret != 0) {
2898 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2899 return 0;
2900 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002901
2902 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002903 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002904
2905 for (i = 0; i < num_audio_blocks; i++) {
2906 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002907 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2908 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002909 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002910 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002911
2912 channel_count = (sad[0] & 0x7) + 1;
2913 if (channel_count > max_channels)
2914 max_channels = channel_count;
2915
2916 /* Advance to next block */
2917 sad += 3;
2918 }
2919
2920 return max_channels;
2921}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002922
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002923int platform_set_incall_recording_session_id(void *platform,
2924 uint32_t session_id, int rec_mode)
2925{
2926 int ret = 0;
2927 struct platform_data *my_data = (struct platform_data *)platform;
2928 struct audio_device *adev = my_data->adev;
2929 struct mixer_ctl *ctl;
2930 const char *mixer_ctl_name = "Voc VSID";
2931 int num_ctl_values;
2932 int i;
2933
2934 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2935 if (!ctl) {
2936 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2937 __func__, mixer_ctl_name);
2938 ret = -EINVAL;
2939 } else {
2940 num_ctl_values = mixer_ctl_get_num_values(ctl);
2941 for (i = 0; i < num_ctl_values; i++) {
2942 if (mixer_ctl_set_value(ctl, i, session_id)) {
2943 ALOGV("Error: invalid session_id: %x", session_id);
2944 ret = -EINVAL;
2945 break;
2946 }
2947 }
2948 }
2949
2950 if (my_data->csd != NULL) {
2951 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2952 if (ret < 0) {
2953 ALOGE("%s: csd_client_start_record failed, error %d",
2954 __func__, ret);
2955 }
2956 }
2957
2958 return ret;
2959}
2960
2961int platform_stop_incall_recording_usecase(void *platform)
2962{
2963 int ret = 0;
2964 struct platform_data *my_data = (struct platform_data *)platform;
2965
2966 if (my_data->csd != NULL) {
2967 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2968 if (ret < 0) {
2969 ALOGE("%s: csd_client_stop_record failed, error %d",
2970 __func__, ret);
2971 }
2972 }
2973
2974 return ret;
2975}
2976
2977int platform_start_incall_music_usecase(void *platform)
2978{
2979 int ret = 0;
2980 struct platform_data *my_data = (struct platform_data *)platform;
2981
2982 if (my_data->csd != NULL) {
2983 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2984 if (ret < 0) {
2985 ALOGE("%s: csd_client_start_playback failed, error %d",
2986 __func__, ret);
2987 }
2988 }
2989
2990 return ret;
2991}
2992
2993int platform_stop_incall_music_usecase(void *platform)
2994{
2995 int ret = 0;
2996 struct platform_data *my_data = (struct platform_data *)platform;
2997
2998 if (my_data->csd != NULL) {
2999 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3000 if (ret < 0) {
3001 ALOGE("%s: csd_client_stop_playback failed, error %d",
3002 __func__, ret);
3003 }
3004 }
3005
3006 return ret;
3007}
3008
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003009int platform_set_parameters(void *platform, struct str_parms *parms)
3010{
3011 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09003012 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003013 char *kv_pairs = str_parms_to_str(parms);
3014 int ret = 0, err;
3015
3016 if (kv_pairs == NULL) {
3017 ret = -EINVAL;
3018 ALOGE("%s: key-value pair is NULL",__func__);
3019 goto done;
3020 }
3021
3022 ALOGV("%s: enter: %s", __func__, kv_pairs);
3023
3024 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
3025 value, sizeof(value));
3026 if (err >= 0) {
3027 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3028 my_data->snd_card_name = strdup(value);
3029 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3030 }
3031
keunhui.park2f7306a2015-07-16 16:48:06 +09003032 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
3033 value, sizeof(value));
3034 if (err >= 0) {
3035 struct operator_info *info;
3036 char *str = value;
3037 char *name;
3038
3039 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3040 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3041 name = strtok(str, ";");
3042 info->name = strdup(name);
3043 info->mccmnc = strdup(str + strlen(name) + 1);
3044
3045 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003046 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003047 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003048
3049 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07003050 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07003051 value, sizeof(value));
3052 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003053 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003054 my_data->max_mic_count = atoi(value);
3055 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003056 }
3057
vivek mehta90933872017-06-15 18:04:39 -07003058 // to-do: disable setting sidetone gain, will revist this later
3059 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003060done:
3061 ALOGV("%s: exit with code(%d)", __func__, ret);
3062 if (kv_pairs != NULL)
3063 free(kv_pairs);
3064
3065 return ret;
3066}
3067
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003068/* Delay in Us */
3069int64_t platform_render_latency(audio_usecase_t usecase)
3070{
3071 switch (usecase) {
3072 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3073 return DEEP_BUFFER_PLATFORM_DELAY;
3074 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3075 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003076 case USECASE_AUDIO_PLAYBACK_ULL:
3077 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003078 case USECASE_AUDIO_PLAYBACK_MMAP:
3079 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003080 default:
3081 return 0;
3082 }
3083}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003084
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003085int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3086 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003087{
3088 int ret = 0;
3089
3090 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3091 ALOGE("%s: Invalid snd_device = %d",
3092 __func__, device);
3093 ret = -EINVAL;
3094 goto done;
3095 }
3096
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003097 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3098 platform_get_snd_device_name(device),
3099 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3100 if (backend_tag_table[device]) {
3101 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003102 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003103 backend_tag_table[device] = strdup(backend_tag);
3104
3105 if (hw_interface != NULL) {
3106 if (hw_interface_table[device])
3107 free(hw_interface_table[device]);
3108 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3109 hw_interface_table[device] = strdup(hw_interface);
3110 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003111done:
3112 return ret;
3113}
3114
3115int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3116{
3117 int ret = 0;
3118 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3119 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3120 ret = -EINVAL;
3121 goto done;
3122 }
3123
3124 if ((type != 0) && (type != 1)) {
3125 ALOGE("%s: invalid usecase type", __func__);
3126 ret = -EINVAL;
3127 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003128 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3129 use_case_table[usecase],
3130 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003131 pcm_device_table[usecase][type] = pcm_id;
3132done:
3133 return ret;
3134}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003135
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003136#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3137int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3138 // backup_gain: gain to try to set in case of an error during ramp
3139 int start_gain, end_gain, step, backup_gain, i;
3140 bool error = false;
3141 const struct mixer_ctl *ctl;
3142 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3143 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3144 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3145 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3146 if (!ctl_left || !ctl_right) {
3147 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3148 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3149 return -EINVAL;
3150 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3151 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3152 ALOGE("%s: Unexpected num values 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 }
3156 if (ramp_up) {
3157 start_gain = 0;
3158 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3159 step = +1;
3160 backup_gain = end_gain;
3161 } else {
3162 // using same gain on left and right
3163 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3164 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3165 end_gain = 0;
3166 step = -1;
3167 backup_gain = start_gain;
3168 }
3169 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3170 //ALOGV("setting speaker gain to %d", i);
3171 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3172 ALOGE("%s: error setting %s to %d during gain ramp",
3173 __func__, mixer_ctl_name_gain_left, i);
3174 error = true;
3175 break;
3176 }
3177 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3178 ALOGE("%s: error setting %s to %d during gain ramp",
3179 __func__, mixer_ctl_name_gain_right, i);
3180 error = true;
3181 break;
3182 }
3183 usleep(1000);
3184 }
3185 if (error) {
3186 // an error occured during the ramp, let's still try to go back to a safe volume
3187 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3188 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3189 }
3190 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3191 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3192 }
3193 }
3194 return start_gain;
3195}
3196
vivek mehtae59cfb22017-06-16 15:57:11 -07003197int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3198{
3199 const char *mixer_ctl_name = "Swap channel";
3200 struct mixer_ctl *ctl;
3201 const char *mixer_path;
3202 struct platform_data *my_data = (struct platform_data *)adev->platform;
3203
3204 // forced to set to swap, but device not rotated ... ignore set
3205 if (swap_channels && !my_data->speaker_lr_swap)
3206 return 0;
3207
3208 ALOGV("%s:", __func__);
3209
3210 if (swap_channels) {
3211 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3212 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3213 } else {
3214 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3215 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3216 }
3217
3218 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3219 if (!ctl) {
3220 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3221 return -EINVAL;
3222 }
3223
3224 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3225 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3226 return -EINVAL;
3227 }
3228
3229 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3230 swap_channels?"R --> L":"L --> R");
3231
3232 return 0;
3233}
3234
3235int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003236{
3237 // only update if there is active pcm playback on speaker
3238 struct audio_usecase *usecase;
3239 struct listnode *node;
3240 struct platform_data *my_data = (struct platform_data *)adev->platform;
3241
vivek mehtae59cfb22017-06-16 15:57:11 -07003242 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003243
vivek mehtae59cfb22017-06-16 15:57:11 -07003244 return platform_set_swap_channels(adev, swap_channels);
3245}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003246
vivek mehtae59cfb22017-06-16 15:57:11 -07003247int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3248{
3249 // only update if there is active pcm playback on speaker
3250 struct audio_usecase *usecase;
3251 struct listnode *node;
3252 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003253
vivek mehtae59cfb22017-06-16 15:57:11 -07003254 // do not swap channels in audio modes with concurrent capture and playback
3255 // as this may break the echo reference
3256 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3257 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3258 return 0;
3259 }
3260
3261 list_for_each(node, &adev->usecase_list) {
3262 usecase = node_to_item(node, struct audio_usecase, list);
3263 if (usecase->type == PCM_PLAYBACK &&
3264 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3265 /*
3266 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3267 * to perform device switch to disable the current backend to
3268 * enable it with new acdb data.
3269 */
3270 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3271 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3272 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3273 select_devices(adev, usecase->id);
3274 if (initial_skpr_gain != -EINVAL)
3275 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3276
3277 } else {
3278 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003279 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003280 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003281 }
3282 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003283
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003284 return 0;
3285}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003286
3287static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3288static int num_gain_tbl_entry = 0;
3289
3290bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3291
3292 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3293 if (num_gain_tbl_entry == -1) {
3294 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3295 __func__);
3296 return false;
3297 }
3298
3299 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3300 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3301 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3302 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3303 return false;
3304 }
3305
3306 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3307 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3308 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3309 return false;
3310 }
3311
3312 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3313 ++num_gain_tbl_entry;
3314
3315 return true;
3316}
3317
3318int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3319 int table_size) {
3320 int itt = 0;
3321 ALOGV("platform_get_gain_level_mapping called ");
3322
3323 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3324 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3325 return 0;
3326 }
3327
3328 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3329 mapping_tbl[itt] = tbl_mapping[itt];
3330 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3331 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3332 }
3333
3334 return num_gain_tbl_entry;
3335}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003336
3337int platform_snd_card_update(void *platform, card_status_t status)
3338{
3339 struct platform_data *my_data = (struct platform_data *)platform;
3340 struct audio_device *adev = my_data->adev;
3341
3342 if (status == CARD_STATUS_ONLINE) {
3343 if (my_data->acdb_send_custom_top)
3344 my_data->acdb_send_custom_top();
3345 }
3346 return 0;
3347}
David Linee3fe402017-03-13 10:00:42 -07003348
3349/*
3350 * configures afe with bit width and Sample Rate
3351 */
3352static int platform_set_backend_cfg(const struct audio_device* adev,
3353 snd_device_t snd_device,
3354 const struct audio_backend_cfg *backend_cfg)
3355{
3356
3357 int ret = 0;
3358 const int backend_idx = platform_get_backend_index(snd_device);
3359 struct platform_data *my_data = (struct platform_data *)adev->platform;
3360 const unsigned int bit_width = backend_cfg->bit_width;
3361 const unsigned int sample_rate = backend_cfg->sample_rate;
3362 const unsigned int channels = backend_cfg->channels;
3363 const audio_format_t format = backend_cfg->format;
3364 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3365
3366
3367 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3368 ", backend_idx %d device (%s)", __func__, bit_width,
3369 sample_rate, channels, backend_idx,
3370 platform_get_snd_device_name(snd_device));
3371
3372 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3373 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3374
3375 struct mixer_ctl *ctl = NULL;
3376 ctl = mixer_get_ctl_by_name(adev->mixer,
3377 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3378 if (!ctl) {
3379 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3380 __func__,
3381 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3382 return -EINVAL;
3383 }
3384
3385 if (bit_width == 24) {
3386 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3387 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3388 else
3389 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3390 } else if (bit_width == 32) {
3391 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3392 } else {
3393 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3394 }
3395 if ( ret < 0) {
3396 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3397 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3398 } else {
3399 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3400 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3401 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3402 }
3403 /* set the ret as 0 and not pass back to upper layer */
3404 ret = 0;
3405 }
3406
3407 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3408 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3409 char *rate_str = NULL;
3410 struct mixer_ctl *ctl = NULL;
3411
3412 switch (sample_rate) {
3413 case 32000:
3414 if (passthrough_enabled) {
3415 rate_str = "KHZ_32";
3416 break;
3417 }
3418 case 8000:
3419 case 11025:
3420 case 16000:
3421 case 22050:
3422 case 48000:
3423 rate_str = "KHZ_48";
3424 break;
3425 case 44100:
3426 rate_str = "KHZ_44P1";
3427 break;
3428 case 64000:
3429 case 96000:
3430 rate_str = "KHZ_96";
3431 break;
3432 case 88200:
3433 rate_str = "KHZ_88P2";
3434 break;
3435 case 176400:
3436 rate_str = "KHZ_176P4";
3437 break;
3438 case 192000:
3439 rate_str = "KHZ_192";
3440 break;
3441 case 352800:
3442 rate_str = "KHZ_352P8";
3443 break;
3444 case 384000:
3445 rate_str = "KHZ_384";
3446 break;
3447 case 144000:
3448 if (passthrough_enabled) {
3449 rate_str = "KHZ_144";
3450 break;
3451 }
3452 default:
3453 rate_str = "KHZ_48";
3454 break;
3455 }
3456
3457 ctl = mixer_get_ctl_by_name(adev->mixer,
3458 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3459 if(!ctl) {
3460 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3461 __func__,
3462 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3463 return -EINVAL;
3464 }
3465
3466 ALOGD("%s:becf: afe: %s set to %s", __func__,
3467 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3468 mixer_ctl_set_enum_by_string(ctl, rate_str);
3469 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3470 }
3471 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3472 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3473 struct mixer_ctl *ctl = NULL;
3474 char *channel_cnt_str = NULL;
3475
3476 switch (channels) {
3477 case 8:
3478 channel_cnt_str = "Eight"; break;
3479 case 7:
3480 channel_cnt_str = "Seven"; break;
3481 case 6:
3482 channel_cnt_str = "Six"; break;
3483 case 5:
3484 channel_cnt_str = "Five"; break;
3485 case 4:
3486 channel_cnt_str = "Four"; break;
3487 case 3:
3488 channel_cnt_str = "Three"; break;
3489 case 1:
3490 channel_cnt_str = "One"; break;
3491 case 2:
3492 default:
3493 channel_cnt_str = "Two"; break;
3494 }
3495
3496 ctl = mixer_get_ctl_by_name(adev->mixer,
3497 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3498 if (!ctl) {
3499 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3500 __func__,
3501 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3502 return -EINVAL;
3503 }
3504 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3505 my_data->current_backend_cfg[backend_idx].channels = channels;
3506
3507 // skip EDID configuration for HDMI backend
3508
3509 ALOGD("%s:becf: afe: %s set to %s", __func__,
3510 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3511 channel_cnt_str);
3512 }
3513
3514 // skip set ext_display format mixer control
3515 return ret;
3516}
3517
3518static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3519{
3520 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3521 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3522 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3523 }
3524
3525 return backend_bit_width_table[snd_device];
3526}
3527
3528/*
3529 * return backend_idx on which voice call is active
3530 */
3531static int platform_get_voice_call_backend(struct audio_device* adev)
3532{
3533 struct audio_usecase *uc = NULL;
3534 struct listnode *node;
3535 snd_device_t out_snd_device = SND_DEVICE_NONE;
3536
3537 int backend_idx = -1;
3538
3539 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3540 list_for_each(node, &adev->usecase_list) {
3541 uc = node_to_item(node, struct audio_usecase, list);
3542 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3543 out_snd_device = platform_get_output_snd_device(adev->platform,
3544 uc->stream.out->devices);
3545 backend_idx = platform_get_backend_index(out_snd_device);
3546 break;
3547 }
3548 }
3549 }
3550 return backend_idx;
3551}
3552
3553/*
3554 * goes through all the current usecases and picks the highest
3555 * bitwidth & samplerate
3556 */
3557static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3558 int backend_idx,
3559 struct audio_backend_cfg *backend_cfg)
3560{
3561 bool backend_change = false;
3562 unsigned int bit_width;
3563 unsigned int sample_rate;
3564 unsigned int channels;
3565 struct platform_data *my_data = (struct platform_data *)adev->platform;
3566
3567 bit_width = backend_cfg->bit_width;
3568 sample_rate = backend_cfg->sample_rate;
3569 channels = backend_cfg->channels;
3570
3571 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3572 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3573 sample_rate, channels);
3574
3575 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3576 // default backend
3577 // force routing is not required here, caller will do it anyway
3578 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3579 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3580 "for unprocessed/camera source", __func__);
3581 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3582 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3583 }
3584
3585 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3586 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3587 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3588 __func__, bit_width, sample_rate, channels);
3589 }
3590
3591 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3592 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3593
3594 // Force routing if the expected bitwdith or samplerate
3595 // is not same as current backend comfiguration
3596 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3597 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3598 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3599 backend_cfg->bit_width = bit_width;
3600 backend_cfg->sample_rate= sample_rate;
3601 backend_cfg->channels = channels;
3602 backend_change = true;
3603 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3604 "new sample rate: %d new channel: %d",
3605 __func__, backend_cfg->bit_width,
3606 backend_cfg->sample_rate, backend_cfg->channels);
3607 }
3608
3609 return backend_change;
3610}
3611
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003612static void pick_playback_cfg_for_uc(struct audio_device *adev,
3613 struct audio_usecase *usecase,
3614 snd_device_t snd_device,
3615 unsigned int *bit_width,
3616 unsigned int *sample_rate,
3617 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003618{
3619 int i =0;
3620 struct listnode *node;
3621 list_for_each(node, &adev->usecase_list) {
3622 struct audio_usecase *uc;
3623 uc = node_to_item(node, struct audio_usecase, list);
3624 struct stream_out *out = (struct stream_out*) uc->stream.out;
3625 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3626 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3627 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3628 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3629 uc->id, out->sample_rate,
3630 pcm_format_to_bits(out->config.format), out_channels,
3631 platform_get_snd_device_name(uc->out_snd_device));
3632
3633 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3634 if (*bit_width < pcm_format_to_bits(out->config.format))
3635 *bit_width = pcm_format_to_bits(out->config.format);
3636 if (*sample_rate < out->sample_rate)
3637 *sample_rate = out->sample_rate;
3638 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3639 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3640 if (*channels < out_channels)
3641 *channels = out_channels;
3642 }
3643 }
3644 }
3645 return;
3646}
3647
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003648static void headset_is_config_supported(unsigned int *bit_width,
3649 unsigned int *sample_rate,
3650 unsigned int *channels) {
3651 switch (*bit_width) {
3652 case 16:
3653 case 24:
3654 break;
3655 default:
3656 *bit_width = 16;
3657 break;
3658 }
3659
3660 if (*sample_rate > 192000) {
3661 *sample_rate = 192000;
3662 }
3663
3664 if (*channels > 2) {
3665 *channels = 2;
3666 }
3667}
3668
David Linee3fe402017-03-13 10:00:42 -07003669static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3670 struct audio_usecase* usecase,
3671 snd_device_t snd_device,
3672 struct audio_backend_cfg *backend_cfg)
3673{
3674 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003675 unsigned int bit_width;
3676 unsigned int sample_rate;
3677 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003678 int backend_idx = DEFAULT_CODEC_BACKEND;
3679 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003680
3681 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3682 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3683 backend_change = false;
3684 return backend_change;
3685 }
3686
3687 backend_idx = platform_get_backend_index(snd_device);
3688 bit_width = backend_cfg->bit_width;
3689 sample_rate = backend_cfg->sample_rate;
3690 channels = backend_cfg->channels;
3691
3692 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3693 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3694 sample_rate, channels, backend_idx, usecase->id,
3695 platform_get_snd_device_name(snd_device));
3696
3697 if (backend_idx == platform_get_voice_call_backend(adev)) {
3698 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3699 __func__);
3700 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3701 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3702 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3703 } else {
3704 /*
3705 * The backend should be configured at highest bit width and/or
3706 * sample rate amongst all playback usecases.
3707 * If the selected sample rate and/or bit width differ with
3708 * current backend sample rate and/or bit width, then, we set the
3709 * backend re-configuration flag.
3710 *
3711 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3712 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003713 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3714 &bit_width,
3715 &sample_rate,
3716 &channels);
David Linee3fe402017-03-13 10:00:42 -07003717 }
3718
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003719 switch (backend_idx) {
3720 case USB_AUDIO_RX_BACKEND:
3721 audio_extn_usb_is_config_supported(&bit_width,
3722 &sample_rate, &channels, true);
3723 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3724 __func__, bit_width, sample_rate, channels);
3725 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003726 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003727 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3728 break;
3729 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003730 default:
3731 bit_width = platform_get_snd_device_bit_width(snd_device);
3732 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3733 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3734 break;
David Linee3fe402017-03-13 10:00:42 -07003735 }
3736
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003737 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3738 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003739 __func__, backend_idx , bit_width, sample_rate);
3740
3741 // Force routing if the expected bitwdith or samplerate
3742 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003743 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3744 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3745 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003746 backend_cfg->bit_width = bit_width;
3747 backend_cfg->sample_rate = sample_rate;
3748 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003749 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003750 backend_change = true;
3751 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3752 "new sample rate: %d new channels: %d",
3753 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3754 }
3755
3756 return backend_change;
3757}
3758
3759bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3760 struct audio_usecase *usecase, snd_device_t snd_device)
3761{
3762 int backend_idx = DEFAULT_CODEC_BACKEND;
3763 int new_snd_devices[SND_DEVICE_OUT_END];
3764 int i, num_devices = 1;
3765 bool ret = false;
3766 struct platform_data *my_data = (struct platform_data *)adev->platform;
3767 struct audio_backend_cfg backend_cfg;
3768
3769 backend_idx = platform_get_backend_index(snd_device);
3770
3771 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3772 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3773 backend_cfg.format = usecase->stream.out->format;
3774 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3775 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3776 backend_cfg.passthrough_enabled = false;
3777
3778 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3779 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3780 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3781 platform_get_snd_device_name(snd_device));
3782
3783 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3784 new_snd_devices[0] = snd_device;
3785
3786 for (i = 0; i < num_devices; i++) {
3787 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3788 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3789 &backend_cfg))) {
3790 platform_set_backend_cfg(adev, new_snd_devices[i],
3791 &backend_cfg);
3792 ret = true;
3793 }
3794 }
3795 return ret;
3796}
3797
3798bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3799 struct audio_usecase *usecase, snd_device_t snd_device)
3800{
3801 int backend_idx = platform_get_backend_index(snd_device);
3802 int ret = 0;
3803 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003804 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003805
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003806 if (usecase->type == PCM_CAPTURE) {
3807 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003808 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3809 } else {
3810 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3811 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3812 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3813 backend_cfg.channels = 1;
3814 }
3815
3816 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3817 ", backend_idx %d usecase = %d device (%s)", __func__,
3818 backend_cfg.bit_width,
3819 backend_cfg.sample_rate,
3820 backend_cfg.channels,
3821 backend_idx, usecase->id,
3822 platform_get_snd_device_name(snd_device));
3823
3824 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3825 ret = platform_set_backend_cfg(adev, snd_device,
3826 &backend_cfg);
3827 if(!ret)
3828 return true;
3829 }
3830
3831 return false;
3832}
3833
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003834static int max_be_dai_names = 0;
3835static const struct be_dai_name_struct *be_dai_name_table;
3836
3837/*
3838 * Retrieves the be_dai_name_table from kernel to enable a mapping
3839 * between sound device hw interfaces and backend IDs. This allows HAL to
3840 * specify the backend a specific calibration is needed for.
3841 */
3842static int init_be_dai_name_table(struct audio_device *adev)
3843{
3844 const char *mixer_ctl_name = "Backend DAI Name Table";
3845 struct mixer_ctl *ctl;
3846 int i, j, ret, size;
3847 bool valid_hw_interface;
3848
3849 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3850 if (!ctl) {
3851 ALOGE("%s: Could not get ctl for mixer name %s\n",
3852 __func__, mixer_ctl_name);
3853 ret = -EINVAL;
3854 goto done;
3855 }
3856
3857 mixer_ctl_update(ctl);
3858
3859 size = mixer_ctl_get_num_values(ctl);
3860 if (size <= 0){
3861 ALOGE("%s: Failed to get %s size %d\n",
3862 __func__, mixer_ctl_name, size);
3863 ret = -EFAULT;
3864 goto done;
3865 }
3866
vivek mehtaa68fea62017-06-08 19:04:02 -07003867 be_dai_name_table =
3868 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003869 if (be_dai_name_table == NULL) {
3870 ALOGE("%s: Failed to allocate memory for %s\n",
3871 __func__, mixer_ctl_name);
3872 ret = -ENOMEM;
3873 goto freeMem;
3874 }
3875
3876 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
3877 if (ret) {
3878 ALOGE("%s: Failed to get %s, ret %d\n",
3879 __func__, mixer_ctl_name, ret);
3880 ret = -EFAULT;
3881 goto freeMem;
3882 }
3883
3884 if (be_dai_name_table != NULL) {
3885 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
3886 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
3887 __func__, mixer_ctl_name, max_be_dai_names);
3888 ret = 0;
3889 } else {
3890 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
3891 ret = -EFAULT;
3892 goto freeMem;
3893 }
3894
3895 /*
3896 * Validate all sound devices have a valid backend set to catch
3897 * errors for uncommon sound devices
3898 */
3899 for (i = 0; i < SND_DEVICE_MAX; i++) {
3900 valid_hw_interface = false;
3901
3902 if (hw_interface_table[i] == NULL) {
3903 ALOGW("%s: sound device %s has no hw interface set\n",
3904 __func__, platform_get_snd_device_name(i));
3905 continue;
3906 }
3907
3908 for (j = 0; j < max_be_dai_names; j++) {
3909 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
3910 == 0) {
3911 valid_hw_interface = true;
3912 break;
3913 }
3914 }
3915 if (!valid_hw_interface)
3916 ALOGD("%s: sound device %s does not have a valid hw interface set "
3917 "(disregard for combo devices) %s\n",
3918 __func__, platform_get_snd_device_name(i),
3919 hw_interface_table[i]);
3920 }
3921
3922 goto done;
3923
3924freeMem:
3925 if (be_dai_name_table) {
3926 free((void *)be_dai_name_table);
3927 be_dai_name_table = NULL;
3928 }
3929
3930done:
3931 return ret;
3932}
3933
3934int platform_get_snd_device_backend_index(snd_device_t device)
3935{
3936 int i, be_dai_id;
3937 const char * hw_interface_name = NULL;
3938
3939 ALOGV("%s: enter with device %d\n", __func__, device);
3940
vivek mehtaa68fea62017-06-08 19:04:02 -07003941 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003942 ALOGE("%s: Invalid snd_device = %d",
3943 __func__, device);
3944 be_dai_id = -EINVAL;
3945 goto done;
3946 }
3947
3948 /* Get string value of necessary backend for device */
3949 hw_interface_name = hw_interface_table[device];
3950 if (hw_interface_name == NULL) {
3951 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
3952 be_dai_id = -EINVAL;
3953 goto done;
3954 }
3955
3956 /* Check if be dai name table was retrieved successfully */
3957 if (be_dai_name_table == NULL) {
3958 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
3959 be_dai_id = -EFAULT;
3960 goto done;
3961 }
3962
3963 /* Get backend ID for device specified */
3964 for (i = 0; i < max_be_dai_names; i++) {
3965 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
3966 be_dai_id = be_dai_name_table[i].be_id;
3967 goto done;
3968 }
3969 }
3970 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
3971 be_dai_id = -EINVAL;
3972 goto done;
3973
3974done:
3975 return be_dai_id;
3976}
3977
3978void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
3979 unsigned int stream_sr, int* sample_rate)
3980{
3981 struct platform_data* my_data = (struct platform_data *)platform;
3982 int backend_idx = platform_get_backend_index(snd_device);
3983 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
3984 /*
3985 *Check if device SR is multiple of 8K or 11.025 Khz
3986 *check if the stream SR is multiple of same base, if yes
3987 *then have copp SR equal to stream SR, this ensures that
3988 *post processing happens at stream SR, else have
3989 *copp SR equal to device SR.
3990 */
3991 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
3992 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
3993 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
3994 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
3995 *sample_rate = device_sr;
3996 } else
3997 *sample_rate = stream_sr;
3998
3999 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4000 , *sample_rate);
4001
4002}
4003
4004// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004005void platform_add_app_type(const char *uc_type,
4006 const char *mode,
4007 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004008 int app_type, int max_rate) {
4009 struct app_type_entry *ap =
4010 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4011
4012 if (!ap) {
4013 ALOGE("%s failed to allocate mem for app type", __func__);
4014 return;
4015 }
4016
4017 ap->uc_type = -1;
4018 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4019 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4020 ap->uc_type = usecase_type_index[i].index;
4021 break;
4022 }
4023 }
4024
4025 if (ap->uc_type == -1) {
4026 free(ap);
4027 return;
4028 }
4029
vivek mehtaa68fea62017-06-08 19:04:02 -07004030 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4031 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004032 ap->bit_width = bw;
4033 ap->app_type = app_type;
4034 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004035 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004036 list_add_tail(&app_type_entry_list, &ap->node);
4037}
4038
4039
4040int platform_get_default_app_type_v2(void *platform __unused,
4041 usecase_type_t type,
4042 int *app_type )
4043{
4044 if (type == PCM_PLAYBACK)
4045 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4046 else
4047 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4048 return 0;
4049}
4050
vivek mehtaa68fea62017-06-08 19:04:02 -07004051int platform_get_app_type_v2(void *platform,
4052 usecase_type_t uc_type,
4053 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004054 int bw, int sr __unused,
4055 int *app_type)
4056{
4057 struct listnode *node;
4058 struct app_type_entry *entry;
4059 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004060
4061 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4062 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004063 list_for_each(node, &app_type_entry_list) {
4064 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004065 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4066 __func__, entry->uc_type, entry->mode, entry->bit_width,
4067 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004068 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004069 entry->uc_type == uc_type &&
4070 sr <= entry->max_rate &&
4071 entry->mode && !strcmp(mode, entry->mode)) {
4072 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004073 *app_type = entry->app_type;
4074 break;
4075 }
4076 }
4077
4078 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004079 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004080 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4081 }
4082 return 0;
4083}
vivek mehta90933872017-06-15 18:04:39 -07004084
4085int platform_set_sidetone(struct audio_device *adev,
4086 snd_device_t out_snd_device,
4087 bool enable, char *str)
4088{
4089 int ret;
4090 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4091 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4092 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4093 if (ret)
4094 ALOGI("%s: usb device %d does not support device sidetone\n",
4095 __func__, out_snd_device);
4096 } else {
4097 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4098 __func__, out_snd_device, str);
4099 if (enable)
4100 audio_route_apply_and_update_path(adev->audio_route, str);
4101 else
4102 audio_route_reset_and_update_path(adev->audio_route, str);
4103 }
4104 return 0;
4105}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004106
4107int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4108 int *fd __unused, uint32_t *size __unused)
4109{
4110#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
4111 struct platform_data *my_data = (struct platform_data *)platform;
4112 struct audio_device *adev = my_data->adev;
4113 int hw_fd = -1;
4114 char dev_name[128];
4115 struct snd_pcm_mmap_fd mmap_fd;
4116 memset(&mmap_fd, 0, sizeof(mmap_fd));
4117 mmap_fd.dir = dir;
4118 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4119 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4120 hw_fd = open(dev_name, O_RDONLY);
4121 if (hw_fd < 0) {
4122 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4123 return -1;
4124 }
4125 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4126 ALOGE("fe hw dep node ioctl failed");
4127 close(hw_fd);
4128 return -1;
4129 }
4130 *fd = mmap_fd.fd;
4131 *size = mmap_fd.size;
4132 close(hw_fd); // mmap_fd should still be valid
4133 return 0;
4134#else
4135 return -1;
4136#endif
4137}