blob: 0f3bcf0692fd6f065c5acaba4b2d56a824a3c67e [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
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001486 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001487 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001488
1489 /* deinit usb */
1490 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001491}
1492
1493const char *platform_get_snd_device_name(snd_device_t snd_device)
1494{
keunhui.park2f7306a2015-07-16 16:48:06 +09001495 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1496 if (operator_specific_device_table[snd_device] != NULL) {
1497 return get_operator_specific_device_mixer_path(snd_device);
1498 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001499 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001500 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001501 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001502}
1503
vivek mehtade4849c2016-03-03 17:23:38 -08001504int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1505 char *device_name)
1506{
1507 struct platform_data *my_data = (struct platform_data *)platform;
1508
David Benjamin1565f992016-09-21 12:10:34 -04001509 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001510 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001511 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1512 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001513 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1514 if (operator_specific_device_table[snd_device] != NULL) {
1515 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1516 DEVICE_NAME_MAX_SIZE);
1517 } else {
1518 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1519 }
1520 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1521 } else {
1522 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1523 }
1524
1525 return 0;
1526}
1527
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001528void platform_add_backend_name(void *platform, char *mixer_path,
1529 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001530{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001531 struct platform_data *my_data = (struct platform_data *)platform;
1532
Haynes Mathew George98c95622014-06-20 19:14:25 -07001533 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1534 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1535 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001536 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001537
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001538 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001539
1540 if (suffix != NULL) {
1541 strcat(mixer_path, " ");
1542 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001543 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001544}
1545
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001546bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1547{
1548 bool result = true;
1549
1550 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1551 platform_get_snd_device_name(snd_device1),
1552 platform_get_snd_device_name(snd_device2));
1553
1554 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1555 ALOGE("%s: Invalid snd_device = %s", __func__,
1556 platform_get_snd_device_name(snd_device1));
1557 return false;
1558 }
1559 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1560 ALOGE("%s: Invalid snd_device = %s", __func__,
1561 platform_get_snd_device_name(snd_device2));
1562 return false;
1563 }
1564 const char * be_itf1 = hw_interface_table[snd_device1];
1565 const char * be_itf2 = hw_interface_table[snd_device2];
1566
1567 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001568 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001569 result = false;
1570 }
1571
1572 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1573 return result;
1574}
1575
Eric Laurentb23d5282013-05-14 15:27:20 -07001576int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1577{
1578 int device_id;
1579 if (device_type == PCM_PLAYBACK)
1580 device_id = pcm_device_table[usecase][0];
1581 else
1582 device_id = pcm_device_table[usecase][1];
1583 return device_id;
1584}
1585
Haynes Mathew George98c95622014-06-20 19:14:25 -07001586static int find_index(const struct name_to_index * table, int32_t len,
1587 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001588{
1589 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001590 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001591
Haynes Mathew George98c95622014-06-20 19:14:25 -07001592 if (table == NULL) {
1593 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001594 ret = -ENODEV;
1595 goto done;
1596 }
1597
Haynes Mathew George98c95622014-06-20 19:14:25 -07001598 if (name == NULL) {
1599 ALOGE("null key");
1600 ret = -ENODEV;
1601 goto done;
1602 }
1603
1604 for (i=0; i < len; i++) {
1605 if (!strcmp(table[i].name, name)) {
1606 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001607 goto done;
1608 }
1609 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001610 ALOGE("%s: Could not find index for name = %s",
1611 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001612 ret = -ENODEV;
1613done:
1614 return ret;
1615}
1616
Haynes Mathew George98c95622014-06-20 19:14:25 -07001617int platform_get_snd_device_index(char *device_name)
1618{
1619 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1620}
1621
1622int platform_get_usecase_index(const char *usecase_name)
1623{
1624 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1625}
1626
keunhui.park2f7306a2015-07-16 16:48:06 +09001627void platform_add_operator_specific_device(snd_device_t snd_device,
1628 const char *operator,
1629 const char *mixer_path,
1630 unsigned int acdb_id)
1631{
1632 struct operator_specific_device *device;
1633
1634 if (operator_specific_device_table[snd_device] == NULL) {
1635 operator_specific_device_table[snd_device] =
1636 (struct listnode *)calloc(1, sizeof(struct listnode));
1637 list_init(operator_specific_device_table[snd_device]);
1638 }
1639
1640 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1641
1642 device->operator = strdup(operator);
1643 device->mixer_path = strdup(mixer_path);
1644 device->acdb_id = acdb_id;
1645
1646 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1647
Eric Laurent2bafff12016-03-17 12:17:23 -07001648 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001649 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1650
1651}
1652
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001653int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1654{
1655 int ret = 0;
1656
1657 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1658 ALOGE("%s: Invalid snd_device = %d",
1659 __func__, snd_device);
1660 ret = -EINVAL;
1661 goto done;
1662 }
1663
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001664 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1665 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001666 acdb_device_table[snd_device] = acdb_id;
1667done:
1668 return ret;
1669}
1670
Glenn Kastencbe06ca2016-11-09 10:49:26 -08001671int platform_get_default_app_type_v2(void *platform __unused, usecase_type_t type __unused,
1672 int *app_type __unused)
Yamit Mehtae3b99562016-09-16 22:44:00 +05301673{
1674 ALOGE("%s: Not implemented", __func__);
1675 return -ENOSYS;
1676}
1677
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001678int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1679{
1680 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1681 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1682 return -EINVAL;
1683 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001684
1685 if (operator_specific_device_table[snd_device] != NULL)
1686 return get_operator_specific_device_acdb_id(snd_device);
1687 else
1688 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001689}
1690
David Linee3fe402017-03-13 10:00:42 -07001691static int platform_get_backend_index(snd_device_t snd_device)
1692{
1693 int32_t port = DEFAULT_CODEC_BACKEND;
1694
1695 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1696 if (backend_tag_table[snd_device] != NULL) {
1697 if (strncmp(backend_tag_table[snd_device], "headphones",
1698 sizeof("headphones")) == 0)
1699 port = HEADPHONE_BACKEND;
1700 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1701 port = HDMI_RX_BACKEND;
1702 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1703 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1704 port = USB_AUDIO_RX_BACKEND;
1705 }
1706 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1707 port = DEFAULT_CODEC_TX_BACKEND;
1708 if (backend_tag_table[snd_device] != NULL) {
1709 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1710 port = USB_AUDIO_TX_BACKEND;
1711 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1712 port = BT_SCO_TX_BACKEND;
1713 }
1714 } else {
1715 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1716 }
1717
1718 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1719
1720 return port;
1721}
1722
Eric Laurentb23d5282013-05-14 15:27:20 -07001723int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1724{
1725 struct platform_data *my_data = (struct platform_data *)platform;
1726 int acdb_dev_id, acdb_dev_type;
1727
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001728 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001729 if (acdb_dev_id < 0) {
1730 ALOGE("%s: Could not find acdb id for device(%d)",
1731 __func__, snd_device);
1732 return -EINVAL;
1733 }
1734 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001735 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001736 __func__, snd_device, acdb_dev_id);
1737 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1738 snd_device < SND_DEVICE_OUT_END)
1739 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1740 else
1741 acdb_dev_type = ACDB_DEV_TYPE_IN;
1742 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1743 }
1744 return 0;
1745}
1746
1747int platform_switch_voice_call_device_pre(void *platform)
1748{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001749 struct platform_data *my_data = (struct platform_data *)platform;
1750 int ret = 0;
1751
1752 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001753 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001754 /* This must be called before disabling mixer controls on APQ side */
1755 ret = my_data->csd->disable_device();
1756 if (ret < 0) {
1757 ALOGE("%s: csd_client_disable_device, failed, error %d",
1758 __func__, ret);
1759 }
1760 }
1761 return ret;
1762}
1763
1764int platform_switch_voice_call_enable_device_config(void *platform,
1765 snd_device_t out_snd_device,
1766 snd_device_t in_snd_device)
1767{
1768 struct platform_data *my_data = (struct platform_data *)platform;
1769 int acdb_rx_id, acdb_tx_id;
1770 int ret = 0;
1771
1772 if (my_data->csd == NULL)
1773 return ret;
1774
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001775 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1776 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001777 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001778 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001779 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001780
keunhui.park2f7306a2015-07-16 16:48:06 +09001781 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001782
1783 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1784 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1785 if (ret < 0) {
1786 ALOGE("%s: csd_enable_device_config, failed, error %d",
1787 __func__, ret);
1788 }
1789 } else {
1790 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1791 acdb_rx_id, acdb_tx_id);
1792 }
1793
1794 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001795}
1796
1797int platform_switch_voice_call_device_post(void *platform,
1798 snd_device_t out_snd_device,
1799 snd_device_t in_snd_device)
1800{
1801 struct platform_data *my_data = (struct platform_data *)platform;
1802 int acdb_rx_id, acdb_tx_id;
1803
1804 if (my_data->acdb_send_voice_cal == NULL) {
1805 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1806 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001807 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1808 audio_extn_spkr_prot_is_enabled())
1809 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1810
keunhui.park2f7306a2015-07-16 16:48:06 +09001811 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1812 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001813
1814 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1815 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1816 else
1817 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1818 acdb_rx_id, acdb_tx_id);
1819 }
1820
1821 return 0;
1822}
1823
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001824int platform_switch_voice_call_usecase_route_post(void *platform,
1825 snd_device_t out_snd_device,
1826 snd_device_t in_snd_device)
1827{
1828 struct platform_data *my_data = (struct platform_data *)platform;
1829 int acdb_rx_id, acdb_tx_id;
1830 int ret = 0;
1831
1832 if (my_data->csd == NULL)
1833 return ret;
1834
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001835 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1836 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001837 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001838 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001839 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001840
keunhui.park2f7306a2015-07-16 16:48:06 +09001841 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001842
1843 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1844 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1845 my_data->adev->acdb_settings);
1846 if (ret < 0) {
1847 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1848 }
1849 } else {
1850 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1851 acdb_rx_id, acdb_tx_id);
1852 }
1853
1854 return ret;
1855}
1856
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001857int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001858{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001859 struct platform_data *my_data = (struct platform_data *)platform;
1860 int ret = 0;
1861
1862 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001863 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001864 if (ret < 0) {
1865 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1866 }
1867 }
1868 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001869}
1870
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001871int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001872{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001873 struct platform_data *my_data = (struct platform_data *)platform;
1874 int ret = 0;
1875
1876 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001877 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001878 if (ret < 0) {
1879 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1880 }
1881 }
1882 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001883}
1884
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001885int platform_get_sample_rate(void *platform, uint32_t *rate)
1886{
1887 struct platform_data *my_data = (struct platform_data *)platform;
1888 int ret = 0;
1889
1890 if (my_data->csd != NULL) {
1891 ret = my_data->csd->get_sample_rate(rate);
1892 if (ret < 0) {
1893 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1894 }
1895 }
1896 return ret;
1897}
1898
vivek mehtab6506412015-08-07 16:55:17 -07001899void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1900 snd_device_t snd_device,
1901 bool enable)
1902{
1903 const char* name;
1904 switch (snd_device) {
1905 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1906 if (enable)
1907 name = "spkr-gain-in-headphone-combo";
1908 else
1909 name = "speaker-gain-default";
1910 break;
1911 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1912 if (enable)
1913 name = "spkr-gain-in-line-combo";
1914 else
1915 name = "speaker-gain-default";
1916 break;
1917 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1918 if (enable)
1919 name = "spkr-safe-gain-in-headphone-combo";
1920 else
1921 name = "speaker-safe-gain-default";
1922 break;
1923 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1924 if (enable)
1925 name = "spkr-safe-gain-in-line-combo";
1926 else
1927 name = "speaker-safe-gain-default";
1928 break;
1929 default:
1930 return;
1931 }
1932
1933 audio_route_apply_and_update_path(adev->audio_route, name);
1934}
1935
Eric Laurentb23d5282013-05-14 15:27:20 -07001936int platform_set_voice_volume(void *platform, int volume)
1937{
1938 struct platform_data *my_data = (struct platform_data *)platform;
1939 struct audio_device *adev = my_data->adev;
1940 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001941 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001942 int vol_index = 0, ret = 0;
1943 uint32_t set_values[ ] = {0,
1944 ALL_SESSION_VSID,
1945 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001946
1947 // Voice volume levels are mapped to adsp volume levels as follows.
1948 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1949 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001950 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001951 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001952
1953 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1954 if (!ctl) {
1955 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1956 __func__, mixer_ctl_name);
1957 return -EINVAL;
1958 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001959 ALOGV("Setting voice volume index: %d", set_values[0]);
1960 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1961
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001962 if (my_data->csd != NULL) {
1963 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1964 DEFAULT_VOLUME_RAMP_DURATION_MS);
1965 if (ret < 0) {
1966 ALOGE("%s: csd_volume error %d", __func__, ret);
1967 }
1968 }
1969 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001970}
1971
1972int platform_set_mic_mute(void *platform, bool state)
1973{
1974 struct platform_data *my_data = (struct platform_data *)platform;
1975 struct audio_device *adev = my_data->adev;
1976 struct mixer_ctl *ctl;
1977 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001978 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001979 uint32_t set_values[ ] = {0,
1980 ALL_SESSION_VSID,
1981 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001982
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001983 if (adev->mode != AUDIO_MODE_IN_CALL &&
1984 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001985 return 0;
1986
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001987 if (adev->enable_hfp)
1988 mixer_ctl_name = "HFP Tx Mute";
1989
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001990 set_values[0] = state;
1991 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1992 if (!ctl) {
1993 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1994 __func__, mixer_ctl_name);
1995 return -EINVAL;
1996 }
1997 ALOGV("Setting voice mute state: %d", state);
1998 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1999
2000 if (my_data->csd != NULL) {
2001 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2002 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002003 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002004 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002005 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002006 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002007 return ret;
2008}
Eric Laurentb23d5282013-05-14 15:27:20 -07002009
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002010int platform_set_device_mute(void *platform, bool state, char *dir)
2011{
2012 struct platform_data *my_data = (struct platform_data *)platform;
2013 struct audio_device *adev = my_data->adev;
2014 struct mixer_ctl *ctl;
2015 char *mixer_ctl_name = NULL;
2016 int ret = 0;
2017 uint32_t set_values[ ] = {0,
2018 ALL_SESSION_VSID,
2019 0};
2020 if(dir == NULL) {
2021 ALOGE("%s: Invalid direction:%s", __func__, dir);
2022 return -EINVAL;
2023 }
2024
2025 if (!strncmp("rx", dir, sizeof("rx"))) {
2026 mixer_ctl_name = "Voice Rx Device Mute";
2027 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2028 mixer_ctl_name = "Voice Tx Device Mute";
2029 } else {
2030 return -EINVAL;
2031 }
2032
2033 set_values[0] = state;
2034 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2035 if (!ctl) {
2036 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2037 __func__, mixer_ctl_name);
2038 return -EINVAL;
2039 }
2040
2041 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2042 __func__,state, mixer_ctl_name);
2043 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2044
2045 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002046}
2047
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002048int platform_can_split_snd_device(snd_device_t snd_device,
2049 int *num_devices,
2050 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002051{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002052 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002053 if (NULL == num_devices || NULL == new_snd_devices) {
2054 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002055 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002056 }
2057
2058 /*
2059 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002060 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002061 */
2062 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2063 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2064 *num_devices = 2;
2065 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2066 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002067 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002068 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2069 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2070 *num_devices = 2;
2071 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2072 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002073 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002074 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2075 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2076 *num_devices = 2;
2077 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2078 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002079 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002080 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2081 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2082 *num_devices = 2;
2083 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2084 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002085 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002086 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2087 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2088 SND_DEVICE_OUT_BT_SCO)) {
2089 *num_devices = 2;
2090 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2091 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2092 ret = 0;
2093 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2094 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2095 SND_DEVICE_OUT_BT_SCO_WB)) {
2096 *num_devices = 2;
2097 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2098 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2099 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002100 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2101 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2102 *num_devices = 2;
2103 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2104 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2105 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002106 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002107 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002108}
2109
Eric Laurentb23d5282013-05-14 15:27:20 -07002110snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2111{
2112 struct platform_data *my_data = (struct platform_data *)platform;
2113 struct audio_device *adev = my_data->adev;
2114 audio_mode_t mode = adev->mode;
2115 snd_device_t snd_device = SND_DEVICE_NONE;
2116
2117 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2118 if (devices == AUDIO_DEVICE_NONE ||
2119 devices & AUDIO_DEVICE_BIT_IN) {
2120 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2121 goto exit;
2122 }
2123
Eric Laurent1b491552015-09-15 17:52:41 -07002124 if (popcount(devices) == 2) {
2125 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2126 AUDIO_DEVICE_OUT_SPEAKER) ||
2127 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2128 AUDIO_DEVICE_OUT_SPEAKER)) {
2129 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2130 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2131 AUDIO_DEVICE_OUT_SPEAKER)) {
2132 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2133 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2134 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2135 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2136 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2137 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2138 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2139 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2140 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2141 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2142 AUDIO_DEVICE_OUT_SPEAKER)) {
2143 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002144 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2145 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2146 snd_device = adev->bt_wb_speech_enabled ?
2147 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2148 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
David Linee3fe402017-03-13 10:00:42 -07002149 } else if (devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2150 AUDIO_DEVICE_OUT_SPEAKER)) {
2151 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002152 } else {
2153 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2154 goto exit;
2155 }
2156 if (snd_device != SND_DEVICE_NONE) {
2157 goto exit;
2158 }
2159 }
2160
2161 if (popcount(devices) != 1) {
2162 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2163 goto exit;
2164 }
2165
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302166 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002167 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002168 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2169 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002170 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002171 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002172 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002173 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002174 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002175 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002176 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002177 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002178 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002179 else {
2180 if (devices & AUDIO_DEVICE_OUT_LINE)
2181 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2182 else
2183 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2184 }
vivek mehtaa6b79742017-03-09 15:40:43 -08002185 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2186 if (voice_is_in_call(adev)) {
2187 switch (adev->voice.tty_mode) {
2188 case TTY_MODE_FULL:
2189 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2190 break;
2191 case TTY_MODE_VCO:
2192 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2193 break;
2194 case TTY_MODE_HCO:
2195 // since Hearing will be on handset\speaker, use existing device
2196 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2197 break;
2198 default:
2199 ALOGE("%s: Invalid TTY mode (%#x)",
2200 __func__, adev->voice.tty_mode);
2201 }
2202 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002203 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002204 if (adev->bt_wb_speech_enabled) {
2205 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2206 } else {
2207 snd_device = SND_DEVICE_OUT_BT_SCO;
2208 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002209 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002210 if (!adev->enable_hfp) {
2211 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2212 } else {
2213 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2214 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002215 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002216 if(adev->voice.hac)
2217 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2218 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002219 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2220 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002221 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002222 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2223 snd_device = SND_DEVICE_OUT_VOICE_TX;
2224
Eric Laurentb23d5282013-05-14 15:27:20 -07002225 if (snd_device != SND_DEVICE_NONE) {
2226 goto exit;
2227 }
2228 }
2229
Eric Laurentb23d5282013-05-14 15:27:20 -07002230 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2231 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2232 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002233 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2234 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002235 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2236 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002237 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002238 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002239 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2240 else
2241 snd_device = SND_DEVICE_OUT_SPEAKER;
2242 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002243 if (adev->bt_wb_speech_enabled) {
2244 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2245 } else {
2246 snd_device = SND_DEVICE_OUT_BT_SCO;
2247 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002248 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2249 snd_device = SND_DEVICE_OUT_HDMI ;
David Linee3fe402017-03-13 10:00:42 -07002250 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2251 if (audio_extn_usb_is_capture_supported())
2252 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2253 else
2254 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2255 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002256 /*HAC support for voice-ish audio (eg visual voicemail)*/
2257 if(adev->voice.hac)
2258 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2259 else
2260 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002261 } else {
2262 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2263 }
2264exit:
2265 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2266 return snd_device;
2267}
2268
2269snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2270{
2271 struct platform_data *my_data = (struct platform_data *)platform;
2272 struct audio_device *adev = my_data->adev;
2273 audio_source_t source = (adev->active_input == NULL) ?
2274 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2275
2276 audio_mode_t mode = adev->mode;
2277 audio_devices_t in_device = ((adev->active_input == NULL) ?
2278 AUDIO_DEVICE_NONE : adev->active_input->device)
2279 & ~AUDIO_DEVICE_BIT_IN;
2280 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2281 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2282 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002283 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002284
Prashant Malanic92c5962015-08-11 15:10:18 -07002285 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2286 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002287 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2288 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002289 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002290 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002291 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2292 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002293 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002294 case TTY_MODE_FULL:
2295 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2296 break;
2297 case TTY_MODE_VCO:
2298 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2299 break;
2300 case TTY_MODE_HCO:
2301 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2302 break;
2303 default:
2304 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2305 }
2306 goto exit;
2307 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2308 switch (adev->voice.tty_mode) {
2309 case TTY_MODE_FULL:
2310 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2311 break;
2312 case TTY_MODE_VCO:
2313 // since voice will be captured from handset mic, use existing device
2314 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2315 break;
2316 case TTY_MODE_HCO:
2317 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2318 break;
2319 default:
2320 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002321 }
2322 goto exit;
2323 }
2324 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002325 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002326 if (my_data->fluence_in_voice_call == false) {
2327 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2328 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002329 if (is_operator_tmus())
2330 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002331 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002332 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002333 }
2334 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2335 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2336 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002337 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002338 if (adev->bluetooth_nrec)
2339 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2340 else
2341 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002342 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002343 if (adev->bluetooth_nrec)
2344 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2345 else
2346 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002347 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002348 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002349 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2350 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2351 out_device & AUDIO_DEVICE_OUT_LINE) {
2352 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2353 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2354 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2355 } else {
2356 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2357 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002358 }
vivek mehtafe121d52015-08-10 23:39:23 -07002359
2360 //select default
2361 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002362 if (!adev->enable_hfp) {
2363 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2364 } else {
2365 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2366 platform_set_echo_reference(adev, true, out_device);
2367 }
vivek mehtafe121d52015-08-10 23:39:23 -07002368 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002369 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002370 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002371 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002372 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2373 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2374 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2375 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2376 }
2377 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2378 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002379 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2380 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2381 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002382 if (adev->active_input->enable_aec)
2383 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2384 else
2385 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002386 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2387 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002388 if (adev->active_input->enable_aec)
2389 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2390 else
2391 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002392 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2393 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2394 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002395 if (adev->active_input->enable_aec)
2396 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2397 else
2398 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002399 }
2400 platform_set_echo_reference(adev, true, out_device);
2401 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2402 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2403 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002404 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002405 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2406 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002407 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002408 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2409 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002410 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002411 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002412 if (adev->active_input->enable_aec) {
2413 if (adev->active_input->enable_ns) {
2414 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2415 } else {
2416 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2417 }
vivek mehta733c1df2016-04-04 15:09:24 -07002418 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002419 } else if (adev->active_input->enable_ns) {
2420 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2421 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002422 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002423 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002424 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002425 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2426 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002427 }
rago90fb9612015-12-02 11:37:53 -08002428 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2429 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002430 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2431 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2432 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2433 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002434 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002435 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2436 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002437 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002438 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2439 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2440 } else {
2441 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2442 }
rago90fb9612015-12-02 11:37:53 -08002443 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2444 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2445 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002446 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002447 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002448 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002449 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2450 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002451 if (adev->active_input->enable_aec &&
2452 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002453 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002454 if (my_data->fluence_in_spkr_mode &&
2455 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002456 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002457 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002458 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002459 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002460 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002461 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002462 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002463 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002464 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002465 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002466 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002467 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002468 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2469 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002470 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002471 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002472 } else if (adev->active_input->enable_aec) {
2473 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2474 if (my_data->fluence_in_spkr_mode &&
2475 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002476 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002477 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002478 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002479 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002480 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002481 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2482 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002483 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002484 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002485 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002486 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002487 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002488 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2489 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2490 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002491 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002492 } else if (adev->active_input->enable_ns) {
2493 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2494 if (my_data->fluence_in_spkr_mode &&
2495 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002496 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002497 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002498 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002499 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002500 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002501 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2502 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002503 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002504 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002505 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002506 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002507 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002508 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002509 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002510 }
2511 } else if (source == AUDIO_SOURCE_DEFAULT) {
2512 goto exit;
2513 }
2514
2515
2516 if (snd_device != SND_DEVICE_NONE) {
2517 goto exit;
2518 }
2519
2520 if (in_device != AUDIO_DEVICE_NONE &&
2521 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2522 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2523 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002524 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002525 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002526 snd_device = SND_DEVICE_IN_QUAD_MIC;
2527 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002528 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002529 snd_device = SND_DEVICE_IN_THREE_MIC;
2530 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2531 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002532 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002533 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2534 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002535 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002536 } else {
2537 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2538 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2539 my_data->source_mic_type, channel_count, channel_mask);
2540 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2541 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002542 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002543 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2544 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002545 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002546 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2547 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002548 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002549 } else {
2550 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2551 " no combination found .. setting to mono", __func__,
2552 my_data->source_mic_type, channel_count);
2553 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2554 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002555 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2556 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2557 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002558 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002559 if (adev->bluetooth_nrec)
2560 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2561 else
2562 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002563 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002564 if (adev->bluetooth_nrec)
2565 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2566 else
2567 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002568 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002569 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2570 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002571 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE ) {
2572 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002573 } else {
2574 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2575 ALOGW("%s: Using default handset-mic", __func__);
2576 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2577 }
2578 } else {
2579 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2580 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2581 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2582 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002583 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002584 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002585 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002586 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002587 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2588 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002589 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002590 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2591 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002592 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002593 } else {
2594 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2595 " no combination found .. setting to mono", __func__,
2596 my_data->source_mic_type, channel_count);
2597 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2598 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002599 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002600 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002601 if (adev->bluetooth_nrec)
2602 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2603 else
2604 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002605 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002606 if (adev->bluetooth_nrec)
2607 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2608 else
2609 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002610 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002611 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2612 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002613 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2614 if (audio_extn_usb_is_capture_supported())
2615 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2616 else
2617 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002618 } else {
2619 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2620 ALOGW("%s: Using default handset-mic", __func__);
2621 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2622 }
2623 }
2624exit:
2625 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2626 return snd_device;
2627}
2628
2629int platform_set_hdmi_channels(void *platform, int channel_count)
2630{
2631 struct platform_data *my_data = (struct platform_data *)platform;
2632 struct audio_device *adev = my_data->adev;
2633 struct mixer_ctl *ctl;
2634 const char *channel_cnt_str = NULL;
2635 const char *mixer_ctl_name = "HDMI_RX Channels";
2636 switch (channel_count) {
2637 case 8:
2638 channel_cnt_str = "Eight"; break;
2639 case 7:
2640 channel_cnt_str = "Seven"; break;
2641 case 6:
2642 channel_cnt_str = "Six"; break;
2643 case 5:
2644 channel_cnt_str = "Five"; break;
2645 case 4:
2646 channel_cnt_str = "Four"; break;
2647 case 3:
2648 channel_cnt_str = "Three"; break;
2649 default:
2650 channel_cnt_str = "Two"; break;
2651 }
2652 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2653 if (!ctl) {
2654 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2655 __func__, mixer_ctl_name);
2656 return -EINVAL;
2657 }
2658 ALOGV("HDMI channel count: %s", channel_cnt_str);
2659 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2660 return 0;
2661}
2662
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002663int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002664{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002665 struct platform_data *my_data = (struct platform_data *)platform;
2666 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002667 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2668 char *sad = block;
2669 int num_audio_blocks;
2670 int channel_count;
2671 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002672 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002673
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002674 struct mixer_ctl *ctl;
2675
2676 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2677 if (!ctl) {
2678 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2679 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002680 return 0;
2681 }
2682
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002683 mixer_ctl_update(ctl);
2684
2685 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002686
2687 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002688 if (count > (int)sizeof(block))
2689 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002690
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002691 ret = mixer_ctl_get_array(ctl, block, count);
2692 if (ret != 0) {
2693 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2694 return 0;
2695 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002696
2697 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002698 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002699
2700 for (i = 0; i < num_audio_blocks; i++) {
2701 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002702 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2703 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002704 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002705 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002706
2707 channel_count = (sad[0] & 0x7) + 1;
2708 if (channel_count > max_channels)
2709 max_channels = channel_count;
2710
2711 /* Advance to next block */
2712 sad += 3;
2713 }
2714
2715 return max_channels;
2716}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002717
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002718int platform_set_incall_recording_session_id(void *platform,
2719 uint32_t session_id, int rec_mode)
2720{
2721 int ret = 0;
2722 struct platform_data *my_data = (struct platform_data *)platform;
2723 struct audio_device *adev = my_data->adev;
2724 struct mixer_ctl *ctl;
2725 const char *mixer_ctl_name = "Voc VSID";
2726 int num_ctl_values;
2727 int i;
2728
2729 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2730 if (!ctl) {
2731 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2732 __func__, mixer_ctl_name);
2733 ret = -EINVAL;
2734 } else {
2735 num_ctl_values = mixer_ctl_get_num_values(ctl);
2736 for (i = 0; i < num_ctl_values; i++) {
2737 if (mixer_ctl_set_value(ctl, i, session_id)) {
2738 ALOGV("Error: invalid session_id: %x", session_id);
2739 ret = -EINVAL;
2740 break;
2741 }
2742 }
2743 }
2744
2745 if (my_data->csd != NULL) {
2746 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2747 if (ret < 0) {
2748 ALOGE("%s: csd_client_start_record failed, error %d",
2749 __func__, ret);
2750 }
2751 }
2752
2753 return ret;
2754}
2755
2756int platform_stop_incall_recording_usecase(void *platform)
2757{
2758 int ret = 0;
2759 struct platform_data *my_data = (struct platform_data *)platform;
2760
2761 if (my_data->csd != NULL) {
2762 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2763 if (ret < 0) {
2764 ALOGE("%s: csd_client_stop_record failed, error %d",
2765 __func__, ret);
2766 }
2767 }
2768
2769 return ret;
2770}
2771
2772int platform_start_incall_music_usecase(void *platform)
2773{
2774 int ret = 0;
2775 struct platform_data *my_data = (struct platform_data *)platform;
2776
2777 if (my_data->csd != NULL) {
2778 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2779 if (ret < 0) {
2780 ALOGE("%s: csd_client_start_playback failed, error %d",
2781 __func__, ret);
2782 }
2783 }
2784
2785 return ret;
2786}
2787
2788int platform_stop_incall_music_usecase(void *platform)
2789{
2790 int ret = 0;
2791 struct platform_data *my_data = (struct platform_data *)platform;
2792
2793 if (my_data->csd != NULL) {
2794 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2795 if (ret < 0) {
2796 ALOGE("%s: csd_client_stop_playback failed, error %d",
2797 __func__, ret);
2798 }
2799 }
2800
2801 return ret;
2802}
2803
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002804int platform_set_parameters(void *platform, struct str_parms *parms)
2805{
2806 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002807 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002808 char *kv_pairs = str_parms_to_str(parms);
2809 int ret = 0, err;
2810
2811 if (kv_pairs == NULL) {
2812 ret = -EINVAL;
2813 ALOGE("%s: key-value pair is NULL",__func__);
2814 goto done;
2815 }
2816
2817 ALOGV("%s: enter: %s", __func__, kv_pairs);
2818
2819 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2820 value, sizeof(value));
2821 if (err >= 0) {
2822 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2823 my_data->snd_card_name = strdup(value);
2824 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2825 }
2826
keunhui.park2f7306a2015-07-16 16:48:06 +09002827 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2828 value, sizeof(value));
2829 if (err >= 0) {
2830 struct operator_info *info;
2831 char *str = value;
2832 char *name;
2833
2834 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2835 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2836 name = strtok(str, ";");
2837 info->name = strdup(name);
2838 info->mccmnc = strdup(str + strlen(name) + 1);
2839
2840 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002841 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002842 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002843
2844 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002845 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002846 value, sizeof(value));
2847 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002848 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002849 my_data->max_mic_count = atoi(value);
2850 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002851 }
2852
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002853done:
2854 ALOGV("%s: exit with code(%d)", __func__, ret);
2855 if (kv_pairs != NULL)
2856 free(kv_pairs);
2857
2858 return ret;
2859}
2860
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002861/* Delay in Us */
2862int64_t platform_render_latency(audio_usecase_t usecase)
2863{
2864 switch (usecase) {
2865 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2866 return DEEP_BUFFER_PLATFORM_DELAY;
2867 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2868 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002869 case USECASE_AUDIO_PLAYBACK_ULL:
2870 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08002871 case USECASE_AUDIO_PLAYBACK_MMAP:
2872 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002873 default:
2874 return 0;
2875 }
2876}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002877
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002878int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2879 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002880{
2881 int ret = 0;
2882
2883 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2884 ALOGE("%s: Invalid snd_device = %d",
2885 __func__, device);
2886 ret = -EINVAL;
2887 goto done;
2888 }
2889
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002890 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2891 platform_get_snd_device_name(device),
2892 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2893 if (backend_tag_table[device]) {
2894 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002895 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002896 backend_tag_table[device] = strdup(backend_tag);
2897
2898 if (hw_interface != NULL) {
2899 if (hw_interface_table[device])
2900 free(hw_interface_table[device]);
2901 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2902 hw_interface_table[device] = strdup(hw_interface);
2903 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002904done:
2905 return ret;
2906}
2907
2908int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2909{
2910 int ret = 0;
2911 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2912 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2913 ret = -EINVAL;
2914 goto done;
2915 }
2916
2917 if ((type != 0) && (type != 1)) {
2918 ALOGE("%s: invalid usecase type", __func__);
2919 ret = -EINVAL;
2920 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002921 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002922 pcm_device_table[usecase][type] = pcm_id;
2923done:
2924 return ret;
2925}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002926
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002927#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2928int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2929 // backup_gain: gain to try to set in case of an error during ramp
2930 int start_gain, end_gain, step, backup_gain, i;
2931 bool error = false;
2932 const struct mixer_ctl *ctl;
2933 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2934 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2935 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2936 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2937 if (!ctl_left || !ctl_right) {
2938 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2939 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2940 return -EINVAL;
2941 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2942 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2943 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2944 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2945 return -EINVAL;
2946 }
2947 if (ramp_up) {
2948 start_gain = 0;
2949 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2950 step = +1;
2951 backup_gain = end_gain;
2952 } else {
2953 // using same gain on left and right
2954 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2955 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2956 end_gain = 0;
2957 step = -1;
2958 backup_gain = start_gain;
2959 }
2960 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2961 //ALOGV("setting speaker gain to %d", i);
2962 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2963 ALOGE("%s: error setting %s to %d during gain ramp",
2964 __func__, mixer_ctl_name_gain_left, i);
2965 error = true;
2966 break;
2967 }
2968 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2969 ALOGE("%s: error setting %s to %d during gain ramp",
2970 __func__, mixer_ctl_name_gain_right, i);
2971 error = true;
2972 break;
2973 }
2974 usleep(1000);
2975 }
2976 if (error) {
2977 // an error occured during the ramp, let's still try to go back to a safe volume
2978 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2979 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2980 }
2981 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2982 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2983 }
2984 }
2985 return start_gain;
2986}
2987
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002988int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2989{
2990 // only update if there is active pcm playback on speaker
2991 struct audio_usecase *usecase;
2992 struct listnode *node;
2993 struct platform_data *my_data = (struct platform_data *)adev->platform;
2994
2995 if (my_data->speaker_lr_swap != swap_channels) {
Jean-Michel Trivif7148702016-09-16 18:23:05 -07002996
2997 // do not swap channels in audio modes with concurrent capture and playback
2998 // as this may break the echo reference
2999 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3000 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3001 return 0;
3002 }
3003
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003004 my_data->speaker_lr_swap = swap_channels;
3005
3006 list_for_each(node, &adev->usecase_list) {
3007 usecase = node_to_item(node, struct audio_usecase, list);
3008 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003009 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3010 /*
3011 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3012 * to perform device switch to disable the current backend to
3013 * enable it with new acdb data.
3014 */
3015 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3016 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003017 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003018 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003019 if (initial_skpr_gain != -EINVAL) {
3020 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3021 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003022 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003023 const char *mixer_path;
3024 if (swap_channels) {
3025 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3026 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3027 } else {
3028 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3029 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3030 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003031 }
3032 break;
3033 }
3034 }
3035 }
3036 return 0;
3037}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003038
3039static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3040static int num_gain_tbl_entry = 0;
3041
3042bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3043
3044 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3045 if (num_gain_tbl_entry == -1) {
3046 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3047 __func__);
3048 return false;
3049 }
3050
3051 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3052 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3053 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3054 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3055 return false;
3056 }
3057
3058 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3059 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3060 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3061 return false;
3062 }
3063
3064 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3065 ++num_gain_tbl_entry;
3066
3067 return true;
3068}
3069
3070int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3071 int table_size) {
3072 int itt = 0;
3073 ALOGV("platform_get_gain_level_mapping called ");
3074
3075 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3076 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3077 return 0;
3078 }
3079
3080 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3081 mapping_tbl[itt] = tbl_mapping[itt];
3082 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3083 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3084 }
3085
3086 return num_gain_tbl_entry;
3087}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003088
3089int platform_snd_card_update(void *platform, card_status_t status)
3090{
3091 struct platform_data *my_data = (struct platform_data *)platform;
3092 struct audio_device *adev = my_data->adev;
3093
3094 if (status == CARD_STATUS_ONLINE) {
3095 if (my_data->acdb_send_custom_top)
3096 my_data->acdb_send_custom_top();
3097 }
3098 return 0;
3099}
David Linee3fe402017-03-13 10:00:42 -07003100
3101/*
3102 * configures afe with bit width and Sample Rate
3103 */
3104static int platform_set_backend_cfg(const struct audio_device* adev,
3105 snd_device_t snd_device,
3106 const struct audio_backend_cfg *backend_cfg)
3107{
3108
3109 int ret = 0;
3110 const int backend_idx = platform_get_backend_index(snd_device);
3111 struct platform_data *my_data = (struct platform_data *)adev->platform;
3112 const unsigned int bit_width = backend_cfg->bit_width;
3113 const unsigned int sample_rate = backend_cfg->sample_rate;
3114 const unsigned int channels = backend_cfg->channels;
3115 const audio_format_t format = backend_cfg->format;
3116 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3117
3118
3119 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3120 ", backend_idx %d device (%s)", __func__, bit_width,
3121 sample_rate, channels, backend_idx,
3122 platform_get_snd_device_name(snd_device));
3123
3124 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3125 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3126
3127 struct mixer_ctl *ctl = NULL;
3128 ctl = mixer_get_ctl_by_name(adev->mixer,
3129 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3130 if (!ctl) {
3131 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3132 __func__,
3133 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3134 return -EINVAL;
3135 }
3136
3137 if (bit_width == 24) {
3138 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3139 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3140 else
3141 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3142 } else if (bit_width == 32) {
3143 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3144 } else {
3145 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3146 }
3147 if ( ret < 0) {
3148 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3149 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3150 } else {
3151 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3152 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3153 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3154 }
3155 /* set the ret as 0 and not pass back to upper layer */
3156 ret = 0;
3157 }
3158
3159 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3160 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3161 char *rate_str = NULL;
3162 struct mixer_ctl *ctl = NULL;
3163
3164 switch (sample_rate) {
3165 case 32000:
3166 if (passthrough_enabled) {
3167 rate_str = "KHZ_32";
3168 break;
3169 }
3170 case 8000:
3171 case 11025:
3172 case 16000:
3173 case 22050:
3174 case 48000:
3175 rate_str = "KHZ_48";
3176 break;
3177 case 44100:
3178 rate_str = "KHZ_44P1";
3179 break;
3180 case 64000:
3181 case 96000:
3182 rate_str = "KHZ_96";
3183 break;
3184 case 88200:
3185 rate_str = "KHZ_88P2";
3186 break;
3187 case 176400:
3188 rate_str = "KHZ_176P4";
3189 break;
3190 case 192000:
3191 rate_str = "KHZ_192";
3192 break;
3193 case 352800:
3194 rate_str = "KHZ_352P8";
3195 break;
3196 case 384000:
3197 rate_str = "KHZ_384";
3198 break;
3199 case 144000:
3200 if (passthrough_enabled) {
3201 rate_str = "KHZ_144";
3202 break;
3203 }
3204 default:
3205 rate_str = "KHZ_48";
3206 break;
3207 }
3208
3209 ctl = mixer_get_ctl_by_name(adev->mixer,
3210 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3211 if(!ctl) {
3212 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3213 __func__,
3214 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3215 return -EINVAL;
3216 }
3217
3218 ALOGD("%s:becf: afe: %s set to %s", __func__,
3219 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3220 mixer_ctl_set_enum_by_string(ctl, rate_str);
3221 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3222 }
3223 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3224 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3225 struct mixer_ctl *ctl = NULL;
3226 char *channel_cnt_str = NULL;
3227
3228 switch (channels) {
3229 case 8:
3230 channel_cnt_str = "Eight"; break;
3231 case 7:
3232 channel_cnt_str = "Seven"; break;
3233 case 6:
3234 channel_cnt_str = "Six"; break;
3235 case 5:
3236 channel_cnt_str = "Five"; break;
3237 case 4:
3238 channel_cnt_str = "Four"; break;
3239 case 3:
3240 channel_cnt_str = "Three"; break;
3241 case 1:
3242 channel_cnt_str = "One"; break;
3243 case 2:
3244 default:
3245 channel_cnt_str = "Two"; break;
3246 }
3247
3248 ctl = mixer_get_ctl_by_name(adev->mixer,
3249 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3250 if (!ctl) {
3251 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3252 __func__,
3253 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3254 return -EINVAL;
3255 }
3256 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3257 my_data->current_backend_cfg[backend_idx].channels = channels;
3258
3259 // skip EDID configuration for HDMI backend
3260
3261 ALOGD("%s:becf: afe: %s set to %s", __func__,
3262 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3263 channel_cnt_str);
3264 }
3265
3266 // skip set ext_display format mixer control
3267 return ret;
3268}
3269
3270static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3271{
3272 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3273 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3274 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3275 }
3276
3277 return backend_bit_width_table[snd_device];
3278}
3279
3280/*
3281 * return backend_idx on which voice call is active
3282 */
3283static int platform_get_voice_call_backend(struct audio_device* adev)
3284{
3285 struct audio_usecase *uc = NULL;
3286 struct listnode *node;
3287 snd_device_t out_snd_device = SND_DEVICE_NONE;
3288
3289 int backend_idx = -1;
3290
3291 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3292 list_for_each(node, &adev->usecase_list) {
3293 uc = node_to_item(node, struct audio_usecase, list);
3294 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3295 out_snd_device = platform_get_output_snd_device(adev->platform,
3296 uc->stream.out->devices);
3297 backend_idx = platform_get_backend_index(out_snd_device);
3298 break;
3299 }
3300 }
3301 }
3302 return backend_idx;
3303}
3304
3305/*
3306 * goes through all the current usecases and picks the highest
3307 * bitwidth & samplerate
3308 */
3309static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3310 int backend_idx,
3311 struct audio_backend_cfg *backend_cfg)
3312{
3313 bool backend_change = false;
3314 unsigned int bit_width;
3315 unsigned int sample_rate;
3316 unsigned int channels;
3317 struct platform_data *my_data = (struct platform_data *)adev->platform;
3318
3319 bit_width = backend_cfg->bit_width;
3320 sample_rate = backend_cfg->sample_rate;
3321 channels = backend_cfg->channels;
3322
3323 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3324 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3325 sample_rate, channels);
3326
3327 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3328 // default backend
3329 // force routing is not required here, caller will do it anyway
3330 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3331 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3332 "for unprocessed/camera source", __func__);
3333 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3334 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3335 }
3336
3337 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3338 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3339 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3340 __func__, bit_width, sample_rate, channels);
3341 }
3342
3343 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3344 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3345
3346 // Force routing if the expected bitwdith or samplerate
3347 // is not same as current backend comfiguration
3348 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3349 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3350 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3351 backend_cfg->bit_width = bit_width;
3352 backend_cfg->sample_rate= sample_rate;
3353 backend_cfg->channels = channels;
3354 backend_change = true;
3355 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3356 "new sample rate: %d new channel: %d",
3357 __func__, backend_cfg->bit_width,
3358 backend_cfg->sample_rate, backend_cfg->channels);
3359 }
3360
3361 return backend_change;
3362}
3363
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003364static void platform_pick_playback_cfg_for_uc(struct audio_device *adev,
3365 struct audio_usecase *usecase,
3366 snd_device_t snd_device,
3367 unsigned int *bit_width,
3368 unsigned int *sample_rate,
3369 unsigned int *channels)
3370{
3371 int i =0;
3372 struct listnode *node;
3373 list_for_each(node, &adev->usecase_list) {
3374 struct audio_usecase *uc;
3375 uc = node_to_item(node, struct audio_usecase, list);
3376 struct stream_out *out = (struct stream_out*) uc->stream.out;
3377 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3378 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3379 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3380 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3381 uc->id, out->sample_rate,
3382 pcm_format_to_bits(out->config.format), out_channels,
3383 platform_get_snd_device_name(uc->out_snd_device));
3384
3385 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3386 if (*bit_width < pcm_format_to_bits(out->config.format))
3387 *bit_width = pcm_format_to_bits(out->config.format);
3388 if (*sample_rate < out->sample_rate)
3389 *sample_rate = out->sample_rate;
3390 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3391 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3392 if (*channels < out_channels)
3393 *channels = out_channels;
3394 }
3395 }
3396 }
3397 return;
3398}
3399
David Linee3fe402017-03-13 10:00:42 -07003400static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3401 struct audio_usecase* usecase,
3402 snd_device_t snd_device,
3403 struct audio_backend_cfg *backend_cfg)
3404{
3405 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003406 unsigned int bit_width;
3407 unsigned int sample_rate;
3408 unsigned int channels;
3409 bool passthrough_enabled = false;
3410 int backend_idx = DEFAULT_CODEC_BACKEND;
3411 struct platform_data *my_data = (struct platform_data *)adev->platform;
3412 bool channels_updated = false;
3413
3414 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3415 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3416 backend_change = false;
3417 return backend_change;
3418 }
3419
3420 backend_idx = platform_get_backend_index(snd_device);
3421 bit_width = backend_cfg->bit_width;
3422 sample_rate = backend_cfg->sample_rate;
3423 channels = backend_cfg->channels;
3424
3425 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3426 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3427 sample_rate, channels, backend_idx, usecase->id,
3428 platform_get_snd_device_name(snd_device));
3429
3430 if (backend_idx == platform_get_voice_call_backend(adev)) {
3431 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3432 __func__);
3433 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3434 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3435 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3436 } else {
3437 /*
3438 * The backend should be configured at highest bit width and/or
3439 * sample rate amongst all playback usecases.
3440 * If the selected sample rate and/or bit width differ with
3441 * current backend sample rate and/or bit width, then, we set the
3442 * backend re-configuration flag.
3443 *
3444 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3445 */
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003446 platform_pick_playback_cfg_for_uc(adev, usecase, snd_device,
3447 &bit_width,
3448 &sample_rate,
3449 &channels);
David Linee3fe402017-03-13 10:00:42 -07003450 }
3451
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003452 switch (backend_idx) {
3453 case USB_AUDIO_RX_BACKEND:
3454 audio_extn_usb_is_config_supported(&bit_width,
3455 &sample_rate, &channels, true);
3456 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3457 __func__, bit_width, sample_rate, channels);
3458 break;
3459 case DEFAULT_CODEC_BACKEND:
3460 case HEADPHONE_BACKEND:
3461 default:
3462 bit_width = platform_get_snd_device_bit_width(snd_device);
3463 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3464 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3465 break;
David Linee3fe402017-03-13 10:00:42 -07003466 }
3467
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003468 if (channels != my_data->current_backend_cfg[backend_idx].channels) {
3469 channels_updated = true;
David Linee3fe402017-03-13 10:00:42 -07003470 }
3471
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003472 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3473 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003474 __func__, backend_idx , bit_width, sample_rate);
3475
3476 // Force routing if the expected bitwdith or samplerate
3477 // is not same as current backend comfiguration
3478 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3479 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3480 passthrough_enabled || channels_updated) {
3481 backend_cfg->bit_width = bit_width;
3482 backend_cfg->sample_rate = sample_rate;
3483 backend_cfg->channels = channels;
3484 backend_cfg->passthrough_enabled = passthrough_enabled;
3485 backend_change = true;
3486 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3487 "new sample rate: %d new channels: %d",
3488 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3489 }
3490
3491 return backend_change;
3492}
3493
3494bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3495 struct audio_usecase *usecase, snd_device_t snd_device)
3496{
3497 int backend_idx = DEFAULT_CODEC_BACKEND;
3498 int new_snd_devices[SND_DEVICE_OUT_END];
3499 int i, num_devices = 1;
3500 bool ret = false;
3501 struct platform_data *my_data = (struct platform_data *)adev->platform;
3502 struct audio_backend_cfg backend_cfg;
3503
3504 backend_idx = platform_get_backend_index(snd_device);
3505
3506 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3507 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3508 backend_cfg.format = usecase->stream.out->format;
3509 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3510 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3511 backend_cfg.passthrough_enabled = false;
3512
3513 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3514 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3515 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3516 platform_get_snd_device_name(snd_device));
3517
3518 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3519 new_snd_devices[0] = snd_device;
3520
3521 for (i = 0; i < num_devices; i++) {
3522 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3523 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3524 &backend_cfg))) {
3525 platform_set_backend_cfg(adev, new_snd_devices[i],
3526 &backend_cfg);
3527 ret = true;
3528 }
3529 }
3530 return ret;
3531}
3532
3533bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3534 struct audio_usecase *usecase, snd_device_t snd_device)
3535{
3536 int backend_idx = platform_get_backend_index(snd_device);
3537 int ret = 0;
3538 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003539 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003540
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003541 if (usecase->type == PCM_CAPTURE) {
3542 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003543 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3544 } else {
3545 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3546 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3547 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3548 backend_cfg.channels = 1;
3549 }
3550
3551 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3552 ", backend_idx %d usecase = %d device (%s)", __func__,
3553 backend_cfg.bit_width,
3554 backend_cfg.sample_rate,
3555 backend_cfg.channels,
3556 backend_idx, usecase->id,
3557 platform_get_snd_device_name(snd_device));
3558
3559 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3560 ret = platform_set_backend_cfg(adev, snd_device,
3561 &backend_cfg);
3562 if(!ret)
3563 return true;
3564 }
3565
3566 return false;
3567}
3568