blob: 857d9e1100ddb92e55615b1e8688cb7e36d4b9ff [file] [log] [blame]
Naresh Tannirue3b18452014-03-04 14:44:27 +05301/*
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05302 * Copyright (c) 2013-2016, 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)
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +053041#define MAX_MIXER_XML_PATH 100
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"
Tanya Finkeldd78e062015-05-26 04:29:56 -070044#define MIXER_XML_PATH_SBC "/system/etc/mixer_paths_sbc.xml"
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +053045#define MIXER_XML_PATH_MSM8909_PM8916 "/system/etc/mixer_paths_msm8909_pm8916.xml"
Walter Yang7ca90d92014-05-06 17:48:02 +080046#define MIXER_XML_PATH_QRD_SKUH "/system/etc/mixer_paths_qrd_skuh.xml"
47#define MIXER_XML_PATH_QRD_SKUI "/system/etc/mixer_paths_qrd_skui.xml"
Walter Yang19f244a2014-06-17 13:30:08 +080048#define MIXER_XML_PATH_QRD_SKUHF "/system/etc/mixer_paths_qrd_skuhf.xml"
Meng Wangf00485b2014-06-03 19:44:38 +080049#define MIXER_XML_PATH_SKUK "/system/etc/mixer_paths_skuk.xml"
Walter Yang42886c52014-10-23 14:31:48 +080050#define MIXER_XML_PATH_SKUA "/system/etc/mixer_paths_skua.xml"
51#define MIXER_XML_PATH_SKUC "/system/etc/mixer_paths_skuc.xml"
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +053052#define MIXER_XML_PATH_SKUE "/system/etc/mixer_paths_skue.xml"
Meng Wangcfefb8b2014-12-05 14:35:55 +080053#define MIXER_XML_PATH_SKUL "/system/etc/mixer_paths_skul.xml"
Walter Yangcd132722015-04-08 16:04:30 +080054#define MIXER_XML_PATH_SKUM "/system/etc/mixer_paths_qrd_skum.xml"
Xiaojun Sang68b39442015-09-23 16:29:43 +080055#define MIXER_XML_PATH_SKU1 "/system/etc/mixer_paths_qrd_sku1.xml"
56#define MIXER_XML_PATH_SKU2 "/system/etc/mixer_paths_qrd_sku2.xml"
Meng Wang2d747622015-08-07 10:11:41 +080057#define MIXER_XML_PATH_SKUN_CAJON "/system/etc/mixer_paths_qrd_skun_cajon.xml"
Xiaojun Sang9cd237a2015-11-20 15:30:18 +080058#define MIXER_XML_PATH_SKU3 "/system/etc/mixer_paths_qrd_sku3.xml"
Meng Wangf00485b2014-06-03 19:44:38 +080059#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053060#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +053061#define MIXER_XML_PATH_I2S "/system/etc/mixer_paths_i2s.xml"
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +053062#define MIXER_XML_PATH_WCD9306 "/system/etc/mixer_paths_wcd9306.xml"
Aviral Gupta8ed0eec2014-08-25 10:22:11 +053063#define MIXER_XML_PATH_WCD9330 "/system/etc/mixer_paths_wcd9330.xml"
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +053064#define MIXER_XML_PATH_WCD9335 "/system/etc/mixer_paths_wcd9335.xml"
65#define MIXER_XML_PATH_WCD9326 "/system/etc/mixer_paths_wcd9326.xml"
Meng Wangf1ec20c2015-06-26 10:32:32 +080066#define MIXER_XML_PATH_SKUN "/system/etc/mixer_paths_qrd_skun.xml"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053067#define PLATFORM_INFO_XML_PATH "/system/etc/audio_platform_info.xml"
Dhananjay Kumara68d7af2015-05-25 19:11:30 +053068#define PLATFORM_INFO_XML_PATH_EXTCODEC "/system/etc/audio_platform_info_extcodec.xml"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +053069
Naresh Tannirue3b18452014-03-04 14:44:27 +053070#define LIB_ACDB_LOADER "libacdbloader.so"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053071#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Avinash Vaish71c066d2014-08-27 12:32:35 +053072#define CVD_VERSION_MIXER_CTL "CVD Version"
Naresh Tannirue3b18452014-03-04 14:44:27 +053073
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053074#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
75#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
76#define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
77#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
78/* Used in calculating fragment size for pcm offload */
Alexy Joseph2ce25e22015-06-18 12:02:01 -070079#define PCM_OFFLOAD_BUFFER_DURATION 40 /* 40 millisecs */
Naresh Tannirue3b18452014-03-04 14:44:27 +053080
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053081/* MAX PCM fragment size cannot be increased further due
82 * to flinger's cblk size of 1mb,and it has to be a multiple of
83 * 24 - lcm of channels supported by DSP
Naresh Tannirue3b18452014-03-04 14:44:27 +053084 */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053085#define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024)
Naresh Tannirude7d1752015-07-01 15:07:46 +053086#define MIN_PCM_OFFLOAD_FRAGMENT_SIZE 512
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +053087
88/*
89 * Offload buffer size for compress passthrough
90 */
91#define MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (2 * 1024)
92#define MAX_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (8 * 1024)
Naresh Tannirue3b18452014-03-04 14:44:27 +053093
Preetam Singh Ranawat6efde5c2015-04-24 11:04:22 +053094#define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y))
95#define ALIGN(x, y) ((y) * DIV_ROUND_UP((x), (y)))
Naresh Tannirue3b18452014-03-04 14:44:27 +053096/*
97 * This file will have a maximum of 38 bytes:
98 *
99 * 4 bytes: number of audio blocks
100 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
101 * Maximum 10 * 3 bytes: SAD blocks
102 */
103#define MAX_SAD_BLOCKS 10
104#define SAD_BLOCK_SIZE 3
Avinash Vaish71c066d2014-08-27 12:32:35 +0530105#define MAX_CVD_VERSION_STRING_SIZE 100
Karthik Reddy Katta8513f432016-04-12 14:29:27 +0530106#define MAX_SND_CARD_STRING_SIZE 100
Naresh Tannirue3b18452014-03-04 14:44:27 +0530107
108/* EDID format ID for LPCM audio */
109#define EDID_FORMAT_LPCM 1
110
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700111/* fallback app type if the default app type from acdb loader fails */
112#define DEFAULT_APP_TYPE 0x11130
Naresh Tanniru2727f822015-05-11 15:27:08 +0530113#define DEFAULT_APP_TYPE_RX_PATH 0x11130
114#define DEFAULT_APP_TYPE_TX_PATH 0x11132
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700115
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530116/* Retry for delay in FW loading*/
117#define RETRY_NUMBER 20
118#define RETRY_US 500000
119#define MAX_SND_CARD 8
120
121#define SAMPLE_RATE_8KHZ 8000
122#define SAMPLE_RATE_16KHZ 16000
123
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530124#define MAX_SET_CAL_BYTE_SIZE 65536
125
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530126#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530127#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530128#define AUDIO_PARAMETER_KEY_HD_VOICE "hd_voice"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530129#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530130#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
131#define AUDIO_PARAMETER_KEY_AUD_CALRESULT "cal_result"
132
Karthik Reddy Katta8513f432016-04-12 14:29:27 +0530133/* Reload ACDB files from specified path */
134#define AUDIO_PARAMETER_KEY_RELOAD_ACDB "reload_acdb"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530135
136/* Query external audio device connection status */
137#define AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE "ext_audio_device"
138
139#define EVENT_EXTERNAL_SPK_1 "qc_ext_spk_1"
140#define EVENT_EXTERNAL_SPK_2 "qc_ext_spk_2"
141#define EVENT_EXTERNAL_MIC "qc_ext_mic"
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530142#define MAX_CAL_NAME 20
Naresh Tanniru34a303c2016-01-27 17:26:41 +0530143#define MAX_MIME_TYPE_LENGTH 30
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530144
145char cal_name_info[WCD9XXX_MAX_CAL][MAX_CAL_NAME] = {
146 [WCD9XXX_ANC_CAL] = "anc_cal",
147 [WCD9XXX_MBHC_CAL] = "mbhc_cal",
Banajit Goswami20cdd212015-09-11 01:11:30 -0700148 [WCD9XXX_VBAT_CAL] = "vbat_cal",
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530149};
150
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530151#define AUDIO_PARAMETER_KEY_REC_PLAY_CONC "rec_play_conc_on"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530152
Sidipotu Ashokf490be52015-10-20 10:41:34 +0530153#define AUDIO_PARAMETER_IS_HW_DECODER_SESSION_AVAILABLE "is_hw_dec_session_available"
Sidipotu Ashok42483b62015-09-08 10:21:44 +0530154
Naresh Tanniru34a303c2016-01-27 17:26:41 +0530155char dsp_only_decoders_mime[][MAX_MIME_TYPE_LENGTH] = {
Sidipotu Ashok42483b62015-09-08 10:21:44 +0530156 "audio/x-ms-wma" /* wma*/ ,
157 "audio/x-ms-wma-lossless" /* wma lossless */ ,
158 "audio/x-ms-wma-pro" /* wma prop */ ,
159 "audio/amr-wb-plus" /* amr wb plus */ ,
160 "audio/alac" /*alac */ ,
161 "audio/x-ape" /*ape */,
162};
163
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530164enum {
165 VOICE_FEATURE_SET_DEFAULT,
166 VOICE_FEATURE_SET_VOLUME_BOOST
167};
168
Naresh Tannirue3b18452014-03-04 14:44:27 +0530169struct audio_block_header
170{
171 int reserved;
172 int length;
173};
174
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530175typedef struct acdb_audio_cal_cfg {
176 uint32_t persist;
177 uint32_t snd_dev_id;
178 audio_devices_t dev_id;
179 int32_t acdb_dev_id;
180 uint32_t app_type;
181 uint32_t topo_id;
182 uint32_t sampling_rate;
183 uint32_t cal_type;
184 uint32_t module_id;
185 uint32_t param_id;
186} acdb_audio_cal_cfg_t;
187
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530188/* Audio calibration related functions */
Naresh Tannirue3b18452014-03-04 14:44:27 +0530189typedef void (*acdb_deallocate_t)();
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530190typedef int (*acdb_init_t)(const char *, char *, int);
191typedef void (*acdb_send_audio_cal_t)(int, int, int , int);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530192typedef void (*acdb_send_voice_cal_t)(int, int);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530193typedef int (*acdb_reload_vocvoltable_t)(int);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700194typedef int (*acdb_get_default_app_type_t)(void);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530195typedef int (*acdb_loader_get_calibration_t)(char *attr, int size, void *data);
196acdb_loader_get_calibration_t acdb_loader_get_calibration;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530197typedef int (*acdb_set_audio_cal_t) (void *, void *, uint32_t);
198typedef int (*acdb_get_audio_cal_t) (void *, void *, uint32_t*);
Ben Rombergerfeca4b82015-07-07 20:40:44 -0700199typedef int (*acdb_send_common_top_t) (void);
Banajit Goswami20cdd212015-09-11 01:11:30 -0700200typedef int (*acdb_set_codec_data_t) (void *, char *);
Karthik Reddy Katta8513f432016-04-12 14:29:27 +0530201typedef int (*acdb_reload_t) (char *, char *, char *, int);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530202
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530203typedef struct codec_backend_cfg {
204 uint32_t sample_rate;
205 uint32_t bit_width;
206 char *bitwidth_mixer_ctl;
207 char *samplerate_mixer_ctl;
208} codec_backend_cfg_t;
209
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +0530210static native_audio_prop na_props = {0, 0, 0};
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530211
Naresh Tannirue3b18452014-03-04 14:44:27 +0530212struct platform_data {
213 struct audio_device *adev;
214 bool fluence_in_spkr_mode;
215 bool fluence_in_voice_call;
216 bool fluence_in_voice_rec;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530217 bool fluence_in_audio_rec;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530218 bool external_spk_1;
219 bool external_spk_2;
220 bool external_mic;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530221 int fluence_type;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530222 char fluence_cap[PROPERTY_VALUE_MAX];
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530223 int fluence_mode;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530224 bool slowtalk;
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530225 bool hd_voice;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530226 bool ec_ref_enabled;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530227 bool is_wsa_speaker;
Ramjee Singh203473b2015-06-09 15:18:42 +0530228 bool is_acdb_initialized;
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +0530229 bool hifi_audio;
Banajit Goswami20cdd212015-09-11 01:11:30 -0700230 /* Vbat monitor related flags */
231 bool is_vbat_speaker;
232 bool gsm_mode_enabled;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530233 /* Audio calibration related functions */
234 void *acdb_handle;
235 int voice_feature_set;
236 acdb_init_t acdb_init;
237 acdb_deallocate_t acdb_deallocate;
238 acdb_send_audio_cal_t acdb_send_audio_cal;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530239 acdb_set_audio_cal_t acdb_set_audio_cal;
240 acdb_get_audio_cal_t acdb_get_audio_cal;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530241 acdb_send_voice_cal_t acdb_send_voice_cal;
242 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700243 acdb_get_default_app_type_t acdb_get_default_app_type;
Ben Rombergerfeca4b82015-07-07 20:40:44 -0700244 acdb_send_common_top_t acdb_send_common_top;
Banajit Goswami20cdd212015-09-11 01:11:30 -0700245 acdb_set_codec_data_t acdb_set_codec_data;
Karthik Reddy Katta8513f432016-04-12 14:29:27 +0530246 acdb_reload_t acdb_reload;
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530247#ifdef RECORD_PLAY_CONCURRENCY
248 bool rec_play_conc_set;
249#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530250 void *hw_info;
251 struct csd_data *csd;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530252 void *edid_info;
253 bool edid_valid;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530254 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Manish Dewanganba9fcfa2016-03-24 16:20:06 +0530255 codec_backend_cfg_t current_tx_backend_cfg[MAX_CODEC_TX_BACKENDS];
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -0700256 char ec_ref_mixer_path[64];
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +0530257 char codec_version[CODEC_VERSION_MAX_LENGTH];
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +0530258 int hw_dep_fd;
Karthik Reddy Katta8513f432016-04-12 14:29:27 +0530259 char cvd_version[MAX_CVD_VERSION_STRING_SIZE];
260 char snd_card_name[MAX_SND_CARD_STRING_SIZE];
261 int metainfo_key;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530262};
263
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530264static bool is_external_codec = false;
265static const int pcm_device_table_of_ext_codec[AUDIO_USECASE_MAX][2] = {
Venkata Narendra Kumar Gutta0d293362015-12-18 15:52:27 +0530266 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE_OF_EXT_CODEC, QCHAT_CALL_PCM_DEVICE_OF_EXT_CODEC}
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530267};
268
269/* List of use cases that has different PCM device ID's for internal and external codecs */
Venkata Narendra Kumar Gutta0d293362015-12-18 15:52:27 +0530270static const int misc_usecase[AUDIO_USECASE_MAX] = { USECASE_QCHAT_CALL };
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530271
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530272int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530273 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
274 DEEP_BUFFER_PCM_DEVICE},
275 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
276 LOWLATENCY_PCM_DEVICE},
277 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
278 MULTIMEDIA2_PCM_DEVICE},
279 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
280 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
Dhananjay Kumara68d7af2015-05-25 19:11:30 +0530281 /* Below entries are initialized with invalid values
282 * Valid values should be updated from fnc platform_info_init()
283 * based on pcm ids defined in audio_platform_info.xml.
284 */
285 [USECASE_AUDIO_PLAYBACK_OFFLOAD2] = {-1, -1},
286 [USECASE_AUDIO_PLAYBACK_OFFLOAD3] = {-1, -1},
287 [USECASE_AUDIO_PLAYBACK_OFFLOAD4] = {-1, -1},
288 [USECASE_AUDIO_PLAYBACK_OFFLOAD5] = {-1, -1},
289 [USECASE_AUDIO_PLAYBACK_OFFLOAD6] = {-1, -1},
290 [USECASE_AUDIO_PLAYBACK_OFFLOAD7] = {-1, -1},
291 [USECASE_AUDIO_PLAYBACK_OFFLOAD8] = {-1, -1},
292 [USECASE_AUDIO_PLAYBACK_OFFLOAD9] = {-1, -1},
Naresh Tanniru3a7dbe72015-06-25 20:08:01 -0700293 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE, MULTIMEDIA3_PCM_DEVICE},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530294 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
295 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
296 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
297 LOWLATENCY_PCM_DEVICE},
298 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
299 MULTIMEDIA2_PCM_DEVICE},
300 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
301 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
302 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
303 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
304 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
305 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
306 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Karthik Reddy Katta3b0a60c2014-04-06 14:52:37 +0530307 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Venkata Narendra Kumar Gutta0d293362015-12-18 15:52:27 +0530308 [USECASE_VOICEMMODE1_CALL] = {-1, -1}, /* pcm ids updated from platform info file */
309 [USECASE_VOICEMMODE2_CALL] = {-1, -1}, /* pcm ids updated from platform info file */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530310 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
311 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
312 AUDIO_RECORD_PCM_DEVICE},
313 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
314 AUDIO_RECORD_PCM_DEVICE},
315 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
316 AUDIO_RECORD_PCM_DEVICE},
317 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
318 COMPRESS_CAPTURE_DEVICE},
319 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
320 COMPRESS_CAPTURE_DEVICE},
321 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
322 COMPRESS_CAPTURE_DEVICE},
323 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
324 INCALL_MUSIC_UPLINK_PCM_DEVICE},
325 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
326 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
327 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
328 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530329 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
330 AFE_PROXY_RECORD_PCM_DEVICE},
331 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
332 AFE_PROXY_RECORD_PCM_DEVICE},
Naresh Tannirue3b18452014-03-04 14:44:27 +0530333};
334
335/* Array to store sound devices */
336static const char * const device_table[SND_DEVICE_MAX] = {
337 [SND_DEVICE_NONE] = "none",
338 /* Playback sound devices */
339 [SND_DEVICE_OUT_HANDSET] = "handset",
340 [SND_DEVICE_OUT_SPEAKER] = "speaker",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530341 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = "speaker-ext-1",
342 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = "speaker-ext-2",
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530343 [SND_DEVICE_OUT_SPEAKER_WSA] = "wsa-speaker",
Venkata Narendra Kumar Gutta55def542015-06-16 13:59:08 +0530344 [SND_DEVICE_OUT_SPEAKER_VBAT] = "vbat-speaker",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530345 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
346 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530347 [SND_DEVICE_OUT_HEADPHONES_44_1] = "headphones-44.1",
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530348 [SND_DEVICE_OUT_LINE] = "line",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530349 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530350 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530351 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = "speaker-and-headphones-ext-1",
352 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = "speaker-and-headphones-ext-2",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530353 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
354 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530355 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = "wsa-voice-speaker",
Venkata Narendra Kumar Gutta55def542015-06-16 13:59:08 +0530356 [SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = "vbat-voice-speaker",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530357 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530358 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530359 [SND_DEVICE_OUT_HDMI] = "hdmi",
360 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
361 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530362 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530363 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
364 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
365 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530366 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530367 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
368 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
369 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
370 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
371 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
372 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
373 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
374 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
375 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
376 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
377 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530378 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Banajit Goswami20cdd212015-09-11 01:11:30 -0700379 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT] = "speaker-protected-vbat",
380 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT] = "voice-speaker-protected-vbat",
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530381#ifdef RECORD_PLAY_CONCURRENCY
382 [SND_DEVICE_OUT_VOIP_HANDSET] = "voip-handset",
383 [SND_DEVICE_OUT_VOIP_SPEAKER] = "voip-speaker",
384 [SND_DEVICE_OUT_VOIP_HEADPHONES] = "voip-headphones",
385#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +0530386
387 /* Capture sound devices */
388 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530389 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = "handset-mic-ext",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530390 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530391 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
392 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
393 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
394 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
395 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
396 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
397 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
398 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
399 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
400 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
401 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
402 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
403 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
404 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
405 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
406 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530407 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
408 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
409 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
410 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700411 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530412 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700413 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530414 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530415 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
416 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
417 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530418 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
419 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
420 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
421 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530422 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
423 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
424 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530425 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530426 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
427 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
428 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
429 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
430 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
431 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
432 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530433 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside",
434 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside",
435 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside",
436 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside",
437 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside",
Sidipotu Ashok3bcca232014-11-07 14:41:58 +0530438 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = "aanc-fluence-dmic-handset",
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530439 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
440 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = "quad-mic",
441 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
442 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
Shiv Maliyappanahalli5a10aea2015-07-02 10:36:23 -0700443 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530444};
445
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530446// Platform specific backend bit width table
447static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
448
Naresh Tannirue3b18452014-03-04 14:44:27 +0530449/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530450static int acdb_device_table[SND_DEVICE_MAX] = {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530451 [SND_DEVICE_NONE] = -1,
452 [SND_DEVICE_OUT_HANDSET] = 7,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530453 [SND_DEVICE_OUT_SPEAKER] = 14,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530454 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = 14,
455 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = 14,
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530456 [SND_DEVICE_OUT_SPEAKER_WSA] = 135,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700457 [SND_DEVICE_OUT_SPEAKER_VBAT] = 135,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530458 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530459 [SND_DEVICE_OUT_LINE] = 10,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530460 [SND_DEVICE_OUT_HEADPHONES] = 10,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530461 [SND_DEVICE_OUT_HEADPHONES_44_1] = 10,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530462 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530463 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 10,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530464 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = 10,
465 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = 10,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530466 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530467 [SND_DEVICE_OUT_VOICE_LINE] = 10,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530468 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530469 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = 135,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700470 [SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = 135,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530471 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
472 [SND_DEVICE_OUT_HDMI] = 18,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530473 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530474 [SND_DEVICE_OUT_BT_SCO] = 22,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530475 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530476 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
477 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
478 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530479 [SND_DEVICE_OUT_VOICE_TX] = 45,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530480 [SND_DEVICE_OUT_AFE_PROXY] = 0,
481 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530482 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530483 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
484 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
485 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
486 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
487 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
488 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
489 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530490 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
491 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700492 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT] = 124,
493 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT] = 101,
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530494#ifdef RECORD_PLAY_CONCURRENCY
495 [SND_DEVICE_OUT_VOIP_HANDSET] = 133,
496 [SND_DEVICE_OUT_VOIP_SPEAKER] = 132,
497 [SND_DEVICE_OUT_VOIP_HEADPHONES] = 134,
498#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +0530499
500 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530501 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530502 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
503 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
504 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
505 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
506 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
507 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
508 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
509 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
510 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
511 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
512 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
513 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
514 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
515 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
516 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530517 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530518 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530519 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
520 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
521 [SND_DEVICE_IN_HDMI_MIC] = 4,
522 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700523 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 122,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530524 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700525 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 123,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530526 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
527 [SND_DEVICE_IN_VOICE_DMIC] = 41,
528 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
529 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530530 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
531 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
532 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530533 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
534 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
535 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
536 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530537 [SND_DEVICE_IN_VOICE_RX] = 44,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530538 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
539 [SND_DEVICE_IN_CAPTURE_FM] = 0,
540 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
541 [SND_DEVICE_IN_QUAD_MIC] = 46,
542 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
543 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
544 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530545 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12,
546 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12,
547 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
548 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
549 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
Venkata Narendra Kumar Gutta9bb5af62015-06-05 11:53:06 +0530550 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = 105,
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530551 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
552 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = 126,
553 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 127,
554 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
Shiv Maliyappanahalli5a10aea2015-07-02 10:36:23 -0700555 [SND_DEVICE_IN_THREE_MIC] = 46,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530556};
557
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530558struct name_to_index {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530559 char name[100];
560 unsigned int index;
561};
Naresh Tannirue3b18452014-03-04 14:44:27 +0530562
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530563#define TO_NAME_INDEX(X) #X, X
Naresh Tannirue3b18452014-03-04 14:44:27 +0530564
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530565/* Used to get index from parsed sting */
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530566static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530567 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
568 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530569 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_1)},
570 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_2)},
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530571 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA)},
Banajit Goswami20cdd212015-09-11 01:11:30 -0700572 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_VBAT)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530573 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
574 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530575 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_44_1)},
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530576 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530577 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530578 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530579 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1)},
580 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530581 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
582 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530583 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_WSA)},
Banajit Goswami20cdd212015-09-11 01:11:30 -0700584 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_VBAT)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530585 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530586 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530587 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
588 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
589 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
590 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
591 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
592 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
593 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530594 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TX)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530595 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
596 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
597 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
598 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
599 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
600 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
601 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
602 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
603 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
604 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
605 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530606 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Banajit Goswami20cdd212015-09-11 01:11:30 -0700607 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT)},
608 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT)},
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530609#ifdef RECORD_PLAY_CONCURRENCY
610 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HANDSET)},
611 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_SPEAKER)},
612 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HEADPHONES)},
613#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530614 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530615 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530616 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
617 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
618 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
619 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
620 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
621 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
622 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
623 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
624 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
625 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
626 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
627 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
628 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
629 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
630 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
631 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
632 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
633 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
634 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
635 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
636 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700637 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530638 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700639 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530640 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
641 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
642 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
643 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
644 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
645 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
646 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
647 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
648 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
649 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
650 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530651 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RX)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530652 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
653 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
654 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
655 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
656 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
657 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
658 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Sidipotu Ashok3bcca232014-11-07 14:41:58 +0530659 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530660 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE)},
661 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE)},
662 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE)},
663 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE)},
664 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)},
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530665 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
666 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC)},
667 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
668 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530669};
670
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530671static char * backend_tag_table[SND_DEVICE_MAX] = {0};
672static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530673
674static struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
675 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
676 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
677 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
678 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530679 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD2)},
680 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD3)},
681 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD4)},
682 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD5)},
683 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD6)},
684 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD7)},
685 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD8)},
686 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD9)},
Naresh Tanniru3a7dbe72015-06-25 20:08:01 -0700687 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530688 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
689 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
690 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
691 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
692 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
693 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
694 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
Avinash Vaish306e6072015-05-13 16:58:18 +0530695 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
696 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530697 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
698 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
699 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
700 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Xiaojun Sangb112f882015-08-03 19:38:28 +0800701 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530702};
703
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700704#define NO_COLS 2
705static int msm_be_id_array_len;
706static int (*msm_device_to_be_id)[];
707
708/* Below table lists output device to BE_ID mapping*/
709/* Update the table based on the board configuration*/
710
711static int msm_device_to_be_id_internal_codec [][NO_COLS] = {
712 {AUDIO_DEVICE_OUT_EARPIECE , 34},
713 {AUDIO_DEVICE_OUT_SPEAKER , 34},
714 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 34},
715 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 34},
716 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
717 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
718 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
719 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
720 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
721 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
722 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
723 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
724 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
725 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
726 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
727 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
728 {AUDIO_DEVICE_OUT_PROXY , 9},
729 {AUDIO_DEVICE_OUT_FM , 7},
730 {AUDIO_DEVICE_OUT_FM_TX , 8},
731 {AUDIO_DEVICE_OUT_ALL , -1},
732 {AUDIO_DEVICE_NONE , -1},
733 {AUDIO_DEVICE_OUT_DEFAULT , -1},
734};
735
736static int msm_device_to_be_id_external_codec [][NO_COLS] = {
737 {AUDIO_DEVICE_OUT_EARPIECE , 2},
738 {AUDIO_DEVICE_OUT_SPEAKER , 2},
739 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
740 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
741 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
742 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
743 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
744 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
745 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
746 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
747 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
748 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
749 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
750 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
751 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
752 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
753 {AUDIO_DEVICE_OUT_PROXY , 9},
754 {AUDIO_DEVICE_OUT_FM , 7},
755 {AUDIO_DEVICE_OUT_FM_TX , 8},
756 {AUDIO_DEVICE_OUT_ALL , -1},
757 {AUDIO_DEVICE_NONE , -1},
758 {AUDIO_DEVICE_OUT_DEFAULT , -1},
759};
760
761
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530762#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
763#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530764
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530765static bool is_misc_usecase(audio_usecase_t usecase) {
766 bool ret = false;
767 int i;
768
769 for (i = 0; i < AUDIO_USECASE_MAX; i++) {
770 if(usecase == misc_usecase[i]) {
771 ret = true;
772 break;
773 }
774 }
775 return ret;
776}
777
778
779static void update_codec_type(const char *snd_card_name) {
780
781 if (!strncmp(snd_card_name, "msm8939-tapan-snd-card",
782 sizeof("msm8939-tapan-snd-card")) ||
783 !strncmp(snd_card_name, "msm8939-tapan9302-snd-card",
Avinash Vaish306e6072015-05-13 16:58:18 +0530784 sizeof("msm8939-tapan9302-snd-card")) ||
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530785 !strncmp(snd_card_name, "msm8939-tomtom9330-snd-card",
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530786 sizeof("msm8939-tomtom9330-snd-card")) ||
787 !strncmp(snd_card_name, "msm8952-tomtom-snd-card",
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +0530788 sizeof("msm8952-tomtom-snd-card")) ||
Xiaojun Sang9cd237a2015-11-20 15:30:18 +0800789 !strncmp(snd_card_name, "msm8953-sku3-tasha-snd-card",
790 sizeof("msm8953-sku3-tasha-snd-card")) ||
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +0530791 !strncmp(snd_card_name, "msm8952-tasha-snd-card",
792 sizeof("msm8952-tasha-snd-card")) ||
793 !strncmp(snd_card_name, "msm8952-tashalite-snd-card",
794 sizeof("msm8952-tashalite-snd-card")) ||
795 !strncmp(snd_card_name, "msm8952-tasha-skun-snd-card",
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +0530796 sizeof("msm8952-tasha-skun-snd-card")) ||
Aravind Kumard7691742015-05-13 13:10:51 +0530797 !strncmp(snd_card_name, "msm8976-tasha-snd-card",
Meng Wangf1ec20c2015-06-26 10:32:32 +0800798 sizeof("msm8976-tasha-snd-card")) ||
Yeleswarapu Nagaradhesh09f30be2015-07-22 14:11:03 +0530799 !strncmp(snd_card_name, "msm8976-tashalite-snd-card",
800 sizeof("msm8976-tashalite-snd-card")) ||
Meng Wangf1ec20c2015-06-26 10:32:32 +0800801 !strncmp(snd_card_name, "msm8976-tasha-skun-snd-card",
Naresh Tanniru4d1e1a12015-12-16 19:37:50 +0530802 sizeof("msm8976-tasha-skun-snd-card")) ||
803 !strncmp(snd_card_name, "msm8937-tasha-snd-card",
804 sizeof("msm8937-tasha-snd-card")) ||
805 !strncmp(snd_card_name, "msm8937-tashalite-snd-card",
806 sizeof("msm8937-tashalite-snd-card")) ||
807 !strncmp(snd_card_name, "msm8953-tasha-snd-card",
808 sizeof("msm8953-tasha-snd-card")) ||
809 !strncmp(snd_card_name, "msm8953-tashalite-snd-card",
810 sizeof("msm8953-tashalite-snd-card")))
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +0530811 {
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530812 ALOGI("%s: snd_card_name: %s",__func__,snd_card_name);
813 is_external_codec = true;
814 }
815}
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530816static void query_platform(const char *snd_card_name,
817 char *mixer_xml_path)
818{
819 if (!strncmp(snd_card_name, "msm8x16-snd-card-mtp",
820 sizeof("msm8x16-snd-card-mtp"))) {
821 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
822 sizeof(MIXER_XML_PATH_MTP));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700823
824 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
825 msm_be_id_array_len =
826 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
827
Tanya Finkeldd78e062015-05-26 04:29:56 -0700828 } else if (!strncmp(snd_card_name, "msm8x16-snd-card-sbc",
829 sizeof("msm8x16-snd-card-sbc"))) {
830 strlcpy(mixer_xml_path, MIXER_XML_PATH_SBC,
831 sizeof(mixer_xml_path));
832
833 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
834 msm_be_id_array_len =
835 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
836
Walter Yang7ca90d92014-05-06 17:48:02 +0800837 } else if (!strncmp(snd_card_name, "msm8x16-skuh-snd-card",
838 sizeof("msm8x16-skuh-snd-card"))) {
839 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUH,
840 sizeof(MIXER_XML_PATH_QRD_SKUH));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700841
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
Walter Yang7ca90d92014-05-06 17:48:02 +0800846 } else if (!strncmp(snd_card_name, "msm8x16-skui-snd-card",
847 sizeof("msm8x16-skui-snd-card"))) {
848 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUI,
849 sizeof(MIXER_XML_PATH_QRD_SKUI));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700850
851 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
852 msm_be_id_array_len =
853 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
854
Walter Yang19f244a2014-06-17 13:30:08 +0800855 } else if (!strncmp(snd_card_name, "msm8x16-skuhf-snd-card",
856 sizeof("msm8x16-skuhf-snd-card"))) {
857 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUHF,
858 sizeof(MIXER_XML_PATH_QRD_SKUHF));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700859
860 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
861 msm_be_id_array_len =
862 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
863
Walter Yangc899d572014-05-27 21:52:17 +0800864 } else if (!strncmp(snd_card_name, "msm8939-snd-card-mtp",
Yamit Mehtac6003e22014-05-19 10:26:02 +0530865 sizeof("msm8939-snd-card-mtp"))) {
Aravind Kumar71ba22b2014-06-23 15:18:50 +0530866 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
867 sizeof(MIXER_XML_PATH_MTP));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700868
869 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
870 msm_be_id_array_len =
871 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
872
Meng Wangf00485b2014-06-03 19:44:38 +0800873 } else if (!strncmp(snd_card_name, "msm8939-snd-card-skuk",
874 sizeof("msm8939-snd-card-skuk"))) {
875 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUK,
876 sizeof(MIXER_XML_PATH_SKUK));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700877 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
878 msm_be_id_array_len =
879 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
880
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +0530881 } else if (!strncmp(snd_card_name, "msm8939-tapan-snd-card",
882 sizeof("msm8939-tapan-snd-card"))) {
883 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
884 sizeof(MIXER_XML_PATH_WCD9306));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700885 msm_device_to_be_id = msm_device_to_be_id_external_codec;
886 msm_be_id_array_len =
887 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
888
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +0530889 } else if (!strncmp(snd_card_name, "msm8939-tapan9302-snd-card",
890 sizeof("msm8939-tapan9302-snd-card"))) {
891 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
892 sizeof(MIXER_XML_PATH_WCD9306));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700893
894 msm_device_to_be_id = msm_device_to_be_id_external_codec;
895 msm_be_id_array_len =
896 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
897
Aviral Gupta8ed0eec2014-08-25 10:22:11 +0530898 } else if (!strncmp(snd_card_name, "msm8939-tomtom9330-snd-card",
899 sizeof("msm8939-tomtom9330-snd-card"))) {
900 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330,
901 sizeof(MIXER_XML_PATH_WCD9330));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700902 msm_device_to_be_id = msm_device_to_be_id_external_codec;
903 msm_be_id_array_len =
904 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
905
Aravind Kumard7691742015-05-13 13:10:51 +0530906 } else if (!strncmp(snd_card_name, "msm8976-tasha-snd-card",
907 sizeof("msm8976-tasha-snd-card"))) {
908 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335,
909 sizeof(MIXER_XML_PATH_WCD9335));
910 msm_device_to_be_id = msm_device_to_be_id_external_codec;
911 msm_be_id_array_len =
912 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
913
Yeleswarapu Nagaradhesh09f30be2015-07-22 14:11:03 +0530914 } else if (!strncmp(snd_card_name, "msm8976-tashalite-snd-card",
915 sizeof("msm8976-tashalite-snd-card"))) {
916 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326,
917 MAX_MIXER_XML_PATH);
918 msm_device_to_be_id = msm_device_to_be_id_external_codec;
919 msm_be_id_array_len =
920 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
921
Meng Wangf1ec20c2015-06-26 10:32:32 +0800922 } else if (!strncmp(snd_card_name, "msm8976-tasha-skun-snd-card",
923 sizeof("msm8976-tasha-skun-snd-card"))) {
924 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUN,
925 sizeof(MIXER_XML_PATH_SKUN));
926 msm_device_to_be_id = msm_device_to_be_id_external_codec;
927 msm_be_id_array_len =
928 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
929
Walter Yang42886c52014-10-23 14:31:48 +0800930 } else if (!strncmp(snd_card_name, "msm8909-skua-snd-card",
931 sizeof("msm8909-skua-snd-card"))) {
932 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUA,
933 sizeof(MIXER_XML_PATH_SKUA));
Walter Yang42886c52014-10-23 14:31:48 +0800934 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
935 msm_be_id_array_len =
936 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 +0530937
Walter Yang42886c52014-10-23 14:31:48 +0800938 } else if (!strncmp(snd_card_name, "msm8909-skuc-snd-card",
939 sizeof("msm8909-skuc-snd-card"))) {
940 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUC,
941 sizeof(MIXER_XML_PATH_SKUC));
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530942 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
943 msm_be_id_array_len =
944 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
945
946 } else if (!strncmp(snd_card_name, "msm8909-pm8916-snd-card",
947 sizeof("msm8909-pm8916-snd-card"))) {
948 strlcpy(mixer_xml_path, MIXER_XML_PATH_MSM8909_PM8916,
949 sizeof(MIXER_XML_PATH_MSM8909_PM8916));
Walter Yang42886c52014-10-23 14:31:48 +0800950
951 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
952 msm_be_id_array_len =
953 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 +0530954
955 } else if (!strncmp(snd_card_name, "msm8909-skue-snd-card",
956 sizeof("msm8909-skue-snd-card"))) {
957 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUE,
958 sizeof(MIXER_XML_PATH_SKUE));
959 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
960 msm_be_id_array_len =
961 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
962
Meng Wangcfefb8b2014-12-05 14:35:55 +0800963 } else if (!strncmp(snd_card_name, "msm8939-snd-card-skul",
964 sizeof("msm8939-snd-card-skul"))) {
965 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUL,
966 sizeof(MIXER_XML_PATH_SKUL));
967 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
968 msm_be_id_array_len =
969 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +0530970 } else if (!strncmp(snd_card_name, "msm8952-snd-card-mtp",
Avinash Vaish306e6072015-05-13 16:58:18 +0530971 sizeof("msm8952-snd-card-mtp"))) {
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +0530972 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
973 sizeof(MIXER_XML_PATH_MTP));
974 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
975 msm_be_id_array_len =
976 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
977 } else if (!strncmp(snd_card_name, "msm8952-tomtom-snd-card",
978 sizeof("msm8952-tomtom-snd-card"))) {
979 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330,
980 sizeof(MIXER_XML_PATH_WCD9330));
981 msm_device_to_be_id = msm_device_to_be_id_external_codec;
982 msm_be_id_array_len =
983 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Xiaojun Sang68b39442015-09-23 16:29:43 +0800984 } else if (!strncmp(snd_card_name, "msm8952-sku1-snd-card",
985 sizeof("msm8952-sku1-snd-card"))) {
986 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKU1,
987 sizeof(MIXER_XML_PATH_SKU1));
988 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
989 msm_be_id_array_len =
990 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
991 } else if (!strncmp(snd_card_name, "msm8952-sku2-snd-card",
992 sizeof("msm8952-sku2-snd-card"))) {
993 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKU2,
994 sizeof(MIXER_XML_PATH_SKU2));
995 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
996 msm_be_id_array_len =
997 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Xiaojun Sang9cd237a2015-11-20 15:30:18 +0800998 } else if (!strncmp(snd_card_name, "msm8953-sku3-tasha-snd-card",
999 sizeof("msm8953-sku3-tasha-snd-card"))) {
1000 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKU3,
1001 sizeof(MIXER_XML_PATH_SKU3));
1002 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1003 msm_be_id_array_len =
1004 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Walter Yangcd132722015-04-08 16:04:30 +08001005 } else if (!strncmp(snd_card_name, "msm8952-skum-snd-card",
1006 sizeof("msm8952-skum-snd-card"))) {
1007 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUM,
1008 sizeof(MIXER_XML_PATH_SKUM));
1009 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1010 msm_be_id_array_len =
1011 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301012 } else if (!strncmp(snd_card_name, "msm8952-tasha-snd-card",
1013 sizeof("msm8952-tasha-snd-card"))) {
1014 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335,
1015 sizeof(MIXER_XML_PATH_WCD9335));
1016 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1017 msm_be_id_array_len =
1018 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +05301019
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301020 } else if (!strncmp(snd_card_name, "msm8952-tashalite-snd-card",
1021 sizeof("msm8952-tashalite-snd-card"))) {
1022 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326,
1023 MAX_MIXER_XML_PATH);
1024 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1025 msm_be_id_array_len =
1026 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Meng Wang2d747622015-08-07 10:11:41 +08001027 } else if (!strncmp(snd_card_name, "msm8976-skun-snd-card",
1028 sizeof("msm8976-skun-snd-card"))) {
1029 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUN_CAJON,
1030 sizeof(MIXER_XML_PATH_SKUN_CAJON));
1031 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1032 msm_be_id_array_len =
1033 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Naresh Tanniru4d1e1a12015-12-16 19:37:50 +05301034
1035 } else if (!strncmp(snd_card_name, "msm8937-snd-card-mtp",
1036 sizeof("msm8937-snd-card-mtp"))) {
1037 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
1038 sizeof(MIXER_XML_PATH_MTP));
1039 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1040 msm_be_id_array_len =
1041 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1042 } else if (!strncmp(snd_card_name, "msm8937-tasha-snd-card",
1043 sizeof("msm8937-tasha-snd-card"))) {
1044 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335,
1045 sizeof(MIXER_XML_PATH_WCD9335));
1046 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1047 msm_be_id_array_len =
1048 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1049 } else if (!strncmp(snd_card_name, "msm8937-tashalite-snd-card",
1050 sizeof("msm8937-tashalite-snd-card"))) {
1051 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326,
1052 MAX_MIXER_XML_PATH);
1053 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1054 msm_be_id_array_len =
1055 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1056 } else if (!strncmp(snd_card_name, "msm8953-snd-card-mtp",
1057 sizeof("msm8953-snd-card-mtp"))) {
1058 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
1059 sizeof(MIXER_XML_PATH_MTP));
1060 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1061 msm_be_id_array_len =
1062 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1063 } else if (!strncmp(snd_card_name, "msm8953-tasha-snd-card",
1064 sizeof("msm8953-tasha-snd-card"))) {
1065 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335,
1066 sizeof(MIXER_XML_PATH_WCD9335));
1067 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1068 msm_be_id_array_len =
1069 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1070 } else if (!strncmp(snd_card_name, "msm8953-tashalite-snd-card",
1071 sizeof("msm8937-tashalite-snd-card"))) {
1072 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326,
1073 MAX_MIXER_XML_PATH);
1074 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1075 msm_be_id_array_len =
1076 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301077 } else {
1078 strlcpy(mixer_xml_path, MIXER_XML_PATH,
1079 sizeof(MIXER_XML_PATH));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001080
1081 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1082 msm_be_id_array_len =
1083 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1084
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301085 }
1086}
1087
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001088void platform_set_echo_reference(struct audio_device *adev, bool enable,
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05301089 audio_devices_t out_device __unused)
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001090{
1091 struct platform_data *my_data = (struct platform_data *)adev->platform;
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001092
1093 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1094 ALOGV("%s: disabling %s", __func__, my_data->ec_ref_mixer_path);
1095 audio_route_reset_and_update_path(adev->audio_route,
1096 my_data->ec_ref_mixer_path);
1097 }
1098
1099 if (enable) {
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001100 if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_HEADPHONES_44_1] > 0)
1101 strlcpy(my_data->ec_ref_mixer_path, "echo-reference headphones-44.1",
1102 sizeof(my_data->ec_ref_mixer_path));
Leena Winterrowdd7a04cd2016-01-07 11:50:02 -08001103 else if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_SPEAKER_VBAT] > 0)
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001104 strlcpy(my_data->ec_ref_mixer_path, "vbat-speaker echo-reference",
1105 sizeof(my_data->ec_ref_mixer_path));
1106 else
1107 strlcpy(my_data->ec_ref_mixer_path, "echo-reference",
1108 sizeof(my_data->ec_ref_mixer_path));
1109
1110
1111 ALOGD("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
1112 audio_route_apply_and_update_path(adev->audio_route,
1113 my_data->ec_ref_mixer_path);
1114 }
1115}
Banajit Goswami20cdd212015-09-11 01:11:30 -07001116void platform_set_gsm_mode(void *platform, bool enable)
1117{
1118 struct platform_data *my_data = (struct platform_data *)platform;
1119 struct audio_device *adev = my_data->adev;
1120
1121 if (my_data->gsm_mode_enabled) {
1122 my_data->gsm_mode_enabled = false;
1123 ALOGV("%s: disabling gsm mode", __func__);
1124 audio_route_reset_and_update_path(adev->audio_route, "gsm-mode");
1125 }
1126
1127 if (enable) {
1128 my_data->gsm_mode_enabled = true;
1129 ALOGD("%s: enabling gsm mode", __func__);
1130 audio_route_apply_and_update_path(adev->audio_route, "gsm-mode");
1131 }
1132}
1133
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301134void close_csd_client(struct csd_data *csd)
1135{
1136 if (csd != NULL) {
1137 csd->deinit();
1138 dlclose(csd->csd_client);
1139 free(csd);
1140 csd = NULL;
1141 }
1142}
1143
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301144
1145static void set_platform_defaults()
1146{
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301147 int32_t dev, count = 0;
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301148 const char *MEDIA_MIMETYPE_AUDIO_ALAC = "audio/alac";
1149 const char *MEDIA_MIMETYPE_AUDIO_APE = "audio/x-ape";
1150
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301151 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301152 backend_tag_table[dev] = NULL;
1153 hw_interface_table[dev] = NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301154 }
1155 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301156 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301157 }
1158
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301159 // To overwrite these go to the audio_platform_info.xml file.
1160 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
1161 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
1162 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
1163 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
1164 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1165 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1166 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1167 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1168 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1169 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
1170 backend_tag_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("afe-proxy");
1171 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headphones");
1172 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301173 strdup("speaker-and-usb-headphones");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301174 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1175 backend_tag_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("capture-fm");
1176 backend_tag_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("transmission-fm");
1177 backend_tag_table[SND_DEVICE_OUT_HEADPHONES_44_1] = strdup("headphones-44.1");
1178 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = strdup("vbat-voice-speaker");
1179
1180 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1181 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1182 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301183
1184 /*remove ALAC & APE from DSP decoder list based on software decoder availability*/
Alexy Josephb1379942016-01-29 15:49:38 -08001185 for (count = 0; count < (int32_t) (sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]));
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301186 count++) {
1187
1188 if (!strncmp(MEDIA_MIMETYPE_AUDIO_ALAC, dsp_only_decoders_mime[count],
1189 strlen(dsp_only_decoders_mime[count]))) {
1190
1191 if(property_get_bool("use.qti.sw.alac.decoder", false)) {
1192 ALOGD("Alac software decoder is available...removing alac from DSP decoder list");
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05301193 strlcpy(dsp_only_decoders_mime[count],"none",5);
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301194 }
1195 } else if (!strncmp(MEDIA_MIMETYPE_AUDIO_APE, dsp_only_decoders_mime[count],
1196 strlen(dsp_only_decoders_mime[count]))) {
1197
1198 if(property_get_bool("use.qti.sw.ape.decoder", false)) {
1199 ALOGD("APE software decoder is available...removing ape from DSP decoder list");
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05301200 strlcpy(dsp_only_decoders_mime[count],"none",5);
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301201 }
1202 }
1203 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301204}
1205
Avinash Vaish71c066d2014-08-27 12:32:35 +05301206void get_cvd_version(char *cvd_version, struct audio_device *adev)
1207{
1208 struct mixer_ctl *ctl;
1209 int count;
1210 int ret = 0;
1211
1212 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1213 if (!ctl) {
1214 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1215 goto done;
1216 }
1217 mixer_ctl_update(ctl);
1218
1219 count = mixer_ctl_get_num_values(ctl);
1220 if (count > MAX_CVD_VERSION_STRING_SIZE)
1221 count = MAX_CVD_VERSION_STRING_SIZE;
1222
1223 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1224 if (ret != 0) {
1225 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1226 goto done;
1227 }
1228
1229done:
1230 return;
1231}
1232
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301233static int hw_util_open(int card_no)
1234{
1235 int fd = -1;
1236 char dev_name[256];
1237
1238 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
1239 card_no, WCD9XXX_CODEC_HWDEP_NODE);
1240 ALOGD("%s Opening device %s\n", __func__, dev_name);
1241 fd = open(dev_name, O_WRONLY);
1242 if (fd < 0) {
1243 ALOGE("%s: cannot open device '%s'\n", __func__, dev_name);
1244 return fd;
1245 }
1246 ALOGD("%s success", __func__);
1247 return fd;
1248}
1249
1250struct param_data {
1251 int use_case;
1252 int acdb_id;
1253 int get_size;
1254 int buff_size;
1255 int data_size;
1256 void *buff;
1257};
1258
Banajit Goswami20cdd212015-09-11 01:11:30 -07001259static int send_vbat_adc_data_to_acdb(struct platform_data *plat_data, char *cal_type)
1260{
1261 int ret = 0;
1262 struct mixer_ctl *ctl;
1263 uint16_t vbat_adc_data[2];
1264 struct platform_data *my_data = plat_data;
1265 struct audio_device *adev = my_data->adev;
1266
1267 const char *mixer_ctl_name = "Vbat ADC data";
1268
1269 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1270 if (!ctl) {
1271 ALOGE("%s: Could not get ctl for mixer ctl name - %s",
1272 __func__, mixer_ctl_name);
1273 ret = -EINVAL;
1274 goto done;
1275 }
1276
1277 vbat_adc_data[0] = mixer_ctl_get_value(ctl, 0);
1278 vbat_adc_data[1] = mixer_ctl_get_value(ctl, 1);
1279
1280 ALOGD("%s: Vbat ADC output values: Dcp1: %d , Dcp2: %d",
1281 __func__, vbat_adc_data[0], vbat_adc_data[1]);
1282
1283 ret = my_data->acdb_set_codec_data(&vbat_adc_data[0], cal_type);
1284
1285done:
1286 return ret;
1287}
1288
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301289static void send_codec_cal(acdb_loader_get_calibration_t acdb_loader_get_calibration,
Banajit Goswami20cdd212015-09-11 01:11:30 -07001290 struct platform_data *plat_data, int fd)
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301291{
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301292 int type;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301293
1294 for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) {
1295 struct wcdcal_ioctl_buffer codec_buffer;
1296 struct param_data calib;
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301297 int ret;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301298
Bharath Ramachandramurthy63a47ef2015-08-31 17:41:46 -07001299 /* MAD calibration is handled by sound trigger HAL, skip here */
1300 if (type == WCD9XXX_MAD_CAL)
1301 continue;
1302
Banajit Goswami20cdd212015-09-11 01:11:30 -07001303 if((plat_data->is_vbat_speaker) && (WCD9XXX_VBAT_CAL == type)) {
1304 ret = send_vbat_adc_data_to_acdb(plat_data, cal_name_info[type]);
1305 if (ret < 0)
1306 ALOGE("%s error in sending vbat adc data to acdb", __func__);
1307 }
1308
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301309 calib.get_size = 1;
1310 ret = acdb_loader_get_calibration(cal_name_info[type], sizeof(struct param_data),
1311 &calib);
1312 if (ret < 0) {
1313 ALOGE("%s get_calibration failed\n", __func__);
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301314 continue;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301315 }
1316 calib.get_size = 0;
1317 calib.buff = malloc(calib.buff_size);
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301318 if(calib.buff == NULL) {
1319 ALOGE("%s mem allocation for %d bytes for %s failed\n"
1320 , __func__, calib.buff_size, cal_name_info[type]);
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301321 continue;
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301322 }
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301323 ret = acdb_loader_get_calibration(cal_name_info[type],
1324 sizeof(struct param_data), &calib);
1325 if (ret < 0) {
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301326 ALOGE("%s get_calibration failed type=%s calib.size=%d\n"
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05301327 , __func__, cal_name_info[type], calib.buff_size);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301328 free(calib.buff);
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301329 continue;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301330 }
1331 codec_buffer.buffer = calib.buff;
1332 codec_buffer.size = calib.data_size;
1333 codec_buffer.cal_type = type;
1334 if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0)
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301335 ALOGE("Failed to call ioctl for %s err=%d calib.size=%d",
1336 cal_name_info[type], errno, codec_buffer.size);
1337 ALOGD("%s cal sent for %s calib.size=%d"
1338 , __func__, cal_name_info[type], codec_buffer.size);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301339 free(calib.buff);
1340 }
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301341}
1342
1343static void audio_hwdep_send_cal(struct platform_data *plat_data)
1344{
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301345 int fd = plat_data->hw_dep_fd;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301346
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301347 if (fd < 0)
1348 fd = hw_util_open(plat_data->adev->snd_card);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301349 if (fd == -1) {
1350 ALOGE("%s error open\n", __func__);
1351 return;
1352 }
1353
1354 acdb_loader_get_calibration = (acdb_loader_get_calibration_t)
1355 dlsym(plat_data->acdb_handle, "acdb_loader_get_calibration");
1356
1357 if (acdb_loader_get_calibration == NULL) {
1358 ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__,
1359 dlerror());
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301360 if (fd >= 0) {
1361 close(fd);
1362 plat_data->hw_dep_fd = -1;
1363 }
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301364 return;
1365 }
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301366
1367 send_codec_cal(acdb_loader_get_calibration, plat_data, fd);
1368 plat_data->hw_dep_fd = fd;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301369}
1370
Naresh Tanniru516c2452015-08-14 12:58:24 +05301371const char * get_snd_card_name_for_acdb_loader(const char *snd_card_name) {
1372
1373 if(snd_card_name == NULL)
1374 return NULL;
1375
1376 // Both tasha & tasha-lite uses tasha ACDB files
1377 // simulate sound card name for tasha lite, so that
1378 // ACDB module loads tasha ACDB files for tasha lite
1379 if(!strncmp(snd_card_name, "msm8976-tashalite-snd-card",
1380 sizeof("msm8976-tashalite-snd-card"))) {
Naresh Tanniru4d1e1a12015-12-16 19:37:50 +05301381 ALOGD("using tasha ACDB files for tasha-lite");
1382 return "msm8976-tasha-snd-card";
1383 }
1384
1385 if(!strncmp(snd_card_name, "msm8952-tashalite-snd-card",
1386 sizeof("msm8952-tashalite-snd-card"))) {
1387 ALOGD("using tasha ACDB files for tasha-lite");
1388 return "msm8952-tasha-snd-card";
1389 }
1390
1391 if(!strncmp(snd_card_name, "msm8937-tashalite-snd-card",
1392 sizeof("msm8937-tashalite-snd-card"))) {
1393 ALOGD("using tasha ACDB files for tasha-lite");
1394 return "msm8937-tasha-snd-card";
1395 }
1396
1397 if(!strncmp(snd_card_name, "msm8953-tashalite-snd-card",
1398 sizeof("msm8953-tashalite-snd-card"))) {
1399 ALOGD("using tasha ACDB files for tasha-lite");
1400 return "msm8953-tasha-snd-card";
1401 }
1402
1403 return snd_card_name;
Naresh Tanniru516c2452015-08-14 12:58:24 +05301404}
1405
1406
1407int platform_acdb_init(void *platform)
Ramjee Singh203473b2015-06-09 15:18:42 +05301408{
1409 struct platform_data *my_data = (struct platform_data *)platform;
1410 char *cvd_version = NULL;
1411 int key = 0;
Naresh Tanniru516c2452015-08-14 12:58:24 +05301412 const char *snd_card_name, *acdb_snd_card_name;
Ramjee Singh203473b2015-06-09 15:18:42 +05301413 int result;
1414 char value[PROPERTY_VALUE_MAX];
1415 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1416 if (!cvd_version)
1417 ALOGE("Failed to allocate cvd version");
1418 else
1419 get_cvd_version(cvd_version, my_data->adev);
1420
1421 property_get("audio.ds1.metainfo.key",value,"0");
1422 key = atoi(value);
1423 snd_card_name = mixer_get_name(my_data->adev->mixer);
Naresh Tanniru516c2452015-08-14 12:58:24 +05301424 acdb_snd_card_name = get_snd_card_name_for_acdb_loader(snd_card_name);
1425
1426 result = my_data->acdb_init(acdb_snd_card_name, cvd_version, key);
1427
Karthik Reddy Katta8513f432016-04-12 14:29:27 +05301428 /* Save these variables in platform_data. These will be used
1429 while reloading ACDB files during run time. */
1430 strlcpy(my_data->cvd_version, cvd_version, MAX_CVD_VERSION_STRING_SIZE);
1431 strlcpy(my_data->snd_card_name, acdb_snd_card_name,
1432 MAX_SND_CARD_STRING_SIZE);
1433 my_data->metainfo_key = key;
1434
Ramjee Singh203473b2015-06-09 15:18:42 +05301435 if (cvd_version)
1436 free(cvd_version);
1437 if (!result) {
1438 my_data->is_acdb_initialized = true;
1439 ALOGD("ACDB initialized");
1440 audio_hwdep_send_cal(my_data);
1441 } else {
1442 my_data->is_acdb_initialized = false;
1443 ALOGD("ACDB initialization failed");
1444 }
1445 return result;
1446}
1447
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301448#define MAX_PATH (256)
1449#define THERMAL_SYSFS "/sys/class/thermal"
1450#define TZ_TYPE "/sys/class/thermal/thermal_zone%d/type"
1451#define TZ_WSA "/sys/class/thermal/thermal_zone%d/temp"
1452
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05301453static bool check_and_get_wsa_info(char *snd_card_name, int *wsaCount,
1454 bool *is_wsa_combo_supported)
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301455{
1456 DIR *tdir = NULL;
1457 struct dirent *tdirent = NULL;
1458 int tzn = 0;
1459 char name[MAX_PATH] = {0};
1460 char cwd[MAX_PATH] = {0};
1461 char file[10] = "wsa";
1462 bool found = false;
1463 int wsa_count = 0;
1464
1465 if (!getcwd(cwd, sizeof(cwd)))
1466 return false;
1467
1468 chdir(THERMAL_SYSFS); /* Change dir to read the entries. Doesnt work
1469 otherwise */
1470 tdir = opendir(THERMAL_SYSFS);
1471 if (!tdir) {
1472 ALOGE("Unable to open %s\n", THERMAL_SYSFS);
1473 return false;
1474 }
1475
1476 while ((tdirent = readdir(tdir))) {
1477 char buf[50];
1478 struct dirent *tzdirent;
1479 DIR *tzdir = NULL;
1480
1481 tzdir = opendir(tdirent->d_name);
1482 if (!tzdir)
1483 continue;
1484 while ((tzdirent = readdir(tzdir))) {
1485 if (strcmp(tzdirent->d_name, "type"))
1486 continue;
1487 snprintf(name, MAX_PATH, TZ_TYPE, tzn);
1488 ALOGD("Opening %s\n", name);
1489 read_line_from_file(name, buf, sizeof(buf));
1490 if (strstr(buf, file)) {
1491 wsa_count++;
1492 /*We support max only two WSA speakers*/
1493 if (wsa_count == 2)
1494 break;
1495 }
1496 tzn++;
1497 }
1498 closedir(tzdir);
1499 }
1500 if (wsa_count > 0){
1501 ALOGD("Found %d WSA present on the platform", wsa_count);
1502 found = true;
1503 *wsaCount = wsa_count;
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05301504
1505 /* update wsa combo supported flag based on sound card name */
1506 /* wsa combo flag needs to be set to true only for hardware
1507 combinations which has support for both wsa and non-wsa speaker */
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05301508 *is_wsa_combo_supported = false;
1509 if(snd_card_name) {
1510 if ((!strncmp(snd_card_name, "msm8953-snd-card-mtp",
1511 sizeof("msm8953-snd-card-mtp")) ||
1512 (!strncmp(snd_card_name, "msm8952-skum-snd-card",
1513 sizeof("msm8952-skum-snd-card"))))) {
1514 *is_wsa_combo_supported = true;
1515 }
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05301516 }
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301517 }
1518 closedir(tdir);
1519 chdir(cwd); /* Restore current working dir */
1520 return found;
1521}
1522
Naresh Tannirue3b18452014-03-04 14:44:27 +05301523void *platform_init(struct audio_device *adev)
1524{
1525 char value[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301526 struct platform_data *my_data = NULL;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05301527 int retry_num = 0, snd_card_num = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301528 const char *snd_card_name;
Yeleswarapu Nagaradhesh09f30be2015-07-22 14:11:03 +05301529 char mixer_xml_path[MAX_MIXER_XML_PATH],ffspEnable[PROPERTY_VALUE_MAX];
Satish Babu Patakokilabbd4e9d2015-05-13 22:08:06 +05301530 const char *mixer_ctl_name = "Set HPX ActiveBe";
1531 struct mixer_ctl *ctl = NULL;
Naveen Kumar70e27352015-07-22 21:07:10 +05301532 int idx;
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301533 int wsaCount =0;
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05301534 bool is_wsa_combo_supported = false;
Naveen Kumar70e27352015-07-22 21:07:10 +05301535
1536 my_data = calloc(1, sizeof(struct platform_data));
1537
Chaithanya Krishna Bacharajudb6236a2015-01-30 10:08:33 +05301538 if (!my_data) {
1539 ALOGE("failed to allocate platform data");
1540 return NULL;
1541 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301542
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301543 while (snd_card_num < MAX_SND_CARD) {
1544 adev->mixer = mixer_open(snd_card_num);
1545
1546 while (!adev->mixer && retry_num < RETRY_NUMBER) {
1547 usleep(RETRY_US);
1548 adev->mixer = mixer_open(snd_card_num);
1549 retry_num++;
1550 }
1551
1552 if (!adev->mixer) {
1553 ALOGE("%s: Unable to open the mixer card: %d", __func__,
1554 snd_card_num);
1555 retry_num = 0;
1556 snd_card_num++;
1557 continue;
1558 }
1559
1560 snd_card_name = mixer_get_name(adev->mixer);
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05301561 ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301562
1563 my_data->hw_info = hw_info_init(snd_card_name);
1564 if (!my_data->hw_info) {
1565 ALOGE("%s: Failed to init hardware info", __func__);
1566 } else {
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301567 query_platform(snd_card_name, mixer_xml_path);
1568 ALOGD("%s: mixer path file is %s", __func__,
1569 mixer_xml_path);
1570 if (audio_extn_read_xml(adev, snd_card_num, mixer_xml_path,
1571 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301572 adev->audio_route = audio_route_init(snd_card_num,
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301573 mixer_xml_path);
1574 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301575 if (!adev->audio_route) {
1576 ALOGE("%s: Failed to init audio route controls, aborting.",
1577 __func__);
1578 free(my_data);
Mingming Yindda29e62015-12-02 18:02:28 -08001579 mixer_close(adev->mixer);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301580 return NULL;
1581 }
1582 adev->snd_card = snd_card_num;
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +05301583 update_codec_type(snd_card_name);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301584 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1585 break;
1586 }
1587 retry_num = 0;
1588 snd_card_num++;
Mingming Yindda29e62015-12-02 18:02:28 -08001589 mixer_close(adev->mixer);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301590 }
1591
1592 if (snd_card_num >= MAX_SND_CARD) {
1593 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1594 free(my_data);
1595 return NULL;
1596 }
1597
Naresh Tannirue3b18452014-03-04 14:44:27 +05301598 my_data->adev = adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301599 my_data->fluence_in_spkr_mode = false;
1600 my_data->fluence_in_voice_call = false;
1601 my_data->fluence_in_voice_rec = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301602 my_data->fluence_in_audio_rec = false;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301603 my_data->external_spk_1 = false;
1604 my_data->external_spk_2 = false;
1605 my_data->external_mic = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301606 my_data->fluence_type = FLUENCE_NONE;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301607 my_data->fluence_mode = FLUENCE_ENDFIRE;
Avinash Vaishd5fa4572014-09-15 14:41:14 +05301608 my_data->slowtalk = false;
1609 my_data->hd_voice = false;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301610 my_data->edid_info = NULL;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05301611 my_data->is_wsa_speaker = false;
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301612 my_data->hw_dep_fd = -1;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301613
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301614 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
1615 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301616 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301617 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301618 my_data->fluence_type = FLUENCE_DUAL_MIC;
1619 } else {
1620 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301621 }
1622
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301623 if (my_data->fluence_type != FLUENCE_NONE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301624 property_get("persist.audio.fluence.voicecall",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301625 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301626 my_data->fluence_in_voice_call = true;
1627 }
1628
1629 property_get("persist.audio.fluence.voicerec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301630 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301631 my_data->fluence_in_voice_rec = true;
1632 }
1633
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301634 property_get("persist.audio.fluence.audiorec",value,"");
1635 if (!strncmp("true", value, sizeof("true"))) {
1636 my_data->fluence_in_audio_rec = true;
1637 }
1638
Naresh Tannirue3b18452014-03-04 14:44:27 +05301639 property_get("persist.audio.fluence.speaker",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301640 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301641 my_data->fluence_in_spkr_mode = true;
1642 }
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301643
1644 property_get("persist.audio.fluence.mode",value,"");
1645 if (!strncmp("broadside", value, sizeof("broadside"))) {
1646 my_data->fluence_mode = FLUENCE_BROADSIDE;
1647 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301648 }
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301649
Alexy Josephb1379942016-01-29 15:49:38 -08001650 if (check_and_get_wsa_info((char *)snd_card_name, &wsaCount, &is_wsa_combo_supported)) {
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301651 /*Set ACDB ID of Stereo speaker if two WSAs are present*/
1652 /*Default ACDB ID for wsa speaker is that for mono*/
1653 if (wsaCount == 2) {
1654 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_WSA, 15);
1655 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_VBAT, 15);
1656 }
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05301657
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301658 my_data->is_wsa_speaker = true;
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05301659
1660 if (is_wsa_combo_supported)
1661 hw_info_enable_wsa_combo_usecase_support(my_data->hw_info);
1662
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301663 }
1664
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +05301665 property_get("persist.audio.FFSP.enable", ffspEnable, "");
1666 if (!strncmp("true", ffspEnable, sizeof("true"))) {
1667 acdb_device_table[SND_DEVICE_OUT_SPEAKER] = 131;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05301668 acdb_device_table[SND_DEVICE_OUT_SPEAKER_WSA] = 131;
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +05301669 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = 131;
1670 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 131;
1671 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 131;
1672 }
Dhananjay Kumara3565b32014-07-23 01:12:48 +05301673
Banajit Goswami20cdd212015-09-11 01:11:30 -07001674 /* Check if Vbat speaker enabled property is set, this should be done before acdb init */
1675 bool ret = false;
1676 ret = audio_extn_can_use_vbat();
1677 if (ret)
1678 my_data->is_vbat_speaker = true;
1679
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05301680 /*
1681 * Check if hifi audio( i.e. 96, 192 KHZ) is enabled for this platform,
1682 * enable hifi audio by default for external codec targets
1683 */
1684 ret = audio_extn_is_hifi_audio_supported();
1685 if (ret || is_external_codec)
1686 my_data->hifi_audio = true;
1687
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301688 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301689 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1690 if (my_data->acdb_handle == NULL) {
1691 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1692 } else {
1693 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1694 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1695 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301696 if (!my_data->acdb_deallocate)
1697 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1698 __func__, LIB_ACDB_LOADER);
1699
Naresh Tannirue3b18452014-03-04 14:44:27 +05301700 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 -07001701 "acdb_loader_send_audio_cal_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301702 if (!my_data->acdb_send_audio_cal)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301703 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +05301704 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301705
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301706 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1707 "acdb_loader_set_audio_cal_v2");
1708 if (!my_data->acdb_set_audio_cal)
1709 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1710 __func__, LIB_ACDB_LOADER);
1711
1712 my_data->acdb_get_audio_cal = (acdb_get_audio_cal_t)dlsym(my_data->acdb_handle,
1713 "acdb_loader_get_audio_cal_v2");
1714 if (!my_data->acdb_get_audio_cal)
1715 ALOGE("%s: Could not find the symbol acdb_get_audio_cal_v2 from %s",
1716 __func__, LIB_ACDB_LOADER);
1717
Naresh Tannirue3b18452014-03-04 14:44:27 +05301718 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1719 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301720 if (!my_data->acdb_send_voice_cal)
1721 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1722 __func__, LIB_ACDB_LOADER);
1723
1724 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1725 "acdb_loader_reload_vocvoltable");
1726 if (!my_data->acdb_reload_vocvoltable)
1727 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1728 __func__, LIB_ACDB_LOADER);
1729
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001730 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
1731 my_data->acdb_handle,
1732 "acdb_loader_get_default_app_type");
1733 if (!my_data->acdb_get_default_app_type)
1734 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1735 __func__, LIB_ACDB_LOADER);
1736
Ben Rombergerfeca4b82015-07-07 20:40:44 -07001737 my_data->acdb_send_common_top = (acdb_send_common_top_t)dlsym(
1738 my_data->acdb_handle,
1739 "acdb_loader_send_common_custom_topology");
1740 if (!my_data->acdb_send_common_top)
1741 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1742 __func__, LIB_ACDB_LOADER);
1743
Banajit Goswami20cdd212015-09-11 01:11:30 -07001744 my_data->acdb_set_codec_data = (acdb_set_codec_data_t)dlsym(
1745 my_data->acdb_handle,
1746 "acdb_loader_set_codec_data");
1747 if (!my_data->acdb_set_codec_data)
1748 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1749 __func__, LIB_ACDB_LOADER);
1750
1751
Naresh Tannirue3b18452014-03-04 14:44:27 +05301752 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301753 "acdb_loader_init_v2");
Avinash Vaish71c066d2014-08-27 12:32:35 +05301754 if (my_data->acdb_init == NULL) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301755 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Avinash Vaish71c066d2014-08-27 12:32:35 +05301756 goto acdb_init_fail;
1757 }
Karthik Reddy Katta8513f432016-04-12 14:29:27 +05301758
1759 my_data->acdb_reload = (acdb_reload_t)dlsym(my_data->acdb_handle,
1760 "acdb_loader_reload_acdb_files");
1761 if (my_data->acdb_reload == NULL) {
1762 ALOGE("%s: dlsym error %s for acdb_loader_reload_acdb_files", __func__, dlerror());
1763 goto acdb_init_fail;
1764 }
Ramjee Singh203473b2015-06-09 15:18:42 +05301765 platform_acdb_init(my_data);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301766 }
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301767 audio_extn_pm_vote();
Naresh Tannirue3b18452014-03-04 14:44:27 +05301768
Satish Babu Patakokilabbd4e9d2015-05-13 22:08:06 +05301769 /* Configure active back end for HPX*/
1770 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1771 if (ctl) {
1772 ALOGE(" sending HPX Active BE information ");
1773 mixer_ctl_set_value(ctl, 0, is_external_codec);
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05301774 }
1775
Avinash Vaish71c066d2014-08-27 12:32:35 +05301776acdb_init_fail:
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301777
1778 set_platform_defaults();
1779
Dhananjay Kumara68d7af2015-05-25 19:11:30 +05301780 /* Initialize ACDB and PCM ID's */
1781 if (is_external_codec)
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001782 platform_info_init(PLATFORM_INFO_XML_PATH_EXTCODEC, my_data);
Dhananjay Kumara68d7af2015-05-25 19:11:30 +05301783 else
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001784 platform_info_init(PLATFORM_INFO_XML_PATH, my_data);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301785
1786 /* init usb */
1787 audio_extn_usb_init(adev);
1788 /* update sound cards appropriately */
1789 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
1790
1791 /* Read one time ssr property */
1792 audio_extn_ssr_update_enabled();
1793 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301794
Ashish Jain8ec50472014-10-16 13:56:28 +05301795 /* init dap hal */
1796 audio_extn_dap_hal_init(adev->snd_card);
1797
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301798 audio_extn_dolby_set_license(adev);
1799
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301800 /* init audio device arbitration */
1801 audio_extn_dev_arbi_init();
1802
1803 my_data->edid_info = NULL;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301804
1805 /* initialize backend config */
1806 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
1807 my_data->current_backend_cfg[idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1808 if (idx == HEADPHONE_44_1_BACKEND)
1809 my_data->current_backend_cfg[idx].sample_rate = OUTPUT_SAMPLING_RATE_44100;
1810 my_data->current_backend_cfg[idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1811 }
1812
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05301813 my_data->current_tx_backend_cfg[DEFAULT_CODEC_BACKEND].sample_rate =
1814 CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1815 my_data->current_tx_backend_cfg[DEFAULT_CODEC_BACKEND].bit_width =
1816 CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1817
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05301818 if (is_external_codec) {
1819 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1820 strdup("SLIM_0_RX Format");
1821 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1822 strdup("SLIM_0_RX SampleRate");
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301823
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05301824 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].bitwidth_mixer_ctl =
1825 strdup("SLIM_5_RX Format");
1826 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].samplerate_mixer_ctl =
1827 strdup("SLIM_5_RX SampleRate");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301828
1829 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1830 strdup("SLIM_6_RX Format");
1831 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1832 strdup("SLIM_6_RX SampleRate");
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05301833
1834 my_data->current_tx_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1835 strdup("SLIM_0_TX Format");
1836 my_data->current_tx_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1837 strdup("SLIM_0_TX SampleRate");
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05301838 } else {
1839 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1840 strdup("MI2S_RX Format");
1841 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1842 strdup("MI2S_RX SampleRate");
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05301843
1844 my_data->current_tx_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1845 strdup("MI2S_TX Format");
1846 my_data->current_tx_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1847 strdup("MI2S_TX SampleRate");
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05301848 }
Sidipotu Ashokcf877732015-09-22 14:58:48 +05301849
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05301850 ret = audio_extn_utils_get_codec_version(snd_card_name,
1851 my_data->adev->snd_card,
1852 my_data->codec_version);
Sidipotu Ashokcf877732015-09-22 14:58:48 +05301853
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05301854 if (NATIVE_AUDIO_MODE_INVALID != platform_get_native_support()) {
1855 /*
1856 * Native playback is enabled from the UI.
1857 */
1858 if(strstr(snd_card_name, "tasha")) {
1859 if (strstr(my_data->codec_version, "WCD9335_1_0") ||
1860 strstr(my_data->codec_version, "WCD9335_1_1")) {
1861 ALOGD("%s:napb: TASHA 1.0 or 1.1 only SRC mode is supported",
1862 __func__);
1863 platform_set_native_support(NATIVE_AUDIO_MODE_SRC);
1864 }
1865 } else {
1866 platform_set_native_support(NATIVE_AUDIO_MODE_INVALID);
Sidipotu Ashokcf877732015-09-22 14:58:48 +05301867 }
1868 }
1869
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301870 my_data->edid_info = NULL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301871 return my_data;
1872}
1873
1874void platform_deinit(void *platform)
1875{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301876 struct platform_data *my_data = (struct platform_data *)platform;
1877
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301878 if (my_data->edid_info) {
1879 free(my_data->edid_info);
1880 my_data->edid_info = NULL;
1881 }
1882
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301883 if (my_data->hw_dep_fd >= 0) {
1884 close(my_data->hw_dep_fd);
1885 my_data->hw_dep_fd = -1;
1886 }
1887
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301888 hw_info_deinit(my_data->hw_info);
1889 close_csd_client(my_data->csd);
1890
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301891 int32_t dev;
1892 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301893 if (backend_tag_table[dev]) {
1894 free(backend_tag_table[dev]);
1895 backend_tag_table[dev]= NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301896 }
1897 }
1898
1899 /* deinit audio device arbitration */
1900 audio_extn_dev_arbi_deinit();
1901
1902 if (my_data->edid_info) {
1903 free(my_data->edid_info);
1904 my_data->edid_info = NULL;
1905 }
1906
Naresh Tannirue3b18452014-03-04 14:44:27 +05301907 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301908 /* deinit usb */
1909 audio_extn_usb_deinit();
Ashish Jain8ec50472014-10-16 13:56:28 +05301910 audio_extn_dap_hal_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +05301911}
1912
Ben Rombergerfeca4b82015-07-07 20:40:44 -07001913static int platform_is_acdb_initialized(void *platform)
Ramjee Singh203473b2015-06-09 15:18:42 +05301914{
1915 struct platform_data *my_data = (struct platform_data *)platform;
1916 ALOGD("%s: acdb initialized %d\n", __func__, my_data->is_acdb_initialized);
1917 return my_data->is_acdb_initialized;
1918}
1919
Ben Rombergerfeca4b82015-07-07 20:40:44 -07001920void platform_snd_card_update(void *platform, int snd_scard_state)
1921{
1922 struct platform_data *my_data = (struct platform_data *)platform;
1923
1924 if (snd_scard_state == SND_CARD_STATE_ONLINE) {
1925 if (!platform_is_acdb_initialized(my_data)) {
1926 if(platform_acdb_init(my_data))
1927 ALOGE("%s: acdb initialization is failed", __func__);
1928 } else if (my_data->acdb_send_common_top() < 0) {
1929 ALOGD("%s: acdb did not set common topology", __func__);
1930 }
1931 }
1932}
1933
Naresh Tannirue3b18452014-03-04 14:44:27 +05301934const char *platform_get_snd_device_name(snd_device_t snd_device)
1935{
1936 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
1937 return device_table[snd_device];
1938 else
1939 return "";
1940}
1941
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301942int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1943 char *device_name)
1944{
1945 struct platform_data *my_data = (struct platform_data *)platform;
1946
1947 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1948 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1949 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1950 } else {
1951 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
1952 return -EINVAL;
1953 }
1954
1955 return 0;
1956}
1957
Banajit Goswami20cdd212015-09-11 01:11:30 -07001958void platform_add_backend_name(char *mixer_path, snd_device_t snd_device,
1959 struct audio_usecase *usecase)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301960{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301961 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1962 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1963 return;
1964 }
1965
Banajit Goswami20cdd212015-09-11 01:11:30 -07001966 if((snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT) &&
1967 !(usecase->type == VOICE_CALL || usecase->type == VOIP_CALL)) {
1968 ALOGI("%s: Not adding vbat speaker device to non voice use cases", __func__);
1969 return;
1970 }
1971
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301972 const char * suffix = backend_tag_table[snd_device];
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301973
1974 if (suffix != NULL) {
1975 strlcat(mixer_path, " ", MIXER_PATH_MAX_LENGTH);
1976 strlcat(mixer_path, suffix, MIXER_PATH_MAX_LENGTH);
1977 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301978}
1979
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301980bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1981{
1982 bool result = true;
1983
1984 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1985 platform_get_snd_device_name(snd_device1),
1986 platform_get_snd_device_name(snd_device2));
1987
1988 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_OUT_END)) {
1989 ALOGE("%s: Invalid snd_device = %s", __func__,
1990 platform_get_snd_device_name(snd_device1));
1991 return false;
1992 }
1993 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_OUT_END)) {
1994 ALOGE("%s: Invalid snd_device = %s", __func__,
1995 platform_get_snd_device_name(snd_device2));
1996 return false;
1997 }
1998 const char * be_itf1 = hw_interface_table[snd_device1];
1999 const char * be_itf2 = hw_interface_table[snd_device2];
2000
2001 if (NULL != be_itf1 && NULL != be_itf2) {
2002 if (0 != strcmp(be_itf1, be_itf2))
2003 result = false;
2004 } else if (NULL == be_itf1 && NULL != be_itf2) {
2005 result = false;
2006 } else if (NULL != be_itf1 && NULL == be_itf2) {
2007 result = false;
2008 }
2009
2010 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
2011 return result;
2012}
2013
Naresh Tannirue3b18452014-03-04 14:44:27 +05302014int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
2015{
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +05302016 int device_id = -1;
2017
2018 if (is_external_codec && is_misc_usecase(usecase)) {
2019 if (device_type == PCM_PLAYBACK)
2020 device_id = pcm_device_table_of_ext_codec[usecase][0];
2021 else
2022 device_id = pcm_device_table_of_ext_codec[usecase][1];
2023 } else {
2024 if (device_type == PCM_PLAYBACK)
2025 device_id = pcm_device_table[usecase][0];
2026 else
2027 device_id = pcm_device_table[usecase][1];
2028 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302029 return device_id;
2030}
2031
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302032static int find_index(struct name_to_index * table, int32_t len, const char * name)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302033{
2034 int ret = 0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302035 int32_t i;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302036
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302037 if (table == NULL) {
2038 ALOGE("%s: table is NULL", __func__);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302039 ret = -ENODEV;
2040 goto done;
2041 }
2042
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302043 if (name == NULL) {
2044 ALOGE("null key");
2045 ret = -ENODEV;
2046 goto done;
2047 }
2048
2049 for (i=0; i < len; i++) {
2050 const char* tn = table[i].name;
2051 size_t len = strlen(tn);
2052 if (strncmp(tn, name, len) == 0) {
2053 if (strlen(name) != len) {
2054 continue; // substring
2055 }
2056 ret = table[i].index;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302057 goto done;
2058 }
2059 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302060 ALOGE("%s: Could not find index for name = %s",
2061 __func__, name);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302062 ret = -ENODEV;
2063done:
2064 return ret;
2065}
2066
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05302067int platform_set_fluence_type(void *platform, char *value)
2068{
2069 int ret = 0;
2070 int fluence_type = FLUENCE_NONE;
2071 int fluence_flag = NONE_FLAG;
2072 struct platform_data *my_data = (struct platform_data *)platform;
2073 struct audio_device *adev = my_data->adev;
2074
2075 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
2076
2077 /* only dual mic turn on and off is supported as of now through setparameters */
2078 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
2079 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
2080 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
2081 ALOGV("fluence dualmic feature enabled \n");
2082 fluence_type = FLUENCE_DUAL_MIC;
2083 fluence_flag = DMIC_FLAG;
2084 } else {
2085 ALOGE("%s: Failed to set DUALMIC", __func__);
2086 ret = -1;
2087 goto done;
2088 }
2089 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
2090 ALOGV("fluence disabled");
2091 fluence_type = FLUENCE_NONE;
2092 } else {
2093 ALOGE("Invalid fluence value : %s",value);
2094 ret = -1;
2095 goto done;
2096 }
2097
2098 if (fluence_type != my_data->fluence_type) {
2099 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
2100 my_data->fluence_type = fluence_type;
2101 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
2102 }
2103done:
2104 return ret;
2105}
2106
2107int platform_get_fluence_type(void *platform, char *value, uint32_t len)
2108{
2109 int ret = 0;
2110 struct platform_data *my_data = (struct platform_data *)platform;
2111
2112 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
2113 strlcpy(value, "quadmic", len);
2114 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
2115 strlcpy(value, "dualmic", len);
2116 } else if (my_data->fluence_type == FLUENCE_NONE) {
2117 strlcpy(value, "none", len);
2118 } else
2119 ret = -1;
2120
2121 return ret;
2122}
2123
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302124int platform_get_snd_device_index(char *device_name)
2125{
2126 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2127}
2128
2129int platform_get_usecase_index(const char *usecase_name)
2130{
2131 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2132}
2133
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302134int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2135{
2136 int ret = 0;
2137
2138 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2139 ALOGE("%s: Invalid snd_device = %d",
2140 __func__, snd_device);
2141 ret = -EINVAL;
2142 goto done;
2143 }
2144
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302145 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2146 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302147 acdb_device_table[snd_device] = acdb_id;
2148done:
2149 return ret;
2150}
2151
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07002152int platform_get_default_app_type(void *platform)
2153{
2154 struct platform_data *my_data = (struct platform_data *)platform;
2155
2156 if (my_data->acdb_get_default_app_type)
2157 return my_data->acdb_get_default_app_type();
2158 else
2159 return DEFAULT_APP_TYPE;
2160}
2161
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05302162int platform_get_default_app_type_v2(void *platform __unused,
2163 usecase_type_t type __unused)
Srikanth Uyyalaa1e32352015-10-09 14:48:04 +05302164{
2165 if(type == PCM_CAPTURE)
2166 return DEFAULT_APP_TYPE_TX_PATH;
2167 else
2168 return DEFAULT_APP_TYPE_RX_PATH;
2169}
2170
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07002171int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2172{
2173 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2174 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2175 return -EINVAL;
2176 }
2177 return acdb_device_table[snd_device];
2178}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302179
2180int platform_set_snd_device_bit_width(snd_device_t snd_device, unsigned int bit_width)
Amit Shekhar5a39c912014-10-14 15:39:30 -07002181{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302182 int ret = 0;
2183
2184 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2185 ALOGE("%s: Invalid snd_device = %d",
2186 __func__, snd_device);
2187 ret = -EINVAL;
2188 goto done;
2189 }
2190
2191 backend_bit_width_table[snd_device] = bit_width;
2192done:
2193 return ret;
Amit Shekhar5a39c912014-10-14 15:39:30 -07002194}
2195
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302196int platform_get_snd_device_bit_width(snd_device_t snd_device)
Amit Shekhar5a39c912014-10-14 15:39:30 -07002197{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302198 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2199 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
Ashish Jainb449be32015-07-19 05:39:23 -07002200 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302201 }
2202 return backend_bit_width_table[snd_device];
Amit Shekhar5a39c912014-10-14 15:39:30 -07002203}
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302204int platform_set_native_support(int na_mode)
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002205{
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302206 if (NATIVE_AUDIO_MODE_SRC == na_mode || NATIVE_AUDIO_MODE_TRUE_44_1 == na_mode) {
2207 na_props.platform_na_prop_enabled = na_props.ui_na_prop_enabled = true;
2208 na_props.na_mode = na_mode;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302209 ALOGD("%s:napb: native audio playback enabled in (%s) mode v2.0", __func__,
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302210 ((na_mode == NATIVE_AUDIO_MODE_SRC)?"SRC mode":"True 44.1 mode"));
2211 } else {
2212 na_props.platform_na_prop_enabled = false;
2213 na_props.na_mode = NATIVE_AUDIO_MODE_INVALID;
2214 ALOGD("%s:napb: native audio playback disabled", __func__);
2215 }
2216
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002217 return 0;
2218}
2219
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302220int platform_get_native_support()
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002221{
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302222 int ret = NATIVE_AUDIO_MODE_INVALID;
2223 if (na_props.platform_na_prop_enabled &&
2224 na_props.ui_na_prop_enabled) {
2225 ret = na_props.na_mode;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302226 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302227 ALOGV("%s:napb: ui Prop enabled(%d) version(%d)", __func__,
2228 na_props.ui_na_prop_enabled, na_props.na_mode);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302229 return ret;
2230}
2231
2232void native_audio_get_params(struct str_parms *query,
2233 struct str_parms *reply,
2234 char *value, int len)
2235{
2236 int ret;
2237 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
2238 value, len);
2239 if (ret >= 0) {
2240 if (na_props.platform_na_prop_enabled) {
2241 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
2242 na_props.ui_na_prop_enabled ? "true" : "false");
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302243 ALOGV("%s:napb: na_props.ui_na_prop_enabled: %d", __func__,
2244 na_props.ui_na_prop_enabled);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302245 } else {
2246 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
2247 "false");
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302248 ALOGV("%s:napb: native audio not supported: %d", __func__,
2249 na_props.platform_na_prop_enabled);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302250 }
2251 }
2252}
2253
2254int native_audio_set_params(struct platform_data *platform,
2255 struct str_parms *parms, char *value, int len)
2256{
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05302257 int ret = -1;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302258 struct audio_usecase *usecase;
2259 struct listnode *node;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302260 int mode = NATIVE_AUDIO_MODE_INVALID;
2261
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05302262 if (!value)
2263 return ret;
2264
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302265 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO_MODE,
2266 value, len);
2267 if (ret >= 0) {
2268 if (value && !strncmp(value, "src", sizeof("src")))
2269 mode = NATIVE_AUDIO_MODE_SRC;
2270 else if (value && !strncmp(value, "true", sizeof("true")))
2271 mode = NATIVE_AUDIO_MODE_TRUE_44_1;
2272 else {
2273 mode = NATIVE_AUDIO_MODE_INVALID;
2274 ALOGE("%s:napb:native_audio_mode in platform info xml,invalid mode string",
2275 __func__);
2276 }
2277 ALOGD("%s:napb updating mode (%d) from XML",__func__, mode);
2278 platform_set_native_support(mode);
2279 }
2280
2281
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302282
2283 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
2284 value, len);
2285 if (ret >= 0) {
2286 if (na_props.platform_na_prop_enabled) {
Sidipotu Ashok894644d2015-07-06 18:35:03 +05302287 if (!strncmp("true", value, sizeof("true"))) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302288 na_props.ui_na_prop_enabled = true;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302289 ALOGD("%s:napb: native audio feature enabled from UI",
2290 __func__);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05302291 }
2292 else {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302293 na_props.ui_na_prop_enabled = false;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302294 ALOGD("%s:napb: native audio feature disabled from UI",
2295 __func__);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05302296 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302297
2298 str_parms_del(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO);
2299
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302300 /*
2301 * Iterate through the usecase list and trigger device switch for
2302 * all the appropriate usecases
2303 */
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302304 list_for_each(node, &(platform->adev)->usecase_list) {
2305 usecase = node_to_item(node, struct audio_usecase, list);
2306
2307 if (is_offload_usecase(usecase->id) &&
2308 (usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2309 usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) &&
2310 OUTPUT_SAMPLING_RATE_44100 == usecase->stream.out->sample_rate) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302311 ALOGD("%s:napb: triggering dynamic device switch for usecase(%d: %s)"
Sidipotu Ashok894644d2015-07-06 18:35:03 +05302312 " stream(%p), device(%d)", __func__, usecase->id,
Alexy Josephb1379942016-01-29 15:49:38 -08002313 use_case_table[usecase->id], (void*) usecase->stream.out,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302314 usecase->stream.out->devices);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05302315 select_devices(platform->adev, usecase->id);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302316 }
2317 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302318 } else
2319 ALOGD("%s:napb: native audio cannot be enabled from UI",
2320 __func__);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302321 }
2322 return ret;
2323}
2324
Sidipotu Ashokad8fff82016-02-02 10:48:42 +05302325int check_hdset_combo_device(snd_device_t snd_device)
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302326{
2327 int ret = false;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302328
Sidipotu Ashokad8fff82016-02-02 10:48:42 +05302329 if (SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES == snd_device ||
2330 SND_DEVICE_OUT_SPEAKER_AND_LINE == snd_device ||
2331 SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1 == snd_device ||
2332 SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2 == snd_device ||
2333 SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET == snd_device)
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302334 ret = true;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302335
2336 return ret;
2337}
2338
2339
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302340static int platform_get_backend_index(snd_device_t snd_device)
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302341{
2342 int32_t port = DEFAULT_CODEC_BACKEND;
2343
2344 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302345 if (backend_tag_table[snd_device] != NULL) {
2346 if (strncmp(backend_tag_table[snd_device], "headphones-44.1",
2347 sizeof("headphones-44.1")) == 0)
2348 port = HEADPHONE_44_1_BACKEND;
2349 else if (strncmp(backend_tag_table[snd_device], "headphones",
2350 sizeof("headphones")) == 0)
2351 port = HEADPHONE_BACKEND;
2352 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2353 port = HDMI_RX_BACKEND;
2354 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302355 } else {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302356 ALOGV("%s:napb: Invalid device - %d ", __func__, snd_device);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302357 }
2358
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302359 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port,
2360 snd_device);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302361 return port;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002362}
2363
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05302364int platform_send_audio_calibration(void *platform, struct audio_usecase *usecase,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07002365 int app_type, int sample_rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302366{
2367 struct platform_data *my_data = (struct platform_data *)platform;
2368 int acdb_dev_id, acdb_dev_type;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05302369 int snd_device = SND_DEVICE_OUT_SPEAKER;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302370 int new_snd_device[SND_DEVICE_OUT_END];
2371 int i, num_devices = 1;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05302372
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302373 if (usecase->type == PCM_PLAYBACK)
Naresh Tannirucc7c4de2015-03-10 16:19:23 +05302374 snd_device = usecase->out_snd_device;
Karthik Reddy Katta81c42612015-11-13 17:49:07 +05302375 else if ((usecase->type == PCM_CAPTURE) &&
2376 voice_is_in_call_rec_stream(usecase->stream.in))
2377 snd_device = voice_get_incall_rec_snd_device(usecase->in_snd_device);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302378 else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Naresh Tannirucc7c4de2015-03-10 16:19:23 +05302379 snd_device = usecase->in_snd_device;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08002380 acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(snd_device)];
Naresh Tannirue3b18452014-03-04 14:44:27 +05302381
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302382 if(!platform_can_split_snd_device(platform, snd_device, &num_devices, new_snd_device)) {
2383 new_snd_device[0] = snd_device;
Naresh Tanniru2727f822015-05-11 15:27:08 +05302384 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302385
2386 for (i = 0; i < num_devices; i++) {
2387 acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(new_snd_device[i])];
2388
2389 // Do not use Rx path default app type for TX path
2390 if ((usecase->type == PCM_CAPTURE) && (app_type == DEFAULT_APP_TYPE_RX_PATH)) {
2391 ALOGD("Resetting app type for Tx path to default");
2392 app_type = DEFAULT_APP_TYPE_TX_PATH;
2393 }
2394 if (acdb_dev_id < 0) {
2395 ALOGE("%s: Could not find acdb id for device(%d)",
2396 __func__, new_snd_device[i]);
2397 return -EINVAL;
2398 }
2399 if (my_data->acdb_send_audio_cal) {
2400 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2401 __func__, new_snd_device[i], acdb_dev_id);
2402 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2403 new_snd_device[i] < SND_DEVICE_OUT_END)
2404 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2405 else
2406 acdb_dev_type = ACDB_DEV_TYPE_IN;
2407 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
2408 sample_rate);
2409 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302410 }
2411 return 0;
2412}
2413
2414int platform_switch_voice_call_device_pre(void *platform)
2415{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302416 struct platform_data *my_data = (struct platform_data *)platform;
2417 int ret = 0;
2418
2419 if (my_data->csd != NULL &&
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07002420 voice_is_in_call(my_data->adev)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302421 /* This must be called before disabling mixer controls on APQ side */
2422 ret = my_data->csd->disable_device();
2423 if (ret < 0) {
2424 ALOGE("%s: csd_client_disable_device, failed, error %d",
2425 __func__, ret);
2426 }
2427 }
2428 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302429}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302430
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302431int platform_switch_voice_call_enable_device_config(void *platform,
2432 snd_device_t out_snd_device,
2433 snd_device_t in_snd_device)
2434{
2435 struct platform_data *my_data = (struct platform_data *)platform;
2436 int acdb_rx_id, acdb_tx_id;
2437 int ret = 0;
2438
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302439 if (my_data->csd == NULL)
2440 return ret;
2441
Banajit Goswami20cdd212015-09-11 01:11:30 -07002442 if ((out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
2443 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT) &&
2444 audio_extn_spkr_prot_is_enabled()) {
2445 if (my_data->is_vbat_speaker)
2446 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT];
2447 else
2448 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
2449 } else
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302450 acdb_rx_id = acdb_device_table[out_snd_device];
2451
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302452 acdb_tx_id = acdb_device_table[in_snd_device];
2453
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302454 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2455 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2456 if (ret < 0) {
2457 ALOGE("%s: csd_enable_device_config, failed, error %d",
2458 __func__, ret);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302459 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302460 } else {
2461 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2462 acdb_rx_id, acdb_tx_id);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302463 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302464
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302465 return ret;
2466}
2467
Naresh Tannirue3b18452014-03-04 14:44:27 +05302468int platform_switch_voice_call_device_post(void *platform,
2469 snd_device_t out_snd_device,
2470 snd_device_t in_snd_device)
2471{
2472 struct platform_data *my_data = (struct platform_data *)platform;
2473 int acdb_rx_id, acdb_tx_id;
2474
2475 if (my_data->acdb_send_voice_cal == NULL) {
2476 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2477 } else {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302478 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2479 audio_extn_spkr_prot_is_enabled())
2480 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
2481
Naresh Tannirue3b18452014-03-04 14:44:27 +05302482 acdb_rx_id = acdb_device_table[out_snd_device];
2483 acdb_tx_id = acdb_device_table[in_snd_device];
2484
2485 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2486 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2487 else
2488 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2489 acdb_rx_id, acdb_tx_id);
2490 }
2491
2492 return 0;
2493}
2494
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302495int platform_switch_voice_call_usecase_route_post(void *platform,
2496 snd_device_t out_snd_device,
2497 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302498{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302499 struct platform_data *my_data = (struct platform_data *)platform;
2500 int acdb_rx_id, acdb_tx_id;
2501 int ret = 0;
2502
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302503 if (my_data->csd == NULL)
2504 return ret;
2505
Banajit Goswami20cdd212015-09-11 01:11:30 -07002506 if ((out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
2507 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT) &&
2508 audio_extn_spkr_prot_is_enabled()) {
2509 if (my_data->is_vbat_speaker)
2510 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT];
2511 else
2512 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
2513 } else
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302514 acdb_rx_id = acdb_device_table[out_snd_device];
2515
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302516 acdb_tx_id = acdb_device_table[in_snd_device];
2517
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302518 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2519 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2520 my_data->adev->acdb_settings);
2521 if (ret < 0) {
2522 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302523 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302524 } else {
2525 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2526 acdb_rx_id, acdb_tx_id);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302527 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302528
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302529 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302530}
2531
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302532int platform_start_voice_call(void *platform, uint32_t vsid)
2533{
2534 struct platform_data *my_data = (struct platform_data *)platform;
2535 int ret = 0;
2536
2537 if (my_data->csd != NULL) {
2538 ret = my_data->csd->start_voice(vsid);
2539 if (ret < 0) {
2540 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2541 }
2542 }
2543 return ret;
2544}
2545
2546int platform_stop_voice_call(void *platform, uint32_t vsid)
2547{
2548 struct platform_data *my_data = (struct platform_data *)platform;
2549 int ret = 0;
2550
2551 if (my_data->csd != NULL) {
2552 ret = my_data->csd->stop_voice(vsid);
2553 if (ret < 0) {
2554 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2555 }
2556 }
2557 return ret;
2558}
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002559
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05302560int platform_get_sample_rate(void *platform __unused,
2561 uint32_t *rate __unused)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302562{
2563 return 0;
2564}
2565
2566int platform_set_voice_volume(void *platform, int volume)
2567{
2568 struct platform_data *my_data = (struct platform_data *)platform;
2569 struct audio_device *adev = my_data->adev;
2570 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302571 const char *mixer_ctl_name = "Voice Rx Gain";
2572 int vol_index = 0, ret = 0;
2573 uint32_t set_values[ ] = {0,
2574 ALL_SESSION_VSID,
2575 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05302576
2577 // Voice volume levels are mapped to adsp volume levels as follows.
2578 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2579 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302580 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
2581 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302582
2583 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2584 if (!ctl) {
2585 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2586 __func__, mixer_ctl_name);
2587 return -EINVAL;
2588 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302589 ALOGV("Setting voice volume index: %d", set_values[0]);
2590 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05302591
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302592 if (my_data->csd != NULL) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302593 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2594 DEFAULT_VOLUME_RAMP_DURATION_MS);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302595 if (ret < 0) {
2596 ALOGE("%s: csd_volume error %d", __func__, ret);
2597 }
2598 }
2599 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302600}
2601
2602int platform_set_mic_mute(void *platform, bool state)
2603{
2604 struct platform_data *my_data = (struct platform_data *)platform;
2605 struct audio_device *adev = my_data->adev;
2606 struct mixer_ctl *ctl;
2607 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302608 int ret = 0;
2609 uint32_t set_values[ ] = {0,
2610 ALL_SESSION_VSID,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302611 DEFAULT_MUTE_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05302612
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302613 set_values[0] = state;
2614 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2615 if (!ctl) {
2616 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2617 __func__, mixer_ctl_name);
2618 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302619 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302620 ALOGV("Setting voice mute state: %d", state);
2621 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05302622
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302623 if (my_data->csd != NULL) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302624 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2625 DEFAULT_MUTE_RAMP_DURATION_MS);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302626 if (ret < 0) {
2627 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
2628 }
2629 }
2630 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302631}
2632
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08002633int platform_set_device_mute(void *platform, bool state, char *dir)
2634{
2635 struct platform_data *my_data = (struct platform_data *)platform;
2636 struct audio_device *adev = my_data->adev;
2637 struct mixer_ctl *ctl;
2638 char *mixer_ctl_name = NULL;
2639 int ret = 0;
2640 uint32_t set_values[ ] = {0,
2641 ALL_SESSION_VSID,
2642 0};
2643 if(dir == NULL) {
2644 ALOGE("%s: Invalid direction:%s", __func__, dir);
2645 return -EINVAL;
2646 }
2647
2648 if (!strncmp("rx", dir, sizeof("rx"))) {
2649 mixer_ctl_name = "Voice Rx Device Mute";
2650 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2651 mixer_ctl_name = "Voice Tx Device Mute";
2652 } else {
2653 return -EINVAL;
2654 }
2655
2656 set_values[0] = state;
2657 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2658 if (!ctl) {
2659 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2660 __func__, mixer_ctl_name);
2661 return -EINVAL;
2662 }
2663
2664 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2665 __func__,state, mixer_ctl_name);
2666 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2667
2668 return ret;
2669}
2670
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302671bool platform_can_split_snd_device(void *platform,
2672 snd_device_t snd_device,
2673 int *num_devices,
2674 snd_device_t *new_snd_devices)
2675{
2676 bool status = false;
2677 struct platform_data *my_data = (struct platform_data *)platform;
2678
2679 if (NULL == num_devices || NULL == new_snd_devices) {
2680 ALOGE("%s: NULL pointer ..", __func__);
2681 return false;
2682 }
2683
2684 /*
2685 * If wired headset/headphones/line devices share the same backend
2686 * with speaker/earpiece this routine returns false.
2687 */
2688 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2689 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2690 *num_devices = 2;
2691
2692 if (my_data->is_vbat_speaker)
2693 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_VBAT;
2694 else if (my_data->is_wsa_speaker)
2695 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
2696 else
2697 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2698
2699 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
2700 status = true;
2701 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI &&
2702 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HDMI)) {
2703 *num_devices = 2;
2704
2705 if (my_data->is_vbat_speaker)
2706 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_VBAT;
2707 else if (my_data->is_wsa_speaker)
2708 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
2709 else
2710 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2711
2712 new_snd_devices[1] = SND_DEVICE_OUT_HDMI;
2713 status = true;
2714 }
2715
2716 ALOGD("%s: snd_device(%d) num devices(%d) new_snd_devices(%d)", __func__,
2717 snd_device, *num_devices, *new_snd_devices);
2718
2719 return status;
2720}
2721
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002722snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *out)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302723{
2724 struct platform_data *my_data = (struct platform_data *)platform;
2725 struct audio_device *adev = my_data->adev;
2726 audio_mode_t mode = adev->mode;
2727 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002728 audio_devices_t devices = out->devices;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302729 unsigned int sample_rate = out->sample_rate;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302730 int na_mode = platform_get_native_support();
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302731#ifdef RECORD_PLAY_CONCURRENCY
2732 bool use_voip_out_devices = false;
2733 bool prop_rec_play_enabled = false;
2734 char recConcPropValue[PROPERTY_VALUE_MAX];
2735
2736 if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) {
2737 prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4);
2738 }
2739 use_voip_out_devices = prop_rec_play_enabled &&
2740 (my_data->rec_play_conc_set || adev->mode == AUDIO_MODE_IN_COMMUNICATION);
2741 ALOGV("platform_get_output_snd_device use_voip_out_devices : %d",use_voip_out_devices);
2742#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +05302743
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302744 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2745 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2746 int channel_count = popcount(channel_mask);
2747
Naresh Tannirue3b18452014-03-04 14:44:27 +05302748 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2749 if (devices == AUDIO_DEVICE_NONE ||
2750 devices & AUDIO_DEVICE_BIT_IN) {
2751 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2752 goto exit;
2753 }
2754
Shiv Maliyappanahallibd401262015-08-17 11:02:21 -07002755 if (popcount(devices) == 2) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302756 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2757 AUDIO_DEVICE_OUT_SPEAKER)) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302758 if (my_data->external_spk_1)
2759 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
2760 else if (my_data->external_spk_2)
2761 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
2762 else
2763 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05302764 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2765 AUDIO_DEVICE_OUT_SPEAKER)) {
2766 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302767 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2768 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302769 if (audio_extn_get_anc_enabled())
2770 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302771 else if (my_data->external_spk_1)
2772 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
2773 else if (my_data->external_spk_2)
2774 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302775 else
2776 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302777 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2778 AUDIO_DEVICE_OUT_SPEAKER)) {
2779 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302780 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
2781 AUDIO_DEVICE_OUT_SPEAKER)) {
2782 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302783 } else {
2784 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2785 goto exit;
2786 }
2787 if (snd_device != SND_DEVICE_NONE) {
2788 goto exit;
2789 }
2790 }
2791
2792 if (popcount(devices) != 1) {
2793 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2794 goto exit;
2795 }
2796
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05302797 if ((mode == AUDIO_MODE_IN_CALL) ||
2798 voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302799 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05302800 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2801 devices & AUDIO_DEVICE_OUT_LINE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302802 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
2803 !voice_extn_compress_voip_is_active(adev)) {
2804 switch (adev->voice.tty_mode) {
2805 case TTY_MODE_FULL:
2806 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
2807 break;
2808 case TTY_MODE_VCO:
2809 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
2810 break;
2811 case TTY_MODE_HCO:
2812 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2813 break;
2814 default:
2815 ALOGE("%s: Invalid TTY mode (%#x)",
2816 __func__, adev->voice.tty_mode);
2817 }
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05302818 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2819 snd_device = SND_DEVICE_OUT_VOICE_LINE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302820 } else if (audio_extn_get_anc_enabled()) {
2821 if (audio_extn_should_use_fb_anc())
2822 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
2823 else
2824 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
2825 } else {
2826 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2827 }
2828 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07002829 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302830 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2831 else
2832 snd_device = SND_DEVICE_OUT_BT_SCO;
2833 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Banajit Goswami20cdd212015-09-11 01:11:30 -07002834 if (my_data->is_vbat_speaker)
2835 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_VBAT;
2836 else if (my_data->is_wsa_speaker)
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05302837 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_WSA;
2838 else
2839 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302840 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2841 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
2842 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2843 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
2844 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
2845 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
2846 if (audio_extn_should_use_handset_anc(channel_count))
2847 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
2848 else
2849 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +05302850 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2851 snd_device = SND_DEVICE_OUT_VOICE_TX;
2852
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302853 if (snd_device != SND_DEVICE_NONE) {
2854 goto exit;
2855 }
2856 }
2857
Naresh Tannirue3b18452014-03-04 14:44:27 +05302858 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2859 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302860 if (OUTPUT_SAMPLING_RATE_44100 == sample_rate &&
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302861 NATIVE_AUDIO_MODE_SRC == na_mode &&
Sidipotu Ashokbffd2202015-08-20 14:06:55 +05302862 !audio_extn_get_anc_enabled()) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302863
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302864 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302865
2866 } else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302867 && audio_extn_get_anc_enabled()) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302868#ifdef RECORD_PLAY_CONCURRENCY
2869 if (use_voip_out_devices) {
2870 // ANC should be disabled for voip concurrency
2871 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
2872 } else
2873#endif
2874 {
2875 if (audio_extn_should_use_fb_anc())
2876 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
2877 else
2878 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
2879 }
2880 } else {
2881#ifdef RECORD_PLAY_CONCURRENCY
2882 if (use_voip_out_devices)
2883 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302884 else
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302885#endif
2886 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302887 }
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05302888 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2889 snd_device = SND_DEVICE_OUT_LINE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302890 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302891#ifdef RECORD_PLAY_CONCURRENCY
2892 if (use_voip_out_devices) {
2893 snd_device = SND_DEVICE_OUT_VOIP_SPEAKER;
2894 } else
2895#endif
2896 {
2897 if (adev->speaker_lr_swap)
2898 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2899 else
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05302900 {
Banajit Goswami20cdd212015-09-11 01:11:30 -07002901 if (my_data->is_vbat_speaker)
2902 snd_device = SND_DEVICE_OUT_SPEAKER_VBAT;
2903 else if (my_data->is_wsa_speaker)
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05302904 snd_device = SND_DEVICE_OUT_SPEAKER_WSA;
2905 else
2906 snd_device = SND_DEVICE_OUT_SPEAKER;
2907 }
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302908 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302909 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07002910 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302911 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2912 else
2913 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302914 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2915 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302916 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2917 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08002918 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
2919 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302920 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2921 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
2922 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302923 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302924#ifdef RECORD_PLAY_CONCURRENCY
2925 if (use_voip_out_devices)
2926 snd_device = SND_DEVICE_OUT_VOIP_HANDSET;
2927 else
2928#endif
2929 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302930 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08002931 channel_count = audio_extn_get_afe_proxy_channel_count();
2932 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
2933 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302934 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302935 } else {
2936 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2937 }
2938exit:
2939 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2940 return snd_device;
2941}
2942
2943snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2944{
2945 struct platform_data *my_data = (struct platform_data *)platform;
2946 struct audio_device *adev = my_data->adev;
2947 audio_source_t source = (adev->active_input == NULL) ?
2948 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2949
2950 audio_mode_t mode = adev->mode;
2951 audio_devices_t in_device = ((adev->active_input == NULL) ?
2952 AUDIO_DEVICE_NONE : adev->active_input->device)
2953 & ~AUDIO_DEVICE_BIT_IN;
2954 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2955 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2956 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302957 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302958
2959 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
2960 __func__, out_device, in_device);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302961 if (my_data->external_mic) {
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05302962 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
2963 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302964 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2965 out_device & AUDIO_DEVICE_OUT_EARPIECE ||
2966 out_device & AUDIO_DEVICE_OUT_SPEAKER )
2967 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
2968 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2969 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2970 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
2971 }
2972 }
2973
2974 if (snd_device != AUDIO_DEVICE_NONE)
2975 goto exit;
2976
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05302977 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
Satya Krishna Pindiproli2aaa6152014-05-21 15:05:22 +05302978 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302979 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
2980 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302981 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05302982 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2983 out_device & AUDIO_DEVICE_OUT_LINE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302984 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302985 case TTY_MODE_FULL:
2986 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2987 break;
2988 case TTY_MODE_VCO:
2989 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2990 break;
2991 case TTY_MODE_HCO:
2992 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2993 break;
2994 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302995 ALOGE("%s: Invalid TTY mode (%#x)",
2996 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302997 }
2998 goto exit;
2999 }
3000 }
3001 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05303002 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3003 out_device & AUDIO_DEVICE_OUT_LINE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303004 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
Sidipotu Ashok3bcca232014-11-07 14:41:58 +05303005 audio_extn_should_use_handset_anc(channel_count) &&
3006 my_data->fluence_type != FLUENCE_NONE) {
3007 snd_device = SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC;
3008 adev->acdb_settings |= DMIC_FLAG;
3009 ALOGD("Selecting AANC, Fluence combo device");
3010 } else if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303011 audio_extn_should_use_handset_anc(channel_count)) {
3012 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303013 adev->acdb_settings |= ANC_FLAG;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303014 } else if (my_data->fluence_type == FLUENCE_NONE ||
3015 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05303016 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05303017 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003018 platform_set_echo_reference(adev, true, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05303019 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303020 snd_device = SND_DEVICE_IN_VOICE_DMIC;
3021 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303022 }
3023 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3024 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303025 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003026 platform_set_echo_reference(adev, true, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05303027 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07003028 if (adev->bt_wb_speech_enabled) {
3029 if (adev->bluetooth_nrec)
3030 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3031 else
3032 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
3033 } else {
3034 if (adev->bluetooth_nrec)
3035 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3036 else
3037 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
3038 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05303039 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303040 if (my_data->fluence_type != FLUENCE_NONE &&
3041 my_data->fluence_in_voice_call &&
3042 my_data->fluence_in_spkr_mode) {
3043 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
3044 adev->acdb_settings |= QMIC_FLAG;
3045 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
3046 } else {
3047 adev->acdb_settings |= DMIC_FLAG;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05303048 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
3049 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
3050 else
3051 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303052 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05303053 } else {
3054 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05303055 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003056 platform_set_echo_reference(adev, true, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05303057 }
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +05303058 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX)
3059 snd_device = SND_DEVICE_IN_VOICE_RX;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303060 } else if (source == AUDIO_SOURCE_CAMCORDER) {
3061 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
3062 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
kunleiz18a33302014-05-30 09:52:25 +08003063 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
3064 channel_count == 2)
kunleiz8f7e9e22014-06-24 15:12:02 +08003065 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
kunleiz18a33302014-05-30 09:52:25 +08003066 else
3067 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303068 }
3069 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
3070 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303071 if (channel_count == 2) {
3072 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
3073 adev->acdb_settings |= DMIC_FLAG;
3074 } else if (adev->active_input->enable_ns)
3075 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
3076 else if (my_data->fluence_type != FLUENCE_NONE &&
3077 my_data->fluence_in_voice_rec) {
3078 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
3079 adev->acdb_settings |= DMIC_FLAG;
3080 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05303081 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
3082 }
3083 }
Karthik Reddy Kattaf621ec72014-11-21 16:37:38 +05303084 } else if ((source == AUDIO_SOURCE_VOICE_COMMUNICATION) ||
3085 (mode == AUDIO_MODE_IN_COMMUNICATION)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05303086 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
3087 in_device = AUDIO_DEVICE_IN_BACK_MIC;
3088 if (adev->active_input) {
Venkata Narendra Kumar Gutta35b5cc52015-05-25 15:32:03 +05303089 if (my_data->fluence_type != FLUENCE_NONE &&
3090 adev->active_input->enable_aec &&
3091 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05303092 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303093 if (my_data->fluence_in_spkr_mode) {
3094 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
3095 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
3096 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
3097 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
3098 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
3099 else
3100 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
3101 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303102 adev->acdb_settings |= DMIC_FLAG;
3103 } else
3104 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303105 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303106 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
3107 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
3108 adev->acdb_settings |= DMIC_FLAG;
3109 } else
3110 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303111 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303112 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303113 }
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003114 platform_set_echo_reference(adev, true, out_device);
Venkata Narendra Kumar Gutta35b5cc52015-05-25 15:32:03 +05303115 } else if (my_data->fluence_type != FLUENCE_NONE &&
3116 adev->active_input->enable_aec) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303117 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303118 if (my_data->fluence_in_spkr_mode) {
3119 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
3120 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC;
3121 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
3122 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
3123 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
3124 else
3125 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
3126 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303127 adev->acdb_settings |= DMIC_FLAG;
3128 } else
3129 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
3130 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3131 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
3132 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3133 adev->acdb_settings |= DMIC_FLAG;
3134 } else
3135 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
3136 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3137 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
3138 }
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003139 platform_set_echo_reference(adev, true, out_device);
Venkata Narendra Kumar Gutta35b5cc52015-05-25 15:32:03 +05303140 } else if (my_data->fluence_type != FLUENCE_NONE &&
3141 adev->active_input->enable_ns) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303142 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303143 if (my_data->fluence_in_spkr_mode) {
3144 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
3145 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_NS;
3146 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
3147 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
3148 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
3149 else
3150 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
3151 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303152 adev->acdb_settings |= DMIC_FLAG;
3153 } else
3154 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
3155 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3156 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
3157 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
3158 adev->acdb_settings |= DMIC_FLAG;
3159 } else
3160 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
3161 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3162 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
3163 }
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003164 platform_set_echo_reference(adev, false, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05303165 } else
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003166 platform_set_echo_reference(adev, false, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05303167 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303168 } else if (source == AUDIO_SOURCE_MIC) {
3169 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
3170 channel_count == 1 ) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303171 if(my_data->fluence_in_audio_rec) {
3172 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
3173 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003174 platform_set_echo_reference(adev, true, out_device);
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303175 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
3176 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003177 platform_set_echo_reference(adev, true, out_device);
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303178 }
3179 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303180 }
Mingming Yin12125e82015-10-26 20:40:36 -07003181 } else if (source == AUDIO_SOURCE_FM_TUNER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303182 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303183 } else if (source == AUDIO_SOURCE_DEFAULT) {
3184 goto exit;
3185 }
3186
Shiv Maliyappanahalli5a10aea2015-07-02 10:36:23 -07003187 if (adev->active_input && (audio_extn_ssr_get_stream() == adev->active_input))
3188 snd_device = SND_DEVICE_IN_THREE_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303189
3190 if (snd_device != SND_DEVICE_NONE) {
3191 goto exit;
3192 }
3193
3194 if (in_device != AUDIO_DEVICE_NONE &&
3195 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3196 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3197 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Shiv Maliyappanahalli5a10aea2015-07-02 10:36:23 -07003198 if (adev->active_input && (audio_extn_ssr_get_stream() == adev->active_input))
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303199 snd_device = SND_DEVICE_IN_QUAD_MIC;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303200 else if (my_data->fluence_type & (FLUENCE_DUAL_MIC | FLUENCE_QUAD_MIC) &&
3201 channel_count == 2)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303202 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
3203 else
3204 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303205 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3206 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3207 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3208 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3209 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07003210 if (adev->bt_wb_speech_enabled) {
3211 if (adev->bluetooth_nrec)
3212 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3213 else
3214 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
3215 } else {
3216 if (adev->bluetooth_nrec)
3217 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3218 else
3219 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
3220 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05303221 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3222 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303223 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
3224 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
3225 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Mingming Yin12125e82015-10-26 20:40:36 -07003226 } else if (in_device & AUDIO_DEVICE_IN_FM_TUNER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303227 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303228 } else {
3229 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3230 ALOGW("%s: Using default handset-mic", __func__);
3231 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3232 }
3233 } else {
3234 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3235 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3236 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3237 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3238 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303239 if (channel_count > 1)
3240 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
3241 else
3242 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05303243 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3244 out_device & AUDIO_DEVICE_OUT_LINE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05303245 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3246 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07003247 if (adev->bt_wb_speech_enabled) {
3248 if (adev->bluetooth_nrec)
3249 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3250 else
3251 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
3252 } else {
3253 if (adev->bluetooth_nrec)
3254 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3255 else
3256 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
3257 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05303258 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3259 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303260 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
3261 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
3262 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303263 } else {
3264 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3265 ALOGW("%s: Using default handset-mic", __func__);
3266 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3267 }
3268 }
3269exit:
3270 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3271 return snd_device;
3272}
3273
3274int platform_set_hdmi_channels(void *platform, int channel_count)
3275{
3276 struct platform_data *my_data = (struct platform_data *)platform;
3277 struct audio_device *adev = my_data->adev;
3278 struct mixer_ctl *ctl;
3279 const char *channel_cnt_str = NULL;
3280 const char *mixer_ctl_name = "HDMI_RX Channels";
3281 switch (channel_count) {
3282 case 8:
3283 channel_cnt_str = "Eight"; break;
3284 case 7:
3285 channel_cnt_str = "Seven"; break;
3286 case 6:
3287 channel_cnt_str = "Six"; break;
3288 case 5:
3289 channel_cnt_str = "Five"; break;
3290 case 4:
3291 channel_cnt_str = "Four"; break;
3292 case 3:
3293 channel_cnt_str = "Three"; break;
3294 default:
3295 channel_cnt_str = "Two"; break;
3296 }
3297 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3298 if (!ctl) {
3299 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3300 __func__, mixer_ctl_name);
3301 return -EINVAL;
3302 }
3303 ALOGV("HDMI channel count: %s", channel_cnt_str);
3304 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3305 return 0;
3306}
3307
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303308int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05303309{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303310 int channel_count;
3311 int max_channels = 2;
3312 int i = 0, ret = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303313 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303314 edid_audio_info *info = NULL;
3315 ret = platform_get_edid_info(platform);
3316 info = (edid_audio_info *)my_data->edid_info;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303317
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303318 if(ret == 0 && info != NULL) {
3319 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
3320 ALOGV("%s:format %d channel %d", __func__,
3321 info->audio_blocks_array[i].format_id,
3322 info->audio_blocks_array[i].channels);
3323 if (info->audio_blocks_array[i].format_id == LPCM) {
3324 channel_count = info->audio_blocks_array[i].channels;
3325 if (channel_count > max_channels) {
3326 max_channels = channel_count;
3327 }
3328 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303329 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05303330 }
3331
3332 return max_channels;
3333}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303334
3335static int platform_set_slowtalk(struct platform_data *my_data, bool state)
3336{
3337 int ret = 0;
3338 struct audio_device *adev = my_data->adev;
3339 struct mixer_ctl *ctl;
3340 const char *mixer_ctl_name = "Slowtalk Enable";
3341 uint32_t set_values[ ] = {0,
3342 ALL_SESSION_VSID};
3343
3344 set_values[0] = state;
3345 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3346 if (!ctl) {
3347 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3348 __func__, mixer_ctl_name);
3349 ret = -EINVAL;
3350 } else {
3351 ALOGV("Setting slowtalk state: %d", state);
3352 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
3353 my_data->slowtalk = state;
3354 }
3355
3356 if (my_data->csd != NULL) {
3357 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
3358 if (ret < 0) {
3359 ALOGE("%s: csd_client_disable_device, failed, error %d",
3360 __func__, ret);
3361 }
3362 }
3363 return ret;
3364}
3365
Avinash Vaishd5fa4572014-09-15 14:41:14 +05303366static int set_hd_voice(struct platform_data *my_data, bool state)
3367{
3368 struct audio_device *adev = my_data->adev;
3369 struct mixer_ctl *ctl;
3370 const char *mixer_ctl_name = "HD Voice Enable";
3371 int ret = 0;
3372 uint32_t set_values[ ] = {0,
3373 ALL_SESSION_VSID};
3374
3375 set_values[0] = state;
3376 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3377 if (!ctl) {
3378 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3379 __func__, mixer_ctl_name);
3380 ret = -EINVAL;
3381 } else {
3382 ALOGV("Setting HD Voice state: %d", state);
3383 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
3384 my_data->hd_voice = state;
3385 }
3386
3387 return ret;
3388}
3389
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303390int platform_set_parameters(void *platform, struct str_parms *parms)
3391{
3392 struct platform_data *my_data = (struct platform_data *)platform;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303393 char value[256] = {0};
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05303394 int len;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303395 int ret = 0, err;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303396 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303397
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303398 kv_pairs = str_parms_to_str(parms);
Venkata Narendra Kumar Gutta7c131ef2015-11-17 14:15:57 +05303399 len = strlen(kv_pairs);
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303400 ALOGV("%s: enter: - %s", __func__, kv_pairs);
3401 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303402
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303403 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
3404 if (err >= 0) {
3405 bool state = false;
3406 if (!strncmp("true", value, sizeof("true"))) {
3407 state = true;
3408 }
3409
3410 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
3411 ret = platform_set_slowtalk(my_data, state);
3412 if (ret)
3413 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
3414 }
3415
Avinash Vaishd5fa4572014-09-15 14:41:14 +05303416 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, sizeof(value));
3417 if (err >= 0) {
3418 bool state = false;
3419 if (!strncmp("true", value, sizeof("true"))) {
3420 state = true;
3421 }
3422
3423 str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE);
3424 if (my_data->hd_voice != state) {
3425 ret = set_hd_voice(my_data, state);
3426 if (ret)
3427 ALOGE("%s: Failed to set HD voice err: %d", __func__, ret);
3428 } else {
3429 ALOGV("%s: HD Voice already set to %d", __func__, state);
3430 }
3431 }
3432
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303433 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
3434 value, sizeof(value));
3435 if (err >= 0) {
3436 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
3437
3438 if (my_data->acdb_reload_vocvoltable == NULL) {
3439 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
3440 } else if (!strcmp(value, "on")) {
3441 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
3442 my_data->voice_feature_set = 1;
3443 }
3444 } else {
3445 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
3446 my_data->voice_feature_set = 0;
3447 }
3448 }
3449 }
3450
Karthik Reddy Katta8513f432016-04-12 14:29:27 +05303451 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_RELOAD_ACDB,
3452 value, sizeof(value));
3453 if (err >= 0) {
3454 str_parms_del(parms, AUDIO_PARAMETER_KEY_RELOAD_ACDB);
3455
3456 my_data->acdb_reload(value, my_data->snd_card_name,
3457 my_data->cvd_version, my_data->metainfo_key);
3458
3459 }
3460
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05303461#ifdef RECORD_PLAY_CONCURRENCY
3462 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_REC_PLAY_CONC, value, sizeof(value));
3463 if (err >= 0) {
3464 if (!strncmp("true", value, sizeof("true"))) {
3465 ALOGD("setting record playback concurrency to true");
3466 my_data->rec_play_conc_set = true;
3467 } else {
3468 ALOGD("setting record playback concurrency to false");
3469 my_data->rec_play_conc_set = false;
3470 }
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05303471 }
3472#endif
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303473 native_audio_set_params(platform, parms, value, sizeof(value));
Venkata Narendra Kumar Gutta7c131ef2015-11-17 14:15:57 +05303474 audio_extn_spkr_prot_set_parameters(parms, value, len);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303475 ALOGV("%s: exit with code(%d)", __func__, ret);
3476 return ret;
3477}
3478
3479int platform_set_incall_recording_session_id(void *platform,
3480 uint32_t session_id, int rec_mode)
3481{
3482 int ret = 0;
3483 struct platform_data *my_data = (struct platform_data *)platform;
3484 struct audio_device *adev = my_data->adev;
3485 struct mixer_ctl *ctl;
3486 const char *mixer_ctl_name = "Voc VSID";
3487 int num_ctl_values;
3488 int i;
3489
3490 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3491 if (!ctl) {
3492 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3493 __func__, mixer_ctl_name);
3494 ret = -EINVAL;
3495 } else {
3496 num_ctl_values = mixer_ctl_get_num_values(ctl);
3497 for (i = 0; i < num_ctl_values; i++) {
3498 if (mixer_ctl_set_value(ctl, i, session_id)) {
3499 ALOGV("Error: invalid session_id: %x", session_id);
3500 ret = -EINVAL;
3501 break;
3502 }
3503 }
3504 }
3505
3506 if (my_data->csd != NULL) {
3507 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3508 if (ret < 0) {
3509 ALOGE("%s: csd_client_start_record failed, error %d",
3510 __func__, ret);
3511 }
3512 }
3513
3514 return ret;
3515}
3516
3517int platform_stop_incall_recording_usecase(void *platform)
3518{
3519 int ret = 0;
3520 struct platform_data *my_data = (struct platform_data *)platform;
3521
3522 if (my_data->csd != NULL) {
3523 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3524 if (ret < 0) {
3525 ALOGE("%s: csd_client_stop_record failed, error %d",
3526 __func__, ret);
3527 }
3528 }
3529
3530 return ret;
3531}
3532
3533int platform_start_incall_music_usecase(void *platform)
3534{
3535 int ret = 0;
3536 struct platform_data *my_data = (struct platform_data *)platform;
3537
3538 if (my_data->csd != NULL) {
3539 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3540 if (ret < 0) {
3541 ALOGE("%s: csd_client_start_playback failed, error %d",
3542 __func__, ret);
3543 }
3544 }
3545
3546 return ret;
3547}
3548
3549int platform_stop_incall_music_usecase(void *platform)
3550{
3551 int ret = 0;
3552 struct platform_data *my_data = (struct platform_data *)platform;
3553
3554 if (my_data->csd != NULL) {
3555 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3556 if (ret < 0) {
3557 ALOGE("%s: csd_client_stop_playback failed, error %d",
3558 __func__, ret);
3559 }
3560 }
3561
3562 return ret;
3563}
3564
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07003565int platform_update_lch(void *platform, struct voice_session *session,
3566 enum voice_lch_mode lch_mode)
3567{
3568 int ret = 0;
3569 struct platform_data *my_data = (struct platform_data *)platform;
3570
3571 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
3572 ret = my_data->csd->set_lch(session->vsid, lch_mode);
3573 else
3574 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
3575
3576 return ret;
3577}
3578
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303579void platform_get_parameters(void *platform,
3580 struct str_parms *query,
3581 struct str_parms *reply)
3582{
3583 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303584 char value[512] = {0};
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303585 int ret;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303586 char *kv_pairs = NULL;
Sidipotu Ashok42483b62015-09-08 10:21:44 +05303587 char propValue[PROPERTY_VALUE_MAX]={0};
3588 bool prop_playback_enabled = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303589
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303590 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
3591 value, sizeof(value));
3592 if (ret >= 0) {
3593 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
3594 my_data->slowtalk?"true":"false");
3595 }
3596
Avinash Vaishd5fa4572014-09-15 14:41:14 +05303597 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE,
3598 value, sizeof(value));
3599 if (ret >= 0) {
3600 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE,
3601 my_data->hd_voice?"true":"false");
3602 }
3603
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303604 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
3605 value, sizeof(value));
3606 if (ret >= 0) {
3607 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
3608 strlcpy(value, "on", sizeof(value));
3609 } else {
3610 strlcpy(value, "off", sizeof(value));
3611 }
3612
3613 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
3614 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303615 native_audio_get_params(query, reply, value, sizeof(value));
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303616
Sidipotu Ashokf490be52015-10-20 10:41:34 +05303617 ret = str_parms_get_str(query, AUDIO_PARAMETER_IS_HW_DECODER_SESSION_AVAILABLE,
Sidipotu Ashok42483b62015-09-08 10:21:44 +05303618 value, sizeof(value));
3619 if (ret >= 0) {
3620 int isallowed = 1; /*true*/
3621
3622 if (property_get("voice.playback.conc.disabled", propValue, NULL)) {
3623 prop_playback_enabled = atoi(propValue) ||
3624 !strncmp("true", propValue, 4);
3625 }
3626
3627 if (prop_playback_enabled && (voice_is_in_call(my_data->adev) ||
3628 (SND_CARD_STATE_OFFLINE == get_snd_card_state(my_data->adev)))) {
3629 char *decoder_mime_type = value;
3630
3631 //check if unsupported mime type or not
3632 if(decoder_mime_type) {
Alexy Josephb1379942016-01-29 15:49:38 -08003633 unsigned int i = 0;
Sidipotu Ashok42483b62015-09-08 10:21:44 +05303634 for (i = 0; i < sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]); i++) {
3635 if (!strncmp(decoder_mime_type, dsp_only_decoders_mime[i],
3636 strlen(dsp_only_decoders_mime[i]))) {
3637 ALOGD("Rejecting request for DSP only session from HAL during voice call/SSR state");
3638 isallowed = 0;
3639 break;
3640 }
3641 }
3642 }
3643 }
Sidipotu Ashokf490be52015-10-20 10:41:34 +05303644 str_parms_add_int(reply, AUDIO_PARAMETER_IS_HW_DECODER_SESSION_AVAILABLE, isallowed);
Sidipotu Ashok42483b62015-09-08 10:21:44 +05303645 }
3646
3647
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303648 /* Handle audio calibration keys */
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303649 kv_pairs = str_parms_to_str(reply);
3650 ALOGV("%s: exit: returns - %s", __func__, kv_pairs);
3651 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303652}
3653
3654/* Delay in Us */
3655int64_t platform_render_latency(audio_usecase_t usecase)
3656{
3657 switch (usecase) {
3658 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3659 return DEEP_BUFFER_PLATFORM_DELAY;
3660 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3661 return LOW_LATENCY_PLATFORM_DELAY;
3662 default:
3663 return 0;
3664 }
3665}
3666
3667int platform_update_usecase_from_source(int source, int usecase)
3668{
3669 ALOGV("%s: input source :%d", __func__, source);
Mingming Yin12125e82015-10-26 20:40:36 -07003670 if (source == AUDIO_SOURCE_FM_TUNER)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303671 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
3672 return usecase;
3673}
3674
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303675bool platform_listen_device_needs_event(snd_device_t snd_device)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303676{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303677 bool needs_event = false;
3678
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303679 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
3680 (snd_device < SND_DEVICE_IN_END) &&
3681 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
3682 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303683 needs_event = true;
3684
3685 return needs_event;
3686}
3687
3688bool platform_listen_usecase_needs_event(audio_usecase_t uc_id)
3689{
3690 bool needs_event = false;
3691
3692 switch(uc_id){
3693 /* concurrent playback usecases needs event */
3694 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3695 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
3696 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
3697 needs_event = true;
3698 break;
3699 /* concurrent playback in low latency allowed */
3700 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3701 break;
3702 /* concurrent playback FM needs event */
3703 case USECASE_AUDIO_PLAYBACK_FM:
3704 needs_event = true;
3705 break;
3706
3707 /* concurrent capture usecases, no event, capture handled by device
3708 * USECASE_AUDIO_RECORD:
3709 * USECASE_AUDIO_RECORD_COMPRESS:
3710 * USECASE_AUDIO_RECORD_LOW_LATENCY:
3711
3712 * USECASE_VOICE_CALL:
3713 * USECASE_VOICE2_CALL:
3714 * USECASE_VOLTE_CALL:
3715 * USECASE_QCHAT_CALL:
3716 * USECASE_VOWLAN_CALL:
Avinash Vaish306e6072015-05-13 16:58:18 +05303717 * USECASE_VOICEMMODE1_CALL:
3718 * USECASE_VOICEMMODE2_CALL:
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303719 * USECASE_COMPRESS_VOIP_CALL:
3720 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
3721 * USECASE_INCALL_REC_UPLINK:
3722 * USECASE_INCALL_REC_DOWNLINK:
3723 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
3724 * USECASE_INCALL_REC_UPLINK_COMPRESS:
3725 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
3726 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
3727 * USECASE_INCALL_MUSIC_UPLINK:
3728 * USECASE_INCALL_MUSIC_UPLINK2:
3729 * USECASE_AUDIO_SPKR_CALIB_RX:
3730 * USECASE_AUDIO_SPKR_CALIB_TX:
3731 */
3732 default:
3733 ALOGV("%s:usecase_id[%d} no need to raise event.", __func__, uc_id);
3734 }
3735 return needs_event;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303736}
3737
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07003738bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
3739{
3740 bool needs_event = false;
3741
3742 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
3743 (snd_device < SND_DEVICE_IN_END) &&
3744 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
3745 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
3746 needs_event = true;
3747
3748 return needs_event;
3749}
3750
3751bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
3752{
3753 bool needs_event = false;
3754
3755 switch(uc_id){
3756 /* concurrent playback usecases needs event */
3757 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3758 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
3759 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
3760 needs_event = true;
3761 break;
3762 /* concurrent playback in low latency allowed */
3763 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3764 break;
3765 /* concurrent playback FM needs event */
3766 case USECASE_AUDIO_PLAYBACK_FM:
3767 needs_event = true;
3768 break;
3769
3770 /* concurrent capture usecases, no event, capture handled by device
3771 * USECASE_AUDIO_RECORD:
3772 * USECASE_AUDIO_RECORD_COMPRESS:
3773 * USECASE_AUDIO_RECORD_LOW_LATENCY:
3774
3775 * USECASE_VOICE_CALL:
3776 * USECASE_VOICE2_CALL:
3777 * USECASE_VOLTE_CALL:
3778 * USECASE_QCHAT_CALL:
3779 * USECASE_VOWLAN_CALL:
Avinash Vaish306e6072015-05-13 16:58:18 +05303780 * USECASE_VOICEMMODE1_CALL:
3781 * USECASE_VOICEMMODE2_CALL:
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07003782 * USECASE_COMPRESS_VOIP_CALL:
3783 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
3784 * USECASE_INCALL_REC_UPLINK:
3785 * USECASE_INCALL_REC_DOWNLINK:
3786 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
3787 * USECASE_INCALL_REC_UPLINK_COMPRESS:
3788 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
3789 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
3790 * USECASE_INCALL_MUSIC_UPLINK:
3791 * USECASE_INCALL_MUSIC_UPLINK2:
3792 * USECASE_AUDIO_SPKR_CALIB_RX:
3793 * USECASE_AUDIO_SPKR_CALIB_TX:
3794 */
3795 default:
3796 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
3797 }
3798 return needs_event;
3799}
3800
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303801/* Read offload buffer size from a property.
3802 * If value is not power of 2 round it to
3803 * power of 2.
3804 */
3805uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
3806{
3807 char value[PROPERTY_VALUE_MAX] = {0};
3808 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3809 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
3810 atoi(value)) {
3811 fragment_size = atoi(value) * 1024;
3812 }
3813
vivek mehta80a44292015-08-10 12:58:10 -07003814 /* Use incoming offload buffer size if default buffer size is less */
3815 if ((info != NULL) && (fragment_size < info->offload_buffer_size)) {
3816 ALOGI("%s:: Overwriting offload buffer size default:%d new:%d", __func__,
3817 fragment_size,
3818 info->offload_buffer_size);
3819 fragment_size = info->offload_buffer_size;
3820 }
3821
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303822 // For FLAC use max size since it is loss less, and has sampling rates
3823 // upto 192kHZ
3824 if (info != NULL && !info->has_video &&
3825 info->format == AUDIO_FORMAT_FLAC) {
3826 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3827 ALOGV("FLAC fragment size %d", fragment_size);
3828 }
3829
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303830 if (info != NULL && info->has_video && info->is_streaming) {
3831 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
3832 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07003833 __func__, fragment_size);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303834 }
3835
3836 fragment_size = ALIGN( fragment_size, 1024);
3837
3838 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
3839 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3840 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
3841 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3842 ALOGV("%s: fragment_size %d", __func__, fragment_size);
3843 return fragment_size;
3844}
3845
3846uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
3847{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303848 uint32_t fragment_size = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303849 uint32_t bits_per_sample = 16;
Alexy Joseph2ce25e22015-06-18 12:02:01 -07003850 uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303851
3852 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
3853 bits_per_sample = 32;
3854 }
3855
Alexy Joseph2ce25e22015-06-18 12:02:01 -07003856 //duration is set to 40 ms worth of stereo data at 48Khz
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303857 //with 16 bit per sample, modify this when the channel
3858 //configuration is different
3859 fragment_size = (pcm_offload_time
3860 * info->sample_rate
3861 * (bits_per_sample >> 3)
3862 * popcount(info->channel_mask))/1000;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303863 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
3864 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
3865 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
3866 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
Preetam Singh Ranawat6efde5c2015-04-24 11:04:22 +05303867 // To have same PCM samples for all channels, the buffer size requires to
3868 // be multiple of (number of channels * bytes per sample)
3869 // For writes to succeed, the buffer must be written at address which is multiple of 32
Preetam Singh Ranawat8347e462015-05-27 11:14:03 +05303870 fragment_size = ALIGN(fragment_size, ((bits_per_sample >> 3)* popcount(info->channel_mask) * 32));
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303871
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303872 ALOGI("PCM offload Fragment size to %d bytes", fragment_size);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303873 return fragment_size;
3874}
3875
Asish Bhattacharya9e25c492015-07-10 14:23:28 +05303876bool platform_use_small_buffer(audio_offload_info_t* info)
3877{
3878 return OFFLOAD_USE_SMALL_BUFFER;
3879}
3880
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303881/*
3882 * configures afe with bit width and Sample Rate
3883 */
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303884static int platform_set_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303885 snd_device_t snd_device,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303886 unsigned int bit_width, unsigned int sample_rate)
3887{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303888 int ret = 0;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303889 int backend_idx = DEFAULT_CODEC_BACKEND;
3890 struct platform_data *my_data = (struct platform_data *)adev->platform;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303891
3892 backend_idx = platform_get_backend_index(snd_device);
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303893 ALOGI("%s:becf: afe: bitwidth %d, samplerate %d, backend_idx %d device (%s)",
3894 __func__, bit_width, sample_rate, backend_idx,
3895 platform_get_snd_device_name(snd_device));
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303896
3897 if (bit_width !=
3898 my_data->current_backend_cfg[backend_idx].bit_width) {
3899
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303900 struct mixer_ctl *ctl;
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05303901 ctl = mixer_get_ctl_by_name(adev->mixer,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303902 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303903 if (!ctl) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303904 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3905 __func__,
3906 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303907 return -EINVAL;
3908 }
3909
3910 if (bit_width == 24) {
3911 mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3912 } else {
3913 mixer_ctl_set_enum_by_string(ctl, "S16_LE");
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303914 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303915 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303916 ALOGD("%s:becf: afe: %s mixer set to %d bit", __func__,
3917 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303918 }
3919
3920 /*
3921 * Backend sample rate configuration follows:
3922 * 16 bit playback - 48khz for streams at any valid sample rate
3923 * 24 bit playback - 48khz for stream sample rate less than 48khz
3924 * 24 bit playback - 96khz for sample rate range of 48khz to 96khz
3925 * 24 bit playback - 192khz for sample rate range of 96khz to 192 khz
3926 * Upper limit is inclusive in the sample rate range.
3927 */
3928 // TODO: This has to be more dynamic based on policy file
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303929
3930 if ((sample_rate != my_data->current_backend_cfg[(int)backend_idx].sample_rate) &&
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05303931 (my_data->hifi_audio)) {
3932 /*
3933 * sample rate update is needed only for hifi audio enabled platforms
3934 */
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303935 char *rate_str = NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303936 struct mixer_ctl *ctl;
3937
3938 switch (sample_rate) {
3939 case 8000:
3940 case 11025:
3941 case 16000:
3942 case 22050:
3943 case 32000:
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303944 case 48000:
3945 rate_str = "KHZ_48";
3946 break;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303947 case 44100:
3948 rate_str = "KHZ_44P1";
3949 break;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303950 case 64000:
3951 case 88200:
3952 case 96000:
3953 rate_str = "KHZ_96";
3954 break;
3955 case 176400:
3956 case 192000:
3957 rate_str = "KHZ_192";
3958 break;
3959 default:
3960 rate_str = "KHZ_48";
3961 break;
3962 }
3963
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303964 ctl = mixer_get_ctl_by_name(adev->mixer,
3965 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303966
3967 if (!ctl) {
3968 ALOGE("%s:becf: afe: Could not get ctl to set the Sample Rate for mixer command - %s",
3969 __func__,
3970 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303971 return -EINVAL;
3972 }
3973
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303974 ALOGD("%s:becf: afe: %s set to %s", __func__,
3975 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl,
3976 rate_str);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303977 mixer_ctl_set_enum_by_string(ctl, rate_str);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303978 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303979 }
3980
3981 return ret;
3982}
3983
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303984/*
3985 * goes through all the current usecases and picks the highest
3986 * bitwidth & samplerate
3987 */
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303988static bool platform_check_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303989 struct audio_usecase* usecase,
3990 snd_device_t snd_device,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303991 unsigned int* new_bit_width,
3992 unsigned int* new_sample_rate)
3993{
3994 bool backend_change = false;
3995 struct listnode *node;
3996 struct stream_out *out = NULL;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303997 char value[PROPERTY_VALUE_MAX] = {0};
3998 unsigned int bit_width;
3999 unsigned int sample_rate;
4000 int backend_idx = DEFAULT_CODEC_BACKEND;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304001 struct platform_data *my_data = (struct platform_data *)adev->platform;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304002 int na_mode = platform_get_native_support();
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304003
4004 backend_idx = platform_get_backend_index(snd_device);
4005
4006 bit_width = *new_bit_width;
4007 sample_rate = *new_sample_rate;
4008
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304009 ALOGI("%s:becf: afe: Codec selected backend: %d current bit width: %d and sample rate: %d",
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304010 __func__, backend_idx, bit_width, sample_rate);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304011
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07004012 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4013 // default backend
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304014 // force routing is not required here, caller will do it anyway
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07004015 if ((voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) &&
4016 backend_idx == DEFAULT_CODEC_BACKEND) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304017 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4018 __func__);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304019 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4020 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4021 } else {
4022 /*
4023 * The backend should be configured at highest bit width and/or
4024 * sample rate amongst all playback usecases.
4025 * If the selected sample rate and/or bit width differ with
4026 * current backend sample rate and/or bit width, then, we set the
4027 * backend re-configuration flag.
4028 *
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304029 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304030 */
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304031 int i =0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304032 list_for_each(node, &adev->usecase_list) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304033 struct audio_usecase *uc;
4034 uc = node_to_item(node, struct audio_usecase, list);
4035 struct stream_out *out = (struct stream_out*) uc->stream.out;
4036 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304037
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304038 ALOGD("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4039 "(%d) device %s", __func__, i++, use_case_table[uc->id],
4040 uc->id, out->sample_rate,
4041 out->bit_width,
4042 platform_get_snd_device_name(uc->out_snd_device));
4043
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304044 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304045 if (bit_width < out->bit_width)
4046 bit_width = out->bit_width;
4047 if (sample_rate < out->sample_rate)
4048 sample_rate = out->sample_rate;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304049 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4050 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304051 }
4052 }
4053 }
4054 }
4055
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304056 if (audio_is_true_native_stream_active(adev)) {
Sidipotu Ashokad8fff82016-02-02 10:48:42 +05304057 if (check_hdset_combo_device(snd_device)) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304058 /*
4059 * In true native mode Tasha has a limitation that one port at 44.1 khz
4060 * cannot drive both spkr and hdset, to simiplify the solution lets
4061 * move the AFE to 48khzwhen a ring tone selects combo device.
4062 */
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304063 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304064 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4065 ALOGD("%s:becf: afe: port has to run at 48k for a combo device",
4066 __func__);
4067 } else {
4068 /*
4069 * in single BE mode, if native audio playback
4070 * is active then it will take priority
4071 */
4072 sample_rate = OUTPUT_SAMPLING_RATE_44100;
4073 ALOGD("%s:becf: afe: napb active set rate to 44.1 khz",
4074 __func__);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304075 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304076 }
Ashish Jainb449be32015-07-19 05:39:23 -07004077
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304078
Sidipotu Ashokfdd505a2016-02-11 10:31:38 +05304079
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304080 /*
Sidipotu Ashokfdd505a2016-02-11 10:31:38 +05304081 * hifi playback not supported on spkr devices, limit the Sample Rate
4082 * to 48 khz.
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304083 */
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304084 if (SND_DEVICE_OUT_SPEAKER == snd_device ||
4085 SND_DEVICE_OUT_SPEAKER_WSA == snd_device ||
4086 SND_DEVICE_OUT_SPEAKER_VBAT == snd_device) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304087 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304088 ALOGD("%s:becf: afe: playback on speaker device Configure afe to "
4089 "default Sample Rate(48k)", __func__);
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304090 }
4091
4092 /*
4093 * native playback is not enabled.Configure afe to default Sample Rate(48k)
4094 */
4095 if (NATIVE_AUDIO_MODE_INVALID == na_mode &&
4096 OUTPUT_SAMPLING_RATE_44100 == sample_rate) {
4097 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4098 ALOGD("%s:becf: afe: napb not active - set (48k) default rate",
4099 __func__);
4100 }
4101
Ashish Jainb449be32015-07-19 05:39:23 -07004102 /*
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05304103 * reset the sample rate to default value(48K), if hifi audio is not supported
Ashish Jainb449be32015-07-19 05:39:23 -07004104 */
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05304105 if (!my_data->hifi_audio) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304106 ALOGD("%s:becf: afe: only 48KHZ sample rate is supported "
4107 "Configure afe to default Sample Rate(48k)", __func__);
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05304108 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304109 }
Ashish Jainb449be32015-07-19 05:39:23 -07004110
Manish Dewangan837dc462015-05-27 10:17:41 +05304111 //check if mulitchannel clip needs to be down sampled to 48k
4112 property_get("audio.playback.mch.downsample",value,"");
4113 if (!strncmp("true", value, sizeof("true"))) {
4114 out = usecase->stream.out;
4115 if ((popcount(out->channel_mask) > 2) &&
4116 (out->sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
4117 !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) {
4118 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4119 /* update out sample rate to reflect current backend sample rate */
4120 out->sample_rate = sample_rate;
4121 ALOGD("%s: MCH session defaulting sample rate to %d",
4122 __func__, sample_rate);
4123 }
4124 }
4125
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304126 ALOGI("%s:becf: afe: Codec selected backend: %d updated bit width: %d and sample rate: %d",
4127 __func__,
4128 backend_idx, bit_width, sample_rate);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304129 // Force routing if the expected bitwdith or samplerate
4130 // is not same as current backend comfiguration
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304131 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4132 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate)) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304133 *new_bit_width = bit_width;
4134 *new_sample_rate = sample_rate;
4135 backend_change = true;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304136 ALOGI("%s:becf: afe: Codec backend needs to be updated. new bit width: %d new sample rate: %d",
4137 __func__,
4138 *new_bit_width, *new_sample_rate);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304139 }
4140
4141 return backend_change;
4142}
4143
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004144bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304145 struct audio_usecase *usecase, snd_device_t snd_device)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304146{
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304147 unsigned int new_bit_width;
4148 unsigned int new_sample_rate;
4149 int backend_idx = DEFAULT_CODEC_BACKEND;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304150 int new_snd_devices[SND_DEVICE_OUT_END];
4151 int i, num_devices = 1;
4152 bool ret = false;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304153
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304154 backend_idx = platform_get_backend_index(snd_device);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304155
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304156 new_bit_width = usecase->stream.out->bit_width;
4157 new_sample_rate = usecase->stream.out->sample_rate;
4158
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304159 ALOGI("%s:becf: afe: bitwidth %d, samplerate %d"
4160 ", backend_idx %d usecase = %d device (%s)", __func__, new_bit_width,
4161 new_sample_rate, backend_idx, usecase->id,
4162 platform_get_snd_device_name(snd_device));
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304163
4164 if (!platform_can_split_snd_device(adev->platform, snd_device,
4165 &num_devices, new_snd_devices))
4166 new_snd_devices[0] = snd_device;
4167
4168 for (i = 0; i < num_devices; i++) {
4169 ALOGI("%s: becf: new_snd_devices[%d] is %s", __func__, i,
4170 platform_get_snd_device_name(new_snd_devices[i]));
4171 if (platform_check_codec_backend_cfg(adev, usecase, new_snd_devices[i],
4172 &new_bit_width, &new_sample_rate)) {
4173 platform_set_codec_backend_cfg(adev, new_snd_devices[i],
4174 new_bit_width, new_sample_rate);
4175 ret = true;
4176 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304177 }
4178
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304179 return ret;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304180}
4181
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05304182/*
4183 * configures afe with bit width and Sample Rate
4184 */
4185
4186int platform_set_capture_codec_backend_cfg(struct audio_device* adev,
4187 snd_device_t snd_device,
4188 unsigned int bit_width, unsigned int sample_rate,
4189 audio_format_t format)
4190{
4191 int ret = 0;
4192 int backend_idx = DEFAULT_CODEC_BACKEND;
4193 struct platform_data *my_data = (struct platform_data *)adev->platform;
4194
4195 ALOGI("%s:txbecf: afe: bitwidth %d, samplerate %d, backend_idx %d device (%s)",
4196 __func__, bit_width, sample_rate, backend_idx,
4197 platform_get_snd_device_name(snd_device));
4198
4199 if (bit_width !=
4200 my_data->current_tx_backend_cfg[backend_idx].bit_width) {
4201
4202 struct mixer_ctl *ctl = NULL;
4203 ctl = mixer_get_ctl_by_name(adev->mixer,
4204 my_data->current_tx_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4205 if (!ctl) {
4206 ALOGE("%s:txbecf: afe: Could not get ctl for mixer command - %s",
4207 __func__,
4208 my_data->current_tx_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4209 return -EINVAL;
4210 }
4211
4212 if (bit_width == 24) {
4213 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
4214 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
4215 else
4216 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
4217 } else {
4218 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
4219 }
4220
4221 if (ret < 0) {
4222 ALOGE("%s:txbecf: afe: Could not set ctl for mixer command - %s",
4223 __func__,
4224 my_data->current_tx_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4225 return -EINVAL;
4226 }
4227
4228 my_data->current_tx_backend_cfg[backend_idx].bit_width = bit_width;
4229 ALOGD("%s:txbecf: afe: %s mixer set to %d bit", __func__,
4230 my_data->current_tx_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width);
4231 }
4232
4233 /*
4234 * Backend sample rate configuration follows:
4235 * 16 bit record - 48khz for streams at any valid sample rate
4236 * 24 bit record - 48khz for stream sample rate less than 48khz
4237 * 24 bit record - 96khz for sample rate range of 48khz to 96khz
4238 * 24 bit record - 192khz for sample rate range of 96khz to 192 khz
4239 * Upper limit is inclusive in the sample rate range.
4240 */
4241 // TODO: This has to be more dynamic based on policy file
4242
4243 if (sample_rate != my_data->current_tx_backend_cfg[(int)backend_idx].sample_rate) {
4244 /*
4245 * sample rate update is needed only for hifi audio enabled platforms
4246 */
4247 char *rate_str = NULL;
4248 struct mixer_ctl *ctl = NULL;
4249
4250 switch (sample_rate) {
4251 case 8000:
4252 case 11025:
4253 case 16000:
4254 case 22050:
4255 case 32000:
4256 case 44100:
4257 case 48000:
4258 rate_str = "KHZ_48";
4259 break;
4260 case 64000:
4261 case 88200:
4262 case 96000:
4263 rate_str = "KHZ_96";
4264 break;
4265 case 176400:
4266 case 192000:
4267 rate_str = "KHZ_192";
4268 break;
4269 default:
4270 rate_str = "KHZ_48";
4271 break;
4272 }
4273
4274 ctl = mixer_get_ctl_by_name(adev->mixer,
4275 my_data->current_tx_backend_cfg[backend_idx].samplerate_mixer_ctl);
4276
4277 if (ctl < 0) {
4278 ALOGE("%s:txbecf: afe: Could not get ctl to set the Sample Rate for mixer command - %s",
4279 __func__,
4280 my_data->current_tx_backend_cfg[backend_idx].samplerate_mixer_ctl);
4281 return -EINVAL;
4282 }
4283
4284 ALOGD("%s:txbecf: afe: %s set to %s", __func__,
4285 my_data->current_tx_backend_cfg[backend_idx].samplerate_mixer_ctl,
4286 rate_str);
4287 ret = mixer_ctl_set_enum_by_string(ctl, rate_str);
4288 if (ret < 0) {
4289 ALOGE("%s:txbecf: afe: Could not set ctl for mixer command - %s",
4290 __func__,
4291 my_data->current_tx_backend_cfg[backend_idx].samplerate_mixer_ctl);
4292 return -EINVAL;
4293 }
4294
4295 my_data->current_tx_backend_cfg[backend_idx].sample_rate = sample_rate;
4296 }
4297
4298 return ret;
4299}
4300
4301/*
4302 * goes through all the current usecases and picks the highest
4303 * bitwidth & samplerate
4304 */
4305bool platform_check_capture_codec_backend_cfg(struct audio_device* adev,
4306 unsigned int* new_bit_width,
4307 unsigned int* new_sample_rate)
4308{
4309 bool backend_change = false;
4310 unsigned int bit_width;
4311 unsigned int sample_rate;
4312 int backend_idx = DEFAULT_CODEC_BACKEND;
4313 struct platform_data *my_data = (struct platform_data *)adev->platform;
4314
4315 bit_width = *new_bit_width;
4316 sample_rate = *new_sample_rate;
4317
4318 ALOGI("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
4319 "sample rate: %d",__func__,backend_idx, bit_width, sample_rate);
4320
4321 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4322 // default backend
4323 // force routing is not required here, caller will do it anyway
4324 if ((voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) ||
4325 (!is_external_codec)) {
4326 ALOGW("%s:txbecf: afe:Use default bw and sr for voice/voip calls",
4327 __func__);
4328 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4329 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4330 }
4331
4332 ALOGI("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4333 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4334 // Force routing if the expected bitwdith or samplerate
4335 // is not same as current backend comfiguration
4336 if ((bit_width != my_data->current_tx_backend_cfg[backend_idx].bit_width) ||
4337 (sample_rate != my_data->current_tx_backend_cfg[backend_idx].sample_rate)) {
4338 *new_bit_width = bit_width;
4339 *new_sample_rate = sample_rate;
4340 backend_change = true;
4341 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4342 "new sample rate: %d", __func__, *new_bit_width, *new_sample_rate);
4343 }
4344
4345 return backend_change;
4346}
4347
4348bool platform_check_and_set_capture_codec_backend_cfg(struct audio_device* adev,
4349 struct audio_usecase *usecase, snd_device_t snd_device)
4350{
4351 unsigned int new_bit_width;
4352 unsigned int new_sample_rate;
4353 audio_format_t format = AUDIO_FORMAT_PCM_16_BIT;
4354 int backend_idx = DEFAULT_CODEC_BACKEND;
4355 int ret = 0;
4356
4357 if(usecase->type == PCM_CAPTURE) {
4358 new_sample_rate = usecase->stream.in->sample_rate;
4359 new_bit_width = usecase->stream.in->bit_width;
4360 format = usecase->stream.in->format;
4361 } else {
4362 new_bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4363 new_sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4364 }
4365
4366 ALOGI("%s:txbecf: afe: bitwidth %d, samplerate %d"
4367 ", backend_idx %d usecase = %d device (%s)", __func__, new_bit_width,
4368 new_sample_rate, backend_idx, usecase->id,
4369 platform_get_snd_device_name(snd_device));
4370 if (platform_check_capture_codec_backend_cfg(adev, &new_bit_width,
4371 &new_sample_rate)) {
4372 ret = platform_set_capture_codec_backend_cfg(adev, snd_device,
4373 new_bit_width, new_sample_rate, format);
4374 if(!ret)
4375 return true;
4376 }
4377
4378 return false;
4379}
4380
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304381int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
4382 const char * hw_interface)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304383{
4384 int ret = 0;
4385
4386 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
4387 ALOGE("%s: Invalid snd_device = %d",
4388 __func__, device);
4389 ret = -EINVAL;
4390 goto done;
4391 }
4392
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304393 ALOGD("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
4394 platform_get_snd_device_name(device),
4395 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null",
4396 backend_tag);
4397 if (backend_tag_table[device]) {
4398 free(backend_tag_table[device]);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304399 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304400 backend_tag_table[device] = strdup(backend_tag);
4401
4402 if (hw_interface != NULL) {
4403 if (hw_interface_table[device])
4404 free(hw_interface_table[device]);
4405
4406 ALOGD("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
4407 hw_interface_table[device] = strdup(hw_interface);
4408 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304409done:
4410 return ret;
4411}
4412
4413int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
4414{
4415 int ret = 0;
4416 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
4417 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
4418 ret = -EINVAL;
4419 goto done;
4420 }
4421
4422 if ((type != 0) && (type != 1)) {
4423 ALOGE("%s: invalid usecase type", __func__);
4424 ret = -EINVAL;
4425 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304426 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304427 pcm_device_table[usecase][type] = pcm_id;
4428done:
4429 return ret;
4430}
4431
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07004432void platform_get_device_to_be_id_map(int **device_to_be_id, int *length)
4433{
Alexy Josephb1379942016-01-29 15:49:38 -08004434 *device_to_be_id = (int*) msm_device_to_be_id;
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07004435 *length = msm_be_id_array_len;
4436}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304437int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask, int snd_id)
4438{
4439 int ret = 0;
4440 int channels = audio_channel_count_from_out_mask(channel_mask);
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07004441
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304442 char channel_map[8];
4443 memset(channel_map, 0, sizeof(channel_map));
4444 /* Following are all most common standard WAV channel layouts
4445 overridden by channel mask if its allowed and different */
4446 switch (channels) {
4447 case 1:
4448 /* AUDIO_CHANNEL_OUT_MONO */
4449 channel_map[0] = PCM_CHANNEL_FC;
4450 break;
4451 case 2:
4452 /* AUDIO_CHANNEL_OUT_STEREO */
4453 channel_map[0] = PCM_CHANNEL_FL;
4454 channel_map[1] = PCM_CHANNEL_FR;
4455 break;
4456 case 3:
4457 /* AUDIO_CHANNEL_OUT_2POINT1 */
4458 channel_map[0] = PCM_CHANNEL_FL;
4459 channel_map[1] = PCM_CHANNEL_FR;
4460 channel_map[2] = PCM_CHANNEL_FC;
4461 break;
4462 case 4:
4463 /* AUDIO_CHANNEL_OUT_QUAD_SIDE */
4464 channel_map[0] = PCM_CHANNEL_FL;
4465 channel_map[1] = PCM_CHANNEL_FR;
4466 channel_map[2] = PCM_CHANNEL_LS;
4467 channel_map[3] = PCM_CHANNEL_RS;
4468 if (channel_mask == AUDIO_CHANNEL_OUT_QUAD_BACK)
4469 {
4470 channel_map[2] = PCM_CHANNEL_LB;
4471 channel_map[3] = PCM_CHANNEL_RB;
4472 }
4473 if (channel_mask == AUDIO_CHANNEL_OUT_SURROUND)
4474 {
4475 channel_map[2] = PCM_CHANNEL_FC;
4476 channel_map[3] = PCM_CHANNEL_CS;
4477 }
4478 break;
4479 case 5:
4480 /* AUDIO_CHANNEL_OUT_PENTA */
4481 channel_map[0] = PCM_CHANNEL_FL;
4482 channel_map[1] = PCM_CHANNEL_FR;
4483 channel_map[2] = PCM_CHANNEL_FC;
4484 channel_map[3] = PCM_CHANNEL_LB;
4485 channel_map[4] = PCM_CHANNEL_RB;
4486 break;
4487 case 6:
4488 /* AUDIO_CHANNEL_OUT_5POINT1 */
4489 channel_map[0] = PCM_CHANNEL_FL;
4490 channel_map[1] = PCM_CHANNEL_FR;
4491 channel_map[2] = PCM_CHANNEL_FC;
4492 channel_map[3] = PCM_CHANNEL_LFE;
4493 channel_map[4] = PCM_CHANNEL_LB;
4494 channel_map[5] = PCM_CHANNEL_RB;
4495 if (channel_mask == AUDIO_CHANNEL_OUT_5POINT1_SIDE)
4496 {
4497 channel_map[4] = PCM_CHANNEL_LS;
4498 channel_map[5] = PCM_CHANNEL_RS;
4499 }
4500 break;
4501 case 7:
4502 /* AUDIO_CHANNEL_OUT_6POINT1 */
4503 channel_map[0] = PCM_CHANNEL_FL;
4504 channel_map[1] = PCM_CHANNEL_FR;
4505 channel_map[2] = PCM_CHANNEL_FC;
4506 channel_map[3] = PCM_CHANNEL_LFE;
4507 channel_map[4] = PCM_CHANNEL_LB;
4508 channel_map[5] = PCM_CHANNEL_RB;
4509 channel_map[6] = PCM_CHANNEL_CS;
4510 break;
4511 case 8:
4512 /* AUDIO_CHANNEL_OUT_7POINT1 */
4513 channel_map[0] = PCM_CHANNEL_FL;
4514 channel_map[1] = PCM_CHANNEL_FR;
4515 channel_map[2] = PCM_CHANNEL_FC;
4516 channel_map[3] = PCM_CHANNEL_LFE;
4517 channel_map[4] = PCM_CHANNEL_LB;
4518 channel_map[5] = PCM_CHANNEL_RB;
4519 channel_map[6] = PCM_CHANNEL_LS;
4520 channel_map[7] = PCM_CHANNEL_RS;
4521 break;
4522 default:
4523 ALOGE("unsupported channels %d for setting channel map", channels);
4524 return -1;
4525 }
4526 ret = platform_set_channel_map(platform, channels, channel_map, snd_id);
4527 return ret;
4528}
4529
4530int platform_get_edid_info(void *platform)
4531{
4532 struct platform_data *my_data = (struct platform_data *)platform;
4533 struct audio_device *adev = my_data->adev;
4534 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05304535 int ret, count;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304536
4537 struct mixer_ctl *ctl;
4538 char edid_data[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE + 1] = {0};
4539 edid_audio_info *info;
4540
4541 if (my_data->edid_valid) {
4542 /* use cached edid */
4543 return 0;
4544 }
4545
4546 if (my_data->edid_info == NULL) {
4547 my_data->edid_info =
4548 (struct edid_audio_info *)calloc(1, sizeof(struct edid_audio_info));
4549 }
4550
4551 info = my_data->edid_info;
4552
4553 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
4554 if (!ctl) {
4555 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4556 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
4557 goto fail;
4558 }
4559
4560 mixer_ctl_update(ctl);
4561
4562 count = mixer_ctl_get_num_values(ctl);
4563
4564 /* Read SAD blocks, clamping the maximum size for safety */
4565 if (count > (int)sizeof(block))
4566 count = (int)sizeof(block);
4567
4568 ret = mixer_ctl_get_array(ctl, block, count);
4569 if (ret != 0) {
4570 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
4571 goto fail;
4572 }
4573 edid_data[0] = count;
4574 memcpy(&edid_data[1], block, count);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304575 if (!edid_get_sink_caps(info, edid_data)) {
4576 ALOGE("%s: Failed to get HDMI sink capabilities", __func__);
4577 goto fail;
4578 }
4579 my_data->edid_valid = true;
4580 return 0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304581fail:
4582 if (my_data->edid_info) {
4583 free(my_data->edid_info);
4584 my_data->edid_info = NULL;
4585 my_data->edid_valid = false;
4586 }
4587 ALOGE("%s: return -EINVAL", __func__);
4588 return -EINVAL;
4589}
4590
4591
4592int platform_set_channel_allocation(void *platform, int channel_alloc)
4593{
4594 struct mixer_ctl *ctl;
4595 const char *mixer_ctl_name = "HDMI RX CA";
4596 int ret;
4597 struct platform_data *my_data = (struct platform_data *)platform;
4598 struct audio_device *adev = my_data->adev;
4599
4600 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4601 if (!ctl) {
4602 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4603 __func__, mixer_ctl_name);
4604 ret = EINVAL;
4605 }
4606 ALOGD(":%s channel allocation = 0x%x", __func__, channel_alloc);
4607 ret = mixer_ctl_set_value(ctl, 0, channel_alloc);
4608
4609 if (ret < 0) {
4610 ALOGE("%s: Could not set ctl, error:%d ", __func__, ret);
4611 }
4612
4613 return ret;
4614}
4615
4616int platform_set_channel_map(void *platform, int ch_count, char *ch_map, int snd_id)
4617{
4618 struct mixer_ctl *ctl;
4619 char mixer_ctl_name[44]; // max length of name is 44 as defined
4620 int ret;
4621 unsigned int i;
4622 int set_values[8] = {0};
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304623 struct platform_data *my_data = (struct platform_data *)platform;
4624 struct audio_device *adev = my_data->adev;
4625 ALOGV("%s channel_count:%d",__func__, ch_count);
4626 if (NULL == ch_map) {
4627 ALOGE("%s: Invalid channel mapping used", __func__);
4628 return -EINVAL;
4629 }
Satish Babu Patakokila624cc922015-06-17 21:21:06 +05304630
4631 /*
4632 * If snd_id is greater than 0, stream channel mapping
4633 * If snd_id is below 0, typically -1, device channel mapping
4634 */
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304635 if (snd_id >= 0) {
Satish Babu Patakokila624cc922015-06-17 21:21:06 +05304636 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "Playback Channel Map%d", snd_id);
4637 } else {
4638 strlcpy(mixer_ctl_name, "Playback Device Channel Map", sizeof(mixer_ctl_name));
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304639 }
4640
4641 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
4642
4643 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4644 if (!ctl) {
4645 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4646 __func__, mixer_ctl_name);
4647 return -EINVAL;
4648 }
4649 for (i = 0; i< ARRAY_SIZE(set_values); i++) {
4650 set_values[i] = ch_map[i];
4651 }
4652
4653 ALOGD("%s: set mapping(%d %d %d %d %d %d %d %d) for channel:%d", __func__,
4654 set_values[0], set_values[1], set_values[2], set_values[3], set_values[4],
4655 set_values[5], set_values[6], set_values[7], ch_count);
4656
4657 ret = mixer_ctl_set_array(ctl, set_values, ch_count);
4658 if (ret < 0) {
4659 ALOGE("%s: Could not set ctl, error:%d ch_count:%d",
4660 __func__, ret, ch_count);
4661 }
4662 return ret;
4663}
4664
4665unsigned char platform_map_to_edid_format(int audio_format)
4666{
4667 unsigned char format;
4668 switch (audio_format & AUDIO_FORMAT_MAIN_MASK) {
4669 case AUDIO_FORMAT_AC3:
4670 ALOGV("%s: AC3", __func__);
4671 format = AC3;
4672 break;
4673 case AUDIO_FORMAT_AAC:
4674 ALOGV("%s:AAC", __func__);
4675 format = AAC;
4676 break;
Manish Dewangana6fc5442015-08-24 20:30:31 +05304677 case AUDIO_FORMAT_AAC_ADTS:
4678 ALOGV("%s:AAC_ADTS", __func__);
4679 format = AAC;
4680 break;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304681 case AUDIO_FORMAT_E_AC3:
4682 ALOGV("%s:E_AC3", __func__);
4683 format = DOLBY_DIGITAL_PLUS;
4684 break;
Mingming Yin3a941d42016-02-17 18:08:05 -08004685 case AUDIO_FORMAT_DTS:
4686 ALOGV("%s:DTS", __func__);
4687 format = DTS;
4688 break;
4689 case AUDIO_FORMAT_DTS_HD:
4690 ALOGV("%s:DTS_HD", __func__);
4691 format = DTS_HD;
4692 break;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304693 case AUDIO_FORMAT_PCM_16_BIT:
4694 case AUDIO_FORMAT_PCM_16_BIT_OFFLOAD:
4695 case AUDIO_FORMAT_PCM_24_BIT_OFFLOAD:
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304696 ALOGV("%s:PCM", __func__);
Mingming Yin3a941d42016-02-17 18:08:05 -08004697 format = LPCM;
4698 break;
4699 default:
Mingming Yin3a941d42016-02-17 18:08:05 -08004700 format = -1;
Naresh Tanniru20e8b022016-04-28 16:54:17 +05304701 ALOGE("%s:invalid format:%d", __func__,format);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304702 break;
4703 }
4704 return format;
4705}
4706
4707uint32_t platform_get_compress_passthrough_buffer_size(
4708 audio_offload_info_t* info)
4709{
4710 uint32_t fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
4711 if (!info->has_video)
4712 fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
4713
4714 return fragment_size;
4715}
4716
4717void platform_reset_edid_info(void *platform) {
4718
4719 ALOGV("%s:", __func__);
4720 struct platform_data *my_data = (struct platform_data *)platform;
4721 if (my_data->edid_info) {
4722 ALOGV("%s :free edid", __func__);
4723 free(my_data->edid_info);
4724 my_data->edid_info = NULL;
4725 }
4726}
4727
4728bool platform_is_edid_supported_format(void *platform, int format)
4729{
4730 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304731 edid_audio_info *info = NULL;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05304732 int i, ret;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304733 unsigned char format_id = platform_map_to_edid_format(format);
4734
Mingming Yin3a941d42016-02-17 18:08:05 -08004735 if (format_id <= 0) {
4736 ALOGE("%s invalid edid format mappting for :%x" ,__func__, format);
4737 return false;
4738 }
4739
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304740 ret = platform_get_edid_info(platform);
4741 info = (edid_audio_info *)my_data->edid_info;
4742 if (ret == 0 && info != NULL) {
4743 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
4744 /*
4745 * To check
4746 * is there any special for CONFIG_HDMI_PASSTHROUGH_CONVERT
4747 * & DOLBY_DIGITAL_PLUS
4748 */
4749 if (info->audio_blocks_array[i].format_id == format_id) {
Mingming Yin3a941d42016-02-17 18:08:05 -08004750 ALOGV("%s:returns true %x",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304751 __func__, format);
4752 return true;
4753 }
4754 }
4755 }
Mingming Yin3a941d42016-02-17 18:08:05 -08004756 ALOGV("%s:returns false %x",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304757 __func__, format);
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07004758 return false;
4759}
4760
Mingming Yin3a941d42016-02-17 18:08:05 -08004761bool platform_is_edid_supported_sample_rate(void *platform, int sample_rate)
4762{
4763 struct platform_data *my_data = (struct platform_data *)platform;
Mingming Yin3a941d42016-02-17 18:08:05 -08004764 edid_audio_info *info = NULL;
Naresh Tanniru20e8b022016-04-28 16:54:17 +05304765 int i, ret;
Mingming Yin3a941d42016-02-17 18:08:05 -08004766
4767 ret = platform_get_edid_info(platform);
4768 info = (edid_audio_info *)my_data->edid_info;
4769 if (ret == 0 && info != NULL) {
4770 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
4771 /*
4772 * To check
4773 * is there any special for CONFIG_HDMI_PASSTHROUGH_CONVERT
4774 * & DOLBY_DIGITAL_PLUS
4775 */
4776 if (info->audio_blocks_array[i].sampling_freq == sample_rate) {
4777 ALOGV("%s: returns true %d", __func__, sample_rate);
4778 return true;
4779 }
4780 }
4781 }
4782 ALOGV("%s: returns false %d", __func__, sample_rate);
4783
4784 return false;
4785}
4786
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304787int platform_set_edid_channels_configuration(void *platform, int channels) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004788
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304789 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304790 edid_audio_info *info = NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304791 int channel_count = 2;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05304792 int i, ret;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304793 char default_channelMap[MAX_CHANNELS_SUPPORTED] = {0};
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004794
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304795 ret = platform_get_edid_info(platform);
4796 info = (edid_audio_info *)my_data->edid_info;
4797 if(ret == 0 && info != NULL) {
4798 if (channels > 2) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004799
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304800 ALOGV("%s:able to get HDMI sink capabilities multi channel playback",
4801 __func__);
4802 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
4803 if (info->audio_blocks_array[i].format_id == LPCM &&
4804 info->audio_blocks_array[i].channels > channel_count &&
4805 info->audio_blocks_array[i].channels <= MAX_HDMI_CHANNEL_CNT) {
4806 channel_count = info->audio_blocks_array[i].channels;
4807 }
4808 }
4809 ALOGV("%s:channel_count:%d", __func__, channel_count);
4810 /*
4811 * Channel map is set for supported hdmi max channel count even
4812 * though the input channel count set on adm is less than or equal to
4813 * max supported channel count
4814 */
4815 platform_set_channel_map(platform, channel_count, info->channel_map, -1);
4816 platform_set_channel_allocation(platform, info->channel_allocation);
4817 } else {
4818 default_channelMap[0] = PCM_CHANNEL_FL;
4819 default_channelMap[1] = PCM_CHANNEL_FR;
4820 platform_set_channel_map(platform,2,default_channelMap,-1);
4821 platform_set_channel_allocation(platform,0);
4822 }
4823 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004824
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004825 return 0;
4826}
4827
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304828void platform_cache_edid(void * platform)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004829{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304830 platform_get_edid_info(platform);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004831}
4832
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304833void platform_invalidate_edid(void * platform)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004834{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304835 struct platform_data *my_data = (struct platform_data *)platform;
4836 my_data->edid_valid = false;
4837 if (my_data->edid_info) {
4838 memset(my_data->edid_info, 0, sizeof(struct edid_audio_info));
4839 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004840}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304841
4842int platform_set_mixer_control(struct stream_out *out, const char * mixer_ctl_name,
4843 const char *mixer_val)
4844{
4845 struct audio_device *adev = out->dev;
4846 struct mixer_ctl *ctl = NULL;
4847 ALOGD("setting mixer ctl %s with value %s", mixer_ctl_name, mixer_val);
4848 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4849 if (!ctl) {
4850 ALOGE("%s: could not get ctl for mixer cmd - %s",
4851 __func__, mixer_ctl_name);
4852 return -EINVAL;
4853 }
4854
4855 return mixer_ctl_set_enum_by_string(ctl, mixer_val);
4856}
4857
Naresh Tanniru20e8b022016-04-28 16:54:17 +05304858static int set_mixer_control(struct mixer *mixer,
4859 const char * mixer_ctl_name,
4860 const char *mixer_val)
4861{
4862 struct mixer_ctl *ctl;
4863 ALOGD("setting mixer ctl %s with value %s", mixer_ctl_name, mixer_val);
4864 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
4865 if (!ctl) {
4866 ALOGE("%s: could not get ctl for mixer cmd - %s",
4867 __func__, mixer_ctl_name);
4868 return -EINVAL;
4869 }
4870
4871 return mixer_ctl_set_enum_by_string(ctl, mixer_val);
4872}
4873
Mingming Yin21854652016-04-13 11:54:02 -07004874int platform_set_hdmi_config(void *platform, uint32_t channel_count,
4875 uint32_t sample_rate, bool enable_passthrough)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304876{
Mingming Yin21854652016-04-13 11:54:02 -07004877 struct platform_data *my_data = (struct platform_data *)platform;
4878 struct audio_device *adev = my_data->adev;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304879 const char *hdmi_format_ctrl = "HDMI RX Format";
Mingming Yin21854652016-04-13 11:54:02 -07004880 const char *hdmi_rate_ctrl = "HDMI_RX SampleRate";
4881 const char *hdmi_chans_ctrl = "HDMI_RX Channels";
4882 const char *channel_cnt_str = NULL;
4883
4884 ALOGI("%s ch[%d] sr[%d], pthru[%d]", __func__,
4885 channel_count, sample_rate, enable_passthrough);
4886
4887 switch (channel_count) {
4888 case 8:
4889 channel_cnt_str = "Eight"; break;
4890 case 7:
4891 channel_cnt_str = "Seven"; break;
4892 case 6:
4893 channel_cnt_str = "Six"; break;
4894 case 5:
4895 channel_cnt_str = "Five"; break;
4896 case 4:
4897 channel_cnt_str = "Four"; break;
4898 case 3:
4899 channel_cnt_str = "Three"; break;
4900 default:
4901 channel_cnt_str = "Two"; break;
4902 }
4903 ALOGV("%s: HDMI channel count: %s", __func__, channel_cnt_str);
4904 set_mixer_control(adev->mixer, hdmi_chans_ctrl, channel_cnt_str);
4905
4906 if (enable_passthrough) {
4907 ALOGD("%s:HDMI compress format", __func__);
4908 set_mixer_control(adev->mixer, hdmi_format_ctrl, "Compr");
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304909 } else {
Mingming Yin21854652016-04-13 11:54:02 -07004910 ALOGD("%s: HDMI PCM format", __func__);
4911 set_mixer_control(adev->mixer, hdmi_format_ctrl, "LPCM");
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304912 }
4913
Mingming Yin21854652016-04-13 11:54:02 -07004914 switch (sample_rate) {
4915 case 32000:
4916 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_32");
4917 break;
4918 case 44100:
4919 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_44P1");
4920 break;
4921 case 96000:
4922 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_96");
4923 break;
4924 case 128000:
4925 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_128");
4926 break;
4927 case 176400:
4928 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_176_4");
4929 break;
4930 case 192000:
4931 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_192");
4932 break;
4933 default:
4934 case 48000:
4935 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_48");
4936 break;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304937 }
4938
4939 return 0;
4940}
4941
Mingming Yin21854652016-04-13 11:54:02 -07004942
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304943int platform_set_device_params(struct stream_out *out, int param, int value)
4944{
4945 struct audio_device *adev = out->dev;
4946 struct mixer_ctl *ctl;
4947 char *mixer_ctl_name = "Device PP Params";
4948 int ret = 0;
4949 uint32_t set_values[] = {0,0};
4950
4951 set_values[0] = param;
4952 set_values[1] = value;
4953
4954 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4955 if (!ctl) {
4956 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4957 __func__, mixer_ctl_name);
4958 ret = -EINVAL;
4959 goto end;
4960 }
4961
4962 ALOGV("%s: Setting device pp params param: %d, value %d mixer ctrl:%s",
4963 __func__,param, value, mixer_ctl_name);
4964 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
4965
4966end:
4967 return ret;
4968}
4969
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05304970int platform_get_subsys_image_name(char *buf)
4971{
4972 strlcpy(buf, PLATFORM_IMAGE_NAME, sizeof(PLATFORM_IMAGE_NAME));
4973 return 0;
4974}
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08004975
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304976/*
4977 * This is a lookup table to map android audio input device to audio h/w interface (backend).
4978 * The table can be extended for other input devices by adding appropriate entries.
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304979 * The audio interface for a particular input device need to be added in
4980 * audio_platform_info.xml file.
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304981 */
4982struct audio_device_to_audio_interface audio_device_to_interface_table[] = {
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304983 {AUDIO_DEVICE_IN_BUILTIN_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC), ""},
4984 {AUDIO_DEVICE_IN_BACK_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BACK_MIC), ""},
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304985};
4986
4987int audio_device_to_interface_table_len =
4988 sizeof(audio_device_to_interface_table) / sizeof(audio_device_to_interface_table[0]);
4989
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304990int platform_set_audio_device_interface(const char * device_name,
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304991 const char *intf_name,
4992 const char *codec_type)
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08004993{
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304994 int ret = 0;
4995 int i;
4996
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304997 if (device_name == NULL || intf_name == NULL || codec_type == NULL) {
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304998 ALOGE("%s: Invalid input", __func__);
4999
5000 ret = -EINVAL;
5001 goto done;
5002 }
5003
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05305004 ALOGD("%s: Enter, device name:%s, intf name:%s, codec_type:%s", __func__,
5005 device_name, intf_name, codec_type);
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305006
5007 size_t device_name_len = strlen(device_name);
5008 for (i = 0; i < audio_device_to_interface_table_len; i++) {
5009 char* name = audio_device_to_interface_table[i].device_name;
5010 size_t name_len = strlen(name);
5011 if ((name_len == device_name_len) &&
5012 (strncmp(device_name, name, name_len) == 0)) {
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05305013 if (is_external_codec &&
5014 (strncmp(codec_type, "external", strlen(codec_type)) == 0)) {
5015 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305016 __func__, device_name, intf_name);
5017
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05305018 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305019 sizeof(audio_device_to_interface_table[i].interface_name));
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05305020 } else if (!is_external_codec &&
5021 (strncmp(codec_type, "internal", strlen(codec_type)) == 0)) {
5022 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
5023 __func__, device_name, intf_name);
5024
5025 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
5026 sizeof(audio_device_to_interface_table[i].interface_name));
5027 } else
5028 ALOGE("Invalid codec_type specified. Ignoring this interface entry.");
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305029 goto done;
5030 }
5031 }
5032 ALOGE("%s: Could not find matching device name %s",
5033 __func__, device_name);
5034
5035 ret = -EINVAL;
5036
5037done:
5038 return ret;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08005039}
Laxminath Kasam82252432015-05-29 18:37:11 +05305040
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05305041 /*
Laxminath Kasam44f49402015-05-29 18:37:11 +05305042 * This is a lookup table to map names of speaker device with respective left and right TZ names.
5043 * Also the tz names for a particular left or right speaker can be overriden by adding
5044 * corresponding entry in audio_platform_info.xml file.
5045 */
5046struct speaker_device_to_tz_names speaker_device_tz_names = {
Alexy Josephb1379942016-01-29 15:49:38 -08005047 SND_DEVICE_OUT_SPEAKER, "", ""
Laxminath Kasam44f49402015-05-29 18:37:11 +05305048};
5049
5050const char *platform_get_spkr_1_tz_name(snd_device_t snd_device)
Asish Bhattacharya4a69acd2015-07-12 20:54:14 +05305051{
Laxminath Kasam44f49402015-05-29 18:37:11 +05305052 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
5053 return speaker_device_tz_names.spkr_1_tz_name;
5054 else
5055 return "";
5056}
5057
5058const char *platform_get_spkr_2_tz_name(snd_device_t snd_device)
5059{
5060 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
5061 return speaker_device_tz_names.spkr_2_tz_name;
5062 else
5063 return "";
5064}
5065
5066int platform_set_spkr_device_tz_names(snd_device_t index,
5067 const char *spkr_1_tz_name, const char *spkr_2_tz_name)
5068{
5069 int ret = 0;
Laxminath Kasam44f49402015-05-29 18:37:11 +05305070
5071 if (spkr_1_tz_name == NULL && spkr_2_tz_name == NULL) {
5072 ALOGE("%s: Invalid input", __func__);
5073 ret = -EINVAL;
5074 goto done;
5075 }
5076 if (index != speaker_device_tz_names.snd_device) {
Alexy Josephb1379942016-01-29 15:49:38 -08005077 ALOGE("%s: not matching speaker device\n", __func__);
Laxminath Kasam44f49402015-05-29 18:37:11 +05305078 ret = -EINVAL;
5079 goto done;
5080 }
5081 ALOGD("%s: Enter, spkr_1_tz_name :%s, spkr_2_tz_name:%s",
5082 __func__, spkr_1_tz_name, spkr_2_tz_name);
5083
5084 if (spkr_1_tz_name != NULL)
5085 strlcpy(speaker_device_tz_names.spkr_1_tz_name, spkr_1_tz_name,
5086 sizeof(speaker_device_tz_names.spkr_1_tz_name));
5087
5088 if (spkr_2_tz_name != NULL)
5089 strlcpy(speaker_device_tz_names.spkr_2_tz_name, spkr_2_tz_name,
5090 sizeof(speaker_device_tz_names.spkr_2_tz_name));
5091done:
5092 return ret;
Asish Bhattacharya4a69acd2015-07-12 20:54:14 +05305093}
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05305094
Venkata Narendra Kumar Gutta7f4817f2016-01-29 14:15:53 +05305095int platform_spkr_prot_is_wsa_analog_mode(void *adev)
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05305096{
5097 struct audio_device *adev_h = adev;
Alexy Josephb1379942016-01-29 15:49:38 -08005098 const char *snd_card_name;
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05305099
Venkata Narendra Kumar Gutta7f4817f2016-01-29 14:15:53 +05305100 /*
5101 * wsa analog mode is decided based on the sound card name
5102 */
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05305103 snd_card_name = mixer_get_name(adev_h->mixer);
5104 if ((!strcmp(snd_card_name, "msm8952-skum-snd-card")) ||
5105 (!strcmp(snd_card_name, "msm8952-snd-card")) ||
5106 (!strcmp(snd_card_name, "msm8952-snd-card-mtp")) ||
Venkata Narendra Kumar Gutta7f4817f2016-01-29 14:15:53 +05305107 (!strcmp(snd_card_name, "msm8976-skun-snd-card")) ||
5108 (!strcmp(snd_card_name, "msm8953-snd-card-mtp")))
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05305109 return 1;
5110 else
5111 return 0;
5112}
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05305113
5114bool platform_send_gain_dep_cal(void *platform __unused,
5115 int level __unused)
5116{
5117 return 0;
5118}
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08005119
5120bool platform_can_enable_spkr_prot_on_device(snd_device_t snd_device)
5121{
5122 bool ret = false;
5123
5124 if (snd_device == SND_DEVICE_OUT_SPEAKER ||
5125 snd_device == SND_DEVICE_OUT_SPEAKER_WSA ||
5126 snd_device == SND_DEVICE_OUT_SPEAKER_VBAT ||
5127 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
5128 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
5129 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_WSA) {
5130 ret = true;
5131 }
5132
5133 return ret;
5134}
5135
5136int platform_get_spkr_prot_acdb_id(snd_device_t snd_device)
5137{
5138 int acdb_id;
5139
5140 switch(snd_device) {
5141 case SND_DEVICE_OUT_SPEAKER:
5142 case SND_DEVICE_OUT_SPEAKER_WSA:
5143 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
5144 break;
5145 case SND_DEVICE_OUT_VOICE_SPEAKER:
5146 case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
5147 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
5148 break;
5149 case SND_DEVICE_OUT_SPEAKER_VBAT:
5150 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT);
5151 break;
5152 case SND_DEVICE_OUT_VOICE_SPEAKER_VBAT:
5153 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT);
5154 break;
5155 default:
5156 acdb_id = -EINVAL;
5157 break;
5158 }
5159 return acdb_id;
5160}
5161
5162int platform_get_spkr_prot_snd_device(snd_device_t snd_device)
5163{
5164 if (!audio_extn_spkr_prot_is_enabled())
5165 return snd_device;
5166
5167 switch(snd_device) {
5168 case SND_DEVICE_OUT_SPEAKER:
5169 case SND_DEVICE_OUT_SPEAKER_WSA:
5170 return SND_DEVICE_OUT_SPEAKER_PROTECTED;
5171 case SND_DEVICE_OUT_VOICE_SPEAKER:
5172 case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
5173 return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
5174 case SND_DEVICE_OUT_SPEAKER_VBAT:
5175 return SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT;
5176 case SND_DEVICE_OUT_VOICE_SPEAKER_VBAT:
5177 return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT;
5178 default:
5179 return snd_device;
5180 }
5181}