blob: ceec5e81dda5edb85fda81f612285da82ee77d0a [file] [log] [blame]
Naresh Tannirue3b18452014-03-04 14:44:27 +05301/*
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08002 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303 * Not a Contribution.
4 *
Naresh Tannirue3b18452014-03-04 14:44:27 +05305 * Copyright (C) 2013 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053020#define LOG_TAG "msm8916_platform"
Naresh Tannirue3b18452014-03-04 14:44:27 +053021/*#define LOG_NDEBUG 0*/
22#define LOG_NDDEBUG 0
23
24#include <stdlib.h>
25#include <dlfcn.h>
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +053026#include <fcntl.h>
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -070027#include <sys/ioctl.h>
Naresh Tannirue3b18452014-03-04 14:44:27 +053028#include <cutils/log.h>
29#include <cutils/properties.h>
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053030#include <cutils/str_parms.h>
Naresh Tannirue3b18452014-03-04 14:44:27 +053031#include <audio_hw.h>
32#include <platform_api.h>
33#include "platform.h"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053034#include "audio_extn.h"
35#include "voice_extn.h"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +053036#include "edid.h"
37#include "sound/compress_params.h"
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +053038#include "sound/msmcal-hwdep.h"
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +053039#include <dirent.h>
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +053040#define SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID (100)
Naresh Tannirue3b18452014-03-04 14:44:27 +053041
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053042#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Asish Bhattacharya4ff24802014-04-24 17:46:54 +053043#define MIXER_XML_PATH_MTP "/system/etc/mixer_paths_mtp.xml"
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +053044#define MIXER_XML_PATH_MSM8909_PM8916 "/system/etc/mixer_paths_msm8909_pm8916.xml"
Walter Yang7ca90d92014-05-06 17:48:02 +080045#define MIXER_XML_PATH_QRD_SKUH "/system/etc/mixer_paths_qrd_skuh.xml"
46#define MIXER_XML_PATH_QRD_SKUI "/system/etc/mixer_paths_qrd_skui.xml"
Walter Yang19f244a2014-06-17 13:30:08 +080047#define MIXER_XML_PATH_QRD_SKUHF "/system/etc/mixer_paths_qrd_skuhf.xml"
Meng Wangf00485b2014-06-03 19:44:38 +080048#define MIXER_XML_PATH_SKUK "/system/etc/mixer_paths_skuk.xml"
Walter Yang42886c52014-10-23 14:31:48 +080049#define MIXER_XML_PATH_SKUA "/system/etc/mixer_paths_skua.xml"
50#define MIXER_XML_PATH_SKUC "/system/etc/mixer_paths_skuc.xml"
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +053051#define MIXER_XML_PATH_SKUE "/system/etc/mixer_paths_skue.xml"
Meng Wangcfefb8b2014-12-05 14:35:55 +080052#define MIXER_XML_PATH_SKUL "/system/etc/mixer_paths_skul.xml"
Walter Yangcd132722015-04-08 16:04:30 +080053#define MIXER_XML_PATH_SKUM "/system/etc/mixer_paths_qrd_skum.xml"
Meng Wangf00485b2014-06-03 19:44:38 +080054#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053055#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +053056#define MIXER_XML_PATH_I2S "/system/etc/mixer_paths_i2s.xml"
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +053057#define MIXER_XML_PATH_WCD9306 "/system/etc/mixer_paths_wcd9306.xml"
Aviral Gupta8ed0eec2014-08-25 10:22:11 +053058#define MIXER_XML_PATH_WCD9330 "/system/etc/mixer_paths_wcd9330.xml"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053059#define PLATFORM_INFO_XML_PATH "/system/etc/audio_platform_info.xml"
Dhananjay Kumara68d7af2015-05-25 19:11:30 +053060#define PLATFORM_INFO_XML_PATH_EXTCODEC "/system/etc/audio_platform_info_extcodec.xml"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +053061
Naresh Tannirue3b18452014-03-04 14:44:27 +053062#define LIB_ACDB_LOADER "libacdbloader.so"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053063#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Avinash Vaish71c066d2014-08-27 12:32:35 +053064#define CVD_VERSION_MIXER_CTL "CVD Version"
Naresh Tannirue3b18452014-03-04 14:44:27 +053065
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053066#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
67#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
68#define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
69#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
70/* Used in calculating fragment size for pcm offload */
Alexy Joseph2ce25e22015-06-18 12:02:01 -070071#define PCM_OFFLOAD_BUFFER_DURATION 40 /* 40 millisecs */
Naresh Tannirue3b18452014-03-04 14:44:27 +053072
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053073/* MAX PCM fragment size cannot be increased further due
74 * to flinger's cblk size of 1mb,and it has to be a multiple of
75 * 24 - lcm of channels supported by DSP
Naresh Tannirue3b18452014-03-04 14:44:27 +053076 */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053077#define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024)
Naresh Tannirude7d1752015-07-01 15:07:46 +053078#define MIN_PCM_OFFLOAD_FRAGMENT_SIZE 512
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +053079
80/*
81 * Offload buffer size for compress passthrough
82 */
83#define MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (2 * 1024)
84#define MAX_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (8 * 1024)
Naresh Tannirue3b18452014-03-04 14:44:27 +053085
Preetam Singh Ranawat6efde5c2015-04-24 11:04:22 +053086#define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y))
87#define ALIGN(x, y) ((y) * DIV_ROUND_UP((x), (y)))
Naresh Tannirue3b18452014-03-04 14:44:27 +053088/*
89 * This file will have a maximum of 38 bytes:
90 *
91 * 4 bytes: number of audio blocks
92 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
93 * Maximum 10 * 3 bytes: SAD blocks
94 */
95#define MAX_SAD_BLOCKS 10
96#define SAD_BLOCK_SIZE 3
Avinash Vaish71c066d2014-08-27 12:32:35 +053097#define MAX_CVD_VERSION_STRING_SIZE 100
Naresh Tannirue3b18452014-03-04 14:44:27 +053098
99/* EDID format ID for LPCM audio */
100#define EDID_FORMAT_LPCM 1
101
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700102/* fallback app type if the default app type from acdb loader fails */
103#define DEFAULT_APP_TYPE 0x11130
Naresh Tanniru2727f822015-05-11 15:27:08 +0530104#define DEFAULT_APP_TYPE_RX_PATH 0x11130
105#define DEFAULT_APP_TYPE_TX_PATH 0x11132
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700106
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530107/* Retry for delay in FW loading*/
108#define RETRY_NUMBER 20
109#define RETRY_US 500000
110#define MAX_SND_CARD 8
111
112#define SAMPLE_RATE_8KHZ 8000
113#define SAMPLE_RATE_16KHZ 16000
114
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530115#define MAX_SET_CAL_BYTE_SIZE 65536
116
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530117#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530118#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530119#define AUDIO_PARAMETER_KEY_HD_VOICE "hd_voice"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530120#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530121#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
122#define AUDIO_PARAMETER_KEY_AUD_CALRESULT "cal_result"
123
124
125/* Query external audio device connection status */
126#define AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE "ext_audio_device"
127
128#define EVENT_EXTERNAL_SPK_1 "qc_ext_spk_1"
129#define EVENT_EXTERNAL_SPK_2 "qc_ext_spk_2"
130#define EVENT_EXTERNAL_MIC "qc_ext_mic"
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530131#define MAX_CAL_NAME 20
132
133char cal_name_info[WCD9XXX_MAX_CAL][MAX_CAL_NAME] = {
134 [WCD9XXX_ANC_CAL] = "anc_cal",
135 [WCD9XXX_MBHC_CAL] = "mbhc_cal",
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530136};
137
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530138#define AUDIO_PARAMETER_KEY_REC_PLAY_CONC "rec_play_conc_on"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530139
140enum {
141 VOICE_FEATURE_SET_DEFAULT,
142 VOICE_FEATURE_SET_VOLUME_BOOST
143};
144
Naresh Tannirue3b18452014-03-04 14:44:27 +0530145struct audio_block_header
146{
147 int reserved;
148 int length;
149};
150
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530151typedef struct acdb_audio_cal_cfg {
152 uint32_t persist;
153 uint32_t snd_dev_id;
154 audio_devices_t dev_id;
155 int32_t acdb_dev_id;
156 uint32_t app_type;
157 uint32_t topo_id;
158 uint32_t sampling_rate;
159 uint32_t cal_type;
160 uint32_t module_id;
161 uint32_t param_id;
162} acdb_audio_cal_cfg_t;
163
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530164/* Audio calibration related functions */
Naresh Tannirue3b18452014-03-04 14:44:27 +0530165typedef void (*acdb_deallocate_t)();
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530166typedef int (*acdb_init_t)(const char *, char *, int);
167typedef void (*acdb_send_audio_cal_t)(int, int, int , int);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530168typedef void (*acdb_send_voice_cal_t)(int, int);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530169typedef int (*acdb_reload_vocvoltable_t)(int);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700170typedef int (*acdb_get_default_app_type_t)(void);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530171typedef int (*acdb_loader_get_calibration_t)(char *attr, int size, void *data);
172acdb_loader_get_calibration_t acdb_loader_get_calibration;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530173typedef int (*acdb_set_audio_cal_t) (void *, void *, uint32_t);
174typedef int (*acdb_get_audio_cal_t) (void *, void *, uint32_t*);
Ben Rombergerfeca4b82015-07-07 20:40:44 -0700175typedef int (*acdb_send_common_top_t) (void);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530176
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530177typedef struct codec_backend_cfg {
178 uint32_t sample_rate;
179 uint32_t bit_width;
180 char *bitwidth_mixer_ctl;
181 char *samplerate_mixer_ctl;
182} codec_backend_cfg_t;
183
184typedef struct {
185 bool platform_na_prop_enabled;
186 bool ui_na_prop_enabled;
187} native_audio_prop;
188
189static native_audio_prop na_props = {0, 0};
190
Naresh Tannirue3b18452014-03-04 14:44:27 +0530191struct platform_data {
192 struct audio_device *adev;
193 bool fluence_in_spkr_mode;
194 bool fluence_in_voice_call;
195 bool fluence_in_voice_rec;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530196 bool fluence_in_audio_rec;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530197 bool external_spk_1;
198 bool external_spk_2;
199 bool external_mic;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530200 int fluence_type;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530201 char fluence_cap[PROPERTY_VALUE_MAX];
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530202 int fluence_mode;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530203 bool slowtalk;
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530204 bool hd_voice;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530205 bool ec_ref_enabled;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530206 bool is_wsa_speaker;
Ramjee Singh203473b2015-06-09 15:18:42 +0530207 bool is_acdb_initialized;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530208 /* Audio calibration related functions */
209 void *acdb_handle;
210 int voice_feature_set;
211 acdb_init_t acdb_init;
212 acdb_deallocate_t acdb_deallocate;
213 acdb_send_audio_cal_t acdb_send_audio_cal;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530214 acdb_set_audio_cal_t acdb_set_audio_cal;
215 acdb_get_audio_cal_t acdb_get_audio_cal;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530216 acdb_send_voice_cal_t acdb_send_voice_cal;
217 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700218 acdb_get_default_app_type_t acdb_get_default_app_type;
Ben Rombergerfeca4b82015-07-07 20:40:44 -0700219 acdb_send_common_top_t acdb_send_common_top;
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530220#ifdef RECORD_PLAY_CONCURRENCY
221 bool rec_play_conc_set;
222#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530223 void *hw_info;
224 struct csd_data *csd;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530225 void *edid_info;
226 bool edid_valid;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530227 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Naresh Tannirue3b18452014-03-04 14:44:27 +0530228};
229
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530230static bool is_external_codec = false;
231static const int pcm_device_table_of_ext_codec[AUDIO_USECASE_MAX][2] = {
232 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE_OF_EXT_CODEC, QCHAT_CALL_PCM_DEVICE_OF_EXT_CODEC}
233};
234
235/* List of use cases that has different PCM device ID's for internal and external codecs */
236static const int misc_usecase[AUDIO_USECASE_MAX] = { USECASE_QCHAT_CALL };
237
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530238int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530239 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
240 DEEP_BUFFER_PCM_DEVICE},
241 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
242 LOWLATENCY_PCM_DEVICE},
243 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
244 MULTIMEDIA2_PCM_DEVICE},
245 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
246 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530247#ifdef MULTIPLE_OFFLOAD_ENABLED
Dhananjay Kumara68d7af2015-05-25 19:11:30 +0530248 /* Below entries are initialized with invalid values
249 * Valid values should be updated from fnc platform_info_init()
250 * based on pcm ids defined in audio_platform_info.xml.
251 */
252 [USECASE_AUDIO_PLAYBACK_OFFLOAD2] = {-1, -1},
253 [USECASE_AUDIO_PLAYBACK_OFFLOAD3] = {-1, -1},
254 [USECASE_AUDIO_PLAYBACK_OFFLOAD4] = {-1, -1},
255 [USECASE_AUDIO_PLAYBACK_OFFLOAD5] = {-1, -1},
256 [USECASE_AUDIO_PLAYBACK_OFFLOAD6] = {-1, -1},
257 [USECASE_AUDIO_PLAYBACK_OFFLOAD7] = {-1, -1},
258 [USECASE_AUDIO_PLAYBACK_OFFLOAD8] = {-1, -1},
259 [USECASE_AUDIO_PLAYBACK_OFFLOAD9] = {-1, -1},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530260#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530261 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
262 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
263 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
264 LOWLATENCY_PCM_DEVICE},
265 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
266 MULTIMEDIA2_PCM_DEVICE},
267 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
268 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
269 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
270 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
271 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
272 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
273 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Karthik Reddy Katta3b0a60c2014-04-06 14:52:37 +0530274 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530275 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
276 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
277 AUDIO_RECORD_PCM_DEVICE},
278 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
279 AUDIO_RECORD_PCM_DEVICE},
280 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
281 AUDIO_RECORD_PCM_DEVICE},
282 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
283 COMPRESS_CAPTURE_DEVICE},
284 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
285 COMPRESS_CAPTURE_DEVICE},
286 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
287 COMPRESS_CAPTURE_DEVICE},
288 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
289 INCALL_MUSIC_UPLINK_PCM_DEVICE},
290 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
291 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
292 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
293 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530294 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
295 AFE_PROXY_RECORD_PCM_DEVICE},
296 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
297 AFE_PROXY_RECORD_PCM_DEVICE},
Naresh Tannirue3b18452014-03-04 14:44:27 +0530298};
299
300/* Array to store sound devices */
301static const char * const device_table[SND_DEVICE_MAX] = {
302 [SND_DEVICE_NONE] = "none",
303 /* Playback sound devices */
304 [SND_DEVICE_OUT_HANDSET] = "handset",
305 [SND_DEVICE_OUT_SPEAKER] = "speaker",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530306 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = "speaker-ext-1",
307 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = "speaker-ext-2",
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530308 [SND_DEVICE_OUT_SPEAKER_WSA] = "wsa-speaker",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530309 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
310 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530311 [SND_DEVICE_OUT_HEADPHONES_44_1] = "headphones-44.1",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530312 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530313 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = "speaker-and-headphones-ext-1",
314 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = "speaker-and-headphones-ext-2",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530315 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
316 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530317 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = "wsa-voice-speaker",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530318 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
319 [SND_DEVICE_OUT_HDMI] = "hdmi",
320 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
321 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530322 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530323 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
324 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
325 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530326 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530327 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
328 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
329 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
330 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
331 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
332 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
333 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
334 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
335 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
336 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
337 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530338 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530339#ifdef RECORD_PLAY_CONCURRENCY
340 [SND_DEVICE_OUT_VOIP_HANDSET] = "voip-handset",
341 [SND_DEVICE_OUT_VOIP_SPEAKER] = "voip-speaker",
342 [SND_DEVICE_OUT_VOIP_HEADPHONES] = "voip-headphones",
343#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +0530344
345 /* Capture sound devices */
346 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530347 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = "handset-mic-ext",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530348 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530349 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
350 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
351 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
352 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
353 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
354 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
355 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
356 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
357 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
358 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
359 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
360 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
361 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
362 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
363 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
364 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530365 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
366 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
367 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
368 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700369 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530370 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700371 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530372 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530373 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
374 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
375 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530376 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
377 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
378 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
379 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530380 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
381 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
382 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530383 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530384 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
385 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
386 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
387 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
388 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
389 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
390 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530391 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside",
392 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside",
393 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside",
394 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside",
395 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside",
Sidipotu Ashok3bcca232014-11-07 14:41:58 +0530396 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = "aanc-fluence-dmic-handset",
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530397 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
398 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = "quad-mic",
399 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
400 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530401};
402
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530403// Platform specific backend bit width table
404static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
405
Naresh Tannirue3b18452014-03-04 14:44:27 +0530406/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530407static int acdb_device_table[SND_DEVICE_MAX] = {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530408 [SND_DEVICE_NONE] = -1,
409 [SND_DEVICE_OUT_HANDSET] = 7,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530410 [SND_DEVICE_OUT_SPEAKER] = 14,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530411 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = 14,
412 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = 14,
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530413 [SND_DEVICE_OUT_SPEAKER_WSA] = 135,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530414 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530415 [SND_DEVICE_OUT_HEADPHONES] = 10,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530416 [SND_DEVICE_OUT_HEADPHONES_44_1] = 10,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530417 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530418 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = 10,
419 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = 10,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530420 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530421 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530422 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = 135,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530423 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
424 [SND_DEVICE_OUT_HDMI] = 18,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530425 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530426 [SND_DEVICE_OUT_BT_SCO] = 22,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530427 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530428 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
429 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
430 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530431 [SND_DEVICE_OUT_VOICE_TX] = 45,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530432 [SND_DEVICE_OUT_AFE_PROXY] = 0,
433 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530434 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530435 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
436 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
437 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
438 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
439 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
440 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
441 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530442 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
443 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530444#ifdef RECORD_PLAY_CONCURRENCY
445 [SND_DEVICE_OUT_VOIP_HANDSET] = 133,
446 [SND_DEVICE_OUT_VOIP_SPEAKER] = 132,
447 [SND_DEVICE_OUT_VOIP_HEADPHONES] = 134,
448#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +0530449
450 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530451 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530452 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
453 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
454 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
455 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
456 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
457 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
458 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
459 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
460 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
461 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
462 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
463 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
464 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
465 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
466 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530467 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530468 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530469 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
470 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
471 [SND_DEVICE_IN_HDMI_MIC] = 4,
472 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700473 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 122,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530474 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700475 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 123,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530476 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
477 [SND_DEVICE_IN_VOICE_DMIC] = 41,
478 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
479 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530480 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
481 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
482 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530483 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
484 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
485 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
486 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530487 [SND_DEVICE_IN_VOICE_RX] = 44,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530488 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
489 [SND_DEVICE_IN_CAPTURE_FM] = 0,
490 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
491 [SND_DEVICE_IN_QUAD_MIC] = 46,
492 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
493 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
494 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530495 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12,
496 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12,
497 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
498 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
499 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
Sidipotu Ashok3bcca232014-11-07 14:41:58 +0530500 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = 135,
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530501 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
502 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = 126,
503 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 127,
504 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530505};
506
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530507struct name_to_index {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530508 char name[100];
509 unsigned int index;
510};
Naresh Tannirue3b18452014-03-04 14:44:27 +0530511
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530512#define TO_NAME_INDEX(X) #X, X
Naresh Tannirue3b18452014-03-04 14:44:27 +0530513
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530514/* Used to get index from parsed sting */
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530515static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530516 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
517 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530518 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_1)},
519 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_2)},
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530520 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530521 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
522 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530523 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_44_1)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530524 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530525 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1)},
526 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530527 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
528 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530529 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_WSA)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530530 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
531 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
532 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
533 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
534 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
535 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
536 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
537 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530538 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TX)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530539 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
540 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
541 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
542 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
543 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
544 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
545 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
546 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
547 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
548 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
549 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530550 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530551#ifdef RECORD_PLAY_CONCURRENCY
552 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HANDSET)},
553 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_SPEAKER)},
554 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HEADPHONES)},
555#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530556 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530557 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530558 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
559 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
560 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
561 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
562 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
563 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
564 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
565 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
566 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
567 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
568 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
569 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
570 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
571 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
572 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
573 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
574 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
575 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
576 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
577 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
578 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700579 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530580 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700581 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530582 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
583 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
584 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
585 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
586 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
587 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
588 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
589 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
590 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
591 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
592 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530593 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RX)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530594 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
595 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
596 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
597 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
598 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
599 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
600 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Sidipotu Ashok3bcca232014-11-07 14:41:58 +0530601 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530602 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE)},
603 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE)},
604 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE)},
605 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE)},
606 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)},
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530607 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
608 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC)},
609 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
610 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530611};
612
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530613static char * backend_table[SND_DEVICE_MAX] = {0};
614
615static struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
616 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
617 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
618 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
619 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
620#ifdef MULTIPLE_OFFLOAD_ENABLED
621 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD2)},
622 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD3)},
623 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD4)},
624 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD5)},
625 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD6)},
626 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD7)},
627 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD8)},
628 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD9)},
629#endif
630 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
631 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
632 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
633 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
634 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
635 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
636 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
637 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
638 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
639 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
640 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
641};
642
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700643#define NO_COLS 2
644static int msm_be_id_array_len;
645static int (*msm_device_to_be_id)[];
646
647/* Below table lists output device to BE_ID mapping*/
648/* Update the table based on the board configuration*/
649
650static int msm_device_to_be_id_internal_codec [][NO_COLS] = {
651 {AUDIO_DEVICE_OUT_EARPIECE , 34},
652 {AUDIO_DEVICE_OUT_SPEAKER , 34},
653 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 34},
654 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 34},
655 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
656 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
657 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
658 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
659 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
660 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
661 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
662 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
663 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
664 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
665 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
666 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
667 {AUDIO_DEVICE_OUT_PROXY , 9},
668 {AUDIO_DEVICE_OUT_FM , 7},
669 {AUDIO_DEVICE_OUT_FM_TX , 8},
670 {AUDIO_DEVICE_OUT_ALL , -1},
671 {AUDIO_DEVICE_NONE , -1},
672 {AUDIO_DEVICE_OUT_DEFAULT , -1},
673};
674
675static int msm_device_to_be_id_external_codec [][NO_COLS] = {
676 {AUDIO_DEVICE_OUT_EARPIECE , 2},
677 {AUDIO_DEVICE_OUT_SPEAKER , 2},
678 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
679 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
680 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
681 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
682 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
683 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
684 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
685 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
686 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
687 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
688 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
689 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
690 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
691 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
692 {AUDIO_DEVICE_OUT_PROXY , 9},
693 {AUDIO_DEVICE_OUT_FM , 7},
694 {AUDIO_DEVICE_OUT_FM_TX , 8},
695 {AUDIO_DEVICE_OUT_ALL , -1},
696 {AUDIO_DEVICE_NONE , -1},
697 {AUDIO_DEVICE_OUT_DEFAULT , -1},
698};
699
700
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530701#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
702#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530703
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530704static bool is_misc_usecase(audio_usecase_t usecase) {
705 bool ret = false;
706 int i;
707
708 for (i = 0; i < AUDIO_USECASE_MAX; i++) {
709 if(usecase == misc_usecase[i]) {
710 ret = true;
711 break;
712 }
713 }
714 return ret;
715}
716
717
718static void update_codec_type(const char *snd_card_name) {
719
720 if (!strncmp(snd_card_name, "msm8939-tapan-snd-card",
721 sizeof("msm8939-tapan-snd-card")) ||
722 !strncmp(snd_card_name, "msm8939-tapan9302-snd-card",
723 sizeof("msm8939-tapan9302-snd-card"))||
724 !strncmp(snd_card_name, "msm8939-tomtom9330-snd-card",
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530725 sizeof("msm8939-tomtom9330-snd-card")) ||
726 !strncmp(snd_card_name, "msm8952-tomtom-snd-card",
727 sizeof("msm8952-tomtom-snd-card"))) {
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530728 ALOGI("%s: snd_card_name: %s",__func__,snd_card_name);
729 is_external_codec = true;
730 }
731}
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530732static void query_platform(const char *snd_card_name,
733 char *mixer_xml_path)
734{
735 if (!strncmp(snd_card_name, "msm8x16-snd-card-mtp",
736 sizeof("msm8x16-snd-card-mtp"))) {
737 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
738 sizeof(MIXER_XML_PATH_MTP));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700739
740 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
741 msm_be_id_array_len =
742 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
743
Walter Yang7ca90d92014-05-06 17:48:02 +0800744 } else if (!strncmp(snd_card_name, "msm8x16-skuh-snd-card",
745 sizeof("msm8x16-skuh-snd-card"))) {
746 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUH,
747 sizeof(MIXER_XML_PATH_QRD_SKUH));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700748
749 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
750 msm_be_id_array_len =
751 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
752
Walter Yang7ca90d92014-05-06 17:48:02 +0800753 } else if (!strncmp(snd_card_name, "msm8x16-skui-snd-card",
754 sizeof("msm8x16-skui-snd-card"))) {
755 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUI,
756 sizeof(MIXER_XML_PATH_QRD_SKUI));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700757
758 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
759 msm_be_id_array_len =
760 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
761
Walter Yang19f244a2014-06-17 13:30:08 +0800762 } else if (!strncmp(snd_card_name, "msm8x16-skuhf-snd-card",
763 sizeof("msm8x16-skuhf-snd-card"))) {
764 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUHF,
765 sizeof(MIXER_XML_PATH_QRD_SKUHF));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700766
767 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
768 msm_be_id_array_len =
769 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
770
Walter Yangc899d572014-05-27 21:52:17 +0800771 } else if (!strncmp(snd_card_name, "msm8939-snd-card-mtp",
Yamit Mehtac6003e22014-05-19 10:26:02 +0530772 sizeof("msm8939-snd-card-mtp"))) {
Aravind Kumar71ba22b2014-06-23 15:18:50 +0530773 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
774 sizeof(MIXER_XML_PATH_MTP));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700775
776 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
777 msm_be_id_array_len =
778 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
779
Meng Wangf00485b2014-06-03 19:44:38 +0800780 } else if (!strncmp(snd_card_name, "msm8939-snd-card-skuk",
781 sizeof("msm8939-snd-card-skuk"))) {
782 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUK,
783 sizeof(MIXER_XML_PATH_SKUK));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700784 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
785 msm_be_id_array_len =
786 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
787
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +0530788 } else if (!strncmp(snd_card_name, "msm8939-tapan-snd-card",
789 sizeof("msm8939-tapan-snd-card"))) {
790 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
791 sizeof(MIXER_XML_PATH_WCD9306));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700792 msm_device_to_be_id = msm_device_to_be_id_external_codec;
793 msm_be_id_array_len =
794 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
795
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +0530796 } else if (!strncmp(snd_card_name, "msm8939-tapan9302-snd-card",
797 sizeof("msm8939-tapan9302-snd-card"))) {
798 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
799 sizeof(MIXER_XML_PATH_WCD9306));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700800
801 msm_device_to_be_id = msm_device_to_be_id_external_codec;
802 msm_be_id_array_len =
803 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
804
Aviral Gupta8ed0eec2014-08-25 10:22:11 +0530805 } else if (!strncmp(snd_card_name, "msm8939-tomtom9330-snd-card",
806 sizeof("msm8939-tomtom9330-snd-card"))) {
807 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330,
808 sizeof(MIXER_XML_PATH_WCD9330));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700809 msm_device_to_be_id = msm_device_to_be_id_external_codec;
810 msm_be_id_array_len =
811 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
812
Walter Yang42886c52014-10-23 14:31:48 +0800813 } else if (!strncmp(snd_card_name, "msm8909-skua-snd-card",
814 sizeof("msm8909-skua-snd-card"))) {
815 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUA,
816 sizeof(MIXER_XML_PATH_SKUA));
Walter Yang42886c52014-10-23 14:31:48 +0800817 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
818 msm_be_id_array_len =
819 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530820
Walter Yang42886c52014-10-23 14:31:48 +0800821 } else if (!strncmp(snd_card_name, "msm8909-skuc-snd-card",
822 sizeof("msm8909-skuc-snd-card"))) {
823 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUC,
824 sizeof(MIXER_XML_PATH_SKUC));
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530825 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
826 msm_be_id_array_len =
827 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
828
829 } else if (!strncmp(snd_card_name, "msm8909-pm8916-snd-card",
830 sizeof("msm8909-pm8916-snd-card"))) {
831 strlcpy(mixer_xml_path, MIXER_XML_PATH_MSM8909_PM8916,
832 sizeof(MIXER_XML_PATH_MSM8909_PM8916));
Walter Yang42886c52014-10-23 14:31:48 +0800833
834 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
835 msm_be_id_array_len =
836 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530837
838 } else if (!strncmp(snd_card_name, "msm8909-skue-snd-card",
839 sizeof("msm8909-skue-snd-card"))) {
840 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUE,
841 sizeof(MIXER_XML_PATH_SKUE));
842 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
843 msm_be_id_array_len =
844 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
845
Meng Wangcfefb8b2014-12-05 14:35:55 +0800846 } else if (!strncmp(snd_card_name, "msm8939-snd-card-skul",
847 sizeof("msm8939-snd-card-skul"))) {
848 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUL,
849 sizeof(MIXER_XML_PATH_SKUL));
850 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
851 msm_be_id_array_len =
852 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +0530853 } else if (!strncmp(snd_card_name, "msm8952-snd-card-mtp",
854 sizeof("msm8952-snd-card-mtpmsm8952-snd-card-mtp"))) {
855 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
856 sizeof(MIXER_XML_PATH_MTP));
857 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
858 msm_be_id_array_len =
859 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
860 } else if (!strncmp(snd_card_name, "msm8952-tomtom-snd-card",
861 sizeof("msm8952-tomtom-snd-card"))) {
862 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330,
863 sizeof(MIXER_XML_PATH_WCD9330));
864 msm_device_to_be_id = msm_device_to_be_id_external_codec;
865 msm_be_id_array_len =
866 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Walter Yangcd132722015-04-08 16:04:30 +0800867 } else if (!strncmp(snd_card_name, "msm8952-skum-snd-card",
868 sizeof("msm8952-skum-snd-card"))) {
869 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUM,
870 sizeof(MIXER_XML_PATH_SKUM));
871 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
872 msm_be_id_array_len =
873 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +0530874
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530875 } else {
876 strlcpy(mixer_xml_path, MIXER_XML_PATH,
877 sizeof(MIXER_XML_PATH));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700878
879 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
880 msm_be_id_array_len =
881 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
882
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530883 }
884}
885
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530886void platform_set_echo_reference(void *platform, bool enable)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530887{
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530888 struct platform_data *my_data = (struct platform_data *)platform;
889 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530890
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530891 if (my_data->ec_ref_enabled) {
892 my_data->ec_ref_enabled = false;
893 ALOGV("%s: disabling echo-reference", __func__);
894 audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530895 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530896
897 if (enable) {
898 my_data->ec_ref_enabled = true;
899 ALOGD("%s: enabling echo-reference", __func__);
900 audio_route_apply_and_update_path(adev->audio_route, "echo-reference");
901 }
Naresh Tannirue3b18452014-03-04 14:44:27 +0530902}
903
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530904static struct csd_data *open_csd_client()
905{
906 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
Chaithanya Krishna Bacharajudb6236a2015-01-30 10:08:33 +0530907 if (!csd) {
908 ALOGE("failed to allocate csd_data mem");
909 return NULL;
910 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530911
912 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
913 if (csd->csd_client == NULL) {
914 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
915 goto error;
916 } else {
917 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
918
919 csd->deinit = (deinit_t)dlsym(csd->csd_client,
920 "csd_client_deinit");
921 if (csd->deinit == NULL) {
922 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
923 dlerror());
924 goto error;
925 }
926 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
927 "csd_client_disable_device");
928 if (csd->disable_device == NULL) {
929 ALOGE("%s: dlsym error %s for csd_client_disable_device",
930 __func__, dlerror());
931 goto error;
932 }
933 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
934 "csd_client_enable_device_config");
935 if (csd->enable_device_config == NULL) {
936 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
937 __func__, dlerror());
938 goto error;
939 }
940 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
941 "csd_client_enable_device");
942 if (csd->enable_device == NULL) {
943 ALOGE("%s: dlsym error %s for csd_client_enable_device",
944 __func__, dlerror());
945 goto error;
946 }
947 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
948 "csd_client_start_voice");
949 if (csd->start_voice == NULL) {
950 ALOGE("%s: dlsym error %s for csd_client_start_voice",
951 __func__, dlerror());
952 goto error;
953 }
954 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
955 "csd_client_stop_voice");
956 if (csd->stop_voice == NULL) {
957 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
958 __func__, dlerror());
959 goto error;
960 }
961 csd->volume = (volume_t)dlsym(csd->csd_client,
962 "csd_client_volume");
963 if (csd->volume == NULL) {
964 ALOGE("%s: dlsym error %s for csd_client_volume",
965 __func__, dlerror());
966 goto error;
967 }
968 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
969 "csd_client_mic_mute");
970 if (csd->mic_mute == NULL) {
971 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
972 __func__, dlerror());
973 goto error;
974 }
975 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
976 "csd_client_slow_talk");
977 if (csd->slow_talk == NULL) {
978 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
979 __func__, dlerror());
980 goto error;
981 }
982 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
983 "csd_client_start_playback");
984 if (csd->start_playback == NULL) {
985 ALOGE("%s: dlsym error %s for csd_client_start_playback",
986 __func__, dlerror());
987 goto error;
988 }
989 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
990 "csd_client_stop_playback");
991 if (csd->stop_playback == NULL) {
992 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
993 __func__, dlerror());
994 goto error;
995 }
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -0700996 csd->set_lch = (set_lch_t)dlsym(csd->csd_client, "csd_client_set_lch");
997 if (csd->set_lch == NULL) {
998 ALOGE("%s: dlsym error %s for csd_client_set_lch",
999 __func__, dlerror());
1000 /* Ignore the error as this is not mandatory function for
1001 * basic voice call to work.
1002 */
1003 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301004 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1005 "csd_client_start_record");
1006 if (csd->start_record == NULL) {
1007 ALOGE("%s: dlsym error %s for csd_client_start_record",
1008 __func__, dlerror());
1009 goto error;
1010 }
1011 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1012 "csd_client_stop_record");
1013 if (csd->stop_record == NULL) {
1014 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1015 __func__, dlerror());
1016 goto error;
1017 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301018
1019
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301020 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1021
1022 if (csd->init == NULL) {
1023 ALOGE("%s: dlsym error %s for csd_client_init",
1024 __func__, dlerror());
1025 goto error;
1026 } else {
1027 csd->init();
1028 }
1029 }
1030 return csd;
1031
1032error:
1033 free(csd);
1034 csd = NULL;
1035 return csd;
1036}
1037
1038void close_csd_client(struct csd_data *csd)
1039{
1040 if (csd != NULL) {
1041 csd->deinit();
1042 dlclose(csd->csd_client);
1043 free(csd);
1044 csd = NULL;
1045 }
1046}
1047
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301048
1049static void set_platform_defaults()
1050{
1051 int32_t dev;
1052 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1053 backend_table[dev] = NULL;
1054 }
1055 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301056 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301057 }
1058
1059 // TBD - do these go to the platform-info.xml file.
1060 // will help in avoiding strdups here
1061 backend_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
1062 backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
1063 backend_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
1064 backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
1065 backend_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1066 backend_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1067 backend_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1068 backend_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1069 backend_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1070 backend_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
1071 backend_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("afe-proxy");
1072 backend_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headphones");
1073 backend_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1074 strdup("speaker-and-usb-headphones");
1075 backend_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1076 backend_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("capture-fm");
1077 backend_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("transmission-fm");
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301078 backend_table[SND_DEVICE_OUT_HEADPHONES_44_1] = strdup("headphones-44.1");
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301079}
1080
Avinash Vaish71c066d2014-08-27 12:32:35 +05301081void get_cvd_version(char *cvd_version, struct audio_device *adev)
1082{
1083 struct mixer_ctl *ctl;
1084 int count;
1085 int ret = 0;
1086
1087 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1088 if (!ctl) {
1089 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1090 goto done;
1091 }
1092 mixer_ctl_update(ctl);
1093
1094 count = mixer_ctl_get_num_values(ctl);
1095 if (count > MAX_CVD_VERSION_STRING_SIZE)
1096 count = MAX_CVD_VERSION_STRING_SIZE;
1097
1098 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1099 if (ret != 0) {
1100 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1101 goto done;
1102 }
1103
1104done:
1105 return;
1106}
1107
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301108static int hw_util_open(int card_no)
1109{
1110 int fd = -1;
1111 char dev_name[256];
1112
1113 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
1114 card_no, WCD9XXX_CODEC_HWDEP_NODE);
1115 ALOGD("%s Opening device %s\n", __func__, dev_name);
1116 fd = open(dev_name, O_WRONLY);
1117 if (fd < 0) {
1118 ALOGE("%s: cannot open device '%s'\n", __func__, dev_name);
1119 return fd;
1120 }
1121 ALOGD("%s success", __func__);
1122 return fd;
1123}
1124
1125struct param_data {
1126 int use_case;
1127 int acdb_id;
1128 int get_size;
1129 int buff_size;
1130 int data_size;
1131 void *buff;
1132};
1133
1134static int send_codec_cal(acdb_loader_get_calibration_t acdb_loader_get_calibration, int fd)
1135{
1136 int ret = 0, type;
1137
1138 for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) {
1139 struct wcdcal_ioctl_buffer codec_buffer;
1140 struct param_data calib;
1141
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301142 calib.get_size = 1;
1143 ret = acdb_loader_get_calibration(cal_name_info[type], sizeof(struct param_data),
1144 &calib);
1145 if (ret < 0) {
1146 ALOGE("%s get_calibration failed\n", __func__);
1147 return ret;
1148 }
1149 calib.get_size = 0;
1150 calib.buff = malloc(calib.buff_size);
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301151 if(calib.buff == NULL) {
1152 ALOGE("%s mem allocation for %d bytes for %s failed\n"
1153 , __func__, calib.buff_size, cal_name_info[type]);
1154 return -1;
1155 }
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301156 ret = acdb_loader_get_calibration(cal_name_info[type],
1157 sizeof(struct param_data), &calib);
1158 if (ret < 0) {
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301159 ALOGE("%s get_calibration failed type=%s calib.size=%d\n"
1160 , __func__, cal_name_info[type], codec_buffer.size);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301161 free(calib.buff);
1162 return ret;
1163 }
1164 codec_buffer.buffer = calib.buff;
1165 codec_buffer.size = calib.data_size;
1166 codec_buffer.cal_type = type;
1167 if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0)
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301168 ALOGE("Failed to call ioctl for %s err=%d calib.size=%d",
1169 cal_name_info[type], errno, codec_buffer.size);
1170 ALOGD("%s cal sent for %s calib.size=%d"
1171 , __func__, cal_name_info[type], codec_buffer.size);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301172 free(calib.buff);
1173 }
1174 return ret;
1175}
1176
1177static void audio_hwdep_send_cal(struct platform_data *plat_data)
1178{
1179 int fd;
1180
1181 fd = hw_util_open(plat_data->adev->snd_card);
1182 if (fd == -1) {
1183 ALOGE("%s error open\n", __func__);
1184 return;
1185 }
1186
1187 acdb_loader_get_calibration = (acdb_loader_get_calibration_t)
1188 dlsym(plat_data->acdb_handle, "acdb_loader_get_calibration");
1189
1190 if (acdb_loader_get_calibration == NULL) {
1191 ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__,
1192 dlerror());
1193 return;
1194 }
1195 if (send_codec_cal(acdb_loader_get_calibration, fd) < 0)
1196 ALOGE("%s: Could not send anc cal", __FUNCTION__);
1197}
1198
Naresh Tanniru516c2452015-08-14 12:58:24 +05301199const char * get_snd_card_name_for_acdb_loader(const char *snd_card_name) {
1200
1201 if(snd_card_name == NULL)
1202 return NULL;
1203
1204 // Both tasha & tasha-lite uses tasha ACDB files
1205 // simulate sound card name for tasha lite, so that
1206 // ACDB module loads tasha ACDB files for tasha lite
1207 if(!strncmp(snd_card_name, "msm8976-tashalite-snd-card",
1208 sizeof("msm8976-tashalite-snd-card"))) {
1209 ALOGD("using tasha ACDB files for tasha-lite");
1210 return "msm8976-tasha-snd-card";
1211 } else {
1212 return snd_card_name;
1213 }
1214}
1215
1216
1217int platform_acdb_init(void *platform)
Ramjee Singh203473b2015-06-09 15:18:42 +05301218{
1219 struct platform_data *my_data = (struct platform_data *)platform;
1220 char *cvd_version = NULL;
1221 int key = 0;
Naresh Tanniru516c2452015-08-14 12:58:24 +05301222 const char *snd_card_name, *acdb_snd_card_name;
Ramjee Singh203473b2015-06-09 15:18:42 +05301223 int result;
1224 char value[PROPERTY_VALUE_MAX];
1225 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1226 if (!cvd_version)
1227 ALOGE("Failed to allocate cvd version");
1228 else
1229 get_cvd_version(cvd_version, my_data->adev);
1230
1231 property_get("audio.ds1.metainfo.key",value,"0");
1232 key = atoi(value);
1233 snd_card_name = mixer_get_name(my_data->adev->mixer);
Naresh Tanniru516c2452015-08-14 12:58:24 +05301234 acdb_snd_card_name = get_snd_card_name_for_acdb_loader(snd_card_name);
1235
1236 result = my_data->acdb_init(acdb_snd_card_name, cvd_version, key);
1237
Ramjee Singh203473b2015-06-09 15:18:42 +05301238 if (cvd_version)
1239 free(cvd_version);
1240 if (!result) {
1241 my_data->is_acdb_initialized = true;
1242 ALOGD("ACDB initialized");
1243 audio_hwdep_send_cal(my_data);
1244 } else {
1245 my_data->is_acdb_initialized = false;
1246 ALOGD("ACDB initialization failed");
1247 }
1248 return result;
1249}
1250
Naresh Tannirue3b18452014-03-04 14:44:27 +05301251void *platform_init(struct audio_device *adev)
1252{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301253 char platform[PROPERTY_VALUE_MAX];
1254 char baseband[PROPERTY_VALUE_MAX];
Naresh Tannirue3b18452014-03-04 14:44:27 +05301255 char value[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301256 struct platform_data *my_data = NULL;
Dhananjay Kumara3565b32014-07-23 01:12:48 +05301257 int retry_num = 0, snd_card_num = 0, key = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301258 const char *snd_card_name;
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +05301259 char mixer_xml_path[100],ffspEnable[PROPERTY_VALUE_MAX];
Avinash Vaish71c066d2014-08-27 12:32:35 +05301260 char *cvd_version = NULL;
Naveen Kumar70e27352015-07-22 21:07:10 +05301261 int idx;
1262
1263 my_data = calloc(1, sizeof(struct platform_data));
1264
Chaithanya Krishna Bacharajudb6236a2015-01-30 10:08:33 +05301265 if (!my_data) {
1266 ALOGE("failed to allocate platform data");
1267 return NULL;
1268 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301269
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301270 while (snd_card_num < MAX_SND_CARD) {
1271 adev->mixer = mixer_open(snd_card_num);
1272
1273 while (!adev->mixer && retry_num < RETRY_NUMBER) {
1274 usleep(RETRY_US);
1275 adev->mixer = mixer_open(snd_card_num);
1276 retry_num++;
1277 }
1278
1279 if (!adev->mixer) {
1280 ALOGE("%s: Unable to open the mixer card: %d", __func__,
1281 snd_card_num);
1282 retry_num = 0;
1283 snd_card_num++;
1284 continue;
1285 }
1286
1287 snd_card_name = mixer_get_name(adev->mixer);
1288 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
1289
1290 my_data->hw_info = hw_info_init(snd_card_name);
1291 if (!my_data->hw_info) {
1292 ALOGE("%s: Failed to init hardware info", __func__);
1293 } else {
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301294 query_platform(snd_card_name, mixer_xml_path);
1295 ALOGD("%s: mixer path file is %s", __func__,
1296 mixer_xml_path);
1297 if (audio_extn_read_xml(adev, snd_card_num, mixer_xml_path,
1298 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301299 adev->audio_route = audio_route_init(snd_card_num,
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301300 mixer_xml_path);
1301 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301302 if (!adev->audio_route) {
1303 ALOGE("%s: Failed to init audio route controls, aborting.",
1304 __func__);
1305 free(my_data);
1306 return NULL;
1307 }
1308 adev->snd_card = snd_card_num;
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +05301309 update_codec_type(snd_card_name);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301310 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1311 break;
1312 }
1313 retry_num = 0;
1314 snd_card_num++;
1315 }
1316
1317 if (snd_card_num >= MAX_SND_CARD) {
1318 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1319 free(my_data);
1320 return NULL;
1321 }
1322
Naresh Tannirue3b18452014-03-04 14:44:27 +05301323 my_data->adev = adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301324 my_data->fluence_in_spkr_mode = false;
1325 my_data->fluence_in_voice_call = false;
1326 my_data->fluence_in_voice_rec = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301327 my_data->fluence_in_audio_rec = false;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301328 my_data->external_spk_1 = false;
1329 my_data->external_spk_2 = false;
1330 my_data->external_mic = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301331 my_data->fluence_type = FLUENCE_NONE;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301332 my_data->fluence_mode = FLUENCE_ENDFIRE;
Avinash Vaishd5fa4572014-09-15 14:41:14 +05301333 my_data->slowtalk = false;
1334 my_data->hd_voice = false;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301335 my_data->edid_info = NULL;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05301336 my_data->is_wsa_speaker = false;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301337
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301338 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
1339 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301340 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301341 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301342 my_data->fluence_type = FLUENCE_DUAL_MIC;
1343 } else {
1344 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301345 }
1346
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301347 if (my_data->fluence_type != FLUENCE_NONE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301348 property_get("persist.audio.fluence.voicecall",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301349 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301350 my_data->fluence_in_voice_call = true;
1351 }
1352
1353 property_get("persist.audio.fluence.voicerec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301354 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301355 my_data->fluence_in_voice_rec = true;
1356 }
1357
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301358 property_get("persist.audio.fluence.audiorec",value,"");
1359 if (!strncmp("true", value, sizeof("true"))) {
1360 my_data->fluence_in_audio_rec = true;
1361 }
1362
Naresh Tannirue3b18452014-03-04 14:44:27 +05301363 property_get("persist.audio.fluence.speaker",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301364 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301365 my_data->fluence_in_spkr_mode = true;
1366 }
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301367
1368 property_get("persist.audio.fluence.mode",value,"");
1369 if (!strncmp("broadside", value, sizeof("broadside"))) {
1370 my_data->fluence_mode = FLUENCE_BROADSIDE;
1371 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301372 }
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +05301373 property_get("persist.audio.FFSP.enable", ffspEnable, "");
1374 if (!strncmp("true", ffspEnable, sizeof("true"))) {
1375 acdb_device_table[SND_DEVICE_OUT_SPEAKER] = 131;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05301376 acdb_device_table[SND_DEVICE_OUT_SPEAKER_WSA] = 131;
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +05301377 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = 131;
1378 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 131;
1379 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 131;
1380 }
Dhananjay Kumara3565b32014-07-23 01:12:48 +05301381
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301382 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301383 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1384 if (my_data->acdb_handle == NULL) {
1385 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1386 } else {
1387 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1388 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1389 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301390 if (!my_data->acdb_deallocate)
1391 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1392 __func__, LIB_ACDB_LOADER);
1393
Naresh Tannirue3b18452014-03-04 14:44:27 +05301394 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001395 "acdb_loader_send_audio_cal_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301396 if (!my_data->acdb_send_audio_cal)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301397 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +05301398 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301399
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301400 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1401 "acdb_loader_set_audio_cal_v2");
1402 if (!my_data->acdb_set_audio_cal)
1403 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1404 __func__, LIB_ACDB_LOADER);
1405
1406 my_data->acdb_get_audio_cal = (acdb_get_audio_cal_t)dlsym(my_data->acdb_handle,
1407 "acdb_loader_get_audio_cal_v2");
1408 if (!my_data->acdb_get_audio_cal)
1409 ALOGE("%s: Could not find the symbol acdb_get_audio_cal_v2 from %s",
1410 __func__, LIB_ACDB_LOADER);
1411
Naresh Tannirue3b18452014-03-04 14:44:27 +05301412 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1413 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301414 if (!my_data->acdb_send_voice_cal)
1415 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1416 __func__, LIB_ACDB_LOADER);
1417
1418 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1419 "acdb_loader_reload_vocvoltable");
1420 if (!my_data->acdb_reload_vocvoltable)
1421 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1422 __func__, LIB_ACDB_LOADER);
1423
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001424 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
1425 my_data->acdb_handle,
1426 "acdb_loader_get_default_app_type");
1427 if (!my_data->acdb_get_default_app_type)
1428 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1429 __func__, LIB_ACDB_LOADER);
1430
Ben Rombergerfeca4b82015-07-07 20:40:44 -07001431 my_data->acdb_send_common_top = (acdb_send_common_top_t)dlsym(
1432 my_data->acdb_handle,
1433 "acdb_loader_send_common_custom_topology");
1434 if (!my_data->acdb_send_common_top)
1435 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1436 __func__, LIB_ACDB_LOADER);
1437
Naresh Tannirue3b18452014-03-04 14:44:27 +05301438 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301439 "acdb_loader_init_v2");
Avinash Vaish71c066d2014-08-27 12:32:35 +05301440 if (my_data->acdb_init == NULL) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301441 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Avinash Vaish71c066d2014-08-27 12:32:35 +05301442 goto acdb_init_fail;
1443 }
Ramjee Singh203473b2015-06-09 15:18:42 +05301444 platform_acdb_init(my_data);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301445 }
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301446 audio_extn_pm_vote();
Naresh Tannirue3b18452014-03-04 14:44:27 +05301447
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05301448 // Check if WSA speaker is supported in codec
1449 char CodecPeek[1024] = "/sys/kernel/debug/asoc/";
1450 DIR *dir;
1451 struct dirent *dirent;
1452 char file_name[10] = "wsa";
1453 strcat(CodecPeek, snd_card_name);
1454
1455 dir = opendir(CodecPeek);
1456 if (dir != NULL) {
1457 while (NULL != (dirent = readdir(dir))) {
1458 if (strstr (dirent->d_name,file_name))
1459 {
1460 my_data->is_wsa_speaker = true;
1461 break;
1462 }
1463 }
1464 closedir(dir);
1465 }
1466
Avinash Vaish71c066d2014-08-27 12:32:35 +05301467acdb_init_fail:
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301468
1469 set_platform_defaults();
1470
Dhananjay Kumara68d7af2015-05-25 19:11:30 +05301471 /* Initialize ACDB and PCM ID's */
1472 if (is_external_codec)
1473 platform_info_init(PLATFORM_INFO_XML_PATH_EXTCODEC);
1474 else
1475 platform_info_init(PLATFORM_INFO_XML_PATH);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301476
1477 /* init usb */
1478 audio_extn_usb_init(adev);
1479 /* update sound cards appropriately */
1480 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
1481
1482 /* Read one time ssr property */
1483 audio_extn_ssr_update_enabled();
1484 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301485
Ashish Jain8ec50472014-10-16 13:56:28 +05301486 /* init dap hal */
1487 audio_extn_dap_hal_init(adev->snd_card);
1488
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301489 audio_extn_dolby_set_license(adev);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301490 audio_hwdep_send_cal(my_data);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301491
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301492 /* init audio device arbitration */
1493 audio_extn_dev_arbi_init();
1494
1495 my_data->edid_info = NULL;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301496
1497 /* initialize backend config */
1498 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
1499 my_data->current_backend_cfg[idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1500 if (idx == HEADPHONE_44_1_BACKEND)
1501 my_data->current_backend_cfg[idx].sample_rate = OUTPUT_SAMPLING_RATE_44100;
1502 my_data->current_backend_cfg[idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1503 }
1504
1505 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1506 strdup("SLIM_0_RX Format");
1507 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1508 strdup("SLIM_0_RX SampleRate");
1509
1510 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].bitwidth_mixer_ctl =
1511 strdup("SLIM_5_RX Format");
1512 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].samplerate_mixer_ctl =
1513 strdup("SLIM_5_RX SampleRate");
1514
1515 my_data->edid_info = NULL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301516 return my_data;
1517}
1518
1519void platform_deinit(void *platform)
1520{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301521 struct platform_data *my_data = (struct platform_data *)platform;
1522
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301523 if (my_data->edid_info) {
1524 free(my_data->edid_info);
1525 my_data->edid_info = NULL;
1526 }
1527
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301528 hw_info_deinit(my_data->hw_info);
1529 close_csd_client(my_data->csd);
1530
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301531 int32_t dev;
1532 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1533 if (backend_table[dev]) {
1534 free(backend_table[dev]);
1535 backend_table[dev]= NULL;
1536 }
1537 }
1538
1539 /* deinit audio device arbitration */
1540 audio_extn_dev_arbi_deinit();
1541
1542 if (my_data->edid_info) {
1543 free(my_data->edid_info);
1544 my_data->edid_info = NULL;
1545 }
1546
Naresh Tannirue3b18452014-03-04 14:44:27 +05301547 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301548 /* deinit usb */
1549 audio_extn_usb_deinit();
Ashish Jain8ec50472014-10-16 13:56:28 +05301550 audio_extn_dap_hal_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +05301551}
1552
Ben Rombergerfeca4b82015-07-07 20:40:44 -07001553static int platform_is_acdb_initialized(void *platform)
Ramjee Singh203473b2015-06-09 15:18:42 +05301554{
1555 struct platform_data *my_data = (struct platform_data *)platform;
1556 ALOGD("%s: acdb initialized %d\n", __func__, my_data->is_acdb_initialized);
1557 return my_data->is_acdb_initialized;
1558}
1559
Ben Rombergerfeca4b82015-07-07 20:40:44 -07001560void platform_snd_card_update(void *platform, int snd_scard_state)
1561{
1562 struct platform_data *my_data = (struct platform_data *)platform;
1563
1564 if (snd_scard_state == SND_CARD_STATE_ONLINE) {
1565 if (!platform_is_acdb_initialized(my_data)) {
1566 if(platform_acdb_init(my_data))
1567 ALOGE("%s: acdb initialization is failed", __func__);
1568 } else if (my_data->acdb_send_common_top() < 0) {
1569 ALOGD("%s: acdb did not set common topology", __func__);
1570 }
1571 }
1572}
1573
Naresh Tannirue3b18452014-03-04 14:44:27 +05301574const char *platform_get_snd_device_name(snd_device_t snd_device)
1575{
1576 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
1577 return device_table[snd_device];
1578 else
1579 return "";
1580}
1581
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301582int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1583 char *device_name)
1584{
1585 struct platform_data *my_data = (struct platform_data *)platform;
1586
1587 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1588 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1589 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1590 } else {
1591 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
1592 return -EINVAL;
1593 }
1594
1595 return 0;
1596}
1597
Naresh Tannirue3b18452014-03-04 14:44:27 +05301598void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
1599{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301600 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1601 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1602 return;
1603 }
1604
1605 const char * suffix = backend_table[snd_device];
1606
1607 if (suffix != NULL) {
1608 strlcat(mixer_path, " ", MIXER_PATH_MAX_LENGTH);
1609 strlcat(mixer_path, suffix, MIXER_PATH_MAX_LENGTH);
1610 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301611}
1612
1613int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1614{
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +05301615 int device_id = -1;
1616
1617 if (is_external_codec && is_misc_usecase(usecase)) {
1618 if (device_type == PCM_PLAYBACK)
1619 device_id = pcm_device_table_of_ext_codec[usecase][0];
1620 else
1621 device_id = pcm_device_table_of_ext_codec[usecase][1];
1622 } else {
1623 if (device_type == PCM_PLAYBACK)
1624 device_id = pcm_device_table[usecase][0];
1625 else
1626 device_id = pcm_device_table[usecase][1];
1627 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301628 return device_id;
1629}
1630
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301631static int find_index(struct name_to_index * table, int32_t len, const char * name)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301632{
1633 int ret = 0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301634 int32_t i;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301635
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301636 if (table == NULL) {
1637 ALOGE("%s: table is NULL", __func__);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301638 ret = -ENODEV;
1639 goto done;
1640 }
1641
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301642 if (name == NULL) {
1643 ALOGE("null key");
1644 ret = -ENODEV;
1645 goto done;
1646 }
1647
1648 for (i=0; i < len; i++) {
1649 const char* tn = table[i].name;
1650 size_t len = strlen(tn);
1651 if (strncmp(tn, name, len) == 0) {
1652 if (strlen(name) != len) {
1653 continue; // substring
1654 }
1655 ret = table[i].index;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301656 goto done;
1657 }
1658 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301659 ALOGE("%s: Could not find index for name = %s",
1660 __func__, name);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301661 ret = -ENODEV;
1662done:
1663 return ret;
1664}
1665
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301666int platform_set_fluence_type(void *platform, char *value)
1667{
1668 int ret = 0;
1669 int fluence_type = FLUENCE_NONE;
1670 int fluence_flag = NONE_FLAG;
1671 struct platform_data *my_data = (struct platform_data *)platform;
1672 struct audio_device *adev = my_data->adev;
1673
1674 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
1675
1676 /* only dual mic turn on and off is supported as of now through setparameters */
1677 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
1678 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
1679 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
1680 ALOGV("fluence dualmic feature enabled \n");
1681 fluence_type = FLUENCE_DUAL_MIC;
1682 fluence_flag = DMIC_FLAG;
1683 } else {
1684 ALOGE("%s: Failed to set DUALMIC", __func__);
1685 ret = -1;
1686 goto done;
1687 }
1688 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
1689 ALOGV("fluence disabled");
1690 fluence_type = FLUENCE_NONE;
1691 } else {
1692 ALOGE("Invalid fluence value : %s",value);
1693 ret = -1;
1694 goto done;
1695 }
1696
1697 if (fluence_type != my_data->fluence_type) {
1698 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
1699 my_data->fluence_type = fluence_type;
1700 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
1701 }
1702done:
1703 return ret;
1704}
1705
1706int platform_get_fluence_type(void *platform, char *value, uint32_t len)
1707{
1708 int ret = 0;
1709 struct platform_data *my_data = (struct platform_data *)platform;
1710
1711 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
1712 strlcpy(value, "quadmic", len);
1713 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
1714 strlcpy(value, "dualmic", len);
1715 } else if (my_data->fluence_type == FLUENCE_NONE) {
1716 strlcpy(value, "none", len);
1717 } else
1718 ret = -1;
1719
1720 return ret;
1721}
1722
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301723int platform_get_snd_device_index(char *device_name)
1724{
1725 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1726}
1727
1728int platform_get_usecase_index(const char *usecase_name)
1729{
1730 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1731}
1732
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301733int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1734{
1735 int ret = 0;
1736
1737 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1738 ALOGE("%s: Invalid snd_device = %d",
1739 __func__, snd_device);
1740 ret = -EINVAL;
1741 goto done;
1742 }
1743
1744 acdb_device_table[snd_device] = acdb_id;
1745done:
1746 return ret;
1747}
1748
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001749int platform_get_default_app_type(void *platform)
1750{
1751 struct platform_data *my_data = (struct platform_data *)platform;
1752
1753 if (my_data->acdb_get_default_app_type)
1754 return my_data->acdb_get_default_app_type();
1755 else
1756 return DEFAULT_APP_TYPE;
1757}
1758
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07001759int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1760{
1761 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1762 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1763 return -EINVAL;
1764 }
1765 return acdb_device_table[snd_device];
1766}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301767
1768int platform_set_snd_device_bit_width(snd_device_t snd_device, unsigned int bit_width)
Amit Shekhar5a39c912014-10-14 15:39:30 -07001769{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301770 int ret = 0;
1771
1772 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1773 ALOGE("%s: Invalid snd_device = %d",
1774 __func__, snd_device);
1775 ret = -EINVAL;
1776 goto done;
1777 }
1778
1779 backend_bit_width_table[snd_device] = bit_width;
1780done:
1781 return ret;
Amit Shekhar5a39c912014-10-14 15:39:30 -07001782}
1783
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301784int platform_get_snd_device_bit_width(snd_device_t snd_device)
Amit Shekhar5a39c912014-10-14 15:39:30 -07001785{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301786 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1787 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
Ashish Jainb449be32015-07-19 05:39:23 -07001788 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301789 }
1790 return backend_bit_width_table[snd_device];
Amit Shekhar5a39c912014-10-14 15:39:30 -07001791}
1792
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301793int platform_set_native_support(bool codec_support)
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08001794{
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301795 na_props.platform_na_prop_enabled = na_props.ui_na_prop_enabled
1796 = codec_support;
Sidipotu Ashok894644d2015-07-06 18:35:03 +05301797 ALOGD("%s: na_props.platform_na_prop_enabled: %d", __func__,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301798 na_props.platform_na_prop_enabled);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08001799 return 0;
1800}
1801
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301802int platform_get_native_support()
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08001803{
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301804 int ret;
1805 if (na_props.platform_na_prop_enabled) {
1806 ret = na_props.ui_na_prop_enabled;
1807 } else {
1808 ret = na_props.platform_na_prop_enabled;
1809 }
1810 ALOGV("%s: na_props.ui_na_prop_enabled: %d", __func__,
1811 na_props.ui_na_prop_enabled);
1812 return ret;
1813}
1814
1815void native_audio_get_params(struct str_parms *query,
1816 struct str_parms *reply,
1817 char *value, int len)
1818{
1819 int ret;
1820 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
1821 value, len);
1822 if (ret >= 0) {
1823 if (na_props.platform_na_prop_enabled) {
1824 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
1825 na_props.ui_na_prop_enabled ? "true" : "false");
1826 ALOGV("%s: na_props.ui_na_prop_enabled: %d", __func__,
1827 na_props.ui_na_prop_enabled);
1828 } else {
1829 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
1830 "false");
1831 ALOGV("%s: native audio not supported: %d", __func__,
1832 na_props.platform_na_prop_enabled);
1833 }
1834 }
1835}
1836
1837int native_audio_set_params(struct platform_data *platform,
1838 struct str_parms *parms, char *value, int len)
1839{
1840 int ret = 0;
1841 struct audio_usecase *usecase;
1842 struct listnode *node;
1843
1844 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
1845 value, len);
1846 if (ret >= 0) {
1847 if (na_props.platform_na_prop_enabled) {
Sidipotu Ashok894644d2015-07-06 18:35:03 +05301848 if (!strncmp("true", value, sizeof("true"))) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301849 na_props.ui_na_prop_enabled = true;
Sidipotu Ashok894644d2015-07-06 18:35:03 +05301850 ALOGD("%s: native audio feature enabled from UI",__func__);
1851 }
1852 else {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301853 na_props.ui_na_prop_enabled = false;
Sidipotu Ashok894644d2015-07-06 18:35:03 +05301854 ALOGD("%s: native audio feature disabled from UI",__func__);
1855
1856 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301857
1858 str_parms_del(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO);
1859
1860 /* Iterate through the usecase list and trigger device switch for
1861 all the appropriate usecases */
1862 list_for_each(node, &(platform->adev)->usecase_list) {
1863 usecase = node_to_item(node, struct audio_usecase, list);
1864
1865 if (is_offload_usecase(usecase->id) &&
1866 (usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1867 usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) &&
1868 OUTPUT_SAMPLING_RATE_44100 == usecase->stream.out->sample_rate) {
Sidipotu Ashok894644d2015-07-06 18:35:03 +05301869 ALOGD("%s: triggering dynamic device switch for usecase(%d: %s)"
1870 " stream(%p), device(%d)", __func__, usecase->id,
1871 use_case_table[usecase->id], usecase->stream,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301872 usecase->stream.out->devices);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05301873 select_devices(platform->adev, usecase->id);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301874 }
1875 }
1876 } else {
Sidipotu Ashok894644d2015-07-06 18:35:03 +05301877 ALOGD("%s: native audio not supported: %d", __func__,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301878 na_props.platform_na_prop_enabled);
1879 }
1880 }
1881 return ret;
1882}
1883
1884int platform_get_backend_index(snd_device_t snd_device)
1885{
1886 int32_t port = DEFAULT_CODEC_BACKEND;
1887
1888 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1889 if (backend_table[snd_device] != NULL &&
1890 !strcmp(backend_table[snd_device], "headphones-44.1"))
1891 port = HEADPHONE_44_1_BACKEND;
1892 else
1893 port = DEFAULT_CODEC_BACKEND;
1894 } else {
1895 ALOGV("%s: Invalid device - %d ", __func__, snd_device);
1896 }
1897
1898 ALOGV("%s: backend port - %d", __func__, port);
1899 return port;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08001900}
1901
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301902int platform_send_audio_calibration(void *platform, struct audio_usecase *usecase,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001903 int app_type, int sample_rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301904{
1905 struct platform_data *my_data = (struct platform_data *)platform;
1906 int acdb_dev_id, acdb_dev_type;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301907 struct audio_device *adev = my_data->adev;
1908 int snd_device = SND_DEVICE_OUT_SPEAKER;
1909
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301910 if (usecase->type == PCM_PLAYBACK)
Naresh Tannirucc7c4de2015-03-10 16:19:23 +05301911 snd_device = usecase->out_snd_device;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301912 else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Naresh Tannirucc7c4de2015-03-10 16:19:23 +05301913 snd_device = usecase->in_snd_device;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301914 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Naresh Tannirue3b18452014-03-04 14:44:27 +05301915
Naresh Tanniru2727f822015-05-11 15:27:08 +05301916 // Do not use Rx path default app type for TX path
1917 if ((usecase->type == PCM_CAPTURE) && (app_type == DEFAULT_APP_TYPE_RX_PATH)) {
1918 ALOGD("Resetting app type for Tx path to default");
1919 app_type = DEFAULT_APP_TYPE_TX_PATH;
1920 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301921 if (acdb_dev_id < 0) {
1922 ALOGE("%s: Could not find acdb id for device(%d)",
1923 __func__, snd_device);
1924 return -EINVAL;
1925 }
1926 if (my_data->acdb_send_audio_cal) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001927 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +05301928 __func__, snd_device, acdb_dev_id);
1929 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1930 snd_device < SND_DEVICE_OUT_END)
1931 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1932 else
1933 acdb_dev_type = ACDB_DEV_TYPE_IN;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001934 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
1935 sample_rate);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301936 }
1937 return 0;
1938}
1939
1940int platform_switch_voice_call_device_pre(void *platform)
1941{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301942 struct platform_data *my_data = (struct platform_data *)platform;
1943 int ret = 0;
1944
1945 if (my_data->csd != NULL &&
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07001946 voice_is_in_call(my_data->adev)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301947 /* This must be called before disabling mixer controls on APQ side */
1948 ret = my_data->csd->disable_device();
1949 if (ret < 0) {
1950 ALOGE("%s: csd_client_disable_device, failed, error %d",
1951 __func__, ret);
1952 }
1953 }
1954 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301955}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301956
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301957int platform_switch_voice_call_enable_device_config(void *platform,
1958 snd_device_t out_snd_device,
1959 snd_device_t in_snd_device)
1960{
1961 struct platform_data *my_data = (struct platform_data *)platform;
1962 int acdb_rx_id, acdb_tx_id;
1963 int ret = 0;
1964
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301965 if (my_data->csd == NULL)
1966 return ret;
1967
1968 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1969 audio_extn_spkr_prot_is_enabled())
1970 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
1971 else
1972 acdb_rx_id = acdb_device_table[out_snd_device];
1973
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301974 acdb_tx_id = acdb_device_table[in_snd_device];
1975
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301976 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1977 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1978 if (ret < 0) {
1979 ALOGE("%s: csd_enable_device_config, failed, error %d",
1980 __func__, ret);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301981 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301982 } else {
1983 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1984 acdb_rx_id, acdb_tx_id);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301985 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301986
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301987 return ret;
1988}
1989
Naresh Tannirue3b18452014-03-04 14:44:27 +05301990int platform_switch_voice_call_device_post(void *platform,
1991 snd_device_t out_snd_device,
1992 snd_device_t in_snd_device)
1993{
1994 struct platform_data *my_data = (struct platform_data *)platform;
1995 int acdb_rx_id, acdb_tx_id;
1996
1997 if (my_data->acdb_send_voice_cal == NULL) {
1998 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1999 } else {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302000 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2001 audio_extn_spkr_prot_is_enabled())
2002 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
2003
Naresh Tannirue3b18452014-03-04 14:44:27 +05302004 acdb_rx_id = acdb_device_table[out_snd_device];
2005 acdb_tx_id = acdb_device_table[in_snd_device];
2006
2007 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2008 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2009 else
2010 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2011 acdb_rx_id, acdb_tx_id);
2012 }
2013
2014 return 0;
2015}
2016
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302017int platform_switch_voice_call_usecase_route_post(void *platform,
2018 snd_device_t out_snd_device,
2019 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302020{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302021 struct platform_data *my_data = (struct platform_data *)platform;
2022 int acdb_rx_id, acdb_tx_id;
2023 int ret = 0;
2024
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302025 if (my_data->csd == NULL)
2026 return ret;
2027
2028 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2029 audio_extn_spkr_prot_is_enabled())
2030 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
2031 else
2032 acdb_rx_id = acdb_device_table[out_snd_device];
2033
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302034 acdb_tx_id = acdb_device_table[in_snd_device];
2035
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302036 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2037 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2038 my_data->adev->acdb_settings);
2039 if (ret < 0) {
2040 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302041 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302042 } else {
2043 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2044 acdb_rx_id, acdb_tx_id);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302045 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302046
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302047 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302048}
2049
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302050int platform_start_voice_call(void *platform, uint32_t vsid)
2051{
2052 struct platform_data *my_data = (struct platform_data *)platform;
2053 int ret = 0;
2054
2055 if (my_data->csd != NULL) {
2056 ret = my_data->csd->start_voice(vsid);
2057 if (ret < 0) {
2058 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2059 }
2060 }
2061 return ret;
2062}
2063
2064int platform_stop_voice_call(void *platform, uint32_t vsid)
2065{
2066 struct platform_data *my_data = (struct platform_data *)platform;
2067 int ret = 0;
2068
2069 if (my_data->csd != NULL) {
2070 ret = my_data->csd->stop_voice(vsid);
2071 if (ret < 0) {
2072 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2073 }
2074 }
2075 return ret;
2076}
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002077
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302078int platform_get_sample_rate(void *platform, uint32_t *rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302079{
2080 return 0;
2081}
2082
2083int platform_set_voice_volume(void *platform, int volume)
2084{
2085 struct platform_data *my_data = (struct platform_data *)platform;
2086 struct audio_device *adev = my_data->adev;
2087 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302088 const char *mixer_ctl_name = "Voice Rx Gain";
2089 int vol_index = 0, ret = 0;
2090 uint32_t set_values[ ] = {0,
2091 ALL_SESSION_VSID,
2092 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05302093
2094 // Voice volume levels are mapped to adsp volume levels as follows.
2095 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2096 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302097 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
2098 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302099
2100 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2101 if (!ctl) {
2102 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2103 __func__, mixer_ctl_name);
2104 return -EINVAL;
2105 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302106 ALOGV("Setting voice volume index: %d", set_values[0]);
2107 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05302108
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302109 if (my_data->csd != NULL) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302110 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2111 DEFAULT_VOLUME_RAMP_DURATION_MS);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302112 if (ret < 0) {
2113 ALOGE("%s: csd_volume error %d", __func__, ret);
2114 }
2115 }
2116 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302117}
2118
2119int platform_set_mic_mute(void *platform, bool state)
2120{
2121 struct platform_data *my_data = (struct platform_data *)platform;
2122 struct audio_device *adev = my_data->adev;
2123 struct mixer_ctl *ctl;
2124 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302125 int ret = 0;
2126 uint32_t set_values[ ] = {0,
2127 ALL_SESSION_VSID,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302128 DEFAULT_MUTE_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05302129
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302130 set_values[0] = state;
2131 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2132 if (!ctl) {
2133 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2134 __func__, mixer_ctl_name);
2135 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302136 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302137 ALOGV("Setting voice mute state: %d", state);
2138 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05302139
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302140 if (my_data->csd != NULL) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302141 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2142 DEFAULT_MUTE_RAMP_DURATION_MS);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302143 if (ret < 0) {
2144 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
2145 }
2146 }
2147 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302148}
2149
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08002150int platform_set_device_mute(void *platform, bool state, char *dir)
2151{
2152 struct platform_data *my_data = (struct platform_data *)platform;
2153 struct audio_device *adev = my_data->adev;
2154 struct mixer_ctl *ctl;
2155 char *mixer_ctl_name = NULL;
2156 int ret = 0;
2157 uint32_t set_values[ ] = {0,
2158 ALL_SESSION_VSID,
2159 0};
2160 if(dir == NULL) {
2161 ALOGE("%s: Invalid direction:%s", __func__, dir);
2162 return -EINVAL;
2163 }
2164
2165 if (!strncmp("rx", dir, sizeof("rx"))) {
2166 mixer_ctl_name = "Voice Rx Device Mute";
2167 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2168 mixer_ctl_name = "Voice Tx Device Mute";
2169 } else {
2170 return -EINVAL;
2171 }
2172
2173 set_values[0] = state;
2174 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2175 if (!ctl) {
2176 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2177 __func__, mixer_ctl_name);
2178 return -EINVAL;
2179 }
2180
2181 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2182 __func__,state, mixer_ctl_name);
2183 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2184
2185 return ret;
2186}
2187
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002188snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *out)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302189{
2190 struct platform_data *my_data = (struct platform_data *)platform;
2191 struct audio_device *adev = my_data->adev;
2192 audio_mode_t mode = adev->mode;
2193 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002194 audio_devices_t devices = out->devices;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302195 unsigned int sample_rate = out->sample_rate;
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302196#ifdef RECORD_PLAY_CONCURRENCY
2197 bool use_voip_out_devices = false;
2198 bool prop_rec_play_enabled = false;
2199 char recConcPropValue[PROPERTY_VALUE_MAX];
2200
2201 if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) {
2202 prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4);
2203 }
2204 use_voip_out_devices = prop_rec_play_enabled &&
2205 (my_data->rec_play_conc_set || adev->mode == AUDIO_MODE_IN_COMMUNICATION);
2206 ALOGV("platform_get_output_snd_device use_voip_out_devices : %d",use_voip_out_devices);
2207#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +05302208
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302209 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2210 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2211 int channel_count = popcount(channel_mask);
2212
Naresh Tannirue3b18452014-03-04 14:44:27 +05302213 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2214 if (devices == AUDIO_DEVICE_NONE ||
2215 devices & AUDIO_DEVICE_BIT_IN) {
2216 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2217 goto exit;
2218 }
2219
Shiv Maliyappanahallibd401262015-08-17 11:02:21 -07002220 if (popcount(devices) == 2) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302221 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2222 AUDIO_DEVICE_OUT_SPEAKER)) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302223 if (my_data->external_spk_1)
2224 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
2225 else if (my_data->external_spk_2)
2226 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
2227 else
2228 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302229 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2230 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302231 if (audio_extn_get_anc_enabled())
2232 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302233 else if (my_data->external_spk_1)
2234 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
2235 else if (my_data->external_spk_2)
2236 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302237 else
2238 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302239 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2240 AUDIO_DEVICE_OUT_SPEAKER)) {
2241 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302242 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
2243 AUDIO_DEVICE_OUT_SPEAKER)) {
2244 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302245 } else {
2246 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2247 goto exit;
2248 }
2249 if (snd_device != SND_DEVICE_NONE) {
2250 goto exit;
2251 }
2252 }
2253
2254 if (popcount(devices) != 1) {
2255 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2256 goto exit;
2257 }
2258
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05302259 if ((mode == AUDIO_MODE_IN_CALL) ||
2260 voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302261 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2262 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2263 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
2264 !voice_extn_compress_voip_is_active(adev)) {
2265 switch (adev->voice.tty_mode) {
2266 case TTY_MODE_FULL:
2267 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
2268 break;
2269 case TTY_MODE_VCO:
2270 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
2271 break;
2272 case TTY_MODE_HCO:
2273 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2274 break;
2275 default:
2276 ALOGE("%s: Invalid TTY mode (%#x)",
2277 __func__, adev->voice.tty_mode);
2278 }
2279 } else if (audio_extn_get_anc_enabled()) {
2280 if (audio_extn_should_use_fb_anc())
2281 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
2282 else
2283 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
2284 } else {
2285 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2286 }
2287 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07002288 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302289 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2290 else
2291 snd_device = SND_DEVICE_OUT_BT_SCO;
2292 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05302293 if (my_data->is_wsa_speaker)
2294 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_WSA;
2295 else
2296 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302297 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2298 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
2299 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2300 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
2301 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
2302 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
2303 if (audio_extn_should_use_handset_anc(channel_count))
2304 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
2305 else
2306 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +05302307 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2308 snd_device = SND_DEVICE_OUT_VOICE_TX;
2309
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302310 if (snd_device != SND_DEVICE_NONE) {
2311 goto exit;
2312 }
2313 }
2314
Naresh Tannirue3b18452014-03-04 14:44:27 +05302315 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2316 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302317 if (OUTPUT_SAMPLING_RATE_44100 == sample_rate &&
2318 platform_get_native_support()) {
2319 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
2320 }else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302321 && audio_extn_get_anc_enabled()) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302322#ifdef RECORD_PLAY_CONCURRENCY
2323 if (use_voip_out_devices) {
2324 // ANC should be disabled for voip concurrency
2325 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
2326 } else
2327#endif
2328 {
2329 if (audio_extn_should_use_fb_anc())
2330 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
2331 else
2332 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
2333 }
2334 } else {
2335#ifdef RECORD_PLAY_CONCURRENCY
2336 if (use_voip_out_devices)
2337 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302338 else
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302339#endif
2340 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302341 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302342 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302343#ifdef RECORD_PLAY_CONCURRENCY
2344 if (use_voip_out_devices) {
2345 snd_device = SND_DEVICE_OUT_VOIP_SPEAKER;
2346 } else
2347#endif
2348 {
2349 if (adev->speaker_lr_swap)
2350 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2351 else
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05302352 {
2353 if (my_data->is_wsa_speaker)
2354 snd_device = SND_DEVICE_OUT_SPEAKER_WSA;
2355 else
2356 snd_device = SND_DEVICE_OUT_SPEAKER;
2357 }
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302358 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302359 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07002360 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302361 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2362 else
2363 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302364 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2365 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302366 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2367 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08002368 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
2369 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302370 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2371 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
2372 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302373 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302374#ifdef RECORD_PLAY_CONCURRENCY
2375 if (use_voip_out_devices)
2376 snd_device = SND_DEVICE_OUT_VOIP_HANDSET;
2377 else
2378#endif
2379 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302380 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08002381 channel_count = audio_extn_get_afe_proxy_channel_count();
2382 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
2383 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302384 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302385 } else {
2386 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2387 }
2388exit:
2389 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2390 return snd_device;
2391}
2392
2393snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2394{
2395 struct platform_data *my_data = (struct platform_data *)platform;
2396 struct audio_device *adev = my_data->adev;
2397 audio_source_t source = (adev->active_input == NULL) ?
2398 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2399
2400 audio_mode_t mode = adev->mode;
2401 audio_devices_t in_device = ((adev->active_input == NULL) ?
2402 AUDIO_DEVICE_NONE : adev->active_input->device)
2403 & ~AUDIO_DEVICE_BIT_IN;
2404 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2405 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2406 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302407 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302408
2409 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
2410 __func__, out_device, in_device);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302411 if (my_data->external_mic) {
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05302412 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
2413 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302414 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2415 out_device & AUDIO_DEVICE_OUT_EARPIECE ||
2416 out_device & AUDIO_DEVICE_OUT_SPEAKER )
2417 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
2418 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2419 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2420 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
2421 }
2422 }
2423
2424 if (snd_device != AUDIO_DEVICE_NONE)
2425 goto exit;
2426
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05302427 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
Satya Krishna Pindiproli2aaa6152014-05-21 15:05:22 +05302428 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302429 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
2430 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302431 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2432 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302433 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302434 case TTY_MODE_FULL:
2435 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2436 break;
2437 case TTY_MODE_VCO:
2438 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2439 break;
2440 case TTY_MODE_HCO:
2441 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2442 break;
2443 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302444 ALOGE("%s: Invalid TTY mode (%#x)",
2445 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302446 }
2447 goto exit;
2448 }
2449 }
2450 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
2451 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302452 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
Sidipotu Ashok3bcca232014-11-07 14:41:58 +05302453 audio_extn_should_use_handset_anc(channel_count) &&
2454 my_data->fluence_type != FLUENCE_NONE) {
2455 snd_device = SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC;
2456 adev->acdb_settings |= DMIC_FLAG;
2457 ALOGD("Selecting AANC, Fluence combo device");
2458 } else if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302459 audio_extn_should_use_handset_anc(channel_count)) {
2460 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302461 adev->acdb_settings |= ANC_FLAG;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302462 } else if (my_data->fluence_type == FLUENCE_NONE ||
2463 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302464 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302465 if (audio_extn_hfp_is_active(adev))
2466 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302467 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302468 snd_device = SND_DEVICE_IN_VOICE_DMIC;
2469 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302470 }
2471 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2472 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302473 if (audio_extn_hfp_is_active(adev))
2474 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302475 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07002476 if (adev->bt_wb_speech_enabled) {
2477 if (adev->bluetooth_nrec)
2478 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2479 else
2480 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
2481 } else {
2482 if (adev->bluetooth_nrec)
2483 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2484 else
2485 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
2486 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302487 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302488 if (my_data->fluence_type != FLUENCE_NONE &&
2489 my_data->fluence_in_voice_call &&
2490 my_data->fluence_in_spkr_mode) {
2491 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
2492 adev->acdb_settings |= QMIC_FLAG;
2493 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
2494 } else {
2495 adev->acdb_settings |= DMIC_FLAG;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05302496 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2497 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
2498 else
2499 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302500 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302501 } else {
2502 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302503 if (audio_extn_hfp_is_active(adev))
2504 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302505 }
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +05302506 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2507 snd_device = SND_DEVICE_IN_VOICE_RX;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302508 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2509 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2510 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
kunleiz18a33302014-05-30 09:52:25 +08002511 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
2512 channel_count == 2)
kunleiz8f7e9e22014-06-24 15:12:02 +08002513 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
kunleiz18a33302014-05-30 09:52:25 +08002514 else
2515 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302516 }
2517 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2518 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302519 if (channel_count == 2) {
2520 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
2521 adev->acdb_settings |= DMIC_FLAG;
2522 } else if (adev->active_input->enable_ns)
2523 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2524 else if (my_data->fluence_type != FLUENCE_NONE &&
2525 my_data->fluence_in_voice_rec) {
2526 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
2527 adev->acdb_settings |= DMIC_FLAG;
2528 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302529 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
2530 }
2531 }
Karthik Reddy Kattaf621ec72014-11-21 16:37:38 +05302532 } else if ((source == AUDIO_SOURCE_VOICE_COMMUNICATION) ||
2533 (mode == AUDIO_MODE_IN_COMMUNICATION)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302534 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
2535 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2536 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302537 if (adev->active_input->enable_aec &&
2538 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302539 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05302540 if (my_data->fluence_in_spkr_mode) {
2541 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
2542 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
2543 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2544 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2545 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
2546 else
2547 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
2548 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302549 adev->acdb_settings |= DMIC_FLAG;
2550 } else
2551 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302552 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302553 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2554 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
2555 adev->acdb_settings |= DMIC_FLAG;
2556 } else
2557 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302558 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302559 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302560 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302561 platform_set_echo_reference(adev->platform, true);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302562 } else if (adev->active_input->enable_aec) {
2563 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05302564 if (my_data->fluence_in_spkr_mode) {
2565 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
2566 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC;
2567 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2568 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2569 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
2570 else
2571 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
2572 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302573 adev->acdb_settings |= DMIC_FLAG;
2574 } else
2575 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
2576 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2577 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2578 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2579 adev->acdb_settings |= DMIC_FLAG;
2580 } else
2581 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
2582 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2583 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
2584 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302585 platform_set_echo_reference(adev->platform, true);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302586 } else if (adev->active_input->enable_ns) {
2587 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05302588 if (my_data->fluence_in_spkr_mode) {
2589 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
2590 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_NS;
2591 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2592 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2593 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
2594 else
2595 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
2596 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302597 adev->acdb_settings |= DMIC_FLAG;
2598 } else
2599 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
2600 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2601 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2602 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
2603 adev->acdb_settings |= DMIC_FLAG;
2604 } else
2605 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
2606 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2607 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
2608 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302609 platform_set_echo_reference(adev->platform,false);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302610 } else
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302611 platform_set_echo_reference(adev->platform, false);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302612 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302613 } else if (source == AUDIO_SOURCE_MIC) {
2614 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
2615 channel_count == 1 ) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05302616 if(my_data->fluence_in_audio_rec) {
2617 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
2618 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
2619 platform_set_echo_reference(adev->platform, true);
2620 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2621 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
2622 platform_set_echo_reference(adev->platform, true);
2623 }
2624 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302625 }
2626 } else if (source == AUDIO_SOURCE_FM_RX ||
Mingming Yin5bba6cb2015-07-30 14:59:12 -07002627 source == AUDIO_SOURCE_FM_RX_A2DP ||
2628 source == AUDIO_SOURCE_FM_TUNER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302629 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302630 } else if (source == AUDIO_SOURCE_DEFAULT) {
2631 goto exit;
2632 }
2633
2634
2635 if (snd_device != SND_DEVICE_NONE) {
2636 goto exit;
2637 }
2638
2639 if (in_device != AUDIO_DEVICE_NONE &&
2640 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2641 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2642 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302643 if (audio_extn_ssr_get_enabled() && channel_count == 6)
2644 snd_device = SND_DEVICE_IN_QUAD_MIC;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302645 else if (my_data->fluence_type & (FLUENCE_DUAL_MIC | FLUENCE_QUAD_MIC) &&
2646 channel_count == 2)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302647 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
2648 else
2649 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302650 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2651 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2652 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2653 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2654 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07002655 if (adev->bt_wb_speech_enabled) {
2656 if (adev->bluetooth_nrec)
2657 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2658 else
2659 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
2660 } else {
2661 if (adev->bluetooth_nrec)
2662 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2663 else
2664 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
2665 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302666 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2667 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302668 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
2669 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
2670 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Mingming Yin5bba6cb2015-07-30 14:59:12 -07002671 } else if (in_device & AUDIO_DEVICE_IN_FM_RX ||
2672 in_device & AUDIO_DEVICE_IN_FM_TUNER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302673 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302674 } else {
2675 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2676 ALOGW("%s: Using default handset-mic", __func__);
2677 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2678 }
2679 } else {
2680 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2681 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2682 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2683 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2684 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302685 if (channel_count > 1)
2686 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
2687 else
2688 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302689 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
2690 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2691 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07002692 if (adev->bt_wb_speech_enabled) {
2693 if (adev->bluetooth_nrec)
2694 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2695 else
2696 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
2697 } else {
2698 if (adev->bluetooth_nrec)
2699 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2700 else
2701 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
2702 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302703 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2704 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302705 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2706 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
2707 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302708 } else {
2709 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2710 ALOGW("%s: Using default handset-mic", __func__);
2711 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2712 }
2713 }
2714exit:
2715 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2716 return snd_device;
2717}
2718
2719int platform_set_hdmi_channels(void *platform, int channel_count)
2720{
2721 struct platform_data *my_data = (struct platform_data *)platform;
2722 struct audio_device *adev = my_data->adev;
2723 struct mixer_ctl *ctl;
2724 const char *channel_cnt_str = NULL;
2725 const char *mixer_ctl_name = "HDMI_RX Channels";
2726 switch (channel_count) {
2727 case 8:
2728 channel_cnt_str = "Eight"; break;
2729 case 7:
2730 channel_cnt_str = "Seven"; break;
2731 case 6:
2732 channel_cnt_str = "Six"; break;
2733 case 5:
2734 channel_cnt_str = "Five"; break;
2735 case 4:
2736 channel_cnt_str = "Four"; break;
2737 case 3:
2738 channel_cnt_str = "Three"; break;
2739 default:
2740 channel_cnt_str = "Two"; break;
2741 }
2742 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2743 if (!ctl) {
2744 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2745 __func__, mixer_ctl_name);
2746 return -EINVAL;
2747 }
2748 ALOGV("HDMI channel count: %s", channel_cnt_str);
2749 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2750 return 0;
2751}
2752
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302753int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302754{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302755 int channel_count;
2756 int max_channels = 2;
2757 int i = 0, ret = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302758 struct platform_data *my_data = (struct platform_data *)platform;
2759 struct audio_device *adev = my_data->adev;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302760 edid_audio_info *info = NULL;
2761 ret = platform_get_edid_info(platform);
2762 info = (edid_audio_info *)my_data->edid_info;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302763
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302764 if(ret == 0 && info != NULL) {
2765 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
2766 ALOGV("%s:format %d channel %d", __func__,
2767 info->audio_blocks_array[i].format_id,
2768 info->audio_blocks_array[i].channels);
2769 if (info->audio_blocks_array[i].format_id == LPCM) {
2770 channel_count = info->audio_blocks_array[i].channels;
2771 if (channel_count > max_channels) {
2772 max_channels = channel_count;
2773 }
2774 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302775 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302776 }
2777
2778 return max_channels;
2779}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302780
2781static int platform_set_slowtalk(struct platform_data *my_data, bool state)
2782{
2783 int ret = 0;
2784 struct audio_device *adev = my_data->adev;
2785 struct mixer_ctl *ctl;
2786 const char *mixer_ctl_name = "Slowtalk Enable";
2787 uint32_t set_values[ ] = {0,
2788 ALL_SESSION_VSID};
2789
2790 set_values[0] = state;
2791 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2792 if (!ctl) {
2793 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2794 __func__, mixer_ctl_name);
2795 ret = -EINVAL;
2796 } else {
2797 ALOGV("Setting slowtalk state: %d", state);
2798 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2799 my_data->slowtalk = state;
2800 }
2801
2802 if (my_data->csd != NULL) {
2803 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
2804 if (ret < 0) {
2805 ALOGE("%s: csd_client_disable_device, failed, error %d",
2806 __func__, ret);
2807 }
2808 }
2809 return ret;
2810}
2811
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302812static int set_hd_voice(struct platform_data *my_data, bool state)
2813{
2814 struct audio_device *adev = my_data->adev;
2815 struct mixer_ctl *ctl;
2816 const char *mixer_ctl_name = "HD Voice Enable";
2817 int ret = 0;
2818 uint32_t set_values[ ] = {0,
2819 ALL_SESSION_VSID};
2820
2821 set_values[0] = state;
2822 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2823 if (!ctl) {
2824 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2825 __func__, mixer_ctl_name);
2826 ret = -EINVAL;
2827 } else {
2828 ALOGV("Setting HD Voice state: %d", state);
2829 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2830 my_data->hd_voice = state;
2831 }
2832
2833 return ret;
2834}
2835
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302836static int update_external_device_status(struct platform_data *my_data,
2837 char* event_name, bool status)
2838{
2839 int ret = 0;
2840 struct audio_usecase *usecase;
2841 struct listnode *node;
2842
2843 ALOGD("Recieved external event switch %s", event_name);
2844
2845 if (!strcmp(event_name, EVENT_EXTERNAL_SPK_1))
2846 my_data->external_spk_1 = status;
2847 else if (!strcmp(event_name, EVENT_EXTERNAL_SPK_2))
2848 my_data->external_spk_2 = status;
2849 else if (!strcmp(event_name, EVENT_EXTERNAL_MIC))
2850 my_data->external_mic = status;
2851 else {
2852 ALOGE("The audio event type is not found");
2853 return -EINVAL;
2854 }
2855
2856 list_for_each(node, &my_data->adev->usecase_list) {
2857 usecase = node_to_item(node, struct audio_usecase, list);
2858 select_devices(my_data->adev, usecase->id);
2859 }
2860
2861 return ret;
2862}
2863
2864static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
2865{
2866 int err;
2867 unsigned int val;
2868 char value[64];
2869 int ret = 0;
2870
2871 if(parms == NULL || cal == NULL)
2872 return ret;
2873
2874 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
2875 if (err >= 0) {
2876 str_parms_del(parms, "cal_persist");
2877 cal->persist = (uint32_t) strtoul(value, NULL, 0);
2878 ret = ret | 0x1;
2879 }
2880 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
2881 if (err >= 0) {
2882 str_parms_del(parms, "cal_apptype");
2883 cal->app_type = (uint32_t) strtoul(value, NULL, 0);
2884 ret = ret | 0x2;
2885 }
2886 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
2887 if (err >= 0) {
2888 str_parms_del(parms, "cal_caltype");
2889 cal->cal_type = (uint32_t) strtoul(value, NULL, 0);
2890 ret = ret | 0x4;
2891 }
2892 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
2893 if (err >= 0) {
2894 str_parms_del(parms, "cal_samplerate");
2895 cal->sampling_rate = (uint32_t) strtoul(value, NULL, 0);
2896 ret = ret | 0x8;
2897 }
2898 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
2899 if (err >= 0) {
2900 str_parms_del(parms, "cal_devid");
2901 cal->dev_id = (uint32_t) strtoul(value, NULL, 0);
2902 ret = ret | 0x10;
2903 }
2904 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
2905 if (err >= 0) {
2906 str_parms_del(parms, "cal_snddevid");
2907 cal->snd_dev_id = (uint32_t) strtoul(value, NULL, 0);
2908 ret = ret | 0x20;
2909 }
2910 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
2911 if (err >= 0) {
2912 str_parms_del(parms, "cal_topoid");
2913 cal->topo_id = (uint32_t) strtoul(value, NULL, 0);
2914 ret = ret | 0x40;
2915 }
2916 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
2917 if (err >= 0) {
2918 str_parms_del(parms, "cal_moduleid");
2919 cal->module_id = (uint32_t) strtoul(value, NULL, 0);
2920 ret = ret | 0x80;
2921 }
2922 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
2923 if (err >= 0) {
2924 str_parms_del(parms, "cal_paramid");
2925 cal->param_id = (uint32_t) strtoul(value, NULL, 0);
2926 ret = ret | 0x100;
2927 }
2928 return ret;
2929}
2930
2931static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len) {
2932 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302933 struct stream_out out={0};
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302934 acdb_audio_cal_cfg_t cal={0};
2935 uint8_t *dptr = NULL;
2936 int32_t dlen;
2937 int err, ret;
2938 if(value == NULL || platform == NULL || parms == NULL) {
2939 ALOGE("[%s] received null pointer, failed",__func__);
2940 goto done_key_audcal;
2941 }
2942
2943 /* parse audio calibration keys */
2944 ret = parse_audiocal_cfg(parms, &cal);
2945
2946 /* handle audio calibration data now */
2947 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
2948 if (err >= 0) {
2949 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
2950 dlen = strlen(value);
2951 if(dlen <= 0) {
2952 ALOGE("[%s] null data received",__func__);
2953 goto done_key_audcal;
2954 }
2955 dptr = (uint8_t*) calloc(dlen, sizeof(uint8_t));
2956 if(dptr == NULL) {
2957 ALOGE("[%s] memory allocation failed for %d",__func__, dlen);
2958 goto done_key_audcal;
2959 }
2960 dlen = b64decode(value, strlen(value), dptr);
2961 if(dlen<=0) {
2962 ALOGE("[%s] data decoding failed %d", __func__, dlen);
2963 goto done_key_audcal;
2964 }
2965
2966 if(cal.dev_id) {
2967 if(audio_is_input_device(cal.dev_id)) {
2968 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
2969 } else {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302970 out.devices = cal.dev_id;
2971 cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302972 }
2973 }
2974 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
2975 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
2976 cal.snd_dev_id, cal.acdb_dev_id);
2977 if(cal.acdb_dev_id == -EINVAL) {
2978 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
2979 __func__, cal.acdb_dev_id, cal.snd_dev_id);
2980 goto done_key_audcal;
2981 }
2982 if(my_data->acdb_set_audio_cal) {
2983 ret = my_data->acdb_set_audio_cal((void *)&cal, (void*)dptr, dlen);
2984 }
2985 }
2986done_key_audcal:
2987 if(dptr != NULL)
2988 free(dptr);
2989}
2990
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302991int platform_set_parameters(void *platform, struct str_parms *parms)
2992{
2993 struct platform_data *my_data = (struct platform_data *)platform;
2994 char *str;
2995 char value[256] = {0};
2996 int val;
2997 int ret = 0, err;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302998 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302999
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303000 kv_pairs = str_parms_to_str(parms);
3001 ALOGV("%s: enter: - %s", __func__, kv_pairs);
3002 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303003
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303004 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
3005 if (err >= 0) {
3006 bool state = false;
3007 if (!strncmp("true", value, sizeof("true"))) {
3008 state = true;
3009 }
3010
3011 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
3012 ret = platform_set_slowtalk(my_data, state);
3013 if (ret)
3014 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
3015 }
3016
Avinash Vaishd5fa4572014-09-15 14:41:14 +05303017 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, sizeof(value));
3018 if (err >= 0) {
3019 bool state = false;
3020 if (!strncmp("true", value, sizeof("true"))) {
3021 state = true;
3022 }
3023
3024 str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE);
3025 if (my_data->hd_voice != state) {
3026 ret = set_hd_voice(my_data, state);
3027 if (ret)
3028 ALOGE("%s: Failed to set HD voice err: %d", __func__, ret);
3029 } else {
3030 ALOGV("%s: HD Voice already set to %d", __func__, state);
3031 }
3032 }
3033
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303034 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
3035 value, sizeof(value));
3036 if (err >= 0) {
3037 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
3038
3039 if (my_data->acdb_reload_vocvoltable == NULL) {
3040 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
3041 } else if (!strcmp(value, "on")) {
3042 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
3043 my_data->voice_feature_set = 1;
3044 }
3045 } else {
3046 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
3047 my_data->voice_feature_set = 0;
3048 }
3049 }
3050 }
3051
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05303052#ifdef RECORD_PLAY_CONCURRENCY
3053 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_REC_PLAY_CONC, value, sizeof(value));
3054 if (err >= 0) {
3055 if (!strncmp("true", value, sizeof("true"))) {
3056 ALOGD("setting record playback concurrency to true");
3057 my_data->rec_play_conc_set = true;
3058 } else {
3059 ALOGD("setting record playback concurrency to false");
3060 my_data->rec_play_conc_set = false;
3061 }
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05303062 }
3063#endif
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303064 native_audio_set_params(platform, parms, value, sizeof(value));
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303065 ALOGV("%s: exit with code(%d)", __func__, ret);
3066 return ret;
3067}
3068
3069int platform_set_incall_recording_session_id(void *platform,
3070 uint32_t session_id, int rec_mode)
3071{
3072 int ret = 0;
3073 struct platform_data *my_data = (struct platform_data *)platform;
3074 struct audio_device *adev = my_data->adev;
3075 struct mixer_ctl *ctl;
3076 const char *mixer_ctl_name = "Voc VSID";
3077 int num_ctl_values;
3078 int i;
3079
3080 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3081 if (!ctl) {
3082 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3083 __func__, mixer_ctl_name);
3084 ret = -EINVAL;
3085 } else {
3086 num_ctl_values = mixer_ctl_get_num_values(ctl);
3087 for (i = 0; i < num_ctl_values; i++) {
3088 if (mixer_ctl_set_value(ctl, i, session_id)) {
3089 ALOGV("Error: invalid session_id: %x", session_id);
3090 ret = -EINVAL;
3091 break;
3092 }
3093 }
3094 }
3095
3096 if (my_data->csd != NULL) {
3097 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3098 if (ret < 0) {
3099 ALOGE("%s: csd_client_start_record failed, error %d",
3100 __func__, ret);
3101 }
3102 }
3103
3104 return ret;
3105}
3106
3107int platform_stop_incall_recording_usecase(void *platform)
3108{
3109 int ret = 0;
3110 struct platform_data *my_data = (struct platform_data *)platform;
3111
3112 if (my_data->csd != NULL) {
3113 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3114 if (ret < 0) {
3115 ALOGE("%s: csd_client_stop_record failed, error %d",
3116 __func__, ret);
3117 }
3118 }
3119
3120 return ret;
3121}
3122
3123int platform_start_incall_music_usecase(void *platform)
3124{
3125 int ret = 0;
3126 struct platform_data *my_data = (struct platform_data *)platform;
3127
3128 if (my_data->csd != NULL) {
3129 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3130 if (ret < 0) {
3131 ALOGE("%s: csd_client_start_playback failed, error %d",
3132 __func__, ret);
3133 }
3134 }
3135
3136 return ret;
3137}
3138
3139int platform_stop_incall_music_usecase(void *platform)
3140{
3141 int ret = 0;
3142 struct platform_data *my_data = (struct platform_data *)platform;
3143
3144 if (my_data->csd != NULL) {
3145 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3146 if (ret < 0) {
3147 ALOGE("%s: csd_client_stop_playback failed, error %d",
3148 __func__, ret);
3149 }
3150 }
3151
3152 return ret;
3153}
3154
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07003155int platform_update_lch(void *platform, struct voice_session *session,
3156 enum voice_lch_mode lch_mode)
3157{
3158 int ret = 0;
3159 struct platform_data *my_data = (struct platform_data *)platform;
3160
3161 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
3162 ret = my_data->csd->set_lch(session->vsid, lch_mode);
3163 else
3164 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
3165
3166 return ret;
3167}
3168
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303169static void get_audiocal(void *platform, void *keys, void *pReply) {
3170 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303171 struct stream_out out={0};
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303172 struct str_parms *query = (struct str_parms *)keys;
3173 struct str_parms *reply=(struct str_parms *)pReply;
3174 acdb_audio_cal_cfg_t cal={0};
3175 uint8_t *dptr = NULL;
3176 char value[512] = {0};
3177 char *rparms=NULL;
3178 int ret=0, err;
3179 uint32_t param_len;
3180
3181 if(query==NULL || platform==NULL || reply==NULL) {
3182 ALOGE("[%s] received null pointer",__func__);
3183 ret=-EINVAL;
3184 goto done;
3185 }
3186 /* parse audiocal configuration keys */
3187 ret = parse_audiocal_cfg(query, &cal);
3188 if(ret == 0) {
3189 /* No calibration keys found */
3190 goto done;
3191 }
3192 err = str_parms_get_str(query, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, sizeof(value));
3193 if (err >= 0) {
3194 str_parms_del(query, AUDIO_PARAMETER_KEY_AUD_CALDATA);
3195 } else {
3196 goto done;
3197 }
3198
3199 if(cal.dev_id & AUDIO_DEVICE_BIT_IN) {
3200 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
3201 } else if(cal.dev_id) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303202 out.devices = cal.dev_id;
3203 cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303204 }
3205 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
3206 if (cal.acdb_dev_id < 0) {
3207 ALOGE("%s: Failed. Could not find acdb id for snd device(%d)",
3208 __func__, cal.snd_dev_id);
3209 ret = -EINVAL;
3210 goto done_key_audcal;
3211 }
3212 ALOGD("[%s] Getting audio calibration for snd_device(%d) acdb_id(%d)",
3213 __func__, cal.snd_dev_id, cal.acdb_dev_id);
3214
3215 param_len = MAX_SET_CAL_BYTE_SIZE;
3216 dptr = (uint8_t*)calloc(param_len, sizeof(uint8_t));
3217 if(dptr == NULL) {
3218 ALOGE("[%s] Memory allocation failed for length %d",__func__,param_len);
3219 ret = -ENOMEM;
3220 goto done_key_audcal;
3221 }
3222 if (my_data->acdb_get_audio_cal != NULL) {
3223 ret = my_data->acdb_get_audio_cal((void*)&cal, (void*)dptr, &param_len);
3224 if (ret == 0) {
3225 int dlen;
3226 if(param_len == 0 || param_len == MAX_SET_CAL_BYTE_SIZE) {
3227 ret = -EINVAL;
3228 goto done_key_audcal;
3229 }
3230 /* Allocate memory for encoding */
3231 rparms = (char*)calloc((param_len*2), sizeof(char));
3232 if(rparms == NULL) {
3233 ALOGE("[%s] Memory allocation failed for size %d",
3234 __func__, param_len*2);
3235 ret = -ENOMEM;
3236 goto done_key_audcal;
3237 }
3238 if(cal.persist==0 && cal.module_id && cal.param_id) {
3239 err = b64encode(dptr+12, param_len-12, rparms);
3240 } else {
3241 err = b64encode(dptr, param_len, rparms);
3242 }
3243 if(err < 0) {
3244 ALOGE("[%s] failed to convert data to string", __func__);
3245 ret = -EINVAL;
3246 goto done_key_audcal;
3247 }
3248 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
3249 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, rparms);
3250 }
3251 }
3252done_key_audcal:
3253 if(ret != 0) {
3254 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
3255 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, "");
3256 }
3257done:
3258 if(dptr != NULL)
3259 free(dptr);
3260 if(rparms != NULL)
3261 free(rparms);
3262}
3263
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303264void platform_get_parameters(void *platform,
3265 struct str_parms *query,
3266 struct str_parms *reply)
3267{
3268 struct platform_data *my_data = (struct platform_data *)platform;
3269 char *str = NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303270 char value[512] = {0};
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303271 int ret;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303272 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303273
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303274 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
3275 value, sizeof(value));
3276 if (ret >= 0) {
3277 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
3278 my_data->slowtalk?"true":"false");
3279 }
3280
Avinash Vaishd5fa4572014-09-15 14:41:14 +05303281 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE,
3282 value, sizeof(value));
3283 if (ret >= 0) {
3284 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE,
3285 my_data->hd_voice?"true":"false");
3286 }
3287
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303288 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
3289 value, sizeof(value));
3290 if (ret >= 0) {
3291 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
3292 strlcpy(value, "on", sizeof(value));
3293 } else {
3294 strlcpy(value, "off", sizeof(value));
3295 }
3296
3297 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
3298 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303299 native_audio_get_params(query, reply, value, sizeof(value));
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303300
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303301 /* Handle audio calibration keys */
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303302 kv_pairs = str_parms_to_str(reply);
3303 ALOGV("%s: exit: returns - %s", __func__, kv_pairs);
3304 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303305}
3306
3307/* Delay in Us */
3308int64_t platform_render_latency(audio_usecase_t usecase)
3309{
3310 switch (usecase) {
3311 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3312 return DEEP_BUFFER_PLATFORM_DELAY;
3313 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3314 return LOW_LATENCY_PLATFORM_DELAY;
3315 default:
3316 return 0;
3317 }
3318}
3319
3320int platform_update_usecase_from_source(int source, int usecase)
3321{
3322 ALOGV("%s: input source :%d", __func__, source);
Mingming Yin5bba6cb2015-07-30 14:59:12 -07003323 if (source == AUDIO_SOURCE_FM_RX_A2DP ||
3324 source == AUDIO_SOURCE_FM_TUNER)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303325 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
3326 return usecase;
3327}
3328
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303329bool platform_listen_device_needs_event(snd_device_t snd_device)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303330{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303331 bool needs_event = false;
3332
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303333 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
3334 (snd_device < SND_DEVICE_IN_END) &&
3335 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
3336 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303337 needs_event = true;
3338
3339 return needs_event;
3340}
3341
3342bool platform_listen_usecase_needs_event(audio_usecase_t uc_id)
3343{
3344 bool needs_event = false;
3345
3346 switch(uc_id){
3347 /* concurrent playback usecases needs event */
3348 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3349 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
3350 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
3351 needs_event = true;
3352 break;
3353 /* concurrent playback in low latency allowed */
3354 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3355 break;
3356 /* concurrent playback FM needs event */
3357 case USECASE_AUDIO_PLAYBACK_FM:
3358 needs_event = true;
3359 break;
3360
3361 /* concurrent capture usecases, no event, capture handled by device
3362 * USECASE_AUDIO_RECORD:
3363 * USECASE_AUDIO_RECORD_COMPRESS:
3364 * USECASE_AUDIO_RECORD_LOW_LATENCY:
3365
3366 * USECASE_VOICE_CALL:
3367 * USECASE_VOICE2_CALL:
3368 * USECASE_VOLTE_CALL:
3369 * USECASE_QCHAT_CALL:
3370 * USECASE_VOWLAN_CALL:
3371 * USECASE_COMPRESS_VOIP_CALL:
3372 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
3373 * USECASE_INCALL_REC_UPLINK:
3374 * USECASE_INCALL_REC_DOWNLINK:
3375 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
3376 * USECASE_INCALL_REC_UPLINK_COMPRESS:
3377 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
3378 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
3379 * USECASE_INCALL_MUSIC_UPLINK:
3380 * USECASE_INCALL_MUSIC_UPLINK2:
3381 * USECASE_AUDIO_SPKR_CALIB_RX:
3382 * USECASE_AUDIO_SPKR_CALIB_TX:
3383 */
3384 default:
3385 ALOGV("%s:usecase_id[%d} no need to raise event.", __func__, uc_id);
3386 }
3387 return needs_event;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303388}
3389
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07003390bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
3391{
3392 bool needs_event = false;
3393
3394 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
3395 (snd_device < SND_DEVICE_IN_END) &&
3396 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
3397 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
3398 needs_event = true;
3399
3400 return needs_event;
3401}
3402
3403bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
3404{
3405 bool needs_event = false;
3406
3407 switch(uc_id){
3408 /* concurrent playback usecases needs event */
3409 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3410 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
3411 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
3412 needs_event = true;
3413 break;
3414 /* concurrent playback in low latency allowed */
3415 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3416 break;
3417 /* concurrent playback FM needs event */
3418 case USECASE_AUDIO_PLAYBACK_FM:
3419 needs_event = true;
3420 break;
3421
3422 /* concurrent capture usecases, no event, capture handled by device
3423 * USECASE_AUDIO_RECORD:
3424 * USECASE_AUDIO_RECORD_COMPRESS:
3425 * USECASE_AUDIO_RECORD_LOW_LATENCY:
3426
3427 * USECASE_VOICE_CALL:
3428 * USECASE_VOICE2_CALL:
3429 * USECASE_VOLTE_CALL:
3430 * USECASE_QCHAT_CALL:
3431 * USECASE_VOWLAN_CALL:
3432 * USECASE_COMPRESS_VOIP_CALL:
3433 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
3434 * USECASE_INCALL_REC_UPLINK:
3435 * USECASE_INCALL_REC_DOWNLINK:
3436 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
3437 * USECASE_INCALL_REC_UPLINK_COMPRESS:
3438 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
3439 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
3440 * USECASE_INCALL_MUSIC_UPLINK:
3441 * USECASE_INCALL_MUSIC_UPLINK2:
3442 * USECASE_AUDIO_SPKR_CALIB_RX:
3443 * USECASE_AUDIO_SPKR_CALIB_TX:
3444 */
3445 default:
3446 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
3447 }
3448 return needs_event;
3449}
3450
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303451/* Read offload buffer size from a property.
3452 * If value is not power of 2 round it to
3453 * power of 2.
3454 */
3455uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
3456{
3457 char value[PROPERTY_VALUE_MAX] = {0};
3458 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3459 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
3460 atoi(value)) {
3461 fragment_size = atoi(value) * 1024;
3462 }
3463
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303464 // For FLAC use max size since it is loss less, and has sampling rates
3465 // upto 192kHZ
3466 if (info != NULL && !info->has_video &&
3467 info->format == AUDIO_FORMAT_FLAC) {
3468 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3469 ALOGV("FLAC fragment size %d", fragment_size);
3470 }
3471
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303472 if (info != NULL && info->has_video && info->is_streaming) {
3473 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
3474 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07003475 __func__, fragment_size);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303476 }
3477
3478 fragment_size = ALIGN( fragment_size, 1024);
3479
3480 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
3481 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3482 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
3483 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3484 ALOGV("%s: fragment_size %d", __func__, fragment_size);
3485 return fragment_size;
3486}
3487
3488uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
3489{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303490 uint32_t fragment_size = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303491 uint32_t bits_per_sample = 16;
Alexy Joseph2ce25e22015-06-18 12:02:01 -07003492 uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303493
3494 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
3495 bits_per_sample = 32;
3496 }
3497
Alexy Joseph2ce25e22015-06-18 12:02:01 -07003498 //duration is set to 40 ms worth of stereo data at 48Khz
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303499 //with 16 bit per sample, modify this when the channel
3500 //configuration is different
3501 fragment_size = (pcm_offload_time
3502 * info->sample_rate
3503 * (bits_per_sample >> 3)
3504 * popcount(info->channel_mask))/1000;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303505 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
3506 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
3507 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
3508 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
Preetam Singh Ranawat6efde5c2015-04-24 11:04:22 +05303509 // To have same PCM samples for all channels, the buffer size requires to
3510 // be multiple of (number of channels * bytes per sample)
3511 // For writes to succeed, the buffer must be written at address which is multiple of 32
Preetam Singh Ranawat8347e462015-05-27 11:14:03 +05303512 fragment_size = ALIGN(fragment_size, ((bits_per_sample >> 3)* popcount(info->channel_mask) * 32));
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303513
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303514 ALOGI("PCM offload Fragment size to %d bytes", fragment_size);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303515 return fragment_size;
3516}
3517
Asish Bhattacharya9e25c492015-07-10 14:23:28 +05303518bool platform_use_small_buffer(audio_offload_info_t* info)
3519{
3520 return OFFLOAD_USE_SMALL_BUFFER;
3521}
3522
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303523int platform_is_external_codec (char *snd_card_name)
3524{
3525
3526 if (!strncmp(snd_card_name, "msm8952-tomtom-snd-card",
3527 sizeof("msm8952-tomtom-snd-card")) ||
3528 !strncmp(snd_card_name, "msm8976-tasha-snd-card",
3529 sizeof("msm8976-tasha-snd-card")))
3530 {
3531 /* external codec, for rest/old of the external codecs
3532 we dont support this funtionality(chaning AFE params)
3533 at the monment
3534 */
3535 return 1;
3536 }
3537 else {
3538 /* internal codec */
3539 return 0;
3540 }
3541}
3542
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303543int platform_set_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303544 snd_device_t snd_device,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303545 unsigned int bit_width, unsigned int sample_rate)
3546{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303547 int ret = 0;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303548 int backend_idx = DEFAULT_CODEC_BACKEND;
3549 struct platform_data *my_data = (struct platform_data *)adev->platform;
3550 ALOGV("%s bit width: %d, sample rate: %d\n", __func__, bit_width, sample_rate);
3551
Preetam Singh Ranawate6755952015-04-27 16:31:54 +05303552 const char *snd_card_name = mixer_get_name(adev->mixer);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303553 int is_external_codec = platform_is_external_codec(snd_card_name);
3554
3555
3556
3557 backend_idx = platform_get_backend_index(snd_device);
3558 ALOGV("%s bit width: %d, sample rate: %d backend_idx - %d\n",
3559 __func__, bit_width, sample_rate, backend_idx);
3560
3561 if (bit_width !=
3562 my_data->current_backend_cfg[backend_idx].bit_width) {
3563
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303564 struct mixer_ctl *ctl;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303565 if (!is_external_codec) {
3566 ctl = mixer_get_ctl_by_name(adev->mixer,
3567 "MI2S_RX Format");
3568
3569 } else {
3570 ctl = mixer_get_ctl_by_name(adev->mixer,
3571 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3572 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303573 if (!ctl) {
3574 ALOGE("%s: Could not get ctl for mixer command - %s",
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303575 __func__, my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303576 return -EINVAL;
3577 }
3578
3579 if (bit_width == 24) {
3580 mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3581 } else {
3582 mixer_ctl_set_enum_by_string(ctl, "S16_LE");
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303583 if (backend_idx != HEADPHONE_44_1_BACKEND)
3584 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303585 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303586 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3587 ALOGD("%s: %s mixer set to %d bit", __func__,
3588 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303589 }
3590
3591 /*
3592 * Backend sample rate configuration follows:
3593 * 16 bit playback - 48khz for streams at any valid sample rate
3594 * 24 bit playback - 48khz for stream sample rate less than 48khz
3595 * 24 bit playback - 96khz for sample rate range of 48khz to 96khz
3596 * 24 bit playback - 192khz for sample rate range of 96khz to 192 khz
3597 * Upper limit is inclusive in the sample rate range.
3598 */
3599 // TODO: This has to be more dynamic based on policy file
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303600
3601 if ((sample_rate != my_data->current_backend_cfg[(int)backend_idx].sample_rate) &&
3602 (is_external_codec) ) {
3603 /* sample rate update is needed only for external codecs which
3604 support 24 bit playback*/
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303605 char *rate_str = NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303606 struct mixer_ctl *ctl;
3607
3608 switch (sample_rate) {
3609 case 8000:
3610 case 11025:
3611 case 16000:
3612 case 22050:
3613 case 32000:
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303614 case 48000:
3615 rate_str = "KHZ_48";
3616 break;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303617 case 44100:
3618 rate_str = "KHZ_44P1";
3619 break;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303620 case 64000:
3621 case 88200:
3622 case 96000:
3623 rate_str = "KHZ_96";
3624 break;
3625 case 176400:
3626 case 192000:
3627 rate_str = "KHZ_192";
3628 break;
3629 default:
3630 rate_str = "KHZ_48";
3631 break;
3632 }
3633
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303634 ctl = mixer_get_ctl_by_name(adev->mixer,
3635 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303636 if(!ctl) {
3637 ALOGE("%s: Could not get ctl for mixer command - %s",
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303638 __func__, my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303639 return -EINVAL;
3640 }
3641
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303642 ALOGD("%s: %s set to %s", __func__,
3643 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303644 mixer_ctl_set_enum_by_string(ctl, rate_str);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303645 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303646 }
3647
3648 return ret;
3649}
3650
3651bool platform_check_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303652 struct audio_usecase* usecase,
3653 snd_device_t snd_device,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303654 unsigned int* new_bit_width,
3655 unsigned int* new_sample_rate)
3656{
3657 bool backend_change = false;
3658 struct listnode *node;
3659 struct stream_out *out = NULL;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303660 char value[PROPERTY_VALUE_MAX] = {0};
3661 unsigned int bit_width;
3662 unsigned int sample_rate;
3663 int backend_idx = DEFAULT_CODEC_BACKEND;
3664 int usecase_backend_idx = DEFAULT_CODEC_BACKEND;
3665 struct platform_data *my_data = (struct platform_data *)adev->platform;
3666
3667 backend_idx = platform_get_backend_index(snd_device);
3668
3669 bit_width = *new_bit_width;
3670 sample_rate = *new_sample_rate;
3671
3672 ALOGI("%s Codec selected backend: %d current bit width: %d and sample rate: %d",
3673 __func__, backend_idx, bit_width, sample_rate);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303674
3675 // For voice calls use default configuration
3676 // force routing is not required here, caller will do it anyway
3677 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3678 ALOGW("%s:Use default bw and sr for voice/voip calls ",__func__);
3679 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3680 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3681 } else {
3682 /*
3683 * The backend should be configured at highest bit width and/or
3684 * sample rate amongst all playback usecases.
3685 * If the selected sample rate and/or bit width differ with
3686 * current backend sample rate and/or bit width, then, we set the
3687 * backend re-configuration flag.
3688 *
3689 * Exception: 16 bit playbacks is allowed through 16 bit/48 khz backend only
3690 */
3691 list_for_each(node, &adev->usecase_list) {
3692 struct audio_usecase *curr_usecase;
3693 curr_usecase = node_to_item(node, struct audio_usecase, list);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303694 if (curr_usecase->type == PCM_PLAYBACK &&
3695 usecase != curr_usecase) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303696 struct stream_out *out =
3697 (struct stream_out*) curr_usecase->stream.out;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303698 usecase_backend_idx = platform_get_backend_index(curr_usecase->out_snd_device);
3699
3700 if (out != NULL &&
3701 usecase_backend_idx == backend_idx) {
3702 ALOGV("%s: usecase Offload playback running bw %d sr %d device %s be_idx %d",
3703 __func__, out->bit_width, out->sample_rate,
3704 platform_get_snd_device_name(curr_usecase->out_snd_device), usecase_backend_idx);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303705 if (bit_width < out->bit_width)
3706 bit_width = out->bit_width;
3707 if (sample_rate < out->sample_rate)
3708 sample_rate = out->sample_rate;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303709 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3710 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303711 }
3712 }
3713 }
3714 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303715 if (backend_idx != HEADPHONE_44_1_BACKEND) {
3716 // 16 bit playbacks are allowed through 16 bit/48 khz backend only for
3717 // all non-native streams
3718 if (16 == bit_width) {
3719 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3720 ALOGD("%s: resetting sample_rate back to default, "
3721 "backend_idx: %d", __func__, backend_idx);
3722 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303723
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303724 // 24 bit playback on speakers is allowed through 48 khz backend only
3725 // bit width re-configured based on platform info
3726 if ((24 == bit_width) &&
3727 (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER)) {
3728 bit_width = (uint32_t)platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
3729 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3730 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303731 }
Ashish Jainb449be32015-07-19 05:39:23 -07003732
3733 /*
3734 * Sample rate greater than 48K is only supported by external codecs on
3735 * specific devices e.g. Headphones, reset the sample rate to
3736 * default value if not external codec.
3737 */
3738 if (!is_external_codec)
3739 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3740
3741
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303742 ALOGI("%s Codec selected backend: %d updated bit width: %d and sample rate: %d",
3743 __func__, backend_idx, bit_width, sample_rate);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303744 // Force routing if the expected bitwdith or samplerate
3745 // is not same as current backend comfiguration
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303746 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3747 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate)) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303748 *new_bit_width = bit_width;
3749 *new_sample_rate = sample_rate;
3750 backend_change = true;
3751 ALOGI("%s Codec backend needs to be updated. new bit width: %d new sample rate: %d",
3752 __func__, *new_bit_width, *new_sample_rate);
3753 }
3754
3755 return backend_change;
3756}
3757
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08003758bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303759 struct audio_usecase *usecase, snd_device_t snd_device)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303760{
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303761 unsigned int new_bit_width;
3762 unsigned int new_sample_rate;
3763 int backend_idx = DEFAULT_CODEC_BACKEND;
3764 struct platform_data *my_data = (struct platform_data *)adev->platform;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303765
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303766 ALOGV("%s: usecase = %d", __func__, usecase->id );
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303767
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303768 backend_idx = platform_get_backend_index(snd_device);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303769
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303770 new_bit_width = usecase->stream.out->bit_width;
3771 new_sample_rate = usecase->stream.out->sample_rate;
3772
3773 ALOGI("%s: Usecase bitwidth %d, samplerate %d, backend_idx %d",
3774 __func__, new_bit_width, new_sample_rate, backend_idx);
3775 if (platform_check_codec_backend_cfg(adev, usecase, snd_device,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303776 &new_bit_width, &new_sample_rate)) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303777 platform_set_codec_backend_cfg(adev, snd_device,
3778 new_bit_width, new_sample_rate);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303779 return true;
3780 }
3781
3782 return false;
3783}
3784
3785int platform_set_snd_device_backend(snd_device_t device, const char *backend)
3786{
3787 int ret = 0;
3788
3789 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3790 ALOGE("%s: Invalid snd_device = %d",
3791 __func__, device);
3792 ret = -EINVAL;
3793 goto done;
3794 }
3795
3796 if (backend_table[device]) {
3797 free(backend_table[device]);
3798 }
3799 backend_table[device] = strdup(backend);
3800done:
3801 return ret;
3802}
3803
3804int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3805{
3806 int ret = 0;
3807 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3808 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3809 ret = -EINVAL;
3810 goto done;
3811 }
3812
3813 if ((type != 0) && (type != 1)) {
3814 ALOGE("%s: invalid usecase type", __func__);
3815 ret = -EINVAL;
3816 }
3817 pcm_device_table[usecase][type] = pcm_id;
3818done:
3819 return ret;
3820}
3821
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07003822void platform_get_device_to_be_id_map(int **device_to_be_id, int *length)
3823{
3824 *device_to_be_id = msm_device_to_be_id;
3825 *length = msm_be_id_array_len;
3826}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303827int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask, int snd_id)
3828{
3829 int ret = 0;
3830 int channels = audio_channel_count_from_out_mask(channel_mask);
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07003831
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303832 char channel_map[8];
3833 memset(channel_map, 0, sizeof(channel_map));
3834 /* Following are all most common standard WAV channel layouts
3835 overridden by channel mask if its allowed and different */
3836 switch (channels) {
3837 case 1:
3838 /* AUDIO_CHANNEL_OUT_MONO */
3839 channel_map[0] = PCM_CHANNEL_FC;
3840 break;
3841 case 2:
3842 /* AUDIO_CHANNEL_OUT_STEREO */
3843 channel_map[0] = PCM_CHANNEL_FL;
3844 channel_map[1] = PCM_CHANNEL_FR;
3845 break;
3846 case 3:
3847 /* AUDIO_CHANNEL_OUT_2POINT1 */
3848 channel_map[0] = PCM_CHANNEL_FL;
3849 channel_map[1] = PCM_CHANNEL_FR;
3850 channel_map[2] = PCM_CHANNEL_FC;
3851 break;
3852 case 4:
3853 /* AUDIO_CHANNEL_OUT_QUAD_SIDE */
3854 channel_map[0] = PCM_CHANNEL_FL;
3855 channel_map[1] = PCM_CHANNEL_FR;
3856 channel_map[2] = PCM_CHANNEL_LS;
3857 channel_map[3] = PCM_CHANNEL_RS;
3858 if (channel_mask == AUDIO_CHANNEL_OUT_QUAD_BACK)
3859 {
3860 channel_map[2] = PCM_CHANNEL_LB;
3861 channel_map[3] = PCM_CHANNEL_RB;
3862 }
3863 if (channel_mask == AUDIO_CHANNEL_OUT_SURROUND)
3864 {
3865 channel_map[2] = PCM_CHANNEL_FC;
3866 channel_map[3] = PCM_CHANNEL_CS;
3867 }
3868 break;
3869 case 5:
3870 /* AUDIO_CHANNEL_OUT_PENTA */
3871 channel_map[0] = PCM_CHANNEL_FL;
3872 channel_map[1] = PCM_CHANNEL_FR;
3873 channel_map[2] = PCM_CHANNEL_FC;
3874 channel_map[3] = PCM_CHANNEL_LB;
3875 channel_map[4] = PCM_CHANNEL_RB;
3876 break;
3877 case 6:
3878 /* AUDIO_CHANNEL_OUT_5POINT1 */
3879 channel_map[0] = PCM_CHANNEL_FL;
3880 channel_map[1] = PCM_CHANNEL_FR;
3881 channel_map[2] = PCM_CHANNEL_FC;
3882 channel_map[3] = PCM_CHANNEL_LFE;
3883 channel_map[4] = PCM_CHANNEL_LB;
3884 channel_map[5] = PCM_CHANNEL_RB;
3885 if (channel_mask == AUDIO_CHANNEL_OUT_5POINT1_SIDE)
3886 {
3887 channel_map[4] = PCM_CHANNEL_LS;
3888 channel_map[5] = PCM_CHANNEL_RS;
3889 }
3890 break;
3891 case 7:
3892 /* AUDIO_CHANNEL_OUT_6POINT1 */
3893 channel_map[0] = PCM_CHANNEL_FL;
3894 channel_map[1] = PCM_CHANNEL_FR;
3895 channel_map[2] = PCM_CHANNEL_FC;
3896 channel_map[3] = PCM_CHANNEL_LFE;
3897 channel_map[4] = PCM_CHANNEL_LB;
3898 channel_map[5] = PCM_CHANNEL_RB;
3899 channel_map[6] = PCM_CHANNEL_CS;
3900 break;
3901 case 8:
3902 /* AUDIO_CHANNEL_OUT_7POINT1 */
3903 channel_map[0] = PCM_CHANNEL_FL;
3904 channel_map[1] = PCM_CHANNEL_FR;
3905 channel_map[2] = PCM_CHANNEL_FC;
3906 channel_map[3] = PCM_CHANNEL_LFE;
3907 channel_map[4] = PCM_CHANNEL_LB;
3908 channel_map[5] = PCM_CHANNEL_RB;
3909 channel_map[6] = PCM_CHANNEL_LS;
3910 channel_map[7] = PCM_CHANNEL_RS;
3911 break;
3912 default:
3913 ALOGE("unsupported channels %d for setting channel map", channels);
3914 return -1;
3915 }
3916 ret = platform_set_channel_map(platform, channels, channel_map, snd_id);
3917 return ret;
3918}
3919
3920int platform_get_edid_info(void *platform)
3921{
3922 struct platform_data *my_data = (struct platform_data *)platform;
3923 struct audio_device *adev = my_data->adev;
3924 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3925 char *sad = block;
3926 int num_audio_blocks;
3927 int channel_count = 2;
3928 int i, ret, count;
3929
3930 struct mixer_ctl *ctl;
3931 char edid_data[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE + 1] = {0};
3932 edid_audio_info *info;
3933
3934 if (my_data->edid_valid) {
3935 /* use cached edid */
3936 return 0;
3937 }
3938
3939 if (my_data->edid_info == NULL) {
3940 my_data->edid_info =
3941 (struct edid_audio_info *)calloc(1, sizeof(struct edid_audio_info));
3942 }
3943
3944 info = my_data->edid_info;
3945
3946 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3947 if (!ctl) {
3948 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3949 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
3950 goto fail;
3951 }
3952
3953 mixer_ctl_update(ctl);
3954
3955 count = mixer_ctl_get_num_values(ctl);
3956
3957 /* Read SAD blocks, clamping the maximum size for safety */
3958 if (count > (int)sizeof(block))
3959 count = (int)sizeof(block);
3960
3961 ret = mixer_ctl_get_array(ctl, block, count);
3962 if (ret != 0) {
3963 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3964 goto fail;
3965 }
3966 edid_data[0] = count;
3967 memcpy(&edid_data[1], block, count);
3968
3969#ifdef AUDIO_FEATURE_ENABLED_HDMI_EDID
3970 if (!edid_get_sink_caps(info, edid_data)) {
3971 ALOGE("%s: Failed to get HDMI sink capabilities", __func__);
3972 goto fail;
3973 }
3974 my_data->edid_valid = true;
3975 return 0;
3976#endif
3977fail:
3978 if (my_data->edid_info) {
3979 free(my_data->edid_info);
3980 my_data->edid_info = NULL;
3981 my_data->edid_valid = false;
3982 }
3983 ALOGE("%s: return -EINVAL", __func__);
3984 return -EINVAL;
3985}
3986
3987
3988int platform_set_channel_allocation(void *platform, int channel_alloc)
3989{
3990 struct mixer_ctl *ctl;
3991 const char *mixer_ctl_name = "HDMI RX CA";
3992 int ret;
3993 struct platform_data *my_data = (struct platform_data *)platform;
3994 struct audio_device *adev = my_data->adev;
3995
3996 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3997 if (!ctl) {
3998 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3999 __func__, mixer_ctl_name);
4000 ret = EINVAL;
4001 }
4002 ALOGD(":%s channel allocation = 0x%x", __func__, channel_alloc);
4003 ret = mixer_ctl_set_value(ctl, 0, channel_alloc);
4004
4005 if (ret < 0) {
4006 ALOGE("%s: Could not set ctl, error:%d ", __func__, ret);
4007 }
4008
4009 return ret;
4010}
4011
4012int platform_set_channel_map(void *platform, int ch_count, char *ch_map, int snd_id)
4013{
4014 struct mixer_ctl *ctl;
4015 char mixer_ctl_name[44]; // max length of name is 44 as defined
4016 int ret;
4017 unsigned int i;
4018 int set_values[8] = {0};
4019 char device_num[13]; // device number up to 2 digit
4020 struct platform_data *my_data = (struct platform_data *)platform;
4021 struct audio_device *adev = my_data->adev;
4022 ALOGV("%s channel_count:%d",__func__, ch_count);
4023 if (NULL == ch_map) {
4024 ALOGE("%s: Invalid channel mapping used", __func__);
4025 return -EINVAL;
4026 }
4027 strlcpy(mixer_ctl_name, "Playback Channel Map", sizeof(mixer_ctl_name));
4028 if (snd_id >= 0) {
4029 snprintf(device_num, sizeof(device_num), "%d", snd_id);
4030 strncat(mixer_ctl_name, device_num, 13);
4031 }
4032
4033 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
4034
4035 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4036 if (!ctl) {
4037 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4038 __func__, mixer_ctl_name);
4039 return -EINVAL;
4040 }
4041 for (i = 0; i< ARRAY_SIZE(set_values); i++) {
4042 set_values[i] = ch_map[i];
4043 }
4044
4045 ALOGD("%s: set mapping(%d %d %d %d %d %d %d %d) for channel:%d", __func__,
4046 set_values[0], set_values[1], set_values[2], set_values[3], set_values[4],
4047 set_values[5], set_values[6], set_values[7], ch_count);
4048
4049 ret = mixer_ctl_set_array(ctl, set_values, ch_count);
4050 if (ret < 0) {
4051 ALOGE("%s: Could not set ctl, error:%d ch_count:%d",
4052 __func__, ret, ch_count);
4053 }
4054 return ret;
4055}
4056
4057unsigned char platform_map_to_edid_format(int audio_format)
4058{
4059 unsigned char format;
4060 switch (audio_format & AUDIO_FORMAT_MAIN_MASK) {
4061 case AUDIO_FORMAT_AC3:
4062 ALOGV("%s: AC3", __func__);
4063 format = AC3;
4064 break;
4065 case AUDIO_FORMAT_AAC:
4066 ALOGV("%s:AAC", __func__);
4067 format = AAC;
4068 break;
4069 case AUDIO_FORMAT_E_AC3:
4070 ALOGV("%s:E_AC3", __func__);
4071 format = DOLBY_DIGITAL_PLUS;
4072 break;
4073 case AUDIO_FORMAT_PCM_16_BIT:
4074 case AUDIO_FORMAT_PCM_16_BIT_OFFLOAD:
4075 case AUDIO_FORMAT_PCM_24_BIT_OFFLOAD:
4076 default:
4077 ALOGV("%s:PCM", __func__);
4078 format = LPCM;
4079 break;
4080 }
4081 return format;
4082}
4083
4084uint32_t platform_get_compress_passthrough_buffer_size(
4085 audio_offload_info_t* info)
4086{
4087 uint32_t fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
4088 if (!info->has_video)
4089 fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
4090
4091 return fragment_size;
4092}
4093
4094void platform_reset_edid_info(void *platform) {
4095
4096 ALOGV("%s:", __func__);
4097 struct platform_data *my_data = (struct platform_data *)platform;
4098 if (my_data->edid_info) {
4099 ALOGV("%s :free edid", __func__);
4100 free(my_data->edid_info);
4101 my_data->edid_info = NULL;
4102 }
4103}
4104
4105bool platform_is_edid_supported_format(void *platform, int format)
4106{
4107 struct platform_data *my_data = (struct platform_data *)platform;
4108 struct audio_device *adev = my_data->adev;
4109 edid_audio_info *info = NULL;
4110 int num_audio_blocks;
4111 int i, ret, count;
4112 unsigned char format_id = platform_map_to_edid_format(format);
4113
4114 ret = platform_get_edid_info(platform);
4115 info = (edid_audio_info *)my_data->edid_info;
4116 if (ret == 0 && info != NULL) {
4117 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
4118 /*
4119 * To check
4120 * is there any special for CONFIG_HDMI_PASSTHROUGH_CONVERT
4121 * & DOLBY_DIGITAL_PLUS
4122 */
4123 if (info->audio_blocks_array[i].format_id == format_id) {
4124 ALOGV("%s:platform_is_edid_supported_format true %x",
4125 __func__, format);
4126 return true;
4127 }
4128 }
4129 }
4130 ALOGV("%s:platform_is_edid_supported_format false %x",
4131 __func__, format);
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07004132 return false;
4133}
4134
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304135int platform_set_edid_channels_configuration(void *platform, int channels) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004136
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304137 struct platform_data *my_data = (struct platform_data *)platform;
4138 struct audio_device *adev = my_data->adev;
4139 edid_audio_info *info = NULL;
4140 int num_audio_blocks;
4141 int channel_count = 2;
4142 int i, ret, count;
4143 char default_channelMap[MAX_CHANNELS_SUPPORTED] = {0};
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004144
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304145 ret = platform_get_edid_info(platform);
4146 info = (edid_audio_info *)my_data->edid_info;
4147 if(ret == 0 && info != NULL) {
4148 if (channels > 2) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004149
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304150 ALOGV("%s:able to get HDMI sink capabilities multi channel playback",
4151 __func__);
4152 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
4153 if (info->audio_blocks_array[i].format_id == LPCM &&
4154 info->audio_blocks_array[i].channels > channel_count &&
4155 info->audio_blocks_array[i].channels <= MAX_HDMI_CHANNEL_CNT) {
4156 channel_count = info->audio_blocks_array[i].channels;
4157 }
4158 }
4159 ALOGV("%s:channel_count:%d", __func__, channel_count);
4160 /*
4161 * Channel map is set for supported hdmi max channel count even
4162 * though the input channel count set on adm is less than or equal to
4163 * max supported channel count
4164 */
4165 platform_set_channel_map(platform, channel_count, info->channel_map, -1);
4166 platform_set_channel_allocation(platform, info->channel_allocation);
4167 } else {
4168 default_channelMap[0] = PCM_CHANNEL_FL;
4169 default_channelMap[1] = PCM_CHANNEL_FR;
4170 platform_set_channel_map(platform,2,default_channelMap,-1);
4171 platform_set_channel_allocation(platform,0);
4172 }
4173 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004174
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004175 return 0;
4176}
4177
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304178void platform_cache_edid(void * platform)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004179{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304180 platform_get_edid_info(platform);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004181}
4182
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304183void platform_invalidate_edid(void * platform)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004184{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304185 struct platform_data *my_data = (struct platform_data *)platform;
4186 my_data->edid_valid = false;
4187 if (my_data->edid_info) {
4188 memset(my_data->edid_info, 0, sizeof(struct edid_audio_info));
4189 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004190}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304191
4192int platform_set_mixer_control(struct stream_out *out, const char * mixer_ctl_name,
4193 const char *mixer_val)
4194{
4195 struct audio_device *adev = out->dev;
4196 struct mixer_ctl *ctl = NULL;
4197 ALOGD("setting mixer ctl %s with value %s", mixer_ctl_name, mixer_val);
4198 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4199 if (!ctl) {
4200 ALOGE("%s: could not get ctl for mixer cmd - %s",
4201 __func__, mixer_ctl_name);
4202 return -EINVAL;
4203 }
4204
4205 return mixer_ctl_set_enum_by_string(ctl, mixer_val);
4206}
4207
4208int platform_set_hdmi_config(struct stream_out *out)
4209{
4210 struct listnode *node;
4211 struct audio_usecase *usecase;
4212 struct audio_device *adev = out->dev;
4213 const char *hdmi_format_ctrl = "HDMI RX Format";
4214 const char *hdmi_rate_ctrl = "HDMI_RX SampleRate";
4215 int sample_rate = out->sample_rate;
4216 /*TODO: Add rules and check if this needs to be done.*/
4217 if((is_offload_usecase(out->usecase)) &&
4218 (out->compr_config.codec->compr_passthr == PASSTHROUGH ||
4219 out->compr_config.codec->compr_passthr == PASSTHROUGH_CONVERT)) {
4220 /* TODO: can we add mixer control for channels here avoid setting */
4221 if ((out->format == AUDIO_FORMAT_E_AC3 ||
4222 out->format == AUDIO_FORMAT_E_AC3_JOC) &&
4223 (out->compr_config.codec->compr_passthr == PASSTHROUGH))
4224 sample_rate = out->sample_rate * 4;
4225 ALOGD("%s:HDMI compress format and samplerate %d, sample_rate %d",
4226 __func__, out->sample_rate, sample_rate);
4227 platform_set_mixer_control(out, hdmi_format_ctrl, "Compr");
4228 switch (sample_rate) {
4229 case 32000:
4230 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_32");
4231 break;
4232 case 44100:
4233 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_44_1");
4234 break;
4235 case 96000:
4236 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_96");
4237 break;
4238 case 176400:
4239 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_176_4");
4240 break;
4241 case 192000:
4242 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_192");
4243 break;
4244 case 128000:
4245 if (out->format != AUDIO_FORMAT_E_AC3) {
4246 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_128");
4247 break;
4248 } else
4249 ALOGW("Unsupported sample rate for E_AC3 32K");
4250 default:
4251 case 48000:
4252 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_48");
4253 break;
4254 }
4255 } else {
4256 ALOGD("%s: HDMI pcm and samplerate %d", __func__,
4257 out->sample_rate);
4258 platform_set_mixer_control(out, hdmi_format_ctrl, "LPCM");
4259 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_48");
4260 }
4261
4262 /*
4263 * Deroute all the playback streams routed to HDMI so that
4264 * the back end is deactivated. Note that backend will not
4265 * be deactivated if any one stream is connected to it.
4266 */
4267 list_for_each(node, &adev->usecase_list) {
4268 usecase = node_to_item(node, struct audio_usecase, list);
4269 ALOGV("%s:disable: usecase type %d, devices 0x%x", __func__,
4270 usecase->type, usecase->devices);
4271 if (usecase->type == PCM_PLAYBACK &&
4272 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
4273 disable_audio_route(adev, usecase);
4274 }
4275 }
4276
4277 /*
4278 * Enable all the streams disabled above. Now the HDMI backend
4279 * will be activated with new channel configuration
4280 */
4281 list_for_each(node, &adev->usecase_list) {
4282 usecase = node_to_item(node, struct audio_usecase, list);
4283 ALOGV("%s:enable: usecase type %d, devices 0x%x", __func__,
4284 usecase->type, usecase->devices);
4285 if (usecase->type == PCM_PLAYBACK &&
4286 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
4287 enable_audio_route(adev, usecase);
4288 }
4289 }
4290
4291 return 0;
4292}
4293
4294int platform_set_device_params(struct stream_out *out, int param, int value)
4295{
4296 struct audio_device *adev = out->dev;
4297 struct mixer_ctl *ctl;
4298 char *mixer_ctl_name = "Device PP Params";
4299 int ret = 0;
4300 uint32_t set_values[] = {0,0};
4301
4302 set_values[0] = param;
4303 set_values[1] = value;
4304
4305 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4306 if (!ctl) {
4307 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4308 __func__, mixer_ctl_name);
4309 ret = -EINVAL;
4310 goto end;
4311 }
4312
4313 ALOGV("%s: Setting device pp params param: %d, value %d mixer ctrl:%s",
4314 __func__,param, value, mixer_ctl_name);
4315 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
4316
4317end:
4318 return ret;
4319}
4320
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05304321int platform_get_subsys_image_name(char *buf)
4322{
4323 strlcpy(buf, PLATFORM_IMAGE_NAME, sizeof(PLATFORM_IMAGE_NAME));
4324 return 0;
4325}
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08004326
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304327/*
4328 * This is a lookup table to map android audio input device to audio h/w interface (backend).
4329 * The table can be extended for other input devices by adding appropriate entries.
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304330 * The audio interface for a particular input device need to be added in
4331 * audio_platform_info.xml file.
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304332 */
4333struct audio_device_to_audio_interface audio_device_to_interface_table[] = {
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304334 {AUDIO_DEVICE_IN_BUILTIN_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC), ""},
4335 {AUDIO_DEVICE_IN_BACK_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BACK_MIC), ""},
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304336};
4337
4338int audio_device_to_interface_table_len =
4339 sizeof(audio_device_to_interface_table) / sizeof(audio_device_to_interface_table[0]);
4340
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304341int platform_set_audio_device_interface(const char * device_name,
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304342 const char *intf_name,
4343 const char *codec_type)
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08004344{
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304345 int ret = 0;
4346 int i;
4347
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304348 if (device_name == NULL || intf_name == NULL || codec_type == NULL) {
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304349 ALOGE("%s: Invalid input", __func__);
4350
4351 ret = -EINVAL;
4352 goto done;
4353 }
4354
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304355 ALOGD("%s: Enter, device name:%s, intf name:%s, codec_type:%s", __func__,
4356 device_name, intf_name, codec_type);
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304357
4358 size_t device_name_len = strlen(device_name);
4359 for (i = 0; i < audio_device_to_interface_table_len; i++) {
4360 char* name = audio_device_to_interface_table[i].device_name;
4361 size_t name_len = strlen(name);
4362 if ((name_len == device_name_len) &&
4363 (strncmp(device_name, name, name_len) == 0)) {
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304364 if (is_external_codec &&
4365 (strncmp(codec_type, "external", strlen(codec_type)) == 0)) {
4366 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304367 __func__, device_name, intf_name);
4368
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304369 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304370 sizeof(audio_device_to_interface_table[i].interface_name));
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304371 } else if (!is_external_codec &&
4372 (strncmp(codec_type, "internal", strlen(codec_type)) == 0)) {
4373 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
4374 __func__, device_name, intf_name);
4375
4376 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
4377 sizeof(audio_device_to_interface_table[i].interface_name));
4378 } else
4379 ALOGE("Invalid codec_type specified. Ignoring this interface entry.");
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304380 goto done;
4381 }
4382 }
4383 ALOGE("%s: Could not find matching device name %s",
4384 __func__, device_name);
4385
4386 ret = -EINVAL;
4387
4388done:
4389 return ret;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08004390}
Laxminath Kasam82252432015-05-29 18:37:11 +05304391
4392/*
4393 * This is a lookup table to map names of speaker device with respective left and right TZ names.
4394 * Also the tz names for a particular left or right speaker can be overriden by adding
4395 * corresponding entry in audio_platform_info.xml file.
4396 */
4397struct speaker_device_to_tz_names speaker_device_tz_names = {
4398 {SND_DEVICE_OUT_SPEAKER, "", ""},
4399};
4400
4401const char *platform_get_spkr_1_tz_name(snd_device_t snd_device)
4402{
4403 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
4404 return speaker_device_tz_names.spkr_1_tz_name;
4405 else
4406 return "";
4407}
4408
4409const char *platform_get_spkr_2_tz_name(snd_device_t snd_device)
4410{
4411 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
4412 return speaker_device_tz_names.spkr_2_tz_name;
4413 else
4414 return "";
4415}
4416
4417int platform_set_spkr_device_tz_names(snd_device_t index,
4418 const char *spkr_1_tz_name, const char *spkr_2_tz_name)
4419{
4420 int ret = 0;
4421
4422 if (spkr_1_tz_name == NULL && spkr_2_tz_name == NULL) {
4423 ALOGE("%s: Invalid input", __func__);
4424 ret = -EINVAL;
4425 goto done;
4426 }
4427 if (index != speaker_device_tz_names.snd_device) {
4428 ALOGE("%s: not matching speaker device\n");
4429 ret = -EINVAL;
4430 goto done;
4431 }
4432 ALOGD("%s: Enter, spkr_1_tz_name :%s, spkr_2_tz_name:%s",
4433 __func__, spkr_1_tz_name, spkr_2_tz_name);
4434
4435 if (spkr_1_tz_name != NULL)
4436 strlcpy(speaker_device_tz_names.spkr_1_tz_name, spkr_1_tz_name,
4437 sizeof(speaker_device_tz_names.spkr_1_tz_name));
4438
4439 if (spkr_2_tz_name != NULL)
4440 strlcpy(speaker_device_tz_names.spkr_2_tz_name, spkr_2_tz_name,
4441 sizeof(speaker_device_tz_names.spkr_2_tz_name));
4442done:
4443 return ret;
4444}
Asish Bhattacharya4a69acd2015-07-12 20:54:14 +05304445
4446bool platform_send_gain_dep_cal(void *platform __unused,
4447 int level __unused)
4448{
4449 return 0;
4450}