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