blob: 72f993717b31254c46c8d7fbf7c2972d73e45c5f [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>
vivek mehta0fb11312017-05-15 19:35:32 -070027#include "acdb.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070028#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070029#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070030#include <linux/msm_audio.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070031
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090032#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
33#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080034#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
35#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
36
Eric Laurentb23d5282013-05-14 15:27:20 -070037#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070038#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090039#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070040
Eric Laurentf9583c32016-03-28 13:50:50 -070041#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070042
43/*
Eric Laurentb23d5282013-05-14 15:27:20 -070044 * This file will have a maximum of 38 bytes:
45 *
46 * 4 bytes: number of audio blocks
47 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
48 * Maximum 10 * 3 bytes: SAD blocks
49 */
50#define MAX_SAD_BLOCKS 10
51#define SAD_BLOCK_SIZE 3
52
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090053#define MAX_CVD_VERSION_STRING_SIZE 100
54
Eric Laurentb23d5282013-05-14 15:27:20 -070055/* EDID format ID for LPCM audio */
56#define EDID_FORMAT_LPCM 1
57
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070058#define MAX_SND_CARD_NAME_LEN 31
59
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080060#define DEFAULT_APP_TYPE_RX_PATH 69936
61#define DEFAULT_APP_TYPE_TX_PATH 69938
vivek mehta1a9b7c02015-06-25 11:49:38 -070062
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090063#define TOSTRING_(x) #x
64#define TOSTRING(x) TOSTRING_(x)
65
Eric Laurentb23d5282013-05-14 15:27:20 -070066struct audio_block_header
67{
68 int reserved;
69 int length;
70};
71
vivek mehta1a9b7c02015-06-25 11:49:38 -070072enum {
73 CAL_MODE_SEND = 0x1,
74 CAL_MODE_PERSIST = 0x2,
75 CAL_MODE_RTAC = 0x4
76};
77
keunhui.park2f7306a2015-07-16 16:48:06 +090078#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
79
80struct operator_info {
81 struct listnode list;
82 char *name;
83 char *mccmnc;
84};
85
86struct operator_specific_device {
87 struct listnode list;
88 char *operator;
89 char *mixer_path;
90 int acdb_id;
91};
92
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080093#define BE_DAI_NAME_MAX_LENGTH 24
94struct be_dai_name_struct {
95 unsigned int be_id;
96 char be_name[BE_DAI_NAME_MAX_LENGTH];
97};
98
keunhui.park2f7306a2015-07-16 16:48:06 +090099static struct listnode operator_info_list;
100static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
101
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700102/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800103typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700104
Eric Laurentb23d5282013-05-14 15:27:20 -0700105struct platform_data {
106 struct audio_device *adev;
107 bool fluence_in_spkr_mode;
108 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700109 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700110 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700111 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
112 int fluence_type;
113 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700114 bool speaker_lr_swap;
115
Eric Laurentb23d5282013-05-14 15:27:20 -0700116 void *acdb_handle;
Thierry Strudel92232b42017-01-26 10:51:48 -0800117#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700118 acdb_init_v2_cvd_t acdb_init;
119#elif defined (PLATFORM_MSM8084)
120 acdb_init_v2_t acdb_init;
121#else
122 acdb_init_t acdb_init;
123#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700124 acdb_deallocate_t acdb_deallocate;
125 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800126 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700127 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700128 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700129 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700130 acdb_send_custom_top_t acdb_send_custom_top;
131 bool acdb_initialized;
132
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700133 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800134 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700135
David Linee3fe402017-03-13 10:00:42 -0700136 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700137 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900138 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700139 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800140
141 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700142};
143
Haynes Mathew George98c95622014-06-20 19:14:25 -0700144static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700145 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
146 DEEP_BUFFER_PCM_DEVICE},
147 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
148 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800149 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700150 MULTIMEDIA2_PCM_DEVICE},
151 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
152 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700153 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
154 MULTIMEDIA2_PCM_DEVICE},
155 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
156 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800157 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
158 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700159
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700160 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
161 AUDIO_RECORD_PCM_DEVICE},
162 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
163 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700164
Eric Laurent0e46adf2016-12-16 12:49:24 -0800165 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
166 MMAP_RECORD_PCM_DEVICE},
167
Haynes Mathew George569b7482017-05-08 14:44:27 -0700168 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
169 MULTIMEDIA2_PCM_DEVICE},
170
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700171 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
172 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700173 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
174 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
175 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
176 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800177 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
178 VOICEMMODE1_CALL_PCM_DEVICE},
179 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
180 VOICEMMODE2_CALL_PCM_DEVICE},
181
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700182 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
183 AUDIO_RECORD_PCM_DEVICE},
184 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
185 AUDIO_RECORD_PCM_DEVICE},
186 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
187 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800188 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700189
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700190 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
191 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
192
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700193 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
194 AFE_PROXY_RECORD_PCM_DEVICE},
195 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
196 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800197 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700198
vivek mehtaa68fea62017-06-08 19:04:02 -0700199 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
200 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
201 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
202 AUDIO_RECORD_VOIP_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700203};
204
205/* Array to store sound devices */
206static const char * const device_table[SND_DEVICE_MAX] = {
207 [SND_DEVICE_NONE] = "none",
208 /* Playback sound devices */
209 [SND_DEVICE_OUT_HANDSET] = "handset",
210 [SND_DEVICE_OUT_SPEAKER] = "speaker",
211 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700212 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700213 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500214 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700215 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700216 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500217 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700218 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700219 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500220 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700221 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
222 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500223 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700224 [SND_DEVICE_OUT_HDMI] = "hdmi",
225 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
226 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700227 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700228 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
229 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
230 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
231 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800232 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
233 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700234 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700235 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700236 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700237 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700238 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700239 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700240 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
241 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700242 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800243 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
244 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700245
246 /* Capture sound devices */
247 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700248 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700249 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
250 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
251 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
252 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
253 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
254 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
255 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
256
257 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
258 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
259 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
260 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
261 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
262 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
263 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
264 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
265 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
266
267 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500268 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700269
Eric Laurentb23d5282013-05-14 15:27:20 -0700270 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
271 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700272 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700273 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700274 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700275 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700276
277 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
278 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
279 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
280 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700281 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700282 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700283 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
284 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
285 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800286 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
287 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700288
Eric Laurentb23d5282013-05-14 15:27:20 -0700289 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700290 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700291 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700292 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700293 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
294 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700295 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700296 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
297 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
298 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
299 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700300 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700301
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700302 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700303 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
304 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
305 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
306 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800307
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700308 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700309
Prashant Malanic92c5962015-08-11 15:10:18 -0700310 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
311 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700312 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700313 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
314 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700315 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
316 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700317};
318
319/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700320static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700321 [SND_DEVICE_NONE] = -1,
322 [SND_DEVICE_OUT_HANDSET] = 7,
323 [SND_DEVICE_OUT_SPEAKER] = 15,
324 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700325 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700326 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500327 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700328 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700329 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500330 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700331 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700332 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
333 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500334 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700335 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500336 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700337 [SND_DEVICE_OUT_HDMI] = 18,
338 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
339 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700340 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700341 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700342 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
343 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
344 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800345 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
346 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700347 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700348 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700349 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700350 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700351 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700352 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700353 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
354 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700355 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700356
357 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700358 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
359 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
360 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
361 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
362 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
363 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
364 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
365 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
366
367 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
368 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
369 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
370 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
371 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
372 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
373 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
374 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
375 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
376
rago90fb9612015-12-02 11:37:53 -0800377 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500378 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700379
Eric Laurentb23d5282013-05-14 15:27:20 -0700380 [SND_DEVICE_IN_HDMI_MIC] = 4,
381 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700382 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700383 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700384 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700385 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700386
387 [SND_DEVICE_IN_VOICE_DMIC] = 41,
388 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
389 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700390 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700391 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800392 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700393 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
394 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
395 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800396 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
397 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700398
rago90fb9612015-12-02 11:37:53 -0800399 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700400 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700401 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700402 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700403 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
404 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800405 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
406
407 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
408 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700409 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
410 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
411 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700412
413 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700414 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700415 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
416 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
417 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
418 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700419 [SND_DEVICE_IN_THREE_MIC] = 46,
420 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700421 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700422 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
423 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700424 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
425 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700426};
427
David Linee3fe402017-03-13 10:00:42 -0700428// Platform specific backend bit width table
429static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
430
Haynes Mathew George98c95622014-06-20 19:14:25 -0700431struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700432 char name[100];
433 unsigned int index;
434};
435
436#define TO_NAME_INDEX(X) #X, X
437
Haynes Mathew George98c95622014-06-20 19:14:25 -0700438/* Used to get index from parsed string */
439static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
440 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700441 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
442 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
443 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700444 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700445 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500446 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700447 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700448 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500449 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700450 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700451 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
452 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700453 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700454 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500455 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700456 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
457 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
458 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
459 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700460 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500461 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700462 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
463 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
464 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800465 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
466 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800467 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
468 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700469 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700470 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700471 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700472 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700473 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700474 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
475 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800476
477 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700478 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700479 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700480 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
481 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
482 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
483 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
484 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
485 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
486 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
487
488 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700489 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700490 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
491 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
492 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
493 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
494 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
495 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
496 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
497
498 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700499 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700500
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700501 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
502 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700503 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700504 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700505 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700506 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700507
508 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
509 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
510 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700511 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700512 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
513 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700514 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
515 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
516 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800517 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
518 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
519
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700520
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700521 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700522 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700523 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700524 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700525 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
526 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700527 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700528 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700529 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
530 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
531 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
532 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700533
rago90fb9612015-12-02 11:37:53 -0800534 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
535 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700536 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
537 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
538 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800539
Prashant Malanic92c5962015-08-11 15:10:18 -0700540 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
541 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700542 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700543 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
544 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700545 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
546 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700547};
548
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700549static char * backend_tag_table[SND_DEVICE_MAX] = {0};
550static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700551
552static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
553 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
554 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800555 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700556 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700557 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
558 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800559 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700560 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
561 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800562 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700563 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700564 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
565 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
566 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
567 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
568 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800569 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
570 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700571 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
572 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
573 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
574 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800575 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
576 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
577 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
578 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
579 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700580 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
581 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700582};
583
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800584static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
585 {TO_NAME_INDEX(PCM_PLAYBACK)},
586 {TO_NAME_INDEX(PCM_CAPTURE)},
587 {TO_NAME_INDEX(VOICE_CALL)},
588 {TO_NAME_INDEX(PCM_HFP_CALL)},
589};
590
591struct app_type_entry {
592 int uc_type;
593 int bit_width;
594 int app_type;
595 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700596 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800597 struct listnode node; // membership in app_type_entry_list;
598};
599
600static struct listnode app_type_entry_list;
601
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700602#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
603#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800604#define ULL_PLATFORM_DELAY (3*1000LL)
605#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700606
Eric Laurentb23d5282013-05-14 15:27:20 -0700607static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
608static bool is_tmus = false;
609
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800610static int init_be_dai_name_table(struct audio_device *adev);
611
Eric Laurentb23d5282013-05-14 15:27:20 -0700612static void check_operator()
613{
614 char value[PROPERTY_VALUE_MAX];
615 int mccmnc;
616 property_get("gsm.sim.operator.numeric",value,"0");
617 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700618 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700619 switch(mccmnc) {
620 /* TMUS MCC(310), MNC(490, 260, 026) */
621 case 310490:
622 case 310260:
623 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900624 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
625 case 310800:
626 case 310660:
627 case 310580:
628 case 310310:
629 case 310270:
630 case 310250:
631 case 310240:
632 case 310230:
633 case 310220:
634 case 310210:
635 case 310200:
636 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700637 is_tmus = true;
638 break;
639 }
640}
641
642bool is_operator_tmus()
643{
644 pthread_once(&check_op_once_ctl, check_operator);
645 return is_tmus;
646}
647
keunhui.park2f7306a2015-07-16 16:48:06 +0900648static char *get_current_operator()
649{
650 struct listnode *node;
651 struct operator_info *info_item;
652 char mccmnc[PROPERTY_VALUE_MAX];
653 char *ret = NULL;
654
Tom Cherry7fea2042016-11-10 18:05:59 -0800655 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900656
657 list_for_each(node, &operator_info_list) {
658 info_item = node_to_item(node, struct operator_info, list);
659 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
660 ret = info_item->name;
661 }
662 }
663
664 return ret;
665}
666
667static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
668{
669 struct listnode *node;
670 struct operator_specific_device *ret = NULL;
671 struct operator_specific_device *device_item;
672 char *operator_name;
673
674 operator_name = get_current_operator();
675 if (operator_name == NULL)
676 return ret;
677
678 list_for_each(node, operator_specific_device_table[snd_device]) {
679 device_item = node_to_item(node, struct operator_specific_device, list);
680 if (strcmp(operator_name, device_item->operator) == 0) {
681 ret = device_item;
682 }
683 }
684
685 return ret;
686}
687
688
689static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
690{
691 struct operator_specific_device *device;
692 int ret = acdb_device_table[snd_device];
693
694 device = get_operator_specific_device(snd_device);
695 if (device != NULL)
696 ret = device->acdb_id;
697
698 return ret;
699}
700
701static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
702{
703 struct operator_specific_device *device;
704 const char *ret = device_table[snd_device];
705
706 device = get_operator_specific_device(snd_device);
707 if (device != NULL)
708 ret = device->mixer_path;
709
710 return ret;
711}
712
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800713inline bool platform_supports_app_type_cfg()
714{
715#ifdef PLATFORM_MSM8998
716 return true;
717#else
718 return false;
719#endif
720}
721
vivek mehta1a9b7c02015-06-25 11:49:38 -0700722bool platform_send_gain_dep_cal(void *platform, int level)
723{
724 bool ret_val = false;
725 struct platform_data *my_data = (struct platform_data *)platform;
726 struct audio_device *adev = my_data->adev;
727 int acdb_dev_id, app_type;
728 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
729 int mode = CAL_MODE_RTAC;
730 struct listnode *node;
731 struct audio_usecase *usecase;
vivek mehtaa68fea62017-06-08 19:04:02 -0700732 bool valid_uc_type = false;
733 bool valid_dev = false;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700734
735 if (my_data->acdb_send_gain_dep_cal == NULL) {
736 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
737 return ret_val;
738 }
739
740 if (!voice_is_in_call(adev)) {
741 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
742 __func__, level);
743 app_type = DEFAULT_APP_TYPE_RX_PATH;
744
745 // find the current active sound device
746 list_for_each(node, &adev->usecase_list) {
747 usecase = node_to_item(node, struct audio_usecase, list);
vivek mehtaa68fea62017-06-08 19:04:02 -0700748 valid_uc_type = usecase->type == PCM_PLAYBACK;
749 audio_devices_t dev = usecase->stream.out->devices;
750 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
751 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
752 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
753 if (usecase != NULL && valid_uc_type && valid_dev) {
754 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
755 if (audio_extn_spkr_prot_is_enabled()) {
vivek mehta4cb82982015-07-13 12:05:49 -0700756 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
vivek mehtaa68fea62017-06-08 19:04:02 -0700757 } else {
758 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
759 }
vivek mehta4cb82982015-07-13 12:05:49 -0700760
vivek mehtaa68fea62017-06-08 19:04:02 -0700761 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700762 acdb_dev_type, mode, level)) {
763 // set ret_val true if at least one calibration is set successfully
764 ret_val = true;
765 } else {
766 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
767 }
768 } else {
769 ALOGW("%s: Usecase list is empty", __func__);
770 }
771 }
772 } else {
773 ALOGW("%s: Voice call in progress .. ignore setting new cal",
774 __func__);
775 }
776 return ret_val;
777}
778
Eric Laurentcefbbac2014-09-04 13:54:10 -0500779void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700780{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800781 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500782 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700783
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800784 if (strcmp(my_data->ec_ref_mixer_path, "")) {
785 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
786 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500787 }
788
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800789 if (enable) {
790 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
791 if (out_device != AUDIO_DEVICE_NONE) {
792 snd_device = platform_get_output_snd_device(adev->platform, out_device);
793 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
794 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500795
Joe Onorato188b6222016-03-01 11:02:27 -0800796 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800797 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
798 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700799}
800
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700801static struct csd_data *open_csd_client(bool i2s_ext_modem)
802{
803 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
804
805 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
806 if (csd->csd_client == NULL) {
807 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
808 goto error;
809 } else {
810 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
811
812 csd->deinit = (deinit_t)dlsym(csd->csd_client,
813 "csd_client_deinit");
814 if (csd->deinit == NULL) {
815 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
816 dlerror());
817 goto error;
818 }
819 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
820 "csd_client_disable_device");
821 if (csd->disable_device == NULL) {
822 ALOGE("%s: dlsym error %s for csd_client_disable_device",
823 __func__, dlerror());
824 goto error;
825 }
826 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
827 "csd_client_enable_device_config");
828 if (csd->enable_device_config == NULL) {
829 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
830 __func__, dlerror());
831 goto error;
832 }
833 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
834 "csd_client_enable_device");
835 if (csd->enable_device == NULL) {
836 ALOGE("%s: dlsym error %s for csd_client_enable_device",
837 __func__, dlerror());
838 goto error;
839 }
840 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
841 "csd_client_start_voice");
842 if (csd->start_voice == NULL) {
843 ALOGE("%s: dlsym error %s for csd_client_start_voice",
844 __func__, dlerror());
845 goto error;
846 }
847 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
848 "csd_client_stop_voice");
849 if (csd->stop_voice == NULL) {
850 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
851 __func__, dlerror());
852 goto error;
853 }
854 csd->volume = (volume_t)dlsym(csd->csd_client,
855 "csd_client_volume");
856 if (csd->volume == NULL) {
857 ALOGE("%s: dlsym error %s for csd_client_volume",
858 __func__, dlerror());
859 goto error;
860 }
861 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
862 "csd_client_mic_mute");
863 if (csd->mic_mute == NULL) {
864 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
865 __func__, dlerror());
866 goto error;
867 }
868 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
869 "csd_client_slow_talk");
870 if (csd->slow_talk == NULL) {
871 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
872 __func__, dlerror());
873 goto error;
874 }
875 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
876 "csd_client_start_playback");
877 if (csd->start_playback == NULL) {
878 ALOGE("%s: dlsym error %s for csd_client_start_playback",
879 __func__, dlerror());
880 goto error;
881 }
882 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
883 "csd_client_stop_playback");
884 if (csd->stop_playback == NULL) {
885 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
886 __func__, dlerror());
887 goto error;
888 }
889 csd->start_record = (start_record_t)dlsym(csd->csd_client,
890 "csd_client_start_record");
891 if (csd->start_record == NULL) {
892 ALOGE("%s: dlsym error %s for csd_client_start_record",
893 __func__, dlerror());
894 goto error;
895 }
896 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
897 "csd_client_stop_record");
898 if (csd->stop_record == NULL) {
899 ALOGE("%s: dlsym error %s for csd_client_stop_record",
900 __func__, dlerror());
901 goto error;
902 }
903
904 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
905 "csd_client_get_sample_rate");
906 if (csd->get_sample_rate == NULL) {
907 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
908 __func__, dlerror());
909
910 goto error;
911 }
912
913 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
914
915 if (csd->init == NULL) {
916 ALOGE("%s: dlsym error %s for csd_client_init",
917 __func__, dlerror());
918 goto error;
919 } else {
920 csd->init(i2s_ext_modem);
921 }
922 }
923 return csd;
924
925error:
926 free(csd);
927 csd = NULL;
928 return csd;
929}
930
931void close_csd_client(struct csd_data *csd)
932{
933 if (csd != NULL) {
934 csd->deinit();
935 dlclose(csd->csd_client);
936 free(csd);
937 csd = NULL;
938 }
939}
940
941static void platform_csd_init(struct platform_data *my_data)
942{
943#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700944 int32_t modems, (*count_modems)(void);
945 const char *name = "libdetectmodem.so";
946 const char *func = "count_modems";
947 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700948
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700949 my_data->csd = NULL;
950
951 void *lib = dlopen(name, RTLD_NOW);
952 error = dlerror();
953 if (!lib) {
954 ALOGE("%s: could not find %s: %s", __func__, name, error);
955 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700956 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700957
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700958 count_modems = NULL;
959 *(void **)(&count_modems) = dlsym(lib, func);
960 error = dlerror();
961 if (!count_modems) {
962 ALOGE("%s: could not find symbol %s in %s: %s",
963 __func__, func, name, error);
964 goto done;
965 }
966
967 modems = count_modems();
968 if (modems < 0) {
969 ALOGE("%s: count_modems failed\n", __func__);
970 goto done;
971 }
972
Eric Laurent2bafff12016-03-17 12:17:23 -0700973 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700974 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700975 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700976
977done:
978 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700979#else
980 my_data->csd = NULL;
981#endif
982}
983
Eric Laurentc6333382015-09-14 12:43:44 -0700984static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700985{
986 int32_t dev;
987 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700988 backend_tag_table[dev] = NULL;
989 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900990 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700991 }
992
David Linee3fe402017-03-13 10:00:42 -0700993 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
994 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
995 }
996
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700997 // To overwrite these go to the audio_platform_info.xml file.
998 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700999 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001000 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1001 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1002 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1003 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1004 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001005 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001006 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1007 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001008
David Linee3fe402017-03-13 10:00:42 -07001009 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001010 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001011 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001012 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001013 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1014 strdup("speaker-and-usb-headphones");
1015 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001016 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1017 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1018 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1019 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001020 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1021 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1022 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1023 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1024 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1025 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1026 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001027 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001028 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001029 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001030 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1031 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1032 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1033 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1034 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1035 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1036 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1037 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1038 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
1039 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1040 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1041 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1042 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001043 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001044 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1045 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001046 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001047 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001048 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001049 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 -07001050 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1051 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1052 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001053 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1054 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1055 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1056 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1057 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1058 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1059 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
1060 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1061 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1062 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1063 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1064 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001065
1066 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001067}
1068
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001069void get_cvd_version(char *cvd_version, struct audio_device *adev)
1070{
1071 struct mixer_ctl *ctl;
1072 int count;
1073 int ret = 0;
1074
1075 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1076 if (!ctl) {
1077 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1078 goto done;
1079 }
1080 mixer_ctl_update(ctl);
1081
1082 count = mixer_ctl_get_num_values(ctl);
1083 if (count > MAX_CVD_VERSION_STRING_SIZE)
1084 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1085
1086 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1087 if (ret != 0) {
1088 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1089 goto done;
1090 }
1091
1092done:
1093 return;
1094}
1095
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001096static int platform_acdb_init(void *platform)
1097{
1098 struct platform_data *my_data = (struct platform_data *)platform;
1099 struct audio_device *adev = my_data->adev;
1100
1101 if (!my_data->acdb_init) {
1102 ALOGE("%s: no acdb_init fn provided", __func__);
1103 return -1;
1104 }
1105
1106 if (my_data->acdb_initialized) {
1107 ALOGW("acdb is already initialized");
1108 return 0;
1109 }
1110
Thierry Strudel92232b42017-01-26 10:51:48 -08001111#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001112 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1113 if (!cvd_version)
1114 ALOGE("failed to allocate cvd_version");
1115 else {
1116 get_cvd_version(cvd_version, adev);
1117 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1118 free(cvd_version);
1119 }
1120#elif defined (PLATFORM_MSM8084)
1121 my_data->acdb_init((char *)my_data->snd_card_name);
1122#else
1123 my_data->acdb_init();
1124#endif
1125 my_data->acdb_initialized = true;
1126 return 0;
1127}
1128
David Linee3fe402017-03-13 10:00:42 -07001129static void
1130platform_backend_config_init(struct platform_data *pdata)
1131{
1132 int i;
1133
1134 /* initialize backend config */
1135 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1136 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1137 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1138 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1139
1140 if (i > MAX_RX_CODEC_BACKENDS)
1141 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1142
1143 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1144 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1145 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1146 }
1147
1148 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1149 strdup("SLIM_0_RX Format");
1150 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1151 strdup("SLIM_0_RX SampleRate");
1152
1153 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1154 strdup("SLIM_0_TX Format");
1155 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1156 strdup("SLIM_0_TX SampleRate");
1157
1158 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1159 strdup("USB_AUDIO_TX Format");
1160 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1161 strdup("USB_AUDIO_TX SampleRate");
1162 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1163 strdup("USB_AUDIO_TX Channels");
1164
1165 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1166 strdup("SLIM_6_RX Format");
1167 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1168 strdup("SLIM_6_RX SampleRate");
1169
1170 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1171 strdup("USB_AUDIO_RX Format");
1172 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1173 strdup("USB_AUDIO_RX SampleRate");
1174
1175 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1176 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1177 strdup("USB_AUDIO_RX Channels");
1178}
1179
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001180static int
1181platform_backend_app_type_cfg_init(struct platform_data *pdata,
1182 struct mixer *mixer)
1183{
1184 size_t app_type_cfg[128] = {0};
1185 int length, num_app_types = 0;
1186 struct mixer_ctl *ctl = NULL;
1187
1188 const char *mixer_ctl_name = "App Type Config";
1189 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1190 if (!ctl) {
1191 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1192 return -1;
1193 }
1194
1195 length = 1; // reserve index 0 for number of app types
1196
1197 struct listnode *node;
1198 struct app_type_entry *entry;
1199 list_for_each(node, &app_type_entry_list) {
1200 entry = node_to_item(node, struct app_type_entry, node);
1201 app_type_cfg[length++] = entry->app_type;
1202 app_type_cfg[length++] = entry->max_rate;
1203 app_type_cfg[length++] = entry->bit_width;
1204 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1205 num_app_types += 1;
1206 }
1207
1208 // default for capture
1209 int t;
1210 platform_get_default_app_type_v2(pdata,
1211 PCM_CAPTURE,
1212 &t);
1213 app_type_cfg[length++] = t;
1214 app_type_cfg[length++] = 48000;
1215 app_type_cfg[length++] = 16;
1216 num_app_types += 1;
1217
1218 if (num_app_types) {
1219 app_type_cfg[0] = num_app_types;
1220 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1221 ALOGE("Failed to set app type cfg");
1222 }
1223 }
1224 return 0;
1225}
1226
Eric Laurentb23d5282013-05-14 15:27:20 -07001227void *platform_init(struct audio_device *adev)
1228{
1229 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001230 struct platform_data *my_data = NULL;
1231 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1232 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001233 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001234 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001235 char *snd_internal_name = NULL;
1236 char *tmp = NULL;
1237 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001238 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1239 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001240 my_data = calloc(1, sizeof(struct platform_data));
1241
1242 my_data->adev = adev;
1243
keunhui.park2f7306a2015-07-16 16:48:06 +09001244 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001245 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001246
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001247 set_platform_defaults(my_data);
1248
vivek mehta0fb11312017-05-15 19:35:32 -07001249 // audio_extn_utils_get_snd_card_num does
1250 // - open mixer and get snd card name
1251 // - parse platform info xml file and check for valid snd card name
1252 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001253
vivek mehta0fb11312017-05-15 19:35:32 -07001254 snd_card_num = audio_extn_utils_get_snd_card_num();
1255 if (-1 == snd_card_num) {
1256 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1257 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001258 }
1259
vivek mehta0fb11312017-05-15 19:35:32 -07001260 adev->mixer = mixer_open(snd_card_num);
1261 snd_card_name = mixer_get_name(adev->mixer);
1262 my_data->hw_info = hw_info_init(snd_card_name);
1263
1264 audio_extn_set_snd_card_split(snd_card_name);
1265 snd_split_handle = audio_extn_get_snd_card_split();
1266
1267 /* Get the codec internal name from the sound card and/or form factor
1268 * name and form the mixer paths and platfor info file name dynamically.
1269 * This is generic way of picking any codec and forma factor name based
1270 * mixer and platform info files in future with no code change.
1271
1272 * current code extends and looks for any of the exteneded mixer path and
1273 * platform info file present based on codec and form factor.
1274
1275 * order of picking appropriate file is
1276 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1277 * <ii> mixer_paths_<codec_name>.xml, if file not present
1278 * <iii> mixer_paths.xml
1279
1280 * same order is followed for audio_platform_info.xml as well
1281 */
1282
1283 // need to carryforward old file name
1284 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1285 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1286 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1287 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1288 } else {
1289
1290 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1291 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1292 snd_split_handle->form_factor);
1293 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1294 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1295 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1296 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1297
1298 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1299 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1300 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1301 audio_extn_utils_resolve_config_file(mixer_xml_file);
1302 }
1303 }
1304 }
1305
1306 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1307
1308 /* Initialize platform specific ids and/or backends*/
1309 platform_info_init(platform_info_file, my_data);
1310
1311 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1312 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1313
1314 if (!adev->audio_route) {
1315 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1316 mixer_close(adev->mixer);
1317 adev->mixer = NULL;
1318 hw_info_deinit(my_data->hw_info);
1319 my_data->hw_info = NULL;
1320 goto init_failed;
1321 }
1322 adev->snd_card = snd_card_num;
1323 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1324
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001325 //set max volume step for voice call
1326 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1327 my_data->max_vol_index = atoi(value);
1328
vivek mehta65ad12d2015-08-13 18:32:48 -07001329 property_get("persist.audio.dualmic.config",value,"");
1330 if (!strcmp("endfire", value)) {
1331 dual_mic_config = true;
1332 }
1333
Prashant Malanic92c5962015-08-11 15:10:18 -07001334 my_data->source_mic_type = SOURCE_DUAL_MIC;
1335
Eric Laurentb23d5282013-05-14 15:27:20 -07001336 my_data->fluence_in_spkr_mode = false;
1337 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001338 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001339 my_data->fluence_in_voice_rec = false;
1340
vivek mehta65ad12d2015-08-13 18:32:48 -07001341 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001342 if (!strcmp("fluencepro", value)) {
1343 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001344 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001345 my_data->fluence_type = FLUENCE_ENABLE;
1346 } else if (!strcmp("none", value)) {
1347 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001348 }
1349
Prashant Malanic92c5962015-08-11 15:10:18 -07001350 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001351 property_get("persist.audio.fluence.voicecall",value,"");
1352 if (!strcmp("true", value)) {
1353 my_data->fluence_in_voice_call = true;
1354 }
1355
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001356 property_get("persist.audio.fluence.voicecomm",value,"");
1357 if (!strcmp("true", value)) {
1358 my_data->fluence_in_voice_comm = true;
1359 }
1360
Eric Laurentb23d5282013-05-14 15:27:20 -07001361 property_get("persist.audio.fluence.voicerec",value,"");
1362 if (!strcmp("true", value)) {
1363 my_data->fluence_in_voice_rec = true;
1364 }
1365
1366 property_get("persist.audio.fluence.speaker",value,"");
1367 if (!strcmp("true", value)) {
1368 my_data->fluence_in_spkr_mode = true;
1369 }
1370 }
1371
Prashant Malanic92c5962015-08-11 15:10:18 -07001372 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1373 switch (my_data->max_mic_count) {
1374 case 4:
1375 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1376 case 3:
1377 my_data->source_mic_type |= SOURCE_THREE_MIC;
1378 case 2:
1379 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1380 case 1:
1381 my_data->source_mic_type |= SOURCE_MONO_MIC;
1382 break;
1383 default:
1384 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1385 __func__, my_data->max_mic_count);
1386 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1387 break;
1388 }
1389
1390 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1391 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1392 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1393 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1394 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1395
Eric Laurentb23d5282013-05-14 15:27:20 -07001396 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1397 if (my_data->acdb_handle == NULL) {
1398 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1399 } else {
1400 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1401 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1402 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001403 if (!my_data->acdb_deallocate)
1404 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1405 __func__, LIB_ACDB_LOADER);
1406
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001407 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1408 "acdb_loader_send_audio_cal_v3");
1409 if (!my_data->acdb_send_audio_cal_v3)
1410 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1411 __func__, LIB_ACDB_LOADER);
1412
Eric Laurentb23d5282013-05-14 15:27:20 -07001413 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1414 "acdb_loader_send_audio_cal");
1415 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001416 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001417 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001418
Eric Laurentb23d5282013-05-14 15:27:20 -07001419 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1420 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001421 if (!my_data->acdb_send_voice_cal)
1422 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1423 __func__, LIB_ACDB_LOADER);
1424
1425 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1426 "acdb_loader_reload_vocvoltable");
1427 if (!my_data->acdb_reload_vocvoltable)
1428 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1429 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001430
1431 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1432 "acdb_loader_send_gain_dep_cal");
1433 if (!my_data->acdb_send_gain_dep_cal)
1434 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1435 __func__, LIB_ACDB_LOADER);
1436
Thierry Strudel92232b42017-01-26 10:51:48 -08001437#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
vivek mehta0fb11312017-05-15 19:35:32 -07001438 acdb_init_v2_cvd_t acdb_init_local;
1439 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001440 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001441 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001442 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1443 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001444
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001445#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001446 acdb_init_v2_t acdb_init_local;
1447 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001448 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001449 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001450 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1451 dlerror());
1452
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001453#else
vivek mehta0fb11312017-05-15 19:35:32 -07001454 acdb_init_t acdb_init_local;
1455 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001456 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001457 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001458 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1459 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001460#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001461 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001462
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001463 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1464 dlsym(my_data->acdb_handle,
1465 "acdb_loader_send_common_custom_topology");
1466
1467 if (!my_data->acdb_send_custom_top)
1468 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1469 __func__, LIB_ACDB_LOADER);
1470
vivek mehta0fb11312017-05-15 19:35:32 -07001471 int result = acdb_init(adev->snd_card);
1472 if (!result) {
1473 my_data->acdb_initialized = true;
1474 ALOGD("ACDB initialized");
1475 } else {
1476 my_data->acdb_initialized = false;
1477 ALOGD("ACDB initialization failed");
1478 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001479 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001480
David Linee3fe402017-03-13 10:00:42 -07001481 /* init usb */
1482 audio_extn_usb_init(adev);
1483
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001484 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001485
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001486 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1487
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001488 /* load csd client */
1489 platform_csd_init(my_data);
1490
David Linee3fe402017-03-13 10:00:42 -07001491 platform_backend_config_init(my_data);
1492
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001493 init_be_dai_name_table(adev);
1494
1495 if (platform_supports_app_type_cfg())
1496 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1497
Eric Laurentb23d5282013-05-14 15:27:20 -07001498 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001499
1500init_failed:
1501 if (my_data)
1502 free(my_data);
1503 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001504}
1505
1506void platform_deinit(void *platform)
1507{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001508 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001509 struct operator_info *info_item;
1510 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001511 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001512 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001513
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001514 struct platform_data *my_data = (struct platform_data *)platform;
1515 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001516
vivek mehtade4849c2016-03-03 17:23:38 -08001517 hw_info_deinit(my_data->hw_info);
1518
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001519 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1520 if (backend_tag_table[dev])
1521 free(backend_tag_table[dev]);
1522 if (hw_interface_table[dev])
1523 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001524 if (operator_specific_device_table[dev]) {
1525 while (!list_empty(operator_specific_device_table[dev])) {
1526 node = list_head(operator_specific_device_table[dev]);
1527 list_remove(node);
1528 device_item = node_to_item(node, struct operator_specific_device, list);
1529 free(device_item->operator);
1530 free(device_item->mixer_path);
1531 free(device_item);
1532 }
1533 free(operator_specific_device_table[dev]);
1534 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001535 }
1536
1537 if (my_data->snd_card_name)
1538 free(my_data->snd_card_name);
1539
keunhui.park2f7306a2015-07-16 16:48:06 +09001540 while (!list_empty(&operator_info_list)) {
1541 node = list_head(&operator_info_list);
1542 list_remove(node);
1543 info_item = node_to_item(node, struct operator_info, list);
1544 free(info_item->name);
1545 free(info_item->mccmnc);
1546 free(info_item);
1547 }
1548
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001549 while (!list_empty(&app_type_entry_list)) {
1550 node = list_head(&app_type_entry_list);
1551 list_remove(node);
1552 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001553 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001554 free(ap);
1555 }
1556
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001557 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001558 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001559
1560 /* deinit usb */
1561 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001562}
1563
1564const char *platform_get_snd_device_name(snd_device_t snd_device)
1565{
keunhui.park2f7306a2015-07-16 16:48:06 +09001566 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1567 if (operator_specific_device_table[snd_device] != NULL) {
1568 return get_operator_specific_device_mixer_path(snd_device);
1569 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001570 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001571 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001572 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001573}
1574
vivek mehtade4849c2016-03-03 17:23:38 -08001575int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1576 char *device_name)
1577{
1578 struct platform_data *my_data = (struct platform_data *)platform;
1579
David Benjamin1565f992016-09-21 12:10:34 -04001580 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001581 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001582 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1583 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001584 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1585 if (operator_specific_device_table[snd_device] != NULL) {
1586 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1587 DEVICE_NAME_MAX_SIZE);
1588 } else {
1589 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1590 }
1591 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1592 } else {
1593 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1594 }
1595
1596 return 0;
1597}
1598
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001599void platform_add_backend_name(void *platform, char *mixer_path,
1600 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001601{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001602 struct platform_data *my_data = (struct platform_data *)platform;
1603
Haynes Mathew George98c95622014-06-20 19:14:25 -07001604 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1605 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1606 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001607 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001608
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001609 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001610
1611 if (suffix != NULL) {
1612 strcat(mixer_path, " ");
1613 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001614 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001615}
1616
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001617bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1618{
1619 bool result = true;
1620
1621 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1622 platform_get_snd_device_name(snd_device1),
1623 platform_get_snd_device_name(snd_device2));
1624
1625 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1626 ALOGE("%s: Invalid snd_device = %s", __func__,
1627 platform_get_snd_device_name(snd_device1));
1628 return false;
1629 }
1630 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1631 ALOGE("%s: Invalid snd_device = %s", __func__,
1632 platform_get_snd_device_name(snd_device2));
1633 return false;
1634 }
1635 const char * be_itf1 = hw_interface_table[snd_device1];
1636 const char * be_itf2 = hw_interface_table[snd_device2];
1637
1638 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001639 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001640 result = false;
1641 }
1642
1643 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1644 return result;
1645}
1646
Eric Laurentb23d5282013-05-14 15:27:20 -07001647int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1648{
1649 int device_id;
1650 if (device_type == PCM_PLAYBACK)
1651 device_id = pcm_device_table[usecase][0];
1652 else
1653 device_id = pcm_device_table[usecase][1];
1654 return device_id;
1655}
1656
Haynes Mathew George98c95622014-06-20 19:14:25 -07001657static int find_index(const struct name_to_index * table, int32_t len,
1658 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001659{
1660 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001661 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001662
Haynes Mathew George98c95622014-06-20 19:14:25 -07001663 if (table == NULL) {
1664 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001665 ret = -ENODEV;
1666 goto done;
1667 }
1668
Haynes Mathew George98c95622014-06-20 19:14:25 -07001669 if (name == NULL) {
1670 ALOGE("null key");
1671 ret = -ENODEV;
1672 goto done;
1673 }
1674
1675 for (i=0; i < len; i++) {
1676 if (!strcmp(table[i].name, name)) {
1677 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001678 goto done;
1679 }
1680 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001681 ALOGE("%s: Could not find index for name = %s",
1682 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001683 ret = -ENODEV;
1684done:
1685 return ret;
1686}
1687
Haynes Mathew George98c95622014-06-20 19:14:25 -07001688int platform_get_snd_device_index(char *device_name)
1689{
1690 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1691}
1692
1693int platform_get_usecase_index(const char *usecase_name)
1694{
1695 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1696}
1697
keunhui.park2f7306a2015-07-16 16:48:06 +09001698void platform_add_operator_specific_device(snd_device_t snd_device,
1699 const char *operator,
1700 const char *mixer_path,
1701 unsigned int acdb_id)
1702{
1703 struct operator_specific_device *device;
1704
1705 if (operator_specific_device_table[snd_device] == NULL) {
1706 operator_specific_device_table[snd_device] =
1707 (struct listnode *)calloc(1, sizeof(struct listnode));
1708 list_init(operator_specific_device_table[snd_device]);
1709 }
1710
1711 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1712
1713 device->operator = strdup(operator);
1714 device->mixer_path = strdup(mixer_path);
1715 device->acdb_id = acdb_id;
1716
1717 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1718
Eric Laurent2bafff12016-03-17 12:17:23 -07001719 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001720 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1721
1722}
1723
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001724int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1725{
1726 int ret = 0;
1727
1728 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1729 ALOGE("%s: Invalid snd_device = %d",
1730 __func__, snd_device);
1731 ret = -EINVAL;
1732 goto done;
1733 }
1734
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001735 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1736 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001737 acdb_device_table[snd_device] = acdb_id;
1738done:
1739 return ret;
1740}
1741
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001742int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1743{
1744 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1745 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1746 return -EINVAL;
1747 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001748
1749 if (operator_specific_device_table[snd_device] != NULL)
1750 return get_operator_specific_device_acdb_id(snd_device);
1751 else
1752 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001753}
1754
David Linee3fe402017-03-13 10:00:42 -07001755static int platform_get_backend_index(snd_device_t snd_device)
1756{
1757 int32_t port = DEFAULT_CODEC_BACKEND;
1758
1759 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1760 if (backend_tag_table[snd_device] != NULL) {
1761 if (strncmp(backend_tag_table[snd_device], "headphones",
1762 sizeof("headphones")) == 0)
1763 port = HEADPHONE_BACKEND;
1764 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1765 port = HDMI_RX_BACKEND;
1766 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1767 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1768 port = USB_AUDIO_RX_BACKEND;
1769 }
1770 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1771 port = DEFAULT_CODEC_TX_BACKEND;
1772 if (backend_tag_table[snd_device] != NULL) {
1773 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1774 port = USB_AUDIO_TX_BACKEND;
1775 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1776 port = BT_SCO_TX_BACKEND;
1777 }
1778 } else {
1779 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1780 }
1781
1782 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1783
1784 return port;
1785}
1786
Eric Laurentb23d5282013-05-14 15:27:20 -07001787int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1788{
1789 struct platform_data *my_data = (struct platform_data *)platform;
1790 int acdb_dev_id, acdb_dev_type;
1791
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001792 if (platform_supports_app_type_cfg()) // use v2 instead
1793 return -ENOSYS;
1794
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001795 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001796 if (acdb_dev_id < 0) {
1797 ALOGE("%s: Could not find acdb id for device(%d)",
1798 __func__, snd_device);
1799 return -EINVAL;
1800 }
1801 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001802 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001803 __func__, snd_device, acdb_dev_id);
1804 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1805 snd_device < SND_DEVICE_OUT_END)
1806 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1807 else
1808 acdb_dev_type = ACDB_DEV_TYPE_IN;
1809 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1810 }
1811 return 0;
1812}
1813
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001814int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1815 int app_type, int sample_rate)
1816{
1817 struct platform_data *my_data = (struct platform_data *)platform;
1818 int acdb_dev_id, acdb_dev_type;
1819 int snd_device = SND_DEVICE_OUT_SPEAKER;
1820 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1821 int i, num_devices = 1;
1822
1823 if (!platform_supports_app_type_cfg()) // use v1 instead
1824 return -ENOSYS;
1825
1826 if (usecase->type == PCM_PLAYBACK)
1827 snd_device = usecase->out_snd_device;
1828 else if (usecase->type == PCM_CAPTURE)
1829 snd_device = usecase->in_snd_device;
1830
1831 // skipped over get_spkr_prot_device
1832 acdb_dev_id = acdb_device_table[snd_device];
1833 if (acdb_dev_id < 0) {
1834 ALOGE("%s: Could not find acdb id for device(%d)",
1835 __func__, snd_device);
1836 return -EINVAL;
1837 }
1838
1839 if (platform_can_split_snd_device(snd_device,
1840 &num_devices, new_snd_device) < 0) {
1841 new_snd_device[0] = snd_device;
1842 }
1843
1844 for (i = 0; i < num_devices; i++) {
1845 acdb_dev_id = acdb_device_table[new_snd_device[i]];
1846 if (acdb_dev_id < 0) {
1847 ALOGE("%s: Could not find acdb id for device(%d)",
1848 __func__, new_snd_device[i]);
1849 return -EINVAL;
1850 }
1851 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1852 __func__, new_snd_device[i], acdb_dev_id);
1853 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1854 new_snd_device[i] < SND_DEVICE_OUT_END)
1855 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1856 else
1857 acdb_dev_type = ACDB_DEV_TYPE_IN;
1858
1859 if (my_data->acdb_send_audio_cal_v3) {
1860 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1861 app_type, sample_rate, i);
1862 } else if (my_data->acdb_send_audio_cal) {
1863 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
1864 }
1865 }
1866
1867 return 0;
1868}
1869
1870
Eric Laurentb23d5282013-05-14 15:27:20 -07001871int platform_switch_voice_call_device_pre(void *platform)
1872{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001873 struct platform_data *my_data = (struct platform_data *)platform;
1874 int ret = 0;
1875
1876 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001877 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001878 /* This must be called before disabling mixer controls on APQ side */
1879 ret = my_data->csd->disable_device();
1880 if (ret < 0) {
1881 ALOGE("%s: csd_client_disable_device, failed, error %d",
1882 __func__, ret);
1883 }
1884 }
1885 return ret;
1886}
1887
1888int platform_switch_voice_call_enable_device_config(void *platform,
1889 snd_device_t out_snd_device,
1890 snd_device_t in_snd_device)
1891{
1892 struct platform_data *my_data = (struct platform_data *)platform;
1893 int acdb_rx_id, acdb_tx_id;
1894 int ret = 0;
1895
1896 if (my_data->csd == NULL)
1897 return ret;
1898
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001899 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1900 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001901 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001902 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001903 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001904
keunhui.park2f7306a2015-07-16 16:48:06 +09001905 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001906
1907 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1908 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1909 if (ret < 0) {
1910 ALOGE("%s: csd_enable_device_config, failed, error %d",
1911 __func__, ret);
1912 }
1913 } else {
1914 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1915 acdb_rx_id, acdb_tx_id);
1916 }
1917
1918 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001919}
1920
1921int platform_switch_voice_call_device_post(void *platform,
1922 snd_device_t out_snd_device,
1923 snd_device_t in_snd_device)
1924{
1925 struct platform_data *my_data = (struct platform_data *)platform;
1926 int acdb_rx_id, acdb_tx_id;
1927
1928 if (my_data->acdb_send_voice_cal == NULL) {
1929 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1930 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001931 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1932 audio_extn_spkr_prot_is_enabled())
1933 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1934
keunhui.park2f7306a2015-07-16 16:48:06 +09001935 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1936 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001937
1938 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1939 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1940 else
1941 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1942 acdb_rx_id, acdb_tx_id);
1943 }
1944
1945 return 0;
1946}
1947
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001948int platform_switch_voice_call_usecase_route_post(void *platform,
1949 snd_device_t out_snd_device,
1950 snd_device_t in_snd_device)
1951{
1952 struct platform_data *my_data = (struct platform_data *)platform;
1953 int acdb_rx_id, acdb_tx_id;
1954 int ret = 0;
1955
1956 if (my_data->csd == NULL)
1957 return ret;
1958
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001959 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1960 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001961 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001962 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001963 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001964
keunhui.park2f7306a2015-07-16 16:48:06 +09001965 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001966
1967 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1968 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1969 my_data->adev->acdb_settings);
1970 if (ret < 0) {
1971 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1972 }
1973 } else {
1974 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1975 acdb_rx_id, acdb_tx_id);
1976 }
1977
1978 return ret;
1979}
1980
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001981int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001982{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001983 struct platform_data *my_data = (struct platform_data *)platform;
1984 int ret = 0;
1985
1986 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001987 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001988 if (ret < 0) {
1989 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1990 }
1991 }
1992 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001993}
1994
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001995int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001996{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001997 struct platform_data *my_data = (struct platform_data *)platform;
1998 int ret = 0;
1999
2000 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002001 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002002 if (ret < 0) {
2003 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2004 }
2005 }
2006 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002007}
2008
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002009int platform_get_sample_rate(void *platform, uint32_t *rate)
2010{
2011 struct platform_data *my_data = (struct platform_data *)platform;
2012 int ret = 0;
2013
2014 if (my_data->csd != NULL) {
2015 ret = my_data->csd->get_sample_rate(rate);
2016 if (ret < 0) {
2017 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2018 }
2019 }
2020 return ret;
2021}
2022
vivek mehtab6506412015-08-07 16:55:17 -07002023void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2024 snd_device_t snd_device,
2025 bool enable)
2026{
2027 const char* name;
2028 switch (snd_device) {
2029 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2030 if (enable)
2031 name = "spkr-gain-in-headphone-combo";
2032 else
2033 name = "speaker-gain-default";
2034 break;
2035 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2036 if (enable)
2037 name = "spkr-gain-in-line-combo";
2038 else
2039 name = "speaker-gain-default";
2040 break;
2041 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2042 if (enable)
2043 name = "spkr-safe-gain-in-headphone-combo";
2044 else
2045 name = "speaker-safe-gain-default";
2046 break;
2047 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2048 if (enable)
2049 name = "spkr-safe-gain-in-line-combo";
2050 else
2051 name = "speaker-safe-gain-default";
2052 break;
2053 default:
2054 return;
2055 }
2056
2057 audio_route_apply_and_update_path(adev->audio_route, name);
2058}
2059
Eric Laurentb23d5282013-05-14 15:27:20 -07002060int platform_set_voice_volume(void *platform, int volume)
2061{
2062 struct platform_data *my_data = (struct platform_data *)platform;
2063 struct audio_device *adev = my_data->adev;
2064 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002065 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002066 int vol_index = 0, ret = 0;
2067 uint32_t set_values[ ] = {0,
2068 ALL_SESSION_VSID,
2069 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002070
2071 // Voice volume levels are mapped to adsp volume levels as follows.
2072 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2073 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002074 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002075 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002076
2077 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2078 if (!ctl) {
2079 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2080 __func__, mixer_ctl_name);
2081 return -EINVAL;
2082 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002083 ALOGV("Setting voice volume index: %d", set_values[0]);
2084 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2085
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002086 if (my_data->csd != NULL) {
2087 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2088 DEFAULT_VOLUME_RAMP_DURATION_MS);
2089 if (ret < 0) {
2090 ALOGE("%s: csd_volume error %d", __func__, ret);
2091 }
2092 }
2093 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002094}
2095
2096int platform_set_mic_mute(void *platform, bool state)
2097{
2098 struct platform_data *my_data = (struct platform_data *)platform;
2099 struct audio_device *adev = my_data->adev;
2100 struct mixer_ctl *ctl;
2101 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002102 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002103 uint32_t set_values[ ] = {0,
2104 ALL_SESSION_VSID,
2105 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002106
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002107 if (adev->mode != AUDIO_MODE_IN_CALL &&
2108 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002109 return 0;
2110
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002111 if (adev->enable_hfp)
2112 mixer_ctl_name = "HFP Tx Mute";
2113
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002114 set_values[0] = state;
2115 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2116 if (!ctl) {
2117 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2118 __func__, mixer_ctl_name);
2119 return -EINVAL;
2120 }
2121 ALOGV("Setting voice mute state: %d", state);
2122 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2123
2124 if (my_data->csd != NULL) {
2125 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2126 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002127 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002128 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002129 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002130 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002131 return ret;
2132}
Eric Laurentb23d5282013-05-14 15:27:20 -07002133
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002134int platform_set_device_mute(void *platform, bool state, char *dir)
2135{
2136 struct platform_data *my_data = (struct platform_data *)platform;
2137 struct audio_device *adev = my_data->adev;
2138 struct mixer_ctl *ctl;
2139 char *mixer_ctl_name = NULL;
2140 int ret = 0;
2141 uint32_t set_values[ ] = {0,
2142 ALL_SESSION_VSID,
2143 0};
2144 if(dir == NULL) {
2145 ALOGE("%s: Invalid direction:%s", __func__, dir);
2146 return -EINVAL;
2147 }
2148
2149 if (!strncmp("rx", dir, sizeof("rx"))) {
2150 mixer_ctl_name = "Voice Rx Device Mute";
2151 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2152 mixer_ctl_name = "Voice Tx Device Mute";
2153 } else {
2154 return -EINVAL;
2155 }
2156
2157 set_values[0] = state;
2158 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2159 if (!ctl) {
2160 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2161 __func__, mixer_ctl_name);
2162 return -EINVAL;
2163 }
2164
2165 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2166 __func__,state, mixer_ctl_name);
2167 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2168
2169 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002170}
2171
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002172int platform_can_split_snd_device(snd_device_t snd_device,
2173 int *num_devices,
2174 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002175{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002176 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002177 if (NULL == num_devices || NULL == new_snd_devices) {
2178 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002179 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002180 }
2181
2182 /*
2183 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002184 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002185 */
2186 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2187 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2188 *num_devices = 2;
2189 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2190 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002191 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002192 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2193 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2194 *num_devices = 2;
2195 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2196 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002197 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002198 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2199 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2200 *num_devices = 2;
2201 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2202 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002203 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002204 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2205 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2206 *num_devices = 2;
2207 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2208 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002209 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002210 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2211 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2212 SND_DEVICE_OUT_BT_SCO)) {
2213 *num_devices = 2;
2214 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2215 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2216 ret = 0;
2217 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2218 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2219 SND_DEVICE_OUT_BT_SCO_WB)) {
2220 *num_devices = 2;
2221 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2222 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2223 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002224 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2225 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2226 *num_devices = 2;
2227 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2228 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2229 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002230 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002231 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002232}
2233
Eric Laurentb23d5282013-05-14 15:27:20 -07002234snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2235{
2236 struct platform_data *my_data = (struct platform_data *)platform;
2237 struct audio_device *adev = my_data->adev;
2238 audio_mode_t mode = adev->mode;
2239 snd_device_t snd_device = SND_DEVICE_NONE;
2240
2241 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2242 if (devices == AUDIO_DEVICE_NONE ||
2243 devices & AUDIO_DEVICE_BIT_IN) {
2244 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2245 goto exit;
2246 }
2247
Eric Laurent1b491552015-09-15 17:52:41 -07002248 if (popcount(devices) == 2) {
2249 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2250 AUDIO_DEVICE_OUT_SPEAKER) ||
2251 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2252 AUDIO_DEVICE_OUT_SPEAKER)) {
2253 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2254 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2255 AUDIO_DEVICE_OUT_SPEAKER)) {
2256 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2257 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2258 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2259 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2260 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2261 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2262 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2263 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2264 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2265 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2266 AUDIO_DEVICE_OUT_SPEAKER)) {
2267 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002268 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2269 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2270 snd_device = adev->bt_wb_speech_enabled ?
2271 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2272 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
David Linee3fe402017-03-13 10:00:42 -07002273 } else if (devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2274 AUDIO_DEVICE_OUT_SPEAKER)) {
2275 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002276 } else {
2277 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2278 goto exit;
2279 }
2280 if (snd_device != SND_DEVICE_NONE) {
2281 goto exit;
2282 }
2283 }
2284
2285 if (popcount(devices) != 1) {
2286 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2287 goto exit;
2288 }
2289
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302290 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002291 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002292 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2293 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002294 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002295 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002296 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002297 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002298 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002299 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002300 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002301 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002302 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002303 else {
2304 if (devices & AUDIO_DEVICE_OUT_LINE)
2305 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2306 else
2307 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2308 }
vivek mehtaa6b79742017-03-09 15:40:43 -08002309 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2310 if (voice_is_in_call(adev)) {
2311 switch (adev->voice.tty_mode) {
2312 case TTY_MODE_FULL:
2313 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2314 break;
2315 case TTY_MODE_VCO:
2316 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2317 break;
2318 case TTY_MODE_HCO:
2319 // since Hearing will be on handset\speaker, use existing device
2320 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2321 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002322 case TTY_MODE_OFF:
2323 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002324 default:
2325 ALOGE("%s: Invalid TTY mode (%#x)",
2326 __func__, adev->voice.tty_mode);
2327 }
2328 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002329 if (snd_device == SND_DEVICE_NONE) {
2330 snd_device = audio_extn_usb_is_capture_supported() ?
2331 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2332 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2333 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002334 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002335 if (adev->bt_wb_speech_enabled) {
2336 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2337 } else {
2338 snd_device = SND_DEVICE_OUT_BT_SCO;
2339 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002340 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002341 if (!adev->enable_hfp) {
2342 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2343 } else {
2344 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2345 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002346 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002347 if(adev->voice.hac)
2348 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2349 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002350 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2351 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002352 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002353 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2354 snd_device = SND_DEVICE_OUT_VOICE_TX;
2355
Eric Laurentb23d5282013-05-14 15:27:20 -07002356 if (snd_device != SND_DEVICE_NONE) {
2357 goto exit;
2358 }
2359 }
2360
Eric Laurentb23d5282013-05-14 15:27:20 -07002361 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2362 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2363 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002364 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2365 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002366 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2367 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002368 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002369 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002370 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2371 else
2372 snd_device = SND_DEVICE_OUT_SPEAKER;
2373 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002374 if (adev->bt_wb_speech_enabled) {
2375 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2376 } else {
2377 snd_device = SND_DEVICE_OUT_BT_SCO;
2378 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002379 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2380 snd_device = SND_DEVICE_OUT_HDMI ;
David Linee3fe402017-03-13 10:00:42 -07002381 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2382 if (audio_extn_usb_is_capture_supported())
2383 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2384 else
2385 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2386 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002387 /*HAC support for voice-ish audio (eg visual voicemail)*/
2388 if(adev->voice.hac)
2389 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2390 else
2391 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002392 } else {
2393 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2394 }
2395exit:
2396 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2397 return snd_device;
2398}
2399
2400snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2401{
2402 struct platform_data *my_data = (struct platform_data *)platform;
2403 struct audio_device *adev = my_data->adev;
2404 audio_source_t source = (adev->active_input == NULL) ?
2405 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2406
2407 audio_mode_t mode = adev->mode;
2408 audio_devices_t in_device = ((adev->active_input == NULL) ?
2409 AUDIO_DEVICE_NONE : adev->active_input->device)
2410 & ~AUDIO_DEVICE_BIT_IN;
2411 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2412 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2413 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002414 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002415
Prashant Malanic92c5962015-08-11 15:10:18 -07002416 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2417 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002418 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2419 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002420 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002421 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002422 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2423 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002424 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002425 case TTY_MODE_FULL:
2426 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2427 break;
2428 case TTY_MODE_VCO:
2429 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2430 break;
2431 case TTY_MODE_HCO:
2432 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2433 break;
2434 default:
2435 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2436 }
2437 goto exit;
2438 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2439 switch (adev->voice.tty_mode) {
2440 case TTY_MODE_FULL:
2441 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2442 break;
2443 case TTY_MODE_VCO:
2444 // since voice will be captured from handset mic, use existing device
2445 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2446 break;
2447 case TTY_MODE_HCO:
2448 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2449 break;
2450 default:
2451 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002452 }
2453 goto exit;
2454 }
2455 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002456 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002457 if (my_data->fluence_in_voice_call == false) {
2458 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2459 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002460 if (is_operator_tmus())
2461 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002462 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002463 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002464 }
2465 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2466 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2467 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002468 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002469 if (adev->bluetooth_nrec)
2470 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2471 else
2472 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002473 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002474 if (adev->bluetooth_nrec)
2475 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2476 else
2477 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002478 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002479 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002480 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2481 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2482 out_device & AUDIO_DEVICE_OUT_LINE) {
2483 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2484 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2485 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2486 } else {
2487 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2488 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002489 }
vivek mehtafe121d52015-08-10 23:39:23 -07002490
2491 //select default
2492 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002493 if (!adev->enable_hfp) {
2494 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2495 } else {
2496 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2497 platform_set_echo_reference(adev, true, out_device);
2498 }
vivek mehtafe121d52015-08-10 23:39:23 -07002499 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002500 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002501 snd_device = SND_DEVICE_IN_VOICE_RX;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002502 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2503 if (audio_extn_usb_is_capture_supported()) {
2504 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2505 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002506 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002507 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2508 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2509 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2510 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2511 }
2512 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2513 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002514 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2515 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2516 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002517 if (adev->active_input->enable_aec)
2518 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2519 else
2520 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002521 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2522 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002523 if (adev->active_input->enable_aec)
2524 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2525 else
2526 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002527 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2528 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2529 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002530 if (adev->active_input->enable_aec)
2531 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2532 else
2533 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002534 }
2535 platform_set_echo_reference(adev, true, out_device);
2536 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2537 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2538 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002539 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002540 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2541 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002542 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002543 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2544 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002545 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002546 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002547 if (adev->active_input->enable_aec) {
2548 if (adev->active_input->enable_ns) {
2549 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2550 } else {
2551 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2552 }
vivek mehta733c1df2016-04-04 15:09:24 -07002553 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002554 } else if (adev->active_input->enable_ns) {
2555 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2556 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002557 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002558 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002559 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002560 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2561 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002562 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2563 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002564 }
rago90fb9612015-12-02 11:37:53 -08002565 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2566 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002567 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2568 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2569 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2570 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002571 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002572 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2573 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002574 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002575 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2576 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2577 } else {
2578 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2579 }
rago90fb9612015-12-02 11:37:53 -08002580 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2581 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002582 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2583 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002584 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002585 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002586 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002587 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002588 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2589 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002590 if (adev->active_input->enable_aec &&
2591 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002592 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002593 if (my_data->fluence_in_spkr_mode &&
2594 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002595 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002596 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002597 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002598 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002599 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002600 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002601 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002602 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002603 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002604 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002605 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002606 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002607 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2608 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002609 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2610 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002611 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002612 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002613 } else if (adev->active_input->enable_aec) {
2614 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2615 if (my_data->fluence_in_spkr_mode &&
2616 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002617 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002618 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002619 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002620 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002621 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002622 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2623 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002624 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002625 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002626 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002627 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002628 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002629 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2630 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002631 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2632 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002633 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002634 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002635 } else if (adev->active_input->enable_ns) {
2636 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2637 if (my_data->fluence_in_spkr_mode &&
2638 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002639 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002640 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002641 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002642 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002643 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002644 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2645 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002646 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002647 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002648 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002649 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002650 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002651 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002652 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002653 }
2654 } else if (source == AUDIO_SOURCE_DEFAULT) {
2655 goto exit;
2656 }
2657
2658
2659 if (snd_device != SND_DEVICE_NONE) {
2660 goto exit;
2661 }
2662
2663 if (in_device != AUDIO_DEVICE_NONE &&
2664 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2665 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2666 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002667 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002668 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002669 snd_device = SND_DEVICE_IN_QUAD_MIC;
2670 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002671 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002672 snd_device = SND_DEVICE_IN_THREE_MIC;
2673 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2674 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002675 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002676 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2677 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002678 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002679 } else {
2680 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2681 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2682 my_data->source_mic_type, channel_count, channel_mask);
2683 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2684 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002685 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002686 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2687 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002688 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002689 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2690 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002691 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002692 } else {
2693 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2694 " no combination found .. setting to mono", __func__,
2695 my_data->source_mic_type, channel_count);
2696 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2697 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002698 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2699 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2700 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002701 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002702 if (adev->bluetooth_nrec)
2703 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2704 else
2705 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002706 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002707 if (adev->bluetooth_nrec)
2708 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2709 else
2710 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002711 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002712 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2713 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002714 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE ) {
2715 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002716 } else {
2717 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2718 ALOGW("%s: Using default handset-mic", __func__);
2719 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2720 }
2721 } else {
2722 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2723 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2724 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2725 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002726 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002727 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002728 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002729 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002730 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2731 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002732 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002733 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2734 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002735 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002736 } else {
2737 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2738 " no combination found .. setting to mono", __func__,
2739 my_data->source_mic_type, channel_count);
2740 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2741 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002742 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002743 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002744 if (adev->bluetooth_nrec)
2745 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2746 else
2747 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002748 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002749 if (adev->bluetooth_nrec)
2750 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2751 else
2752 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002753 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002754 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2755 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002756 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2757 if (audio_extn_usb_is_capture_supported())
2758 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2759 else
2760 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002761 } else {
2762 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2763 ALOGW("%s: Using default handset-mic", __func__);
2764 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2765 }
2766 }
2767exit:
2768 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2769 return snd_device;
2770}
2771
2772int platform_set_hdmi_channels(void *platform, int channel_count)
2773{
2774 struct platform_data *my_data = (struct platform_data *)platform;
2775 struct audio_device *adev = my_data->adev;
2776 struct mixer_ctl *ctl;
2777 const char *channel_cnt_str = NULL;
2778 const char *mixer_ctl_name = "HDMI_RX Channels";
2779 switch (channel_count) {
2780 case 8:
2781 channel_cnt_str = "Eight"; break;
2782 case 7:
2783 channel_cnt_str = "Seven"; break;
2784 case 6:
2785 channel_cnt_str = "Six"; break;
2786 case 5:
2787 channel_cnt_str = "Five"; break;
2788 case 4:
2789 channel_cnt_str = "Four"; break;
2790 case 3:
2791 channel_cnt_str = "Three"; break;
2792 default:
2793 channel_cnt_str = "Two"; break;
2794 }
2795 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2796 if (!ctl) {
2797 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2798 __func__, mixer_ctl_name);
2799 return -EINVAL;
2800 }
2801 ALOGV("HDMI channel count: %s", channel_cnt_str);
2802 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2803 return 0;
2804}
2805
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002806int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002807{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002808 struct platform_data *my_data = (struct platform_data *)platform;
2809 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002810 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2811 char *sad = block;
2812 int num_audio_blocks;
2813 int channel_count;
2814 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002815 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002816
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002817 struct mixer_ctl *ctl;
2818
2819 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2820 if (!ctl) {
2821 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2822 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002823 return 0;
2824 }
2825
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002826 mixer_ctl_update(ctl);
2827
2828 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002829
2830 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002831 if (count > (int)sizeof(block))
2832 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002833
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002834 ret = mixer_ctl_get_array(ctl, block, count);
2835 if (ret != 0) {
2836 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2837 return 0;
2838 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002839
2840 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002841 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002842
2843 for (i = 0; i < num_audio_blocks; i++) {
2844 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002845 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2846 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002847 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002848 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002849
2850 channel_count = (sad[0] & 0x7) + 1;
2851 if (channel_count > max_channels)
2852 max_channels = channel_count;
2853
2854 /* Advance to next block */
2855 sad += 3;
2856 }
2857
2858 return max_channels;
2859}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002860
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002861int platform_set_incall_recording_session_id(void *platform,
2862 uint32_t session_id, int rec_mode)
2863{
2864 int ret = 0;
2865 struct platform_data *my_data = (struct platform_data *)platform;
2866 struct audio_device *adev = my_data->adev;
2867 struct mixer_ctl *ctl;
2868 const char *mixer_ctl_name = "Voc VSID";
2869 int num_ctl_values;
2870 int i;
2871
2872 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2873 if (!ctl) {
2874 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2875 __func__, mixer_ctl_name);
2876 ret = -EINVAL;
2877 } else {
2878 num_ctl_values = mixer_ctl_get_num_values(ctl);
2879 for (i = 0; i < num_ctl_values; i++) {
2880 if (mixer_ctl_set_value(ctl, i, session_id)) {
2881 ALOGV("Error: invalid session_id: %x", session_id);
2882 ret = -EINVAL;
2883 break;
2884 }
2885 }
2886 }
2887
2888 if (my_data->csd != NULL) {
2889 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2890 if (ret < 0) {
2891 ALOGE("%s: csd_client_start_record failed, error %d",
2892 __func__, ret);
2893 }
2894 }
2895
2896 return ret;
2897}
2898
2899int platform_stop_incall_recording_usecase(void *platform)
2900{
2901 int ret = 0;
2902 struct platform_data *my_data = (struct platform_data *)platform;
2903
2904 if (my_data->csd != NULL) {
2905 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2906 if (ret < 0) {
2907 ALOGE("%s: csd_client_stop_record failed, error %d",
2908 __func__, ret);
2909 }
2910 }
2911
2912 return ret;
2913}
2914
2915int platform_start_incall_music_usecase(void *platform)
2916{
2917 int ret = 0;
2918 struct platform_data *my_data = (struct platform_data *)platform;
2919
2920 if (my_data->csd != NULL) {
2921 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2922 if (ret < 0) {
2923 ALOGE("%s: csd_client_start_playback failed, error %d",
2924 __func__, ret);
2925 }
2926 }
2927
2928 return ret;
2929}
2930
2931int platform_stop_incall_music_usecase(void *platform)
2932{
2933 int ret = 0;
2934 struct platform_data *my_data = (struct platform_data *)platform;
2935
2936 if (my_data->csd != NULL) {
2937 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2938 if (ret < 0) {
2939 ALOGE("%s: csd_client_stop_playback failed, error %d",
2940 __func__, ret);
2941 }
2942 }
2943
2944 return ret;
2945}
2946
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002947int platform_set_parameters(void *platform, struct str_parms *parms)
2948{
2949 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002950 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002951 char *kv_pairs = str_parms_to_str(parms);
2952 int ret = 0, err;
2953
2954 if (kv_pairs == NULL) {
2955 ret = -EINVAL;
2956 ALOGE("%s: key-value pair is NULL",__func__);
2957 goto done;
2958 }
2959
2960 ALOGV("%s: enter: %s", __func__, kv_pairs);
2961
2962 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2963 value, sizeof(value));
2964 if (err >= 0) {
2965 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2966 my_data->snd_card_name = strdup(value);
2967 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2968 }
2969
keunhui.park2f7306a2015-07-16 16:48:06 +09002970 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2971 value, sizeof(value));
2972 if (err >= 0) {
2973 struct operator_info *info;
2974 char *str = value;
2975 char *name;
2976
2977 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2978 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2979 name = strtok(str, ";");
2980 info->name = strdup(name);
2981 info->mccmnc = strdup(str + strlen(name) + 1);
2982
2983 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002984 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002985 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002986
2987 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002988 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002989 value, sizeof(value));
2990 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002991 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002992 my_data->max_mic_count = atoi(value);
2993 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002994 }
2995
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002996done:
2997 ALOGV("%s: exit with code(%d)", __func__, ret);
2998 if (kv_pairs != NULL)
2999 free(kv_pairs);
3000
3001 return ret;
3002}
3003
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003004/* Delay in Us */
3005int64_t platform_render_latency(audio_usecase_t usecase)
3006{
3007 switch (usecase) {
3008 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3009 return DEEP_BUFFER_PLATFORM_DELAY;
3010 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3011 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003012 case USECASE_AUDIO_PLAYBACK_ULL:
3013 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003014 case USECASE_AUDIO_PLAYBACK_MMAP:
3015 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003016 default:
3017 return 0;
3018 }
3019}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003020
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003021int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3022 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003023{
3024 int ret = 0;
3025
3026 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3027 ALOGE("%s: Invalid snd_device = %d",
3028 __func__, device);
3029 ret = -EINVAL;
3030 goto done;
3031 }
3032
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003033 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3034 platform_get_snd_device_name(device),
3035 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3036 if (backend_tag_table[device]) {
3037 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003038 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003039 backend_tag_table[device] = strdup(backend_tag);
3040
3041 if (hw_interface != NULL) {
3042 if (hw_interface_table[device])
3043 free(hw_interface_table[device]);
3044 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3045 hw_interface_table[device] = strdup(hw_interface);
3046 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003047done:
3048 return ret;
3049}
3050
3051int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3052{
3053 int ret = 0;
3054 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3055 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3056 ret = -EINVAL;
3057 goto done;
3058 }
3059
3060 if ((type != 0) && (type != 1)) {
3061 ALOGE("%s: invalid usecase type", __func__);
3062 ret = -EINVAL;
3063 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003064 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3065 use_case_table[usecase],
3066 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003067 pcm_device_table[usecase][type] = pcm_id;
3068done:
3069 return ret;
3070}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003071
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003072#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3073int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3074 // backup_gain: gain to try to set in case of an error during ramp
3075 int start_gain, end_gain, step, backup_gain, i;
3076 bool error = false;
3077 const struct mixer_ctl *ctl;
3078 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3079 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3080 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3081 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3082 if (!ctl_left || !ctl_right) {
3083 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3084 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3085 return -EINVAL;
3086 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3087 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3088 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3089 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3090 return -EINVAL;
3091 }
3092 if (ramp_up) {
3093 start_gain = 0;
3094 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3095 step = +1;
3096 backup_gain = end_gain;
3097 } else {
3098 // using same gain on left and right
3099 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3100 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3101 end_gain = 0;
3102 step = -1;
3103 backup_gain = start_gain;
3104 }
3105 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3106 //ALOGV("setting speaker gain to %d", i);
3107 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3108 ALOGE("%s: error setting %s to %d during gain ramp",
3109 __func__, mixer_ctl_name_gain_left, i);
3110 error = true;
3111 break;
3112 }
3113 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3114 ALOGE("%s: error setting %s to %d during gain ramp",
3115 __func__, mixer_ctl_name_gain_right, i);
3116 error = true;
3117 break;
3118 }
3119 usleep(1000);
3120 }
3121 if (error) {
3122 // an error occured during the ramp, let's still try to go back to a safe volume
3123 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3124 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3125 }
3126 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3127 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3128 }
3129 }
3130 return start_gain;
3131}
3132
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003133int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
3134{
3135 // only update if there is active pcm playback on speaker
3136 struct audio_usecase *usecase;
3137 struct listnode *node;
3138 struct platform_data *my_data = (struct platform_data *)adev->platform;
3139
3140 if (my_data->speaker_lr_swap != swap_channels) {
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003141
3142 // do not swap channels in audio modes with concurrent capture and playback
3143 // as this may break the echo reference
3144 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3145 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3146 return 0;
3147 }
3148
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003149 my_data->speaker_lr_swap = swap_channels;
3150
3151 list_for_each(node, &adev->usecase_list) {
3152 usecase = node_to_item(node, struct audio_usecase, list);
3153 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003154 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3155 /*
3156 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3157 * to perform device switch to disable the current backend to
3158 * enable it with new acdb data.
3159 */
3160 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3161 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003162 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003163 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003164 if (initial_skpr_gain != -EINVAL) {
3165 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3166 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003167 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003168 const char *mixer_path;
3169 if (swap_channels) {
3170 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3171 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3172 } else {
3173 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3174 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3175 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003176 }
3177 break;
3178 }
3179 }
3180 }
3181 return 0;
3182}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003183
3184static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3185static int num_gain_tbl_entry = 0;
3186
3187bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3188
3189 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3190 if (num_gain_tbl_entry == -1) {
3191 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3192 __func__);
3193 return false;
3194 }
3195
3196 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3197 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3198 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3199 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3200 return false;
3201 }
3202
3203 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3204 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3205 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3206 return false;
3207 }
3208
3209 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3210 ++num_gain_tbl_entry;
3211
3212 return true;
3213}
3214
3215int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3216 int table_size) {
3217 int itt = 0;
3218 ALOGV("platform_get_gain_level_mapping called ");
3219
3220 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3221 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3222 return 0;
3223 }
3224
3225 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3226 mapping_tbl[itt] = tbl_mapping[itt];
3227 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3228 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3229 }
3230
3231 return num_gain_tbl_entry;
3232}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003233
3234int platform_snd_card_update(void *platform, card_status_t status)
3235{
3236 struct platform_data *my_data = (struct platform_data *)platform;
3237 struct audio_device *adev = my_data->adev;
3238
3239 if (status == CARD_STATUS_ONLINE) {
3240 if (my_data->acdb_send_custom_top)
3241 my_data->acdb_send_custom_top();
3242 }
3243 return 0;
3244}
David Linee3fe402017-03-13 10:00:42 -07003245
3246/*
3247 * configures afe with bit width and Sample Rate
3248 */
3249static int platform_set_backend_cfg(const struct audio_device* adev,
3250 snd_device_t snd_device,
3251 const struct audio_backend_cfg *backend_cfg)
3252{
3253
3254 int ret = 0;
3255 const int backend_idx = platform_get_backend_index(snd_device);
3256 struct platform_data *my_data = (struct platform_data *)adev->platform;
3257 const unsigned int bit_width = backend_cfg->bit_width;
3258 const unsigned int sample_rate = backend_cfg->sample_rate;
3259 const unsigned int channels = backend_cfg->channels;
3260 const audio_format_t format = backend_cfg->format;
3261 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3262
3263
3264 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3265 ", backend_idx %d device (%s)", __func__, bit_width,
3266 sample_rate, channels, backend_idx,
3267 platform_get_snd_device_name(snd_device));
3268
3269 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3270 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3271
3272 struct mixer_ctl *ctl = NULL;
3273 ctl = mixer_get_ctl_by_name(adev->mixer,
3274 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3275 if (!ctl) {
3276 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3277 __func__,
3278 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3279 return -EINVAL;
3280 }
3281
3282 if (bit_width == 24) {
3283 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3284 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3285 else
3286 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3287 } else if (bit_width == 32) {
3288 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3289 } else {
3290 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3291 }
3292 if ( ret < 0) {
3293 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3294 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3295 } else {
3296 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3297 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3298 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3299 }
3300 /* set the ret as 0 and not pass back to upper layer */
3301 ret = 0;
3302 }
3303
3304 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3305 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3306 char *rate_str = NULL;
3307 struct mixer_ctl *ctl = NULL;
3308
3309 switch (sample_rate) {
3310 case 32000:
3311 if (passthrough_enabled) {
3312 rate_str = "KHZ_32";
3313 break;
3314 }
3315 case 8000:
3316 case 11025:
3317 case 16000:
3318 case 22050:
3319 case 48000:
3320 rate_str = "KHZ_48";
3321 break;
3322 case 44100:
3323 rate_str = "KHZ_44P1";
3324 break;
3325 case 64000:
3326 case 96000:
3327 rate_str = "KHZ_96";
3328 break;
3329 case 88200:
3330 rate_str = "KHZ_88P2";
3331 break;
3332 case 176400:
3333 rate_str = "KHZ_176P4";
3334 break;
3335 case 192000:
3336 rate_str = "KHZ_192";
3337 break;
3338 case 352800:
3339 rate_str = "KHZ_352P8";
3340 break;
3341 case 384000:
3342 rate_str = "KHZ_384";
3343 break;
3344 case 144000:
3345 if (passthrough_enabled) {
3346 rate_str = "KHZ_144";
3347 break;
3348 }
3349 default:
3350 rate_str = "KHZ_48";
3351 break;
3352 }
3353
3354 ctl = mixer_get_ctl_by_name(adev->mixer,
3355 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3356 if(!ctl) {
3357 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3358 __func__,
3359 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3360 return -EINVAL;
3361 }
3362
3363 ALOGD("%s:becf: afe: %s set to %s", __func__,
3364 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3365 mixer_ctl_set_enum_by_string(ctl, rate_str);
3366 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3367 }
3368 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3369 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3370 struct mixer_ctl *ctl = NULL;
3371 char *channel_cnt_str = NULL;
3372
3373 switch (channels) {
3374 case 8:
3375 channel_cnt_str = "Eight"; break;
3376 case 7:
3377 channel_cnt_str = "Seven"; break;
3378 case 6:
3379 channel_cnt_str = "Six"; break;
3380 case 5:
3381 channel_cnt_str = "Five"; break;
3382 case 4:
3383 channel_cnt_str = "Four"; break;
3384 case 3:
3385 channel_cnt_str = "Three"; break;
3386 case 1:
3387 channel_cnt_str = "One"; break;
3388 case 2:
3389 default:
3390 channel_cnt_str = "Two"; break;
3391 }
3392
3393 ctl = mixer_get_ctl_by_name(adev->mixer,
3394 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3395 if (!ctl) {
3396 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3397 __func__,
3398 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3399 return -EINVAL;
3400 }
3401 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3402 my_data->current_backend_cfg[backend_idx].channels = channels;
3403
3404 // skip EDID configuration for HDMI backend
3405
3406 ALOGD("%s:becf: afe: %s set to %s", __func__,
3407 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3408 channel_cnt_str);
3409 }
3410
3411 // skip set ext_display format mixer control
3412 return ret;
3413}
3414
3415static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3416{
3417 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3418 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3419 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3420 }
3421
3422 return backend_bit_width_table[snd_device];
3423}
3424
3425/*
3426 * return backend_idx on which voice call is active
3427 */
3428static int platform_get_voice_call_backend(struct audio_device* adev)
3429{
3430 struct audio_usecase *uc = NULL;
3431 struct listnode *node;
3432 snd_device_t out_snd_device = SND_DEVICE_NONE;
3433
3434 int backend_idx = -1;
3435
3436 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3437 list_for_each(node, &adev->usecase_list) {
3438 uc = node_to_item(node, struct audio_usecase, list);
3439 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3440 out_snd_device = platform_get_output_snd_device(adev->platform,
3441 uc->stream.out->devices);
3442 backend_idx = platform_get_backend_index(out_snd_device);
3443 break;
3444 }
3445 }
3446 }
3447 return backend_idx;
3448}
3449
3450/*
3451 * goes through all the current usecases and picks the highest
3452 * bitwidth & samplerate
3453 */
3454static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3455 int backend_idx,
3456 struct audio_backend_cfg *backend_cfg)
3457{
3458 bool backend_change = false;
3459 unsigned int bit_width;
3460 unsigned int sample_rate;
3461 unsigned int channels;
3462 struct platform_data *my_data = (struct platform_data *)adev->platform;
3463
3464 bit_width = backend_cfg->bit_width;
3465 sample_rate = backend_cfg->sample_rate;
3466 channels = backend_cfg->channels;
3467
3468 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3469 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3470 sample_rate, channels);
3471
3472 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3473 // default backend
3474 // force routing is not required here, caller will do it anyway
3475 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3476 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3477 "for unprocessed/camera source", __func__);
3478 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3479 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3480 }
3481
3482 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3483 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3484 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3485 __func__, bit_width, sample_rate, channels);
3486 }
3487
3488 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3489 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3490
3491 // Force routing if the expected bitwdith or samplerate
3492 // is not same as current backend comfiguration
3493 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3494 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3495 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3496 backend_cfg->bit_width = bit_width;
3497 backend_cfg->sample_rate= sample_rate;
3498 backend_cfg->channels = channels;
3499 backend_change = true;
3500 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3501 "new sample rate: %d new channel: %d",
3502 __func__, backend_cfg->bit_width,
3503 backend_cfg->sample_rate, backend_cfg->channels);
3504 }
3505
3506 return backend_change;
3507}
3508
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003509static void pick_playback_cfg_for_uc(struct audio_device *adev,
3510 struct audio_usecase *usecase,
3511 snd_device_t snd_device,
3512 unsigned int *bit_width,
3513 unsigned int *sample_rate,
3514 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003515{
3516 int i =0;
3517 struct listnode *node;
3518 list_for_each(node, &adev->usecase_list) {
3519 struct audio_usecase *uc;
3520 uc = node_to_item(node, struct audio_usecase, list);
3521 struct stream_out *out = (struct stream_out*) uc->stream.out;
3522 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3523 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3524 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3525 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3526 uc->id, out->sample_rate,
3527 pcm_format_to_bits(out->config.format), out_channels,
3528 platform_get_snd_device_name(uc->out_snd_device));
3529
3530 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3531 if (*bit_width < pcm_format_to_bits(out->config.format))
3532 *bit_width = pcm_format_to_bits(out->config.format);
3533 if (*sample_rate < out->sample_rate)
3534 *sample_rate = out->sample_rate;
3535 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3536 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3537 if (*channels < out_channels)
3538 *channels = out_channels;
3539 }
3540 }
3541 }
3542 return;
3543}
3544
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003545static void headset_is_config_supported(unsigned int *bit_width,
3546 unsigned int *sample_rate,
3547 unsigned int *channels) {
3548 switch (*bit_width) {
3549 case 16:
3550 case 24:
3551 break;
3552 default:
3553 *bit_width = 16;
3554 break;
3555 }
3556
3557 if (*sample_rate > 192000) {
3558 *sample_rate = 192000;
3559 }
3560
3561 if (*channels > 2) {
3562 *channels = 2;
3563 }
3564}
3565
David Linee3fe402017-03-13 10:00:42 -07003566static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3567 struct audio_usecase* usecase,
3568 snd_device_t snd_device,
3569 struct audio_backend_cfg *backend_cfg)
3570{
3571 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003572 unsigned int bit_width;
3573 unsigned int sample_rate;
3574 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003575 int backend_idx = DEFAULT_CODEC_BACKEND;
3576 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003577
3578 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3579 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3580 backend_change = false;
3581 return backend_change;
3582 }
3583
3584 backend_idx = platform_get_backend_index(snd_device);
3585 bit_width = backend_cfg->bit_width;
3586 sample_rate = backend_cfg->sample_rate;
3587 channels = backend_cfg->channels;
3588
3589 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3590 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3591 sample_rate, channels, backend_idx, usecase->id,
3592 platform_get_snd_device_name(snd_device));
3593
3594 if (backend_idx == platform_get_voice_call_backend(adev)) {
3595 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3596 __func__);
3597 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3598 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3599 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3600 } else {
3601 /*
3602 * The backend should be configured at highest bit width and/or
3603 * sample rate amongst all playback usecases.
3604 * If the selected sample rate and/or bit width differ with
3605 * current backend sample rate and/or bit width, then, we set the
3606 * backend re-configuration flag.
3607 *
3608 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3609 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003610 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3611 &bit_width,
3612 &sample_rate,
3613 &channels);
David Linee3fe402017-03-13 10:00:42 -07003614 }
3615
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003616 switch (backend_idx) {
3617 case USB_AUDIO_RX_BACKEND:
3618 audio_extn_usb_is_config_supported(&bit_width,
3619 &sample_rate, &channels, true);
3620 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3621 __func__, bit_width, sample_rate, channels);
3622 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003623 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003624 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3625 break;
3626 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003627 default:
3628 bit_width = platform_get_snd_device_bit_width(snd_device);
3629 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3630 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3631 break;
David Linee3fe402017-03-13 10:00:42 -07003632 }
3633
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003634 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3635 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003636 __func__, backend_idx , bit_width, sample_rate);
3637
3638 // Force routing if the expected bitwdith or samplerate
3639 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003640 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3641 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3642 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003643 backend_cfg->bit_width = bit_width;
3644 backend_cfg->sample_rate = sample_rate;
3645 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003646 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003647 backend_change = true;
3648 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3649 "new sample rate: %d new channels: %d",
3650 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3651 }
3652
3653 return backend_change;
3654}
3655
3656bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3657 struct audio_usecase *usecase, snd_device_t snd_device)
3658{
3659 int backend_idx = DEFAULT_CODEC_BACKEND;
3660 int new_snd_devices[SND_DEVICE_OUT_END];
3661 int i, num_devices = 1;
3662 bool ret = false;
3663 struct platform_data *my_data = (struct platform_data *)adev->platform;
3664 struct audio_backend_cfg backend_cfg;
3665
3666 backend_idx = platform_get_backend_index(snd_device);
3667
3668 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3669 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3670 backend_cfg.format = usecase->stream.out->format;
3671 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3672 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3673 backend_cfg.passthrough_enabled = false;
3674
3675 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3676 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3677 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3678 platform_get_snd_device_name(snd_device));
3679
3680 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3681 new_snd_devices[0] = snd_device;
3682
3683 for (i = 0; i < num_devices; i++) {
3684 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3685 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3686 &backend_cfg))) {
3687 platform_set_backend_cfg(adev, new_snd_devices[i],
3688 &backend_cfg);
3689 ret = true;
3690 }
3691 }
3692 return ret;
3693}
3694
3695bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3696 struct audio_usecase *usecase, snd_device_t snd_device)
3697{
3698 int backend_idx = platform_get_backend_index(snd_device);
3699 int ret = 0;
3700 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003701 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003702
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003703 if (usecase->type == PCM_CAPTURE) {
3704 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003705 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3706 } else {
3707 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3708 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3709 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3710 backend_cfg.channels = 1;
3711 }
3712
3713 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3714 ", backend_idx %d usecase = %d device (%s)", __func__,
3715 backend_cfg.bit_width,
3716 backend_cfg.sample_rate,
3717 backend_cfg.channels,
3718 backend_idx, usecase->id,
3719 platform_get_snd_device_name(snd_device));
3720
3721 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3722 ret = platform_set_backend_cfg(adev, snd_device,
3723 &backend_cfg);
3724 if(!ret)
3725 return true;
3726 }
3727
3728 return false;
3729}
3730
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003731static int max_be_dai_names = 0;
3732static const struct be_dai_name_struct *be_dai_name_table;
3733
3734/*
3735 * Retrieves the be_dai_name_table from kernel to enable a mapping
3736 * between sound device hw interfaces and backend IDs. This allows HAL to
3737 * specify the backend a specific calibration is needed for.
3738 */
3739static int init_be_dai_name_table(struct audio_device *adev)
3740{
3741 const char *mixer_ctl_name = "Backend DAI Name Table";
3742 struct mixer_ctl *ctl;
3743 int i, j, ret, size;
3744 bool valid_hw_interface;
3745
3746 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3747 if (!ctl) {
3748 ALOGE("%s: Could not get ctl for mixer name %s\n",
3749 __func__, mixer_ctl_name);
3750 ret = -EINVAL;
3751 goto done;
3752 }
3753
3754 mixer_ctl_update(ctl);
3755
3756 size = mixer_ctl_get_num_values(ctl);
3757 if (size <= 0){
3758 ALOGE("%s: Failed to get %s size %d\n",
3759 __func__, mixer_ctl_name, size);
3760 ret = -EFAULT;
3761 goto done;
3762 }
3763
vivek mehtaa68fea62017-06-08 19:04:02 -07003764 be_dai_name_table =
3765 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003766 if (be_dai_name_table == NULL) {
3767 ALOGE("%s: Failed to allocate memory for %s\n",
3768 __func__, mixer_ctl_name);
3769 ret = -ENOMEM;
3770 goto freeMem;
3771 }
3772
3773 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
3774 if (ret) {
3775 ALOGE("%s: Failed to get %s, ret %d\n",
3776 __func__, mixer_ctl_name, ret);
3777 ret = -EFAULT;
3778 goto freeMem;
3779 }
3780
3781 if (be_dai_name_table != NULL) {
3782 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
3783 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
3784 __func__, mixer_ctl_name, max_be_dai_names);
3785 ret = 0;
3786 } else {
3787 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
3788 ret = -EFAULT;
3789 goto freeMem;
3790 }
3791
3792 /*
3793 * Validate all sound devices have a valid backend set to catch
3794 * errors for uncommon sound devices
3795 */
3796 for (i = 0; i < SND_DEVICE_MAX; i++) {
3797 valid_hw_interface = false;
3798
3799 if (hw_interface_table[i] == NULL) {
3800 ALOGW("%s: sound device %s has no hw interface set\n",
3801 __func__, platform_get_snd_device_name(i));
3802 continue;
3803 }
3804
3805 for (j = 0; j < max_be_dai_names; j++) {
3806 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
3807 == 0) {
3808 valid_hw_interface = true;
3809 break;
3810 }
3811 }
3812 if (!valid_hw_interface)
3813 ALOGD("%s: sound device %s does not have a valid hw interface set "
3814 "(disregard for combo devices) %s\n",
3815 __func__, platform_get_snd_device_name(i),
3816 hw_interface_table[i]);
3817 }
3818
3819 goto done;
3820
3821freeMem:
3822 if (be_dai_name_table) {
3823 free((void *)be_dai_name_table);
3824 be_dai_name_table = NULL;
3825 }
3826
3827done:
3828 return ret;
3829}
3830
3831int platform_get_snd_device_backend_index(snd_device_t device)
3832{
3833 int i, be_dai_id;
3834 const char * hw_interface_name = NULL;
3835
3836 ALOGV("%s: enter with device %d\n", __func__, device);
3837
vivek mehtaa68fea62017-06-08 19:04:02 -07003838 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003839 ALOGE("%s: Invalid snd_device = %d",
3840 __func__, device);
3841 be_dai_id = -EINVAL;
3842 goto done;
3843 }
3844
3845 /* Get string value of necessary backend for device */
3846 hw_interface_name = hw_interface_table[device];
3847 if (hw_interface_name == NULL) {
3848 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
3849 be_dai_id = -EINVAL;
3850 goto done;
3851 }
3852
3853 /* Check if be dai name table was retrieved successfully */
3854 if (be_dai_name_table == NULL) {
3855 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
3856 be_dai_id = -EFAULT;
3857 goto done;
3858 }
3859
3860 /* Get backend ID for device specified */
3861 for (i = 0; i < max_be_dai_names; i++) {
3862 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
3863 be_dai_id = be_dai_name_table[i].be_id;
3864 goto done;
3865 }
3866 }
3867 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
3868 be_dai_id = -EINVAL;
3869 goto done;
3870
3871done:
3872 return be_dai_id;
3873}
3874
3875void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
3876 unsigned int stream_sr, int* sample_rate)
3877{
3878 struct platform_data* my_data = (struct platform_data *)platform;
3879 int backend_idx = platform_get_backend_index(snd_device);
3880 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
3881 /*
3882 *Check if device SR is multiple of 8K or 11.025 Khz
3883 *check if the stream SR is multiple of same base, if yes
3884 *then have copp SR equal to stream SR, this ensures that
3885 *post processing happens at stream SR, else have
3886 *copp SR equal to device SR.
3887 */
3888 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
3889 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
3890 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
3891 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
3892 *sample_rate = device_sr;
3893 } else
3894 *sample_rate = stream_sr;
3895
3896 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
3897 , *sample_rate);
3898
3899}
3900
3901// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07003902void platform_add_app_type(const char *uc_type,
3903 const char *mode,
3904 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003905 int app_type, int max_rate) {
3906 struct app_type_entry *ap =
3907 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
3908
3909 if (!ap) {
3910 ALOGE("%s failed to allocate mem for app type", __func__);
3911 return;
3912 }
3913
3914 ap->uc_type = -1;
3915 for (int i=0; i<USECASE_TYPE_MAX; i++) {
3916 if (!strcmp(uc_type, usecase_type_index[i].name)) {
3917 ap->uc_type = usecase_type_index[i].index;
3918 break;
3919 }
3920 }
3921
3922 if (ap->uc_type == -1) {
3923 free(ap);
3924 return;
3925 }
3926
vivek mehtaa68fea62017-06-08 19:04:02 -07003927 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
3928 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003929 ap->bit_width = bw;
3930 ap->app_type = app_type;
3931 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07003932 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003933 list_add_tail(&app_type_entry_list, &ap->node);
3934}
3935
3936
3937int platform_get_default_app_type_v2(void *platform __unused,
3938 usecase_type_t type,
3939 int *app_type )
3940{
3941 if (type == PCM_PLAYBACK)
3942 *app_type = DEFAULT_APP_TYPE_RX_PATH;
3943 else
3944 *app_type = DEFAULT_APP_TYPE_TX_PATH;
3945 return 0;
3946}
3947
vivek mehtaa68fea62017-06-08 19:04:02 -07003948int platform_get_app_type_v2(void *platform,
3949 usecase_type_t uc_type,
3950 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003951 int bw, int sr __unused,
3952 int *app_type)
3953{
3954 struct listnode *node;
3955 struct app_type_entry *entry;
3956 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07003957
3958 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
3959 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003960 list_for_each(node, &app_type_entry_list) {
3961 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07003962 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
3963 __func__, entry->uc_type, entry->mode, entry->bit_width,
3964 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003965 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07003966 entry->uc_type == uc_type &&
3967 sr <= entry->max_rate &&
3968 entry->mode && !strcmp(mode, entry->mode)) {
3969 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003970 *app_type = entry->app_type;
3971 break;
3972 }
3973 }
3974
3975 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07003976 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003977 return platform_get_default_app_type_v2(platform, uc_type, app_type);
3978 }
3979 return 0;
3980}