blob: 7bbf168d560989f49142a6e75e314849b43527cd [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>
22#include <cutils/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070023#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070024#include <cutils/properties.h>
25#include <audio_hw.h>
26#include <platform_api.h>
27#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070028#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070029#include <linux/msm_audio.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070030
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090031#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
32#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080033#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
34#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
35
Eric Laurentb23d5282013-05-14 15:27:20 -070036#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070037#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090038#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070039
Eric Laurentf9583c32016-03-28 13:50:50 -070040#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070041
42/*
Eric Laurentb23d5282013-05-14 15:27:20 -070043 * This file will have a maximum of 38 bytes:
44 *
45 * 4 bytes: number of audio blocks
46 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
47 * Maximum 10 * 3 bytes: SAD blocks
48 */
49#define MAX_SAD_BLOCKS 10
50#define SAD_BLOCK_SIZE 3
51
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090052#define MAX_CVD_VERSION_STRING_SIZE 100
53
Eric Laurentb23d5282013-05-14 15:27:20 -070054/* EDID format ID for LPCM audio */
55#define EDID_FORMAT_LPCM 1
56
sangwoo1b9f4b32013-06-21 18:22:55 -070057/* Retry for delay in FW loading*/
58#define RETRY_NUMBER 10
59#define RETRY_US 500000
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070060#define MAX_SND_CARD 8
sangwoo53b2cf02013-07-25 19:18:44 -070061
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070062#define MAX_SND_CARD_NAME_LEN 31
63
vivek mehta1a9b7c02015-06-25 11:49:38 -070064#define DEFAULT_APP_TYPE_RX_PATH 0x11130
65
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090066#define TOSTRING_(x) #x
67#define TOSTRING(x) TOSTRING_(x)
68
Eric Laurentb23d5282013-05-14 15:27:20 -070069struct audio_block_header
70{
71 int reserved;
72 int length;
73};
74
vivek mehta1a9b7c02015-06-25 11:49:38 -070075enum {
76 CAL_MODE_SEND = 0x1,
77 CAL_MODE_PERSIST = 0x2,
78 CAL_MODE_RTAC = 0x4
79};
80
keunhui.park2f7306a2015-07-16 16:48:06 +090081#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
82
83struct operator_info {
84 struct listnode list;
85 char *name;
86 char *mccmnc;
87};
88
89struct operator_specific_device {
90 struct listnode list;
91 char *operator;
92 char *mixer_path;
93 int acdb_id;
94};
95
96static struct listnode operator_info_list;
97static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
98
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070099/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -0700100typedef void (*acdb_deallocate_t)();
vivek mehtac698f132016-02-25 18:50:35 -0800101typedef int (*acdb_init_v2_cvd_t)(char *, char *, int);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900102typedef int (*acdb_init_v2_t)(char *);
Eric Laurentb23d5282013-05-14 15:27:20 -0700103typedef int (*acdb_init_t)();
104typedef void (*acdb_send_audio_cal_t)(int, int);
105typedef void (*acdb_send_voice_cal_t)(int, int);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700106typedef int (*acdb_reload_vocvoltable_t)(int);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700107typedef int (*acdb_send_gain_dep_cal_t)(int, int, int, int, int);
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700108typedef int (*acdb_send_custom_top_t) (void);
Eric Laurentb23d5282013-05-14 15:27:20 -0700109
110/* Audio calibration related functions */
111struct platform_data {
112 struct audio_device *adev;
113 bool fluence_in_spkr_mode;
114 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700115 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700116 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700117 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
118 int fluence_type;
119 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700120 bool speaker_lr_swap;
121
Eric Laurentb23d5282013-05-14 15:27:20 -0700122 void *acdb_handle;
Thierry Strudel92232b42017-01-26 10:51:48 -0800123#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700124 acdb_init_v2_cvd_t acdb_init;
125#elif defined (PLATFORM_MSM8084)
126 acdb_init_v2_t acdb_init;
127#else
128 acdb_init_t acdb_init;
129#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700130 acdb_deallocate_t acdb_deallocate;
131 acdb_send_audio_cal_t acdb_send_audio_cal;
132 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700133 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700134 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700135 acdb_send_custom_top_t acdb_send_custom_top;
136 bool acdb_initialized;
137
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700138 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800139 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700140
David Linee3fe402017-03-13 10:00:42 -0700141 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700142 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900143 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700144 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800145
146 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700147};
148
Haynes Mathew George98c95622014-06-20 19:14:25 -0700149static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700150 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
151 DEEP_BUFFER_PCM_DEVICE},
152 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
153 LOWLATENCY_PCM_DEVICE},
154 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
155 MULTIMEDIA2_PCM_DEVICE},
156 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
157 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700158 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
159 MULTIMEDIA2_PCM_DEVICE},
160 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
161 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800162 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
163 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700164
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700165 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
166 AUDIO_RECORD_PCM_DEVICE},
167 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
168 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700169
Eric Laurent0e46adf2016-12-16 12:49:24 -0800170 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
171 MMAP_RECORD_PCM_DEVICE},
172
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700173 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
174 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700175 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
176 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
177 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
178 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800179 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
180 VOICEMMODE1_CALL_PCM_DEVICE},
181 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
182 VOICEMMODE2_CALL_PCM_DEVICE},
183
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700184 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
185 AUDIO_RECORD_PCM_DEVICE},
186 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
187 AUDIO_RECORD_PCM_DEVICE},
188 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
189 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800190 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700191
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700192 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
193 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
194
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700195 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
196 AFE_PROXY_RECORD_PCM_DEVICE},
197 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
198 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800199 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700200
Eric Laurentb23d5282013-05-14 15:27:20 -0700201};
202
203/* Array to store sound devices */
204static const char * const device_table[SND_DEVICE_MAX] = {
205 [SND_DEVICE_NONE] = "none",
206 /* Playback sound devices */
207 [SND_DEVICE_OUT_HANDSET] = "handset",
208 [SND_DEVICE_OUT_SPEAKER] = "speaker",
209 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700210 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700211 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500212 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700213 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700214 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500215 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700216 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700217 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500218 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700219 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
220 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500221 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700222 [SND_DEVICE_OUT_HDMI] = "hdmi",
223 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
224 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700225 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700226 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
227 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
228 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
229 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800230 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
231 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700232 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700233 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
234 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
235 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700236 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
237 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700238 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800239 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
240 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700241
242 /* Capture sound devices */
243 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700244 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700245 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
246 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
247 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
248 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
249 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
250 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
251 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
252
253 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
254 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
255 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
256 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
257 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
258 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
259 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
260 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
261 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
262
263 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500264 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700265
Eric Laurentb23d5282013-05-14 15:27:20 -0700266 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
267 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700268 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700269 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700270 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700271 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700272
273 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
274 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
275 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
276 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700277 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700278 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700279 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
280 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
281 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800282 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
283 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700284
Eric Laurentb23d5282013-05-14 15:27:20 -0700285 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700286 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700287 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700288 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700289 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
290 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700291 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700292 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700293
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700294 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700295 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
296 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
297 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
298 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800299
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700300 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700301
Prashant Malanic92c5962015-08-11 15:10:18 -0700302 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
303 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700304 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700305 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
306 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700307 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
308 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700309};
310
311/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700312static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700313 [SND_DEVICE_NONE] = -1,
314 [SND_DEVICE_OUT_HANDSET] = 7,
315 [SND_DEVICE_OUT_SPEAKER] = 15,
316 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700317 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700318 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500319 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700320 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700321 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500322 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700323 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700324 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
325 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500326 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700327 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500328 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700329 [SND_DEVICE_OUT_HDMI] = 18,
330 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
331 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700332 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700333 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700334 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
335 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
336 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800337 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
338 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700339 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700340 [SND_DEVICE_OUT_USB_HEADSET] = 45,
341 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
342 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700343 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
344 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700345 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700346
347 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700348 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
349 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
350 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
351 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
352 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
353 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
354 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
355 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
356
357 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
358 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
359 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
360 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
361 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
362 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
363 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
364 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
365 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
366
rago90fb9612015-12-02 11:37:53 -0800367 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500368 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700369
Eric Laurentb23d5282013-05-14 15:27:20 -0700370 [SND_DEVICE_IN_HDMI_MIC] = 4,
371 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700372 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700373 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700374 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700375 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700376
377 [SND_DEVICE_IN_VOICE_DMIC] = 41,
378 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
379 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700380 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700381 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800382 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700383 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
384 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
385 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800386 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
387 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700388
rago90fb9612015-12-02 11:37:53 -0800389 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700390 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700391 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700392 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700393 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
394 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800395 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
396
397 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
398 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700399 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
400 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
401 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700402
403 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700404 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700405 [SND_DEVICE_IN_THREE_MIC] = 46,
406 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700407 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700408 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
409 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700410 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
411 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700412};
413
David Linee3fe402017-03-13 10:00:42 -0700414// Platform specific backend bit width table
415static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
416
Haynes Mathew George98c95622014-06-20 19:14:25 -0700417struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700418 char name[100];
419 unsigned int index;
420};
421
422#define TO_NAME_INDEX(X) #X, X
423
Haynes Mathew George98c95622014-06-20 19:14:25 -0700424/* Used to get index from parsed string */
425static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
426 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700427 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
428 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
429 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700430 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700431 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500432 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700433 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700434 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500435 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700436 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700437 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
438 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700439 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700440 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500441 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700442 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
443 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
444 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
445 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700446 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500447 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700448 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
449 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
450 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800451 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
452 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800453 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
454 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700455 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
456 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
457 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700458 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
459 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800460
461 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700462 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700463 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700464 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
465 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
466 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
467 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
468 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
469 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
470 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
471
472 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700473 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700474 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
475 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
476 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
477 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
478 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
479 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
480 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
481
482 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700483 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700484
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700485 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
486 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700487 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700488 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700489 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700490 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700491
492 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
493 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
494 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700495 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700496 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
497 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700498 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
499 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
500 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800501 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
502 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
503
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700504
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700505 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700506 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700507 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700508 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700509 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
510 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700511 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700512 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700513
rago90fb9612015-12-02 11:37:53 -0800514 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
515 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700516 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
517 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
518 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800519
Prashant Malanic92c5962015-08-11 15:10:18 -0700520 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
521 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700522 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700523 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
524 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700525 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
526 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700527};
528
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700529static char * backend_tag_table[SND_DEVICE_MAX] = {0};
530static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700531
532static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
533 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
534 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
535 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
536 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700537 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
538 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800539 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700540 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
541 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800542 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700543 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
544 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
545 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
546 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
547 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800548 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
549 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700550 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
551 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
552 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
553 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800554 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
555 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
556 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
557 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
558 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700559};
560
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700561#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
562#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800563#define ULL_PLATFORM_DELAY (3*1000LL)
564#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700565
Eric Laurentb23d5282013-05-14 15:27:20 -0700566static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
567static bool is_tmus = false;
568
569static void check_operator()
570{
571 char value[PROPERTY_VALUE_MAX];
572 int mccmnc;
573 property_get("gsm.sim.operator.numeric",value,"0");
574 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700575 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700576 switch(mccmnc) {
577 /* TMUS MCC(310), MNC(490, 260, 026) */
578 case 310490:
579 case 310260:
580 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900581 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
582 case 310800:
583 case 310660:
584 case 310580:
585 case 310310:
586 case 310270:
587 case 310250:
588 case 310240:
589 case 310230:
590 case 310220:
591 case 310210:
592 case 310200:
593 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700594 is_tmus = true;
595 break;
596 }
597}
598
599bool is_operator_tmus()
600{
601 pthread_once(&check_op_once_ctl, check_operator);
602 return is_tmus;
603}
604
keunhui.park2f7306a2015-07-16 16:48:06 +0900605static char *get_current_operator()
606{
607 struct listnode *node;
608 struct operator_info *info_item;
609 char mccmnc[PROPERTY_VALUE_MAX];
610 char *ret = NULL;
611
Tom Cherry7fea2042016-11-10 18:05:59 -0800612 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900613
614 list_for_each(node, &operator_info_list) {
615 info_item = node_to_item(node, struct operator_info, list);
616 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
617 ret = info_item->name;
618 }
619 }
620
621 return ret;
622}
623
624static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
625{
626 struct listnode *node;
627 struct operator_specific_device *ret = NULL;
628 struct operator_specific_device *device_item;
629 char *operator_name;
630
631 operator_name = get_current_operator();
632 if (operator_name == NULL)
633 return ret;
634
635 list_for_each(node, operator_specific_device_table[snd_device]) {
636 device_item = node_to_item(node, struct operator_specific_device, list);
637 if (strcmp(operator_name, device_item->operator) == 0) {
638 ret = device_item;
639 }
640 }
641
642 return ret;
643}
644
645
646static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
647{
648 struct operator_specific_device *device;
649 int ret = acdb_device_table[snd_device];
650
651 device = get_operator_specific_device(snd_device);
652 if (device != NULL)
653 ret = device->acdb_id;
654
655 return ret;
656}
657
658static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
659{
660 struct operator_specific_device *device;
661 const char *ret = device_table[snd_device];
662
663 device = get_operator_specific_device(snd_device);
664 if (device != NULL)
665 ret = device->mixer_path;
666
667 return ret;
668}
669
vivek mehta1a9b7c02015-06-25 11:49:38 -0700670bool platform_send_gain_dep_cal(void *platform, int level)
671{
672 bool ret_val = false;
673 struct platform_data *my_data = (struct platform_data *)platform;
674 struct audio_device *adev = my_data->adev;
675 int acdb_dev_id, app_type;
676 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
677 int mode = CAL_MODE_RTAC;
678 struct listnode *node;
679 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700680
681 if (my_data->acdb_send_gain_dep_cal == NULL) {
682 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
683 return ret_val;
684 }
685
686 if (!voice_is_in_call(adev)) {
687 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
688 __func__, level);
689 app_type = DEFAULT_APP_TYPE_RX_PATH;
690
691 // find the current active sound device
692 list_for_each(node, &adev->usecase_list) {
693 usecase = node_to_item(node, struct audio_usecase, list);
694
695 if (usecase != NULL &&
696 usecase->type == PCM_PLAYBACK &&
697 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
698
699 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700700 if (audio_extn_spkr_prot_is_enabled()) {
701 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
702 } else {
703 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
704 }
705
vivek mehta1a9b7c02015-06-25 11:49:38 -0700706 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
707 acdb_dev_type, mode, level)) {
708 // set ret_val true if at least one calibration is set successfully
709 ret_val = true;
710 } else {
711 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
712 }
713 } else {
714 ALOGW("%s: Usecase list is empty", __func__);
715 }
716 }
717 } else {
718 ALOGW("%s: Voice call in progress .. ignore setting new cal",
719 __func__);
720 }
721 return ret_val;
722}
723
Eric Laurentcefbbac2014-09-04 13:54:10 -0500724void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700725{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800726 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500727 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700728
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800729 if (strcmp(my_data->ec_ref_mixer_path, "")) {
730 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
731 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500732 }
733
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800734 if (enable) {
735 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
736 if (out_device != AUDIO_DEVICE_NONE) {
737 snd_device = platform_get_output_snd_device(adev->platform, out_device);
738 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
739 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500740
Joe Onorato188b6222016-03-01 11:02:27 -0800741 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800742 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
743 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700744}
745
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700746static struct csd_data *open_csd_client(bool i2s_ext_modem)
747{
748 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
749
750 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
751 if (csd->csd_client == NULL) {
752 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
753 goto error;
754 } else {
755 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
756
757 csd->deinit = (deinit_t)dlsym(csd->csd_client,
758 "csd_client_deinit");
759 if (csd->deinit == NULL) {
760 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
761 dlerror());
762 goto error;
763 }
764 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
765 "csd_client_disable_device");
766 if (csd->disable_device == NULL) {
767 ALOGE("%s: dlsym error %s for csd_client_disable_device",
768 __func__, dlerror());
769 goto error;
770 }
771 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
772 "csd_client_enable_device_config");
773 if (csd->enable_device_config == NULL) {
774 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
775 __func__, dlerror());
776 goto error;
777 }
778 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
779 "csd_client_enable_device");
780 if (csd->enable_device == NULL) {
781 ALOGE("%s: dlsym error %s for csd_client_enable_device",
782 __func__, dlerror());
783 goto error;
784 }
785 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
786 "csd_client_start_voice");
787 if (csd->start_voice == NULL) {
788 ALOGE("%s: dlsym error %s for csd_client_start_voice",
789 __func__, dlerror());
790 goto error;
791 }
792 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
793 "csd_client_stop_voice");
794 if (csd->stop_voice == NULL) {
795 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
796 __func__, dlerror());
797 goto error;
798 }
799 csd->volume = (volume_t)dlsym(csd->csd_client,
800 "csd_client_volume");
801 if (csd->volume == NULL) {
802 ALOGE("%s: dlsym error %s for csd_client_volume",
803 __func__, dlerror());
804 goto error;
805 }
806 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
807 "csd_client_mic_mute");
808 if (csd->mic_mute == NULL) {
809 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
810 __func__, dlerror());
811 goto error;
812 }
813 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
814 "csd_client_slow_talk");
815 if (csd->slow_talk == NULL) {
816 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
817 __func__, dlerror());
818 goto error;
819 }
820 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
821 "csd_client_start_playback");
822 if (csd->start_playback == NULL) {
823 ALOGE("%s: dlsym error %s for csd_client_start_playback",
824 __func__, dlerror());
825 goto error;
826 }
827 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
828 "csd_client_stop_playback");
829 if (csd->stop_playback == NULL) {
830 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
831 __func__, dlerror());
832 goto error;
833 }
834 csd->start_record = (start_record_t)dlsym(csd->csd_client,
835 "csd_client_start_record");
836 if (csd->start_record == NULL) {
837 ALOGE("%s: dlsym error %s for csd_client_start_record",
838 __func__, dlerror());
839 goto error;
840 }
841 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
842 "csd_client_stop_record");
843 if (csd->stop_record == NULL) {
844 ALOGE("%s: dlsym error %s for csd_client_stop_record",
845 __func__, dlerror());
846 goto error;
847 }
848
849 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
850 "csd_client_get_sample_rate");
851 if (csd->get_sample_rate == NULL) {
852 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
853 __func__, dlerror());
854
855 goto error;
856 }
857
858 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
859
860 if (csd->init == NULL) {
861 ALOGE("%s: dlsym error %s for csd_client_init",
862 __func__, dlerror());
863 goto error;
864 } else {
865 csd->init(i2s_ext_modem);
866 }
867 }
868 return csd;
869
870error:
871 free(csd);
872 csd = NULL;
873 return csd;
874}
875
876void close_csd_client(struct csd_data *csd)
877{
878 if (csd != NULL) {
879 csd->deinit();
880 dlclose(csd->csd_client);
881 free(csd);
882 csd = NULL;
883 }
884}
885
886static void platform_csd_init(struct platform_data *my_data)
887{
888#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700889 int32_t modems, (*count_modems)(void);
890 const char *name = "libdetectmodem.so";
891 const char *func = "count_modems";
892 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700893
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700894 my_data->csd = NULL;
895
896 void *lib = dlopen(name, RTLD_NOW);
897 error = dlerror();
898 if (!lib) {
899 ALOGE("%s: could not find %s: %s", __func__, name, error);
900 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700901 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700902
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700903 count_modems = NULL;
904 *(void **)(&count_modems) = dlsym(lib, func);
905 error = dlerror();
906 if (!count_modems) {
907 ALOGE("%s: could not find symbol %s in %s: %s",
908 __func__, func, name, error);
909 goto done;
910 }
911
912 modems = count_modems();
913 if (modems < 0) {
914 ALOGE("%s: count_modems failed\n", __func__);
915 goto done;
916 }
917
Eric Laurent2bafff12016-03-17 12:17:23 -0700918 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700919 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700920 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700921
922done:
923 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700924#else
925 my_data->csd = NULL;
926#endif
927}
928
Eric Laurentc6333382015-09-14 12:43:44 -0700929static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700930{
931 int32_t dev;
932 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700933 backend_tag_table[dev] = NULL;
934 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900935 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700936 }
937
David Linee3fe402017-03-13 10:00:42 -0700938 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
939 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
940 }
941
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700942 // To overwrite these go to the audio_platform_info.xml file.
943 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700944 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700945 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
946 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
947 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
948 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
949 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700950 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700951 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
952 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700953
David Linee3fe402017-03-13 10:00:42 -0700954 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
955 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
956 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
957 strdup("speaker-and-usb-headphones");
958 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700959 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
960 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
961 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
962 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
963 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
964 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
965 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700966 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700967 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700968 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700969 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
970 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
971 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
972 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
973 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
974 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
975 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
976 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
977 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
978 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
979 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
980 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
981 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -0700982 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
983 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
984 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700985 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
986 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
987 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700988
989 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700990}
991
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900992void get_cvd_version(char *cvd_version, struct audio_device *adev)
993{
994 struct mixer_ctl *ctl;
995 int count;
996 int ret = 0;
997
998 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
999 if (!ctl) {
1000 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1001 goto done;
1002 }
1003 mixer_ctl_update(ctl);
1004
1005 count = mixer_ctl_get_num_values(ctl);
1006 if (count > MAX_CVD_VERSION_STRING_SIZE)
1007 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1008
1009 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1010 if (ret != 0) {
1011 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1012 goto done;
1013 }
1014
1015done:
1016 return;
1017}
1018
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001019static int platform_acdb_init(void *platform)
1020{
1021 struct platform_data *my_data = (struct platform_data *)platform;
1022 struct audio_device *adev = my_data->adev;
1023
1024 if (!my_data->acdb_init) {
1025 ALOGE("%s: no acdb_init fn provided", __func__);
1026 return -1;
1027 }
1028
1029 if (my_data->acdb_initialized) {
1030 ALOGW("acdb is already initialized");
1031 return 0;
1032 }
1033
Thierry Strudel92232b42017-01-26 10:51:48 -08001034#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001035 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1036 if (!cvd_version)
1037 ALOGE("failed to allocate cvd_version");
1038 else {
1039 get_cvd_version(cvd_version, adev);
1040 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1041 free(cvd_version);
1042 }
1043#elif defined (PLATFORM_MSM8084)
1044 my_data->acdb_init((char *)my_data->snd_card_name);
1045#else
1046 my_data->acdb_init();
1047#endif
1048 my_data->acdb_initialized = true;
1049 return 0;
1050}
1051
David Linee3fe402017-03-13 10:00:42 -07001052static void
1053platform_backend_config_init(struct platform_data *pdata)
1054{
1055 int i;
1056
1057 /* initialize backend config */
1058 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1059 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1060 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1061 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1062
1063 if (i > MAX_RX_CODEC_BACKENDS)
1064 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1065
1066 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1067 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1068 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1069 }
1070
1071 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1072 strdup("SLIM_0_RX Format");
1073 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1074 strdup("SLIM_0_RX SampleRate");
1075
1076 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1077 strdup("SLIM_0_TX Format");
1078 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1079 strdup("SLIM_0_TX SampleRate");
1080
1081 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1082 strdup("USB_AUDIO_TX Format");
1083 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1084 strdup("USB_AUDIO_TX SampleRate");
1085 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1086 strdup("USB_AUDIO_TX Channels");
1087
1088 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1089 strdup("SLIM_6_RX Format");
1090 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1091 strdup("SLIM_6_RX SampleRate");
1092
1093 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1094 strdup("USB_AUDIO_RX Format");
1095 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1096 strdup("USB_AUDIO_RX SampleRate");
1097
1098 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1099 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1100 strdup("USB_AUDIO_RX Channels");
1101}
1102
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001103// Treblized config files will be located in /odm/etc or /vendor/etc.
1104static const char *kConfigLocationList[] =
1105 {"/odm/etc", "/vendor/etc", "/system/etc"};
1106static const int kConfigLocationListSize =
1107 (sizeof(kConfigLocationList) / sizeof(kConfigLocationList[0]));
1108
1109bool resolveConfigFile(char file_name[MIXER_PATH_MAX_LENGTH]) {
1110 char full_config_path[MIXER_PATH_MAX_LENGTH];
1111 for (int i = 0; i < kConfigLocationListSize; i++) {
1112 snprintf(full_config_path,
1113 MIXER_PATH_MAX_LENGTH,
1114 "%s/%s",
1115 kConfigLocationList[i],
1116 file_name);
1117 if (F_OK == access(full_config_path, 0)) {
1118 strcpy(file_name, full_config_path);
1119 return true;
1120 }
1121 }
1122 return false;
1123}
1124
Eric Laurentb23d5282013-05-14 15:27:20 -07001125void *platform_init(struct audio_device *adev)
1126{
1127 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001128 struct platform_data *my_data = NULL;
1129 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1130 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001131 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001132 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001133 char *snd_internal_name = NULL;
1134 char *tmp = NULL;
1135 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001136 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1137 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001138 my_data = calloc(1, sizeof(struct platform_data));
1139
1140 my_data->adev = adev;
1141
keunhui.park2f7306a2015-07-16 16:48:06 +09001142 list_init(&operator_info_list);
1143
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001144 set_platform_defaults(my_data);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001145 bool card_verifed[MAX_SND_CARD] = {0};
1146 const int retry_limit = property_get_int32("audio.snd_card.open.retries", RETRY_NUMBER);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001147
vivek mehta2b0e5a62016-09-02 17:31:58 -07001148 for (;;) {
1149 if (snd_card_num >= MAX_SND_CARD) {
1150 if (retry_num++ >= retry_limit) {
1151 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1152 goto init_failed;
1153 }
sangwoo1b9f4b32013-06-21 18:22:55 -07001154
vivek mehta2b0e5a62016-09-02 17:31:58 -07001155 snd_card_num = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001156 usleep(RETRY_US);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001157 continue;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001158 }
1159
vivek mehta2b0e5a62016-09-02 17:31:58 -07001160 if (card_verifed[snd_card_num]) {
1161 ++snd_card_num;
1162 continue;
1163 }
1164
1165 adev->mixer = mixer_open(snd_card_num);
1166
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001167 if (!adev->mixer) {
1168 ALOGE("%s: Unable to open the mixer card: %d", __func__,
vivek mehta2b0e5a62016-09-02 17:31:58 -07001169 snd_card_num);
1170 ++snd_card_num;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001171 continue;
1172 }
1173
vivek mehta2b0e5a62016-09-02 17:31:58 -07001174 card_verifed[snd_card_num] = true;
1175
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001176 snd_card_name = mixer_get_name(adev->mixer);
vivek mehtade4849c2016-03-03 17:23:38 -08001177 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001178
vivek mehtade4849c2016-03-03 17:23:38 -08001179 audio_extn_set_snd_card_split(snd_card_name);
1180 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001181
vivek mehtade4849c2016-03-03 17:23:38 -08001182 /* Get the codec internal name from the sound card and/or form factor
1183 * name and form the mixer paths and platfor info file name dynamically.
1184 * This is generic way of picking any codec and forma factor name based
1185 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001186
vivek mehtade4849c2016-03-03 17:23:38 -08001187 * current code extends and looks for any of the exteneded mixer path and
1188 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -08001189
vivek mehtade4849c2016-03-03 17:23:38 -08001190 * order of picking appropriate file is
1191 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1192 * <ii> mixer_paths_<codec_name>.xml, if file not present
1193 * <iii> mixer_paths.xml
1194
1195 * same order is followed for audio_platform_info.xml as well
1196 */
1197
1198 // need to carryforward old file name
1199 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
Eric Laurentf9583c32016-03-28 13:50:50 -07001200 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
vivek mehtade4849c2016-03-03 17:23:38 -08001201 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -08001202 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -08001203 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -07001204
vivek mehtade4849c2016-03-03 17:23:38 -08001205 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1206 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1207 snd_split_handle->form_factor);
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001208 if (!resolveConfigFile(mixer_xml_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001209 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1210 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1211 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1212
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001213 if (!resolveConfigFile(mixer_xml_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001214 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1215 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001216 resolveConfigFile(mixer_xml_file);
vivek mehtade4849c2016-03-03 17:23:38 -08001217 }
1218 }
1219
1220 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1221 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1222 snd_split_handle->form_factor);
1223
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001224 if (!resolveConfigFile(platform_info_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001225 memset(platform_info_file, 0, sizeof(platform_info_file));
1226 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1227 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1228
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001229 if (!resolveConfigFile(platform_info_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001230 memset(platform_info_file, 0, sizeof(platform_info_file));
1231 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001232 resolveConfigFile(platform_info_file);
vivek mehta60ea4152016-02-18 17:10:26 -08001233 }
1234 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001235 }
1236
vivek mehtade4849c2016-03-03 17:23:38 -08001237 /* Initialize platform specific ids and/or backends*/
1238 platform_info_init(platform_info_file, my_data);
1239
1240 /* validate the sound card name
1241 * my_data->snd_card_name can contain
1242 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1243 * example: msm8994-tomtom-mtp-snd-card
1244 * <b> or sub string of the card name, i.e. <device>-<codec>
1245 * example: msm8994-tomtom
Eric Laurentf9583c32016-03-28 13:50:50 -07001246 * snd_card_name is truncated to 32 charaters as per mixer_get_name() implementation
1247 * so use min of my_data->snd_card_name and snd_card_name length for comparison
vivek mehtade4849c2016-03-03 17:23:38 -08001248 */
1249
1250 if (my_data->snd_card_name != NULL &&
Eric Laurentf9583c32016-03-28 13:50:50 -07001251 strncmp(snd_card_name, my_data->snd_card_name,
1252 min(strlen(snd_card_name), strlen(my_data->snd_card_name))) != 0) {
vivek mehtade4849c2016-03-03 17:23:38 -08001253 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1254 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001255 ++snd_card_num;
1256 mixer_close(adev->mixer);
1257 adev->mixer = NULL;
vivek mehtade4849c2016-03-03 17:23:38 -08001258 hw_info_deinit(my_data->hw_info);
1259 my_data->hw_info = NULL;
1260 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001261 }
vivek mehtade4849c2016-03-03 17:23:38 -08001262 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1263 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001264
1265 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1266 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1267
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001268 if (!adev->audio_route) {
1269 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001270 mixer_close(adev->mixer);
1271 adev->mixer = NULL;
1272 hw_info_deinit(my_data->hw_info);
1273 my_data->hw_info = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001274 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001275 }
1276 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001277 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001278 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001279 }
1280
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001281 //set max volume step for voice call
1282 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1283 my_data->max_vol_index = atoi(value);
1284
vivek mehta65ad12d2015-08-13 18:32:48 -07001285 property_get("persist.audio.dualmic.config",value,"");
1286 if (!strcmp("endfire", value)) {
1287 dual_mic_config = true;
1288 }
1289
Prashant Malanic92c5962015-08-11 15:10:18 -07001290 my_data->source_mic_type = SOURCE_DUAL_MIC;
1291
Eric Laurentb23d5282013-05-14 15:27:20 -07001292 my_data->fluence_in_spkr_mode = false;
1293 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001294 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001295 my_data->fluence_in_voice_rec = false;
1296
vivek mehta65ad12d2015-08-13 18:32:48 -07001297 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001298 if (!strcmp("fluencepro", value)) {
1299 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001300 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001301 my_data->fluence_type = FLUENCE_ENABLE;
1302 } else if (!strcmp("none", value)) {
1303 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001304 }
1305
Prashant Malanic92c5962015-08-11 15:10:18 -07001306 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001307 property_get("persist.audio.fluence.voicecall",value,"");
1308 if (!strcmp("true", value)) {
1309 my_data->fluence_in_voice_call = true;
1310 }
1311
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001312 property_get("persist.audio.fluence.voicecomm",value,"");
1313 if (!strcmp("true", value)) {
1314 my_data->fluence_in_voice_comm = true;
1315 }
1316
Eric Laurentb23d5282013-05-14 15:27:20 -07001317 property_get("persist.audio.fluence.voicerec",value,"");
1318 if (!strcmp("true", value)) {
1319 my_data->fluence_in_voice_rec = true;
1320 }
1321
1322 property_get("persist.audio.fluence.speaker",value,"");
1323 if (!strcmp("true", value)) {
1324 my_data->fluence_in_spkr_mode = true;
1325 }
1326 }
1327
Prashant Malanic92c5962015-08-11 15:10:18 -07001328 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1329 switch (my_data->max_mic_count) {
1330 case 4:
1331 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1332 case 3:
1333 my_data->source_mic_type |= SOURCE_THREE_MIC;
1334 case 2:
1335 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1336 case 1:
1337 my_data->source_mic_type |= SOURCE_MONO_MIC;
1338 break;
1339 default:
1340 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1341 __func__, my_data->max_mic_count);
1342 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1343 break;
1344 }
1345
1346 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1347 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1348 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1349 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1350 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1351
Eric Laurentb23d5282013-05-14 15:27:20 -07001352 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1353 if (my_data->acdb_handle == NULL) {
1354 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1355 } else {
1356 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1357 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1358 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001359 if (!my_data->acdb_deallocate)
1360 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1361 __func__, LIB_ACDB_LOADER);
1362
Eric Laurentb23d5282013-05-14 15:27:20 -07001363 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1364 "acdb_loader_send_audio_cal");
1365 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001366 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001367 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001368
Eric Laurentb23d5282013-05-14 15:27:20 -07001369 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1370 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001371 if (!my_data->acdb_send_voice_cal)
1372 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1373 __func__, LIB_ACDB_LOADER);
1374
1375 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1376 "acdb_loader_reload_vocvoltable");
1377 if (!my_data->acdb_reload_vocvoltable)
1378 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1379 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001380
1381 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1382 "acdb_loader_send_gain_dep_cal");
1383 if (!my_data->acdb_send_gain_dep_cal)
1384 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1385 __func__, LIB_ACDB_LOADER);
1386
Thierry Strudel92232b42017-01-26 10:51:48 -08001387#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001388 acdb_init_v2_cvd_t acdb_init;
1389 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1390 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001391 if (acdb_init == NULL)
1392 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1393 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001394
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001395#elif defined (PLATFORM_MSM8084)
1396 acdb_init_v2_t acdb_init;
1397 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1398 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001399 if (acdb_init == NULL)
1400 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1401 dlerror());
1402
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001403#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001404 acdb_init_t acdb_init;
1405 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001406 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001407 if (acdb_init == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001408 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1409 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001410#endif
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001411 my_data->acdb_init = acdb_init;
Eric Laurentb23d5282013-05-14 15:27:20 -07001412
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001413 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1414 dlsym(my_data->acdb_handle,
1415 "acdb_loader_send_common_custom_topology");
1416
1417 if (!my_data->acdb_send_custom_top)
1418 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1419 __func__, LIB_ACDB_LOADER);
1420
1421 platform_acdb_init(my_data);
1422 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001423
David Linee3fe402017-03-13 10:00:42 -07001424 /* init usb */
1425 audio_extn_usb_init(adev);
1426
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001427 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001428
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001429 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1430
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001431 /* load csd client */
1432 platform_csd_init(my_data);
1433
David Linee3fe402017-03-13 10:00:42 -07001434 platform_backend_config_init(my_data);
1435
Eric Laurentb23d5282013-05-14 15:27:20 -07001436 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001437
1438init_failed:
1439 if (my_data)
1440 free(my_data);
1441 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001442}
1443
1444void platform_deinit(void *platform)
1445{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001446 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001447 struct operator_info *info_item;
1448 struct operator_specific_device *device_item;
1449 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001450
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001451 struct platform_data *my_data = (struct platform_data *)platform;
1452 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001453
vivek mehtade4849c2016-03-03 17:23:38 -08001454 hw_info_deinit(my_data->hw_info);
1455
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001456 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1457 if (backend_tag_table[dev])
1458 free(backend_tag_table[dev]);
1459 if (hw_interface_table[dev])
1460 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001461 if (operator_specific_device_table[dev]) {
1462 while (!list_empty(operator_specific_device_table[dev])) {
1463 node = list_head(operator_specific_device_table[dev]);
1464 list_remove(node);
1465 device_item = node_to_item(node, struct operator_specific_device, list);
1466 free(device_item->operator);
1467 free(device_item->mixer_path);
1468 free(device_item);
1469 }
1470 free(operator_specific_device_table[dev]);
1471 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001472 }
1473
1474 if (my_data->snd_card_name)
1475 free(my_data->snd_card_name);
1476
keunhui.park2f7306a2015-07-16 16:48:06 +09001477 while (!list_empty(&operator_info_list)) {
1478 node = list_head(&operator_info_list);
1479 list_remove(node);
1480 info_item = node_to_item(node, struct operator_info, list);
1481 free(info_item->name);
1482 free(info_item->mccmnc);
1483 free(info_item);
1484 }
1485
Eric Laurentb23d5282013-05-14 15:27:20 -07001486 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001487
1488 /* deinit usb */
1489 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001490}
1491
1492const char *platform_get_snd_device_name(snd_device_t snd_device)
1493{
keunhui.park2f7306a2015-07-16 16:48:06 +09001494 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1495 if (operator_specific_device_table[snd_device] != NULL) {
1496 return get_operator_specific_device_mixer_path(snd_device);
1497 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001498 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001499 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001500 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001501}
1502
vivek mehtade4849c2016-03-03 17:23:38 -08001503int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1504 char *device_name)
1505{
1506 struct platform_data *my_data = (struct platform_data *)platform;
1507
David Benjamin1565f992016-09-21 12:10:34 -04001508 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001509 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001510 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1511 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001512 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1513 if (operator_specific_device_table[snd_device] != NULL) {
1514 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1515 DEVICE_NAME_MAX_SIZE);
1516 } else {
1517 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1518 }
1519 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1520 } else {
1521 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1522 }
1523
1524 return 0;
1525}
1526
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001527void platform_add_backend_name(void *platform, char *mixer_path,
1528 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001529{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001530 struct platform_data *my_data = (struct platform_data *)platform;
1531
Haynes Mathew George98c95622014-06-20 19:14:25 -07001532 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1533 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1534 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001535 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001536
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001537 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001538
1539 if (suffix != NULL) {
1540 strcat(mixer_path, " ");
1541 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001542 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001543}
1544
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001545bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1546{
1547 bool result = true;
1548
1549 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1550 platform_get_snd_device_name(snd_device1),
1551 platform_get_snd_device_name(snd_device2));
1552
1553 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1554 ALOGE("%s: Invalid snd_device = %s", __func__,
1555 platform_get_snd_device_name(snd_device1));
1556 return false;
1557 }
1558 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1559 ALOGE("%s: Invalid snd_device = %s", __func__,
1560 platform_get_snd_device_name(snd_device2));
1561 return false;
1562 }
1563 const char * be_itf1 = hw_interface_table[snd_device1];
1564 const char * be_itf2 = hw_interface_table[snd_device2];
1565
1566 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001567 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001568 result = false;
1569 }
1570
1571 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1572 return result;
1573}
1574
Eric Laurentb23d5282013-05-14 15:27:20 -07001575int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1576{
1577 int device_id;
1578 if (device_type == PCM_PLAYBACK)
1579 device_id = pcm_device_table[usecase][0];
1580 else
1581 device_id = pcm_device_table[usecase][1];
1582 return device_id;
1583}
1584
Haynes Mathew George98c95622014-06-20 19:14:25 -07001585static int find_index(const struct name_to_index * table, int32_t len,
1586 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001587{
1588 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001589 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001590
Haynes Mathew George98c95622014-06-20 19:14:25 -07001591 if (table == NULL) {
1592 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001593 ret = -ENODEV;
1594 goto done;
1595 }
1596
Haynes Mathew George98c95622014-06-20 19:14:25 -07001597 if (name == NULL) {
1598 ALOGE("null key");
1599 ret = -ENODEV;
1600 goto done;
1601 }
1602
1603 for (i=0; i < len; i++) {
1604 if (!strcmp(table[i].name, name)) {
1605 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001606 goto done;
1607 }
1608 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001609 ALOGE("%s: Could not find index for name = %s",
1610 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001611 ret = -ENODEV;
1612done:
1613 return ret;
1614}
1615
Haynes Mathew George98c95622014-06-20 19:14:25 -07001616int platform_get_snd_device_index(char *device_name)
1617{
1618 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1619}
1620
1621int platform_get_usecase_index(const char *usecase_name)
1622{
1623 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1624}
1625
keunhui.park2f7306a2015-07-16 16:48:06 +09001626void platform_add_operator_specific_device(snd_device_t snd_device,
1627 const char *operator,
1628 const char *mixer_path,
1629 unsigned int acdb_id)
1630{
1631 struct operator_specific_device *device;
1632
1633 if (operator_specific_device_table[snd_device] == NULL) {
1634 operator_specific_device_table[snd_device] =
1635 (struct listnode *)calloc(1, sizeof(struct listnode));
1636 list_init(operator_specific_device_table[snd_device]);
1637 }
1638
1639 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1640
1641 device->operator = strdup(operator);
1642 device->mixer_path = strdup(mixer_path);
1643 device->acdb_id = acdb_id;
1644
1645 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1646
Eric Laurent2bafff12016-03-17 12:17:23 -07001647 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001648 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1649
1650}
1651
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001652int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1653{
1654 int ret = 0;
1655
1656 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1657 ALOGE("%s: Invalid snd_device = %d",
1658 __func__, snd_device);
1659 ret = -EINVAL;
1660 goto done;
1661 }
1662
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001663 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1664 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001665 acdb_device_table[snd_device] = acdb_id;
1666done:
1667 return ret;
1668}
1669
Glenn Kastencbe06ca2016-11-09 10:49:26 -08001670int platform_get_default_app_type_v2(void *platform __unused, usecase_type_t type __unused,
1671 int *app_type __unused)
Yamit Mehtae3b99562016-09-16 22:44:00 +05301672{
1673 ALOGE("%s: Not implemented", __func__);
1674 return -ENOSYS;
1675}
1676
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001677int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1678{
1679 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1680 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1681 return -EINVAL;
1682 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001683
1684 if (operator_specific_device_table[snd_device] != NULL)
1685 return get_operator_specific_device_acdb_id(snd_device);
1686 else
1687 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001688}
1689
David Linee3fe402017-03-13 10:00:42 -07001690static int platform_get_backend_index(snd_device_t snd_device)
1691{
1692 int32_t port = DEFAULT_CODEC_BACKEND;
1693
1694 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1695 if (backend_tag_table[snd_device] != NULL) {
1696 if (strncmp(backend_tag_table[snd_device], "headphones",
1697 sizeof("headphones")) == 0)
1698 port = HEADPHONE_BACKEND;
1699 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1700 port = HDMI_RX_BACKEND;
1701 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1702 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1703 port = USB_AUDIO_RX_BACKEND;
1704 }
1705 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1706 port = DEFAULT_CODEC_TX_BACKEND;
1707 if (backend_tag_table[snd_device] != NULL) {
1708 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1709 port = USB_AUDIO_TX_BACKEND;
1710 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1711 port = BT_SCO_TX_BACKEND;
1712 }
1713 } else {
1714 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1715 }
1716
1717 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1718
1719 return port;
1720}
1721
Eric Laurentb23d5282013-05-14 15:27:20 -07001722int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1723{
1724 struct platform_data *my_data = (struct platform_data *)platform;
1725 int acdb_dev_id, acdb_dev_type;
1726
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001727 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001728 if (acdb_dev_id < 0) {
1729 ALOGE("%s: Could not find acdb id for device(%d)",
1730 __func__, snd_device);
1731 return -EINVAL;
1732 }
1733 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001734 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001735 __func__, snd_device, acdb_dev_id);
1736 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1737 snd_device < SND_DEVICE_OUT_END)
1738 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1739 else
1740 acdb_dev_type = ACDB_DEV_TYPE_IN;
1741 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1742 }
1743 return 0;
1744}
1745
1746int platform_switch_voice_call_device_pre(void *platform)
1747{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001748 struct platform_data *my_data = (struct platform_data *)platform;
1749 int ret = 0;
1750
1751 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001752 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001753 /* This must be called before disabling mixer controls on APQ side */
1754 ret = my_data->csd->disable_device();
1755 if (ret < 0) {
1756 ALOGE("%s: csd_client_disable_device, failed, error %d",
1757 __func__, ret);
1758 }
1759 }
1760 return ret;
1761}
1762
1763int platform_switch_voice_call_enable_device_config(void *platform,
1764 snd_device_t out_snd_device,
1765 snd_device_t in_snd_device)
1766{
1767 struct platform_data *my_data = (struct platform_data *)platform;
1768 int acdb_rx_id, acdb_tx_id;
1769 int ret = 0;
1770
1771 if (my_data->csd == NULL)
1772 return ret;
1773
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001774 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1775 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001776 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001777 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001778 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001779
keunhui.park2f7306a2015-07-16 16:48:06 +09001780 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001781
1782 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1783 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1784 if (ret < 0) {
1785 ALOGE("%s: csd_enable_device_config, failed, error %d",
1786 __func__, ret);
1787 }
1788 } else {
1789 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1790 acdb_rx_id, acdb_tx_id);
1791 }
1792
1793 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001794}
1795
1796int platform_switch_voice_call_device_post(void *platform,
1797 snd_device_t out_snd_device,
1798 snd_device_t in_snd_device)
1799{
1800 struct platform_data *my_data = (struct platform_data *)platform;
1801 int acdb_rx_id, acdb_tx_id;
1802
1803 if (my_data->acdb_send_voice_cal == NULL) {
1804 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1805 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001806 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1807 audio_extn_spkr_prot_is_enabled())
1808 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1809
keunhui.park2f7306a2015-07-16 16:48:06 +09001810 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1811 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001812
1813 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1814 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1815 else
1816 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1817 acdb_rx_id, acdb_tx_id);
1818 }
1819
1820 return 0;
1821}
1822
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001823int platform_switch_voice_call_usecase_route_post(void *platform,
1824 snd_device_t out_snd_device,
1825 snd_device_t in_snd_device)
1826{
1827 struct platform_data *my_data = (struct platform_data *)platform;
1828 int acdb_rx_id, acdb_tx_id;
1829 int ret = 0;
1830
1831 if (my_data->csd == NULL)
1832 return ret;
1833
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001834 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1835 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001836 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001837 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001838 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001839
keunhui.park2f7306a2015-07-16 16:48:06 +09001840 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001841
1842 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1843 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1844 my_data->adev->acdb_settings);
1845 if (ret < 0) {
1846 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1847 }
1848 } else {
1849 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1850 acdb_rx_id, acdb_tx_id);
1851 }
1852
1853 return ret;
1854}
1855
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001856int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001857{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001858 struct platform_data *my_data = (struct platform_data *)platform;
1859 int ret = 0;
1860
1861 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001862 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001863 if (ret < 0) {
1864 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1865 }
1866 }
1867 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001868}
1869
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001870int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001871{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001872 struct platform_data *my_data = (struct platform_data *)platform;
1873 int ret = 0;
1874
1875 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001876 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001877 if (ret < 0) {
1878 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1879 }
1880 }
1881 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001882}
1883
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001884int platform_get_sample_rate(void *platform, uint32_t *rate)
1885{
1886 struct platform_data *my_data = (struct platform_data *)platform;
1887 int ret = 0;
1888
1889 if (my_data->csd != NULL) {
1890 ret = my_data->csd->get_sample_rate(rate);
1891 if (ret < 0) {
1892 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1893 }
1894 }
1895 return ret;
1896}
1897
vivek mehtab6506412015-08-07 16:55:17 -07001898void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1899 snd_device_t snd_device,
1900 bool enable)
1901{
1902 const char* name;
1903 switch (snd_device) {
1904 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1905 if (enable)
1906 name = "spkr-gain-in-headphone-combo";
1907 else
1908 name = "speaker-gain-default";
1909 break;
1910 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1911 if (enable)
1912 name = "spkr-gain-in-line-combo";
1913 else
1914 name = "speaker-gain-default";
1915 break;
1916 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1917 if (enable)
1918 name = "spkr-safe-gain-in-headphone-combo";
1919 else
1920 name = "speaker-safe-gain-default";
1921 break;
1922 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1923 if (enable)
1924 name = "spkr-safe-gain-in-line-combo";
1925 else
1926 name = "speaker-safe-gain-default";
1927 break;
1928 default:
1929 return;
1930 }
1931
1932 audio_route_apply_and_update_path(adev->audio_route, name);
1933}
1934
Eric Laurentb23d5282013-05-14 15:27:20 -07001935int platform_set_voice_volume(void *platform, int volume)
1936{
1937 struct platform_data *my_data = (struct platform_data *)platform;
1938 struct audio_device *adev = my_data->adev;
1939 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001940 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001941 int vol_index = 0, ret = 0;
1942 uint32_t set_values[ ] = {0,
1943 ALL_SESSION_VSID,
1944 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001945
1946 // Voice volume levels are mapped to adsp volume levels as follows.
1947 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1948 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001949 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001950 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001951
1952 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1953 if (!ctl) {
1954 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1955 __func__, mixer_ctl_name);
1956 return -EINVAL;
1957 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001958 ALOGV("Setting voice volume index: %d", set_values[0]);
1959 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1960
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001961 if (my_data->csd != NULL) {
1962 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1963 DEFAULT_VOLUME_RAMP_DURATION_MS);
1964 if (ret < 0) {
1965 ALOGE("%s: csd_volume error %d", __func__, ret);
1966 }
1967 }
1968 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001969}
1970
1971int platform_set_mic_mute(void *platform, bool state)
1972{
1973 struct platform_data *my_data = (struct platform_data *)platform;
1974 struct audio_device *adev = my_data->adev;
1975 struct mixer_ctl *ctl;
1976 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001977 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001978 uint32_t set_values[ ] = {0,
1979 ALL_SESSION_VSID,
1980 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001981
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001982 if (adev->mode != AUDIO_MODE_IN_CALL &&
1983 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001984 return 0;
1985
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001986 if (adev->enable_hfp)
1987 mixer_ctl_name = "HFP Tx Mute";
1988
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001989 set_values[0] = state;
1990 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1991 if (!ctl) {
1992 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1993 __func__, mixer_ctl_name);
1994 return -EINVAL;
1995 }
1996 ALOGV("Setting voice mute state: %d", state);
1997 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1998
1999 if (my_data->csd != NULL) {
2000 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2001 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002002 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002003 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002004 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002005 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002006 return ret;
2007}
Eric Laurentb23d5282013-05-14 15:27:20 -07002008
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002009int platform_set_device_mute(void *platform, bool state, char *dir)
2010{
2011 struct platform_data *my_data = (struct platform_data *)platform;
2012 struct audio_device *adev = my_data->adev;
2013 struct mixer_ctl *ctl;
2014 char *mixer_ctl_name = NULL;
2015 int ret = 0;
2016 uint32_t set_values[ ] = {0,
2017 ALL_SESSION_VSID,
2018 0};
2019 if(dir == NULL) {
2020 ALOGE("%s: Invalid direction:%s", __func__, dir);
2021 return -EINVAL;
2022 }
2023
2024 if (!strncmp("rx", dir, sizeof("rx"))) {
2025 mixer_ctl_name = "Voice Rx Device Mute";
2026 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2027 mixer_ctl_name = "Voice Tx Device Mute";
2028 } else {
2029 return -EINVAL;
2030 }
2031
2032 set_values[0] = state;
2033 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2034 if (!ctl) {
2035 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2036 __func__, mixer_ctl_name);
2037 return -EINVAL;
2038 }
2039
2040 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2041 __func__,state, mixer_ctl_name);
2042 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2043
2044 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002045}
2046
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002047int platform_can_split_snd_device(snd_device_t snd_device,
2048 int *num_devices,
2049 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002050{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002051 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002052 if (NULL == num_devices || NULL == new_snd_devices) {
2053 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002054 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002055 }
2056
2057 /*
2058 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002059 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002060 */
2061 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2062 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2063 *num_devices = 2;
2064 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2065 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002066 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002067 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2068 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2069 *num_devices = 2;
2070 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2071 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002072 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002073 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2074 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2075 *num_devices = 2;
2076 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2077 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002078 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002079 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2080 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2081 *num_devices = 2;
2082 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2083 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002084 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002085 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2086 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2087 SND_DEVICE_OUT_BT_SCO)) {
2088 *num_devices = 2;
2089 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2090 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2091 ret = 0;
2092 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2093 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2094 SND_DEVICE_OUT_BT_SCO_WB)) {
2095 *num_devices = 2;
2096 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2097 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2098 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002099 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2100 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2101 *num_devices = 2;
2102 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2103 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2104 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002105 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002106 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002107}
2108
Eric Laurentb23d5282013-05-14 15:27:20 -07002109snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2110{
2111 struct platform_data *my_data = (struct platform_data *)platform;
2112 struct audio_device *adev = my_data->adev;
2113 audio_mode_t mode = adev->mode;
2114 snd_device_t snd_device = SND_DEVICE_NONE;
2115
2116 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2117 if (devices == AUDIO_DEVICE_NONE ||
2118 devices & AUDIO_DEVICE_BIT_IN) {
2119 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2120 goto exit;
2121 }
2122
Eric Laurent1b491552015-09-15 17:52:41 -07002123 if (popcount(devices) == 2) {
2124 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2125 AUDIO_DEVICE_OUT_SPEAKER) ||
2126 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2127 AUDIO_DEVICE_OUT_SPEAKER)) {
2128 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2129 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2130 AUDIO_DEVICE_OUT_SPEAKER)) {
2131 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2132 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2133 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2134 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2135 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2136 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2137 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2138 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2139 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2140 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2141 AUDIO_DEVICE_OUT_SPEAKER)) {
2142 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002143 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2144 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2145 snd_device = adev->bt_wb_speech_enabled ?
2146 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2147 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
David Linee3fe402017-03-13 10:00:42 -07002148 } else if (devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2149 AUDIO_DEVICE_OUT_SPEAKER)) {
2150 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002151 } else {
2152 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2153 goto exit;
2154 }
2155 if (snd_device != SND_DEVICE_NONE) {
2156 goto exit;
2157 }
2158 }
2159
2160 if (popcount(devices) != 1) {
2161 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2162 goto exit;
2163 }
2164
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302165 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002166 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002167 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2168 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002169 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002170 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002171 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002172 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002173 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002174 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002175 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002176 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002177 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002178 else {
2179 if (devices & AUDIO_DEVICE_OUT_LINE)
2180 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2181 else
2182 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2183 }
vivek mehtaa6b79742017-03-09 15:40:43 -08002184 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2185 if (voice_is_in_call(adev)) {
2186 switch (adev->voice.tty_mode) {
2187 case TTY_MODE_FULL:
2188 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2189 break;
2190 case TTY_MODE_VCO:
2191 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2192 break;
2193 case TTY_MODE_HCO:
2194 // since Hearing will be on handset\speaker, use existing device
2195 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2196 break;
2197 default:
2198 ALOGE("%s: Invalid TTY mode (%#x)",
2199 __func__, adev->voice.tty_mode);
2200 }
2201 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002202 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002203 if (adev->bt_wb_speech_enabled) {
2204 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2205 } else {
2206 snd_device = SND_DEVICE_OUT_BT_SCO;
2207 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002208 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002209 if (!adev->enable_hfp) {
2210 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2211 } else {
2212 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2213 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002214 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002215 if(adev->voice.hac)
2216 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2217 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002218 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2219 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002220 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002221 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2222 snd_device = SND_DEVICE_OUT_VOICE_TX;
2223
Eric Laurentb23d5282013-05-14 15:27:20 -07002224 if (snd_device != SND_DEVICE_NONE) {
2225 goto exit;
2226 }
2227 }
2228
Eric Laurentb23d5282013-05-14 15:27:20 -07002229 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2230 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2231 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002232 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2233 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002234 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2235 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002236 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002237 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002238 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2239 else
2240 snd_device = SND_DEVICE_OUT_SPEAKER;
2241 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002242 if (adev->bt_wb_speech_enabled) {
2243 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2244 } else {
2245 snd_device = SND_DEVICE_OUT_BT_SCO;
2246 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002247 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2248 snd_device = SND_DEVICE_OUT_HDMI ;
David Linee3fe402017-03-13 10:00:42 -07002249 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2250 if (audio_extn_usb_is_capture_supported())
2251 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2252 else
2253 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2254 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002255 /*HAC support for voice-ish audio (eg visual voicemail)*/
2256 if(adev->voice.hac)
2257 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2258 else
2259 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002260 } else {
2261 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2262 }
2263exit:
2264 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2265 return snd_device;
2266}
2267
2268snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2269{
2270 struct platform_data *my_data = (struct platform_data *)platform;
2271 struct audio_device *adev = my_data->adev;
2272 audio_source_t source = (adev->active_input == NULL) ?
2273 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2274
2275 audio_mode_t mode = adev->mode;
2276 audio_devices_t in_device = ((adev->active_input == NULL) ?
2277 AUDIO_DEVICE_NONE : adev->active_input->device)
2278 & ~AUDIO_DEVICE_BIT_IN;
2279 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2280 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2281 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002282 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002283
Prashant Malanic92c5962015-08-11 15:10:18 -07002284 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2285 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002286 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2287 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002288 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002289 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002290 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2291 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002292 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002293 case TTY_MODE_FULL:
2294 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2295 break;
2296 case TTY_MODE_VCO:
2297 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2298 break;
2299 case TTY_MODE_HCO:
2300 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2301 break;
2302 default:
2303 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2304 }
2305 goto exit;
2306 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2307 switch (adev->voice.tty_mode) {
2308 case TTY_MODE_FULL:
2309 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2310 break;
2311 case TTY_MODE_VCO:
2312 // since voice will be captured from handset mic, use existing device
2313 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2314 break;
2315 case TTY_MODE_HCO:
2316 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2317 break;
2318 default:
2319 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002320 }
2321 goto exit;
2322 }
2323 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002324 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002325 if (my_data->fluence_in_voice_call == false) {
2326 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2327 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002328 if (is_operator_tmus())
2329 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002330 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002331 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002332 }
2333 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2334 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2335 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002336 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002337 if (adev->bluetooth_nrec)
2338 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2339 else
2340 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002341 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002342 if (adev->bluetooth_nrec)
2343 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2344 else
2345 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002346 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002347 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002348 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2349 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2350 out_device & AUDIO_DEVICE_OUT_LINE) {
2351 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2352 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2353 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2354 } else {
2355 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2356 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002357 }
vivek mehtafe121d52015-08-10 23:39:23 -07002358
2359 //select default
2360 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002361 if (!adev->enable_hfp) {
2362 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2363 } else {
2364 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2365 platform_set_echo_reference(adev, true, out_device);
2366 }
vivek mehtafe121d52015-08-10 23:39:23 -07002367 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002368 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002369 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002370 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002371 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2372 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2373 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2374 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2375 }
2376 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2377 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002378 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2379 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2380 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002381 if (adev->active_input->enable_aec)
2382 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2383 else
2384 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002385 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2386 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002387 if (adev->active_input->enable_aec)
2388 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2389 else
2390 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002391 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2392 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2393 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002394 if (adev->active_input->enable_aec)
2395 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2396 else
2397 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002398 }
2399 platform_set_echo_reference(adev, true, out_device);
2400 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2401 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2402 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002403 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002404 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2405 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002406 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002407 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2408 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002409 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002410 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002411 if (adev->active_input->enable_aec) {
2412 if (adev->active_input->enable_ns) {
2413 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2414 } else {
2415 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2416 }
vivek mehta733c1df2016-04-04 15:09:24 -07002417 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002418 } else if (adev->active_input->enable_ns) {
2419 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2420 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002421 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002422 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002423 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002424 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2425 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002426 }
rago90fb9612015-12-02 11:37:53 -08002427 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2428 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002429 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2430 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2431 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2432 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002433 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002434 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2435 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002436 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002437 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2438 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2439 } else {
2440 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2441 }
rago90fb9612015-12-02 11:37:53 -08002442 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2443 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2444 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002445 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002446 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002447 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002448 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2449 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002450 if (adev->active_input->enable_aec &&
2451 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002452 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002453 if (my_data->fluence_in_spkr_mode &&
2454 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002455 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002456 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002457 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002458 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002459 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002460 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002461 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002462 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002463 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002464 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002465 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002466 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002467 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2468 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002469 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002470 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002471 } else if (adev->active_input->enable_aec) {
2472 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2473 if (my_data->fluence_in_spkr_mode &&
2474 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002475 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002476 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002477 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002478 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002479 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002480 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2481 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002482 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002483 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002484 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002485 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002486 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002487 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2488 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2489 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002490 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002491 } else if (adev->active_input->enable_ns) {
2492 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2493 if (my_data->fluence_in_spkr_mode &&
2494 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002495 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002496 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002497 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002498 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002499 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002500 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2501 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002502 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002503 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002504 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002505 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002506 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002507 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002508 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002509 }
2510 } else if (source == AUDIO_SOURCE_DEFAULT) {
2511 goto exit;
2512 }
2513
2514
2515 if (snd_device != SND_DEVICE_NONE) {
2516 goto exit;
2517 }
2518
2519 if (in_device != AUDIO_DEVICE_NONE &&
2520 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2521 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2522 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002523 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002524 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002525 snd_device = SND_DEVICE_IN_QUAD_MIC;
2526 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002527 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002528 snd_device = SND_DEVICE_IN_THREE_MIC;
2529 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2530 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002531 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002532 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2533 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002534 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002535 } else {
2536 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2537 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2538 my_data->source_mic_type, channel_count, channel_mask);
2539 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2540 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002541 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002542 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2543 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002544 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002545 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2546 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002547 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002548 } else {
2549 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2550 " no combination found .. setting to mono", __func__,
2551 my_data->source_mic_type, channel_count);
2552 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2553 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002554 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2555 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2556 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002557 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002558 if (adev->bluetooth_nrec)
2559 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2560 else
2561 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002562 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002563 if (adev->bluetooth_nrec)
2564 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2565 else
2566 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002567 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002568 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2569 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002570 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE ) {
2571 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002572 } else {
2573 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2574 ALOGW("%s: Using default handset-mic", __func__);
2575 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2576 }
2577 } else {
2578 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2579 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2580 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2581 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002582 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002583 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002584 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002585 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002586 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2587 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002588 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002589 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2590 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002591 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002592 } else {
2593 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2594 " no combination found .. setting to mono", __func__,
2595 my_data->source_mic_type, channel_count);
2596 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2597 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002598 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002599 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002600 if (adev->bluetooth_nrec)
2601 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2602 else
2603 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002604 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002605 if (adev->bluetooth_nrec)
2606 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2607 else
2608 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002609 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002610 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2611 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002612 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2613 if (audio_extn_usb_is_capture_supported())
2614 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2615 else
2616 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002617 } else {
2618 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2619 ALOGW("%s: Using default handset-mic", __func__);
2620 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2621 }
2622 }
2623exit:
2624 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2625 return snd_device;
2626}
2627
2628int platform_set_hdmi_channels(void *platform, int channel_count)
2629{
2630 struct platform_data *my_data = (struct platform_data *)platform;
2631 struct audio_device *adev = my_data->adev;
2632 struct mixer_ctl *ctl;
2633 const char *channel_cnt_str = NULL;
2634 const char *mixer_ctl_name = "HDMI_RX Channels";
2635 switch (channel_count) {
2636 case 8:
2637 channel_cnt_str = "Eight"; break;
2638 case 7:
2639 channel_cnt_str = "Seven"; break;
2640 case 6:
2641 channel_cnt_str = "Six"; break;
2642 case 5:
2643 channel_cnt_str = "Five"; break;
2644 case 4:
2645 channel_cnt_str = "Four"; break;
2646 case 3:
2647 channel_cnt_str = "Three"; break;
2648 default:
2649 channel_cnt_str = "Two"; break;
2650 }
2651 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2652 if (!ctl) {
2653 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2654 __func__, mixer_ctl_name);
2655 return -EINVAL;
2656 }
2657 ALOGV("HDMI channel count: %s", channel_cnt_str);
2658 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2659 return 0;
2660}
2661
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002662int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002663{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002664 struct platform_data *my_data = (struct platform_data *)platform;
2665 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002666 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2667 char *sad = block;
2668 int num_audio_blocks;
2669 int channel_count;
2670 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002671 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002672
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002673 struct mixer_ctl *ctl;
2674
2675 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2676 if (!ctl) {
2677 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2678 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002679 return 0;
2680 }
2681
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002682 mixer_ctl_update(ctl);
2683
2684 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002685
2686 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002687 if (count > (int)sizeof(block))
2688 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002689
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002690 ret = mixer_ctl_get_array(ctl, block, count);
2691 if (ret != 0) {
2692 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2693 return 0;
2694 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002695
2696 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002697 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002698
2699 for (i = 0; i < num_audio_blocks; i++) {
2700 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002701 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2702 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002703 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002704 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002705
2706 channel_count = (sad[0] & 0x7) + 1;
2707 if (channel_count > max_channels)
2708 max_channels = channel_count;
2709
2710 /* Advance to next block */
2711 sad += 3;
2712 }
2713
2714 return max_channels;
2715}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002716
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002717int platform_set_incall_recording_session_id(void *platform,
2718 uint32_t session_id, int rec_mode)
2719{
2720 int ret = 0;
2721 struct platform_data *my_data = (struct platform_data *)platform;
2722 struct audio_device *adev = my_data->adev;
2723 struct mixer_ctl *ctl;
2724 const char *mixer_ctl_name = "Voc VSID";
2725 int num_ctl_values;
2726 int i;
2727
2728 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2729 if (!ctl) {
2730 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2731 __func__, mixer_ctl_name);
2732 ret = -EINVAL;
2733 } else {
2734 num_ctl_values = mixer_ctl_get_num_values(ctl);
2735 for (i = 0; i < num_ctl_values; i++) {
2736 if (mixer_ctl_set_value(ctl, i, session_id)) {
2737 ALOGV("Error: invalid session_id: %x", session_id);
2738 ret = -EINVAL;
2739 break;
2740 }
2741 }
2742 }
2743
2744 if (my_data->csd != NULL) {
2745 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2746 if (ret < 0) {
2747 ALOGE("%s: csd_client_start_record failed, error %d",
2748 __func__, ret);
2749 }
2750 }
2751
2752 return ret;
2753}
2754
2755int platform_stop_incall_recording_usecase(void *platform)
2756{
2757 int ret = 0;
2758 struct platform_data *my_data = (struct platform_data *)platform;
2759
2760 if (my_data->csd != NULL) {
2761 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2762 if (ret < 0) {
2763 ALOGE("%s: csd_client_stop_record failed, error %d",
2764 __func__, ret);
2765 }
2766 }
2767
2768 return ret;
2769}
2770
2771int platform_start_incall_music_usecase(void *platform)
2772{
2773 int ret = 0;
2774 struct platform_data *my_data = (struct platform_data *)platform;
2775
2776 if (my_data->csd != NULL) {
2777 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2778 if (ret < 0) {
2779 ALOGE("%s: csd_client_start_playback failed, error %d",
2780 __func__, ret);
2781 }
2782 }
2783
2784 return ret;
2785}
2786
2787int platform_stop_incall_music_usecase(void *platform)
2788{
2789 int ret = 0;
2790 struct platform_data *my_data = (struct platform_data *)platform;
2791
2792 if (my_data->csd != NULL) {
2793 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2794 if (ret < 0) {
2795 ALOGE("%s: csd_client_stop_playback failed, error %d",
2796 __func__, ret);
2797 }
2798 }
2799
2800 return ret;
2801}
2802
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002803int platform_set_parameters(void *platform, struct str_parms *parms)
2804{
2805 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002806 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002807 char *kv_pairs = str_parms_to_str(parms);
2808 int ret = 0, err;
2809
2810 if (kv_pairs == NULL) {
2811 ret = -EINVAL;
2812 ALOGE("%s: key-value pair is NULL",__func__);
2813 goto done;
2814 }
2815
2816 ALOGV("%s: enter: %s", __func__, kv_pairs);
2817
2818 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2819 value, sizeof(value));
2820 if (err >= 0) {
2821 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2822 my_data->snd_card_name = strdup(value);
2823 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2824 }
2825
keunhui.park2f7306a2015-07-16 16:48:06 +09002826 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2827 value, sizeof(value));
2828 if (err >= 0) {
2829 struct operator_info *info;
2830 char *str = value;
2831 char *name;
2832
2833 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2834 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2835 name = strtok(str, ";");
2836 info->name = strdup(name);
2837 info->mccmnc = strdup(str + strlen(name) + 1);
2838
2839 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002840 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002841 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002842
2843 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002844 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002845 value, sizeof(value));
2846 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002847 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002848 my_data->max_mic_count = atoi(value);
2849 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002850 }
2851
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002852done:
2853 ALOGV("%s: exit with code(%d)", __func__, ret);
2854 if (kv_pairs != NULL)
2855 free(kv_pairs);
2856
2857 return ret;
2858}
2859
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002860/* Delay in Us */
2861int64_t platform_render_latency(audio_usecase_t usecase)
2862{
2863 switch (usecase) {
2864 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2865 return DEEP_BUFFER_PLATFORM_DELAY;
2866 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2867 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002868 case USECASE_AUDIO_PLAYBACK_ULL:
2869 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08002870 case USECASE_AUDIO_PLAYBACK_MMAP:
2871 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002872 default:
2873 return 0;
2874 }
2875}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002876
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002877int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2878 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002879{
2880 int ret = 0;
2881
2882 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2883 ALOGE("%s: Invalid snd_device = %d",
2884 __func__, device);
2885 ret = -EINVAL;
2886 goto done;
2887 }
2888
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002889 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2890 platform_get_snd_device_name(device),
2891 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2892 if (backend_tag_table[device]) {
2893 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002894 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002895 backend_tag_table[device] = strdup(backend_tag);
2896
2897 if (hw_interface != NULL) {
2898 if (hw_interface_table[device])
2899 free(hw_interface_table[device]);
2900 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2901 hw_interface_table[device] = strdup(hw_interface);
2902 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002903done:
2904 return ret;
2905}
2906
2907int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2908{
2909 int ret = 0;
2910 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2911 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2912 ret = -EINVAL;
2913 goto done;
2914 }
2915
2916 if ((type != 0) && (type != 1)) {
2917 ALOGE("%s: invalid usecase type", __func__);
2918 ret = -EINVAL;
2919 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002920 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002921 pcm_device_table[usecase][type] = pcm_id;
2922done:
2923 return ret;
2924}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002925
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002926#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2927int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2928 // backup_gain: gain to try to set in case of an error during ramp
2929 int start_gain, end_gain, step, backup_gain, i;
2930 bool error = false;
2931 const struct mixer_ctl *ctl;
2932 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2933 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2934 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2935 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2936 if (!ctl_left || !ctl_right) {
2937 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2938 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2939 return -EINVAL;
2940 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2941 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2942 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2943 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2944 return -EINVAL;
2945 }
2946 if (ramp_up) {
2947 start_gain = 0;
2948 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2949 step = +1;
2950 backup_gain = end_gain;
2951 } else {
2952 // using same gain on left and right
2953 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2954 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2955 end_gain = 0;
2956 step = -1;
2957 backup_gain = start_gain;
2958 }
2959 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2960 //ALOGV("setting speaker gain to %d", i);
2961 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2962 ALOGE("%s: error setting %s to %d during gain ramp",
2963 __func__, mixer_ctl_name_gain_left, i);
2964 error = true;
2965 break;
2966 }
2967 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2968 ALOGE("%s: error setting %s to %d during gain ramp",
2969 __func__, mixer_ctl_name_gain_right, i);
2970 error = true;
2971 break;
2972 }
2973 usleep(1000);
2974 }
2975 if (error) {
2976 // an error occured during the ramp, let's still try to go back to a safe volume
2977 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2978 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2979 }
2980 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2981 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2982 }
2983 }
2984 return start_gain;
2985}
2986
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002987int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2988{
2989 // only update if there is active pcm playback on speaker
2990 struct audio_usecase *usecase;
2991 struct listnode *node;
2992 struct platform_data *my_data = (struct platform_data *)adev->platform;
2993
2994 if (my_data->speaker_lr_swap != swap_channels) {
Jean-Michel Trivif7148702016-09-16 18:23:05 -07002995
2996 // do not swap channels in audio modes with concurrent capture and playback
2997 // as this may break the echo reference
2998 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
2999 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3000 return 0;
3001 }
3002
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003003 my_data->speaker_lr_swap = swap_channels;
3004
3005 list_for_each(node, &adev->usecase_list) {
3006 usecase = node_to_item(node, struct audio_usecase, list);
3007 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003008 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3009 /*
3010 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3011 * to perform device switch to disable the current backend to
3012 * enable it with new acdb data.
3013 */
3014 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3015 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003016 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003017 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003018 if (initial_skpr_gain != -EINVAL) {
3019 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3020 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003021 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003022 const char *mixer_path;
3023 if (swap_channels) {
3024 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3025 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3026 } else {
3027 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3028 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3029 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003030 }
3031 break;
3032 }
3033 }
3034 }
3035 return 0;
3036}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003037
3038static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3039static int num_gain_tbl_entry = 0;
3040
3041bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3042
3043 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3044 if (num_gain_tbl_entry == -1) {
3045 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3046 __func__);
3047 return false;
3048 }
3049
3050 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3051 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3052 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3053 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3054 return false;
3055 }
3056
3057 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3058 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3059 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3060 return false;
3061 }
3062
3063 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3064 ++num_gain_tbl_entry;
3065
3066 return true;
3067}
3068
3069int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3070 int table_size) {
3071 int itt = 0;
3072 ALOGV("platform_get_gain_level_mapping called ");
3073
3074 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3075 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3076 return 0;
3077 }
3078
3079 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3080 mapping_tbl[itt] = tbl_mapping[itt];
3081 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3082 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3083 }
3084
3085 return num_gain_tbl_entry;
3086}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003087
3088int platform_snd_card_update(void *platform, card_status_t status)
3089{
3090 struct platform_data *my_data = (struct platform_data *)platform;
3091 struct audio_device *adev = my_data->adev;
3092
3093 if (status == CARD_STATUS_ONLINE) {
3094 if (my_data->acdb_send_custom_top)
3095 my_data->acdb_send_custom_top();
3096 }
3097 return 0;
3098}
David Linee3fe402017-03-13 10:00:42 -07003099
3100/*
3101 * configures afe with bit width and Sample Rate
3102 */
3103static int platform_set_backend_cfg(const struct audio_device* adev,
3104 snd_device_t snd_device,
3105 const struct audio_backend_cfg *backend_cfg)
3106{
3107
3108 int ret = 0;
3109 const int backend_idx = platform_get_backend_index(snd_device);
3110 struct platform_data *my_data = (struct platform_data *)adev->platform;
3111 const unsigned int bit_width = backend_cfg->bit_width;
3112 const unsigned int sample_rate = backend_cfg->sample_rate;
3113 const unsigned int channels = backend_cfg->channels;
3114 const audio_format_t format = backend_cfg->format;
3115 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3116
3117
3118 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3119 ", backend_idx %d device (%s)", __func__, bit_width,
3120 sample_rate, channels, backend_idx,
3121 platform_get_snd_device_name(snd_device));
3122
3123 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3124 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3125
3126 struct mixer_ctl *ctl = NULL;
3127 ctl = mixer_get_ctl_by_name(adev->mixer,
3128 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3129 if (!ctl) {
3130 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3131 __func__,
3132 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3133 return -EINVAL;
3134 }
3135
3136 if (bit_width == 24) {
3137 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3138 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3139 else
3140 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3141 } else if (bit_width == 32) {
3142 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3143 } else {
3144 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3145 }
3146 if ( ret < 0) {
3147 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3148 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3149 } else {
3150 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3151 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3152 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3153 }
3154 /* set the ret as 0 and not pass back to upper layer */
3155 ret = 0;
3156 }
3157
3158 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3159 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3160 char *rate_str = NULL;
3161 struct mixer_ctl *ctl = NULL;
3162
3163 switch (sample_rate) {
3164 case 32000:
3165 if (passthrough_enabled) {
3166 rate_str = "KHZ_32";
3167 break;
3168 }
3169 case 8000:
3170 case 11025:
3171 case 16000:
3172 case 22050:
3173 case 48000:
3174 rate_str = "KHZ_48";
3175 break;
3176 case 44100:
3177 rate_str = "KHZ_44P1";
3178 break;
3179 case 64000:
3180 case 96000:
3181 rate_str = "KHZ_96";
3182 break;
3183 case 88200:
3184 rate_str = "KHZ_88P2";
3185 break;
3186 case 176400:
3187 rate_str = "KHZ_176P4";
3188 break;
3189 case 192000:
3190 rate_str = "KHZ_192";
3191 break;
3192 case 352800:
3193 rate_str = "KHZ_352P8";
3194 break;
3195 case 384000:
3196 rate_str = "KHZ_384";
3197 break;
3198 case 144000:
3199 if (passthrough_enabled) {
3200 rate_str = "KHZ_144";
3201 break;
3202 }
3203 default:
3204 rate_str = "KHZ_48";
3205 break;
3206 }
3207
3208 ctl = mixer_get_ctl_by_name(adev->mixer,
3209 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3210 if(!ctl) {
3211 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3212 __func__,
3213 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3214 return -EINVAL;
3215 }
3216
3217 ALOGD("%s:becf: afe: %s set to %s", __func__,
3218 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3219 mixer_ctl_set_enum_by_string(ctl, rate_str);
3220 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3221 }
3222 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3223 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3224 struct mixer_ctl *ctl = NULL;
3225 char *channel_cnt_str = NULL;
3226
3227 switch (channels) {
3228 case 8:
3229 channel_cnt_str = "Eight"; break;
3230 case 7:
3231 channel_cnt_str = "Seven"; break;
3232 case 6:
3233 channel_cnt_str = "Six"; break;
3234 case 5:
3235 channel_cnt_str = "Five"; break;
3236 case 4:
3237 channel_cnt_str = "Four"; break;
3238 case 3:
3239 channel_cnt_str = "Three"; break;
3240 case 1:
3241 channel_cnt_str = "One"; break;
3242 case 2:
3243 default:
3244 channel_cnt_str = "Two"; break;
3245 }
3246
3247 ctl = mixer_get_ctl_by_name(adev->mixer,
3248 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3249 if (!ctl) {
3250 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3251 __func__,
3252 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3253 return -EINVAL;
3254 }
3255 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3256 my_data->current_backend_cfg[backend_idx].channels = channels;
3257
3258 // skip EDID configuration for HDMI backend
3259
3260 ALOGD("%s:becf: afe: %s set to %s", __func__,
3261 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3262 channel_cnt_str);
3263 }
3264
3265 // skip set ext_display format mixer control
3266 return ret;
3267}
3268
3269static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3270{
3271 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3272 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3273 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3274 }
3275
3276 return backend_bit_width_table[snd_device];
3277}
3278
3279/*
3280 * return backend_idx on which voice call is active
3281 */
3282static int platform_get_voice_call_backend(struct audio_device* adev)
3283{
3284 struct audio_usecase *uc = NULL;
3285 struct listnode *node;
3286 snd_device_t out_snd_device = SND_DEVICE_NONE;
3287
3288 int backend_idx = -1;
3289
3290 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3291 list_for_each(node, &adev->usecase_list) {
3292 uc = node_to_item(node, struct audio_usecase, list);
3293 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3294 out_snd_device = platform_get_output_snd_device(adev->platform,
3295 uc->stream.out->devices);
3296 backend_idx = platform_get_backend_index(out_snd_device);
3297 break;
3298 }
3299 }
3300 }
3301 return backend_idx;
3302}
3303
3304/*
3305 * goes through all the current usecases and picks the highest
3306 * bitwidth & samplerate
3307 */
3308static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3309 int backend_idx,
3310 struct audio_backend_cfg *backend_cfg)
3311{
3312 bool backend_change = false;
3313 unsigned int bit_width;
3314 unsigned int sample_rate;
3315 unsigned int channels;
3316 struct platform_data *my_data = (struct platform_data *)adev->platform;
3317
3318 bit_width = backend_cfg->bit_width;
3319 sample_rate = backend_cfg->sample_rate;
3320 channels = backend_cfg->channels;
3321
3322 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3323 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3324 sample_rate, channels);
3325
3326 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3327 // default backend
3328 // force routing is not required here, caller will do it anyway
3329 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3330 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3331 "for unprocessed/camera source", __func__);
3332 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3333 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3334 }
3335
3336 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3337 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3338 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3339 __func__, bit_width, sample_rate, channels);
3340 }
3341
3342 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3343 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3344
3345 // Force routing if the expected bitwdith or samplerate
3346 // is not same as current backend comfiguration
3347 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3348 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3349 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3350 backend_cfg->bit_width = bit_width;
3351 backend_cfg->sample_rate= sample_rate;
3352 backend_cfg->channels = channels;
3353 backend_change = true;
3354 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3355 "new sample rate: %d new channel: %d",
3356 __func__, backend_cfg->bit_width,
3357 backend_cfg->sample_rate, backend_cfg->channels);
3358 }
3359
3360 return backend_change;
3361}
3362
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003363static void platform_pick_playback_cfg_for_uc(struct audio_device *adev,
3364 struct audio_usecase *usecase,
3365 snd_device_t snd_device,
3366 unsigned int *bit_width,
3367 unsigned int *sample_rate,
3368 unsigned int *channels)
3369{
3370 int i =0;
3371 struct listnode *node;
3372 list_for_each(node, &adev->usecase_list) {
3373 struct audio_usecase *uc;
3374 uc = node_to_item(node, struct audio_usecase, list);
3375 struct stream_out *out = (struct stream_out*) uc->stream.out;
3376 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3377 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3378 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3379 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3380 uc->id, out->sample_rate,
3381 pcm_format_to_bits(out->config.format), out_channels,
3382 platform_get_snd_device_name(uc->out_snd_device));
3383
3384 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3385 if (*bit_width < pcm_format_to_bits(out->config.format))
3386 *bit_width = pcm_format_to_bits(out->config.format);
3387 if (*sample_rate < out->sample_rate)
3388 *sample_rate = out->sample_rate;
3389 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3390 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3391 if (*channels < out_channels)
3392 *channels = out_channels;
3393 }
3394 }
3395 }
3396 return;
3397}
3398
David Linee3fe402017-03-13 10:00:42 -07003399static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3400 struct audio_usecase* usecase,
3401 snd_device_t snd_device,
3402 struct audio_backend_cfg *backend_cfg)
3403{
3404 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003405 unsigned int bit_width;
3406 unsigned int sample_rate;
3407 unsigned int channels;
3408 bool passthrough_enabled = false;
3409 int backend_idx = DEFAULT_CODEC_BACKEND;
3410 struct platform_data *my_data = (struct platform_data *)adev->platform;
3411 bool channels_updated = false;
3412
3413 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3414 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3415 backend_change = false;
3416 return backend_change;
3417 }
3418
3419 backend_idx = platform_get_backend_index(snd_device);
3420 bit_width = backend_cfg->bit_width;
3421 sample_rate = backend_cfg->sample_rate;
3422 channels = backend_cfg->channels;
3423
3424 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3425 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3426 sample_rate, channels, backend_idx, usecase->id,
3427 platform_get_snd_device_name(snd_device));
3428
3429 if (backend_idx == platform_get_voice_call_backend(adev)) {
3430 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3431 __func__);
3432 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3433 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3434 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3435 } else {
3436 /*
3437 * The backend should be configured at highest bit width and/or
3438 * sample rate amongst all playback usecases.
3439 * If the selected sample rate and/or bit width differ with
3440 * current backend sample rate and/or bit width, then, we set the
3441 * backend re-configuration flag.
3442 *
3443 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3444 */
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003445 platform_pick_playback_cfg_for_uc(adev, usecase, snd_device,
3446 &bit_width,
3447 &sample_rate,
3448 &channels);
David Linee3fe402017-03-13 10:00:42 -07003449 }
3450
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003451 switch (backend_idx) {
3452 case USB_AUDIO_RX_BACKEND:
3453 audio_extn_usb_is_config_supported(&bit_width,
3454 &sample_rate, &channels, true);
3455 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3456 __func__, bit_width, sample_rate, channels);
3457 break;
3458 case DEFAULT_CODEC_BACKEND:
3459 case HEADPHONE_BACKEND:
3460 default:
3461 bit_width = platform_get_snd_device_bit_width(snd_device);
3462 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3463 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3464 break;
David Linee3fe402017-03-13 10:00:42 -07003465 }
3466
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003467 if (channels != my_data->current_backend_cfg[backend_idx].channels) {
3468 channels_updated = true;
David Linee3fe402017-03-13 10:00:42 -07003469 }
3470
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003471 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3472 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003473 __func__, backend_idx , bit_width, sample_rate);
3474
3475 // Force routing if the expected bitwdith or samplerate
3476 // is not same as current backend comfiguration
3477 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3478 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3479 passthrough_enabled || channels_updated) {
3480 backend_cfg->bit_width = bit_width;
3481 backend_cfg->sample_rate = sample_rate;
3482 backend_cfg->channels = channels;
3483 backend_cfg->passthrough_enabled = passthrough_enabled;
3484 backend_change = true;
3485 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3486 "new sample rate: %d new channels: %d",
3487 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3488 }
3489
3490 return backend_change;
3491}
3492
3493bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3494 struct audio_usecase *usecase, snd_device_t snd_device)
3495{
3496 int backend_idx = DEFAULT_CODEC_BACKEND;
3497 int new_snd_devices[SND_DEVICE_OUT_END];
3498 int i, num_devices = 1;
3499 bool ret = false;
3500 struct platform_data *my_data = (struct platform_data *)adev->platform;
3501 struct audio_backend_cfg backend_cfg;
3502
3503 backend_idx = platform_get_backend_index(snd_device);
3504
3505 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3506 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3507 backend_cfg.format = usecase->stream.out->format;
3508 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3509 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3510 backend_cfg.passthrough_enabled = false;
3511
3512 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3513 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3514 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3515 platform_get_snd_device_name(snd_device));
3516
3517 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3518 new_snd_devices[0] = snd_device;
3519
3520 for (i = 0; i < num_devices; i++) {
3521 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3522 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3523 &backend_cfg))) {
3524 platform_set_backend_cfg(adev, new_snd_devices[i],
3525 &backend_cfg);
3526 ret = true;
3527 }
3528 }
3529 return ret;
3530}
3531
3532bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3533 struct audio_usecase *usecase, snd_device_t snd_device)
3534{
3535 int backend_idx = platform_get_backend_index(snd_device);
3536 int ret = 0;
3537 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003538 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003539
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003540 if (usecase->type == PCM_CAPTURE) {
3541 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003542 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3543 } else {
3544 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3545 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3546 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3547 backend_cfg.channels = 1;
3548 }
3549
3550 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3551 ", backend_idx %d usecase = %d device (%s)", __func__,
3552 backend_cfg.bit_width,
3553 backend_cfg.sample_rate,
3554 backend_cfg.channels,
3555 backend_idx, usecase->id,
3556 platform_get_snd_device_name(snd_device));
3557
3558 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3559 ret = platform_set_backend_cfg(adev, snd_device,
3560 &backend_cfg);
3561 if(!ret)
3562 return true;
3563 }
3564
3565 return false;
3566}
3567