blob: 44107bd3314c04bf44cc4ca2bad85c59537f38bf [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa6b79742017-03-09 15:40:43 -08002 * Copyright (C) 2013-2017 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Eric Laurentb23d5282013-05-14 15:27:20 -070016#define LOG_TAG "msm8974_platform"
17/*#define LOG_NDEBUG 0*/
18#define LOG_NDDEBUG 0
19
20#include <stdlib.h>
21#include <dlfcn.h>
Jiyong Park6431fe62017-06-29 15:15:58 +090022#include <pthread.h>
23#include <unistd.h>
Haynes Mathew Georgee6e2d442018-02-22 18:51:56 -080024#include <log/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070025#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070026#include <cutils/properties.h>
27#include <audio_hw.h>
28#include <platform_api.h>
vivek mehta0fb11312017-05-15 19:35:32 -070029#include "acdb.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070030#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070031#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070032#include <linux/msm_audio.h>
Alexey Polyudove920d4b2017-09-15 17:09:07 -070033#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -070034#include <sound/devdep_params.h>
35#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070036
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;
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700123#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
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},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200208
209 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
210 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700211};
212
213/* Array to store sound devices */
214static const char * const device_table[SND_DEVICE_MAX] = {
215 [SND_DEVICE_NONE] = "none",
216 /* Playback sound devices */
217 [SND_DEVICE_OUT_HANDSET] = "handset",
218 [SND_DEVICE_OUT_SPEAKER] = "speaker",
219 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700220 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700221 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500222 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700223 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700224 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500225 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700226 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700227 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500228 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700229 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
230 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500231 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700232 [SND_DEVICE_OUT_HDMI] = "hdmi",
233 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
234 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700235 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700236 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
237 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
238 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
239 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800240 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
241 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700242 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700243 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700244 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700245 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700246 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700247 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700248 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700249 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
250 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700251 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800252 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
253 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700254
255 /* Capture sound devices */
256 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700257 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700258 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
259 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
260 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
261 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
262 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
263 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
264 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
265
266 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
267 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
268 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
269 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
270 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
271 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
272 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
273 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
274 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
275
276 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500277 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700278
Eric Laurentb23d5282013-05-14 15:27:20 -0700279 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
280 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700281 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700282 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700283 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700284 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700285
286 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
287 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
288 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
289 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700290 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700291 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700292 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
293 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
294 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800295 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
296 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700297
Eric Laurentb23d5282013-05-14 15:27:20 -0700298 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700299 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700300 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700301 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700302 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
303 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700304 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700305 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
306 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
307 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
308 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700309 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700310
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700311 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700312 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
313 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
314 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
315 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800316
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700317 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700318
Prashant Malanic92c5962015-08-11 15:10:18 -0700319 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
320 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700321 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700322 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
323 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700324 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
325 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700326};
327
328/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700329static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700330 [SND_DEVICE_NONE] = -1,
331 [SND_DEVICE_OUT_HANDSET] = 7,
332 [SND_DEVICE_OUT_SPEAKER] = 15,
333 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700334 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700335 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500336 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700337 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700338 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500339 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700340 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700341 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
342 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500343 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700344 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500345 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700346 [SND_DEVICE_OUT_HDMI] = 18,
347 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
348 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700349 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700350 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700351 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
352 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
353 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800354 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
355 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700356 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700357 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700358 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700359 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700360 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700361 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700362 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700363 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
364 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700365 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700366
367 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700368 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
369 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
370 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
371 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
372 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
373 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
374 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
375 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
376
377 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
378 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
379 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
380 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
381 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
382 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
383 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
384 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
385 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
386
rago90fb9612015-12-02 11:37:53 -0800387 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500388 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700389
Eric Laurentb23d5282013-05-14 15:27:20 -0700390 [SND_DEVICE_IN_HDMI_MIC] = 4,
391 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700392 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700393 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700394 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700395 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700396
397 [SND_DEVICE_IN_VOICE_DMIC] = 41,
398 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
399 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700400 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700401 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800402 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700403 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
404 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
405 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800406 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
407 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700408
rago90fb9612015-12-02 11:37:53 -0800409 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700410 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700411 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700412 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700413 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
414 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800415 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
416
417 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
418 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700419 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
420 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
421 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700422
423 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700424 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700425 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
426 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
427 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
428 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700429 [SND_DEVICE_IN_THREE_MIC] = 46,
430 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700431 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700432 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
433 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700434 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
435 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700436};
437
David Linee3fe402017-03-13 10:00:42 -0700438// Platform specific backend bit width table
439static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
440
Haynes Mathew George98c95622014-06-20 19:14:25 -0700441struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700442 char name[100];
443 unsigned int index;
444};
445
446#define TO_NAME_INDEX(X) #X, X
447
Haynes Mathew George98c95622014-06-20 19:14:25 -0700448/* Used to get index from parsed string */
449static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
450 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700451 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
452 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
453 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700454 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700455 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500456 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700457 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700458 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500459 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700460 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700461 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
462 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700463 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700464 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500465 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700466 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
467 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
468 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
469 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700470 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500471 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700472 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
473 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
474 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800475 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
476 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800477 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
478 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700479 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700480 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700481 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700482 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700483 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700484 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700485 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
486 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800487
488 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700489 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700490 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700491 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
492 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
493 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
494 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
495 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
496 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
497 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
498
499 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700500 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700501 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
502 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
503 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
504 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
505 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
506 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
507 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
508
509 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700510 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700511
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700512 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
513 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700514 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700515 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700516 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700517 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700518
519 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
520 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
521 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700522 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700523 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
524 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700525 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
526 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
527 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800528 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
529 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
530
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700531
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700532 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700533 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700534 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700535 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700536 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
537 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700538 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700539 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700540 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
541 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
542 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700544
rago90fb9612015-12-02 11:37:53 -0800545 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
546 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700547 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
548 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
549 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800550
Prashant Malanic92c5962015-08-11 15:10:18 -0700551 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
552 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700553 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700554 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
555 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700556 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
557 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700558};
559
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700560static char * backend_tag_table[SND_DEVICE_MAX] = {0};
561static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700562
563static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
564 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
565 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800566 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700567 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700568 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
569 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800570 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700571 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
572 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800573 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700574 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700575 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
576 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
577 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
578 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
579 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800580 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
581 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700582 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
583 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
584 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
585 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800586 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
587 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
588 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
589 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
590 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700591 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
592 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200593 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700594};
595
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800596static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
597 {TO_NAME_INDEX(PCM_PLAYBACK)},
598 {TO_NAME_INDEX(PCM_CAPTURE)},
599 {TO_NAME_INDEX(VOICE_CALL)},
600 {TO_NAME_INDEX(PCM_HFP_CALL)},
601};
602
603struct app_type_entry {
604 int uc_type;
605 int bit_width;
606 int app_type;
607 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700608 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800609 struct listnode node; // membership in app_type_entry_list;
610};
611
612static struct listnode app_type_entry_list;
613
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700614#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
615#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800616#define ULL_PLATFORM_DELAY (3*1000LL)
617#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700618
Eric Laurentb23d5282013-05-14 15:27:20 -0700619static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
620static bool is_tmus = false;
621
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800622static int init_be_dai_name_table(struct audio_device *adev);
623
Eric Laurentb23d5282013-05-14 15:27:20 -0700624static void check_operator()
625{
626 char value[PROPERTY_VALUE_MAX];
627 int mccmnc;
628 property_get("gsm.sim.operator.numeric",value,"0");
629 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700630 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700631 switch(mccmnc) {
632 /* TMUS MCC(310), MNC(490, 260, 026) */
633 case 310490:
634 case 310260:
635 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900636 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
637 case 310800:
638 case 310660:
639 case 310580:
640 case 310310:
641 case 310270:
642 case 310250:
643 case 310240:
644 case 310230:
645 case 310220:
646 case 310210:
647 case 310200:
648 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700649 is_tmus = true;
650 break;
651 }
652}
653
654bool is_operator_tmus()
655{
656 pthread_once(&check_op_once_ctl, check_operator);
657 return is_tmus;
658}
659
keunhui.park2f7306a2015-07-16 16:48:06 +0900660static char *get_current_operator()
661{
662 struct listnode *node;
663 struct operator_info *info_item;
664 char mccmnc[PROPERTY_VALUE_MAX];
665 char *ret = NULL;
666
Tom Cherry7fea2042016-11-10 18:05:59 -0800667 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900668
669 list_for_each(node, &operator_info_list) {
670 info_item = node_to_item(node, struct operator_info, list);
671 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
672 ret = info_item->name;
673 }
674 }
675
676 return ret;
677}
678
679static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
680{
681 struct listnode *node;
682 struct operator_specific_device *ret = NULL;
683 struct operator_specific_device *device_item;
684 char *operator_name;
685
686 operator_name = get_current_operator();
687 if (operator_name == NULL)
688 return ret;
689
690 list_for_each(node, operator_specific_device_table[snd_device]) {
691 device_item = node_to_item(node, struct operator_specific_device, list);
692 if (strcmp(operator_name, device_item->operator) == 0) {
693 ret = device_item;
694 }
695 }
696
697 return ret;
698}
699
700
701static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
702{
703 struct operator_specific_device *device;
704 int ret = acdb_device_table[snd_device];
705
706 device = get_operator_specific_device(snd_device);
707 if (device != NULL)
708 ret = device->acdb_id;
709
710 return ret;
711}
712
713static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
714{
715 struct operator_specific_device *device;
716 const char *ret = device_table[snd_device];
717
718 device = get_operator_specific_device(snd_device);
719 if (device != NULL)
720 ret = device->mixer_path;
721
722 return ret;
723}
724
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800725inline bool platform_supports_app_type_cfg()
726{
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700727#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800728 return true;
729#else
730 return false;
731#endif
732}
733
vivek mehta1a9b7c02015-06-25 11:49:38 -0700734bool platform_send_gain_dep_cal(void *platform, int level)
735{
736 bool ret_val = false;
737 struct platform_data *my_data = (struct platform_data *)platform;
738 struct audio_device *adev = my_data->adev;
739 int acdb_dev_id, app_type;
740 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
741 int mode = CAL_MODE_RTAC;
742 struct listnode *node;
743 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700744 bool valid_uc_type;
745 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700746
747 if (my_data->acdb_send_gain_dep_cal == NULL) {
748 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
749 return ret_val;
750 }
751
752 if (!voice_is_in_call(adev)) {
753 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
754 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700755
756 // find the current active sound device
757 list_for_each(node, &adev->usecase_list) {
758 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700759 LOG_ALWAYS_FATAL_IF(usecase == NULL,
760 "unxpected NULL usecase in usecase_list");
761 valid_uc_type = usecase->type == PCM_PLAYBACK;
762 valid_dev = false;
763 if (valid_uc_type) {
764 audio_devices_t dev = usecase->stream.out->devices;
765 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700766 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700767 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
768 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
769 }
770 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700771 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
772 if (platform_supports_app_type_cfg())
773 app_type = usecase->stream.out->app_type_cfg.app_type;
774 else
775 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700776
vivek mehta7e573672018-03-13 17:41:41 -0700777 acdb_dev_id =
778 acdb_device_table[audio_extn_get_spkr_prot_snd_device(usecase->out_snd_device)];
vivek mehta40125092017-08-21 18:48:51 -0700779
780 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700781 acdb_dev_type, mode, level)) {
782 // set ret_val true if at least one calibration is set successfully
783 ret_val = true;
784 } else {
785 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
786 }
787 } else {
788 ALOGW("%s: Usecase list is empty", __func__);
789 }
790 }
791 } else {
792 ALOGW("%s: Voice call in progress .. ignore setting new cal",
793 __func__);
794 }
795 return ret_val;
796}
797
Eric Laurentcefbbac2014-09-04 13:54:10 -0500798void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700799{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800800 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500801 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700802
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800803 if (strcmp(my_data->ec_ref_mixer_path, "")) {
804 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
805 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500806 }
807
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800808 if (enable) {
809 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
810 if (out_device != AUDIO_DEVICE_NONE) {
811 snd_device = platform_get_output_snd_device(adev->platform, out_device);
812 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
813 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500814
Joe Onorato188b6222016-03-01 11:02:27 -0800815 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800816 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
817 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700818}
819
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700820static struct csd_data *open_csd_client(bool i2s_ext_modem)
821{
822 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
823
824 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
825 if (csd->csd_client == NULL) {
826 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
827 goto error;
828 } else {
829 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
830
831 csd->deinit = (deinit_t)dlsym(csd->csd_client,
832 "csd_client_deinit");
833 if (csd->deinit == NULL) {
834 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
835 dlerror());
836 goto error;
837 }
838 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
839 "csd_client_disable_device");
840 if (csd->disable_device == NULL) {
841 ALOGE("%s: dlsym error %s for csd_client_disable_device",
842 __func__, dlerror());
843 goto error;
844 }
845 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
846 "csd_client_enable_device_config");
847 if (csd->enable_device_config == NULL) {
848 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
849 __func__, dlerror());
850 goto error;
851 }
852 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
853 "csd_client_enable_device");
854 if (csd->enable_device == NULL) {
855 ALOGE("%s: dlsym error %s for csd_client_enable_device",
856 __func__, dlerror());
857 goto error;
858 }
859 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
860 "csd_client_start_voice");
861 if (csd->start_voice == NULL) {
862 ALOGE("%s: dlsym error %s for csd_client_start_voice",
863 __func__, dlerror());
864 goto error;
865 }
866 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
867 "csd_client_stop_voice");
868 if (csd->stop_voice == NULL) {
869 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
870 __func__, dlerror());
871 goto error;
872 }
873 csd->volume = (volume_t)dlsym(csd->csd_client,
874 "csd_client_volume");
875 if (csd->volume == NULL) {
876 ALOGE("%s: dlsym error %s for csd_client_volume",
877 __func__, dlerror());
878 goto error;
879 }
880 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
881 "csd_client_mic_mute");
882 if (csd->mic_mute == NULL) {
883 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
884 __func__, dlerror());
885 goto error;
886 }
887 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
888 "csd_client_slow_talk");
889 if (csd->slow_talk == NULL) {
890 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
891 __func__, dlerror());
892 goto error;
893 }
894 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
895 "csd_client_start_playback");
896 if (csd->start_playback == NULL) {
897 ALOGE("%s: dlsym error %s for csd_client_start_playback",
898 __func__, dlerror());
899 goto error;
900 }
901 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
902 "csd_client_stop_playback");
903 if (csd->stop_playback == NULL) {
904 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
905 __func__, dlerror());
906 goto error;
907 }
908 csd->start_record = (start_record_t)dlsym(csd->csd_client,
909 "csd_client_start_record");
910 if (csd->start_record == NULL) {
911 ALOGE("%s: dlsym error %s for csd_client_start_record",
912 __func__, dlerror());
913 goto error;
914 }
915 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
916 "csd_client_stop_record");
917 if (csd->stop_record == NULL) {
918 ALOGE("%s: dlsym error %s for csd_client_stop_record",
919 __func__, dlerror());
920 goto error;
921 }
922
923 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
924 "csd_client_get_sample_rate");
925 if (csd->get_sample_rate == NULL) {
926 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
927 __func__, dlerror());
928
929 goto error;
930 }
931
932 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
933
934 if (csd->init == NULL) {
935 ALOGE("%s: dlsym error %s for csd_client_init",
936 __func__, dlerror());
937 goto error;
938 } else {
939 csd->init(i2s_ext_modem);
940 }
941 }
942 return csd;
943
944error:
945 free(csd);
946 csd = NULL;
947 return csd;
948}
949
950void close_csd_client(struct csd_data *csd)
951{
952 if (csd != NULL) {
953 csd->deinit();
954 dlclose(csd->csd_client);
955 free(csd);
956 csd = NULL;
957 }
958}
959
960static void platform_csd_init(struct platform_data *my_data)
961{
962#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700963 int32_t modems, (*count_modems)(void);
964 const char *name = "libdetectmodem.so";
965 const char *func = "count_modems";
966 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700967
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700968 my_data->csd = NULL;
969
970 void *lib = dlopen(name, RTLD_NOW);
971 error = dlerror();
972 if (!lib) {
973 ALOGE("%s: could not find %s: %s", __func__, name, error);
974 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700975 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700976
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700977 count_modems = NULL;
978 *(void **)(&count_modems) = dlsym(lib, func);
979 error = dlerror();
980 if (!count_modems) {
981 ALOGE("%s: could not find symbol %s in %s: %s",
982 __func__, func, name, error);
983 goto done;
984 }
985
986 modems = count_modems();
987 if (modems < 0) {
988 ALOGE("%s: count_modems failed\n", __func__);
989 goto done;
990 }
991
Eric Laurent2bafff12016-03-17 12:17:23 -0700992 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700993 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700994 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700995
996done:
997 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700998#else
999 my_data->csd = NULL;
1000#endif
1001}
1002
Eric Laurentc6333382015-09-14 12:43:44 -07001003static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001004{
1005 int32_t dev;
1006 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001007 backend_tag_table[dev] = NULL;
1008 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001009 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001010 }
1011
David Linee3fe402017-03-13 10:00:42 -07001012 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1013 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1014 }
1015
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001016 // To overwrite these go to the audio_platform_info.xml file.
1017 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001018 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001019 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1020 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1021 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1022 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1023 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001024 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001025 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1026 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001027
David Linee3fe402017-03-13 10:00:42 -07001028 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001029 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001030 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001031 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001032 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1033 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001034 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1035 strdup("speaker-safe-and-usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001036 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001037 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1038 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1039 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1040 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001041 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1042 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1043 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1044 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1045 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1046 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1047 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001048 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001049 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001050 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001051 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1052 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1053 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1054 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1055 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1056 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1057 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1058 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1059 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
1060 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1061 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1062 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1063 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001064 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001065 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1066 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001067 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001068 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001069 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001070 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 -07001071 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 -07001072 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1073 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1074 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001075 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1076 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1077 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1078 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1079 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1080 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1081 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
1082 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1083 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1084 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1085 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1086 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001087 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1088 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
1089 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1090 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001091 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1092 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1093 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1094 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1095 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001096 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1097 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1098 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1099 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1100 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1101 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1102 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1103 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1104 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1105 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001106 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001107}
1108
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001109void get_cvd_version(char *cvd_version, struct audio_device *adev)
1110{
1111 struct mixer_ctl *ctl;
1112 int count;
1113 int ret = 0;
1114
1115 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1116 if (!ctl) {
1117 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1118 goto done;
1119 }
1120 mixer_ctl_update(ctl);
1121
1122 count = mixer_ctl_get_num_values(ctl);
1123 if (count > MAX_CVD_VERSION_STRING_SIZE)
1124 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1125
1126 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1127 if (ret != 0) {
1128 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1129 goto done;
1130 }
1131
1132done:
1133 return;
1134}
1135
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001136static int platform_acdb_init(void *platform)
1137{
1138 struct platform_data *my_data = (struct platform_data *)platform;
1139 struct audio_device *adev = my_data->adev;
1140
1141 if (!my_data->acdb_init) {
1142 ALOGE("%s: no acdb_init fn provided", __func__);
1143 return -1;
1144 }
1145
1146 if (my_data->acdb_initialized) {
1147 ALOGW("acdb is already initialized");
1148 return 0;
1149 }
1150
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001151#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001152 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1153 if (!cvd_version)
1154 ALOGE("failed to allocate cvd_version");
1155 else {
1156 get_cvd_version(cvd_version, adev);
1157 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1158 free(cvd_version);
1159 }
1160#elif defined (PLATFORM_MSM8084)
1161 my_data->acdb_init((char *)my_data->snd_card_name);
1162#else
1163 my_data->acdb_init();
1164#endif
1165 my_data->acdb_initialized = true;
1166 return 0;
1167}
1168
David Linee3fe402017-03-13 10:00:42 -07001169static void
1170platform_backend_config_init(struct platform_data *pdata)
1171{
1172 int i;
1173
1174 /* initialize backend config */
1175 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1176 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1177 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1178 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1179
1180 if (i > MAX_RX_CODEC_BACKENDS)
1181 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1182
1183 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1184 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1185 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1186 }
1187
1188 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1189 strdup("SLIM_0_RX Format");
1190 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1191 strdup("SLIM_0_RX SampleRate");
1192
1193 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1194 strdup("SLIM_0_TX Format");
1195 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1196 strdup("SLIM_0_TX SampleRate");
1197
1198 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1199 strdup("USB_AUDIO_TX Format");
1200 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1201 strdup("USB_AUDIO_TX SampleRate");
1202 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1203 strdup("USB_AUDIO_TX Channels");
1204
1205 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1206 strdup("SLIM_6_RX Format");
1207 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1208 strdup("SLIM_6_RX SampleRate");
1209
1210 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1211 strdup("USB_AUDIO_RX Format");
1212 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1213 strdup("USB_AUDIO_RX SampleRate");
1214
1215 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1216 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1217 strdup("USB_AUDIO_RX Channels");
1218}
1219
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001220static int
1221platform_backend_app_type_cfg_init(struct platform_data *pdata,
1222 struct mixer *mixer)
1223{
1224 size_t app_type_cfg[128] = {0};
1225 int length, num_app_types = 0;
1226 struct mixer_ctl *ctl = NULL;
1227
1228 const char *mixer_ctl_name = "App Type Config";
1229 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1230 if (!ctl) {
1231 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1232 return -1;
1233 }
1234
1235 length = 1; // reserve index 0 for number of app types
1236
1237 struct listnode *node;
1238 struct app_type_entry *entry;
1239 list_for_each(node, &app_type_entry_list) {
1240 entry = node_to_item(node, struct app_type_entry, node);
1241 app_type_cfg[length++] = entry->app_type;
1242 app_type_cfg[length++] = entry->max_rate;
1243 app_type_cfg[length++] = entry->bit_width;
1244 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1245 num_app_types += 1;
1246 }
1247
1248 // default for capture
1249 int t;
1250 platform_get_default_app_type_v2(pdata,
1251 PCM_CAPTURE,
1252 &t);
1253 app_type_cfg[length++] = t;
1254 app_type_cfg[length++] = 48000;
1255 app_type_cfg[length++] = 16;
1256 num_app_types += 1;
1257
1258 if (num_app_types) {
1259 app_type_cfg[0] = num_app_types;
1260 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1261 ALOGE("Failed to set app type cfg");
1262 }
1263 }
1264 return 0;
1265}
1266
Eric Laurentb23d5282013-05-14 15:27:20 -07001267void *platform_init(struct audio_device *adev)
1268{
1269 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001270 struct platform_data *my_data = NULL;
1271 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1272 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001273 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001274 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001275 char *snd_internal_name = NULL;
1276 char *tmp = NULL;
1277 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001278 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1279 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001280 my_data = calloc(1, sizeof(struct platform_data));
1281
1282 my_data->adev = adev;
1283
keunhui.park2f7306a2015-07-16 16:48:06 +09001284 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001285 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001286
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001287 set_platform_defaults(my_data);
1288
vivek mehta0fb11312017-05-15 19:35:32 -07001289 // audio_extn_utils_get_snd_card_num does
1290 // - open mixer and get snd card name
1291 // - parse platform info xml file and check for valid snd card name
1292 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001293
vivek mehta0fb11312017-05-15 19:35:32 -07001294 snd_card_num = audio_extn_utils_get_snd_card_num();
1295 if (-1 == snd_card_num) {
1296 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1297 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001298 }
1299
vivek mehta0fb11312017-05-15 19:35:32 -07001300 adev->mixer = mixer_open(snd_card_num);
1301 snd_card_name = mixer_get_name(adev->mixer);
1302 my_data->hw_info = hw_info_init(snd_card_name);
1303
1304 audio_extn_set_snd_card_split(snd_card_name);
1305 snd_split_handle = audio_extn_get_snd_card_split();
1306
1307 /* Get the codec internal name from the sound card and/or form factor
1308 * name and form the mixer paths and platfor info file name dynamically.
1309 * This is generic way of picking any codec and forma factor name based
1310 * mixer and platform info files in future with no code change.
1311
1312 * current code extends and looks for any of the exteneded mixer path and
1313 * platform info file present based on codec and form factor.
1314
1315 * order of picking appropriate file is
1316 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1317 * <ii> mixer_paths_<codec_name>.xml, if file not present
1318 * <iii> mixer_paths.xml
1319
1320 * same order is followed for audio_platform_info.xml as well
1321 */
1322
1323 // need to carryforward old file name
1324 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1325 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1326 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1327 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1328 } else {
1329
1330 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1331 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1332 snd_split_handle->form_factor);
1333 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1334 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1335 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1336 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1337
1338 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1339 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1340 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1341 audio_extn_utils_resolve_config_file(mixer_xml_file);
1342 }
1343 }
1344 }
1345
1346 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1347
1348 /* Initialize platform specific ids and/or backends*/
1349 platform_info_init(platform_info_file, my_data);
1350
1351 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1352 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1353
1354 if (!adev->audio_route) {
1355 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1356 mixer_close(adev->mixer);
1357 adev->mixer = NULL;
1358 hw_info_deinit(my_data->hw_info);
1359 my_data->hw_info = NULL;
1360 goto init_failed;
1361 }
1362 adev->snd_card = snd_card_num;
1363 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1364
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001365 //set max volume step for voice call
1366 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1367 my_data->max_vol_index = atoi(value);
1368
vivek mehta65ad12d2015-08-13 18:32:48 -07001369 property_get("persist.audio.dualmic.config",value,"");
1370 if (!strcmp("endfire", value)) {
1371 dual_mic_config = true;
1372 }
1373
John Muir9e59a962018-01-10 13:30:00 -08001374 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001375
Eric Laurentb23d5282013-05-14 15:27:20 -07001376 my_data->fluence_in_spkr_mode = false;
1377 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001378 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001379 my_data->fluence_in_voice_rec = false;
1380
vivek mehta65ad12d2015-08-13 18:32:48 -07001381 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001382 if (!strcmp("fluencepro", value)) {
1383 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001384 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001385 my_data->fluence_type = FLUENCE_ENABLE;
1386 } else if (!strcmp("none", value)) {
1387 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001388 }
1389
Prashant Malanic92c5962015-08-11 15:10:18 -07001390 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001391 property_get("persist.audio.fluence.voicecall",value,"");
1392 if (!strcmp("true", value)) {
1393 my_data->fluence_in_voice_call = true;
1394 }
1395
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001396 property_get("persist.audio.fluence.voicecomm",value,"");
1397 if (!strcmp("true", value)) {
1398 my_data->fluence_in_voice_comm = true;
1399 }
1400
Eric Laurentb23d5282013-05-14 15:27:20 -07001401 property_get("persist.audio.fluence.voicerec",value,"");
1402 if (!strcmp("true", value)) {
1403 my_data->fluence_in_voice_rec = true;
1404 }
1405
1406 property_get("persist.audio.fluence.speaker",value,"");
1407 if (!strcmp("true", value)) {
1408 my_data->fluence_in_spkr_mode = true;
1409 }
1410 }
1411
Prashant Malanic92c5962015-08-11 15:10:18 -07001412 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1413 switch (my_data->max_mic_count) {
1414 case 4:
1415 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1416 case 3:
1417 my_data->source_mic_type |= SOURCE_THREE_MIC;
1418 case 2:
1419 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1420 case 1:
1421 my_data->source_mic_type |= SOURCE_MONO_MIC;
1422 break;
1423 default:
1424 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1425 __func__, my_data->max_mic_count);
1426 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1427 break;
1428 }
1429
1430 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1431 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1432 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1433 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1434 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1435
Eric Laurentb23d5282013-05-14 15:27:20 -07001436 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1437 if (my_data->acdb_handle == NULL) {
1438 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1439 } else {
1440 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1441 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1442 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001443 if (!my_data->acdb_deallocate)
1444 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1445 __func__, LIB_ACDB_LOADER);
1446
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001447 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1448 "acdb_loader_send_audio_cal_v3");
1449 if (!my_data->acdb_send_audio_cal_v3)
1450 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1451 __func__, LIB_ACDB_LOADER);
1452
Eric Laurentb23d5282013-05-14 15:27:20 -07001453 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1454 "acdb_loader_send_audio_cal");
1455 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001456 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001457 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001458
Eric Laurentb23d5282013-05-14 15:27:20 -07001459 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1460 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001461 if (!my_data->acdb_send_voice_cal)
1462 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1463 __func__, LIB_ACDB_LOADER);
1464
1465 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1466 "acdb_loader_reload_vocvoltable");
1467 if (!my_data->acdb_reload_vocvoltable)
1468 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1469 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001470
1471 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1472 "acdb_loader_send_gain_dep_cal");
1473 if (!my_data->acdb_send_gain_dep_cal)
1474 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1475 __func__, LIB_ACDB_LOADER);
1476
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001477#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
vivek mehta0fb11312017-05-15 19:35:32 -07001478 acdb_init_v2_cvd_t acdb_init_local;
1479 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001480 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001481 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001482 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1483 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001484
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001485#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001486 acdb_init_v2_t acdb_init_local;
1487 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001488 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001489 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001490 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1491 dlerror());
1492
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001493#else
vivek mehta0fb11312017-05-15 19:35:32 -07001494 acdb_init_t acdb_init_local;
1495 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001496 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001497 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001498 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1499 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001500#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001501 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001502
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001503 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1504 dlsym(my_data->acdb_handle,
1505 "acdb_loader_send_common_custom_topology");
1506
1507 if (!my_data->acdb_send_custom_top)
1508 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1509 __func__, LIB_ACDB_LOADER);
1510
vivek mehta0fb11312017-05-15 19:35:32 -07001511 int result = acdb_init(adev->snd_card);
1512 if (!result) {
1513 my_data->acdb_initialized = true;
1514 ALOGD("ACDB initialized");
1515 } else {
1516 my_data->acdb_initialized = false;
1517 ALOGD("ACDB initialization failed");
1518 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001519 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001520
David Linee3fe402017-03-13 10:00:42 -07001521 /* init usb */
1522 audio_extn_usb_init(adev);
1523
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001524 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001525
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001526 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1527
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001528 /* load csd client */
1529 platform_csd_init(my_data);
1530
David Linee3fe402017-03-13 10:00:42 -07001531 platform_backend_config_init(my_data);
1532
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001533 init_be_dai_name_table(adev);
1534
1535 if (platform_supports_app_type_cfg())
1536 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1537
Eric Laurentb23d5282013-05-14 15:27:20 -07001538 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001539
1540init_failed:
1541 if (my_data)
1542 free(my_data);
1543 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001544}
1545
1546void platform_deinit(void *platform)
1547{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001548 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001549 struct operator_info *info_item;
1550 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001551 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001552 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001553
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001554 struct platform_data *my_data = (struct platform_data *)platform;
1555 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001556
vivek mehtade4849c2016-03-03 17:23:38 -08001557 hw_info_deinit(my_data->hw_info);
1558
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001559 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1560 if (backend_tag_table[dev])
1561 free(backend_tag_table[dev]);
1562 if (hw_interface_table[dev])
1563 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001564 if (operator_specific_device_table[dev]) {
1565 while (!list_empty(operator_specific_device_table[dev])) {
1566 node = list_head(operator_specific_device_table[dev]);
1567 list_remove(node);
1568 device_item = node_to_item(node, struct operator_specific_device, list);
1569 free(device_item->operator);
1570 free(device_item->mixer_path);
1571 free(device_item);
1572 }
1573 free(operator_specific_device_table[dev]);
1574 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001575 }
1576
1577 if (my_data->snd_card_name)
1578 free(my_data->snd_card_name);
1579
keunhui.park2f7306a2015-07-16 16:48:06 +09001580 while (!list_empty(&operator_info_list)) {
1581 node = list_head(&operator_info_list);
1582 list_remove(node);
1583 info_item = node_to_item(node, struct operator_info, list);
1584 free(info_item->name);
1585 free(info_item->mccmnc);
1586 free(info_item);
1587 }
1588
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001589 while (!list_empty(&app_type_entry_list)) {
1590 node = list_head(&app_type_entry_list);
1591 list_remove(node);
1592 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001593 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001594 free(ap);
1595 }
1596
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001597 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001598 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001599
1600 /* deinit usb */
1601 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001602}
1603
1604const char *platform_get_snd_device_name(snd_device_t snd_device)
1605{
keunhui.park2f7306a2015-07-16 16:48:06 +09001606 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1607 if (operator_specific_device_table[snd_device] != NULL) {
1608 return get_operator_specific_device_mixer_path(snd_device);
1609 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001610 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001611 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001612 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001613}
1614
vivek mehtade4849c2016-03-03 17:23:38 -08001615int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1616 char *device_name)
1617{
1618 struct platform_data *my_data = (struct platform_data *)platform;
1619
David Benjamin1565f992016-09-21 12:10:34 -04001620 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001621 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001622 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1623 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001624 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1625 if (operator_specific_device_table[snd_device] != NULL) {
1626 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1627 DEVICE_NAME_MAX_SIZE);
1628 } else {
1629 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1630 }
1631 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1632 } else {
1633 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1634 }
1635
1636 return 0;
1637}
1638
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001639void platform_add_backend_name(void *platform, char *mixer_path,
1640 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001641{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001642 struct platform_data *my_data = (struct platform_data *)platform;
1643
Haynes Mathew George98c95622014-06-20 19:14:25 -07001644 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1645 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1646 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001647 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001648
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001649 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001650
1651 if (suffix != NULL) {
1652 strcat(mixer_path, " ");
1653 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001654 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001655}
1656
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001657bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1658{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001659 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1660 platform_get_snd_device_name(snd_device1),
1661 platform_get_snd_device_name(snd_device2));
1662
1663 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1664 ALOGE("%s: Invalid snd_device = %s", __func__,
1665 platform_get_snd_device_name(snd_device1));
1666 return false;
1667 }
1668 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1669 ALOGE("%s: Invalid snd_device = %s", __func__,
1670 platform_get_snd_device_name(snd_device2));
1671 return false;
1672 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001673
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001674 const char * be_itf1 = hw_interface_table[snd_device1];
1675 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001676 /*
1677 hw_interface_table has overrides for a snd_device.
1678 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1679 */
1680 if (be_itf1 == NULL) {
1681 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001682 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001683 if (be_itf2 == NULL) {
1684 be_itf2 = DEFAULT_RX_BACKEND;
1685 }
1686 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1687 /*
1688 this takes care of finding a device within a combo device pair as well
1689 */
1690 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001691}
1692
Eric Laurentb23d5282013-05-14 15:27:20 -07001693int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1694{
1695 int device_id;
1696 if (device_type == PCM_PLAYBACK)
1697 device_id = pcm_device_table[usecase][0];
1698 else
1699 device_id = pcm_device_table[usecase][1];
1700 return device_id;
1701}
1702
Haynes Mathew George98c95622014-06-20 19:14:25 -07001703static int find_index(const struct name_to_index * table, int32_t len,
1704 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001705{
1706 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001707 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001708
Haynes Mathew George98c95622014-06-20 19:14:25 -07001709 if (table == NULL) {
1710 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001711 ret = -ENODEV;
1712 goto done;
1713 }
1714
Haynes Mathew George98c95622014-06-20 19:14:25 -07001715 if (name == NULL) {
1716 ALOGE("null key");
1717 ret = -ENODEV;
1718 goto done;
1719 }
1720
1721 for (i=0; i < len; i++) {
1722 if (!strcmp(table[i].name, name)) {
1723 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001724 goto done;
1725 }
1726 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001727 ALOGE("%s: Could not find index for name = %s",
1728 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001729 ret = -ENODEV;
1730done:
1731 return ret;
1732}
1733
Haynes Mathew George98c95622014-06-20 19:14:25 -07001734int platform_get_snd_device_index(char *device_name)
1735{
1736 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1737}
1738
1739int platform_get_usecase_index(const char *usecase_name)
1740{
1741 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1742}
1743
keunhui.park2f7306a2015-07-16 16:48:06 +09001744void platform_add_operator_specific_device(snd_device_t snd_device,
1745 const char *operator,
1746 const char *mixer_path,
1747 unsigned int acdb_id)
1748{
1749 struct operator_specific_device *device;
1750
1751 if (operator_specific_device_table[snd_device] == NULL) {
1752 operator_specific_device_table[snd_device] =
1753 (struct listnode *)calloc(1, sizeof(struct listnode));
1754 list_init(operator_specific_device_table[snd_device]);
1755 }
1756
1757 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1758
1759 device->operator = strdup(operator);
1760 device->mixer_path = strdup(mixer_path);
1761 device->acdb_id = acdb_id;
1762
1763 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1764
Eric Laurent2bafff12016-03-17 12:17:23 -07001765 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001766 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1767
1768}
1769
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001770int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1771{
1772 int ret = 0;
1773
1774 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1775 ALOGE("%s: Invalid snd_device = %d",
1776 __func__, snd_device);
1777 ret = -EINVAL;
1778 goto done;
1779 }
1780
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001781 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1782 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001783 acdb_device_table[snd_device] = acdb_id;
1784done:
1785 return ret;
1786}
1787
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001788int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1789{
1790 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1791 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1792 return -EINVAL;
1793 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001794
1795 if (operator_specific_device_table[snd_device] != NULL)
1796 return get_operator_specific_device_acdb_id(snd_device);
1797 else
1798 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001799}
1800
David Linee3fe402017-03-13 10:00:42 -07001801static int platform_get_backend_index(snd_device_t snd_device)
1802{
1803 int32_t port = DEFAULT_CODEC_BACKEND;
1804
1805 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1806 if (backend_tag_table[snd_device] != NULL) {
1807 if (strncmp(backend_tag_table[snd_device], "headphones",
1808 sizeof("headphones")) == 0)
1809 port = HEADPHONE_BACKEND;
1810 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1811 port = HDMI_RX_BACKEND;
1812 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1813 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1814 port = USB_AUDIO_RX_BACKEND;
1815 }
1816 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1817 port = DEFAULT_CODEC_TX_BACKEND;
1818 if (backend_tag_table[snd_device] != NULL) {
1819 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1820 port = USB_AUDIO_TX_BACKEND;
1821 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1822 port = BT_SCO_TX_BACKEND;
1823 }
1824 } else {
1825 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1826 }
1827
1828 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1829
1830 return port;
1831}
1832
Eric Laurentb23d5282013-05-14 15:27:20 -07001833int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1834{
1835 struct platform_data *my_data = (struct platform_data *)platform;
1836 int acdb_dev_id, acdb_dev_type;
1837
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001838 if (platform_supports_app_type_cfg()) // use v2 instead
1839 return -ENOSYS;
1840
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001841 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001842 if (acdb_dev_id < 0) {
1843 ALOGE("%s: Could not find acdb id for device(%d)",
1844 __func__, snd_device);
1845 return -EINVAL;
1846 }
1847 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001848 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001849 __func__, snd_device, acdb_dev_id);
1850 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1851 snd_device < SND_DEVICE_OUT_END)
1852 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1853 else
1854 acdb_dev_type = ACDB_DEV_TYPE_IN;
1855 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1856 }
1857 return 0;
1858}
1859
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001860int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1861 int app_type, int sample_rate)
1862{
1863 struct platform_data *my_data = (struct platform_data *)platform;
1864 int acdb_dev_id, acdb_dev_type;
vivek mehta7e573672018-03-13 17:41:41 -07001865 int snd_device = usecase->out_snd_device;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001866 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1867 int i, num_devices = 1;
1868
1869 if (!platform_supports_app_type_cfg()) // use v1 instead
1870 return -ENOSYS;
1871
vivek mehta7e573672018-03-13 17:41:41 -07001872 if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001873 snd_device = usecase->in_snd_device;
1874
1875 // skipped over get_spkr_prot_device
vivek mehta7e573672018-03-13 17:41:41 -07001876 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001877 if (acdb_dev_id < 0) {
1878 ALOGE("%s: Could not find acdb id for device(%d)",
1879 __func__, snd_device);
1880 return -EINVAL;
1881 }
1882
1883 if (platform_can_split_snd_device(snd_device,
1884 &num_devices, new_snd_device) < 0) {
1885 new_snd_device[0] = snd_device;
1886 }
1887
1888 for (i = 0; i < num_devices; i++) {
vivek mehta7e573672018-03-13 17:41:41 -07001889 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(new_snd_device[i])];
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001890 if (acdb_dev_id < 0) {
1891 ALOGE("%s: Could not find acdb id for device(%d)",
1892 __func__, new_snd_device[i]);
1893 return -EINVAL;
1894 }
1895 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1896 __func__, new_snd_device[i], acdb_dev_id);
1897 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1898 new_snd_device[i] < SND_DEVICE_OUT_END)
1899 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1900 else
1901 acdb_dev_type = ACDB_DEV_TYPE_IN;
1902
1903 if (my_data->acdb_send_audio_cal_v3) {
1904 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1905 app_type, sample_rate, i);
1906 } else if (my_data->acdb_send_audio_cal) {
1907 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
1908 }
1909 }
1910
1911 return 0;
1912}
1913
1914
Eric Laurentb23d5282013-05-14 15:27:20 -07001915int platform_switch_voice_call_device_pre(void *platform)
1916{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001917 struct platform_data *my_data = (struct platform_data *)platform;
1918 int ret = 0;
1919
1920 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001921 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001922 /* This must be called before disabling mixer controls on APQ side */
1923 ret = my_data->csd->disable_device();
1924 if (ret < 0) {
1925 ALOGE("%s: csd_client_disable_device, failed, error %d",
1926 __func__, ret);
1927 }
1928 }
1929 return ret;
1930}
1931
1932int platform_switch_voice_call_enable_device_config(void *platform,
1933 snd_device_t out_snd_device,
1934 snd_device_t in_snd_device)
1935{
1936 struct platform_data *my_data = (struct platform_data *)platform;
1937 int acdb_rx_id, acdb_tx_id;
1938 int ret = 0;
1939
1940 if (my_data->csd == NULL)
1941 return ret;
1942
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001943 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1944 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001945 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001946 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001947 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001948
keunhui.park2f7306a2015-07-16 16:48:06 +09001949 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001950
1951 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1952 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1953 if (ret < 0) {
1954 ALOGE("%s: csd_enable_device_config, failed, error %d",
1955 __func__, ret);
1956 }
1957 } else {
1958 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1959 acdb_rx_id, acdb_tx_id);
1960 }
1961
1962 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001963}
1964
1965int platform_switch_voice_call_device_post(void *platform,
1966 snd_device_t out_snd_device,
1967 snd_device_t in_snd_device)
1968{
1969 struct platform_data *my_data = (struct platform_data *)platform;
1970 int acdb_rx_id, acdb_tx_id;
1971
1972 if (my_data->acdb_send_voice_cal == NULL) {
1973 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1974 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001975 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1976 audio_extn_spkr_prot_is_enabled())
1977 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1978
keunhui.park2f7306a2015-07-16 16:48:06 +09001979 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1980 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001981
1982 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1983 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1984 else
1985 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1986 acdb_rx_id, acdb_tx_id);
1987 }
1988
1989 return 0;
1990}
1991
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001992int platform_switch_voice_call_usecase_route_post(void *platform,
1993 snd_device_t out_snd_device,
1994 snd_device_t in_snd_device)
1995{
1996 struct platform_data *my_data = (struct platform_data *)platform;
1997 int acdb_rx_id, acdb_tx_id;
1998 int ret = 0;
1999
2000 if (my_data->csd == NULL)
2001 return ret;
2002
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002003 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2004 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09002005 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002006 else
keunhui.park2f7306a2015-07-16 16:48:06 +09002007 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002008
keunhui.park2f7306a2015-07-16 16:48:06 +09002009 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002010
2011 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2012 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2013 my_data->adev->acdb_settings);
2014 if (ret < 0) {
2015 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2016 }
2017 } else {
2018 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2019 acdb_rx_id, acdb_tx_id);
2020 }
2021
2022 return ret;
2023}
2024
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002025int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002026{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002027 struct platform_data *my_data = (struct platform_data *)platform;
2028 int ret = 0;
2029
2030 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002031 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002032 if (ret < 0) {
2033 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2034 }
2035 }
2036 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002037}
2038
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002039int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002040{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002041 struct platform_data *my_data = (struct platform_data *)platform;
2042 int ret = 0;
2043
2044 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002045 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002046 if (ret < 0) {
2047 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2048 }
2049 }
2050 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002051}
2052
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002053int platform_get_sample_rate(void *platform, uint32_t *rate)
2054{
2055 struct platform_data *my_data = (struct platform_data *)platform;
2056 int ret = 0;
2057
2058 if (my_data->csd != NULL) {
2059 ret = my_data->csd->get_sample_rate(rate);
2060 if (ret < 0) {
2061 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2062 }
2063 }
2064 return ret;
2065}
2066
vivek mehtab6506412015-08-07 16:55:17 -07002067void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2068 snd_device_t snd_device,
2069 bool enable)
2070{
2071 const char* name;
2072 switch (snd_device) {
2073 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2074 if (enable)
2075 name = "spkr-gain-in-headphone-combo";
2076 else
2077 name = "speaker-gain-default";
2078 break;
2079 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2080 if (enable)
2081 name = "spkr-gain-in-line-combo";
2082 else
2083 name = "speaker-gain-default";
2084 break;
2085 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2086 if (enable)
2087 name = "spkr-safe-gain-in-headphone-combo";
2088 else
2089 name = "speaker-safe-gain-default";
2090 break;
2091 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2092 if (enable)
2093 name = "spkr-safe-gain-in-line-combo";
2094 else
2095 name = "speaker-safe-gain-default";
2096 break;
2097 default:
2098 return;
2099 }
2100
2101 audio_route_apply_and_update_path(adev->audio_route, name);
2102}
2103
Eric Laurentb23d5282013-05-14 15:27:20 -07002104int platform_set_voice_volume(void *platform, int volume)
2105{
2106 struct platform_data *my_data = (struct platform_data *)platform;
2107 struct audio_device *adev = my_data->adev;
2108 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002109 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002110 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002111 int vol_index = 0, ret = 0;
2112 uint32_t set_values[ ] = {0,
2113 ALL_SESSION_VSID,
2114 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002115
2116 // Voice volume levels are mapped to adsp volume levels as follows.
2117 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2118 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002119 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002120 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002121
2122 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2123 if (!ctl) {
2124 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2125 __func__, mixer_ctl_name);
2126 return -EINVAL;
2127 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002128 ALOGV("Setting voice volume index: %d", set_values[0]);
2129 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2130
Nadav Barc46d0fa2017-12-24 14:50:37 +02002131 // Send mute command in case volume index is max since indexes are inverted
2132 // for mixer controls.
2133 if (vol_index == my_data->max_vol_index) {
2134 set_values[0] = 1;
2135 }
2136 else {
2137 set_values[0] = 0;
2138 }
2139
2140 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2141 if (!ctl) {
2142 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2143 __func__, mute_mixer_ctl_name);
2144 return -EINVAL;
2145 }
2146 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2147 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2148
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002149 if (my_data->csd != NULL) {
2150 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2151 DEFAULT_VOLUME_RAMP_DURATION_MS);
2152 if (ret < 0) {
2153 ALOGE("%s: csd_volume error %d", __func__, ret);
2154 }
2155 }
2156 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002157}
2158
2159int platform_set_mic_mute(void *platform, bool state)
2160{
2161 struct platform_data *my_data = (struct platform_data *)platform;
2162 struct audio_device *adev = my_data->adev;
2163 struct mixer_ctl *ctl;
2164 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002165 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002166 uint32_t set_values[ ] = {0,
2167 ALL_SESSION_VSID,
2168 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002169
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002170 if (adev->mode != AUDIO_MODE_IN_CALL &&
2171 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002172 return 0;
2173
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002174 if (adev->enable_hfp)
2175 mixer_ctl_name = "HFP Tx Mute";
2176
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002177 set_values[0] = state;
2178 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2179 if (!ctl) {
2180 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2181 __func__, mixer_ctl_name);
2182 return -EINVAL;
2183 }
2184 ALOGV("Setting voice mute state: %d", state);
2185 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2186
2187 if (my_data->csd != NULL) {
2188 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2189 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002190 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002191 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002192 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002193 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002194 return ret;
2195}
Eric Laurentb23d5282013-05-14 15:27:20 -07002196
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002197int platform_set_device_mute(void *platform, bool state, char *dir)
2198{
2199 struct platform_data *my_data = (struct platform_data *)platform;
2200 struct audio_device *adev = my_data->adev;
2201 struct mixer_ctl *ctl;
2202 char *mixer_ctl_name = NULL;
2203 int ret = 0;
2204 uint32_t set_values[ ] = {0,
2205 ALL_SESSION_VSID,
2206 0};
2207 if(dir == NULL) {
2208 ALOGE("%s: Invalid direction:%s", __func__, dir);
2209 return -EINVAL;
2210 }
2211
2212 if (!strncmp("rx", dir, sizeof("rx"))) {
2213 mixer_ctl_name = "Voice Rx Device Mute";
2214 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2215 mixer_ctl_name = "Voice Tx Device Mute";
2216 } else {
2217 return -EINVAL;
2218 }
2219
2220 set_values[0] = state;
2221 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2222 if (!ctl) {
2223 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2224 __func__, mixer_ctl_name);
2225 return -EINVAL;
2226 }
2227
2228 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2229 __func__,state, mixer_ctl_name);
2230 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2231
2232 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002233}
2234
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002235int platform_can_split_snd_device(snd_device_t snd_device,
2236 int *num_devices,
2237 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002238{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002239 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002240 if (NULL == num_devices || NULL == new_snd_devices) {
2241 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002242 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002243 }
2244
2245 /*
2246 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002247 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002248 */
2249 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2250 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2251 *num_devices = 2;
2252 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2253 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002254 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002255 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2256 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2257 *num_devices = 2;
2258 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2259 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002260 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002261 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2262 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2263 *num_devices = 2;
2264 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2265 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002266 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002267 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2268 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2269 *num_devices = 2;
2270 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2271 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002272 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002273 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2274 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2275 SND_DEVICE_OUT_BT_SCO)) {
2276 *num_devices = 2;
2277 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2278 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2279 ret = 0;
2280 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2281 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2282 SND_DEVICE_OUT_BT_SCO_WB)) {
2283 *num_devices = 2;
2284 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2285 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2286 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002287 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2288 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2289 *num_devices = 2;
2290 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2291 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2292 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002293 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2294 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2295 *num_devices = 2;
2296 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2297 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2298 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002299 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002300 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002301}
2302
Eric Laurentb23d5282013-05-14 15:27:20 -07002303snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2304{
2305 struct platform_data *my_data = (struct platform_data *)platform;
2306 struct audio_device *adev = my_data->adev;
2307 audio_mode_t mode = adev->mode;
2308 snd_device_t snd_device = SND_DEVICE_NONE;
2309
2310 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2311 if (devices == AUDIO_DEVICE_NONE ||
2312 devices & AUDIO_DEVICE_BIT_IN) {
2313 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2314 goto exit;
2315 }
2316
Eric Laurent1b491552015-09-15 17:52:41 -07002317 if (popcount(devices) == 2) {
2318 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2319 AUDIO_DEVICE_OUT_SPEAKER) ||
2320 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2321 AUDIO_DEVICE_OUT_SPEAKER)) {
2322 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2323 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2324 AUDIO_DEVICE_OUT_SPEAKER)) {
2325 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2326 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2327 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2328 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2329 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2330 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2331 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2332 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2333 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2334 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2335 AUDIO_DEVICE_OUT_SPEAKER)) {
2336 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002337 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2338 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2339 snd_device = adev->bt_wb_speech_enabled ?
2340 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2341 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002342 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2343 AUDIO_DEVICE_OUT_SPEAKER)) ||
2344 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2345 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002346 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002347 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2348 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2349 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2350 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002351 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002352 } else {
2353 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2354 goto exit;
2355 }
2356 if (snd_device != SND_DEVICE_NONE) {
2357 goto exit;
2358 }
2359 }
2360
2361 if (popcount(devices) != 1) {
2362 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2363 goto exit;
2364 }
2365
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302366 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002367 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002368 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2369 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002370 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002371 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002372 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002373 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002374 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002375 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002376 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002377 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002378 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002379 else {
2380 if (devices & AUDIO_DEVICE_OUT_LINE)
2381 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2382 else
2383 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2384 }
Eric Laurent99dab492017-06-17 15:19:08 -07002385 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002386 if (voice_is_in_call(adev)) {
2387 switch (adev->voice.tty_mode) {
2388 case TTY_MODE_FULL:
2389 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2390 break;
2391 case TTY_MODE_VCO:
2392 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2393 break;
2394 case TTY_MODE_HCO:
2395 // since Hearing will be on handset\speaker, use existing device
2396 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2397 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002398 case TTY_MODE_OFF:
2399 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002400 default:
2401 ALOGE("%s: Invalid TTY mode (%#x)",
2402 __func__, adev->voice.tty_mode);
2403 }
2404 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002405 if (snd_device == SND_DEVICE_NONE) {
2406 snd_device = audio_extn_usb_is_capture_supported() ?
2407 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2408 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2409 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002410 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002411 if (adev->bt_wb_speech_enabled) {
2412 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2413 } else {
2414 snd_device = SND_DEVICE_OUT_BT_SCO;
2415 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002416 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002417 if (!adev->enable_hfp) {
2418 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2419 } else {
2420 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2421 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002422 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002423 if(adev->voice.hac)
2424 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2425 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002426 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2427 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002428 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002429 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2430 snd_device = SND_DEVICE_OUT_VOICE_TX;
2431
Eric Laurentb23d5282013-05-14 15:27:20 -07002432 if (snd_device != SND_DEVICE_NONE) {
2433 goto exit;
2434 }
2435 }
2436
Eric Laurentb23d5282013-05-14 15:27:20 -07002437 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2438 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2439 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002440 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2441 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002442 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2443 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002444 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002445 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002446 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2447 else
2448 snd_device = SND_DEVICE_OUT_SPEAKER;
2449 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002450 if (adev->bt_wb_speech_enabled) {
2451 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2452 } else {
2453 snd_device = SND_DEVICE_OUT_BT_SCO;
2454 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002455 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2456 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002457 } else if (audio_is_usb_out_device(devices)) {
David Linee3fe402017-03-13 10:00:42 -07002458 if (audio_extn_usb_is_capture_supported())
2459 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2460 else
2461 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2462 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002463 /*HAC support for voice-ish audio (eg visual voicemail)*/
2464 if(adev->voice.hac)
2465 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2466 else
2467 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002468 } else {
2469 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2470 }
2471exit:
2472 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2473 return snd_device;
2474}
2475
2476snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2477{
2478 struct platform_data *my_data = (struct platform_data *)platform;
2479 struct audio_device *adev = my_data->adev;
2480 audio_source_t source = (adev->active_input == NULL) ?
2481 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2482
2483 audio_mode_t mode = adev->mode;
2484 audio_devices_t in_device = ((adev->active_input == NULL) ?
2485 AUDIO_DEVICE_NONE : adev->active_input->device)
2486 & ~AUDIO_DEVICE_BIT_IN;
2487 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2488 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2489 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002490 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002491
Prashant Malanic92c5962015-08-11 15:10:18 -07002492 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2493 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002494 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2495 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002496 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002497 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002498 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2499 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002500 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002501 case TTY_MODE_FULL:
2502 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2503 break;
2504 case TTY_MODE_VCO:
2505 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2506 break;
2507 case TTY_MODE_HCO:
2508 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2509 break;
2510 default:
2511 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2512 }
2513 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002514 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002515 switch (adev->voice.tty_mode) {
2516 case TTY_MODE_FULL:
2517 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2518 break;
2519 case TTY_MODE_VCO:
2520 // since voice will be captured from handset mic, use existing device
2521 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2522 break;
2523 case TTY_MODE_HCO:
2524 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2525 break;
2526 default:
2527 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002528 }
2529 goto exit;
2530 }
2531 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002532 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002533 if (my_data->fluence_in_voice_call == false) {
2534 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2535 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002536 if (is_operator_tmus())
2537 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002538 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002539 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002540 }
2541 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2542 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2543 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002544 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002545 if (adev->bluetooth_nrec)
2546 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2547 else
2548 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002549 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002550 if (adev->bluetooth_nrec)
2551 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2552 else
2553 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002554 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002555 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002556 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2557 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2558 out_device & AUDIO_DEVICE_OUT_LINE) {
2559 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2560 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2561 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2562 } else {
2563 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2564 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002565 }
vivek mehtafe121d52015-08-10 23:39:23 -07002566
2567 //select default
2568 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002569 if (!adev->enable_hfp) {
2570 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2571 } else {
2572 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2573 platform_set_echo_reference(adev, true, out_device);
2574 }
vivek mehtafe121d52015-08-10 23:39:23 -07002575 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002576 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002577 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002578 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002579 if (audio_extn_usb_is_capture_supported()) {
2580 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2581 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2582 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2583 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2584 } else {
2585 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2586 }
2587 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002588 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002589 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2590 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2591 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2592 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2593 }
2594 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2595 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002596 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2597 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2598 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002599 if (adev->active_input->enable_aec)
2600 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2601 else
2602 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002603 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2604 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002605 if (adev->active_input->enable_aec)
2606 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2607 else
2608 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002609 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2610 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2611 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002612 if (adev->active_input->enable_aec)
2613 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2614 else
2615 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002616 }
2617 platform_set_echo_reference(adev, true, out_device);
2618 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2619 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2620 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002621 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002622 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2623 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002624 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002625 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2626 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002627 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002628 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002629 if (adev->active_input->enable_aec) {
2630 if (adev->active_input->enable_ns) {
2631 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2632 } else {
2633 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2634 }
vivek mehta733c1df2016-04-04 15:09:24 -07002635 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002636 } else if (adev->active_input->enable_ns) {
2637 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2638 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002639 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002640 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002641 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002642 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2643 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002644 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002645 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002646 }
rago90fb9612015-12-02 11:37:53 -08002647 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2648 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002649 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2650 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2651 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2652 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002653 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002654 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2655 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002656 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002657 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2658 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2659 } else {
2660 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2661 }
rago90fb9612015-12-02 11:37:53 -08002662 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2663 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002664 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002665 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002666 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002667 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002668 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002669 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2670 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2671 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2672 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002673 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002674 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002675 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002676 if (adev->active_input->enable_aec &&
2677 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002678 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002679 if (my_data->fluence_in_spkr_mode &&
2680 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002681 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002682 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002683 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002684 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002685 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002686 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002687 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002688 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002689 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002690 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002691 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002692 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002693 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2694 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002695 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002696 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002697 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002698 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002699 } else if (adev->active_input->enable_aec) {
2700 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2701 if (my_data->fluence_in_spkr_mode &&
2702 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002703 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002704 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002705 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002706 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002707 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002708 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2709 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002710 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002711 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002712 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002713 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002714 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002715 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2716 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002717 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002718 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002719 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002720 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002721 } else if (adev->active_input->enable_ns) {
2722 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2723 if (my_data->fluence_in_spkr_mode &&
2724 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002725 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002726 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002727 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002728 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002729 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002730 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2731 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002732 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002733 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002734 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002735 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002736 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002737 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002738 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002739 }
2740 } else if (source == AUDIO_SOURCE_DEFAULT) {
2741 goto exit;
2742 }
2743
2744
2745 if (snd_device != SND_DEVICE_NONE) {
2746 goto exit;
2747 }
2748
2749 if (in_device != AUDIO_DEVICE_NONE &&
2750 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2751 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2752 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002753 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002754 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002755 snd_device = SND_DEVICE_IN_QUAD_MIC;
2756 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002757 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002758 snd_device = SND_DEVICE_IN_THREE_MIC;
2759 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2760 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002761 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002762 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2763 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002764 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002765 } else {
2766 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2767 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2768 my_data->source_mic_type, channel_count, channel_mask);
2769 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2770 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002771 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002772 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2773 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002774 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002775 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2776 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002777 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002778 } else {
2779 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2780 " no combination found .. setting to mono", __func__,
2781 my_data->source_mic_type, channel_count);
2782 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2783 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002784 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2785 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2786 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002787 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002788 if (adev->bluetooth_nrec)
2789 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2790 else
2791 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002792 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002793 if (adev->bluetooth_nrec)
2794 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2795 else
2796 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002797 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002798 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2799 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002800 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07002801 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002802 } else {
2803 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2804 ALOGW("%s: Using default handset-mic", __func__);
2805 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2806 }
2807 } else {
2808 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2809 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2810 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2811 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002812 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002813 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002814 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002815 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002816 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2817 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002818 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002819 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2820 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002821 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002822 } else {
2823 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2824 " no combination found .. setting to mono", __func__,
2825 my_data->source_mic_type, channel_count);
2826 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2827 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002828 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002829 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002830 if (adev->bluetooth_nrec)
2831 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2832 else
2833 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002834 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002835 if (adev->bluetooth_nrec)
2836 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2837 else
2838 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002839 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002840 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2841 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002842 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07002843 if (audio_extn_usb_is_capture_supported())
2844 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2845 else
2846 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002847 } else {
2848 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2849 ALOGW("%s: Using default handset-mic", __func__);
2850 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2851 }
2852 }
2853exit:
2854 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2855 return snd_device;
2856}
2857
2858int platform_set_hdmi_channels(void *platform, int channel_count)
2859{
2860 struct platform_data *my_data = (struct platform_data *)platform;
2861 struct audio_device *adev = my_data->adev;
2862 struct mixer_ctl *ctl;
2863 const char *channel_cnt_str = NULL;
2864 const char *mixer_ctl_name = "HDMI_RX Channels";
2865 switch (channel_count) {
2866 case 8:
2867 channel_cnt_str = "Eight"; break;
2868 case 7:
2869 channel_cnt_str = "Seven"; break;
2870 case 6:
2871 channel_cnt_str = "Six"; break;
2872 case 5:
2873 channel_cnt_str = "Five"; break;
2874 case 4:
2875 channel_cnt_str = "Four"; break;
2876 case 3:
2877 channel_cnt_str = "Three"; break;
2878 default:
2879 channel_cnt_str = "Two"; break;
2880 }
2881 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2882 if (!ctl) {
2883 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2884 __func__, mixer_ctl_name);
2885 return -EINVAL;
2886 }
2887 ALOGV("HDMI channel count: %s", channel_cnt_str);
2888 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2889 return 0;
2890}
2891
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002892int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002893{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002894 struct platform_data *my_data = (struct platform_data *)platform;
2895 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002896 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2897 char *sad = block;
2898 int num_audio_blocks;
2899 int channel_count;
2900 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002901 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002902
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002903 struct mixer_ctl *ctl;
2904
2905 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2906 if (!ctl) {
2907 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2908 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002909 return 0;
2910 }
2911
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002912 mixer_ctl_update(ctl);
2913
2914 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002915
2916 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002917 if (count > (int)sizeof(block))
2918 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002919
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002920 ret = mixer_ctl_get_array(ctl, block, count);
2921 if (ret != 0) {
2922 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2923 return 0;
2924 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002925
2926 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002927 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002928
2929 for (i = 0; i < num_audio_blocks; i++) {
2930 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002931 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2932 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002933 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002934 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002935
2936 channel_count = (sad[0] & 0x7) + 1;
2937 if (channel_count > max_channels)
2938 max_channels = channel_count;
2939
2940 /* Advance to next block */
2941 sad += 3;
2942 }
2943
2944 return max_channels;
2945}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002946
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002947int platform_set_incall_recording_session_id(void *platform,
2948 uint32_t session_id, int rec_mode)
2949{
2950 int ret = 0;
2951 struct platform_data *my_data = (struct platform_data *)platform;
2952 struct audio_device *adev = my_data->adev;
2953 struct mixer_ctl *ctl;
2954 const char *mixer_ctl_name = "Voc VSID";
2955 int num_ctl_values;
2956 int i;
2957
2958 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2959 if (!ctl) {
2960 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2961 __func__, mixer_ctl_name);
2962 ret = -EINVAL;
2963 } else {
2964 num_ctl_values = mixer_ctl_get_num_values(ctl);
2965 for (i = 0; i < num_ctl_values; i++) {
2966 if (mixer_ctl_set_value(ctl, i, session_id)) {
2967 ALOGV("Error: invalid session_id: %x", session_id);
2968 ret = -EINVAL;
2969 break;
2970 }
2971 }
2972 }
2973
2974 if (my_data->csd != NULL) {
2975 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2976 if (ret < 0) {
2977 ALOGE("%s: csd_client_start_record failed, error %d",
2978 __func__, ret);
2979 }
2980 }
2981
2982 return ret;
2983}
2984
2985int platform_stop_incall_recording_usecase(void *platform)
2986{
2987 int ret = 0;
2988 struct platform_data *my_data = (struct platform_data *)platform;
2989
2990 if (my_data->csd != NULL) {
2991 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2992 if (ret < 0) {
2993 ALOGE("%s: csd_client_stop_record failed, error %d",
2994 __func__, ret);
2995 }
2996 }
2997
2998 return ret;
2999}
3000
3001int platform_start_incall_music_usecase(void *platform)
3002{
3003 int ret = 0;
3004 struct platform_data *my_data = (struct platform_data *)platform;
3005
3006 if (my_data->csd != NULL) {
3007 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3008 if (ret < 0) {
3009 ALOGE("%s: csd_client_start_playback failed, error %d",
3010 __func__, ret);
3011 }
3012 }
3013
3014 return ret;
3015}
3016
3017int platform_stop_incall_music_usecase(void *platform)
3018{
3019 int ret = 0;
3020 struct platform_data *my_data = (struct platform_data *)platform;
3021
3022 if (my_data->csd != NULL) {
3023 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3024 if (ret < 0) {
3025 ALOGE("%s: csd_client_stop_playback failed, error %d",
3026 __func__, ret);
3027 }
3028 }
3029
3030 return ret;
3031}
3032
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003033int platform_set_parameters(void *platform, struct str_parms *parms)
3034{
3035 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09003036 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003037 char *kv_pairs = str_parms_to_str(parms);
3038 int ret = 0, err;
3039
3040 if (kv_pairs == NULL) {
3041 ret = -EINVAL;
3042 ALOGE("%s: key-value pair is NULL",__func__);
3043 goto done;
3044 }
3045
3046 ALOGV("%s: enter: %s", __func__, kv_pairs);
3047
3048 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
3049 value, sizeof(value));
3050 if (err >= 0) {
3051 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3052 my_data->snd_card_name = strdup(value);
3053 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3054 }
3055
keunhui.park2f7306a2015-07-16 16:48:06 +09003056 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
3057 value, sizeof(value));
3058 if (err >= 0) {
3059 struct operator_info *info;
3060 char *str = value;
3061 char *name;
3062
3063 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3064 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3065 name = strtok(str, ";");
3066 info->name = strdup(name);
3067 info->mccmnc = strdup(str + strlen(name) + 1);
3068
3069 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003070 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003071 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003072
3073 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07003074 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07003075 value, sizeof(value));
3076 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003077 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003078 my_data->max_mic_count = atoi(value);
3079 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003080 }
3081
vivek mehta90933872017-06-15 18:04:39 -07003082 // to-do: disable setting sidetone gain, will revist this later
3083 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003084done:
3085 ALOGV("%s: exit with code(%d)", __func__, ret);
3086 if (kv_pairs != NULL)
3087 free(kv_pairs);
3088
3089 return ret;
3090}
3091
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003092/* Delay in Us */
3093int64_t platform_render_latency(audio_usecase_t usecase)
3094{
3095 switch (usecase) {
3096 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3097 return DEEP_BUFFER_PLATFORM_DELAY;
3098 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3099 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003100 case USECASE_AUDIO_PLAYBACK_ULL:
3101 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003102 case USECASE_AUDIO_PLAYBACK_MMAP:
3103 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003104 default:
3105 return 0;
3106 }
3107}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003108
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003109int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3110 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003111{
3112 int ret = 0;
3113
3114 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3115 ALOGE("%s: Invalid snd_device = %d",
3116 __func__, device);
3117 ret = -EINVAL;
3118 goto done;
3119 }
3120
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003121 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3122 platform_get_snd_device_name(device),
3123 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3124 if (backend_tag_table[device]) {
3125 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003126 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003127 backend_tag_table[device] = strdup(backend_tag);
3128
3129 if (hw_interface != NULL) {
3130 if (hw_interface_table[device])
3131 free(hw_interface_table[device]);
3132 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3133 hw_interface_table[device] = strdup(hw_interface);
3134 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003135done:
3136 return ret;
3137}
3138
3139int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3140{
3141 int ret = 0;
3142 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3143 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3144 ret = -EINVAL;
3145 goto done;
3146 }
3147
3148 if ((type != 0) && (type != 1)) {
3149 ALOGE("%s: invalid usecase type", __func__);
3150 ret = -EINVAL;
3151 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003152 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3153 use_case_table[usecase],
3154 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003155 pcm_device_table[usecase][type] = pcm_id;
3156done:
3157 return ret;
3158}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003159
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003160#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3161int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3162 // backup_gain: gain to try to set in case of an error during ramp
3163 int start_gain, end_gain, step, backup_gain, i;
3164 bool error = false;
3165 const struct mixer_ctl *ctl;
3166 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3167 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3168 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3169 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3170 if (!ctl_left || !ctl_right) {
3171 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3172 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3173 return -EINVAL;
3174 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3175 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3176 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3177 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3178 return -EINVAL;
3179 }
3180 if (ramp_up) {
3181 start_gain = 0;
3182 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3183 step = +1;
3184 backup_gain = end_gain;
3185 } else {
3186 // using same gain on left and right
3187 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3188 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3189 end_gain = 0;
3190 step = -1;
3191 backup_gain = start_gain;
3192 }
3193 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3194 //ALOGV("setting speaker gain to %d", i);
3195 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3196 ALOGE("%s: error setting %s to %d during gain ramp",
3197 __func__, mixer_ctl_name_gain_left, i);
3198 error = true;
3199 break;
3200 }
3201 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3202 ALOGE("%s: error setting %s to %d during gain ramp",
3203 __func__, mixer_ctl_name_gain_right, i);
3204 error = true;
3205 break;
3206 }
3207 usleep(1000);
3208 }
3209 if (error) {
3210 // an error occured during the ramp, let's still try to go back to a safe volume
3211 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3212 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3213 }
3214 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3215 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3216 }
3217 }
3218 return start_gain;
3219}
3220
vivek mehtae59cfb22017-06-16 15:57:11 -07003221int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3222{
3223 const char *mixer_ctl_name = "Swap channel";
3224 struct mixer_ctl *ctl;
3225 const char *mixer_path;
3226 struct platform_data *my_data = (struct platform_data *)adev->platform;
3227
3228 // forced to set to swap, but device not rotated ... ignore set
3229 if (swap_channels && !my_data->speaker_lr_swap)
3230 return 0;
3231
3232 ALOGV("%s:", __func__);
3233
3234 if (swap_channels) {
3235 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3236 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3237 } else {
3238 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3239 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3240 }
3241
3242 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3243 if (!ctl) {
3244 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3245 return -EINVAL;
3246 }
3247
3248 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3249 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3250 return -EINVAL;
3251 }
3252
3253 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3254 swap_channels?"R --> L":"L --> R");
3255
3256 return 0;
3257}
3258
3259int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003260{
3261 // only update if there is active pcm playback on speaker
3262 struct audio_usecase *usecase;
3263 struct listnode *node;
3264 struct platform_data *my_data = (struct platform_data *)adev->platform;
3265
vivek mehtae59cfb22017-06-16 15:57:11 -07003266 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003267
vivek mehtae59cfb22017-06-16 15:57:11 -07003268 return platform_set_swap_channels(adev, swap_channels);
3269}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003270
vivek mehtae59cfb22017-06-16 15:57:11 -07003271int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3272{
3273 // only update if there is active pcm playback on speaker
3274 struct audio_usecase *usecase;
3275 struct listnode *node;
3276 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003277
vivek mehtae59cfb22017-06-16 15:57:11 -07003278 // do not swap channels in audio modes with concurrent capture and playback
3279 // as this may break the echo reference
3280 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3281 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3282 return 0;
3283 }
3284
3285 list_for_each(node, &adev->usecase_list) {
3286 usecase = node_to_item(node, struct audio_usecase, list);
3287 if (usecase->type == PCM_PLAYBACK &&
3288 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3289 /*
3290 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3291 * to perform device switch to disable the current backend to
3292 * enable it with new acdb data.
3293 */
3294 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3295 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3296 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3297 select_devices(adev, usecase->id);
3298 if (initial_skpr_gain != -EINVAL)
3299 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3300
3301 } else {
3302 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003303 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003304 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003305 }
3306 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003307
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003308 return 0;
3309}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003310
3311static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3312static int num_gain_tbl_entry = 0;
3313
3314bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3315
3316 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3317 if (num_gain_tbl_entry == -1) {
3318 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3319 __func__);
3320 return false;
3321 }
3322
3323 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3324 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3325 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3326 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3327 return false;
3328 }
3329
3330 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3331 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3332 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3333 return false;
3334 }
3335
3336 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3337 ++num_gain_tbl_entry;
3338
3339 return true;
3340}
3341
3342int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3343 int table_size) {
3344 int itt = 0;
3345 ALOGV("platform_get_gain_level_mapping called ");
3346
3347 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3348 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3349 return 0;
3350 }
3351
3352 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3353 mapping_tbl[itt] = tbl_mapping[itt];
3354 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3355 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3356 }
3357
3358 return num_gain_tbl_entry;
3359}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003360
3361int platform_snd_card_update(void *platform, card_status_t status)
3362{
3363 struct platform_data *my_data = (struct platform_data *)platform;
3364 struct audio_device *adev = my_data->adev;
3365
3366 if (status == CARD_STATUS_ONLINE) {
3367 if (my_data->acdb_send_custom_top)
3368 my_data->acdb_send_custom_top();
3369 }
3370 return 0;
3371}
David Linee3fe402017-03-13 10:00:42 -07003372
3373/*
3374 * configures afe with bit width and Sample Rate
3375 */
3376static int platform_set_backend_cfg(const struct audio_device* adev,
3377 snd_device_t snd_device,
3378 const struct audio_backend_cfg *backend_cfg)
3379{
3380
3381 int ret = 0;
3382 const int backend_idx = platform_get_backend_index(snd_device);
3383 struct platform_data *my_data = (struct platform_data *)adev->platform;
3384 const unsigned int bit_width = backend_cfg->bit_width;
3385 const unsigned int sample_rate = backend_cfg->sample_rate;
3386 const unsigned int channels = backend_cfg->channels;
3387 const audio_format_t format = backend_cfg->format;
3388 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3389
3390
3391 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3392 ", backend_idx %d device (%s)", __func__, bit_width,
3393 sample_rate, channels, backend_idx,
3394 platform_get_snd_device_name(snd_device));
3395
3396 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3397 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3398
3399 struct mixer_ctl *ctl = NULL;
3400 ctl = mixer_get_ctl_by_name(adev->mixer,
3401 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3402 if (!ctl) {
3403 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3404 __func__,
3405 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3406 return -EINVAL;
3407 }
3408
3409 if (bit_width == 24) {
3410 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3411 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3412 else
3413 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3414 } else if (bit_width == 32) {
3415 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3416 } else {
3417 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3418 }
3419 if ( ret < 0) {
3420 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3421 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3422 } else {
3423 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3424 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3425 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3426 }
3427 /* set the ret as 0 and not pass back to upper layer */
3428 ret = 0;
3429 }
3430
3431 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3432 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3433 char *rate_str = NULL;
3434 struct mixer_ctl *ctl = NULL;
3435
3436 switch (sample_rate) {
3437 case 32000:
3438 if (passthrough_enabled) {
3439 rate_str = "KHZ_32";
3440 break;
3441 }
3442 case 8000:
3443 case 11025:
3444 case 16000:
3445 case 22050:
3446 case 48000:
3447 rate_str = "KHZ_48";
3448 break;
3449 case 44100:
3450 rate_str = "KHZ_44P1";
3451 break;
3452 case 64000:
3453 case 96000:
3454 rate_str = "KHZ_96";
3455 break;
3456 case 88200:
3457 rate_str = "KHZ_88P2";
3458 break;
3459 case 176400:
3460 rate_str = "KHZ_176P4";
3461 break;
3462 case 192000:
3463 rate_str = "KHZ_192";
3464 break;
3465 case 352800:
3466 rate_str = "KHZ_352P8";
3467 break;
3468 case 384000:
3469 rate_str = "KHZ_384";
3470 break;
3471 case 144000:
3472 if (passthrough_enabled) {
3473 rate_str = "KHZ_144";
3474 break;
3475 }
3476 default:
3477 rate_str = "KHZ_48";
3478 break;
3479 }
3480
3481 ctl = mixer_get_ctl_by_name(adev->mixer,
3482 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3483 if(!ctl) {
3484 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3485 __func__,
3486 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3487 return -EINVAL;
3488 }
3489
3490 ALOGD("%s:becf: afe: %s set to %s", __func__,
3491 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3492 mixer_ctl_set_enum_by_string(ctl, rate_str);
3493 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3494 }
3495 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3496 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3497 struct mixer_ctl *ctl = NULL;
3498 char *channel_cnt_str = NULL;
3499
3500 switch (channels) {
3501 case 8:
3502 channel_cnt_str = "Eight"; break;
3503 case 7:
3504 channel_cnt_str = "Seven"; break;
3505 case 6:
3506 channel_cnt_str = "Six"; break;
3507 case 5:
3508 channel_cnt_str = "Five"; break;
3509 case 4:
3510 channel_cnt_str = "Four"; break;
3511 case 3:
3512 channel_cnt_str = "Three"; break;
3513 case 1:
3514 channel_cnt_str = "One"; break;
3515 case 2:
3516 default:
3517 channel_cnt_str = "Two"; break;
3518 }
3519
3520 ctl = mixer_get_ctl_by_name(adev->mixer,
3521 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3522 if (!ctl) {
3523 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3524 __func__,
3525 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3526 return -EINVAL;
3527 }
3528 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3529 my_data->current_backend_cfg[backend_idx].channels = channels;
3530
3531 // skip EDID configuration for HDMI backend
3532
3533 ALOGD("%s:becf: afe: %s set to %s", __func__,
3534 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3535 channel_cnt_str);
3536 }
3537
3538 // skip set ext_display format mixer control
3539 return ret;
3540}
3541
3542static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3543{
3544 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3545 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3546 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3547 }
3548
3549 return backend_bit_width_table[snd_device];
3550}
3551
3552/*
3553 * return backend_idx on which voice call is active
3554 */
3555static int platform_get_voice_call_backend(struct audio_device* adev)
3556{
3557 struct audio_usecase *uc = NULL;
3558 struct listnode *node;
3559 snd_device_t out_snd_device = SND_DEVICE_NONE;
3560
3561 int backend_idx = -1;
3562
3563 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3564 list_for_each(node, &adev->usecase_list) {
3565 uc = node_to_item(node, struct audio_usecase, list);
3566 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3567 out_snd_device = platform_get_output_snd_device(adev->platform,
3568 uc->stream.out->devices);
3569 backend_idx = platform_get_backend_index(out_snd_device);
3570 break;
3571 }
3572 }
3573 }
3574 return backend_idx;
3575}
3576
3577/*
3578 * goes through all the current usecases and picks the highest
3579 * bitwidth & samplerate
3580 */
3581static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3582 int backend_idx,
3583 struct audio_backend_cfg *backend_cfg)
3584{
3585 bool backend_change = false;
3586 unsigned int bit_width;
3587 unsigned int sample_rate;
3588 unsigned int channels;
3589 struct platform_data *my_data = (struct platform_data *)adev->platform;
3590
3591 bit_width = backend_cfg->bit_width;
3592 sample_rate = backend_cfg->sample_rate;
3593 channels = backend_cfg->channels;
3594
3595 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3596 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3597 sample_rate, channels);
3598
3599 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3600 // default backend
3601 // force routing is not required here, caller will do it anyway
3602 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3603 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3604 "for unprocessed/camera source", __func__);
3605 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3606 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3607 }
3608
3609 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3610 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3611 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3612 __func__, bit_width, sample_rate, channels);
3613 }
3614
3615 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3616 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3617
3618 // Force routing if the expected bitwdith or samplerate
3619 // is not same as current backend comfiguration
3620 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3621 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3622 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3623 backend_cfg->bit_width = bit_width;
3624 backend_cfg->sample_rate= sample_rate;
3625 backend_cfg->channels = channels;
3626 backend_change = true;
3627 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3628 "new sample rate: %d new channel: %d",
3629 __func__, backend_cfg->bit_width,
3630 backend_cfg->sample_rate, backend_cfg->channels);
3631 }
3632
3633 return backend_change;
3634}
3635
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003636static void pick_playback_cfg_for_uc(struct audio_device *adev,
3637 struct audio_usecase *usecase,
3638 snd_device_t snd_device,
3639 unsigned int *bit_width,
3640 unsigned int *sample_rate,
3641 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003642{
3643 int i =0;
3644 struct listnode *node;
3645 list_for_each(node, &adev->usecase_list) {
3646 struct audio_usecase *uc;
3647 uc = node_to_item(node, struct audio_usecase, list);
3648 struct stream_out *out = (struct stream_out*) uc->stream.out;
3649 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3650 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3651 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3652 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3653 uc->id, out->sample_rate,
3654 pcm_format_to_bits(out->config.format), out_channels,
3655 platform_get_snd_device_name(uc->out_snd_device));
3656
3657 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3658 if (*bit_width < pcm_format_to_bits(out->config.format))
3659 *bit_width = pcm_format_to_bits(out->config.format);
3660 if (*sample_rate < out->sample_rate)
3661 *sample_rate = out->sample_rate;
3662 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3663 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3664 if (*channels < out_channels)
3665 *channels = out_channels;
3666 }
3667 }
3668 }
3669 return;
3670}
3671
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003672static void headset_is_config_supported(unsigned int *bit_width,
3673 unsigned int *sample_rate,
3674 unsigned int *channels) {
3675 switch (*bit_width) {
3676 case 16:
3677 case 24:
3678 break;
3679 default:
3680 *bit_width = 16;
3681 break;
3682 }
3683
3684 if (*sample_rate > 192000) {
3685 *sample_rate = 192000;
3686 }
3687
3688 if (*channels > 2) {
3689 *channels = 2;
3690 }
3691}
3692
David Linee3fe402017-03-13 10:00:42 -07003693static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3694 struct audio_usecase* usecase,
3695 snd_device_t snd_device,
3696 struct audio_backend_cfg *backend_cfg)
3697{
3698 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003699 unsigned int bit_width;
3700 unsigned int sample_rate;
3701 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003702 int backend_idx = DEFAULT_CODEC_BACKEND;
3703 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003704
3705 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3706 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3707 backend_change = false;
3708 return backend_change;
3709 }
3710
3711 backend_idx = platform_get_backend_index(snd_device);
3712 bit_width = backend_cfg->bit_width;
3713 sample_rate = backend_cfg->sample_rate;
3714 channels = backend_cfg->channels;
3715
3716 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3717 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3718 sample_rate, channels, backend_idx, usecase->id,
3719 platform_get_snd_device_name(snd_device));
3720
3721 if (backend_idx == platform_get_voice_call_backend(adev)) {
3722 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3723 __func__);
3724 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3725 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3726 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3727 } else {
3728 /*
3729 * The backend should be configured at highest bit width and/or
3730 * sample rate amongst all playback usecases.
3731 * If the selected sample rate and/or bit width differ with
3732 * current backend sample rate and/or bit width, then, we set the
3733 * backend re-configuration flag.
3734 *
3735 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3736 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003737 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3738 &bit_width,
3739 &sample_rate,
3740 &channels);
David Linee3fe402017-03-13 10:00:42 -07003741 }
3742
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003743 switch (backend_idx) {
3744 case USB_AUDIO_RX_BACKEND:
3745 audio_extn_usb_is_config_supported(&bit_width,
3746 &sample_rate, &channels, true);
3747 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3748 __func__, bit_width, sample_rate, channels);
3749 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003750 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003751 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3752 break;
3753 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003754 default:
3755 bit_width = platform_get_snd_device_bit_width(snd_device);
3756 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3757 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3758 break;
David Linee3fe402017-03-13 10:00:42 -07003759 }
3760
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003761 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3762 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003763 __func__, backend_idx , bit_width, sample_rate);
3764
3765 // Force routing if the expected bitwdith or samplerate
3766 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003767 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3768 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3769 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003770 backend_cfg->bit_width = bit_width;
3771 backend_cfg->sample_rate = sample_rate;
3772 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003773 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003774 backend_change = true;
3775 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3776 "new sample rate: %d new channels: %d",
3777 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3778 }
3779
3780 return backend_change;
3781}
3782
3783bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3784 struct audio_usecase *usecase, snd_device_t snd_device)
3785{
3786 int backend_idx = DEFAULT_CODEC_BACKEND;
3787 int new_snd_devices[SND_DEVICE_OUT_END];
3788 int i, num_devices = 1;
3789 bool ret = false;
3790 struct platform_data *my_data = (struct platform_data *)adev->platform;
3791 struct audio_backend_cfg backend_cfg;
3792
3793 backend_idx = platform_get_backend_index(snd_device);
3794
3795 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3796 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3797 backend_cfg.format = usecase->stream.out->format;
3798 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3799 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3800 backend_cfg.passthrough_enabled = false;
3801
3802 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3803 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3804 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3805 platform_get_snd_device_name(snd_device));
3806
3807 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3808 new_snd_devices[0] = snd_device;
3809
3810 for (i = 0; i < num_devices; i++) {
3811 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3812 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3813 &backend_cfg))) {
3814 platform_set_backend_cfg(adev, new_snd_devices[i],
3815 &backend_cfg);
3816 ret = true;
3817 }
3818 }
3819 return ret;
3820}
3821
3822bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3823 struct audio_usecase *usecase, snd_device_t snd_device)
3824{
3825 int backend_idx = platform_get_backend_index(snd_device);
3826 int ret = 0;
3827 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003828 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003829
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003830 if (usecase->type == PCM_CAPTURE) {
3831 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003832 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3833 } else {
3834 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3835 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3836 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3837 backend_cfg.channels = 1;
3838 }
3839
3840 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3841 ", backend_idx %d usecase = %d device (%s)", __func__,
3842 backend_cfg.bit_width,
3843 backend_cfg.sample_rate,
3844 backend_cfg.channels,
3845 backend_idx, usecase->id,
3846 platform_get_snd_device_name(snd_device));
3847
3848 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3849 ret = platform_set_backend_cfg(adev, snd_device,
3850 &backend_cfg);
3851 if(!ret)
3852 return true;
3853 }
3854
3855 return false;
3856}
3857
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003858static int max_be_dai_names = 0;
3859static const struct be_dai_name_struct *be_dai_name_table;
3860
3861/*
3862 * Retrieves the be_dai_name_table from kernel to enable a mapping
3863 * between sound device hw interfaces and backend IDs. This allows HAL to
3864 * specify the backend a specific calibration is needed for.
3865 */
3866static int init_be_dai_name_table(struct audio_device *adev)
3867{
3868 const char *mixer_ctl_name = "Backend DAI Name Table";
3869 struct mixer_ctl *ctl;
3870 int i, j, ret, size;
3871 bool valid_hw_interface;
3872
3873 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3874 if (!ctl) {
3875 ALOGE("%s: Could not get ctl for mixer name %s\n",
3876 __func__, mixer_ctl_name);
3877 ret = -EINVAL;
3878 goto done;
3879 }
3880
3881 mixer_ctl_update(ctl);
3882
3883 size = mixer_ctl_get_num_values(ctl);
3884 if (size <= 0){
3885 ALOGE("%s: Failed to get %s size %d\n",
3886 __func__, mixer_ctl_name, size);
3887 ret = -EFAULT;
3888 goto done;
3889 }
3890
vivek mehtaa68fea62017-06-08 19:04:02 -07003891 be_dai_name_table =
3892 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003893 if (be_dai_name_table == NULL) {
3894 ALOGE("%s: Failed to allocate memory for %s\n",
3895 __func__, mixer_ctl_name);
3896 ret = -ENOMEM;
3897 goto freeMem;
3898 }
3899
3900 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
3901 if (ret) {
3902 ALOGE("%s: Failed to get %s, ret %d\n",
3903 __func__, mixer_ctl_name, ret);
3904 ret = -EFAULT;
3905 goto freeMem;
3906 }
3907
3908 if (be_dai_name_table != NULL) {
3909 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
3910 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
3911 __func__, mixer_ctl_name, max_be_dai_names);
3912 ret = 0;
3913 } else {
3914 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
3915 ret = -EFAULT;
3916 goto freeMem;
3917 }
3918
3919 /*
3920 * Validate all sound devices have a valid backend set to catch
3921 * errors for uncommon sound devices
3922 */
3923 for (i = 0; i < SND_DEVICE_MAX; i++) {
3924 valid_hw_interface = false;
3925
3926 if (hw_interface_table[i] == NULL) {
3927 ALOGW("%s: sound device %s has no hw interface set\n",
3928 __func__, platform_get_snd_device_name(i));
3929 continue;
3930 }
3931
3932 for (j = 0; j < max_be_dai_names; j++) {
3933 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
3934 == 0) {
3935 valid_hw_interface = true;
3936 break;
3937 }
3938 }
3939 if (!valid_hw_interface)
3940 ALOGD("%s: sound device %s does not have a valid hw interface set "
3941 "(disregard for combo devices) %s\n",
3942 __func__, platform_get_snd_device_name(i),
3943 hw_interface_table[i]);
3944 }
3945
3946 goto done;
3947
3948freeMem:
3949 if (be_dai_name_table) {
3950 free((void *)be_dai_name_table);
3951 be_dai_name_table = NULL;
3952 }
3953
3954done:
3955 return ret;
3956}
3957
3958int platform_get_snd_device_backend_index(snd_device_t device)
3959{
3960 int i, be_dai_id;
3961 const char * hw_interface_name = NULL;
3962
3963 ALOGV("%s: enter with device %d\n", __func__, device);
3964
vivek mehtaa68fea62017-06-08 19:04:02 -07003965 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003966 ALOGE("%s: Invalid snd_device = %d",
3967 __func__, device);
3968 be_dai_id = -EINVAL;
3969 goto done;
3970 }
3971
3972 /* Get string value of necessary backend for device */
3973 hw_interface_name = hw_interface_table[device];
3974 if (hw_interface_name == NULL) {
3975 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
3976 be_dai_id = -EINVAL;
3977 goto done;
3978 }
3979
3980 /* Check if be dai name table was retrieved successfully */
3981 if (be_dai_name_table == NULL) {
3982 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
3983 be_dai_id = -EFAULT;
3984 goto done;
3985 }
3986
3987 /* Get backend ID for device specified */
3988 for (i = 0; i < max_be_dai_names; i++) {
3989 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
3990 be_dai_id = be_dai_name_table[i].be_id;
3991 goto done;
3992 }
3993 }
3994 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
3995 be_dai_id = -EINVAL;
3996 goto done;
3997
3998done:
3999 return be_dai_id;
4000}
4001
4002void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4003 unsigned int stream_sr, int* sample_rate)
4004{
4005 struct platform_data* my_data = (struct platform_data *)platform;
4006 int backend_idx = platform_get_backend_index(snd_device);
4007 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4008 /*
4009 *Check if device SR is multiple of 8K or 11.025 Khz
4010 *check if the stream SR is multiple of same base, if yes
4011 *then have copp SR equal to stream SR, this ensures that
4012 *post processing happens at stream SR, else have
4013 *copp SR equal to device SR.
4014 */
4015 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4016 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4017 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4018 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4019 *sample_rate = device_sr;
4020 } else
4021 *sample_rate = stream_sr;
4022
4023 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4024 , *sample_rate);
4025
4026}
4027
4028// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004029void platform_add_app_type(const char *uc_type,
4030 const char *mode,
4031 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004032 int app_type, int max_rate) {
4033 struct app_type_entry *ap =
4034 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4035
4036 if (!ap) {
4037 ALOGE("%s failed to allocate mem for app type", __func__);
4038 return;
4039 }
4040
4041 ap->uc_type = -1;
4042 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4043 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4044 ap->uc_type = usecase_type_index[i].index;
4045 break;
4046 }
4047 }
4048
4049 if (ap->uc_type == -1) {
4050 free(ap);
4051 return;
4052 }
4053
vivek mehtaa68fea62017-06-08 19:04:02 -07004054 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4055 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004056 ap->bit_width = bw;
4057 ap->app_type = app_type;
4058 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004059 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004060 list_add_tail(&app_type_entry_list, &ap->node);
4061}
4062
4063
4064int platform_get_default_app_type_v2(void *platform __unused,
4065 usecase_type_t type,
4066 int *app_type )
4067{
4068 if (type == PCM_PLAYBACK)
4069 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4070 else
4071 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4072 return 0;
4073}
4074
vivek mehtaa68fea62017-06-08 19:04:02 -07004075int platform_get_app_type_v2(void *platform,
4076 usecase_type_t uc_type,
4077 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004078 int bw, int sr __unused,
4079 int *app_type)
4080{
4081 struct listnode *node;
4082 struct app_type_entry *entry;
4083 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004084
4085 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4086 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004087 list_for_each(node, &app_type_entry_list) {
4088 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004089 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4090 __func__, entry->uc_type, entry->mode, entry->bit_width,
4091 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004092 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004093 entry->uc_type == uc_type &&
4094 sr <= entry->max_rate &&
4095 entry->mode && !strcmp(mode, entry->mode)) {
4096 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004097 *app_type = entry->app_type;
4098 break;
4099 }
4100 }
4101
4102 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004103 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004104 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4105 }
4106 return 0;
4107}
vivek mehta90933872017-06-15 18:04:39 -07004108
4109int platform_set_sidetone(struct audio_device *adev,
4110 snd_device_t out_snd_device,
4111 bool enable, char *str)
4112{
4113 int ret;
4114 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4115 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4116 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4117 if (ret)
4118 ALOGI("%s: usb device %d does not support device sidetone\n",
4119 __func__, out_snd_device);
4120 } else {
4121 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4122 __func__, out_snd_device, str);
4123 if (enable)
4124 audio_route_apply_and_update_path(adev->audio_route, str);
4125 else
4126 audio_route_reset_and_update_path(adev->audio_route, str);
4127 }
4128 return 0;
4129}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004130
4131int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4132 int *fd __unused, uint32_t *size __unused)
4133{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004134#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004135 struct platform_data *my_data = (struct platform_data *)platform;
4136 struct audio_device *adev = my_data->adev;
4137 int hw_fd = -1;
4138 char dev_name[128];
4139 struct snd_pcm_mmap_fd mmap_fd;
4140 memset(&mmap_fd, 0, sizeof(mmap_fd));
4141 mmap_fd.dir = dir;
4142 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4143 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4144 hw_fd = open(dev_name, O_RDONLY);
4145 if (hw_fd < 0) {
4146 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4147 return -1;
4148 }
4149 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4150 ALOGE("fe hw dep node ioctl failed");
4151 close(hw_fd);
4152 return -1;
4153 }
4154 *fd = mmap_fd.fd;
4155 *size = mmap_fd.size;
4156 close(hw_fd); // mmap_fd should still be valid
4157 return 0;
4158#else
4159 return -1;
4160#endif
4161}