blob: b39b6687c44ee83487af7b3ef124f8e22ddbfa84 [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;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530262 int source_mic_type;
263 int max_mic_count;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530264};
265
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530266static bool is_external_codec = false;
267static const int pcm_device_table_of_ext_codec[AUDIO_USECASE_MAX][2] = {
Venkata Narendra Kumar Gutta0d293362015-12-18 15:52:27 +0530268 [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 +0530269};
270
271/* 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 +0530272static const int misc_usecase[AUDIO_USECASE_MAX] = { USECASE_QCHAT_CALL };
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530273
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530274int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530275 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
276 DEEP_BUFFER_PCM_DEVICE},
277 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
278 LOWLATENCY_PCM_DEVICE},
279 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
280 MULTIMEDIA2_PCM_DEVICE},
281 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
282 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
Dhananjay Kumara68d7af2015-05-25 19:11:30 +0530283 /* Below entries are initialized with invalid values
284 * Valid values should be updated from fnc platform_info_init()
285 * based on pcm ids defined in audio_platform_info.xml.
286 */
287 [USECASE_AUDIO_PLAYBACK_OFFLOAD2] = {-1, -1},
288 [USECASE_AUDIO_PLAYBACK_OFFLOAD3] = {-1, -1},
289 [USECASE_AUDIO_PLAYBACK_OFFLOAD4] = {-1, -1},
290 [USECASE_AUDIO_PLAYBACK_OFFLOAD5] = {-1, -1},
291 [USECASE_AUDIO_PLAYBACK_OFFLOAD6] = {-1, -1},
292 [USECASE_AUDIO_PLAYBACK_OFFLOAD7] = {-1, -1},
293 [USECASE_AUDIO_PLAYBACK_OFFLOAD8] = {-1, -1},
294 [USECASE_AUDIO_PLAYBACK_OFFLOAD9] = {-1, -1},
Naresh Tanniru3a7dbe72015-06-25 20:08:01 -0700295 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE, MULTIMEDIA3_PCM_DEVICE},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530296 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
297 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
298 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
299 LOWLATENCY_PCM_DEVICE},
300 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
301 MULTIMEDIA2_PCM_DEVICE},
302 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
303 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
304 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
305 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
306 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
307 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
308 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Karthik Reddy Katta3b0a60c2014-04-06 14:52:37 +0530309 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Venkata Narendra Kumar Gutta0d293362015-12-18 15:52:27 +0530310 [USECASE_VOICEMMODE1_CALL] = {-1, -1}, /* pcm ids updated from platform info file */
311 [USECASE_VOICEMMODE2_CALL] = {-1, -1}, /* pcm ids updated from platform info file */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530312 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
313 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
314 AUDIO_RECORD_PCM_DEVICE},
315 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
316 AUDIO_RECORD_PCM_DEVICE},
317 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
318 AUDIO_RECORD_PCM_DEVICE},
319 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
320 COMPRESS_CAPTURE_DEVICE},
321 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
322 COMPRESS_CAPTURE_DEVICE},
323 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
324 COMPRESS_CAPTURE_DEVICE},
325 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
326 INCALL_MUSIC_UPLINK_PCM_DEVICE},
327 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
328 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
329 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
330 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530331 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
332 AFE_PROXY_RECORD_PCM_DEVICE},
333 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
334 AFE_PROXY_RECORD_PCM_DEVICE},
Naresh Tannirue3b18452014-03-04 14:44:27 +0530335};
336
337/* Array to store sound devices */
338static const char * const device_table[SND_DEVICE_MAX] = {
339 [SND_DEVICE_NONE] = "none",
340 /* Playback sound devices */
341 [SND_DEVICE_OUT_HANDSET] = "handset",
342 [SND_DEVICE_OUT_SPEAKER] = "speaker",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530343 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = "speaker-ext-1",
344 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = "speaker-ext-2",
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530345 [SND_DEVICE_OUT_SPEAKER_WSA] = "wsa-speaker",
Venkata Narendra Kumar Gutta55def542015-06-16 13:59:08 +0530346 [SND_DEVICE_OUT_SPEAKER_VBAT] = "vbat-speaker",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530347 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
348 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530349 [SND_DEVICE_OUT_HEADPHONES_44_1] = "headphones-44.1",
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530350 [SND_DEVICE_OUT_LINE] = "line",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530351 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530352 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530353 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = "speaker-and-headphones-ext-1",
354 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = "speaker-and-headphones-ext-2",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530355 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
356 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530357 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = "wsa-voice-speaker",
Venkata Narendra Kumar Gutta55def542015-06-16 13:59:08 +0530358 [SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = "vbat-voice-speaker",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530359 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530360 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530361 [SND_DEVICE_OUT_HDMI] = "hdmi",
362 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
363 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530364 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530365 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
366 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
367 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530368 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530369 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
370 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
371 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
372 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
373 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
374 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
375 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
376 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
377 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
378 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
379 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530380 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Banajit Goswami20cdd212015-09-11 01:11:30 -0700381 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT] = "speaker-protected-vbat",
382 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT] = "voice-speaker-protected-vbat",
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530383#ifdef RECORD_PLAY_CONCURRENCY
384 [SND_DEVICE_OUT_VOIP_HANDSET] = "voip-handset",
385 [SND_DEVICE_OUT_VOIP_SPEAKER] = "voip-speaker",
386 [SND_DEVICE_OUT_VOIP_HEADPHONES] = "voip-headphones",
387#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +0530388
389 /* Capture sound devices */
390 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530391 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = "handset-mic-ext",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530392 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530393 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
394 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
395 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
396 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
397 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
398 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
399 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
400 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
401 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
402 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
403 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
404 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
405 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
406 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
407 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
408 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530409 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
410 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
411 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
412 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700413 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530414 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700415 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530416 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530417 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
418 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
419 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530420 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
421 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
422 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
423 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530424 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
425 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
426 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530427 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530428 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
429 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
430 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
431 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
432 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
433 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
434 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530435 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside",
436 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside",
437 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside",
438 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside",
439 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside",
Sidipotu Ashok3bcca232014-11-07 14:41:58 +0530440 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = "aanc-fluence-dmic-handset",
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530441 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
442 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = "quad-mic",
443 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
444 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
Shiv Maliyappanahalli5a10aea2015-07-02 10:36:23 -0700445 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530446 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +0530447 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
448 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "voice-rec-dmic-ef",
449 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "three-mic",
450 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "quad-mic",
451 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "headset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530452};
453
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530454// Platform specific backend bit width table
455static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
456
Naresh Tannirue3b18452014-03-04 14:44:27 +0530457/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530458static int acdb_device_table[SND_DEVICE_MAX] = {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530459 [SND_DEVICE_NONE] = -1,
460 [SND_DEVICE_OUT_HANDSET] = 7,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530461 [SND_DEVICE_OUT_SPEAKER] = 14,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530462 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = 14,
463 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = 14,
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530464 [SND_DEVICE_OUT_SPEAKER_WSA] = 135,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700465 [SND_DEVICE_OUT_SPEAKER_VBAT] = 135,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530466 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530467 [SND_DEVICE_OUT_LINE] = 10,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530468 [SND_DEVICE_OUT_HEADPHONES] = 10,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530469 [SND_DEVICE_OUT_HEADPHONES_44_1] = 10,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530470 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530471 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 10,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530472 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = 10,
473 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = 10,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530474 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530475 [SND_DEVICE_OUT_VOICE_LINE] = 10,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530476 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530477 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = 135,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700478 [SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = 135,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530479 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
480 [SND_DEVICE_OUT_HDMI] = 18,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530481 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530482 [SND_DEVICE_OUT_BT_SCO] = 22,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530483 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530484 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
485 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
486 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530487 [SND_DEVICE_OUT_VOICE_TX] = 45,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530488 [SND_DEVICE_OUT_AFE_PROXY] = 0,
489 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530490 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530491 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
492 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
493 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
494 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
495 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
496 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
497 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530498 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
499 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700500 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT] = 124,
501 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT] = 101,
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530502#ifdef RECORD_PLAY_CONCURRENCY
503 [SND_DEVICE_OUT_VOIP_HANDSET] = 133,
504 [SND_DEVICE_OUT_VOIP_SPEAKER] = 132,
505 [SND_DEVICE_OUT_VOIP_HEADPHONES] = 134,
506#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +0530507
508 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530509 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530510 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
511 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
512 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
513 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
514 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
515 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
516 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
517 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
518 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
519 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
520 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
521 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
522 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
523 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
524 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530525 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530526 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530527 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
528 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
529 [SND_DEVICE_IN_HDMI_MIC] = 4,
530 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700531 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 122,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530532 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700533 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 123,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530534 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
535 [SND_DEVICE_IN_VOICE_DMIC] = 41,
536 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
537 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530538 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
539 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
540 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530541 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
542 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
543 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
544 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530545 [SND_DEVICE_IN_VOICE_RX] = 44,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530546 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
547 [SND_DEVICE_IN_CAPTURE_FM] = 0,
548 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
549 [SND_DEVICE_IN_QUAD_MIC] = 46,
550 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
551 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
552 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530553 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12,
554 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12,
555 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
556 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
557 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
Venkata Narendra Kumar Gutta9bb5af62015-06-05 11:53:06 +0530558 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = 105,
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530559 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
560 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = 126,
561 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 127,
562 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530563 [SND_DEVICE_IN_THREE_MIC] = 46, /* for APSS Surround Sound Recording */
564 [SND_DEVICE_IN_HANDSET_TMIC] = 125, /* for 3mic recording with fluence */
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +0530565 [SND_DEVICE_IN_UNPROCESSED_MIC] = 143,
566 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 144,
567 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 145,
568 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 146,
569 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = 147,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530570};
571
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530572struct name_to_index {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530573 char name[100];
574 unsigned int index;
575};
Naresh Tannirue3b18452014-03-04 14:44:27 +0530576
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530577#define TO_NAME_INDEX(X) #X, X
Naresh Tannirue3b18452014-03-04 14:44:27 +0530578
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530579/* Used to get index from parsed sting */
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530580static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530581 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
582 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530583 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_1)},
584 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_2)},
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530585 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA)},
Banajit Goswami20cdd212015-09-11 01:11:30 -0700586 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_VBAT)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530587 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
588 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +0530589 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_44_1)},
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530590 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530591 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530592 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530593 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1)},
594 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530595 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
596 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530597 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_WSA)},
Banajit Goswami20cdd212015-09-11 01:11:30 -0700598 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_VBAT)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530599 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Naresh Tanniru9c4ba542015-11-06 18:01:09 +0530600 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530601 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
602 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
603 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
604 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
605 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
606 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
607 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530608 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TX)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530609 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
610 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
611 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
612 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
613 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
614 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
615 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
616 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
617 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
618 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
619 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530620 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Banajit Goswami20cdd212015-09-11 01:11:30 -0700621 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT)},
622 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT)},
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530623#ifdef RECORD_PLAY_CONCURRENCY
624 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HANDSET)},
625 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_SPEAKER)},
626 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HEADPHONES)},
627#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530628 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530629 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530630 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
631 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
632 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
633 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
634 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
635 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
636 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
637 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
638 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
639 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
640 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
641 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
642 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
643 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
644 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
645 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
646 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
647 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
648 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
649 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
650 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700651 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530652 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700653 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530654 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
655 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
656 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
657 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
658 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
659 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
660 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
661 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
662 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
663 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
664 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530665 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RX)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530666 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
667 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
668 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
669 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
670 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
671 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
672 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Sidipotu Ashok3bcca232014-11-07 14:41:58 +0530673 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530674 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE)},
675 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE)},
676 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE)},
677 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE)},
678 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)},
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530679 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
680 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC)},
681 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
682 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530683 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
684 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +0530685 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
686 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
687 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
688 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
689 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530690};
691
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530692static char * backend_tag_table[SND_DEVICE_MAX] = {0};
693static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530694
695static struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
696 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
697 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
698 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
699 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530700 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD2)},
701 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD3)},
702 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD4)},
703 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD5)},
704 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD6)},
705 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD7)},
706 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD8)},
707 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD9)},
Naresh Tanniru3a7dbe72015-06-25 20:08:01 -0700708 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530709 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
710 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
711 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
712 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
713 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
714 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
715 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
Avinash Vaish306e6072015-05-13 16:58:18 +0530716 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
717 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530718 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
719 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
720 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
721 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Xiaojun Sangb112f882015-08-03 19:38:28 +0800722 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530723};
724
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700725#define NO_COLS 2
726static int msm_be_id_array_len;
727static int (*msm_device_to_be_id)[];
728
729/* Below table lists output device to BE_ID mapping*/
730/* Update the table based on the board configuration*/
731
732static int msm_device_to_be_id_internal_codec [][NO_COLS] = {
733 {AUDIO_DEVICE_OUT_EARPIECE , 34},
734 {AUDIO_DEVICE_OUT_SPEAKER , 34},
735 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 34},
736 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 34},
737 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
738 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
739 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
740 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
741 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
742 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
743 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
744 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
745 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
746 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
747 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
748 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
749 {AUDIO_DEVICE_OUT_PROXY , 9},
750 {AUDIO_DEVICE_OUT_FM , 7},
751 {AUDIO_DEVICE_OUT_FM_TX , 8},
752 {AUDIO_DEVICE_OUT_ALL , -1},
753 {AUDIO_DEVICE_NONE , -1},
754 {AUDIO_DEVICE_OUT_DEFAULT , -1},
755};
756
757static int msm_device_to_be_id_external_codec [][NO_COLS] = {
758 {AUDIO_DEVICE_OUT_EARPIECE , 2},
759 {AUDIO_DEVICE_OUT_SPEAKER , 2},
760 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
761 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
762 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
763 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
764 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
765 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
766 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
767 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
768 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
769 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
770 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
771 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
772 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
773 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
774 {AUDIO_DEVICE_OUT_PROXY , 9},
775 {AUDIO_DEVICE_OUT_FM , 7},
776 {AUDIO_DEVICE_OUT_FM_TX , 8},
777 {AUDIO_DEVICE_OUT_ALL , -1},
778 {AUDIO_DEVICE_NONE , -1},
779 {AUDIO_DEVICE_OUT_DEFAULT , -1},
780};
781
782
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530783#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
Ashish Jain5106d362016-05-11 19:23:33 +0530784#define PCM_OFFLOAD_PLATFORM_DELAY (30*1000LL)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530785#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530786
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530787static bool is_misc_usecase(audio_usecase_t usecase) {
788 bool ret = false;
789 int i;
790
791 for (i = 0; i < AUDIO_USECASE_MAX; i++) {
792 if(usecase == misc_usecase[i]) {
793 ret = true;
794 break;
795 }
796 }
797 return ret;
798}
799
800
801static void update_codec_type(const char *snd_card_name) {
802
803 if (!strncmp(snd_card_name, "msm8939-tapan-snd-card",
804 sizeof("msm8939-tapan-snd-card")) ||
805 !strncmp(snd_card_name, "msm8939-tapan9302-snd-card",
Avinash Vaish306e6072015-05-13 16:58:18 +0530806 sizeof("msm8939-tapan9302-snd-card")) ||
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530807 !strncmp(snd_card_name, "msm8939-tomtom9330-snd-card",
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530808 sizeof("msm8939-tomtom9330-snd-card")) ||
809 !strncmp(snd_card_name, "msm8952-tomtom-snd-card",
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +0530810 sizeof("msm8952-tomtom-snd-card")) ||
Xiaojun Sang9cd237a2015-11-20 15:30:18 +0800811 !strncmp(snd_card_name, "msm8953-sku3-tasha-snd-card",
812 sizeof("msm8953-sku3-tasha-snd-card")) ||
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +0530813 !strncmp(snd_card_name, "msm8952-tasha-snd-card",
814 sizeof("msm8952-tasha-snd-card")) ||
815 !strncmp(snd_card_name, "msm8952-tashalite-snd-card",
816 sizeof("msm8952-tashalite-snd-card")) ||
817 !strncmp(snd_card_name, "msm8952-tasha-skun-snd-card",
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +0530818 sizeof("msm8952-tasha-skun-snd-card")) ||
Aravind Kumard7691742015-05-13 13:10:51 +0530819 !strncmp(snd_card_name, "msm8976-tasha-snd-card",
Meng Wangf1ec20c2015-06-26 10:32:32 +0800820 sizeof("msm8976-tasha-snd-card")) ||
Yeleswarapu Nagaradhesh09f30be2015-07-22 14:11:03 +0530821 !strncmp(snd_card_name, "msm8976-tashalite-snd-card",
822 sizeof("msm8976-tashalite-snd-card")) ||
Meng Wangf1ec20c2015-06-26 10:32:32 +0800823 !strncmp(snd_card_name, "msm8976-tasha-skun-snd-card",
Naresh Tanniru4d1e1a12015-12-16 19:37:50 +0530824 sizeof("msm8976-tasha-skun-snd-card")) ||
825 !strncmp(snd_card_name, "msm8937-tasha-snd-card",
826 sizeof("msm8937-tasha-snd-card")) ||
827 !strncmp(snd_card_name, "msm8937-tashalite-snd-card",
828 sizeof("msm8937-tashalite-snd-card")) ||
829 !strncmp(snd_card_name, "msm8953-tasha-snd-card",
830 sizeof("msm8953-tasha-snd-card")) ||
831 !strncmp(snd_card_name, "msm8953-tashalite-snd-card",
832 sizeof("msm8953-tashalite-snd-card")))
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +0530833 {
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530834 ALOGI("%s: snd_card_name: %s",__func__,snd_card_name);
835 is_external_codec = true;
836 }
837}
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530838static void query_platform(const char *snd_card_name,
839 char *mixer_xml_path)
840{
841 if (!strncmp(snd_card_name, "msm8x16-snd-card-mtp",
842 sizeof("msm8x16-snd-card-mtp"))) {
843 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
844 sizeof(MIXER_XML_PATH_MTP));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700845
846 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
847 msm_be_id_array_len =
848 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
849
Tanya Finkeldd78e062015-05-26 04:29:56 -0700850 } else if (!strncmp(snd_card_name, "msm8x16-snd-card-sbc",
851 sizeof("msm8x16-snd-card-sbc"))) {
852 strlcpy(mixer_xml_path, MIXER_XML_PATH_SBC,
853 sizeof(mixer_xml_path));
854
855 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
856 msm_be_id_array_len =
857 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
858
Walter Yang7ca90d92014-05-06 17:48:02 +0800859 } else if (!strncmp(snd_card_name, "msm8x16-skuh-snd-card",
860 sizeof("msm8x16-skuh-snd-card"))) {
861 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUH,
862 sizeof(MIXER_XML_PATH_QRD_SKUH));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700863
864 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
865 msm_be_id_array_len =
866 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
867
Walter Yang7ca90d92014-05-06 17:48:02 +0800868 } else if (!strncmp(snd_card_name, "msm8x16-skui-snd-card",
869 sizeof("msm8x16-skui-snd-card"))) {
870 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUI,
871 sizeof(MIXER_XML_PATH_QRD_SKUI));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700872
873 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
874 msm_be_id_array_len =
875 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
876
Walter Yang19f244a2014-06-17 13:30:08 +0800877 } else if (!strncmp(snd_card_name, "msm8x16-skuhf-snd-card",
878 sizeof("msm8x16-skuhf-snd-card"))) {
879 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUHF,
880 sizeof(MIXER_XML_PATH_QRD_SKUHF));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700881
882 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
883 msm_be_id_array_len =
884 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
885
Walter Yangc899d572014-05-27 21:52:17 +0800886 } else if (!strncmp(snd_card_name, "msm8939-snd-card-mtp",
Yamit Mehtac6003e22014-05-19 10:26:02 +0530887 sizeof("msm8939-snd-card-mtp"))) {
Aravind Kumar71ba22b2014-06-23 15:18:50 +0530888 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
889 sizeof(MIXER_XML_PATH_MTP));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700890
891 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
892 msm_be_id_array_len =
893 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
894
Meng Wangf00485b2014-06-03 19:44:38 +0800895 } else if (!strncmp(snd_card_name, "msm8939-snd-card-skuk",
896 sizeof("msm8939-snd-card-skuk"))) {
897 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUK,
898 sizeof(MIXER_XML_PATH_SKUK));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700899 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
900 msm_be_id_array_len =
901 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
902
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +0530903 } else if (!strncmp(snd_card_name, "msm8939-tapan-snd-card",
904 sizeof("msm8939-tapan-snd-card"))) {
905 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
906 sizeof(MIXER_XML_PATH_WCD9306));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700907 msm_device_to_be_id = msm_device_to_be_id_external_codec;
908 msm_be_id_array_len =
909 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
910
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +0530911 } else if (!strncmp(snd_card_name, "msm8939-tapan9302-snd-card",
912 sizeof("msm8939-tapan9302-snd-card"))) {
913 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
914 sizeof(MIXER_XML_PATH_WCD9306));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700915
916 msm_device_to_be_id = msm_device_to_be_id_external_codec;
917 msm_be_id_array_len =
918 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
919
Aviral Gupta8ed0eec2014-08-25 10:22:11 +0530920 } else if (!strncmp(snd_card_name, "msm8939-tomtom9330-snd-card",
921 sizeof("msm8939-tomtom9330-snd-card"))) {
922 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330,
923 sizeof(MIXER_XML_PATH_WCD9330));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700924 msm_device_to_be_id = msm_device_to_be_id_external_codec;
925 msm_be_id_array_len =
926 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
927
Aravind Kumard7691742015-05-13 13:10:51 +0530928 } else if (!strncmp(snd_card_name, "msm8976-tasha-snd-card",
929 sizeof("msm8976-tasha-snd-card"))) {
930 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335,
931 sizeof(MIXER_XML_PATH_WCD9335));
932 msm_device_to_be_id = msm_device_to_be_id_external_codec;
933 msm_be_id_array_len =
934 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
935
Yeleswarapu Nagaradhesh09f30be2015-07-22 14:11:03 +0530936 } else if (!strncmp(snd_card_name, "msm8976-tashalite-snd-card",
937 sizeof("msm8976-tashalite-snd-card"))) {
938 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326,
939 MAX_MIXER_XML_PATH);
940 msm_device_to_be_id = msm_device_to_be_id_external_codec;
941 msm_be_id_array_len =
942 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
943
Meng Wangf1ec20c2015-06-26 10:32:32 +0800944 } else if (!strncmp(snd_card_name, "msm8976-tasha-skun-snd-card",
945 sizeof("msm8976-tasha-skun-snd-card"))) {
946 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUN,
947 sizeof(MIXER_XML_PATH_SKUN));
948 msm_device_to_be_id = msm_device_to_be_id_external_codec;
949 msm_be_id_array_len =
950 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
951
Walter Yang42886c52014-10-23 14:31:48 +0800952 } else if (!strncmp(snd_card_name, "msm8909-skua-snd-card",
953 sizeof("msm8909-skua-snd-card"))) {
954 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUA,
955 sizeof(MIXER_XML_PATH_SKUA));
Walter Yang42886c52014-10-23 14:31:48 +0800956 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
957 msm_be_id_array_len =
958 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 +0530959
Walter Yang42886c52014-10-23 14:31:48 +0800960 } else if (!strncmp(snd_card_name, "msm8909-skuc-snd-card",
961 sizeof("msm8909-skuc-snd-card"))) {
962 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUC,
963 sizeof(MIXER_XML_PATH_SKUC));
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530964 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
965 msm_be_id_array_len =
966 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
967
968 } else if (!strncmp(snd_card_name, "msm8909-pm8916-snd-card",
969 sizeof("msm8909-pm8916-snd-card"))) {
970 strlcpy(mixer_xml_path, MIXER_XML_PATH_MSM8909_PM8916,
971 sizeof(MIXER_XML_PATH_MSM8909_PM8916));
Walter Yang42886c52014-10-23 14:31:48 +0800972
973 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
974 msm_be_id_array_len =
975 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 +0530976
977 } else if (!strncmp(snd_card_name, "msm8909-skue-snd-card",
978 sizeof("msm8909-skue-snd-card"))) {
979 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUE,
980 sizeof(MIXER_XML_PATH_SKUE));
981 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
982 msm_be_id_array_len =
983 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
984
Meng Wangcfefb8b2014-12-05 14:35:55 +0800985 } else if (!strncmp(snd_card_name, "msm8939-snd-card-skul",
986 sizeof("msm8939-snd-card-skul"))) {
987 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUL,
988 sizeof(MIXER_XML_PATH_SKUL));
989 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
990 msm_be_id_array_len =
991 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +0530992 } else if (!strncmp(snd_card_name, "msm8952-snd-card-mtp",
Avinash Vaish306e6072015-05-13 16:58:18 +0530993 sizeof("msm8952-snd-card-mtp"))) {
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +0530994 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
995 sizeof(MIXER_XML_PATH_MTP));
996 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
997 msm_be_id_array_len =
998 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
999 } else if (!strncmp(snd_card_name, "msm8952-tomtom-snd-card",
1000 sizeof("msm8952-tomtom-snd-card"))) {
1001 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330,
1002 sizeof(MIXER_XML_PATH_WCD9330));
1003 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1004 msm_be_id_array_len =
1005 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Xiaojun Sang68b39442015-09-23 16:29:43 +08001006 } else if (!strncmp(snd_card_name, "msm8952-sku1-snd-card",
1007 sizeof("msm8952-sku1-snd-card"))) {
1008 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKU1,
1009 sizeof(MIXER_XML_PATH_SKU1));
1010 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1011 msm_be_id_array_len =
1012 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1013 } else if (!strncmp(snd_card_name, "msm8952-sku2-snd-card",
1014 sizeof("msm8952-sku2-snd-card"))) {
1015 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKU2,
1016 sizeof(MIXER_XML_PATH_SKU2));
1017 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1018 msm_be_id_array_len =
1019 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Xiaojun Sang9cd237a2015-11-20 15:30:18 +08001020 } else if (!strncmp(snd_card_name, "msm8953-sku3-tasha-snd-card",
1021 sizeof("msm8953-sku3-tasha-snd-card"))) {
1022 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKU3,
1023 sizeof(MIXER_XML_PATH_SKU3));
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]);
Walter Yangcd132722015-04-08 16:04:30 +08001027 } else if (!strncmp(snd_card_name, "msm8952-skum-snd-card",
1028 sizeof("msm8952-skum-snd-card"))) {
1029 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUM,
1030 sizeof(MIXER_XML_PATH_SKUM));
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]);
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301034 } else if (!strncmp(snd_card_name, "msm8952-tasha-snd-card",
1035 sizeof("msm8952-tasha-snd-card"))) {
1036 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335,
1037 sizeof(MIXER_XML_PATH_WCD9335));
1038 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1039 msm_be_id_array_len =
1040 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +05301041
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301042 } else if (!strncmp(snd_card_name, "msm8952-tashalite-snd-card",
1043 sizeof("msm8952-tashalite-snd-card"))) {
1044 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326,
1045 MAX_MIXER_XML_PATH);
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]);
Meng Wang2d747622015-08-07 10:11:41 +08001049 } else if (!strncmp(snd_card_name, "msm8976-skun-snd-card",
1050 sizeof("msm8976-skun-snd-card"))) {
1051 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUN_CAJON,
1052 sizeof(MIXER_XML_PATH_SKUN_CAJON));
1053 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1054 msm_be_id_array_len =
1055 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Naresh Tanniru4d1e1a12015-12-16 19:37:50 +05301056
1057 } else if (!strncmp(snd_card_name, "msm8937-snd-card-mtp",
1058 sizeof("msm8937-snd-card-mtp"))) {
1059 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
1060 sizeof(MIXER_XML_PATH_MTP));
1061 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1062 msm_be_id_array_len =
1063 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1064 } else if (!strncmp(snd_card_name, "msm8937-tasha-snd-card",
1065 sizeof("msm8937-tasha-snd-card"))) {
1066 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335,
1067 sizeof(MIXER_XML_PATH_WCD9335));
1068 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1069 msm_be_id_array_len =
1070 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1071 } else if (!strncmp(snd_card_name, "msm8937-tashalite-snd-card",
1072 sizeof("msm8937-tashalite-snd-card"))) {
1073 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326,
1074 MAX_MIXER_XML_PATH);
1075 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1076 msm_be_id_array_len =
1077 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1078 } else if (!strncmp(snd_card_name, "msm8953-snd-card-mtp",
1079 sizeof("msm8953-snd-card-mtp"))) {
1080 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
1081 sizeof(MIXER_XML_PATH_MTP));
1082 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1083 msm_be_id_array_len =
1084 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1085 } else if (!strncmp(snd_card_name, "msm8953-tasha-snd-card",
1086 sizeof("msm8953-tasha-snd-card"))) {
1087 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9335,
1088 sizeof(MIXER_XML_PATH_WCD9335));
1089 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1090 msm_be_id_array_len =
1091 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
1092 } else if (!strncmp(snd_card_name, "msm8953-tashalite-snd-card",
1093 sizeof("msm8937-tashalite-snd-card"))) {
1094 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326,
1095 MAX_MIXER_XML_PATH);
1096 msm_device_to_be_id = msm_device_to_be_id_external_codec;
1097 msm_be_id_array_len =
1098 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301099 } else {
1100 strlcpy(mixer_xml_path, MIXER_XML_PATH,
1101 sizeof(MIXER_XML_PATH));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001102
1103 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
1104 msm_be_id_array_len =
1105 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
1106
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301107 }
1108}
1109
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001110void platform_set_echo_reference(struct audio_device *adev, bool enable,
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05301111 audio_devices_t out_device __unused)
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001112{
1113 struct platform_data *my_data = (struct platform_data *)adev->platform;
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001114
1115 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1116 ALOGV("%s: disabling %s", __func__, my_data->ec_ref_mixer_path);
1117 audio_route_reset_and_update_path(adev->audio_route,
1118 my_data->ec_ref_mixer_path);
1119 }
1120
1121 if (enable) {
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001122 if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_HEADPHONES_44_1] > 0)
1123 strlcpy(my_data->ec_ref_mixer_path, "echo-reference headphones-44.1",
1124 sizeof(my_data->ec_ref_mixer_path));
Leena Winterrowdd7a04cd2016-01-07 11:50:02 -08001125 else if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_SPEAKER_VBAT] > 0)
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07001126 strlcpy(my_data->ec_ref_mixer_path, "vbat-speaker echo-reference",
1127 sizeof(my_data->ec_ref_mixer_path));
1128 else
1129 strlcpy(my_data->ec_ref_mixer_path, "echo-reference",
1130 sizeof(my_data->ec_ref_mixer_path));
1131
1132
1133 ALOGD("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
1134 audio_route_apply_and_update_path(adev->audio_route,
1135 my_data->ec_ref_mixer_path);
1136 }
1137}
Banajit Goswami20cdd212015-09-11 01:11:30 -07001138void platform_set_gsm_mode(void *platform, bool enable)
1139{
1140 struct platform_data *my_data = (struct platform_data *)platform;
1141 struct audio_device *adev = my_data->adev;
1142
1143 if (my_data->gsm_mode_enabled) {
1144 my_data->gsm_mode_enabled = false;
1145 ALOGV("%s: disabling gsm mode", __func__);
1146 audio_route_reset_and_update_path(adev->audio_route, "gsm-mode");
1147 }
1148
1149 if (enable) {
1150 my_data->gsm_mode_enabled = true;
1151 ALOGD("%s: enabling gsm mode", __func__);
1152 audio_route_apply_and_update_path(adev->audio_route, "gsm-mode");
1153 }
1154}
1155
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301156void close_csd_client(struct csd_data *csd)
1157{
1158 if (csd != NULL) {
1159 csd->deinit();
1160 dlclose(csd->csd_client);
1161 free(csd);
1162 csd = NULL;
1163 }
1164}
1165
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301166
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05301167static void set_platform_defaults(struct platform_data * my_data)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301168{
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301169 int32_t dev, count = 0;
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301170 const char *MEDIA_MIMETYPE_AUDIO_ALAC = "audio/alac";
1171 const char *MEDIA_MIMETYPE_AUDIO_APE = "audio/x-ape";
1172
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301173 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301174 backend_tag_table[dev] = NULL;
1175 hw_interface_table[dev] = NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301176 }
1177 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301178 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301179 }
1180
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301181 // To overwrite these go to the audio_platform_info.xml file.
1182 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
1183 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
1184 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
1185 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
1186 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1187 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1188 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1189 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1190 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1191 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
1192 backend_tag_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("afe-proxy");
1193 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headphones");
1194 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301195 strdup("speaker-and-usb-headphones");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301196 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1197 backend_tag_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("capture-fm");
1198 backend_tag_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("transmission-fm");
1199 backend_tag_table[SND_DEVICE_OUT_HEADPHONES_44_1] = strdup("headphones-44.1");
1200 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = strdup("vbat-voice-speaker");
1201
1202 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1203 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1204 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301205
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05301206 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301207 /*remove ALAC & APE from DSP decoder list based on software decoder availability*/
Alexy Josephb1379942016-01-29 15:49:38 -08001208 for (count = 0; count < (int32_t) (sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]));
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301209 count++) {
1210
1211 if (!strncmp(MEDIA_MIMETYPE_AUDIO_ALAC, dsp_only_decoders_mime[count],
1212 strlen(dsp_only_decoders_mime[count]))) {
1213
1214 if(property_get_bool("use.qti.sw.alac.decoder", false)) {
1215 ALOGD("Alac software decoder is available...removing alac from DSP decoder list");
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05301216 strlcpy(dsp_only_decoders_mime[count],"none",5);
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301217 }
1218 } else if (!strncmp(MEDIA_MIMETYPE_AUDIO_APE, dsp_only_decoders_mime[count],
1219 strlen(dsp_only_decoders_mime[count]))) {
1220
1221 if(property_get_bool("use.qti.sw.ape.decoder", false)) {
1222 ALOGD("APE software decoder is available...removing ape from DSP decoder list");
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05301223 strlcpy(dsp_only_decoders_mime[count],"none",5);
Naresh Tanniru34a303c2016-01-27 17:26:41 +05301224 }
1225 }
1226 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301227}
1228
Avinash Vaish71c066d2014-08-27 12:32:35 +05301229void get_cvd_version(char *cvd_version, struct audio_device *adev)
1230{
1231 struct mixer_ctl *ctl;
1232 int count;
1233 int ret = 0;
1234
1235 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1236 if (!ctl) {
1237 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1238 goto done;
1239 }
1240 mixer_ctl_update(ctl);
1241
1242 count = mixer_ctl_get_num_values(ctl);
1243 if (count > MAX_CVD_VERSION_STRING_SIZE)
1244 count = MAX_CVD_VERSION_STRING_SIZE;
1245
1246 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1247 if (ret != 0) {
1248 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1249 goto done;
1250 }
1251
1252done:
1253 return;
1254}
1255
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301256static int hw_util_open(int card_no)
1257{
1258 int fd = -1;
1259 char dev_name[256];
1260
1261 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
1262 card_no, WCD9XXX_CODEC_HWDEP_NODE);
1263 ALOGD("%s Opening device %s\n", __func__, dev_name);
1264 fd = open(dev_name, O_WRONLY);
1265 if (fd < 0) {
1266 ALOGE("%s: cannot open device '%s'\n", __func__, dev_name);
1267 return fd;
1268 }
1269 ALOGD("%s success", __func__);
1270 return fd;
1271}
1272
1273struct param_data {
1274 int use_case;
1275 int acdb_id;
1276 int get_size;
1277 int buff_size;
1278 int data_size;
1279 void *buff;
1280};
1281
Banajit Goswami20cdd212015-09-11 01:11:30 -07001282static int send_vbat_adc_data_to_acdb(struct platform_data *plat_data, char *cal_type)
1283{
1284 int ret = 0;
1285 struct mixer_ctl *ctl;
1286 uint16_t vbat_adc_data[2];
1287 struct platform_data *my_data = plat_data;
1288 struct audio_device *adev = my_data->adev;
1289
1290 const char *mixer_ctl_name = "Vbat ADC data";
1291
1292 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1293 if (!ctl) {
1294 ALOGE("%s: Could not get ctl for mixer ctl name - %s",
1295 __func__, mixer_ctl_name);
1296 ret = -EINVAL;
1297 goto done;
1298 }
1299
1300 vbat_adc_data[0] = mixer_ctl_get_value(ctl, 0);
1301 vbat_adc_data[1] = mixer_ctl_get_value(ctl, 1);
1302
1303 ALOGD("%s: Vbat ADC output values: Dcp1: %d , Dcp2: %d",
1304 __func__, vbat_adc_data[0], vbat_adc_data[1]);
1305
1306 ret = my_data->acdb_set_codec_data(&vbat_adc_data[0], cal_type);
1307
1308done:
1309 return ret;
1310}
1311
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301312static void send_codec_cal(acdb_loader_get_calibration_t acdb_loader_get_calibration,
Banajit Goswami20cdd212015-09-11 01:11:30 -07001313 struct platform_data *plat_data, int fd)
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301314{
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301315 int type;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301316
1317 for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) {
1318 struct wcdcal_ioctl_buffer codec_buffer;
1319 struct param_data calib;
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301320 int ret;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301321
Bharath Ramachandramurthy63a47ef2015-08-31 17:41:46 -07001322 /* MAD calibration is handled by sound trigger HAL, skip here */
1323 if (type == WCD9XXX_MAD_CAL)
1324 continue;
1325
Banajit Goswami20cdd212015-09-11 01:11:30 -07001326 if((plat_data->is_vbat_speaker) && (WCD9XXX_VBAT_CAL == type)) {
1327 ret = send_vbat_adc_data_to_acdb(plat_data, cal_name_info[type]);
1328 if (ret < 0)
1329 ALOGE("%s error in sending vbat adc data to acdb", __func__);
1330 }
1331
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301332 calib.get_size = 1;
1333 ret = acdb_loader_get_calibration(cal_name_info[type], sizeof(struct param_data),
1334 &calib);
1335 if (ret < 0) {
1336 ALOGE("%s get_calibration failed\n", __func__);
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301337 continue;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301338 }
1339 calib.get_size = 0;
1340 calib.buff = malloc(calib.buff_size);
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301341 if(calib.buff == NULL) {
1342 ALOGE("%s mem allocation for %d bytes for %s failed\n"
1343 , __func__, calib.buff_size, cal_name_info[type]);
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301344 continue;
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301345 }
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301346 ret = acdb_loader_get_calibration(cal_name_info[type],
1347 sizeof(struct param_data), &calib);
1348 if (ret < 0) {
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301349 ALOGE("%s get_calibration failed type=%s calib.size=%d\n"
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05301350 , __func__, cal_name_info[type], calib.buff_size);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301351 free(calib.buff);
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301352 continue;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301353 }
1354 codec_buffer.buffer = calib.buff;
1355 codec_buffer.size = calib.data_size;
1356 codec_buffer.cal_type = type;
1357 if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0)
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301358 ALOGE("Failed to call ioctl for %s err=%d calib.size=%d",
1359 cal_name_info[type], errno, codec_buffer.size);
1360 ALOGD("%s cal sent for %s calib.size=%d"
1361 , __func__, cal_name_info[type], codec_buffer.size);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301362 free(calib.buff);
1363 }
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301364}
1365
1366static void audio_hwdep_send_cal(struct platform_data *plat_data)
1367{
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301368 int fd = plat_data->hw_dep_fd;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301369
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301370 if (fd < 0)
1371 fd = hw_util_open(plat_data->adev->snd_card);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301372 if (fd == -1) {
1373 ALOGE("%s error open\n", __func__);
1374 return;
1375 }
1376
1377 acdb_loader_get_calibration = (acdb_loader_get_calibration_t)
1378 dlsym(plat_data->acdb_handle, "acdb_loader_get_calibration");
1379
1380 if (acdb_loader_get_calibration == NULL) {
1381 ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__,
1382 dlerror());
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301383 if (fd >= 0) {
1384 close(fd);
1385 plat_data->hw_dep_fd = -1;
1386 }
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301387 return;
1388 }
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301389
1390 send_codec_cal(acdb_loader_get_calibration, plat_data, fd);
1391 plat_data->hw_dep_fd = fd;
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301392}
1393
Naresh Tanniru516c2452015-08-14 12:58:24 +05301394const char * get_snd_card_name_for_acdb_loader(const char *snd_card_name) {
1395
1396 if(snd_card_name == NULL)
1397 return NULL;
1398
1399 // Both tasha & tasha-lite uses tasha ACDB files
1400 // simulate sound card name for tasha lite, so that
1401 // ACDB module loads tasha ACDB files for tasha lite
1402 if(!strncmp(snd_card_name, "msm8976-tashalite-snd-card",
1403 sizeof("msm8976-tashalite-snd-card"))) {
Naresh Tanniru4d1e1a12015-12-16 19:37:50 +05301404 ALOGD("using tasha ACDB files for tasha-lite");
1405 return "msm8976-tasha-snd-card";
1406 }
1407
1408 if(!strncmp(snd_card_name, "msm8952-tashalite-snd-card",
1409 sizeof("msm8952-tashalite-snd-card"))) {
1410 ALOGD("using tasha ACDB files for tasha-lite");
1411 return "msm8952-tasha-snd-card";
1412 }
1413
1414 if(!strncmp(snd_card_name, "msm8937-tashalite-snd-card",
1415 sizeof("msm8937-tashalite-snd-card"))) {
1416 ALOGD("using tasha ACDB files for tasha-lite");
1417 return "msm8937-tasha-snd-card";
1418 }
1419
1420 if(!strncmp(snd_card_name, "msm8953-tashalite-snd-card",
1421 sizeof("msm8953-tashalite-snd-card"))) {
1422 ALOGD("using tasha ACDB files for tasha-lite");
1423 return "msm8953-tasha-snd-card";
1424 }
1425
1426 return snd_card_name;
Naresh Tanniru516c2452015-08-14 12:58:24 +05301427}
1428
1429
1430int platform_acdb_init(void *platform)
Ramjee Singh203473b2015-06-09 15:18:42 +05301431{
1432 struct platform_data *my_data = (struct platform_data *)platform;
1433 char *cvd_version = NULL;
1434 int key = 0;
Naresh Tanniru516c2452015-08-14 12:58:24 +05301435 const char *snd_card_name, *acdb_snd_card_name;
Ramjee Singh203473b2015-06-09 15:18:42 +05301436 int result;
1437 char value[PROPERTY_VALUE_MAX];
1438 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1439 if (!cvd_version)
1440 ALOGE("Failed to allocate cvd version");
1441 else
1442 get_cvd_version(cvd_version, my_data->adev);
1443
1444 property_get("audio.ds1.metainfo.key",value,"0");
1445 key = atoi(value);
1446 snd_card_name = mixer_get_name(my_data->adev->mixer);
Naresh Tanniru516c2452015-08-14 12:58:24 +05301447 acdb_snd_card_name = get_snd_card_name_for_acdb_loader(snd_card_name);
1448
1449 result = my_data->acdb_init(acdb_snd_card_name, cvd_version, key);
1450
Karthik Reddy Katta8513f432016-04-12 14:29:27 +05301451 /* Save these variables in platform_data. These will be used
1452 while reloading ACDB files during run time. */
1453 strlcpy(my_data->cvd_version, cvd_version, MAX_CVD_VERSION_STRING_SIZE);
1454 strlcpy(my_data->snd_card_name, acdb_snd_card_name,
1455 MAX_SND_CARD_STRING_SIZE);
1456 my_data->metainfo_key = key;
1457
Ramjee Singh203473b2015-06-09 15:18:42 +05301458 if (cvd_version)
1459 free(cvd_version);
1460 if (!result) {
1461 my_data->is_acdb_initialized = true;
1462 ALOGD("ACDB initialized");
1463 audio_hwdep_send_cal(my_data);
1464 } else {
1465 my_data->is_acdb_initialized = false;
1466 ALOGD("ACDB initialization failed");
1467 }
1468 return result;
1469}
1470
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301471#define MAX_PATH (256)
1472#define THERMAL_SYSFS "/sys/class/thermal"
1473#define TZ_TYPE "/sys/class/thermal/thermal_zone%d/type"
1474#define TZ_WSA "/sys/class/thermal/thermal_zone%d/temp"
1475
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05301476static bool check_and_get_wsa_info(char *snd_card_name, int *wsaCount,
1477 bool *is_wsa_combo_supported)
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301478{
1479 DIR *tdir = NULL;
1480 struct dirent *tdirent = NULL;
1481 int tzn = 0;
1482 char name[MAX_PATH] = {0};
1483 char cwd[MAX_PATH] = {0};
1484 char file[10] = "wsa";
1485 bool found = false;
1486 int wsa_count = 0;
1487
1488 if (!getcwd(cwd, sizeof(cwd)))
1489 return false;
1490
1491 chdir(THERMAL_SYSFS); /* Change dir to read the entries. Doesnt work
1492 otherwise */
1493 tdir = opendir(THERMAL_SYSFS);
1494 if (!tdir) {
1495 ALOGE("Unable to open %s\n", THERMAL_SYSFS);
1496 return false;
1497 }
1498
1499 while ((tdirent = readdir(tdir))) {
1500 char buf[50];
1501 struct dirent *tzdirent;
1502 DIR *tzdir = NULL;
1503
1504 tzdir = opendir(tdirent->d_name);
1505 if (!tzdir)
1506 continue;
1507 while ((tzdirent = readdir(tzdir))) {
1508 if (strcmp(tzdirent->d_name, "type"))
1509 continue;
1510 snprintf(name, MAX_PATH, TZ_TYPE, tzn);
1511 ALOGD("Opening %s\n", name);
1512 read_line_from_file(name, buf, sizeof(buf));
1513 if (strstr(buf, file)) {
1514 wsa_count++;
1515 /*We support max only two WSA speakers*/
1516 if (wsa_count == 2)
1517 break;
1518 }
1519 tzn++;
1520 }
1521 closedir(tzdir);
1522 }
1523 if (wsa_count > 0){
1524 ALOGD("Found %d WSA present on the platform", wsa_count);
1525 found = true;
1526 *wsaCount = wsa_count;
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05301527
1528 /* update wsa combo supported flag based on sound card name */
1529 /* wsa combo flag needs to be set to true only for hardware
1530 combinations which has support for both wsa and non-wsa speaker */
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05301531 *is_wsa_combo_supported = false;
1532 if(snd_card_name) {
1533 if ((!strncmp(snd_card_name, "msm8953-snd-card-mtp",
1534 sizeof("msm8953-snd-card-mtp")) ||
1535 (!strncmp(snd_card_name, "msm8952-skum-snd-card",
1536 sizeof("msm8952-skum-snd-card"))))) {
1537 *is_wsa_combo_supported = true;
1538 }
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05301539 }
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301540 }
1541 closedir(tdir);
1542 chdir(cwd); /* Restore current working dir */
1543 return found;
1544}
1545
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05301546static void get_source_mic_type(struct platform_data * my_data)
1547{
1548 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1549 switch (my_data->max_mic_count) {
1550 case 4:
1551 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1552 case 3:
1553 my_data->source_mic_type |= SOURCE_THREE_MIC;;
1554 case 2:
1555 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1556 case 1:
1557 my_data->source_mic_type |= SOURCE_MONO_MIC;
1558 break;
1559 default:
1560 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1561 __func__, my_data->max_mic_count);
1562 my_data->source_mic_type = SOURCE_MONO_MIC | SOURCE_DUAL_MIC;
1563 break;
1564 }
1565}
1566
Naresh Tannirue3b18452014-03-04 14:44:27 +05301567void *platform_init(struct audio_device *adev)
1568{
1569 char value[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301570 struct platform_data *my_data = NULL;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05301571 int retry_num = 0, snd_card_num = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301572 const char *snd_card_name;
Yeleswarapu Nagaradhesh09f30be2015-07-22 14:11:03 +05301573 char mixer_xml_path[MAX_MIXER_XML_PATH],ffspEnable[PROPERTY_VALUE_MAX];
Satish Babu Patakokilabbd4e9d2015-05-13 22:08:06 +05301574 const char *mixer_ctl_name = "Set HPX ActiveBe";
1575 struct mixer_ctl *ctl = NULL;
Naveen Kumar70e27352015-07-22 21:07:10 +05301576 int idx;
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301577 int wsaCount =0;
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05301578 bool is_wsa_combo_supported = false;
Naveen Kumar70e27352015-07-22 21:07:10 +05301579
1580 my_data = calloc(1, sizeof(struct platform_data));
1581
Chaithanya Krishna Bacharajudb6236a2015-01-30 10:08:33 +05301582 if (!my_data) {
1583 ALOGE("failed to allocate platform data");
1584 return NULL;
1585 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301586
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301587 while (snd_card_num < MAX_SND_CARD) {
1588 adev->mixer = mixer_open(snd_card_num);
1589
1590 while (!adev->mixer && retry_num < RETRY_NUMBER) {
1591 usleep(RETRY_US);
1592 adev->mixer = mixer_open(snd_card_num);
1593 retry_num++;
1594 }
1595
1596 if (!adev->mixer) {
1597 ALOGE("%s: Unable to open the mixer card: %d", __func__,
1598 snd_card_num);
1599 retry_num = 0;
1600 snd_card_num++;
1601 continue;
1602 }
1603
1604 snd_card_name = mixer_get_name(adev->mixer);
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05301605 ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301606
1607 my_data->hw_info = hw_info_init(snd_card_name);
1608 if (!my_data->hw_info) {
1609 ALOGE("%s: Failed to init hardware info", __func__);
1610 } else {
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301611 query_platform(snd_card_name, mixer_xml_path);
1612 ALOGD("%s: mixer path file is %s", __func__,
1613 mixer_xml_path);
1614 if (audio_extn_read_xml(adev, snd_card_num, mixer_xml_path,
1615 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301616 adev->audio_route = audio_route_init(snd_card_num,
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301617 mixer_xml_path);
1618 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301619 if (!adev->audio_route) {
1620 ALOGE("%s: Failed to init audio route controls, aborting.",
1621 __func__);
1622 free(my_data);
Mingming Yindda29e62015-12-02 18:02:28 -08001623 mixer_close(adev->mixer);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301624 return NULL;
1625 }
1626 adev->snd_card = snd_card_num;
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +05301627 update_codec_type(snd_card_name);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301628 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1629 break;
1630 }
1631 retry_num = 0;
1632 snd_card_num++;
Mingming Yindda29e62015-12-02 18:02:28 -08001633 mixer_close(adev->mixer);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301634 }
1635
1636 if (snd_card_num >= MAX_SND_CARD) {
1637 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1638 free(my_data);
1639 return NULL;
1640 }
1641
Naresh Tannirue3b18452014-03-04 14:44:27 +05301642 my_data->adev = adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301643 my_data->fluence_in_spkr_mode = false;
1644 my_data->fluence_in_voice_call = false;
1645 my_data->fluence_in_voice_rec = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301646 my_data->fluence_in_audio_rec = false;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301647 my_data->external_spk_1 = false;
1648 my_data->external_spk_2 = false;
1649 my_data->external_mic = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301650 my_data->fluence_type = FLUENCE_NONE;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301651 my_data->fluence_mode = FLUENCE_ENDFIRE;
Avinash Vaishd5fa4572014-09-15 14:41:14 +05301652 my_data->slowtalk = false;
1653 my_data->hd_voice = false;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301654 my_data->edid_info = NULL;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05301655 my_data->is_wsa_speaker = false;
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301656 my_data->hw_dep_fd = -1;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301657
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301658 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
1659 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301660 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301661 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301662 my_data->fluence_type = FLUENCE_DUAL_MIC;
1663 } else {
1664 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301665 }
1666
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301667 if (my_data->fluence_type != FLUENCE_NONE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301668 property_get("persist.audio.fluence.voicecall",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301669 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301670 my_data->fluence_in_voice_call = true;
1671 }
1672
1673 property_get("persist.audio.fluence.voicerec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301674 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301675 my_data->fluence_in_voice_rec = true;
1676 }
1677
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301678 property_get("persist.audio.fluence.audiorec",value,"");
1679 if (!strncmp("true", value, sizeof("true"))) {
1680 my_data->fluence_in_audio_rec = true;
1681 }
1682
Naresh Tannirue3b18452014-03-04 14:44:27 +05301683 property_get("persist.audio.fluence.speaker",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301684 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301685 my_data->fluence_in_spkr_mode = true;
1686 }
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301687
1688 property_get("persist.audio.fluence.mode",value,"");
1689 if (!strncmp("broadside", value, sizeof("broadside"))) {
1690 my_data->fluence_mode = FLUENCE_BROADSIDE;
1691 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301692 }
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301693
Alexy Josephb1379942016-01-29 15:49:38 -08001694 if (check_and_get_wsa_info((char *)snd_card_name, &wsaCount, &is_wsa_combo_supported)) {
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301695 /*Set ACDB ID of Stereo speaker if two WSAs are present*/
1696 /*Default ACDB ID for wsa speaker is that for mono*/
1697 if (wsaCount == 2) {
1698 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_WSA, 15);
1699 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_VBAT, 15);
1700 }
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05301701
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301702 my_data->is_wsa_speaker = true;
Naresh Tanniru74a2eee2016-02-10 13:38:19 +05301703
1704 if (is_wsa_combo_supported)
1705 hw_info_enable_wsa_combo_usecase_support(my_data->hw_info);
1706
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301707 }
1708
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +05301709 property_get("persist.audio.FFSP.enable", ffspEnable, "");
1710 if (!strncmp("true", ffspEnable, sizeof("true"))) {
1711 acdb_device_table[SND_DEVICE_OUT_SPEAKER] = 131;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05301712 acdb_device_table[SND_DEVICE_OUT_SPEAKER_WSA] = 131;
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +05301713 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = 131;
1714 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 131;
1715 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 131;
1716 }
Dhananjay Kumara3565b32014-07-23 01:12:48 +05301717
Banajit Goswami20cdd212015-09-11 01:11:30 -07001718 /* Check if Vbat speaker enabled property is set, this should be done before acdb init */
1719 bool ret = false;
1720 ret = audio_extn_can_use_vbat();
1721 if (ret)
1722 my_data->is_vbat_speaker = true;
1723
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05301724 /*
1725 * Check if hifi audio( i.e. 96, 192 KHZ) is enabled for this platform,
1726 * enable hifi audio by default for external codec targets
1727 */
1728 ret = audio_extn_is_hifi_audio_supported();
1729 if (ret || is_external_codec)
1730 my_data->hifi_audio = true;
1731
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301732 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301733 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1734 if (my_data->acdb_handle == NULL) {
1735 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1736 } else {
1737 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1738 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1739 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301740 if (!my_data->acdb_deallocate)
1741 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1742 __func__, LIB_ACDB_LOADER);
1743
Naresh Tannirue3b18452014-03-04 14:44:27 +05301744 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 -07001745 "acdb_loader_send_audio_cal_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301746 if (!my_data->acdb_send_audio_cal)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301747 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +05301748 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301749
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301750 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1751 "acdb_loader_set_audio_cal_v2");
1752 if (!my_data->acdb_set_audio_cal)
1753 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1754 __func__, LIB_ACDB_LOADER);
1755
1756 my_data->acdb_get_audio_cal = (acdb_get_audio_cal_t)dlsym(my_data->acdb_handle,
1757 "acdb_loader_get_audio_cal_v2");
1758 if (!my_data->acdb_get_audio_cal)
1759 ALOGE("%s: Could not find the symbol acdb_get_audio_cal_v2 from %s",
1760 __func__, LIB_ACDB_LOADER);
1761
Naresh Tannirue3b18452014-03-04 14:44:27 +05301762 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1763 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301764 if (!my_data->acdb_send_voice_cal)
1765 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1766 __func__, LIB_ACDB_LOADER);
1767
1768 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1769 "acdb_loader_reload_vocvoltable");
1770 if (!my_data->acdb_reload_vocvoltable)
1771 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1772 __func__, LIB_ACDB_LOADER);
1773
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001774 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
1775 my_data->acdb_handle,
1776 "acdb_loader_get_default_app_type");
1777 if (!my_data->acdb_get_default_app_type)
1778 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1779 __func__, LIB_ACDB_LOADER);
1780
Ben Rombergerfeca4b82015-07-07 20:40:44 -07001781 my_data->acdb_send_common_top = (acdb_send_common_top_t)dlsym(
1782 my_data->acdb_handle,
1783 "acdb_loader_send_common_custom_topology");
1784 if (!my_data->acdb_send_common_top)
1785 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1786 __func__, LIB_ACDB_LOADER);
1787
Banajit Goswami20cdd212015-09-11 01:11:30 -07001788 my_data->acdb_set_codec_data = (acdb_set_codec_data_t)dlsym(
1789 my_data->acdb_handle,
1790 "acdb_loader_set_codec_data");
1791 if (!my_data->acdb_set_codec_data)
1792 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1793 __func__, LIB_ACDB_LOADER);
1794
1795
Naresh Tannirue3b18452014-03-04 14:44:27 +05301796 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301797 "acdb_loader_init_v2");
Avinash Vaish71c066d2014-08-27 12:32:35 +05301798 if (my_data->acdb_init == NULL) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301799 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Avinash Vaish71c066d2014-08-27 12:32:35 +05301800 goto acdb_init_fail;
1801 }
Karthik Reddy Katta8513f432016-04-12 14:29:27 +05301802
1803 my_data->acdb_reload = (acdb_reload_t)dlsym(my_data->acdb_handle,
1804 "acdb_loader_reload_acdb_files");
1805 if (my_data->acdb_reload == NULL) {
1806 ALOGE("%s: dlsym error %s for acdb_loader_reload_acdb_files", __func__, dlerror());
1807 goto acdb_init_fail;
1808 }
Ramjee Singh203473b2015-06-09 15:18:42 +05301809 platform_acdb_init(my_data);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301810 }
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301811 audio_extn_pm_vote();
Naresh Tannirue3b18452014-03-04 14:44:27 +05301812
Satish Babu Patakokilabbd4e9d2015-05-13 22:08:06 +05301813 /* Configure active back end for HPX*/
1814 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1815 if (ctl) {
1816 ALOGE(" sending HPX Active BE information ");
1817 mixer_ctl_set_value(ctl, 0, is_external_codec);
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05301818 }
1819
Avinash Vaish71c066d2014-08-27 12:32:35 +05301820acdb_init_fail:
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301821
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05301822 set_platform_defaults(my_data);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301823
Dhananjay Kumara68d7af2015-05-25 19:11:30 +05301824 /* Initialize ACDB and PCM ID's */
1825 if (is_external_codec)
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001826 platform_info_init(PLATFORM_INFO_XML_PATH_EXTCODEC, my_data);
Dhananjay Kumara68d7af2015-05-25 19:11:30 +05301827 else
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -07001828 platform_info_init(PLATFORM_INFO_XML_PATH, my_data);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301829
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05301830 /* obtain source mic type from max mic count*/
1831 get_source_mic_type(my_data);
1832 ALOGD("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1833 " fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1834 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1835 my_data->fluence_in_voice_call, my_data->fluence_in_voice_rec,
1836 my_data->fluence_in_spkr_mode);
1837
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301838 /* init usb */
1839 audio_extn_usb_init(adev);
1840 /* update sound cards appropriately */
1841 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
1842
1843 /* Read one time ssr property */
1844 audio_extn_ssr_update_enabled();
1845 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301846
Ashish Jain8ec50472014-10-16 13:56:28 +05301847 /* init dap hal */
1848 audio_extn_dap_hal_init(adev->snd_card);
1849
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301850 audio_extn_dolby_set_license(adev);
1851
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301852 /* init audio device arbitration */
1853 audio_extn_dev_arbi_init();
1854
1855 my_data->edid_info = NULL;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301856
1857 /* initialize backend config */
1858 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
1859 my_data->current_backend_cfg[idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1860 if (idx == HEADPHONE_44_1_BACKEND)
1861 my_data->current_backend_cfg[idx].sample_rate = OUTPUT_SAMPLING_RATE_44100;
1862 my_data->current_backend_cfg[idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1863 }
1864
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05301865 my_data->current_tx_backend_cfg[DEFAULT_CODEC_BACKEND].sample_rate =
1866 CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1867 my_data->current_tx_backend_cfg[DEFAULT_CODEC_BACKEND].bit_width =
1868 CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1869
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05301870 if (is_external_codec) {
1871 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1872 strdup("SLIM_0_RX Format");
1873 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1874 strdup("SLIM_0_RX SampleRate");
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301875
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05301876 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].bitwidth_mixer_ctl =
1877 strdup("SLIM_5_RX Format");
1878 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].samplerate_mixer_ctl =
1879 strdup("SLIM_5_RX SampleRate");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301880
1881 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1882 strdup("SLIM_6_RX Format");
1883 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1884 strdup("SLIM_6_RX SampleRate");
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05301885
1886 my_data->current_tx_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1887 strdup("SLIM_0_TX Format");
1888 my_data->current_tx_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1889 strdup("SLIM_0_TX SampleRate");
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05301890 } else {
1891 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1892 strdup("MI2S_RX Format");
1893 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1894 strdup("MI2S_RX SampleRate");
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05301895
1896 my_data->current_tx_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1897 strdup("MI2S_TX Format");
1898 my_data->current_tx_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1899 strdup("MI2S_TX SampleRate");
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05301900 }
Sidipotu Ashokcf877732015-09-22 14:58:48 +05301901
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05301902 ret = audio_extn_utils_get_codec_version(snd_card_name,
1903 my_data->adev->snd_card,
1904 my_data->codec_version);
Sidipotu Ashokcf877732015-09-22 14:58:48 +05301905
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05301906 if (NATIVE_AUDIO_MODE_INVALID != platform_get_native_support()) {
1907 /*
1908 * Native playback is enabled from the UI.
1909 */
1910 if(strstr(snd_card_name, "tasha")) {
1911 if (strstr(my_data->codec_version, "WCD9335_1_0") ||
1912 strstr(my_data->codec_version, "WCD9335_1_1")) {
1913 ALOGD("%s:napb: TASHA 1.0 or 1.1 only SRC mode is supported",
1914 __func__);
1915 platform_set_native_support(NATIVE_AUDIO_MODE_SRC);
1916 }
1917 } else {
1918 platform_set_native_support(NATIVE_AUDIO_MODE_INVALID);
Sidipotu Ashokcf877732015-09-22 14:58:48 +05301919 }
1920 }
1921
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05301922 my_data->edid_info = NULL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301923 return my_data;
1924}
1925
1926void platform_deinit(void *platform)
1927{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301928 struct platform_data *my_data = (struct platform_data *)platform;
1929
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301930 if (my_data->edid_info) {
1931 free(my_data->edid_info);
1932 my_data->edid_info = NULL;
1933 }
1934
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05301935 if (my_data->hw_dep_fd >= 0) {
1936 close(my_data->hw_dep_fd);
1937 my_data->hw_dep_fd = -1;
1938 }
1939
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301940 hw_info_deinit(my_data->hw_info);
1941 close_csd_client(my_data->csd);
1942
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301943 int32_t dev;
1944 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301945 if (backend_tag_table[dev]) {
1946 free(backend_tag_table[dev]);
1947 backend_tag_table[dev]= NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301948 }
1949 }
1950
1951 /* deinit audio device arbitration */
1952 audio_extn_dev_arbi_deinit();
1953
1954 if (my_data->edid_info) {
1955 free(my_data->edid_info);
1956 my_data->edid_info = NULL;
1957 }
1958
Naresh Tannirue3b18452014-03-04 14:44:27 +05301959 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301960 /* deinit usb */
1961 audio_extn_usb_deinit();
Ashish Jain8ec50472014-10-16 13:56:28 +05301962 audio_extn_dap_hal_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +05301963}
1964
Ben Rombergerfeca4b82015-07-07 20:40:44 -07001965static int platform_is_acdb_initialized(void *platform)
Ramjee Singh203473b2015-06-09 15:18:42 +05301966{
1967 struct platform_data *my_data = (struct platform_data *)platform;
1968 ALOGD("%s: acdb initialized %d\n", __func__, my_data->is_acdb_initialized);
1969 return my_data->is_acdb_initialized;
1970}
1971
Ben Rombergerfeca4b82015-07-07 20:40:44 -07001972void platform_snd_card_update(void *platform, int snd_scard_state)
1973{
1974 struct platform_data *my_data = (struct platform_data *)platform;
1975
1976 if (snd_scard_state == SND_CARD_STATE_ONLINE) {
1977 if (!platform_is_acdb_initialized(my_data)) {
1978 if(platform_acdb_init(my_data))
1979 ALOGE("%s: acdb initialization is failed", __func__);
1980 } else if (my_data->acdb_send_common_top() < 0) {
1981 ALOGD("%s: acdb did not set common topology", __func__);
1982 }
1983 }
1984}
1985
Naresh Tannirue3b18452014-03-04 14:44:27 +05301986const char *platform_get_snd_device_name(snd_device_t snd_device)
1987{
1988 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
1989 return device_table[snd_device];
1990 else
1991 return "";
1992}
1993
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301994int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1995 char *device_name)
1996{
1997 struct platform_data *my_data = (struct platform_data *)platform;
1998
1999 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
2000 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
2001 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
2002 } else {
2003 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
2004 return -EINVAL;
2005 }
2006
2007 return 0;
2008}
2009
Banajit Goswami20cdd212015-09-11 01:11:30 -07002010void platform_add_backend_name(char *mixer_path, snd_device_t snd_device,
2011 struct audio_usecase *usecase)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302012{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302013 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2014 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2015 return;
2016 }
2017
Banajit Goswami20cdd212015-09-11 01:11:30 -07002018 if((snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT) &&
2019 !(usecase->type == VOICE_CALL || usecase->type == VOIP_CALL)) {
2020 ALOGI("%s: Not adding vbat speaker device to non voice use cases", __func__);
2021 return;
2022 }
2023
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302024 const char * suffix = backend_tag_table[snd_device];
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302025
2026 if (suffix != NULL) {
2027 strlcat(mixer_path, " ", MIXER_PATH_MAX_LENGTH);
2028 strlcat(mixer_path, suffix, MIXER_PATH_MAX_LENGTH);
2029 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302030}
2031
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302032bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
2033{
2034 bool result = true;
2035
2036 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
2037 platform_get_snd_device_name(snd_device1),
2038 platform_get_snd_device_name(snd_device2));
2039
2040 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_OUT_END)) {
2041 ALOGE("%s: Invalid snd_device = %s", __func__,
2042 platform_get_snd_device_name(snd_device1));
2043 return false;
2044 }
2045 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_OUT_END)) {
2046 ALOGE("%s: Invalid snd_device = %s", __func__,
2047 platform_get_snd_device_name(snd_device2));
2048 return false;
2049 }
2050 const char * be_itf1 = hw_interface_table[snd_device1];
2051 const char * be_itf2 = hw_interface_table[snd_device2];
2052
2053 if (NULL != be_itf1 && NULL != be_itf2) {
Kuirong Wangb9fbb1e2016-05-03 18:36:39 -07002054 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302055 result = false;
2056 } else if (NULL == be_itf1 && NULL != be_itf2) {
2057 result = false;
2058 } else if (NULL != be_itf1 && NULL == be_itf2) {
2059 result = false;
2060 }
2061
2062 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
2063 return result;
2064}
2065
Naresh Tannirue3b18452014-03-04 14:44:27 +05302066int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
2067{
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +05302068 int device_id = -1;
2069
2070 if (is_external_codec && is_misc_usecase(usecase)) {
2071 if (device_type == PCM_PLAYBACK)
2072 device_id = pcm_device_table_of_ext_codec[usecase][0];
2073 else
2074 device_id = pcm_device_table_of_ext_codec[usecase][1];
2075 } else {
2076 if (device_type == PCM_PLAYBACK)
2077 device_id = pcm_device_table[usecase][0];
2078 else
2079 device_id = pcm_device_table[usecase][1];
2080 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302081 return device_id;
2082}
2083
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302084static int find_index(struct name_to_index * table, int32_t len, const char * name)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302085{
2086 int ret = 0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302087 int32_t i;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302088
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302089 if (table == NULL) {
2090 ALOGE("%s: table is NULL", __func__);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302091 ret = -ENODEV;
2092 goto done;
2093 }
2094
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302095 if (name == NULL) {
2096 ALOGE("null key");
2097 ret = -ENODEV;
2098 goto done;
2099 }
2100
2101 for (i=0; i < len; i++) {
2102 const char* tn = table[i].name;
2103 size_t len = strlen(tn);
2104 if (strncmp(tn, name, len) == 0) {
2105 if (strlen(name) != len) {
2106 continue; // substring
2107 }
2108 ret = table[i].index;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302109 goto done;
2110 }
2111 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302112 ALOGE("%s: Could not find index for name = %s",
2113 __func__, name);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302114 ret = -ENODEV;
2115done:
2116 return ret;
2117}
2118
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05302119int platform_set_fluence_type(void *platform, char *value)
2120{
2121 int ret = 0;
2122 int fluence_type = FLUENCE_NONE;
2123 int fluence_flag = NONE_FLAG;
2124 struct platform_data *my_data = (struct platform_data *)platform;
2125 struct audio_device *adev = my_data->adev;
2126
2127 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
2128
2129 /* only dual mic turn on and off is supported as of now through setparameters */
2130 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
2131 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
2132 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
2133 ALOGV("fluence dualmic feature enabled \n");
2134 fluence_type = FLUENCE_DUAL_MIC;
2135 fluence_flag = DMIC_FLAG;
2136 } else {
2137 ALOGE("%s: Failed to set DUALMIC", __func__);
2138 ret = -1;
2139 goto done;
2140 }
2141 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
2142 ALOGV("fluence disabled");
2143 fluence_type = FLUENCE_NONE;
2144 } else {
2145 ALOGE("Invalid fluence value : %s",value);
2146 ret = -1;
2147 goto done;
2148 }
2149
2150 if (fluence_type != my_data->fluence_type) {
2151 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
2152 my_data->fluence_type = fluence_type;
2153 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
2154 }
2155done:
2156 return ret;
2157}
2158
2159int platform_get_fluence_type(void *platform, char *value, uint32_t len)
2160{
2161 int ret = 0;
2162 struct platform_data *my_data = (struct platform_data *)platform;
2163
2164 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
2165 strlcpy(value, "quadmic", len);
2166 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
2167 strlcpy(value, "dualmic", len);
2168 } else if (my_data->fluence_type == FLUENCE_NONE) {
2169 strlcpy(value, "none", len);
2170 } else
2171 ret = -1;
2172
2173 return ret;
2174}
2175
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302176int platform_get_snd_device_index(char *device_name)
2177{
2178 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
2179}
2180
2181int platform_get_usecase_index(const char *usecase_name)
2182{
2183 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
2184}
2185
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302186int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
2187{
2188 int ret = 0;
2189
2190 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2191 ALOGE("%s: Invalid snd_device = %d",
2192 __func__, snd_device);
2193 ret = -EINVAL;
2194 goto done;
2195 }
2196
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302197 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
2198 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302199 acdb_device_table[snd_device] = acdb_id;
2200done:
2201 return ret;
2202}
2203
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07002204int platform_get_default_app_type(void *platform)
2205{
2206 struct platform_data *my_data = (struct platform_data *)platform;
2207
2208 if (my_data->acdb_get_default_app_type)
2209 return my_data->acdb_get_default_app_type();
2210 else
2211 return DEFAULT_APP_TYPE;
2212}
2213
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05302214int platform_get_default_app_type_v2(void *platform __unused,
2215 usecase_type_t type __unused)
Srikanth Uyyalaa1e32352015-10-09 14:48:04 +05302216{
2217 if(type == PCM_CAPTURE)
2218 return DEFAULT_APP_TYPE_TX_PATH;
2219 else
2220 return DEFAULT_APP_TYPE_RX_PATH;
2221}
2222
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07002223int platform_get_snd_device_acdb_id(snd_device_t snd_device)
2224{
2225 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2226 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
2227 return -EINVAL;
2228 }
2229 return acdb_device_table[snd_device];
2230}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302231
2232int platform_set_snd_device_bit_width(snd_device_t snd_device, unsigned int bit_width)
Amit Shekhar5a39c912014-10-14 15:39:30 -07002233{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302234 int ret = 0;
2235
2236 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2237 ALOGE("%s: Invalid snd_device = %d",
2238 __func__, snd_device);
2239 ret = -EINVAL;
2240 goto done;
2241 }
2242
2243 backend_bit_width_table[snd_device] = bit_width;
2244done:
2245 return ret;
Amit Shekhar5a39c912014-10-14 15:39:30 -07002246}
2247
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302248int platform_get_snd_device_bit_width(snd_device_t snd_device)
Amit Shekhar5a39c912014-10-14 15:39:30 -07002249{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302250 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
2251 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
Ashish Jainb449be32015-07-19 05:39:23 -07002252 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302253 }
2254 return backend_bit_width_table[snd_device];
Amit Shekhar5a39c912014-10-14 15:39:30 -07002255}
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302256int platform_set_native_support(int na_mode)
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002257{
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302258 if (NATIVE_AUDIO_MODE_SRC == na_mode || NATIVE_AUDIO_MODE_TRUE_44_1 == na_mode) {
2259 na_props.platform_na_prop_enabled = na_props.ui_na_prop_enabled = true;
2260 na_props.na_mode = na_mode;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302261 ALOGD("%s:napb: native audio playback enabled in (%s) mode v2.0", __func__,
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302262 ((na_mode == NATIVE_AUDIO_MODE_SRC)?"SRC mode":"True 44.1 mode"));
2263 } else {
2264 na_props.platform_na_prop_enabled = false;
2265 na_props.na_mode = NATIVE_AUDIO_MODE_INVALID;
2266 ALOGD("%s:napb: native audio playback disabled", __func__);
2267 }
2268
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002269 return 0;
2270}
2271
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302272int platform_get_native_support()
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002273{
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302274 int ret = NATIVE_AUDIO_MODE_INVALID;
2275 if (na_props.platform_na_prop_enabled &&
2276 na_props.ui_na_prop_enabled) {
2277 ret = na_props.na_mode;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302278 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302279 ALOGV("%s:napb: ui Prop enabled(%d) version(%d)", __func__,
2280 na_props.ui_na_prop_enabled, na_props.na_mode);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302281 return ret;
2282}
2283
2284void native_audio_get_params(struct str_parms *query,
2285 struct str_parms *reply,
2286 char *value, int len)
2287{
2288 int ret;
2289 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
2290 value, len);
2291 if (ret >= 0) {
2292 if (na_props.platform_na_prop_enabled) {
2293 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
2294 na_props.ui_na_prop_enabled ? "true" : "false");
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302295 ALOGV("%s:napb: na_props.ui_na_prop_enabled: %d", __func__,
2296 na_props.ui_na_prop_enabled);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302297 } else {
2298 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
2299 "false");
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302300 ALOGV("%s:napb: native audio not supported: %d", __func__,
2301 na_props.platform_na_prop_enabled);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302302 }
2303 }
2304}
2305
2306int native_audio_set_params(struct platform_data *platform,
2307 struct str_parms *parms, char *value, int len)
2308{
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05302309 int ret = -1;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302310 struct audio_usecase *usecase;
2311 struct listnode *node;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302312 int mode = NATIVE_AUDIO_MODE_INVALID;
2313
Preetam Singh Ranawat53194302016-03-15 16:37:42 +05302314 if (!value)
2315 return ret;
2316
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302317 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO_MODE,
2318 value, len);
2319 if (ret >= 0) {
2320 if (value && !strncmp(value, "src", sizeof("src")))
2321 mode = NATIVE_AUDIO_MODE_SRC;
2322 else if (value && !strncmp(value, "true", sizeof("true")))
2323 mode = NATIVE_AUDIO_MODE_TRUE_44_1;
2324 else {
2325 mode = NATIVE_AUDIO_MODE_INVALID;
2326 ALOGE("%s:napb:native_audio_mode in platform info xml,invalid mode string",
2327 __func__);
2328 }
2329 ALOGD("%s:napb updating mode (%d) from XML",__func__, mode);
2330 platform_set_native_support(mode);
2331 }
2332
2333
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302334
2335 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
2336 value, len);
2337 if (ret >= 0) {
2338 if (na_props.platform_na_prop_enabled) {
Sidipotu Ashok894644d2015-07-06 18:35:03 +05302339 if (!strncmp("true", value, sizeof("true"))) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302340 na_props.ui_na_prop_enabled = true;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302341 ALOGD("%s:napb: native audio feature enabled from UI",
2342 __func__);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05302343 }
2344 else {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302345 na_props.ui_na_prop_enabled = false;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302346 ALOGD("%s:napb: native audio feature disabled from UI",
2347 __func__);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05302348 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302349
2350 str_parms_del(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO);
2351
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302352 /*
2353 * Iterate through the usecase list and trigger device switch for
2354 * all the appropriate usecases
2355 */
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302356 list_for_each(node, &(platform->adev)->usecase_list) {
2357 usecase = node_to_item(node, struct audio_usecase, list);
2358
2359 if (is_offload_usecase(usecase->id) &&
2360 (usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2361 usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) &&
2362 OUTPUT_SAMPLING_RATE_44100 == usecase->stream.out->sample_rate) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302363 ALOGD("%s:napb: triggering dynamic device switch for usecase(%d: %s)"
Sidipotu Ashok894644d2015-07-06 18:35:03 +05302364 " stream(%p), device(%d)", __func__, usecase->id,
Alexy Josephb1379942016-01-29 15:49:38 -08002365 use_case_table[usecase->id], (void*) usecase->stream.out,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302366 usecase->stream.out->devices);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05302367 select_devices(platform->adev, usecase->id);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302368 }
2369 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302370 } else
2371 ALOGD("%s:napb: native audio cannot be enabled from UI",
2372 __func__);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302373 }
2374 return ret;
2375}
2376
Sidipotu Ashokad8fff82016-02-02 10:48:42 +05302377int check_hdset_combo_device(snd_device_t snd_device)
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302378{
2379 int ret = false;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302380
Sidipotu Ashokad8fff82016-02-02 10:48:42 +05302381 if (SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES == snd_device ||
2382 SND_DEVICE_OUT_SPEAKER_AND_LINE == snd_device ||
2383 SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1 == snd_device ||
2384 SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2 == snd_device ||
2385 SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET == snd_device)
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302386 ret = true;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302387
2388 return ret;
2389}
2390
2391
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302392static int platform_get_backend_index(snd_device_t snd_device)
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302393{
2394 int32_t port = DEFAULT_CODEC_BACKEND;
2395
2396 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302397 if (backend_tag_table[snd_device] != NULL) {
2398 if (strncmp(backend_tag_table[snd_device], "headphones-44.1",
2399 sizeof("headphones-44.1")) == 0)
2400 port = HEADPHONE_44_1_BACKEND;
2401 else if (strncmp(backend_tag_table[snd_device], "headphones",
2402 sizeof("headphones")) == 0)
2403 port = HEADPHONE_BACKEND;
2404 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
2405 port = HDMI_RX_BACKEND;
2406 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302407 } else {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302408 ALOGV("%s:napb: Invalid device - %d ", __func__, snd_device);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302409 }
2410
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302411 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port,
2412 snd_device);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302413 return port;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002414}
2415
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05302416int platform_send_audio_calibration(void *platform, struct audio_usecase *usecase,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07002417 int app_type, int sample_rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302418{
2419 struct platform_data *my_data = (struct platform_data *)platform;
2420 int acdb_dev_id, acdb_dev_type;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05302421 int snd_device = SND_DEVICE_OUT_SPEAKER;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302422 int new_snd_device[SND_DEVICE_OUT_END];
2423 int i, num_devices = 1;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05302424
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302425 if (usecase->type == PCM_PLAYBACK)
Naresh Tannirucc7c4de2015-03-10 16:19:23 +05302426 snd_device = usecase->out_snd_device;
Karthik Reddy Katta81c42612015-11-13 17:49:07 +05302427 else if ((usecase->type == PCM_CAPTURE) &&
2428 voice_is_in_call_rec_stream(usecase->stream.in))
2429 snd_device = voice_get_incall_rec_snd_device(usecase->in_snd_device);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302430 else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Naresh Tannirucc7c4de2015-03-10 16:19:23 +05302431 snd_device = usecase->in_snd_device;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08002432 acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(snd_device)];
Naresh Tannirue3b18452014-03-04 14:44:27 +05302433
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302434 if(!platform_can_split_snd_device(platform, snd_device, &num_devices, new_snd_device)) {
2435 new_snd_device[0] = snd_device;
Naresh Tanniru2727f822015-05-11 15:27:08 +05302436 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302437
2438 for (i = 0; i < num_devices; i++) {
2439 acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(new_snd_device[i])];
2440
2441 // Do not use Rx path default app type for TX path
2442 if ((usecase->type == PCM_CAPTURE) && (app_type == DEFAULT_APP_TYPE_RX_PATH)) {
2443 ALOGD("Resetting app type for Tx path to default");
2444 app_type = DEFAULT_APP_TYPE_TX_PATH;
2445 }
2446 if (acdb_dev_id < 0) {
2447 ALOGE("%s: Could not find acdb id for device(%d)",
2448 __func__, new_snd_device[i]);
2449 return -EINVAL;
2450 }
2451 if (my_data->acdb_send_audio_cal) {
2452 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
2453 __func__, new_snd_device[i], acdb_dev_id);
2454 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
2455 new_snd_device[i] < SND_DEVICE_OUT_END)
2456 acdb_dev_type = ACDB_DEV_TYPE_OUT;
2457 else
2458 acdb_dev_type = ACDB_DEV_TYPE_IN;
2459 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
2460 sample_rate);
2461 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302462 }
2463 return 0;
2464}
2465
2466int platform_switch_voice_call_device_pre(void *platform)
2467{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302468 struct platform_data *my_data = (struct platform_data *)platform;
2469 int ret = 0;
2470
2471 if (my_data->csd != NULL &&
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07002472 voice_is_in_call(my_data->adev)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302473 /* This must be called before disabling mixer controls on APQ side */
2474 ret = my_data->csd->disable_device();
2475 if (ret < 0) {
2476 ALOGE("%s: csd_client_disable_device, failed, error %d",
2477 __func__, ret);
2478 }
2479 }
2480 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302481}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302482
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302483int platform_switch_voice_call_enable_device_config(void *platform,
2484 snd_device_t out_snd_device,
2485 snd_device_t in_snd_device)
2486{
2487 struct platform_data *my_data = (struct platform_data *)platform;
2488 int acdb_rx_id, acdb_tx_id;
2489 int ret = 0;
2490
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302491 if (my_data->csd == NULL)
2492 return ret;
2493
Banajit Goswami20cdd212015-09-11 01:11:30 -07002494 if ((out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
2495 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT) &&
2496 audio_extn_spkr_prot_is_enabled()) {
2497 if (my_data->is_vbat_speaker)
2498 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT];
2499 else
2500 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
2501 } else
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302502 acdb_rx_id = acdb_device_table[out_snd_device];
2503
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302504 acdb_tx_id = acdb_device_table[in_snd_device];
2505
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302506 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2507 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
2508 if (ret < 0) {
2509 ALOGE("%s: csd_enable_device_config, failed, error %d",
2510 __func__, ret);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302511 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302512 } else {
2513 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2514 acdb_rx_id, acdb_tx_id);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302515 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302516
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302517 return ret;
2518}
2519
Naresh Tannirue3b18452014-03-04 14:44:27 +05302520int platform_switch_voice_call_device_post(void *platform,
2521 snd_device_t out_snd_device,
2522 snd_device_t in_snd_device)
2523{
2524 struct platform_data *my_data = (struct platform_data *)platform;
2525 int acdb_rx_id, acdb_tx_id;
2526
2527 if (my_data->acdb_send_voice_cal == NULL) {
2528 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
2529 } else {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302530 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2531 audio_extn_spkr_prot_is_enabled())
2532 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
2533
Naresh Tannirue3b18452014-03-04 14:44:27 +05302534 acdb_rx_id = acdb_device_table[out_snd_device];
2535 acdb_tx_id = acdb_device_table[in_snd_device];
2536
2537 if (acdb_rx_id > 0 && acdb_tx_id > 0)
2538 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
2539 else
2540 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2541 acdb_rx_id, acdb_tx_id);
2542 }
2543
2544 return 0;
2545}
2546
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302547int platform_switch_voice_call_usecase_route_post(void *platform,
2548 snd_device_t out_snd_device,
2549 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302550{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302551 struct platform_data *my_data = (struct platform_data *)platform;
2552 int acdb_rx_id, acdb_tx_id;
2553 int ret = 0;
2554
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302555 if (my_data->csd == NULL)
2556 return ret;
2557
Banajit Goswami20cdd212015-09-11 01:11:30 -07002558 if ((out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
2559 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT) &&
2560 audio_extn_spkr_prot_is_enabled()) {
2561 if (my_data->is_vbat_speaker)
2562 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT];
2563 else
2564 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
2565 } else
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302566 acdb_rx_id = acdb_device_table[out_snd_device];
2567
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302568 acdb_tx_id = acdb_device_table[in_snd_device];
2569
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302570 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2571 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2572 my_data->adev->acdb_settings);
2573 if (ret < 0) {
2574 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302575 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302576 } else {
2577 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2578 acdb_rx_id, acdb_tx_id);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302579 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302580
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302581 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302582}
2583
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302584int platform_start_voice_call(void *platform, uint32_t vsid)
2585{
2586 struct platform_data *my_data = (struct platform_data *)platform;
2587 int ret = 0;
2588
2589 if (my_data->csd != NULL) {
2590 ret = my_data->csd->start_voice(vsid);
2591 if (ret < 0) {
2592 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2593 }
2594 }
2595 return ret;
2596}
2597
2598int platform_stop_voice_call(void *platform, uint32_t vsid)
2599{
2600 struct platform_data *my_data = (struct platform_data *)platform;
2601 int ret = 0;
2602
2603 if (my_data->csd != NULL) {
2604 ret = my_data->csd->stop_voice(vsid);
2605 if (ret < 0) {
2606 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2607 }
2608 }
2609 return ret;
2610}
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002611
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05302612int platform_get_sample_rate(void *platform __unused,
2613 uint32_t *rate __unused)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302614{
2615 return 0;
2616}
2617
2618int platform_set_voice_volume(void *platform, int volume)
2619{
2620 struct platform_data *my_data = (struct platform_data *)platform;
2621 struct audio_device *adev = my_data->adev;
2622 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302623 const char *mixer_ctl_name = "Voice Rx Gain";
2624 int vol_index = 0, ret = 0;
2625 uint32_t set_values[ ] = {0,
2626 ALL_SESSION_VSID,
2627 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05302628
2629 // Voice volume levels are mapped to adsp volume levels as follows.
2630 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2631 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302632 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
2633 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302634
2635 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2636 if (!ctl) {
2637 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2638 __func__, mixer_ctl_name);
2639 return -EINVAL;
2640 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302641 ALOGV("Setting voice volume index: %d", set_values[0]);
2642 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05302643
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302644 if (my_data->csd != NULL) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302645 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2646 DEFAULT_VOLUME_RAMP_DURATION_MS);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302647 if (ret < 0) {
2648 ALOGE("%s: csd_volume error %d", __func__, ret);
2649 }
2650 }
2651 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302652}
2653
2654int platform_set_mic_mute(void *platform, bool state)
2655{
2656 struct platform_data *my_data = (struct platform_data *)platform;
2657 struct audio_device *adev = my_data->adev;
2658 struct mixer_ctl *ctl;
2659 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302660 int ret = 0;
2661 uint32_t set_values[ ] = {0,
2662 ALL_SESSION_VSID,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302663 DEFAULT_MUTE_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05302664
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302665 set_values[0] = state;
2666 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2667 if (!ctl) {
2668 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2669 __func__, mixer_ctl_name);
2670 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302671 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302672 ALOGV("Setting voice mute state: %d", state);
2673 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05302674
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302675 if (my_data->csd != NULL) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302676 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2677 DEFAULT_MUTE_RAMP_DURATION_MS);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302678 if (ret < 0) {
2679 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
2680 }
2681 }
2682 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302683}
2684
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08002685int platform_set_device_mute(void *platform, bool state, char *dir)
2686{
2687 struct platform_data *my_data = (struct platform_data *)platform;
2688 struct audio_device *adev = my_data->adev;
2689 struct mixer_ctl *ctl;
2690 char *mixer_ctl_name = NULL;
2691 int ret = 0;
2692 uint32_t set_values[ ] = {0,
2693 ALL_SESSION_VSID,
2694 0};
2695 if(dir == NULL) {
2696 ALOGE("%s: Invalid direction:%s", __func__, dir);
2697 return -EINVAL;
2698 }
2699
2700 if (!strncmp("rx", dir, sizeof("rx"))) {
2701 mixer_ctl_name = "Voice Rx Device Mute";
2702 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2703 mixer_ctl_name = "Voice Tx Device Mute";
2704 } else {
2705 return -EINVAL;
2706 }
2707
2708 set_values[0] = state;
2709 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2710 if (!ctl) {
2711 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2712 __func__, mixer_ctl_name);
2713 return -EINVAL;
2714 }
2715
2716 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2717 __func__,state, mixer_ctl_name);
2718 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2719
2720 return ret;
2721}
2722
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302723bool platform_can_split_snd_device(void *platform,
2724 snd_device_t snd_device,
2725 int *num_devices,
2726 snd_device_t *new_snd_devices)
2727{
2728 bool status = false;
2729 struct platform_data *my_data = (struct platform_data *)platform;
2730
2731 if (NULL == num_devices || NULL == new_snd_devices) {
2732 ALOGE("%s: NULL pointer ..", __func__);
2733 return false;
2734 }
2735
2736 /*
2737 * If wired headset/headphones/line devices share the same backend
2738 * with speaker/earpiece this routine returns false.
2739 */
2740 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2741 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2742 *num_devices = 2;
2743
2744 if (my_data->is_vbat_speaker)
2745 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_VBAT;
2746 else if (my_data->is_wsa_speaker)
2747 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
2748 else
2749 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2750
2751 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
2752 status = true;
2753 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI &&
2754 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HDMI)) {
2755 *num_devices = 2;
2756
2757 if (my_data->is_vbat_speaker)
2758 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_VBAT;
2759 else if (my_data->is_wsa_speaker)
2760 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
2761 else
2762 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2763
2764 new_snd_devices[1] = SND_DEVICE_OUT_HDMI;
2765 status = true;
2766 }
2767
2768 ALOGD("%s: snd_device(%d) num devices(%d) new_snd_devices(%d)", __func__,
2769 snd_device, *num_devices, *new_snd_devices);
2770
2771 return status;
2772}
2773
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002774snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *out)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302775{
2776 struct platform_data *my_data = (struct platform_data *)platform;
2777 struct audio_device *adev = my_data->adev;
2778 audio_mode_t mode = adev->mode;
2779 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002780 audio_devices_t devices = out->devices;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302781 unsigned int sample_rate = out->sample_rate;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302782 int na_mode = platform_get_native_support();
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302783#ifdef RECORD_PLAY_CONCURRENCY
2784 bool use_voip_out_devices = false;
2785 bool prop_rec_play_enabled = false;
2786 char recConcPropValue[PROPERTY_VALUE_MAX];
2787
2788 if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) {
2789 prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4);
2790 }
2791 use_voip_out_devices = prop_rec_play_enabled &&
2792 (my_data->rec_play_conc_set || adev->mode == AUDIO_MODE_IN_COMMUNICATION);
2793 ALOGV("platform_get_output_snd_device use_voip_out_devices : %d",use_voip_out_devices);
2794#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +05302795
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302796 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2797 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2798 int channel_count = popcount(channel_mask);
2799
Naresh Tannirue3b18452014-03-04 14:44:27 +05302800 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2801 if (devices == AUDIO_DEVICE_NONE ||
2802 devices & AUDIO_DEVICE_BIT_IN) {
2803 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2804 goto exit;
2805 }
2806
Shiv Maliyappanahallibd401262015-08-17 11:02:21 -07002807 if (popcount(devices) == 2) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302808 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2809 AUDIO_DEVICE_OUT_SPEAKER)) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302810 if (my_data->external_spk_1)
2811 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
2812 else if (my_data->external_spk_2)
2813 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
2814 else
2815 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05302816 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2817 AUDIO_DEVICE_OUT_SPEAKER)) {
2818 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302819 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2820 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302821 if (audio_extn_get_anc_enabled())
2822 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302823 else if (my_data->external_spk_1)
2824 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
2825 else if (my_data->external_spk_2)
2826 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302827 else
2828 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302829 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2830 AUDIO_DEVICE_OUT_SPEAKER)) {
2831 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302832 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
2833 AUDIO_DEVICE_OUT_SPEAKER)) {
2834 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302835 } else {
2836 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2837 goto exit;
2838 }
2839 if (snd_device != SND_DEVICE_NONE) {
2840 goto exit;
2841 }
2842 }
2843
2844 if (popcount(devices) != 1) {
2845 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2846 goto exit;
2847 }
2848
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05302849 if ((mode == AUDIO_MODE_IN_CALL) ||
2850 voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302851 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05302852 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2853 devices & AUDIO_DEVICE_OUT_LINE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302854 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
2855 !voice_extn_compress_voip_is_active(adev)) {
2856 switch (adev->voice.tty_mode) {
2857 case TTY_MODE_FULL:
2858 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
2859 break;
2860 case TTY_MODE_VCO:
2861 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
2862 break;
2863 case TTY_MODE_HCO:
2864 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2865 break;
2866 default:
2867 ALOGE("%s: Invalid TTY mode (%#x)",
2868 __func__, adev->voice.tty_mode);
2869 }
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05302870 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2871 snd_device = SND_DEVICE_OUT_VOICE_LINE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302872 } else if (audio_extn_get_anc_enabled()) {
2873 if (audio_extn_should_use_fb_anc())
2874 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
2875 else
2876 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
2877 } else {
2878 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2879 }
2880 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07002881 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302882 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2883 else
2884 snd_device = SND_DEVICE_OUT_BT_SCO;
2885 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Banajit Goswami20cdd212015-09-11 01:11:30 -07002886 if (my_data->is_vbat_speaker)
2887 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_VBAT;
2888 else if (my_data->is_wsa_speaker)
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05302889 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_WSA;
2890 else
2891 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302892 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2893 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
2894 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2895 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
2896 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
2897 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
2898 if (audio_extn_should_use_handset_anc(channel_count))
2899 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
2900 else
2901 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +05302902 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2903 snd_device = SND_DEVICE_OUT_VOICE_TX;
2904
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302905 if (snd_device != SND_DEVICE_NONE) {
2906 goto exit;
2907 }
2908 }
2909
Naresh Tannirue3b18452014-03-04 14:44:27 +05302910 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2911 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302912 if (OUTPUT_SAMPLING_RATE_44100 == sample_rate &&
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302913 NATIVE_AUDIO_MODE_SRC == na_mode &&
Sidipotu Ashokbffd2202015-08-20 14:06:55 +05302914 !audio_extn_get_anc_enabled()) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302915
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05302916 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05302917
2918 } else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302919 && audio_extn_get_anc_enabled()) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302920#ifdef RECORD_PLAY_CONCURRENCY
2921 if (use_voip_out_devices) {
2922 // ANC should be disabled for voip concurrency
2923 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
2924 } else
2925#endif
2926 {
2927 if (audio_extn_should_use_fb_anc())
2928 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
2929 else
2930 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
2931 }
2932 } else {
2933#ifdef RECORD_PLAY_CONCURRENCY
2934 if (use_voip_out_devices)
2935 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302936 else
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302937#endif
2938 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302939 }
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05302940 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2941 snd_device = SND_DEVICE_OUT_LINE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302942 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302943#ifdef RECORD_PLAY_CONCURRENCY
2944 if (use_voip_out_devices) {
2945 snd_device = SND_DEVICE_OUT_VOIP_SPEAKER;
2946 } else
2947#endif
2948 {
2949 if (adev->speaker_lr_swap)
2950 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2951 else
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05302952 {
Banajit Goswami20cdd212015-09-11 01:11:30 -07002953 if (my_data->is_vbat_speaker)
2954 snd_device = SND_DEVICE_OUT_SPEAKER_VBAT;
2955 else if (my_data->is_wsa_speaker)
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05302956 snd_device = SND_DEVICE_OUT_SPEAKER_WSA;
2957 else
2958 snd_device = SND_DEVICE_OUT_SPEAKER;
2959 }
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302960 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302961 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07002962 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302963 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2964 else
2965 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302966 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2967 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302968 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2969 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08002970 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
2971 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302972 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2973 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
2974 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302975 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302976#ifdef RECORD_PLAY_CONCURRENCY
2977 if (use_voip_out_devices)
2978 snd_device = SND_DEVICE_OUT_VOIP_HANDSET;
2979 else
2980#endif
2981 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302982 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08002983 channel_count = audio_extn_get_afe_proxy_channel_count();
2984 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
2985 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302986 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302987 } else {
2988 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2989 }
2990exit:
2991 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2992 return snd_device;
2993}
2994
2995snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2996{
2997 struct platform_data *my_data = (struct platform_data *)platform;
2998 struct audio_device *adev = my_data->adev;
2999 audio_source_t source = (adev->active_input == NULL) ?
3000 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
3001
3002 audio_mode_t mode = adev->mode;
3003 audio_devices_t in_device = ((adev->active_input == NULL) ?
3004 AUDIO_DEVICE_NONE : adev->active_input->device)
3005 & ~AUDIO_DEVICE_BIT_IN;
3006 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
3007 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
3008 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303009 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05303010
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303011 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
3012 __func__, out_device, in_device, channel_count, channel_mask);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303013 if (my_data->external_mic) {
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05303014 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
3015 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303016 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3017 out_device & AUDIO_DEVICE_OUT_EARPIECE ||
3018 out_device & AUDIO_DEVICE_OUT_SPEAKER )
3019 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
3020 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
3021 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3022 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
3023 }
3024 }
3025
3026 if (snd_device != AUDIO_DEVICE_NONE)
3027 goto exit;
3028
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05303029 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
Satya Krishna Pindiproli2aaa6152014-05-21 15:05:22 +05303030 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303031 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
3032 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05303033 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05303034 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
3035 out_device & AUDIO_DEVICE_OUT_LINE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303036 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05303037 case TTY_MODE_FULL:
3038 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
3039 break;
3040 case TTY_MODE_VCO:
3041 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
3042 break;
3043 case TTY_MODE_HCO:
3044 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
3045 break;
3046 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303047 ALOGE("%s: Invalid TTY mode (%#x)",
3048 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05303049 }
3050 goto exit;
3051 }
3052 }
3053 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05303054 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3055 out_device & AUDIO_DEVICE_OUT_LINE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303056 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
Sidipotu Ashok3bcca232014-11-07 14:41:58 +05303057 audio_extn_should_use_handset_anc(channel_count) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303058 my_data->fluence_type != FLUENCE_NONE &&
3059 my_data->source_mic_type & SOURCE_DUAL_MIC) {
Sidipotu Ashok3bcca232014-11-07 14:41:58 +05303060 snd_device = SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC;
3061 adev->acdb_settings |= DMIC_FLAG;
3062 ALOGD("Selecting AANC, Fluence combo device");
3063 } else if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303064 audio_extn_should_use_handset_anc(channel_count)) {
3065 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303066 adev->acdb_settings |= ANC_FLAG;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303067 } else if (my_data->fluence_type == FLUENCE_NONE ||
3068 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05303069 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05303070 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003071 platform_set_echo_reference(adev, true, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05303072 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303073 snd_device = SND_DEVICE_IN_VOICE_DMIC;
3074 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303075 }
3076 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3077 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303078 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003079 platform_set_echo_reference(adev, true, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05303080 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07003081 if (adev->bt_wb_speech_enabled) {
3082 if (adev->bluetooth_nrec)
3083 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3084 else
3085 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
3086 } else {
3087 if (adev->bluetooth_nrec)
3088 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3089 else
3090 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
3091 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05303092 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303093 if (my_data->fluence_type != FLUENCE_NONE &&
3094 my_data->fluence_in_voice_call &&
3095 my_data->fluence_in_spkr_mode) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303096 if((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
3097 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303098 adev->acdb_settings |= QMIC_FLAG;
3099 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
3100 } else {
3101 adev->acdb_settings |= DMIC_FLAG;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05303102 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
3103 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
3104 else
3105 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303106 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05303107 } else {
3108 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05303109 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003110 platform_set_echo_reference(adev, true, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05303111 }
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +05303112 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX)
3113 snd_device = SND_DEVICE_IN_VOICE_RX;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303114 } else if (source == AUDIO_SOURCE_CAMCORDER) {
3115 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
3116 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303117 if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
3118 (my_data->source_mic_type & SOURCE_DUAL_MIC) &&
3119 (channel_count == 2))
kunleiz8f7e9e22014-06-24 15:12:02 +08003120 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
kunleiz18a33302014-05-30 09:52:25 +08003121 else
3122 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303123 }
3124 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
3125 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303126 if (my_data->fluence_in_voice_rec && channel_count == 1) {
3127 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
3128 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3129 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
3130 } else if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
3131 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3132 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
3133 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
3134 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3135 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
3136 }
3137 platform_set_echo_reference(adev, true, out_device);
3138 } else if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3139 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3140 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303141 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303142 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
3143 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3144 snd_device = SND_DEVICE_IN_THREE_MIC;
3145 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
3146 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3147 snd_device = SND_DEVICE_IN_QUAD_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303148 }
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303149 if (snd_device == SND_DEVICE_NONE) {
3150 if (adev->active_input->enable_ns)
3151 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
3152 else
3153 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
3154 }
3155 }
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05303156 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
3157 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
3158 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
3159 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
3160 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
3161 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
3162 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
3163 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3164 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
3165 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
3166 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
3167 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
3168 } else {
3169 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
3170 }
3171 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3172 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
3173 }
Karthik Reddy Kattaf621ec72014-11-21 16:37:38 +05303174 } else if ((source == AUDIO_SOURCE_VOICE_COMMUNICATION) ||
3175 (mode == AUDIO_MODE_IN_COMMUNICATION)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05303176 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
3177 in_device = AUDIO_DEVICE_IN_BACK_MIC;
3178 if (adev->active_input) {
Venkata Narendra Kumar Gutta35b5cc52015-05-25 15:32:03 +05303179 if (my_data->fluence_type != FLUENCE_NONE &&
3180 adev->active_input->enable_aec &&
3181 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05303182 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303183 if (my_data->fluence_in_spkr_mode) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303184 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
3185 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303186 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303187 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
3188 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303189 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
3190 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
3191 else
3192 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
3193 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303194 adev->acdb_settings |= DMIC_FLAG;
3195 } else
3196 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303197 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303198 if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
3199 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303200 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
3201 adev->acdb_settings |= DMIC_FLAG;
3202 } else
3203 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303204 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303205 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303206 }
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003207 platform_set_echo_reference(adev, true, out_device);
Venkata Narendra Kumar Gutta35b5cc52015-05-25 15:32:03 +05303208 } else if (my_data->fluence_type != FLUENCE_NONE &&
3209 adev->active_input->enable_aec) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303210 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303211 if (my_data->fluence_in_spkr_mode) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303212 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
3213 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303214 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303215 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
3216 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303217 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
3218 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
3219 else
3220 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
3221 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303222 adev->acdb_settings |= DMIC_FLAG;
3223 } else
3224 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
3225 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303226 if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
3227 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303228 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
3229 adev->acdb_settings |= DMIC_FLAG;
3230 } else
3231 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
3232 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3233 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
3234 }
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003235 platform_set_echo_reference(adev, true, out_device);
Venkata Narendra Kumar Gutta35b5cc52015-05-25 15:32:03 +05303236 } else if (my_data->fluence_type != FLUENCE_NONE &&
3237 adev->active_input->enable_ns) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303238 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303239 if (my_data->fluence_in_spkr_mode) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303240 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
3241 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303242 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_NS;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303243 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
3244 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303245 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
3246 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
3247 else
3248 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
3249 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303250 adev->acdb_settings |= DMIC_FLAG;
3251 } else
3252 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
3253 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303254 if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
3255 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303256 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
3257 adev->acdb_settings |= DMIC_FLAG;
3258 } else
3259 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
3260 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3261 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
3262 }
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003263 platform_set_echo_reference(adev, false, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05303264 } else
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003265 platform_set_echo_reference(adev, false, out_device);
Naresh Tannirue3b18452014-03-04 14:44:27 +05303266 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303267 } else if (source == AUDIO_SOURCE_MIC) {
3268 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
3269 channel_count == 1 ) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303270 if(my_data->fluence_in_audio_rec) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303271 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
3272 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303273 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003274 platform_set_echo_reference(adev, true, out_device);
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303275 } else if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
3276 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
3277 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
3278 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
3279 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303280 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07003281 platform_set_echo_reference(adev, true, out_device);
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05303282 }
3283 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303284 }
Mingming Yin12125e82015-10-26 20:40:36 -07003285 } else if (source == AUDIO_SOURCE_FM_TUNER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303286 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303287 } else if (source == AUDIO_SOURCE_DEFAULT) {
3288 goto exit;
3289 }
3290
Shiv Maliyappanahalli5a10aea2015-07-02 10:36:23 -07003291 if (adev->active_input && (audio_extn_ssr_get_stream() == adev->active_input))
3292 snd_device = SND_DEVICE_IN_THREE_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303293
3294 if (snd_device != SND_DEVICE_NONE) {
3295 goto exit;
3296 }
3297
3298 if (in_device != AUDIO_DEVICE_NONE &&
3299 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
3300 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
3301 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Shiv Maliyappanahalli5a10aea2015-07-02 10:36:23 -07003302 if (adev->active_input && (audio_extn_ssr_get_stream() == adev->active_input))
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303303 snd_device = SND_DEVICE_IN_QUAD_MIC;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303304 else if ((my_data->fluence_type & (FLUENCE_DUAL_MIC | FLUENCE_QUAD_MIC)) &&
3305 (channel_count == 2) && (my_data->source_mic_type & SOURCE_DUAL_MIC))
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303306 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
3307 else
3308 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303309 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
3310 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
3311 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
3312 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3313 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07003314 if (adev->bt_wb_speech_enabled) {
3315 if (adev->bluetooth_nrec)
3316 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3317 else
3318 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
3319 } else {
3320 if (adev->bluetooth_nrec)
3321 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3322 else
3323 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
3324 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05303325 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
3326 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303327 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
3328 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
3329 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Mingming Yin12125e82015-10-26 20:40:36 -07003330 } else if (in_device & AUDIO_DEVICE_IN_FM_TUNER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303331 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303332 } else {
3333 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
3334 ALOGW("%s: Using default handset-mic", __func__);
3335 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3336 }
3337 } else {
3338 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
3339 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3340 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
3341 snd_device = SND_DEVICE_IN_HEADSET_MIC;
3342 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303343 if ((channel_count > 1) && (my_data->source_mic_type & SOURCE_DUAL_MIC))
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303344 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
3345 else
3346 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tanniru9c4ba542015-11-06 18:01:09 +05303347 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
3348 out_device & AUDIO_DEVICE_OUT_LINE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05303349 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3350 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07003351 if (adev->bt_wb_speech_enabled) {
3352 if (adev->bluetooth_nrec)
3353 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
3354 else
3355 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
3356 } else {
3357 if (adev->bluetooth_nrec)
3358 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
3359 else
3360 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
3361 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05303362 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3363 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303364 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
3365 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
3366 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303367 } else {
3368 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
3369 ALOGW("%s: Using default handset-mic", __func__);
3370 snd_device = SND_DEVICE_IN_HANDSET_MIC;
3371 }
3372 }
3373exit:
3374 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
3375 return snd_device;
3376}
3377
3378int platform_set_hdmi_channels(void *platform, int channel_count)
3379{
3380 struct platform_data *my_data = (struct platform_data *)platform;
3381 struct audio_device *adev = my_data->adev;
3382 struct mixer_ctl *ctl;
3383 const char *channel_cnt_str = NULL;
3384 const char *mixer_ctl_name = "HDMI_RX Channels";
3385 switch (channel_count) {
3386 case 8:
3387 channel_cnt_str = "Eight"; break;
3388 case 7:
3389 channel_cnt_str = "Seven"; break;
3390 case 6:
3391 channel_cnt_str = "Six"; break;
3392 case 5:
3393 channel_cnt_str = "Five"; break;
3394 case 4:
3395 channel_cnt_str = "Four"; break;
3396 case 3:
3397 channel_cnt_str = "Three"; break;
3398 default:
3399 channel_cnt_str = "Two"; break;
3400 }
3401 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3402 if (!ctl) {
3403 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3404 __func__, mixer_ctl_name);
3405 return -EINVAL;
3406 }
3407 ALOGV("HDMI channel count: %s", channel_cnt_str);
3408 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3409 return 0;
3410}
3411
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303412int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05303413{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303414 int channel_count;
3415 int max_channels = 2;
3416 int i = 0, ret = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303417 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303418 edid_audio_info *info = NULL;
3419 ret = platform_get_edid_info(platform);
3420 info = (edid_audio_info *)my_data->edid_info;
Naresh Tannirue3b18452014-03-04 14:44:27 +05303421
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303422 if(ret == 0 && info != NULL) {
3423 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
3424 ALOGV("%s:format %d channel %d", __func__,
3425 info->audio_blocks_array[i].format_id,
3426 info->audio_blocks_array[i].channels);
3427 if (info->audio_blocks_array[i].format_id == LPCM) {
3428 channel_count = info->audio_blocks_array[i].channels;
3429 if (channel_count > max_channels) {
3430 max_channels = channel_count;
3431 }
3432 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303433 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05303434 }
3435
3436 return max_channels;
3437}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303438
3439static int platform_set_slowtalk(struct platform_data *my_data, bool state)
3440{
3441 int ret = 0;
3442 struct audio_device *adev = my_data->adev;
3443 struct mixer_ctl *ctl;
3444 const char *mixer_ctl_name = "Slowtalk Enable";
3445 uint32_t set_values[ ] = {0,
3446 ALL_SESSION_VSID};
3447
3448 set_values[0] = state;
3449 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3450 if (!ctl) {
3451 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3452 __func__, mixer_ctl_name);
3453 ret = -EINVAL;
3454 } else {
3455 ALOGV("Setting slowtalk state: %d", state);
3456 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
3457 my_data->slowtalk = state;
3458 }
3459
3460 if (my_data->csd != NULL) {
3461 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
3462 if (ret < 0) {
3463 ALOGE("%s: csd_client_disable_device, failed, error %d",
3464 __func__, ret);
3465 }
3466 }
3467 return ret;
3468}
3469
Avinash Vaishd5fa4572014-09-15 14:41:14 +05303470static int set_hd_voice(struct platform_data *my_data, bool state)
3471{
3472 struct audio_device *adev = my_data->adev;
3473 struct mixer_ctl *ctl;
3474 const char *mixer_ctl_name = "HD Voice Enable";
3475 int ret = 0;
3476 uint32_t set_values[ ] = {0,
3477 ALL_SESSION_VSID};
3478
3479 set_values[0] = state;
3480 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3481 if (!ctl) {
3482 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3483 __func__, mixer_ctl_name);
3484 ret = -EINVAL;
3485 } else {
3486 ALOGV("Setting HD Voice state: %d", state);
3487 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
3488 my_data->hd_voice = state;
3489 }
3490
3491 return ret;
3492}
3493
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303494int platform_set_parameters(void *platform, struct str_parms *parms)
3495{
3496 struct platform_data *my_data = (struct platform_data *)platform;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303497 char value[256] = {0};
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05303498 int len;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303499 int ret = 0, err;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303500 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303501
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303502 kv_pairs = str_parms_to_str(parms);
Venkata Narendra Kumar Gutta7c131ef2015-11-17 14:15:57 +05303503 len = strlen(kv_pairs);
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303504 ALOGV("%s: enter: - %s", __func__, kv_pairs);
3505 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303506
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303507 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
3508 if (err >= 0) {
3509 bool state = false;
3510 if (!strncmp("true", value, sizeof("true"))) {
3511 state = true;
3512 }
3513
3514 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
3515 ret = platform_set_slowtalk(my_data, state);
3516 if (ret)
3517 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
3518 }
3519
Avinash Vaishd5fa4572014-09-15 14:41:14 +05303520 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, sizeof(value));
3521 if (err >= 0) {
3522 bool state = false;
3523 if (!strncmp("true", value, sizeof("true"))) {
3524 state = true;
3525 }
3526
3527 str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE);
3528 if (my_data->hd_voice != state) {
3529 ret = set_hd_voice(my_data, state);
3530 if (ret)
3531 ALOGE("%s: Failed to set HD voice err: %d", __func__, ret);
3532 } else {
3533 ALOGV("%s: HD Voice already set to %d", __func__, state);
3534 }
3535 }
3536
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303537 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
3538 value, sizeof(value));
3539 if (err >= 0) {
3540 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
3541
3542 if (my_data->acdb_reload_vocvoltable == NULL) {
3543 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
3544 } else if (!strcmp(value, "on")) {
3545 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
3546 my_data->voice_feature_set = 1;
3547 }
3548 } else {
3549 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
3550 my_data->voice_feature_set = 0;
3551 }
3552 }
3553 }
3554
Karthik Reddy Katta8513f432016-04-12 14:29:27 +05303555 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_RELOAD_ACDB,
3556 value, sizeof(value));
3557 if (err >= 0) {
3558 str_parms_del(parms, AUDIO_PARAMETER_KEY_RELOAD_ACDB);
3559
3560 my_data->acdb_reload(value, my_data->snd_card_name,
3561 my_data->cvd_version, my_data->metainfo_key);
3562
3563 }
3564
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05303565#ifdef RECORD_PLAY_CONCURRENCY
3566 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_REC_PLAY_CONC, value, sizeof(value));
3567 if (err >= 0) {
3568 if (!strncmp("true", value, sizeof("true"))) {
3569 ALOGD("setting record playback concurrency to true");
3570 my_data->rec_play_conc_set = true;
3571 } else {
3572 ALOGD("setting record playback concurrency to false");
3573 my_data->rec_play_conc_set = false;
3574 }
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05303575 }
3576#endif
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303577
3578 err = str_parms_get_str(parms, PLATFORM_MAX_MIC_COUNT,
3579 value, sizeof(value));
3580 if (err >= 0) {
3581 str_parms_del(parms, PLATFORM_MAX_MIC_COUNT);
3582 my_data->max_mic_count = atoi(value);
3583 ALOGV("%s: max_mic_count %d", __func__, my_data->max_mic_count);
3584 }
3585
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303586 native_audio_set_params(platform, parms, value, sizeof(value));
Venkata Narendra Kumar Gutta7c131ef2015-11-17 14:15:57 +05303587 audio_extn_spkr_prot_set_parameters(parms, value, len);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303588 ALOGV("%s: exit with code(%d)", __func__, ret);
3589 return ret;
3590}
3591
3592int platform_set_incall_recording_session_id(void *platform,
3593 uint32_t session_id, int rec_mode)
3594{
3595 int ret = 0;
3596 struct platform_data *my_data = (struct platform_data *)platform;
3597 struct audio_device *adev = my_data->adev;
3598 struct mixer_ctl *ctl;
3599 const char *mixer_ctl_name = "Voc VSID";
3600 int num_ctl_values;
3601 int i;
3602
3603 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3604 if (!ctl) {
3605 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3606 __func__, mixer_ctl_name);
3607 ret = -EINVAL;
3608 } else {
3609 num_ctl_values = mixer_ctl_get_num_values(ctl);
3610 for (i = 0; i < num_ctl_values; i++) {
3611 if (mixer_ctl_set_value(ctl, i, session_id)) {
3612 ALOGV("Error: invalid session_id: %x", session_id);
3613 ret = -EINVAL;
3614 break;
3615 }
3616 }
3617 }
3618
3619 if (my_data->csd != NULL) {
3620 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
3621 if (ret < 0) {
3622 ALOGE("%s: csd_client_start_record failed, error %d",
3623 __func__, ret);
3624 }
3625 }
3626
3627 return ret;
3628}
3629
3630int platform_stop_incall_recording_usecase(void *platform)
3631{
3632 int ret = 0;
3633 struct platform_data *my_data = (struct platform_data *)platform;
3634
3635 if (my_data->csd != NULL) {
3636 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
3637 if (ret < 0) {
3638 ALOGE("%s: csd_client_stop_record failed, error %d",
3639 __func__, ret);
3640 }
3641 }
3642
3643 return ret;
3644}
3645
3646int platform_start_incall_music_usecase(void *platform)
3647{
3648 int ret = 0;
3649 struct platform_data *my_data = (struct platform_data *)platform;
3650
3651 if (my_data->csd != NULL) {
3652 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3653 if (ret < 0) {
3654 ALOGE("%s: csd_client_start_playback failed, error %d",
3655 __func__, ret);
3656 }
3657 }
3658
3659 return ret;
3660}
3661
3662int platform_stop_incall_music_usecase(void *platform)
3663{
3664 int ret = 0;
3665 struct platform_data *my_data = (struct platform_data *)platform;
3666
3667 if (my_data->csd != NULL) {
3668 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3669 if (ret < 0) {
3670 ALOGE("%s: csd_client_stop_playback failed, error %d",
3671 __func__, ret);
3672 }
3673 }
3674
3675 return ret;
3676}
3677
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07003678int platform_update_lch(void *platform, struct voice_session *session,
3679 enum voice_lch_mode lch_mode)
3680{
3681 int ret = 0;
3682 struct platform_data *my_data = (struct platform_data *)platform;
3683
3684 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
3685 ret = my_data->csd->set_lch(session->vsid, lch_mode);
3686 else
3687 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
3688
3689 return ret;
3690}
3691
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303692void platform_get_parameters(void *platform,
3693 struct str_parms *query,
3694 struct str_parms *reply)
3695{
3696 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303697 char value[512] = {0};
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303698 int ret;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303699 char *kv_pairs = NULL;
Sidipotu Ashok42483b62015-09-08 10:21:44 +05303700 char propValue[PROPERTY_VALUE_MAX]={0};
3701 bool prop_playback_enabled = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303702
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303703 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
3704 value, sizeof(value));
3705 if (ret >= 0) {
3706 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
3707 my_data->slowtalk?"true":"false");
3708 }
3709
Avinash Vaishd5fa4572014-09-15 14:41:14 +05303710 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE,
3711 value, sizeof(value));
3712 if (ret >= 0) {
3713 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE,
3714 my_data->hd_voice?"true":"false");
3715 }
3716
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303717 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
3718 value, sizeof(value));
3719 if (ret >= 0) {
3720 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
3721 strlcpy(value, "on", sizeof(value));
3722 } else {
3723 strlcpy(value, "off", sizeof(value));
3724 }
3725
3726 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
3727 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303728 native_audio_get_params(query, reply, value, sizeof(value));
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303729
Sidipotu Ashokf490be52015-10-20 10:41:34 +05303730 ret = str_parms_get_str(query, AUDIO_PARAMETER_IS_HW_DECODER_SESSION_AVAILABLE,
Sidipotu Ashok42483b62015-09-08 10:21:44 +05303731 value, sizeof(value));
3732 if (ret >= 0) {
3733 int isallowed = 1; /*true*/
3734
3735 if (property_get("voice.playback.conc.disabled", propValue, NULL)) {
3736 prop_playback_enabled = atoi(propValue) ||
3737 !strncmp("true", propValue, 4);
3738 }
3739
3740 if (prop_playback_enabled && (voice_is_in_call(my_data->adev) ||
3741 (SND_CARD_STATE_OFFLINE == get_snd_card_state(my_data->adev)))) {
3742 char *decoder_mime_type = value;
3743
3744 //check if unsupported mime type or not
3745 if(decoder_mime_type) {
Alexy Josephb1379942016-01-29 15:49:38 -08003746 unsigned int i = 0;
Sidipotu Ashok42483b62015-09-08 10:21:44 +05303747 for (i = 0; i < sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]); i++) {
3748 if (!strncmp(decoder_mime_type, dsp_only_decoders_mime[i],
3749 strlen(dsp_only_decoders_mime[i]))) {
3750 ALOGD("Rejecting request for DSP only session from HAL during voice call/SSR state");
3751 isallowed = 0;
3752 break;
3753 }
3754 }
3755 }
3756 }
Sidipotu Ashokf490be52015-10-20 10:41:34 +05303757 str_parms_add_int(reply, AUDIO_PARAMETER_IS_HW_DECODER_SESSION_AVAILABLE, isallowed);
Sidipotu Ashok42483b62015-09-08 10:21:44 +05303758 }
3759
3760
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303761 /* Handle audio calibration keys */
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303762 kv_pairs = str_parms_to_str(reply);
3763 ALOGV("%s: exit: returns - %s", __func__, kv_pairs);
3764 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303765}
3766
Ashish Jain5106d362016-05-11 19:23:33 +05303767/* Delay in Us, only to be used for PCM formats */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303768int64_t platform_render_latency(audio_usecase_t usecase)
3769{
3770 switch (usecase) {
3771 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3772 return DEEP_BUFFER_PLATFORM_DELAY;
3773 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3774 return LOW_LATENCY_PLATFORM_DELAY;
Ashish Jain5106d362016-05-11 19:23:33 +05303775 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
3776 case USECASE_AUDIO_PLAYBACK_OFFLOAD2:
3777 return PCM_OFFLOAD_PLATFORM_DELAY;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303778 default:
3779 return 0;
3780 }
3781}
3782
3783int platform_update_usecase_from_source(int source, int usecase)
3784{
3785 ALOGV("%s: input source :%d", __func__, source);
Mingming Yin12125e82015-10-26 20:40:36 -07003786 if (source == AUDIO_SOURCE_FM_TUNER)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303787 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
3788 return usecase;
3789}
3790
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303791bool platform_listen_device_needs_event(snd_device_t snd_device)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303792{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303793 bool needs_event = false;
3794
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303795 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
3796 (snd_device < SND_DEVICE_IN_END) &&
3797 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
3798 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303799 needs_event = true;
3800
3801 return needs_event;
3802}
3803
3804bool platform_listen_usecase_needs_event(audio_usecase_t uc_id)
3805{
3806 bool needs_event = false;
3807
3808 switch(uc_id){
3809 /* concurrent playback usecases needs event */
3810 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3811 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
3812 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
3813 needs_event = true;
3814 break;
3815 /* concurrent playback in low latency allowed */
3816 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3817 break;
3818 /* concurrent playback FM needs event */
3819 case USECASE_AUDIO_PLAYBACK_FM:
3820 needs_event = true;
3821 break;
3822
3823 /* concurrent capture usecases, no event, capture handled by device
3824 * USECASE_AUDIO_RECORD:
3825 * USECASE_AUDIO_RECORD_COMPRESS:
3826 * USECASE_AUDIO_RECORD_LOW_LATENCY:
3827
3828 * USECASE_VOICE_CALL:
3829 * USECASE_VOICE2_CALL:
3830 * USECASE_VOLTE_CALL:
3831 * USECASE_QCHAT_CALL:
3832 * USECASE_VOWLAN_CALL:
Avinash Vaish306e6072015-05-13 16:58:18 +05303833 * USECASE_VOICEMMODE1_CALL:
3834 * USECASE_VOICEMMODE2_CALL:
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303835 * USECASE_COMPRESS_VOIP_CALL:
3836 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
3837 * USECASE_INCALL_REC_UPLINK:
3838 * USECASE_INCALL_REC_DOWNLINK:
3839 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
3840 * USECASE_INCALL_REC_UPLINK_COMPRESS:
3841 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
3842 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
3843 * USECASE_INCALL_MUSIC_UPLINK:
3844 * USECASE_INCALL_MUSIC_UPLINK2:
3845 * USECASE_AUDIO_SPKR_CALIB_RX:
3846 * USECASE_AUDIO_SPKR_CALIB_TX:
3847 */
3848 default:
3849 ALOGV("%s:usecase_id[%d} no need to raise event.", __func__, uc_id);
3850 }
3851 return needs_event;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303852}
3853
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07003854bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
3855{
3856 bool needs_event = false;
3857
3858 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
3859 (snd_device < SND_DEVICE_IN_END) &&
3860 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
3861 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
3862 needs_event = true;
3863
3864 return needs_event;
3865}
3866
3867bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
3868{
3869 bool needs_event = false;
3870
3871 switch(uc_id){
3872 /* concurrent playback usecases needs event */
3873 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3874 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
3875 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
3876 needs_event = true;
3877 break;
3878 /* concurrent playback in low latency allowed */
3879 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3880 break;
3881 /* concurrent playback FM needs event */
3882 case USECASE_AUDIO_PLAYBACK_FM:
3883 needs_event = true;
3884 break;
3885
3886 /* concurrent capture usecases, no event, capture handled by device
3887 * USECASE_AUDIO_RECORD:
3888 * USECASE_AUDIO_RECORD_COMPRESS:
3889 * USECASE_AUDIO_RECORD_LOW_LATENCY:
3890
3891 * USECASE_VOICE_CALL:
3892 * USECASE_VOICE2_CALL:
3893 * USECASE_VOLTE_CALL:
3894 * USECASE_QCHAT_CALL:
3895 * USECASE_VOWLAN_CALL:
Avinash Vaish306e6072015-05-13 16:58:18 +05303896 * USECASE_VOICEMMODE1_CALL:
3897 * USECASE_VOICEMMODE2_CALL:
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07003898 * USECASE_COMPRESS_VOIP_CALL:
3899 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
3900 * USECASE_INCALL_REC_UPLINK:
3901 * USECASE_INCALL_REC_DOWNLINK:
3902 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
3903 * USECASE_INCALL_REC_UPLINK_COMPRESS:
3904 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
3905 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
3906 * USECASE_INCALL_MUSIC_UPLINK:
3907 * USECASE_INCALL_MUSIC_UPLINK2:
3908 * USECASE_AUDIO_SPKR_CALIB_RX:
3909 * USECASE_AUDIO_SPKR_CALIB_TX:
3910 */
3911 default:
3912 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
3913 }
3914 return needs_event;
3915}
3916
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303917/* Read offload buffer size from a property.
3918 * If value is not power of 2 round it to
3919 * power of 2.
3920 */
3921uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
3922{
3923 char value[PROPERTY_VALUE_MAX] = {0};
3924 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3925 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
3926 atoi(value)) {
3927 fragment_size = atoi(value) * 1024;
3928 }
3929
vivek mehta80a44292015-08-10 12:58:10 -07003930 /* Use incoming offload buffer size if default buffer size is less */
3931 if ((info != NULL) && (fragment_size < info->offload_buffer_size)) {
3932 ALOGI("%s:: Overwriting offload buffer size default:%d new:%d", __func__,
3933 fragment_size,
3934 info->offload_buffer_size);
3935 fragment_size = info->offload_buffer_size;
3936 }
3937
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303938 // For FLAC use max size since it is loss less, and has sampling rates
3939 // upto 192kHZ
3940 if (info != NULL && !info->has_video &&
3941 info->format == AUDIO_FORMAT_FLAC) {
3942 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3943 ALOGV("FLAC fragment size %d", fragment_size);
3944 }
3945
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303946 if (info != NULL && info->has_video && info->is_streaming) {
3947 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
3948 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07003949 __func__, fragment_size);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303950 }
3951
3952 fragment_size = ALIGN( fragment_size, 1024);
3953
3954 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
3955 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3956 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
3957 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3958 ALOGV("%s: fragment_size %d", __func__, fragment_size);
3959 return fragment_size;
3960}
3961
3962uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
3963{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303964 uint32_t fragment_size = 0;
Ashish Jain5106d362016-05-11 19:23:33 +05303965 uint32_t bytes_per_sample;
Alexy Joseph2ce25e22015-06-18 12:02:01 -07003966 uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303967
Ashish Jain5106d362016-05-11 19:23:33 +05303968 bytes_per_sample = audio_bytes_per_sample(info->format);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303969
Alexy Joseph2ce25e22015-06-18 12:02:01 -07003970 //duration is set to 40 ms worth of stereo data at 48Khz
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303971 //with 16 bit per sample, modify this when the channel
3972 //configuration is different
3973 fragment_size = (pcm_offload_time
3974 * info->sample_rate
Ashish Jain5106d362016-05-11 19:23:33 +05303975 * bytes_per_sample
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303976 * popcount(info->channel_mask))/1000;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303977 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
3978 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
3979 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
3980 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
Preetam Singh Ranawat6efde5c2015-04-24 11:04:22 +05303981 // To have same PCM samples for all channels, the buffer size requires to
3982 // be multiple of (number of channels * bytes per sample)
3983 // For writes to succeed, the buffer must be written at address which is multiple of 32
Ashish Jain5106d362016-05-11 19:23:33 +05303984 fragment_size = ALIGN(fragment_size, (bytes_per_sample * popcount(info->channel_mask) * 32));
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303985
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303986 ALOGI("PCM offload Fragment size to %d bytes", fragment_size);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303987 return fragment_size;
3988}
3989
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303990/*
3991 * configures afe with bit width and Sample Rate
3992 */
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303993static int platform_set_codec_backend_cfg(struct audio_device* adev,
Ashish Jain5106d362016-05-11 19:23:33 +05303994 snd_device_t snd_device, unsigned int bit_width,
3995 unsigned int sample_rate, audio_format_t format)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303996{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303997 int ret = 0;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05303998 int backend_idx = DEFAULT_CODEC_BACKEND;
3999 struct platform_data *my_data = (struct platform_data *)adev->platform;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304000
4001 backend_idx = platform_get_backend_index(snd_device);
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304002 ALOGI("%s:becf: afe: bitwidth %d, samplerate %d, backend_idx %d device (%s)",
4003 __func__, bit_width, sample_rate, backend_idx,
4004 platform_get_snd_device_name(snd_device));
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304005
4006 if (bit_width !=
4007 my_data->current_backend_cfg[backend_idx].bit_width) {
4008
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304009 struct mixer_ctl *ctl;
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05304010 ctl = mixer_get_ctl_by_name(adev->mixer,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304011 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304012 if (!ctl) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304013 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
4014 __func__,
4015 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304016 return -EINVAL;
4017 }
4018
4019 if (bit_width == 24) {
Ashish Jain5106d362016-05-11 19:23:33 +05304020 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
4021 mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
4022 else
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304023 mixer_ctl_set_enum_by_string(ctl, "S24_LE");
4024 } else {
4025 mixer_ctl_set_enum_by_string(ctl, "S16_LE");
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304026 }
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304027 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
Ashish Jain5106d362016-05-11 19:23:33 +05304028 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
4029 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl,
4030 bit_width, format);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304031 }
4032
4033 /*
4034 * Backend sample rate configuration follows:
4035 * 16 bit playback - 48khz for streams at any valid sample rate
4036 * 24 bit playback - 48khz for stream sample rate less than 48khz
4037 * 24 bit playback - 96khz for sample rate range of 48khz to 96khz
4038 * 24 bit playback - 192khz for sample rate range of 96khz to 192 khz
4039 * Upper limit is inclusive in the sample rate range.
4040 */
4041 // TODO: This has to be more dynamic based on policy file
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304042
4043 if ((sample_rate != my_data->current_backend_cfg[(int)backend_idx].sample_rate) &&
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05304044 (my_data->hifi_audio)) {
4045 /*
4046 * sample rate update is needed only for hifi audio enabled platforms
4047 */
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304048 char *rate_str = NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304049 struct mixer_ctl *ctl;
4050
4051 switch (sample_rate) {
4052 case 8000:
4053 case 11025:
4054 case 16000:
4055 case 22050:
4056 case 32000:
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304057 case 48000:
4058 rate_str = "KHZ_48";
4059 break;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304060 case 44100:
4061 rate_str = "KHZ_44P1";
4062 break;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304063 case 64000:
4064 case 88200:
4065 case 96000:
4066 rate_str = "KHZ_96";
4067 break;
4068 case 176400:
4069 case 192000:
4070 rate_str = "KHZ_192";
4071 break;
4072 default:
4073 rate_str = "KHZ_48";
4074 break;
4075 }
4076
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304077 ctl = mixer_get_ctl_by_name(adev->mixer,
4078 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304079
4080 if (!ctl) {
4081 ALOGE("%s:becf: afe: Could not get ctl to set the Sample Rate for mixer command - %s",
4082 __func__,
4083 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304084 return -EINVAL;
4085 }
4086
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304087 ALOGD("%s:becf: afe: %s set to %s", __func__,
4088 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl,
4089 rate_str);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304090 mixer_ctl_set_enum_by_string(ctl, rate_str);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304091 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304092 }
4093
4094 return ret;
4095}
4096
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304097/*
4098 * goes through all the current usecases and picks the highest
4099 * bitwidth & samplerate
4100 */
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304101static bool platform_check_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304102 struct audio_usecase* usecase,
4103 snd_device_t snd_device,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304104 unsigned int* new_bit_width,
4105 unsigned int* new_sample_rate)
4106{
4107 bool backend_change = false;
4108 struct listnode *node;
4109 struct stream_out *out = NULL;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304110 char value[PROPERTY_VALUE_MAX] = {0};
4111 unsigned int bit_width;
4112 unsigned int sample_rate;
4113 int backend_idx = DEFAULT_CODEC_BACKEND;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304114 struct platform_data *my_data = (struct platform_data *)adev->platform;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304115 int na_mode = platform_get_native_support();
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304116
4117 backend_idx = platform_get_backend_index(snd_device);
4118
4119 bit_width = *new_bit_width;
4120 sample_rate = *new_sample_rate;
4121
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304122 ALOGI("%s:becf: afe: Codec selected backend: %d current bit width: %d and sample rate: %d",
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304123 __func__, backend_idx, bit_width, sample_rate);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304124
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07004125 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4126 // default backend
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304127 // force routing is not required here, caller will do it anyway
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07004128 if ((voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) &&
4129 backend_idx == DEFAULT_CODEC_BACKEND) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304130 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
4131 __func__);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304132 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4133 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4134 } else {
4135 /*
4136 * The backend should be configured at highest bit width and/or
4137 * sample rate amongst all playback usecases.
4138 * If the selected sample rate and/or bit width differ with
4139 * current backend sample rate and/or bit width, then, we set the
4140 * backend re-configuration flag.
4141 *
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304142 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304143 */
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304144 int i =0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304145 list_for_each(node, &adev->usecase_list) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304146 struct audio_usecase *uc;
4147 uc = node_to_item(node, struct audio_usecase, list);
4148 struct stream_out *out = (struct stream_out*) uc->stream.out;
4149 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304150
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304151 ALOGD("%s:napb: (%d) - (%s)id (%d) sr %d bw "
4152 "(%d) device %s", __func__, i++, use_case_table[uc->id],
4153 uc->id, out->sample_rate,
4154 out->bit_width,
4155 platform_get_snd_device_name(uc->out_snd_device));
4156
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304157 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304158 if (bit_width < out->bit_width)
4159 bit_width = out->bit_width;
4160 if (sample_rate < out->sample_rate)
4161 sample_rate = out->sample_rate;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304162 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
4163 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304164 }
4165 }
4166 }
4167 }
4168
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304169 if (audio_is_true_native_stream_active(adev)) {
Sidipotu Ashokad8fff82016-02-02 10:48:42 +05304170 if (check_hdset_combo_device(snd_device)) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304171 /*
4172 * In true native mode Tasha has a limitation that one port at 44.1 khz
4173 * cannot drive both spkr and hdset, to simiplify the solution lets
4174 * move the AFE to 48khzwhen a ring tone selects combo device.
4175 */
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304176 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304177 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4178 ALOGD("%s:becf: afe: port has to run at 48k for a combo device",
4179 __func__);
4180 } else {
4181 /*
4182 * in single BE mode, if native audio playback
4183 * is active then it will take priority
4184 */
4185 sample_rate = OUTPUT_SAMPLING_RATE_44100;
4186 ALOGD("%s:becf: afe: napb active set rate to 44.1 khz",
4187 __func__);
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304188 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304189 }
Ashish Jainb449be32015-07-19 05:39:23 -07004190
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304191
Sidipotu Ashokfdd505a2016-02-11 10:31:38 +05304192
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304193 /*
Sidipotu Ashokfdd505a2016-02-11 10:31:38 +05304194 * hifi playback not supported on spkr devices, limit the Sample Rate
4195 * to 48 khz.
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304196 */
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304197 if (SND_DEVICE_OUT_SPEAKER == snd_device ||
4198 SND_DEVICE_OUT_SPEAKER_WSA == snd_device ||
4199 SND_DEVICE_OUT_SPEAKER_VBAT == snd_device) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304200 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304201 ALOGD("%s:becf: afe: playback on speaker device Configure afe to "
4202 "default Sample Rate(48k)", __func__);
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304203 }
4204
4205 /*
4206 * native playback is not enabled.Configure afe to default Sample Rate(48k)
4207 */
4208 if (NATIVE_AUDIO_MODE_INVALID == na_mode &&
4209 OUTPUT_SAMPLING_RATE_44100 == sample_rate) {
4210 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4211 ALOGD("%s:becf: afe: napb not active - set (48k) default rate",
4212 __func__);
4213 }
4214
Ashish Jainb449be32015-07-19 05:39:23 -07004215 /*
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05304216 * reset the sample rate to default value(48K), if hifi audio is not supported
Ashish Jainb449be32015-07-19 05:39:23 -07004217 */
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05304218 if (!my_data->hifi_audio) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304219 ALOGD("%s:becf: afe: only 48KHZ sample rate is supported "
4220 "Configure afe to default Sample Rate(48k)", __func__);
Venkata Narendra Kumar Gutta4bd09d02016-01-29 15:31:04 +05304221 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304222 }
Ashish Jainb449be32015-07-19 05:39:23 -07004223
Manish Dewangan837dc462015-05-27 10:17:41 +05304224 //check if mulitchannel clip needs to be down sampled to 48k
4225 property_get("audio.playback.mch.downsample",value,"");
4226 if (!strncmp("true", value, sizeof("true"))) {
4227 out = usecase->stream.out;
4228 if ((popcount(out->channel_mask) > 2) &&
4229 (out->sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
4230 !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) {
4231 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4232 /* update out sample rate to reflect current backend sample rate */
4233 out->sample_rate = sample_rate;
4234 ALOGD("%s: MCH session defaulting sample rate to %d",
4235 __func__, sample_rate);
4236 }
4237 }
4238
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304239 ALOGI("%s:becf: afe: Codec selected backend: %d updated bit width: %d and sample rate: %d",
4240 __func__,
4241 backend_idx, bit_width, sample_rate);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304242 // Force routing if the expected bitwdith or samplerate
4243 // is not same as current backend comfiguration
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304244 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
4245 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate)) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304246 *new_bit_width = bit_width;
4247 *new_sample_rate = sample_rate;
4248 backend_change = true;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304249 ALOGI("%s:becf: afe: Codec backend needs to be updated. new bit width: %d new sample rate: %d",
4250 __func__,
4251 *new_bit_width, *new_sample_rate);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304252 }
4253
4254 return backend_change;
4255}
4256
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004257bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304258 struct audio_usecase *usecase, snd_device_t snd_device)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304259{
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304260 unsigned int new_bit_width;
4261 unsigned int new_sample_rate;
4262 int backend_idx = DEFAULT_CODEC_BACKEND;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304263 int new_snd_devices[SND_DEVICE_OUT_END];
4264 int i, num_devices = 1;
4265 bool ret = false;
Ashish Jain5106d362016-05-11 19:23:33 +05304266 audio_format_t format;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304267
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304268 backend_idx = platform_get_backend_index(snd_device);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304269
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304270 new_bit_width = usecase->stream.out->bit_width;
4271 new_sample_rate = usecase->stream.out->sample_rate;
Ashish Jain5106d362016-05-11 19:23:33 +05304272 format = usecase->stream.out->format;
Preetam Singh Ranawatc61f8672015-06-18 23:20:28 +05304273
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304274 ALOGI("%s:becf: afe: bitwidth %d, samplerate %d"
4275 ", backend_idx %d usecase = %d device (%s)", __func__, new_bit_width,
4276 new_sample_rate, backend_idx, usecase->id,
4277 platform_get_snd_device_name(snd_device));
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304278
4279 if (!platform_can_split_snd_device(adev->platform, snd_device,
4280 &num_devices, new_snd_devices))
4281 new_snd_devices[0] = snd_device;
4282
4283 for (i = 0; i < num_devices; i++) {
4284 ALOGI("%s: becf: new_snd_devices[%d] is %s", __func__, i,
4285 platform_get_snd_device_name(new_snd_devices[i]));
4286 if (platform_check_codec_backend_cfg(adev, usecase, new_snd_devices[i],
4287 &new_bit_width, &new_sample_rate)) {
4288 platform_set_codec_backend_cfg(adev, new_snd_devices[i],
Ashish Jain5106d362016-05-11 19:23:33 +05304289 new_bit_width, new_sample_rate, format);
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304290 ret = true;
4291 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304292 }
4293
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304294 return ret;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304295}
4296
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05304297/*
4298 * configures afe with bit width and Sample Rate
4299 */
4300
4301int platform_set_capture_codec_backend_cfg(struct audio_device* adev,
4302 snd_device_t snd_device,
4303 unsigned int bit_width, unsigned int sample_rate,
4304 audio_format_t format)
4305{
4306 int ret = 0;
4307 int backend_idx = DEFAULT_CODEC_BACKEND;
4308 struct platform_data *my_data = (struct platform_data *)adev->platform;
4309
4310 ALOGI("%s:txbecf: afe: bitwidth %d, samplerate %d, backend_idx %d device (%s)",
4311 __func__, bit_width, sample_rate, backend_idx,
4312 platform_get_snd_device_name(snd_device));
4313
4314 if (bit_width !=
4315 my_data->current_tx_backend_cfg[backend_idx].bit_width) {
4316
4317 struct mixer_ctl *ctl = NULL;
4318 ctl = mixer_get_ctl_by_name(adev->mixer,
4319 my_data->current_tx_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4320 if (!ctl) {
4321 ALOGE("%s:txbecf: afe: Could not get ctl for mixer command - %s",
4322 __func__,
4323 my_data->current_tx_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4324 return -EINVAL;
4325 }
4326
4327 if (bit_width == 24) {
4328 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
4329 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
4330 else
4331 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
4332 } else {
4333 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
4334 }
4335
4336 if (ret < 0) {
4337 ALOGE("%s:txbecf: afe: Could not set ctl for mixer command - %s",
4338 __func__,
4339 my_data->current_tx_backend_cfg[backend_idx].bitwidth_mixer_ctl);
4340 return -EINVAL;
4341 }
4342
4343 my_data->current_tx_backend_cfg[backend_idx].bit_width = bit_width;
4344 ALOGD("%s:txbecf: afe: %s mixer set to %d bit", __func__,
4345 my_data->current_tx_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width);
4346 }
4347
4348 /*
4349 * Backend sample rate configuration follows:
4350 * 16 bit record - 48khz for streams at any valid sample rate
4351 * 24 bit record - 48khz for stream sample rate less than 48khz
4352 * 24 bit record - 96khz for sample rate range of 48khz to 96khz
4353 * 24 bit record - 192khz for sample rate range of 96khz to 192 khz
4354 * Upper limit is inclusive in the sample rate range.
4355 */
4356 // TODO: This has to be more dynamic based on policy file
4357
4358 if (sample_rate != my_data->current_tx_backend_cfg[(int)backend_idx].sample_rate) {
4359 /*
4360 * sample rate update is needed only for hifi audio enabled platforms
4361 */
4362 char *rate_str = NULL;
4363 struct mixer_ctl *ctl = NULL;
4364
4365 switch (sample_rate) {
4366 case 8000:
4367 case 11025:
4368 case 16000:
4369 case 22050:
4370 case 32000:
4371 case 44100:
4372 case 48000:
4373 rate_str = "KHZ_48";
4374 break;
4375 case 64000:
4376 case 88200:
4377 case 96000:
4378 rate_str = "KHZ_96";
4379 break;
4380 case 176400:
4381 case 192000:
4382 rate_str = "KHZ_192";
4383 break;
4384 default:
4385 rate_str = "KHZ_48";
4386 break;
4387 }
4388
4389 ctl = mixer_get_ctl_by_name(adev->mixer,
4390 my_data->current_tx_backend_cfg[backend_idx].samplerate_mixer_ctl);
4391
4392 if (ctl < 0) {
4393 ALOGE("%s:txbecf: afe: Could not get ctl to set the Sample Rate for mixer command - %s",
4394 __func__,
4395 my_data->current_tx_backend_cfg[backend_idx].samplerate_mixer_ctl);
4396 return -EINVAL;
4397 }
4398
4399 ALOGD("%s:txbecf: afe: %s set to %s", __func__,
4400 my_data->current_tx_backend_cfg[backend_idx].samplerate_mixer_ctl,
4401 rate_str);
4402 ret = mixer_ctl_set_enum_by_string(ctl, rate_str);
4403 if (ret < 0) {
4404 ALOGE("%s:txbecf: afe: Could not set ctl for mixer command - %s",
4405 __func__,
4406 my_data->current_tx_backend_cfg[backend_idx].samplerate_mixer_ctl);
4407 return -EINVAL;
4408 }
4409
4410 my_data->current_tx_backend_cfg[backend_idx].sample_rate = sample_rate;
4411 }
4412
4413 return ret;
4414}
4415
4416/*
4417 * goes through all the current usecases and picks the highest
4418 * bitwidth & samplerate
4419 */
4420bool platform_check_capture_codec_backend_cfg(struct audio_device* adev,
4421 unsigned int* new_bit_width,
4422 unsigned int* new_sample_rate)
4423{
4424 bool backend_change = false;
4425 unsigned int bit_width;
4426 unsigned int sample_rate;
4427 int backend_idx = DEFAULT_CODEC_BACKEND;
4428 struct platform_data *my_data = (struct platform_data *)adev->platform;
4429
4430 bit_width = *new_bit_width;
4431 sample_rate = *new_sample_rate;
4432
4433 ALOGI("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
4434 "sample rate: %d",__func__,backend_idx, bit_width, sample_rate);
4435
4436 // For voice calls use default configuration i.e. 16b/48K, only applicable to
4437 // default backend
4438 // force routing is not required here, caller will do it anyway
4439 if ((voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) ||
4440 (!is_external_codec)) {
4441 ALOGW("%s:txbecf: afe:Use default bw and sr for voice/voip calls",
4442 __func__);
4443 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4444 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4445 }
4446
4447 ALOGI("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
4448 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
4449 // Force routing if the expected bitwdith or samplerate
4450 // is not same as current backend comfiguration
4451 if ((bit_width != my_data->current_tx_backend_cfg[backend_idx].bit_width) ||
4452 (sample_rate != my_data->current_tx_backend_cfg[backend_idx].sample_rate)) {
4453 *new_bit_width = bit_width;
4454 *new_sample_rate = sample_rate;
4455 backend_change = true;
4456 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
4457 "new sample rate: %d", __func__, *new_bit_width, *new_sample_rate);
4458 }
4459
4460 return backend_change;
4461}
4462
4463bool platform_check_and_set_capture_codec_backend_cfg(struct audio_device* adev,
4464 struct audio_usecase *usecase, snd_device_t snd_device)
4465{
4466 unsigned int new_bit_width;
4467 unsigned int new_sample_rate;
4468 audio_format_t format = AUDIO_FORMAT_PCM_16_BIT;
4469 int backend_idx = DEFAULT_CODEC_BACKEND;
4470 int ret = 0;
4471
4472 if(usecase->type == PCM_CAPTURE) {
4473 new_sample_rate = usecase->stream.in->sample_rate;
4474 new_bit_width = usecase->stream.in->bit_width;
4475 format = usecase->stream.in->format;
4476 } else {
4477 new_bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
4478 new_sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
4479 }
4480
4481 ALOGI("%s:txbecf: afe: bitwidth %d, samplerate %d"
4482 ", backend_idx %d usecase = %d device (%s)", __func__, new_bit_width,
4483 new_sample_rate, backend_idx, usecase->id,
4484 platform_get_snd_device_name(snd_device));
4485 if (platform_check_capture_codec_backend_cfg(adev, &new_bit_width,
4486 &new_sample_rate)) {
4487 ret = platform_set_capture_codec_backend_cfg(adev, snd_device,
4488 new_bit_width, new_sample_rate, format);
4489 if(!ret)
4490 return true;
4491 }
4492
4493 return false;
4494}
4495
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304496int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
4497 const char * hw_interface)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304498{
4499 int ret = 0;
4500
4501 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
4502 ALOGE("%s: Invalid snd_device = %d",
4503 __func__, device);
4504 ret = -EINVAL;
4505 goto done;
4506 }
4507
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304508 ALOGD("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
4509 platform_get_snd_device_name(device),
4510 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null",
4511 backend_tag);
4512 if (backend_tag_table[device]) {
4513 free(backend_tag_table[device]);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304514 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304515 backend_tag_table[device] = strdup(backend_tag);
4516
4517 if (hw_interface != NULL) {
4518 if (hw_interface_table[device])
4519 free(hw_interface_table[device]);
4520
4521 ALOGD("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
4522 hw_interface_table[device] = strdup(hw_interface);
4523 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304524done:
4525 return ret;
4526}
4527
4528int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
4529{
4530 int ret = 0;
4531 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
4532 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
4533 ret = -EINVAL;
4534 goto done;
4535 }
4536
4537 if ((type != 0) && (type != 1)) {
4538 ALOGE("%s: invalid usecase type", __func__);
4539 ret = -EINVAL;
4540 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304541 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304542 pcm_device_table[usecase][type] = pcm_id;
4543done:
4544 return ret;
4545}
4546
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07004547void platform_get_device_to_be_id_map(int **device_to_be_id, int *length)
4548{
Alexy Josephb1379942016-01-29 15:49:38 -08004549 *device_to_be_id = (int*) msm_device_to_be_id;
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07004550 *length = msm_be_id_array_len;
4551}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304552int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask, int snd_id)
4553{
4554 int ret = 0;
4555 int channels = audio_channel_count_from_out_mask(channel_mask);
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07004556
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304557 char channel_map[8];
4558 memset(channel_map, 0, sizeof(channel_map));
4559 /* Following are all most common standard WAV channel layouts
4560 overridden by channel mask if its allowed and different */
4561 switch (channels) {
4562 case 1:
4563 /* AUDIO_CHANNEL_OUT_MONO */
4564 channel_map[0] = PCM_CHANNEL_FC;
4565 break;
4566 case 2:
4567 /* AUDIO_CHANNEL_OUT_STEREO */
4568 channel_map[0] = PCM_CHANNEL_FL;
4569 channel_map[1] = PCM_CHANNEL_FR;
4570 break;
4571 case 3:
4572 /* AUDIO_CHANNEL_OUT_2POINT1 */
4573 channel_map[0] = PCM_CHANNEL_FL;
4574 channel_map[1] = PCM_CHANNEL_FR;
4575 channel_map[2] = PCM_CHANNEL_FC;
4576 break;
4577 case 4:
4578 /* AUDIO_CHANNEL_OUT_QUAD_SIDE */
4579 channel_map[0] = PCM_CHANNEL_FL;
4580 channel_map[1] = PCM_CHANNEL_FR;
4581 channel_map[2] = PCM_CHANNEL_LS;
4582 channel_map[3] = PCM_CHANNEL_RS;
4583 if (channel_mask == AUDIO_CHANNEL_OUT_QUAD_BACK)
4584 {
4585 channel_map[2] = PCM_CHANNEL_LB;
4586 channel_map[3] = PCM_CHANNEL_RB;
4587 }
4588 if (channel_mask == AUDIO_CHANNEL_OUT_SURROUND)
4589 {
4590 channel_map[2] = PCM_CHANNEL_FC;
4591 channel_map[3] = PCM_CHANNEL_CS;
4592 }
4593 break;
4594 case 5:
4595 /* AUDIO_CHANNEL_OUT_PENTA */
4596 channel_map[0] = PCM_CHANNEL_FL;
4597 channel_map[1] = PCM_CHANNEL_FR;
4598 channel_map[2] = PCM_CHANNEL_FC;
4599 channel_map[3] = PCM_CHANNEL_LB;
4600 channel_map[4] = PCM_CHANNEL_RB;
4601 break;
4602 case 6:
4603 /* AUDIO_CHANNEL_OUT_5POINT1 */
4604 channel_map[0] = PCM_CHANNEL_FL;
4605 channel_map[1] = PCM_CHANNEL_FR;
4606 channel_map[2] = PCM_CHANNEL_FC;
4607 channel_map[3] = PCM_CHANNEL_LFE;
4608 channel_map[4] = PCM_CHANNEL_LB;
4609 channel_map[5] = PCM_CHANNEL_RB;
4610 if (channel_mask == AUDIO_CHANNEL_OUT_5POINT1_SIDE)
4611 {
4612 channel_map[4] = PCM_CHANNEL_LS;
4613 channel_map[5] = PCM_CHANNEL_RS;
4614 }
4615 break;
4616 case 7:
4617 /* AUDIO_CHANNEL_OUT_6POINT1 */
4618 channel_map[0] = PCM_CHANNEL_FL;
4619 channel_map[1] = PCM_CHANNEL_FR;
4620 channel_map[2] = PCM_CHANNEL_FC;
4621 channel_map[3] = PCM_CHANNEL_LFE;
4622 channel_map[4] = PCM_CHANNEL_LB;
4623 channel_map[5] = PCM_CHANNEL_RB;
4624 channel_map[6] = PCM_CHANNEL_CS;
4625 break;
4626 case 8:
4627 /* AUDIO_CHANNEL_OUT_7POINT1 */
4628 channel_map[0] = PCM_CHANNEL_FL;
4629 channel_map[1] = PCM_CHANNEL_FR;
4630 channel_map[2] = PCM_CHANNEL_FC;
4631 channel_map[3] = PCM_CHANNEL_LFE;
4632 channel_map[4] = PCM_CHANNEL_LB;
4633 channel_map[5] = PCM_CHANNEL_RB;
4634 channel_map[6] = PCM_CHANNEL_LS;
4635 channel_map[7] = PCM_CHANNEL_RS;
4636 break;
4637 default:
4638 ALOGE("unsupported channels %d for setting channel map", channels);
4639 return -1;
4640 }
4641 ret = platform_set_channel_map(platform, channels, channel_map, snd_id);
4642 return ret;
4643}
4644
4645int platform_get_edid_info(void *platform)
4646{
4647 struct platform_data *my_data = (struct platform_data *)platform;
4648 struct audio_device *adev = my_data->adev;
4649 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05304650 int ret, count;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304651
4652 struct mixer_ctl *ctl;
4653 char edid_data[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE + 1] = {0};
4654 edid_audio_info *info;
4655
4656 if (my_data->edid_valid) {
4657 /* use cached edid */
4658 return 0;
4659 }
4660
4661 if (my_data->edid_info == NULL) {
4662 my_data->edid_info =
4663 (struct edid_audio_info *)calloc(1, sizeof(struct edid_audio_info));
4664 }
4665
4666 info = my_data->edid_info;
4667
4668 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
4669 if (!ctl) {
4670 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4671 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
4672 goto fail;
4673 }
4674
4675 mixer_ctl_update(ctl);
4676
4677 count = mixer_ctl_get_num_values(ctl);
4678
4679 /* Read SAD blocks, clamping the maximum size for safety */
4680 if (count > (int)sizeof(block))
4681 count = (int)sizeof(block);
4682
4683 ret = mixer_ctl_get_array(ctl, block, count);
4684 if (ret != 0) {
4685 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
4686 goto fail;
4687 }
4688 edid_data[0] = count;
4689 memcpy(&edid_data[1], block, count);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304690 if (!edid_get_sink_caps(info, edid_data)) {
4691 ALOGE("%s: Failed to get HDMI sink capabilities", __func__);
4692 goto fail;
4693 }
4694 my_data->edid_valid = true;
4695 return 0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304696fail:
4697 if (my_data->edid_info) {
4698 free(my_data->edid_info);
4699 my_data->edid_info = NULL;
4700 my_data->edid_valid = false;
4701 }
4702 ALOGE("%s: return -EINVAL", __func__);
4703 return -EINVAL;
4704}
4705
4706
4707int platform_set_channel_allocation(void *platform, int channel_alloc)
4708{
4709 struct mixer_ctl *ctl;
4710 const char *mixer_ctl_name = "HDMI RX CA";
4711 int ret;
4712 struct platform_data *my_data = (struct platform_data *)platform;
4713 struct audio_device *adev = my_data->adev;
4714
4715 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4716 if (!ctl) {
4717 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4718 __func__, mixer_ctl_name);
4719 ret = EINVAL;
4720 }
4721 ALOGD(":%s channel allocation = 0x%x", __func__, channel_alloc);
4722 ret = mixer_ctl_set_value(ctl, 0, channel_alloc);
4723
4724 if (ret < 0) {
4725 ALOGE("%s: Could not set ctl, error:%d ", __func__, ret);
4726 }
4727
4728 return ret;
4729}
4730
4731int platform_set_channel_map(void *platform, int ch_count, char *ch_map, int snd_id)
4732{
4733 struct mixer_ctl *ctl;
4734 char mixer_ctl_name[44]; // max length of name is 44 as defined
4735 int ret;
4736 unsigned int i;
4737 int set_values[8] = {0};
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304738 struct platform_data *my_data = (struct platform_data *)platform;
4739 struct audio_device *adev = my_data->adev;
4740 ALOGV("%s channel_count:%d",__func__, ch_count);
4741 if (NULL == ch_map) {
4742 ALOGE("%s: Invalid channel mapping used", __func__);
4743 return -EINVAL;
4744 }
Satish Babu Patakokila624cc922015-06-17 21:21:06 +05304745
4746 /*
4747 * If snd_id is greater than 0, stream channel mapping
4748 * If snd_id is below 0, typically -1, device channel mapping
4749 */
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304750 if (snd_id >= 0) {
Satish Babu Patakokila624cc922015-06-17 21:21:06 +05304751 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "Playback Channel Map%d", snd_id);
4752 } else {
4753 strlcpy(mixer_ctl_name, "Playback Device Channel Map", sizeof(mixer_ctl_name));
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304754 }
4755
4756 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
4757
4758 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4759 if (!ctl) {
4760 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4761 __func__, mixer_ctl_name);
4762 return -EINVAL;
4763 }
4764 for (i = 0; i< ARRAY_SIZE(set_values); i++) {
4765 set_values[i] = ch_map[i];
4766 }
4767
4768 ALOGD("%s: set mapping(%d %d %d %d %d %d %d %d) for channel:%d", __func__,
4769 set_values[0], set_values[1], set_values[2], set_values[3], set_values[4],
4770 set_values[5], set_values[6], set_values[7], ch_count);
4771
4772 ret = mixer_ctl_set_array(ctl, set_values, ch_count);
4773 if (ret < 0) {
4774 ALOGE("%s: Could not set ctl, error:%d ch_count:%d",
4775 __func__, ret, ch_count);
4776 }
4777 return ret;
4778}
4779
4780unsigned char platform_map_to_edid_format(int audio_format)
4781{
4782 unsigned char format;
4783 switch (audio_format & AUDIO_FORMAT_MAIN_MASK) {
4784 case AUDIO_FORMAT_AC3:
4785 ALOGV("%s: AC3", __func__);
4786 format = AC3;
4787 break;
4788 case AUDIO_FORMAT_AAC:
4789 ALOGV("%s:AAC", __func__);
4790 format = AAC;
4791 break;
Manish Dewangana6fc5442015-08-24 20:30:31 +05304792 case AUDIO_FORMAT_AAC_ADTS:
4793 ALOGV("%s:AAC_ADTS", __func__);
4794 format = AAC;
4795 break;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304796 case AUDIO_FORMAT_E_AC3:
4797 ALOGV("%s:E_AC3", __func__);
4798 format = DOLBY_DIGITAL_PLUS;
4799 break;
Mingming Yin3a941d42016-02-17 18:08:05 -08004800 case AUDIO_FORMAT_DTS:
4801 ALOGV("%s:DTS", __func__);
4802 format = DTS;
4803 break;
4804 case AUDIO_FORMAT_DTS_HD:
4805 ALOGV("%s:DTS_HD", __func__);
4806 format = DTS_HD;
4807 break;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304808 case AUDIO_FORMAT_PCM_16_BIT:
Ashish Jain5106d362016-05-11 19:23:33 +05304809 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
4810 case AUDIO_FORMAT_PCM_8_24_BIT:
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304811 ALOGV("%s:PCM", __func__);
Mingming Yin3a941d42016-02-17 18:08:05 -08004812 format = LPCM;
4813 break;
4814 default:
Mingming Yin3a941d42016-02-17 18:08:05 -08004815 format = -1;
Naresh Tanniru20e8b022016-04-28 16:54:17 +05304816 ALOGE("%s:invalid format:%d", __func__,format);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304817 break;
4818 }
4819 return format;
4820}
4821
4822uint32_t platform_get_compress_passthrough_buffer_size(
4823 audio_offload_info_t* info)
4824{
4825 uint32_t fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
4826 if (!info->has_video)
4827 fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
4828
4829 return fragment_size;
4830}
4831
4832void platform_reset_edid_info(void *platform) {
4833
4834 ALOGV("%s:", __func__);
4835 struct platform_data *my_data = (struct platform_data *)platform;
4836 if (my_data->edid_info) {
4837 ALOGV("%s :free edid", __func__);
4838 free(my_data->edid_info);
4839 my_data->edid_info = NULL;
4840 }
4841}
4842
4843bool platform_is_edid_supported_format(void *platform, int format)
4844{
4845 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304846 edid_audio_info *info = NULL;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05304847 int i, ret;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304848 unsigned char format_id = platform_map_to_edid_format(format);
4849
Mingming Yin3a941d42016-02-17 18:08:05 -08004850 if (format_id <= 0) {
4851 ALOGE("%s invalid edid format mappting for :%x" ,__func__, format);
4852 return false;
4853 }
4854
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304855 ret = platform_get_edid_info(platform);
4856 info = (edid_audio_info *)my_data->edid_info;
4857 if (ret == 0 && info != NULL) {
4858 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
4859 /*
4860 * To check
4861 * is there any special for CONFIG_HDMI_PASSTHROUGH_CONVERT
4862 * & DOLBY_DIGITAL_PLUS
4863 */
4864 if (info->audio_blocks_array[i].format_id == format_id) {
Mingming Yin3a941d42016-02-17 18:08:05 -08004865 ALOGV("%s:returns true %x",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304866 __func__, format);
4867 return true;
4868 }
4869 }
4870 }
Mingming Yin3a941d42016-02-17 18:08:05 -08004871 ALOGV("%s:returns false %x",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304872 __func__, format);
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07004873 return false;
4874}
4875
Mingming Yin3a941d42016-02-17 18:08:05 -08004876bool platform_is_edid_supported_sample_rate(void *platform, int sample_rate)
4877{
4878 struct platform_data *my_data = (struct platform_data *)platform;
Mingming Yin3a941d42016-02-17 18:08:05 -08004879 edid_audio_info *info = NULL;
Naresh Tanniru20e8b022016-04-28 16:54:17 +05304880 int i, ret;
Mingming Yin3a941d42016-02-17 18:08:05 -08004881
4882 ret = platform_get_edid_info(platform);
4883 info = (edid_audio_info *)my_data->edid_info;
4884 if (ret == 0 && info != NULL) {
4885 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
4886 /*
4887 * To check
4888 * is there any special for CONFIG_HDMI_PASSTHROUGH_CONVERT
4889 * & DOLBY_DIGITAL_PLUS
4890 */
4891 if (info->audio_blocks_array[i].sampling_freq == sample_rate) {
4892 ALOGV("%s: returns true %d", __func__, sample_rate);
4893 return true;
4894 }
4895 }
4896 }
4897 ALOGV("%s: returns false %d", __func__, sample_rate);
4898
4899 return false;
4900}
4901
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304902int platform_set_edid_channels_configuration(void *platform, int channels) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004903
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304904 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304905 edid_audio_info *info = NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304906 int channel_count = 2;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05304907 int i, ret;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304908 char default_channelMap[MAX_CHANNELS_SUPPORTED] = {0};
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004909
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304910 ret = platform_get_edid_info(platform);
4911 info = (edid_audio_info *)my_data->edid_info;
4912 if(ret == 0 && info != NULL) {
4913 if (channels > 2) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004914
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304915 ALOGV("%s:able to get HDMI sink capabilities multi channel playback",
4916 __func__);
4917 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
4918 if (info->audio_blocks_array[i].format_id == LPCM &&
4919 info->audio_blocks_array[i].channels > channel_count &&
4920 info->audio_blocks_array[i].channels <= MAX_HDMI_CHANNEL_CNT) {
4921 channel_count = info->audio_blocks_array[i].channels;
4922 }
4923 }
4924 ALOGV("%s:channel_count:%d", __func__, channel_count);
4925 /*
4926 * Channel map is set for supported hdmi max channel count even
4927 * though the input channel count set on adm is less than or equal to
4928 * max supported channel count
4929 */
4930 platform_set_channel_map(platform, channel_count, info->channel_map, -1);
4931 platform_set_channel_allocation(platform, info->channel_allocation);
4932 } else {
4933 default_channelMap[0] = PCM_CHANNEL_FL;
4934 default_channelMap[1] = PCM_CHANNEL_FR;
4935 platform_set_channel_map(platform,2,default_channelMap,-1);
4936 platform_set_channel_allocation(platform,0);
4937 }
4938 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004939
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004940 return 0;
4941}
4942
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304943void platform_cache_edid(void * platform)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004944{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304945 platform_get_edid_info(platform);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004946}
4947
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304948void platform_invalidate_edid(void * platform)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004949{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304950 struct platform_data *my_data = (struct platform_data *)platform;
4951 my_data->edid_valid = false;
4952 if (my_data->edid_info) {
4953 memset(my_data->edid_info, 0, sizeof(struct edid_audio_info));
4954 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004955}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304956
4957int platform_set_mixer_control(struct stream_out *out, const char * mixer_ctl_name,
4958 const char *mixer_val)
4959{
4960 struct audio_device *adev = out->dev;
4961 struct mixer_ctl *ctl = NULL;
4962 ALOGD("setting mixer ctl %s with value %s", mixer_ctl_name, mixer_val);
4963 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4964 if (!ctl) {
4965 ALOGE("%s: could not get ctl for mixer cmd - %s",
4966 __func__, mixer_ctl_name);
4967 return -EINVAL;
4968 }
4969
4970 return mixer_ctl_set_enum_by_string(ctl, mixer_val);
4971}
4972
Naresh Tanniru20e8b022016-04-28 16:54:17 +05304973static int set_mixer_control(struct mixer *mixer,
4974 const char * mixer_ctl_name,
4975 const char *mixer_val)
4976{
4977 struct mixer_ctl *ctl;
4978 ALOGD("setting mixer ctl %s with value %s", mixer_ctl_name, mixer_val);
4979 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
4980 if (!ctl) {
4981 ALOGE("%s: could not get ctl for mixer cmd - %s",
4982 __func__, mixer_ctl_name);
4983 return -EINVAL;
4984 }
4985
4986 return mixer_ctl_set_enum_by_string(ctl, mixer_val);
4987}
4988
Mingming Yin21854652016-04-13 11:54:02 -07004989int platform_set_hdmi_config(void *platform, uint32_t channel_count,
4990 uint32_t sample_rate, bool enable_passthrough)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304991{
Mingming Yin21854652016-04-13 11:54:02 -07004992 struct platform_data *my_data = (struct platform_data *)platform;
4993 struct audio_device *adev = my_data->adev;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05304994 const char *hdmi_format_ctrl = "HDMI RX Format";
Mingming Yin21854652016-04-13 11:54:02 -07004995 const char *hdmi_rate_ctrl = "HDMI_RX SampleRate";
4996 const char *hdmi_chans_ctrl = "HDMI_RX Channels";
4997 const char *channel_cnt_str = NULL;
4998
4999 ALOGI("%s ch[%d] sr[%d], pthru[%d]", __func__,
5000 channel_count, sample_rate, enable_passthrough);
5001
5002 switch (channel_count) {
5003 case 8:
5004 channel_cnt_str = "Eight"; break;
5005 case 7:
5006 channel_cnt_str = "Seven"; break;
5007 case 6:
5008 channel_cnt_str = "Six"; break;
5009 case 5:
5010 channel_cnt_str = "Five"; break;
5011 case 4:
5012 channel_cnt_str = "Four"; break;
5013 case 3:
5014 channel_cnt_str = "Three"; break;
5015 default:
5016 channel_cnt_str = "Two"; break;
5017 }
5018 ALOGV("%s: HDMI channel count: %s", __func__, channel_cnt_str);
5019 set_mixer_control(adev->mixer, hdmi_chans_ctrl, channel_cnt_str);
5020
5021 if (enable_passthrough) {
5022 ALOGD("%s:HDMI compress format", __func__);
5023 set_mixer_control(adev->mixer, hdmi_format_ctrl, "Compr");
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05305024 } else {
Mingming Yin21854652016-04-13 11:54:02 -07005025 ALOGD("%s: HDMI PCM format", __func__);
5026 set_mixer_control(adev->mixer, hdmi_format_ctrl, "LPCM");
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05305027 }
5028
Mingming Yin21854652016-04-13 11:54:02 -07005029 switch (sample_rate) {
5030 case 32000:
5031 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_32");
5032 break;
5033 case 44100:
5034 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_44P1");
5035 break;
5036 case 96000:
5037 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_96");
5038 break;
5039 case 128000:
5040 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_128");
5041 break;
5042 case 176400:
5043 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_176_4");
5044 break;
5045 case 192000:
5046 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_192");
5047 break;
5048 default:
5049 case 48000:
5050 set_mixer_control(adev->mixer, hdmi_rate_ctrl, "KHZ_48");
5051 break;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05305052 }
5053
5054 return 0;
5055}
5056
Mingming Yin21854652016-04-13 11:54:02 -07005057
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05305058int platform_set_device_params(struct stream_out *out, int param, int value)
5059{
5060 struct audio_device *adev = out->dev;
5061 struct mixer_ctl *ctl;
5062 char *mixer_ctl_name = "Device PP Params";
5063 int ret = 0;
5064 uint32_t set_values[] = {0,0};
5065
5066 set_values[0] = param;
5067 set_values[1] = value;
5068
5069 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5070 if (!ctl) {
5071 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5072 __func__, mixer_ctl_name);
5073 ret = -EINVAL;
5074 goto end;
5075 }
5076
5077 ALOGV("%s: Setting device pp params param: %d, value %d mixer ctrl:%s",
5078 __func__,param, value, mixer_ctl_name);
5079 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
5080
5081end:
5082 return ret;
5083}
5084
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05305085int platform_get_subsys_image_name(char *buf)
5086{
5087 strlcpy(buf, PLATFORM_IMAGE_NAME, sizeof(PLATFORM_IMAGE_NAME));
5088 return 0;
5089}
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08005090
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305091/*
5092 * This is a lookup table to map android audio input device to audio h/w interface (backend).
5093 * The table can be extended for other input devices by adding appropriate entries.
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05305094 * The audio interface for a particular input device need to be added in
5095 * audio_platform_info.xml file.
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305096 */
5097struct audio_device_to_audio_interface audio_device_to_interface_table[] = {
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05305098 {AUDIO_DEVICE_IN_BUILTIN_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC), ""},
5099 {AUDIO_DEVICE_IN_BACK_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BACK_MIC), ""},
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305100};
5101
5102int audio_device_to_interface_table_len =
5103 sizeof(audio_device_to_interface_table) / sizeof(audio_device_to_interface_table[0]);
5104
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305105int platform_set_audio_device_interface(const char * device_name,
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05305106 const char *intf_name,
5107 const char *codec_type)
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08005108{
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305109 int ret = 0;
5110 int i;
5111
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05305112 if (device_name == NULL || intf_name == NULL || codec_type == NULL) {
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305113 ALOGE("%s: Invalid input", __func__);
5114
5115 ret = -EINVAL;
5116 goto done;
5117 }
5118
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05305119 ALOGD("%s: Enter, device name:%s, intf name:%s, codec_type:%s", __func__,
5120 device_name, intf_name, codec_type);
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305121
5122 size_t device_name_len = strlen(device_name);
5123 for (i = 0; i < audio_device_to_interface_table_len; i++) {
5124 char* name = audio_device_to_interface_table[i].device_name;
5125 size_t name_len = strlen(name);
5126 if ((name_len == device_name_len) &&
5127 (strncmp(device_name, name, name_len) == 0)) {
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05305128 if (is_external_codec &&
5129 (strncmp(codec_type, "external", strlen(codec_type)) == 0)) {
5130 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305131 __func__, device_name, intf_name);
5132
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05305133 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305134 sizeof(audio_device_to_interface_table[i].interface_name));
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05305135 } else if (!is_external_codec &&
5136 (strncmp(codec_type, "internal", strlen(codec_type)) == 0)) {
5137 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
5138 __func__, device_name, intf_name);
5139
5140 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
5141 sizeof(audio_device_to_interface_table[i].interface_name));
5142 } else
5143 ALOGE("Invalid codec_type specified. Ignoring this interface entry.");
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05305144 goto done;
5145 }
5146 }
5147 ALOGE("%s: Could not find matching device name %s",
5148 __func__, device_name);
5149
5150 ret = -EINVAL;
5151
5152done:
5153 return ret;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08005154}
Laxminath Kasam82252432015-05-29 18:37:11 +05305155
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05305156 /*
Laxminath Kasam44f49402015-05-29 18:37:11 +05305157 * This is a lookup table to map names of speaker device with respective left and right TZ names.
5158 * Also the tz names for a particular left or right speaker can be overriden by adding
5159 * corresponding entry in audio_platform_info.xml file.
5160 */
5161struct speaker_device_to_tz_names speaker_device_tz_names = {
Alexy Josephb1379942016-01-29 15:49:38 -08005162 SND_DEVICE_OUT_SPEAKER, "", ""
Laxminath Kasam44f49402015-05-29 18:37:11 +05305163};
5164
5165const char *platform_get_spkr_1_tz_name(snd_device_t snd_device)
Asish Bhattacharya4a69acd2015-07-12 20:54:14 +05305166{
Laxminath Kasam44f49402015-05-29 18:37:11 +05305167 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
5168 return speaker_device_tz_names.spkr_1_tz_name;
5169 else
5170 return "";
5171}
5172
5173const char *platform_get_spkr_2_tz_name(snd_device_t snd_device)
5174{
5175 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
5176 return speaker_device_tz_names.spkr_2_tz_name;
5177 else
5178 return "";
5179}
5180
5181int platform_set_spkr_device_tz_names(snd_device_t index,
5182 const char *spkr_1_tz_name, const char *spkr_2_tz_name)
5183{
5184 int ret = 0;
Laxminath Kasam44f49402015-05-29 18:37:11 +05305185
5186 if (spkr_1_tz_name == NULL && spkr_2_tz_name == NULL) {
5187 ALOGE("%s: Invalid input", __func__);
5188 ret = -EINVAL;
5189 goto done;
5190 }
5191 if (index != speaker_device_tz_names.snd_device) {
Alexy Josephb1379942016-01-29 15:49:38 -08005192 ALOGE("%s: not matching speaker device\n", __func__);
Laxminath Kasam44f49402015-05-29 18:37:11 +05305193 ret = -EINVAL;
5194 goto done;
5195 }
5196 ALOGD("%s: Enter, spkr_1_tz_name :%s, spkr_2_tz_name:%s",
5197 __func__, spkr_1_tz_name, spkr_2_tz_name);
5198
5199 if (spkr_1_tz_name != NULL)
5200 strlcpy(speaker_device_tz_names.spkr_1_tz_name, spkr_1_tz_name,
5201 sizeof(speaker_device_tz_names.spkr_1_tz_name));
5202
5203 if (spkr_2_tz_name != NULL)
5204 strlcpy(speaker_device_tz_names.spkr_2_tz_name, spkr_2_tz_name,
5205 sizeof(speaker_device_tz_names.spkr_2_tz_name));
5206done:
5207 return ret;
Asish Bhattacharya4a69acd2015-07-12 20:54:14 +05305208}
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05305209
Venkata Narendra Kumar Gutta7f4817f2016-01-29 14:15:53 +05305210int platform_spkr_prot_is_wsa_analog_mode(void *adev)
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05305211{
5212 struct audio_device *adev_h = adev;
Alexy Josephb1379942016-01-29 15:49:38 -08005213 const char *snd_card_name;
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05305214
Venkata Narendra Kumar Gutta7f4817f2016-01-29 14:15:53 +05305215 /*
5216 * wsa analog mode is decided based on the sound card name
5217 */
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05305218 snd_card_name = mixer_get_name(adev_h->mixer);
5219 if ((!strcmp(snd_card_name, "msm8952-skum-snd-card")) ||
5220 (!strcmp(snd_card_name, "msm8952-snd-card")) ||
5221 (!strcmp(snd_card_name, "msm8952-snd-card-mtp")) ||
Venkata Narendra Kumar Gutta7f4817f2016-01-29 14:15:53 +05305222 (!strcmp(snd_card_name, "msm8976-skun-snd-card")) ||
5223 (!strcmp(snd_card_name, "msm8953-snd-card-mtp")))
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05305224 return 1;
5225 else
5226 return 0;
5227}
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05305228
5229bool platform_send_gain_dep_cal(void *platform __unused,
5230 int level __unused)
5231{
5232 return 0;
5233}
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08005234
5235bool platform_can_enable_spkr_prot_on_device(snd_device_t snd_device)
5236{
5237 bool ret = false;
5238
5239 if (snd_device == SND_DEVICE_OUT_SPEAKER ||
5240 snd_device == SND_DEVICE_OUT_SPEAKER_WSA ||
5241 snd_device == SND_DEVICE_OUT_SPEAKER_VBAT ||
5242 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
5243 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
5244 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_WSA) {
5245 ret = true;
5246 }
5247
5248 return ret;
5249}
5250
5251int platform_get_spkr_prot_acdb_id(snd_device_t snd_device)
5252{
5253 int acdb_id;
5254
5255 switch(snd_device) {
5256 case SND_DEVICE_OUT_SPEAKER:
5257 case SND_DEVICE_OUT_SPEAKER_WSA:
5258 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
5259 break;
5260 case SND_DEVICE_OUT_VOICE_SPEAKER:
5261 case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
5262 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
5263 break;
5264 case SND_DEVICE_OUT_SPEAKER_VBAT:
5265 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT);
5266 break;
5267 case SND_DEVICE_OUT_VOICE_SPEAKER_VBAT:
5268 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT);
5269 break;
5270 default:
5271 acdb_id = -EINVAL;
5272 break;
5273 }
5274 return acdb_id;
5275}
5276
5277int platform_get_spkr_prot_snd_device(snd_device_t snd_device)
5278{
5279 if (!audio_extn_spkr_prot_is_enabled())
5280 return snd_device;
5281
5282 switch(snd_device) {
5283 case SND_DEVICE_OUT_SPEAKER:
5284 case SND_DEVICE_OUT_SPEAKER_WSA:
5285 return SND_DEVICE_OUT_SPEAKER_PROTECTED;
5286 case SND_DEVICE_OUT_VOICE_SPEAKER:
5287 case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
5288 return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
5289 case SND_DEVICE_OUT_SPEAKER_VBAT:
5290 return SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT;
5291 case SND_DEVICE_OUT_VOICE_SPEAKER_VBAT:
5292 return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT;
5293 default:
5294 return snd_device;
5295 }
5296}