blob: 82ded60ef5e71892a6c4077cd1e7f8953d98a6ce [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07003 * Not a Contribution.
4 *
Shiv Maliyappanahalli8911f282014-01-10 15:56:19 -08005 * Copyright (C) 2013 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07006 *
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
20#define LOG_TAG "msm8974_platform"
21/*#define LOG_NDEBUG 0*/
22#define LOG_NDDEBUG 0
23
24#include <stdlib.h>
25#include <dlfcn.h>
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -070026#include <sys/ioctl.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070027#include <cutils/log.h>
28#include <cutils/properties.h>
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070029#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070030#include <audio_hw.h>
31#include <platform_api.h>
32#include "platform.h"
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -070033#include "audio_extn.h"
Narsinga Rao Chella05573b72013-11-15 15:21:40 -080034#include "voice_extn.h"
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -080035#include "sound/compress_params.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070036
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070037#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Damir Didjustof1d46c72013-11-06 17:59:04 -080038#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
Helen Zeng6a16ad72014-02-23 22:04:44 -080039#define MIXER_XML_PATH_I2S "/system/etc/mixer_paths_i2s.xml"
40
41#define PLATFORM_INFO_XML_PATH "/system/etc/audio_platform_info.xml"
42#define PLATFORM_INFO_XML_PATH_I2S "/system/etc/audio_platform_info_i2s.xml"
43
Eric Laurentb23d5282013-05-14 15:27:20 -070044#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070045#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Walter Yang6f800052014-07-14 16:15:38 -070046#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070047
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -080048#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
49#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
50#define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
51#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
52
53/* Used in calculating fragment size for pcm offload */
ApurupaPattapub57da782014-04-08 10:41:07 -070054#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV 1000 /* 1 sec */
55#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING 80 /* 80 millisecs */
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -080056
57/* MAX PCM fragment size cannot be increased further due
58 * to flinger's cblk size of 1mb,and it has to be a multiple of
59 * 24 - lcm of channels supported by DSP
60 */
61#define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024)
ApurupaPattapub57da782014-04-08 10:41:07 -070062#define MIN_PCM_OFFLOAD_FRAGMENT_SIZE (4 * 1024)
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -080063
64#define ALIGN( num, to ) (((num) + (to-1)) & (~(to-1)))
Eric Laurentb23d5282013-05-14 15:27:20 -070065/*
Eric Laurentb23d5282013-05-14 15:27:20 -070066 * This file will have a maximum of 38 bytes:
67 *
68 * 4 bytes: number of audio blocks
69 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
70 * Maximum 10 * 3 bytes: SAD blocks
71 */
72#define MAX_SAD_BLOCKS 10
73#define SAD_BLOCK_SIZE 3
74
Walter Yang6f800052014-07-14 16:15:38 -070075#define MAX_CVD_VERSION_STRING_SIZE 100
76
Eric Laurentb23d5282013-05-14 15:27:20 -070077/* EDID format ID for LPCM audio */
78#define EDID_FORMAT_LPCM 1
79
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -070080/* fallback app type if the default app type from acdb loader fails */
81#define DEFAULT_APP_TYPE 0x11130
82
sangwoo1b9f4b32013-06-21 18:22:55 -070083/* Retry for delay in FW loading*/
84#define RETRY_NUMBER 10
85#define RETRY_US 500000
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -080086#define MAX_SND_CARD 8
sangwoo1b9f4b32013-06-21 18:22:55 -070087
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070088#define SAMPLE_RATE_8KHZ 8000
89#define SAMPLE_RATE_16KHZ 16000
90
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070091#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070092#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
Ben Rombergerc1dc70d2013-12-19 15:11:17 -080093#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
Tanya Finkel00130052014-07-14 04:26:56 -070094/* Query external audio device connection status */
95#define AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE "ext_audio_device"
96
97#define EVENT_EXTERNAL_SPK_1 "qc_ext_spk_1"
98#define EVENT_EXTERNAL_SPK_2 "qc_ext_spk_2"
99#define EVENT_EXTERNAL_MIC "qc_ext_mic"
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800100
101enum {
102 VOICE_FEATURE_SET_DEFAULT,
103 VOICE_FEATURE_SET_VOLUME_BOOST
104};
sangwoo53b2cf02013-07-25 19:18:44 -0700105
Eric Laurentb23d5282013-05-14 15:27:20 -0700106struct audio_block_header
107{
108 int reserved;
109 int length;
110};
111
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800112/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -0700113typedef void (*acdb_deallocate_t)();
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700114typedef int (*acdb_init_t)(const char *, char *);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700115typedef void (*acdb_send_audio_cal_t)(int, int, int , int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700116typedef void (*acdb_send_voice_cal_t)(int, int);
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800117typedef int (*acdb_reload_vocvoltable_t)(int);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700118typedef int (*acdb_get_default_app_type_t)(void);
Eric Laurentb23d5282013-05-14 15:27:20 -0700119
Eric Laurentb23d5282013-05-14 15:27:20 -0700120struct platform_data {
121 struct audio_device *adev;
122 bool fluence_in_spkr_mode;
123 bool fluence_in_voice_call;
124 bool fluence_in_voice_rec;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800125 bool fluence_in_audio_rec;
Tanya Finkel00130052014-07-14 04:26:56 -0700126 bool external_spk_1;
127 bool external_spk_2;
128 bool external_mic;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700129 int fluence_type;
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800130 int fluence_mode;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530131 char fluence_cap[PROPERTY_VALUE_MAX];
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700132 bool slowtalk;
Helen Zeng6a16ad72014-02-23 22:04:44 -0800133 bool is_i2s_ext_modem;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700134 /* Audio calibration related functions */
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800135 void *acdb_handle;
136 int voice_feature_set;
137 acdb_init_t acdb_init;
138 acdb_deallocate_t acdb_deallocate;
139 acdb_send_audio_cal_t acdb_send_audio_cal;
140 acdb_send_voice_cal_t acdb_send_voice_cal;
141 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700142 acdb_get_default_app_type_t acdb_get_default_app_type;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700143
144 void *hw_info;
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800145 struct csd_data *csd;
Eric Laurentb23d5282013-05-14 15:27:20 -0700146};
147
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700148static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700149 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
150 DEEP_BUFFER_PCM_DEVICE},
151 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700152 LOWLATENCY_PCM_DEVICE},
153 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
154 MULTIMEDIA2_PCM_DEVICE},
Krishnankutty Kolathappillya43f96e2013-11-01 12:17:53 -0700155 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
156 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -0700157#ifdef MULTIPLE_OFFLOAD_ENABLED
158 [USECASE_AUDIO_PLAYBACK_OFFLOAD2] =
159 {PLAYBACK_OFFLOAD_DEVICE2, PLAYBACK_OFFLOAD_DEVICE2},
160 [USECASE_AUDIO_PLAYBACK_OFFLOAD3] =
161 {PLAYBACK_OFFLOAD_DEVICE3, PLAYBACK_OFFLOAD_DEVICE3},
162 [USECASE_AUDIO_PLAYBACK_OFFLOAD4] =
163 {PLAYBACK_OFFLOAD_DEVICE4, PLAYBACK_OFFLOAD_DEVICE4},
164 [USECASE_AUDIO_PLAYBACK_OFFLOAD5] =
165 {PLAYBACK_OFFLOAD_DEVICE5, PLAYBACK_OFFLOAD_DEVICE5},
166 [USECASE_AUDIO_PLAYBACK_OFFLOAD6] =
167 {PLAYBACK_OFFLOAD_DEVICE6, PLAYBACK_OFFLOAD_DEVICE6},
168 [USECASE_AUDIO_PLAYBACK_OFFLOAD7] =
169 {PLAYBACK_OFFLOAD_DEVICE7, PLAYBACK_OFFLOAD_DEVICE7},
170 [USECASE_AUDIO_PLAYBACK_OFFLOAD8] =
171 {PLAYBACK_OFFLOAD_DEVICE8, PLAYBACK_OFFLOAD_DEVICE8},
172 [USECASE_AUDIO_PLAYBACK_OFFLOAD9] =
173 {PLAYBACK_OFFLOAD_DEVICE9, PLAYBACK_OFFLOAD_DEVICE9},
174#endif
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700175 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
Mingming Yine62d7842013-10-25 16:26:03 -0700176 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700177 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
178 LOWLATENCY_PCM_DEVICE},
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700179 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
180 MULTIMEDIA2_PCM_DEVICE},
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700181 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800182 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800183 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700184 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
185 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
186 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
187 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Vicky Sehrawat7e4fc152014-02-12 17:58:59 -0800188 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800189 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700190 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
191 AUDIO_RECORD_PCM_DEVICE},
192 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
193 AUDIO_RECORD_PCM_DEVICE},
194 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
195 AUDIO_RECORD_PCM_DEVICE},
Helen Zenge56b4852013-12-03 16:54:40 -0800196 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
197 COMPRESS_CAPTURE_DEVICE},
198 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
199 COMPRESS_CAPTURE_DEVICE},
200 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
201 COMPRESS_CAPTURE_DEVICE},
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -0700202 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
203 INCALL_MUSIC_UPLINK_PCM_DEVICE},
204 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
205 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700206 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
207 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700208};
209
210/* Array to store sound devices */
211static const char * const device_table[SND_DEVICE_MAX] = {
212 [SND_DEVICE_NONE] = "none",
213 /* Playback sound devices */
214 [SND_DEVICE_OUT_HANDSET] = "handset",
215 [SND_DEVICE_OUT_SPEAKER] = "speaker",
Tanya Finkel00130052014-07-14 04:26:56 -0700216 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = "speaker-ext-1",
217 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = "speaker-ext-2",
Eric Laurentb23d5282013-05-14 15:27:20 -0700218 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
219 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
220 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Tanya Finkel00130052014-07-14 04:26:56 -0700221 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = "speaker-and-headphones-ext-1",
222 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = "speaker-and-headphones-ext-2",
Eric Laurentb23d5282013-05-14 15:27:20 -0700223 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
224 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
225 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
226 [SND_DEVICE_OUT_HDMI] = "hdmi",
227 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
228 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700229 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700230 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
231 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
232 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700233 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
234 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
235 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700236 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700237 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
238 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
239 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
240 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
241 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
242 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700243 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Eric Laurentb23d5282013-05-14 15:27:20 -0700244
245 /* Capture sound devices */
246 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Tanya Finkel00130052014-07-14 04:26:56 -0700247 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = "handset-mic-ext",
Eric Laurentb23d5282013-05-14 15:27:20 -0700248 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800249 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
250 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
251 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800252 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800253 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
254 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
255 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800256 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800257 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
258 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
259 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800260 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800261 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
262 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
263 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
264 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700265 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
266 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
267 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
268 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700269 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700270 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700271 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700272 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700273 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700274 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Vidyakumar Athotaadfe4e32013-12-13 14:51:26 -0800275 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700276 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
277 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
278 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
279 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800280 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800281 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700282 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700283 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700284 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700285 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700286 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700287 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
288 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700289 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800290 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside",
291 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside",
292 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside",
293 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside",
294 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside",
Eric Laurentb23d5282013-05-14 15:27:20 -0700295};
296
297/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Ben Romberger55886882014-01-10 13:49:02 -0800298static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700299 [SND_DEVICE_NONE] = -1,
300 [SND_DEVICE_OUT_HANDSET] = 7,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800301 [SND_DEVICE_OUT_SPEAKER] = 14,
Tanya Finkel00130052014-07-14 04:26:56 -0700302 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = 14,
303 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = 14,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800304 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700305 [SND_DEVICE_OUT_HEADPHONES] = 10,
306 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Tanya Finkel00130052014-07-14 04:26:56 -0700307 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = 10,
308 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = 10,
Eric Laurentb23d5282013-05-14 15:27:20 -0700309 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800310 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700311 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
312 [SND_DEVICE_OUT_HDMI] = 18,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800313 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700314 [SND_DEVICE_OUT_BT_SCO] = 22,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700315 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Eric Laurentb23d5282013-05-14 15:27:20 -0700316 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
317 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
318 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700319 [SND_DEVICE_OUT_AFE_PROXY] = 0,
Vidyakumar Athotab9522202014-01-14 20:08:27 -0800320 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700321 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700322 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700323 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700324 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700325 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700326 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700327 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
328 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700329 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 101,
Eric Laurentb23d5282013-05-14 15:27:20 -0700330
331 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Tanya Finkel00130052014-07-14 04:26:56 -0700332 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800333 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
334 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
335 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800336 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800337 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
338 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
339 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800340 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800341 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
342 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
343 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800344 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800345 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
346 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
347 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Eric Laurentb23d5282013-05-14 15:27:20 -0700348 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800349 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Eric Laurentb23d5282013-05-14 15:27:20 -0700350 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
351 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
352 [SND_DEVICE_IN_HDMI_MIC] = 4,
353 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700354 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 122,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700355 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700356 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 123,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800357 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700358 [SND_DEVICE_IN_VOICE_DMIC] = 41,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700359 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
Vidyakumar Athotaadfe4e32013-12-13 14:51:26 -0800360 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Eric Laurentb23d5282013-05-14 15:27:20 -0700361 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
362 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
363 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800364 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800365 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800366 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
367 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700368 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700369 [SND_DEVICE_IN_CAPTURE_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700370 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700371 [SND_DEVICE_IN_QUAD_MIC] = 46,
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700372 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
373 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700374 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800375 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12,
376 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12,
377 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
378 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
379 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
Eric Laurentb23d5282013-05-14 15:27:20 -0700380};
381
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700382struct name_to_index {
Ben Romberger61764e32014-01-10 13:49:02 -0800383 char name[100];
384 unsigned int index;
385};
386
387#define TO_NAME_INDEX(X) #X, X
388
389/* Used to get index from parsed sting */
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700390static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
Ben Romberger61764e32014-01-10 13:49:02 -0800391 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
392 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
Tanya Finkel00130052014-07-14 04:26:56 -0700393 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_1)},
394 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_2)},
Ben Romberger61764e32014-01-10 13:49:02 -0800395 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
396 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
397 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Tanya Finkel00130052014-07-14 04:26:56 -0700398 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1)},
399 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2)},
Ben Romberger61764e32014-01-10 13:49:02 -0800400 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
401 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
402 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
403 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
404 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
405 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
406 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
407 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
408 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
409 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
410 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
411 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
412 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
413 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
414 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
415 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
416 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
417 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
418 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
419 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
420 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
421 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Tanya Finkel00130052014-07-14 04:26:56 -0700422 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)},
Ben Romberger61764e32014-01-10 13:49:02 -0800423 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
424 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
425 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
426 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
427 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
428 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
429 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
430 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
431 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
432 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
433 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
434 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
435 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
436 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
437 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
438 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
439 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
440 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
441 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
442 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
443 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700444 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Ben Romberger61764e32014-01-10 13:49:02 -0800445 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700446 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Ben Romberger61764e32014-01-10 13:49:02 -0800447 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
448 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
449 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
450 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
451 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
452 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
453 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
454 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
455 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
456 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
457 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
458 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
459 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
460 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
461 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
462 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
463 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
464 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800465 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE)},
466 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE)},
467 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE)},
468 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE)},
469 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)},
Ben Romberger61764e32014-01-10 13:49:02 -0800470};
471
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700472static char * backend_table[SND_DEVICE_MAX] = {0};
473
474static struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
475 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
476 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
477 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
478 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
479 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
480 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
481 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
482 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
483 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
484 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
485 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
486 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
487 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
488 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
489 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
490};
491
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700492#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
493#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
494
Anish Kumar4980fa12014-04-17 12:42:20 -0700495static void set_echo_reference(struct audio_device *adev, bool enable)
Eric Laurentb23d5282013-05-14 15:27:20 -0700496{
Anish Kumar4980fa12014-04-17 12:42:20 -0700497 if (enable)
498 audio_route_apply_and_update_path(adev->audio_route, "echo-reference");
499 else
500 audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
Eric Laurentb23d5282013-05-14 15:27:20 -0700501
Anish Kumar4980fa12014-04-17 12:42:20 -0700502 ALOGV("Setting EC Reference: %d", enable);
Eric Laurentb23d5282013-05-14 15:27:20 -0700503}
504
Helen Zeng6a16ad72014-02-23 22:04:44 -0800505static struct csd_data *open_csd_client(bool i2s_ext_modem)
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800506{
507 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
508
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700509 if (!csd) {
510 ALOGE("failed to allocate csd_data mem");
511 return NULL;
512 }
513
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800514 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
515 if (csd->csd_client == NULL) {
516 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
517 goto error;
518 } else {
519 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
520
521 csd->deinit = (deinit_t)dlsym(csd->csd_client,
522 "csd_client_deinit");
523 if (csd->deinit == NULL) {
524 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
525 dlerror());
526 goto error;
527 }
528 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
529 "csd_client_disable_device");
530 if (csd->disable_device == NULL) {
531 ALOGE("%s: dlsym error %s for csd_client_disable_device",
532 __func__, dlerror());
533 goto error;
534 }
Vidyakumar Athota545dbd32013-11-13 17:30:53 -0800535 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
536 "csd_client_enable_device_config");
537 if (csd->enable_device_config == NULL) {
538 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
539 __func__, dlerror());
540 goto error;
541 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800542 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
543 "csd_client_enable_device");
544 if (csd->enable_device == NULL) {
545 ALOGE("%s: dlsym error %s for csd_client_enable_device",
546 __func__, dlerror());
547 goto error;
548 }
549 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
550 "csd_client_start_voice");
551 if (csd->start_voice == NULL) {
552 ALOGE("%s: dlsym error %s for csd_client_start_voice",
553 __func__, dlerror());
554 goto error;
555 }
556 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
557 "csd_client_stop_voice");
558 if (csd->stop_voice == NULL) {
559 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
560 __func__, dlerror());
561 goto error;
562 }
563 csd->volume = (volume_t)dlsym(csd->csd_client,
564 "csd_client_volume");
565 if (csd->volume == NULL) {
566 ALOGE("%s: dlsym error %s for csd_client_volume",
567 __func__, dlerror());
568 goto error;
569 }
570 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
571 "csd_client_mic_mute");
572 if (csd->mic_mute == NULL) {
573 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
574 __func__, dlerror());
575 goto error;
576 }
577 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
578 "csd_client_slow_talk");
579 if (csd->slow_talk == NULL) {
580 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
581 __func__, dlerror());
582 goto error;
583 }
584 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
585 "csd_client_start_playback");
586 if (csd->start_playback == NULL) {
587 ALOGE("%s: dlsym error %s for csd_client_start_playback",
588 __func__, dlerror());
589 goto error;
590 }
591 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
592 "csd_client_stop_playback");
593 if (csd->stop_playback == NULL) {
594 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
595 __func__, dlerror());
596 goto error;
597 }
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -0700598 csd->set_lch = (set_lch_t)dlsym(csd->csd_client, "csd_client_set_lch");
599 if (csd->set_lch == NULL) {
600 ALOGE("%s: dlsym error %s for csd_client_set_lch",
601 __func__, dlerror());
602 /* Ignore the error as this is not mandatory function for
603 * basic voice call to work.
604 */
605 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800606 csd->start_record = (start_record_t)dlsym(csd->csd_client,
607 "csd_client_start_record");
608 if (csd->start_record == NULL) {
609 ALOGE("%s: dlsym error %s for csd_client_start_record",
610 __func__, dlerror());
611 goto error;
612 }
613 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
614 "csd_client_stop_record");
615 if (csd->stop_record == NULL) {
616 ALOGE("%s: dlsym error %s for csd_client_stop_record",
617 __func__, dlerror());
618 goto error;
619 }
Helen Zeng6a16ad72014-02-23 22:04:44 -0800620
621 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
622 "csd_client_get_sample_rate");
623 if (csd->get_sample_rate == NULL) {
624 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
625 __func__, dlerror());
626
627 goto error;
628 }
629
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800630 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
631
632 if (csd->init == NULL) {
633 ALOGE("%s: dlsym error %s for csd_client_init",
634 __func__, dlerror());
635 goto error;
636 } else {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800637 csd->init(i2s_ext_modem);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800638 }
639 }
640 return csd;
641
642error:
643 free(csd);
644 csd = NULL;
645 return csd;
646}
647
648void close_csd_client(struct csd_data *csd)
649{
650 if (csd != NULL) {
651 csd->deinit();
652 dlclose(csd->csd_client);
653 free(csd);
654 csd = NULL;
655 }
656}
657
Helen Zeng6a16ad72014-02-23 22:04:44 -0800658static bool platform_is_i2s_ext_modem(const char *snd_card_name,
659 struct platform_data *plat_data)
660{
661 plat_data->is_i2s_ext_modem = false;
662
663 if (!strncmp(snd_card_name, "apq8084-taiko-i2s-mtp-snd-card",
664 sizeof("apq8084-taiko-i2s-mtp-snd-card")) ||
665 !strncmp(snd_card_name, "apq8084-taiko-i2s-cdp-snd-card",
666 sizeof("apq8084-taiko-i2s-cdp-snd-card"))) {
667 plat_data->is_i2s_ext_modem = true;
668 }
669 ALOGV("%s, is_i2s_ext_modem:%d",__func__, plat_data->is_i2s_ext_modem);
670
671 return plat_data->is_i2s_ext_modem;
Helen Zeng008aebd2014-02-23 19:13:12 -0800672}
673
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700674static void set_platform_defaults()
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700675{
676 int32_t dev;
677 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
678 backend_table[dev] = NULL;
679 }
680
681 // TBD - do these go to the platform-info.xml file.
682 // will help in avoiding strdups here
683 backend_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
684 backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700685 backend_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
686 backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700687 backend_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
688 backend_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
689 backend_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
690 backend_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
691 backend_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("afe-proxy");
692 backend_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headphones");
693 backend_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
694 strdup("speaker-and-usb-headphones");
695 backend_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
696 backend_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("capture-fm");
697 backend_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("transmission-fm");
698}
699
Walter Yang6f800052014-07-14 16:15:38 -0700700void get_cvd_version(char *cvd_version, struct audio_device *adev)
701{
702 struct mixer_ctl *ctl;
703 int count;
704 int ret = 0;
705
706 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
707 if (!ctl) {
708 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
709 goto done;
710 }
711 mixer_ctl_update(ctl);
712
713 count = mixer_ctl_get_num_values(ctl);
714 if (count > MAX_CVD_VERSION_STRING_SIZE)
715 count = MAX_CVD_VERSION_STRING_SIZE;
716
717 ret = mixer_ctl_get_array(ctl, cvd_version, count);
718 if (ret != 0) {
719 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
720 goto done;
721 }
722
723done:
724 return;
725}
726
Eric Laurentb23d5282013-05-14 15:27:20 -0700727void *platform_init(struct audio_device *adev)
728{
Vidyakumar Athota77327dd2014-08-07 16:44:25 -0700729 char platform[PROPERTY_VALUE_MAX];
730 char baseband[PROPERTY_VALUE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -0700731 char value[PROPERTY_VALUE_MAX];
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800732 struct platform_data *my_data = NULL;
733 int retry_num = 0, snd_card_num = 0;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700734 const char *snd_card_name;
Walter Yang6f800052014-07-14 16:15:38 -0700735 char *cvd_version = NULL;
sangwoo1b9f4b32013-06-21 18:22:55 -0700736
Eric Laurentb23d5282013-05-14 15:27:20 -0700737 my_data = calloc(1, sizeof(struct platform_data));
738
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700739 if (!my_data) {
740 ALOGE("failed to allocate platform data");
741 return NULL;
742 }
743
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800744 while (snd_card_num < MAX_SND_CARD) {
745 adev->mixer = mixer_open(snd_card_num);
746
747 while (!adev->mixer && retry_num < RETRY_NUMBER) {
748 usleep(RETRY_US);
749 adev->mixer = mixer_open(snd_card_num);
750 retry_num++;
751 }
752
753 if (!adev->mixer) {
754 ALOGE("%s: Unable to open the mixer card: %d", __func__,
755 snd_card_num);
756 retry_num = 0;
757 snd_card_num++;
758 continue;
759 }
760
761 snd_card_name = mixer_get_name(adev->mixer);
762 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
763
764 my_data->hw_info = hw_info_init(snd_card_name);
765 if (!my_data->hw_info) {
766 ALOGE("%s: Failed to init hardware info", __func__);
767 } else {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800768 if (platform_is_i2s_ext_modem(snd_card_name, my_data)) {
769 ALOGD("%s: Call MIXER_XML_PATH_I2S", __func__);
770
771 adev->audio_route = audio_route_init(snd_card_num,
772 MIXER_XML_PATH_I2S);
773 } else if (audio_extn_read_xml(adev, snd_card_num, MIXER_XML_PATH,
774 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800775 adev->audio_route = audio_route_init(snd_card_num,
776 MIXER_XML_PATH);
Helen Zeng6a16ad72014-02-23 22:04:44 -0800777 }
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800778 if (!adev->audio_route) {
779 ALOGE("%s: Failed to init audio route controls, aborting.",
780 __func__);
781 free(my_data);
782 return NULL;
783 }
784 adev->snd_card = snd_card_num;
785 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
786 break;
787 }
788 retry_num = 0;
789 snd_card_num++;
790 }
791
792 if (snd_card_num >= MAX_SND_CARD) {
793 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
794 free(my_data);
795 return NULL;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700796 }
797
Eric Laurentb23d5282013-05-14 15:27:20 -0700798 my_data->adev = adev;
Eric Laurentb23d5282013-05-14 15:27:20 -0700799 my_data->fluence_in_spkr_mode = false;
800 my_data->fluence_in_voice_call = false;
801 my_data->fluence_in_voice_rec = false;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800802 my_data->fluence_in_audio_rec = false;
Tanya Finkel00130052014-07-14 04:26:56 -0700803 my_data->external_spk_1 = false;
804 my_data->external_spk_2 = false;
805 my_data->external_mic = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700806 my_data->fluence_type = FLUENCE_NONE;
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800807 my_data->fluence_mode = FLUENCE_ENDFIRE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700808
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530809 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
810 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800811 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530812 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700813 my_data->fluence_type = FLUENCE_DUAL_MIC;
814 } else {
815 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700816 }
817
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700818 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700819 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700820 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700821 my_data->fluence_in_voice_call = true;
822 }
823
824 property_get("persist.audio.fluence.voicerec",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700825 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700826 my_data->fluence_in_voice_rec = true;
827 }
828
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800829 property_get("persist.audio.fluence.audiorec",value,"");
830 if (!strncmp("true", value, sizeof("true"))) {
831 my_data->fluence_in_audio_rec = true;
832 }
833
Eric Laurentb23d5282013-05-14 15:27:20 -0700834 property_get("persist.audio.fluence.speaker",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700835 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700836 my_data->fluence_in_spkr_mode = true;
837 }
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800838
839 property_get("persist.audio.fluence.mode",value,"");
840 if (!strncmp("broadside", value, sizeof("broadside"))) {
841 my_data->fluence_mode = FLUENCE_BROADSIDE;
842 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700843 }
844
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800845 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Eric Laurentb23d5282013-05-14 15:27:20 -0700846 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
847 if (my_data->acdb_handle == NULL) {
848 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
849 } else {
850 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
851 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
852 "acdb_loader_deallocate_ACDB");
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800853 if (!my_data->acdb_deallocate)
854 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
855 __func__, LIB_ACDB_LOADER);
856
Eric Laurentb23d5282013-05-14 15:27:20 -0700857 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 -0700858 "acdb_loader_send_audio_cal_v2");
Eric Laurentb23d5282013-05-14 15:27:20 -0700859 if (!my_data->acdb_send_audio_cal)
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800860 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -0700861 __func__, LIB_ACDB_LOADER);
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800862
Eric Laurentb23d5282013-05-14 15:27:20 -0700863 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
864 "acdb_loader_send_voice_cal");
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800865 if (!my_data->acdb_send_voice_cal)
866 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
867 __func__, LIB_ACDB_LOADER);
868
869 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
870 "acdb_loader_reload_vocvoltable");
871 if (!my_data->acdb_reload_vocvoltable)
872 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
873 __func__, LIB_ACDB_LOADER);
874
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700875 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
876 my_data->acdb_handle,
877 "acdb_loader_get_default_app_type");
878 if (!my_data->acdb_get_default_app_type)
879 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
880 __func__, LIB_ACDB_LOADER);
881
Eric Laurentb23d5282013-05-14 15:27:20 -0700882 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Ben Romberger490d3472014-01-15 17:11:59 -0800883 "acdb_loader_init_v2");
Walter Yang6f800052014-07-14 16:15:38 -0700884 if (my_data->acdb_init == NULL) {
Ben Romberger490d3472014-01-15 17:11:59 -0800885 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Walter Yang6f800052014-07-14 16:15:38 -0700886 goto acdb_init_fail;
887 }
888
889 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
890 if (!cvd_version)
891 ALOGE("failed to allocate cvd_version");
Eric Laurentb23d5282013-05-14 15:27:20 -0700892 else
Walter Yang6f800052014-07-14 16:15:38 -0700893 get_cvd_version(cvd_version, adev);
894
895 my_data->acdb_init(snd_card_name, cvd_version);
896 if (cvd_version)
897 free(cvd_version);
Eric Laurentb23d5282013-05-14 15:27:20 -0700898 }
899
Walter Yang6f800052014-07-14 16:15:38 -0700900acdb_init_fail:
901
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700902 set_platform_defaults();
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700903
Ben Romberger55886882014-01-10 13:49:02 -0800904 /* Initialize ACDB ID's */
Helen Zeng6a16ad72014-02-23 22:04:44 -0800905 if (my_data->is_i2s_ext_modem)
906 platform_info_init(PLATFORM_INFO_XML_PATH_I2S);
907 else
908 platform_info_init(PLATFORM_INFO_XML_PATH);
Ben Romberger55886882014-01-10 13:49:02 -0800909
Vidyakumar Athota77327dd2014-08-07 16:44:25 -0700910 /* If platform is apq8084 and baseband is MDM, load CSD Client specific
911 * symbols. Voice call is handled by MDM and apps processor talks to
912 * MDM through CSD Client
913 */
914 property_get("ro.board.platform", platform, "");
915 property_get("ro.baseband", baseband, "");
916 if (!strncmp("apq8084", platform, sizeof("apq8084")) &&
917 !strncmp("mdm", baseband, (sizeof("mdm")-1))) {
918 my_data->csd = open_csd_client(my_data->is_i2s_ext_modem);
919 } else {
920 my_data->csd = NULL;
921 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800922
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700923 /* init usb */
924 audio_extn_usb_init(adev);
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800925 /* update sound cards appropriately */
926 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700927
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700928 /* Read one time ssr property */
Mingming Yin49be8032013-12-19 12:51:25 -0800929 audio_extn_ssr_update_enabled();
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700930 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530931
932 audio_extn_dolby_set_license(adev);
933
Lior Barenboim0b61bc72014-05-13 13:01:37 +0300934 /* init audio device arbitration */
935 audio_extn_dev_arbi_init();
936
Eric Laurentb23d5282013-05-14 15:27:20 -0700937 return my_data;
938}
939
940void platform_deinit(void *platform)
941{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700942 struct platform_data *my_data = (struct platform_data *)platform;
943
944 hw_info_deinit(my_data->hw_info);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800945 close_csd_client(my_data->csd);
946
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700947 int32_t dev;
948 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
949 if (backend_table[dev]) {
950 free(backend_table[dev]);
951 backend_table[dev]= NULL;
952 }
953 }
954
Lior Barenboim0b61bc72014-05-13 13:01:37 +0300955 /* deinit audio device arbitration */
956 audio_extn_dev_arbi_deinit();
957
Eric Laurentb23d5282013-05-14 15:27:20 -0700958 free(platform);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700959 /* deinit usb */
960 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -0700961}
962
963const char *platform_get_snd_device_name(snd_device_t snd_device)
964{
965 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
966 return device_table[snd_device];
967 else
968 return "";
969}
970
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700971int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
972 char *device_name)
973{
974 struct platform_data *my_data = (struct platform_data *)platform;
975
976 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
977 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
978 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
979 } else {
980 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
981 return -EINVAL;
982 }
983
984 return 0;
985}
986
Eric Laurentb23d5282013-05-14 15:27:20 -0700987void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
988{
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700989 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
990 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
991 return;
992 }
993
994 const char * suffix = backend_table[snd_device];
995
996 if (suffix != NULL) {
997 strlcat(mixer_path, " ", MIXER_PATH_MAX_LENGTH);
998 strlcat(mixer_path, suffix, MIXER_PATH_MAX_LENGTH);
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -0800999 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001000}
1001
1002int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1003{
1004 int device_id;
1005 if (device_type == PCM_PLAYBACK)
1006 device_id = pcm_device_table[usecase][0];
1007 else
1008 device_id = pcm_device_table[usecase][1];
1009 return device_id;
1010}
1011
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001012static int find_index(struct name_to_index * table, int32_t len, const char * name)
Ben Romberger61764e32014-01-10 13:49:02 -08001013{
1014 int ret = 0;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001015 int32_t i;
Ben Romberger61764e32014-01-10 13:49:02 -08001016
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001017 if (table == NULL) {
1018 ALOGE("%s: table is NULL", __func__);
Ben Romberger61764e32014-01-10 13:49:02 -08001019 ret = -ENODEV;
1020 goto done;
1021 }
1022
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001023 if (name == NULL) {
1024 ALOGE("null key");
1025 ret = -ENODEV;
1026 goto done;
1027 }
1028
1029 for (i=0; i < len; i++) {
1030 const char* tn = table[i].name;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001031 size_t len = strlen(tn);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001032 if (strncmp(tn, name, len) == 0) {
1033 if (strlen(name) != len) {
1034 continue; // substring
1035 }
1036 ret = table[i].index;
Ben Romberger61764e32014-01-10 13:49:02 -08001037 goto done;
1038 }
1039 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001040 ALOGE("%s: Could not find index for name = %s",
1041 __func__, name);
Ben Romberger61764e32014-01-10 13:49:02 -08001042 ret = -ENODEV;
1043done:
1044 return ret;
1045}
1046
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301047int platform_set_fluence_type(void *platform, char *value)
1048{
1049 int ret = 0;
1050 int fluence_type = FLUENCE_NONE;
1051 int fluence_flag = NONE_FLAG;
1052 struct platform_data *my_data = (struct platform_data *)platform;
1053 struct audio_device *adev = my_data->adev;
1054
1055 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
1056
1057 /* only dual mic turn on and off is supported as of now through setparameters */
1058 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
1059 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
1060 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
1061 ALOGV("fluence dualmic feature enabled \n");
1062 fluence_type = FLUENCE_DUAL_MIC;
1063 fluence_flag = DMIC_FLAG;
1064 } else {
1065 ALOGE("%s: Failed to set DUALMIC", __func__);
1066 ret = -1;
1067 goto done;
1068 }
1069 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
1070 ALOGV("fluence disabled");
1071 fluence_type = FLUENCE_NONE;
1072 } else {
1073 ALOGE("Invalid fluence value : %s",value);
1074 ret = -1;
1075 goto done;
1076 }
1077
1078 if (fluence_type != my_data->fluence_type) {
1079 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
1080 my_data->fluence_type = fluence_type;
1081 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
1082 }
1083done:
1084 return ret;
1085}
1086
1087int platform_get_fluence_type(void *platform, char *value, uint32_t len)
1088{
1089 int ret = 0;
1090 struct platform_data *my_data = (struct platform_data *)platform;
1091
1092 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
1093 strlcpy(value, "quadmic", len);
1094 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
1095 strlcpy(value, "dualmic", len);
1096 } else if (my_data->fluence_type == FLUENCE_NONE) {
1097 strlcpy(value, "none", len);
1098 } else
1099 ret = -1;
1100
1101 return ret;
1102}
1103
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001104int platform_get_snd_device_index(char *device_name)
1105{
1106 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1107}
1108
1109int platform_get_usecase_index(const char *usecase_name)
1110{
1111 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1112}
1113
Ben Romberger55886882014-01-10 13:49:02 -08001114int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1115{
1116 int ret = 0;
1117
1118 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1119 ALOGE("%s: Invalid snd_device = %d",
1120 __func__, snd_device);
1121 ret = -EINVAL;
1122 goto done;
1123 }
1124
1125 acdb_device_table[snd_device] = acdb_id;
1126done:
1127 return ret;
1128}
1129
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001130int platform_get_default_app_type(void *platform)
1131{
1132 struct platform_data *my_data = (struct platform_data *)platform;
1133
1134 if (my_data->acdb_get_default_app_type)
1135 return my_data->acdb_get_default_app_type();
1136 else
1137 return DEFAULT_APP_TYPE;
1138}
1139
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07001140int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1141{
1142 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1143 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1144 return -EINVAL;
1145 }
1146 return acdb_device_table[snd_device];
1147}
1148
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001149int platform_send_audio_calibration(void *platform, snd_device_t snd_device,
1150 int app_type, int sample_rate)
Eric Laurentb23d5282013-05-14 15:27:20 -07001151{
1152 struct platform_data *my_data = (struct platform_data *)platform;
1153 int acdb_dev_id, acdb_dev_type;
1154
Anish Kumarf16721c2014-08-01 15:09:25 -07001155 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001156 if (acdb_dev_id < 0) {
1157 ALOGE("%s: Could not find acdb id for device(%d)",
1158 __func__, snd_device);
1159 return -EINVAL;
1160 }
1161 if (my_data->acdb_send_audio_cal) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001162 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001163 __func__, snd_device, acdb_dev_id);
1164 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1165 snd_device < SND_DEVICE_OUT_END)
1166 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1167 else
1168 acdb_dev_type = ACDB_DEV_TYPE_IN;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001169 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
1170 sample_rate);
Eric Laurentb23d5282013-05-14 15:27:20 -07001171 }
1172 return 0;
1173}
1174
1175int platform_switch_voice_call_device_pre(void *platform)
1176{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001177 struct platform_data *my_data = (struct platform_data *)platform;
1178 int ret = 0;
1179
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08001180 if (my_data->csd != NULL &&
1181 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001182 /* This must be called before disabling mixer controls on APQ side */
1183 ret = my_data->csd->disable_device();
1184 if (ret < 0) {
1185 ALOGE("%s: csd_client_disable_device, failed, error %d",
1186 __func__, ret);
1187 }
1188 }
1189 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001190}
1191
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001192int platform_switch_voice_call_enable_device_config(void *platform,
1193 snd_device_t out_snd_device,
1194 snd_device_t in_snd_device)
1195{
1196 struct platform_data *my_data = (struct platform_data *)platform;
1197 int acdb_rx_id, acdb_tx_id;
1198 int ret = 0;
1199
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001200 if (my_data->csd == NULL)
1201 return ret;
1202
1203 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1204 audio_extn_spkr_prot_is_enabled())
1205 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
1206 else
1207 acdb_rx_id = acdb_device_table[out_snd_device];
1208
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001209 acdb_tx_id = acdb_device_table[in_snd_device];
1210
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001211 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1212 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1213 if (ret < 0) {
1214 ALOGE("%s: csd_enable_device_config, failed, error %d",
1215 __func__, ret);
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001216 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001217 } else {
1218 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1219 acdb_rx_id, acdb_tx_id);
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001220 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001221
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001222 return ret;
1223}
1224
Eric Laurentb23d5282013-05-14 15:27:20 -07001225int platform_switch_voice_call_device_post(void *platform,
1226 snd_device_t out_snd_device,
1227 snd_device_t in_snd_device)
1228{
1229 struct platform_data *my_data = (struct platform_data *)platform;
1230 int acdb_rx_id, acdb_tx_id;
1231
1232 if (my_data->acdb_send_voice_cal == NULL) {
1233 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1234 } else {
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08001235 acdb_rx_id = acdb_device_table[out_snd_device];
1236 acdb_tx_id = acdb_device_table[in_snd_device];
1237
Eric Laurentb23d5282013-05-14 15:27:20 -07001238 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1239 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1240 else
1241 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1242 acdb_rx_id, acdb_tx_id);
1243 }
1244
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08001245 return 0;
1246}
1247
1248int platform_switch_voice_call_usecase_route_post(void *platform,
1249 snd_device_t out_snd_device,
1250 snd_device_t in_snd_device)
1251{
1252 struct platform_data *my_data = (struct platform_data *)platform;
1253 int acdb_rx_id, acdb_tx_id;
1254 int ret = 0;
1255
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001256 if (my_data->csd == NULL)
1257 return ret;
1258
1259 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1260 audio_extn_spkr_prot_is_enabled())
1261 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
1262 else
1263 acdb_rx_id = acdb_device_table[out_snd_device];
1264
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08001265 acdb_tx_id = acdb_device_table[in_snd_device];
1266
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001267 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1268 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1269 my_data->adev->acdb_settings);
1270 if (ret < 0) {
1271 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001272 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001273 } else {
1274 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1275 acdb_rx_id, acdb_tx_id);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001276 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001277
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001278 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001279}
1280
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001281int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001282{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001283 struct platform_data *my_data = (struct platform_data *)platform;
1284 int ret = 0;
1285
1286 if (my_data->csd != NULL) {
1287 ret = my_data->csd->start_voice(vsid);
1288 if (ret < 0) {
1289 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1290 }
1291 }
1292 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001293}
1294
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001295int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001296{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001297 struct platform_data *my_data = (struct platform_data *)platform;
1298 int ret = 0;
1299
1300 if (my_data->csd != NULL) {
1301 ret = my_data->csd->stop_voice(vsid);
1302 if (ret < 0) {
1303 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1304 }
1305 }
1306 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001307}
1308
Helen Zeng6a16ad72014-02-23 22:04:44 -08001309int platform_get_sample_rate(void *platform, uint32_t *rate)
1310{
1311 struct platform_data *my_data = (struct platform_data *)platform;
1312 int ret = 0;
1313
1314 if ((my_data->csd != NULL) && my_data->is_i2s_ext_modem) {
1315 ret = my_data->csd->get_sample_rate(rate);
1316 if (ret < 0) {
1317 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1318 }
1319 }
1320 return ret;
1321}
1322
Eric Laurentb23d5282013-05-14 15:27:20 -07001323int platform_set_voice_volume(void *platform, int volume)
1324{
1325 struct platform_data *my_data = (struct platform_data *)platform;
1326 struct audio_device *adev = my_data->adev;
1327 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001328 const char *mixer_ctl_name = "Voice Rx Gain";
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001329 int vol_index = 0, ret = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001330 uint32_t set_values[ ] = {0,
1331 ALL_SESSION_VSID,
1332 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001333
1334 // Voice volume levels are mapped to adsp volume levels as follows.
1335 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1336 // But this values don't changed in kernel. So, below change is need.
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001337 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1338 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001339
1340 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1341 if (!ctl) {
1342 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1343 __func__, mixer_ctl_name);
1344 return -EINVAL;
1345 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001346 ALOGV("Setting voice volume index: %d", set_values[0]);
1347 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -07001348
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001349 if (my_data->csd != NULL) {
Vidyakumar Athotac37f42a2014-03-11 11:57:48 -07001350 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1351 DEFAULT_VOLUME_RAMP_DURATION_MS);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001352 if (ret < 0) {
1353 ALOGE("%s: csd_volume error %d", __func__, ret);
1354 }
1355 }
1356 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001357}
1358
1359int platform_set_mic_mute(void *platform, bool state)
1360{
1361 struct platform_data *my_data = (struct platform_data *)platform;
1362 struct audio_device *adev = my_data->adev;
1363 struct mixer_ctl *ctl;
1364 const char *mixer_ctl_name = "Voice Tx Mute";
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001365 int ret = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001366 uint32_t set_values[ ] = {0,
1367 ALL_SESSION_VSID,
Vidyakumar Athotac37f42a2014-03-11 11:57:48 -07001368 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001369
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001370 set_values[0] = state;
1371 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1372 if (!ctl) {
1373 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1374 __func__, mixer_ctl_name);
1375 return -EINVAL;
1376 }
1377 ALOGV("Setting voice mute state: %d", state);
1378 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -07001379
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001380 if (my_data->csd != NULL) {
Vidyakumar Athotac37f42a2014-03-11 11:57:48 -07001381 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1382 DEFAULT_MUTE_RAMP_DURATION_MS);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001383 if (ret < 0) {
1384 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001385 }
1386 }
1387 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001388}
1389
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001390int platform_set_device_mute(void *platform, bool state, char *dir)
1391{
1392 struct platform_data *my_data = (struct platform_data *)platform;
1393 struct audio_device *adev = my_data->adev;
1394 struct mixer_ctl *ctl;
1395 char *mixer_ctl_name = NULL;
1396 int ret = 0;
1397 uint32_t set_values[ ] = {0,
1398 ALL_SESSION_VSID,
1399 0};
1400 if(dir == NULL) {
1401 ALOGE("%s: Invalid direction:%s", __func__, dir);
1402 return -EINVAL;
1403 }
1404
1405 if (!strncmp("rx", dir, sizeof("rx"))) {
1406 mixer_ctl_name = "Voice Rx Device Mute";
1407 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1408 mixer_ctl_name = "Voice Tx Device Mute";
1409 } else {
1410 return -EINVAL;
1411 }
1412
1413 set_values[0] = state;
1414 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1415 if (!ctl) {
1416 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1417 __func__, mixer_ctl_name);
1418 return -EINVAL;
1419 }
1420
1421 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1422 __func__,state, mixer_ctl_name);
1423 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1424
1425 return ret;
1426}
1427
Eric Laurentb23d5282013-05-14 15:27:20 -07001428snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1429{
1430 struct platform_data *my_data = (struct platform_data *)platform;
1431 struct audio_device *adev = my_data->adev;
1432 audio_mode_t mode = adev->mode;
1433 snd_device_t snd_device = SND_DEVICE_NONE;
1434
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001435 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1436 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1437 int channel_count = popcount(channel_mask);
1438
Eric Laurentb23d5282013-05-14 15:27:20 -07001439 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1440 if (devices == AUDIO_DEVICE_NONE ||
1441 devices & AUDIO_DEVICE_BIT_IN) {
1442 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1443 goto exit;
1444 }
1445
Mingming Yin4a72d652014-01-03 18:54:18 -08001446 if (popcount(devices) == 2) {
1447 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1448 AUDIO_DEVICE_OUT_SPEAKER)) {
Tanya Finkel00130052014-07-14 04:26:56 -07001449 if (my_data->external_spk_1)
1450 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
1451 else if (my_data->external_spk_2)
1452 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
1453 else
1454 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Mingming Yin4a72d652014-01-03 18:54:18 -08001455 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1456 AUDIO_DEVICE_OUT_SPEAKER)) {
1457 if (audio_extn_get_anc_enabled())
1458 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
Tanya Finkel00130052014-07-14 04:26:56 -07001459 else if (my_data->external_spk_1)
1460 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
1461 else if (my_data->external_spk_2)
1462 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
Mingming Yin4a72d652014-01-03 18:54:18 -08001463 else
1464 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1465 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1466 AUDIO_DEVICE_OUT_SPEAKER)) {
1467 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1468 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
1469 AUDIO_DEVICE_OUT_SPEAKER)) {
1470 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
1471 } else {
1472 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1473 goto exit;
1474 }
1475 if (snd_device != SND_DEVICE_NONE) {
1476 goto exit;
1477 }
1478 }
1479
1480 if (popcount(devices) != 1) {
1481 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1482 goto exit;
1483 }
1484
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001485 if ((mode == AUDIO_MODE_IN_CALL) ||
1486 voice_extn_compress_voip_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001487 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1488 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001489 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1490 !voice_extn_compress_voip_is_active(adev)) {
1491 switch (adev->voice.tty_mode) {
1492 case TTY_MODE_FULL:
1493 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
1494 break;
1495 case TTY_MODE_VCO:
1496 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
1497 break;
1498 case TTY_MODE_HCO:
1499 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
1500 break;
1501 default:
1502 ALOGE("%s: Invalid TTY mode (%#x)",
1503 __func__, adev->voice.tty_mode);
1504 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001505 } else if (audio_extn_get_anc_enabled()) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001506 if (audio_extn_should_use_fb_anc())
1507 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
1508 else
1509 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001510 } else {
Eric Laurentb23d5282013-05-14 15:27:20 -07001511 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001512 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001513 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07001514 if (adev->bt_wb_speech_enabled)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001515 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1516 else
1517 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -07001518 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1519 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001520 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1521 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1522 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07001523 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1524 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07001525 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -08001526 if (audio_extn_should_use_handset_anc(channel_count))
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001527 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001528 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001529 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001530 }
1531 if (snd_device != SND_DEVICE_NONE) {
1532 goto exit;
1533 }
1534 }
1535
Eric Laurentb23d5282013-05-14 15:27:20 -07001536 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1537 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001538 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
1539 && audio_extn_get_anc_enabled()) {
1540 if (audio_extn_should_use_fb_anc())
1541 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
1542 else
1543 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001544 } else
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001545 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurentb23d5282013-05-14 15:27:20 -07001546 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Tanya Finkel00130052014-07-14 04:26:56 -07001547 if (my_data->external_spk_1)
1548 snd_device = SND_DEVICE_OUT_SPEAKER_EXTERNAL_1;
1549 else if (my_data->external_spk_2)
1550 snd_device = SND_DEVICE_OUT_SPEAKER_EXTERNAL_2;
1551 else if (adev->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07001552 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1553 else
1554 snd_device = SND_DEVICE_OUT_SPEAKER;
1555 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07001556 if (adev->bt_wb_speech_enabled)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001557 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1558 else
1559 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -07001560 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1561 snd_device = SND_DEVICE_OUT_HDMI ;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001562 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1563 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001564 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
1565 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001566 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07001567 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
1568 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07001569 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
1570 snd_device = SND_DEVICE_OUT_HANDSET;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001571 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08001572 channel_count = audio_extn_get_afe_proxy_channel_count();
1573 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
1574 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001575 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Eric Laurentb23d5282013-05-14 15:27:20 -07001576 } else {
1577 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1578 }
1579exit:
1580 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1581 return snd_device;
1582}
1583
1584snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1585{
1586 struct platform_data *my_data = (struct platform_data *)platform;
1587 struct audio_device *adev = my_data->adev;
1588 audio_source_t source = (adev->active_input == NULL) ?
1589 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1590
1591 audio_mode_t mode = adev->mode;
1592 audio_devices_t in_device = ((adev->active_input == NULL) ?
1593 AUDIO_DEVICE_NONE : adev->active_input->device)
1594 & ~AUDIO_DEVICE_BIT_IN;
1595 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1596 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1597 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001598 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001599
1600 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1601 __func__, out_device, in_device);
Tanya Finkel00130052014-07-14 04:26:56 -07001602 if (my_data->external_mic) {
1603 if (((out_device != AUDIO_DEVICE_NONE) && (mode == AUDIO_MODE_IN_CALL)) ||
1604 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev)) {
1605 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1606 out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1607 out_device & AUDIO_DEVICE_OUT_SPEAKER )
1608 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
1609 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1610 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1611 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
1612 }
1613 }
1614
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001615 if (snd_device != AUDIO_DEVICE_NONE)
Tanya Finkel00130052014-07-14 04:26:56 -07001616 goto exit;
1617
Helen Zeng067b96b2013-11-26 12:10:29 -08001618 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
Satya Krishna Pindiproli071950f2014-05-21 14:45:28 +05301619 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001620 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
1621 !voice_extn_compress_voip_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001622 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1623 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001624 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001625 case TTY_MODE_FULL:
1626 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1627 break;
1628 case TTY_MODE_VCO:
1629 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1630 break;
1631 case TTY_MODE_HCO:
1632 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1633 break;
1634 default:
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001635 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07001636 }
1637 goto exit;
1638 }
1639 }
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001640 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001641 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
1642 audio_extn_should_use_handset_anc(channel_count)) {
1643 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
Banajit Goswamide0ea452014-04-07 12:11:47 -07001644 adev->acdb_settings |= ANC_FLAG;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001645 } else if (my_data->fluence_type == FLUENCE_NONE ||
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001646 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001647 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Anish Kumar4980fa12014-04-17 12:42:20 -07001648 set_echo_reference(adev, true);
Eric Laurentb23d5282013-05-14 15:27:20 -07001649 } else {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -08001650 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001651 }
1652 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1653 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Anish Kumar02f899d2014-05-08 10:01:42 -07001654 set_echo_reference(adev, true);
Eric Laurentb23d5282013-05-14 15:27:20 -07001655 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001656 if (adev->bt_wb_speech_enabled) {
1657 if (adev->bluetooth_nrec)
1658 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1659 else
1660 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1661 } else {
1662 if (adev->bluetooth_nrec)
1663 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1664 else
1665 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1666 }
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001667 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
1668 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001669 if (my_data->fluence_type != FLUENCE_NONE &&
1670 my_data->fluence_in_voice_call &&
1671 my_data->fluence_in_spkr_mode) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001672 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001673 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001674 } else {
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08001675 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1676 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
1677 else
1678 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001679 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001680 } else {
1681 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Anish Kumar02f899d2014-05-08 10:01:42 -07001682 set_echo_reference(adev, true);
Eric Laurentb23d5282013-05-14 15:27:20 -07001683 }
1684 }
1685 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1686 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1687 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1688 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1689 }
1690 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1691 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001692 if (channel_count == 2) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001693 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001694 } else if (adev->active_input->enable_ns)
1695 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1696 else if (my_data->fluence_type != FLUENCE_NONE &&
1697 my_data->fluence_in_voice_rec) {
1698 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001699 } else {
1700 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1701 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001702 }
1703 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1704 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1705 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1706 if (adev->active_input) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001707 if (adev->active_input->enable_aec &&
1708 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001709 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001710 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1711 my_data->fluence_in_spkr_mode) {
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08001712 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1713 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
1714 else
1715 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001716 } else
1717 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Eric Laurentb23d5282013-05-14 15:27:20 -07001718 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001719 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1720 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001721 } else
1722 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Eric Laurentb23d5282013-05-14 15:27:20 -07001723 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001724 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001725 }
Anish Kumar4980fa12014-04-17 12:42:20 -07001726 set_echo_reference(adev, true);
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001727 } else if (adev->active_input->enable_aec) {
1728 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08001729 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1730 my_data->fluence_in_spkr_mode) {
1731 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1732 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
1733 else
1734 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001735 } else
1736 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1737 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1738 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1739 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001740 } else
1741 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1742 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1743 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1744 }
Anish Kumar4980fa12014-04-17 12:42:20 -07001745 set_echo_reference(adev, true);
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001746 } else if (adev->active_input->enable_ns) {
1747 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08001748 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
1749 my_data->fluence_in_spkr_mode) {
1750 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
1751 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
1752 else
1753 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001754 } else
1755 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1756 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1757 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
1758 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001759 } else
1760 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1761 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1762 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
1763 }
Anish Kumar4980fa12014-04-17 12:42:20 -07001764 set_echo_reference(adev, false);
Eric Laurentb23d5282013-05-14 15:27:20 -07001765 } else
Anish Kumar4980fa12014-04-17 12:42:20 -07001766 set_echo_reference(adev, false);
Eric Laurentb23d5282013-05-14 15:27:20 -07001767 }
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001768 } else if (source == AUDIO_SOURCE_MIC) {
Apoorv Raghuvanshic0536542013-11-14 16:25:59 -08001769 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
1770 channel_count == 1 ) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001771 if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
Ravi Kumar Alamanda7076b162014-03-07 11:40:24 -08001772 my_data->fluence_in_audio_rec) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001773 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
Anish Kumar4980fa12014-04-17 12:42:20 -07001774 set_echo_reference(adev, true);
Ravi Kumar Alamanda7076b162014-03-07 11:40:24 -08001775 }
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001776 }
Mingming Yinab429782013-11-07 11:16:55 -08001777 } else if (source == AUDIO_SOURCE_FM_RX ||
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001778 source == AUDIO_SOURCE_FM_RX_A2DP) {
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07001779 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07001780 } else if (source == AUDIO_SOURCE_DEFAULT) {
1781 goto exit;
1782 }
1783
1784
1785 if (snd_device != SND_DEVICE_NONE) {
1786 goto exit;
1787 }
1788
1789 if (in_device != AUDIO_DEVICE_NONE &&
1790 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1791 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1792 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07001793 if (audio_extn_ssr_get_enabled() && channel_count == 6)
1794 snd_device = SND_DEVICE_IN_QUAD_MIC;
Walter Yangbc136bd2014-01-17 11:24:23 +08001795 else if (my_data->fluence_type & (FLUENCE_DUAL_MIC | FLUENCE_QUAD_MIC) &&
1796 channel_count == 2)
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -07001797 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07001798 else
1799 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001800 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1801 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1802 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1803 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1804 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001805 if (adev->bt_wb_speech_enabled) {
1806 if (adev->bluetooth_nrec)
1807 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1808 else
1809 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1810 } else {
1811 if (adev->bluetooth_nrec)
1812 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1813 else
1814 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1815 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001816 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1817 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001818 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
1819 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
1820 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07001821 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
1822 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07001823 } else {
1824 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1825 ALOGW("%s: Using default handset-mic", __func__);
1826 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1827 }
1828 } else {
1829 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1830 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1831 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1832 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001833 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
1834 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1835 if (channel_count == 2)
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -07001836 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
1837 else
1838 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001839 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001840 if (adev->bt_wb_speech_enabled) {
1841 if (adev->bluetooth_nrec)
1842 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1843 else
1844 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1845 } else {
1846 if (adev->bluetooth_nrec)
1847 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1848 else
1849 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1850 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001851 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1852 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001853 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
1854 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
1855 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001856 } else {
1857 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1858 ALOGW("%s: Using default handset-mic", __func__);
1859 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1860 }
1861 }
1862exit:
1863 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1864 return snd_device;
1865}
1866
1867int platform_set_hdmi_channels(void *platform, int channel_count)
1868{
1869 struct platform_data *my_data = (struct platform_data *)platform;
1870 struct audio_device *adev = my_data->adev;
1871 struct mixer_ctl *ctl;
1872 const char *channel_cnt_str = NULL;
1873 const char *mixer_ctl_name = "HDMI_RX Channels";
1874 switch (channel_count) {
1875 case 8:
1876 channel_cnt_str = "Eight"; break;
1877 case 7:
1878 channel_cnt_str = "Seven"; break;
1879 case 6:
1880 channel_cnt_str = "Six"; break;
1881 case 5:
1882 channel_cnt_str = "Five"; break;
1883 case 4:
1884 channel_cnt_str = "Four"; break;
1885 case 3:
1886 channel_cnt_str = "Three"; break;
1887 default:
1888 channel_cnt_str = "Two"; break;
1889 }
1890 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1891 if (!ctl) {
1892 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1893 __func__, mixer_ctl_name);
1894 return -EINVAL;
1895 }
1896 ALOGV("HDMI channel count: %s", channel_cnt_str);
1897 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1898 return 0;
1899}
1900
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001901int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07001902{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001903 struct platform_data *my_data = (struct platform_data *)platform;
1904 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07001905 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1906 char *sad = block;
1907 int num_audio_blocks;
1908 int channel_count;
1909 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001910 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07001911
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001912 struct mixer_ctl *ctl;
1913
1914 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1915 if (!ctl) {
1916 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1917 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07001918 return 0;
1919 }
1920
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001921 mixer_ctl_update(ctl);
1922
1923 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07001924
1925 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001926 if (count > (int)sizeof(block))
1927 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07001928
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001929 ret = mixer_ctl_get_array(ctl, block, count);
1930 if (ret != 0) {
1931 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1932 return 0;
1933 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001934
1935 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001936 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001937
1938 for (i = 0; i < num_audio_blocks; i++) {
1939 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001940 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1941 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07001942 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001943 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001944
1945 channel_count = (sad[0] & 0x7) + 1;
1946 if (channel_count > max_channels)
1947 max_channels = channel_count;
1948
1949 /* Advance to next block */
1950 sad += 3;
1951 }
1952
1953 return max_channels;
1954}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001955
1956static int platform_set_slowtalk(struct platform_data *my_data, bool state)
1957{
1958 int ret = 0;
1959 struct audio_device *adev = my_data->adev;
1960 struct mixer_ctl *ctl;
1961 const char *mixer_ctl_name = "Slowtalk Enable";
1962 uint32_t set_values[ ] = {0,
1963 ALL_SESSION_VSID};
1964
1965 set_values[0] = state;
1966 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1967 if (!ctl) {
1968 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1969 __func__, mixer_ctl_name);
1970 ret = -EINVAL;
1971 } else {
1972 ALOGV("Setting slowtalk state: %d", state);
1973 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1974 my_data->slowtalk = state;
1975 }
1976
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001977 if (my_data->csd != NULL) {
1978 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
1979 if (ret < 0) {
1980 ALOGE("%s: csd_client_disable_device, failed, error %d",
1981 __func__, ret);
1982 }
1983 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001984 return ret;
1985}
1986
Tanya Finkel00130052014-07-14 04:26:56 -07001987
1988static int update_external_device_status(struct platform_data *my_data,
1989 char* event_name, bool status)
1990{
1991 int ret = 0;
1992 struct audio_usecase *usecase;
1993 struct listnode *node;
1994
1995 ALOGD("Recieved external event switch %s", event_name);
1996
1997 if (!strcmp(event_name, EVENT_EXTERNAL_SPK_1))
1998 my_data->external_spk_1 = status;
1999 else if (!strcmp(event_name, EVENT_EXTERNAL_SPK_2))
2000 my_data->external_spk_2 = status;
2001 else if (!strcmp(event_name, EVENT_EXTERNAL_MIC))
2002 my_data->external_mic = status;
2003 else {
2004 ALOGE("The audio event type is not found");
2005 return -EINVAL;
2006 }
2007
2008 list_for_each(node, &my_data->adev->usecase_list) {
2009 usecase = node_to_item(node, struct audio_usecase, list);
2010 select_devices(my_data->adev, usecase->id);
2011 }
2012
2013 return ret;
2014}
2015
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002016int platform_set_parameters(void *platform, struct str_parms *parms)
2017{
2018 struct platform_data *my_data = (struct platform_data *)platform;
2019 char *str;
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08002020 char value[256] = {0};
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002021 int val;
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002022 int ret = 0, err;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08002023 char *kv_pairs = str_parms_to_str(parms);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002024
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08002025 ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002026
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002027 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
2028 if (err >= 0) {
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08002029 bool state = false;
2030 if (!strncmp("true", value, sizeof("true"))) {
2031 state = true;
2032 }
2033
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002034 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08002035 ret = platform_set_slowtalk(my_data, state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002036 if (ret)
2037 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002038 }
2039
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002040 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08002041 value, sizeof(value));
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002042 if (err >= 0) {
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08002043 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
2044
2045 if (my_data->acdb_reload_vocvoltable == NULL) {
2046 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
2047 } else if (!strcmp(value, "on")) {
2048 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
2049 my_data->voice_feature_set = 1;
2050 }
2051 } else {
2052 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
2053 my_data->voice_feature_set = 0;
2054 }
2055 }
2056 }
2057
Tanya Finkel00130052014-07-14 04:26:56 -07002058 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE,
2059 value, sizeof(value));
2060 if (err >= 0) {
2061 char *event_name, *status_str;
2062 bool status = false;
2063 str_parms_del(parms, AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE);
2064 event_name = strtok_r(value, ",", &status_str);
2065 ALOGV("%s: recieved update of external audio device %s %s",
2066 __func__,
2067 event_name, status_str);
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002068 if (!strncmp(status_str, "ON", sizeof("ON")))
Tanya Finkel00130052014-07-14 04:26:56 -07002069 status = true;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002070 else if (!strncmp(status_str, "OFF", sizeof("OFF")))
Tanya Finkel00130052014-07-14 04:26:56 -07002071 status = false;
2072 update_external_device_status(my_data, event_name, status);
2073 }
2074
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002075 ALOGV("%s: exit with code(%d)", __func__, ret);
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08002076 free(kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002077 return ret;
2078}
2079
Vidyakumar Athota2850d532013-11-19 16:02:12 -08002080int platform_set_incall_recording_session_id(void *platform,
2081 uint32_t session_id, int rec_mode)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07002082{
2083 int ret = 0;
2084 struct platform_data *my_data = (struct platform_data *)platform;
2085 struct audio_device *adev = my_data->adev;
2086 struct mixer_ctl *ctl;
2087 const char *mixer_ctl_name = "Voc VSID";
2088 int num_ctl_values;
2089 int i;
2090
2091 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2092 if (!ctl) {
2093 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2094 __func__, mixer_ctl_name);
2095 ret = -EINVAL;
2096 } else {
2097 num_ctl_values = mixer_ctl_get_num_values(ctl);
2098 for (i = 0; i < num_ctl_values; i++) {
2099 if (mixer_ctl_set_value(ctl, i, session_id)) {
2100 ALOGV("Error: invalid session_id: %x", session_id);
2101 ret = -EINVAL;
2102 break;
2103 }
2104 }
2105 }
2106
Vidyakumar Athota2850d532013-11-19 16:02:12 -08002107 if (my_data->csd != NULL) {
2108 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2109 if (ret < 0) {
2110 ALOGE("%s: csd_client_start_record failed, error %d",
2111 __func__, ret);
2112 }
2113 }
2114
2115 return ret;
2116}
2117
2118int platform_stop_incall_recording_usecase(void *platform)
2119{
2120 int ret = 0;
2121 struct platform_data *my_data = (struct platform_data *)platform;
2122
2123 if (my_data->csd != NULL) {
2124 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2125 if (ret < 0) {
2126 ALOGE("%s: csd_client_stop_record failed, error %d",
2127 __func__, ret);
2128 }
2129 }
2130
2131 return ret;
2132}
2133
2134int platform_start_incall_music_usecase(void *platform)
2135{
2136 int ret = 0;
2137 struct platform_data *my_data = (struct platform_data *)platform;
2138
2139 if (my_data->csd != NULL) {
2140 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2141 if (ret < 0) {
2142 ALOGE("%s: csd_client_start_playback failed, error %d",
2143 __func__, ret);
2144 }
2145 }
2146
2147 return ret;
2148}
2149
2150int platform_stop_incall_music_usecase(void *platform)
2151{
2152 int ret = 0;
2153 struct platform_data *my_data = (struct platform_data *)platform;
2154
2155 if (my_data->csd != NULL) {
2156 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2157 if (ret < 0) {
2158 ALOGE("%s: csd_client_stop_playback failed, error %d",
2159 __func__, ret);
2160 }
2161 }
2162
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07002163 return ret;
2164}
2165
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07002166int platform_update_lch(void *platform, struct voice_session *session,
2167 enum voice_lch_mode lch_mode)
2168{
2169 int ret = 0;
2170 struct platform_data *my_data = (struct platform_data *)platform;
2171
2172 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
2173 ret = my_data->csd->set_lch(session->vsid, lch_mode);
2174 else
2175 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
2176
2177 return ret;
2178}
2179
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002180void platform_get_parameters(void *platform,
2181 struct str_parms *query,
2182 struct str_parms *reply)
2183{
2184 struct platform_data *my_data = (struct platform_data *)platform;
2185 char *str = NULL;
2186 char value[256] = {0};
2187 int ret;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08002188 char *kv_pairs = NULL;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002189
Shiv Maliyappanahalli9d899292013-11-20 14:43:01 -08002190 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
2191 value, sizeof(value));
2192 if (ret >= 0) {
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08002193 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
2194 my_data->slowtalk?"true":"false");
Shiv Maliyappanahalli9d899292013-11-20 14:43:01 -08002195 }
2196
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08002197 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
2198 value, sizeof(value));
2199 if (ret >= 0) {
2200 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
2201 strlcpy(value, "on", sizeof(value));
2202 } else {
2203 strlcpy(value, "off", sizeof(value));
2204 }
2205
2206 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
2207 }
2208
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08002209 kv_pairs = str_parms_to_str(reply);
2210 ALOGV_IF(kv_pairs != NULL, "%s: exit: returns - %s", __func__, kv_pairs);
Narsinga Rao Chellacde45d12014-02-13 11:44:31 -08002211 free(kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002212}
2213
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002214/* Delay in Us */
2215int64_t platform_render_latency(audio_usecase_t usecase)
2216{
2217 switch (usecase) {
2218 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2219 return DEEP_BUFFER_PLATFORM_DELAY;
2220 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2221 return LOW_LATENCY_PLATFORM_DELAY;
2222 default:
2223 return 0;
2224 }
2225}
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07002226
Mingming Yine62d7842013-10-25 16:26:03 -07002227int platform_update_usecase_from_source(int source, int usecase)
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07002228{
Mingming Yinab429782013-11-07 11:16:55 -08002229 ALOGV("%s: input source :%d", __func__, source);
2230 if(source == AUDIO_SOURCE_FM_RX_A2DP)
Mingming Yine62d7842013-10-25 16:26:03 -07002231 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
2232 return usecase;
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07002233}
Kiran Kandide144c82013-11-20 15:58:32 -08002234
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302235bool platform_listen_device_needs_event(snd_device_t snd_device)
Kiran Kandide144c82013-11-20 15:58:32 -08002236{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302237 bool needs_event = false;
2238
Kiran Kandide144c82013-11-20 15:58:32 -08002239 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
2240 (snd_device < SND_DEVICE_IN_END) &&
2241 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
2242 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302243 needs_event = true;
2244
2245 return needs_event;
2246}
2247
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07002248bool platform_listen_usecase_needs_event(audio_usecase_t uc_id __unused)
2249{
2250 return false;
2251}
2252
2253bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
2254{
2255 bool needs_event = false;
2256
2257 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
2258 (snd_device < SND_DEVICE_IN_END) &&
2259 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
2260 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
2261 needs_event = true;
2262
2263 return needs_event;
2264}
2265
2266bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id __unused)
Dhananjay Kumar45b71742014-05-29 21:47:27 +05302267{
2268 return false;
Kiran Kandide144c82013-11-20 15:58:32 -08002269}
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08002270
2271/* Read offload buffer size from a property.
2272 * If value is not power of 2 round it to
2273 * power of 2.
2274 */
2275uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
2276{
2277 char value[PROPERTY_VALUE_MAX] = {0};
2278 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2279 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
2280 atoi(value)) {
2281 fragment_size = atoi(value) * 1024;
2282 }
2283
Mingming Yin3ee55c62014-08-04 14:23:35 -07002284 // For FLAC use max size since it is loss less, and has sampling rates
2285 // upto 192kHZ
2286 if (info != NULL && !info->has_video &&
2287 info->format == AUDIO_FORMAT_FLAC) {
2288 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2289 ALOGV("FLAC fragment size %d", fragment_size);
2290 }
2291
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08002292 if (info != NULL && info->has_video && info->is_streaming) {
2293 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
2294 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
ApurupaPattapu31d09d72014-03-05 11:13:32 -08002295 __func__, fragment_size);
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08002296 }
2297
2298 fragment_size = ALIGN( fragment_size, 1024);
2299
2300 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
2301 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2302 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
2303 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2304 ALOGV("%s: fragment_size %d", __func__, fragment_size);
2305 return fragment_size;
2306}
2307
2308uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
2309{
2310 uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
2311 uint32_t bits_per_sample = 16;
2312
2313 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
2314 bits_per_sample = 32;
2315 }
2316
2317 if (!info->has_video) {
2318 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
2319
2320 } else if (info->has_video && info->is_streaming) {
2321 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
2322 * info->sample_rate
ApurupaPattapub57da782014-04-08 10:41:07 -07002323 * (bits_per_sample >> 3)
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08002324 * popcount(info->channel_mask))/1000;
2325
2326 } else if (info->has_video) {
2327 fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
2328 * info->sample_rate
ApurupaPattapub57da782014-04-08 10:41:07 -07002329 * (bits_per_sample >> 3)
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08002330 * popcount(info->channel_mask))/1000;
2331 }
2332
ApurupaPattapub57da782014-04-08 10:41:07 -07002333 char value[PROPERTY_VALUE_MAX] = {0};
2334 if((property_get("audio.offload.pcm.buffer.size", value, "")) &&
2335 atoi(value)) {
2336 fragment_size = atoi(value) * 1024;
2337 ALOGV("Using buffer size from sys prop %d", fragment_size);
2338 }
2339
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08002340 fragment_size = ALIGN( fragment_size, 1024);
2341
2342 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
2343 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
2344 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
2345 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
2346
2347 ALOGV("%s: fragment_size %d", __func__, fragment_size);
2348 return fragment_size;
2349}
2350
Mingming Yin3ee55c62014-08-04 14:23:35 -07002351bool platform_check_24_bit_support() {
2352
2353 char value[PROPERTY_VALUE_MAX] = {0};
2354 property_get("audio.offload.24bit.enable", value, "0");
2355 if (atoi(value)) {
2356 ALOGW("Property audio.offload.24bit.enable is set");
2357 return true;
2358 }
2359 return false;
2360}
2361
2362int platform_set_codec_backend_cfg(struct audio_device* adev,
2363 unsigned int bit_width, unsigned int sample_rate)
2364{
Amit Shekhared7fb5c2014-08-01 17:18:53 -07002365 ALOGV("%s bit width: %d, sample rate: %d", __func__, bit_width, sample_rate);
Mingming Yin3ee55c62014-08-04 14:23:35 -07002366
2367 int ret = 0;
2368 if (bit_width != adev->cur_codec_backend_bit_width) {
2369 const char * mixer_ctl_name = "SLIM_0_RX Format";
2370 struct mixer_ctl *ctl;
2371 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2372 if (!ctl) {
2373 ALOGE("%s: Could not get ctl for mixer command - %s",
2374 __func__, mixer_ctl_name);
2375 return -EINVAL;
2376 }
2377
2378 if (bit_width == 24) {
2379 mixer_ctl_set_enum_by_string(ctl, "S24_LE");
2380 } else {
2381 mixer_ctl_set_enum_by_string(ctl, "S16_LE");
2382 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
2383 }
2384 adev->cur_codec_backend_bit_width = bit_width;
2385 ALOGE("Backend bit width is set to %d ", bit_width);
2386 }
2387
Amit Shekhared7fb5c2014-08-01 17:18:53 -07002388 /*
2389 * Backend sample rate configuration follows:
2390 * 16 bit playback - 48khz for streams at any valid sample rate
2391 * 24 bit playback - 48khz for stream sample rate less than 48khz
2392 * 24 bit playback - 96khz for sample rate range of 48khz to 96khz
2393 * 24 bit playback - 192khz for sample rate range of 96khz to 192 khz
2394 * Upper limit is inclusive in the sample rate range.
2395 */
2396 // TODO: This has to be more dynamic based on policy file
2397 if (sample_rate != adev->cur_codec_backend_samplerate) {
Mingming Yin3ee55c62014-08-04 14:23:35 -07002398 char *rate_str = NULL;
2399 const char * mixer_ctl_name = "SLIM_0_RX SampleRate";
2400 struct mixer_ctl *ctl;
2401
2402 switch (sample_rate) {
2403 case 8000:
Mingming Yin3ee55c62014-08-04 14:23:35 -07002404 case 11025:
Mingming Yin3ee55c62014-08-04 14:23:35 -07002405 case 16000:
Mingming Yin3ee55c62014-08-04 14:23:35 -07002406 case 22050:
Mingming Yin3ee55c62014-08-04 14:23:35 -07002407 case 32000:
Mingming Yin3ee55c62014-08-04 14:23:35 -07002408 case 44100:
Mingming Yin3ee55c62014-08-04 14:23:35 -07002409 case 48000:
2410 rate_str = "KHZ_48";
2411 break;
2412 case 64000:
Mingming Yin3ee55c62014-08-04 14:23:35 -07002413 case 88200:
Mingming Yin3ee55c62014-08-04 14:23:35 -07002414 case 96000:
2415 rate_str = "KHZ_96";
2416 break;
2417 case 176400:
Mingming Yin3ee55c62014-08-04 14:23:35 -07002418 case 192000:
2419 rate_str = "KHZ_192";
2420 break;
2421 default:
2422 rate_str = "KHZ_48";
2423 break;
2424 }
2425
2426 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2427 if(!ctl) {
2428 ALOGE("%s: Could not get ctl for mixer command - %s",
2429 __func__, mixer_ctl_name);
2430 return -EINVAL;
2431 }
2432
2433 ALOGV("Set sample rate as rate_str = %s", rate_str);
2434 mixer_ctl_set_enum_by_string(ctl, rate_str);
2435 adev->cur_codec_backend_samplerate = sample_rate;
2436 }
2437
2438 return ret;
2439}
2440
2441bool platform_check_codec_backend_cfg(struct audio_device* adev,
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002442 struct audio_usecase* usecase __unused,
Mingming Yin3ee55c62014-08-04 14:23:35 -07002443 unsigned int* new_bit_width,
2444 unsigned int* new_sample_rate)
2445{
2446 bool backend_change = false;
2447 struct listnode *node;
2448 struct stream_out *out = NULL;
Amit Shekhar278e3362014-09-08 14:08:19 -07002449 unsigned int bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
2450 unsigned int sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Mingming Yin3ee55c62014-08-04 14:23:35 -07002451
2452 // For voice calls use default configuration
2453 // force routing is not required here, caller will do it anyway
2454 if (adev->mode == AUDIO_MODE_IN_CALL ||
2455 adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
2456 ALOGW("%s:Use default bw and sr for voice/voip calls ",__func__);
2457 *new_bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
2458 *new_sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
2459 backend_change = true;
2460 }
2461
Amit Shekhar278e3362014-09-08 14:08:19 -07002462 /*
2463 * The backend should be configured at highest bit width and/or
2464 * sample rate amongst all playback usecases.
2465 * If the selected sample rate and/or bit width differ with
2466 * current backend sample rate and/or bit width, then, we set the
2467 * backend re-configuration flag.
2468 *
2469 * Exception: 16 bit playbacks is allowed through 16 bit/48 khz backend only
2470 */
Mingming Yin3ee55c62014-08-04 14:23:35 -07002471 if (!backend_change) {
Mingming Yin3ee55c62014-08-04 14:23:35 -07002472 list_for_each(node, &adev->usecase_list) {
2473 struct audio_usecase *curr_usecase;
2474 curr_usecase = node_to_item(node, struct audio_usecase, list);
Amit Shekhared7fb5c2014-08-01 17:18:53 -07002475 if (curr_usecase->type == PCM_PLAYBACK) {
Mingming Yin3ee55c62014-08-04 14:23:35 -07002476 struct stream_out *out =
2477 (struct stream_out*) curr_usecase->stream.out;
2478 if (out != NULL ) {
2479 ALOGV("Offload playback running bw %d sr %d",
2480 out->bit_width, out->sample_rate);
Amit Shekhar278e3362014-09-08 14:08:19 -07002481 if (bit_width < out->bit_width)
2482 bit_width = out->bit_width;
2483 if (sample_rate < out->sample_rate)
2484 sample_rate = out->sample_rate;
Mingming Yin3ee55c62014-08-04 14:23:35 -07002485 }
2486 }
2487 }
2488 }
2489
Amit Shekhar278e3362014-09-08 14:08:19 -07002490 // 16 bit playbacks is allowed through 16 bit/48 khz backend only
2491 if (16 == bit_width)
2492 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Mingming Yin3ee55c62014-08-04 14:23:35 -07002493 // Force routing if the expected bitwdith or samplerate
2494 // is not same as current backend comfiguration
Amit Shekhar278e3362014-09-08 14:08:19 -07002495 if ((bit_width != adev->cur_codec_backend_bit_width) ||
2496 (sample_rate != adev->cur_codec_backend_samplerate)) {
2497 *new_bit_width = bit_width;
2498 *new_sample_rate = sample_rate;
Mingming Yin3ee55c62014-08-04 14:23:35 -07002499 backend_change = true;
Amit Shekhar278e3362014-09-08 14:08:19 -07002500 ALOGI("%s Codec backend needs to be updated. new bit width: %d new sample rate: %d",
2501 __func__, *new_bit_width, *new_sample_rate);
Mingming Yin3ee55c62014-08-04 14:23:35 -07002502 }
2503
2504 return backend_change;
2505}
2506
2507bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev, struct audio_usecase *usecase)
2508{
2509 // check if 24bit configuration is enabled first
2510 if (!platform_check_24_bit_support()) {
2511 ALOGW("24bit not enable, no need to check for backend change");
2512 return false;
2513 }
2514
2515 ALOGV("platform_check_and_set_codec_backend_cfg usecase = %d",usecase->id );
2516
2517 unsigned int new_bit_width, old_bit_width;
2518 unsigned int new_sample_rate, old_sample_rate;
2519
2520 new_bit_width = old_bit_width = adev->cur_codec_backend_bit_width;
2521 new_sample_rate = old_sample_rate = adev->cur_codec_backend_samplerate;
2522
2523 ALOGW("Codec backend bitwidth %d, samplerate %d", old_bit_width, old_sample_rate);
2524 if (platform_check_codec_backend_cfg(adev, usecase,
2525 &new_bit_width, &new_sample_rate)) {
2526 platform_set_codec_backend_cfg(adev, new_bit_width, new_sample_rate);
Mingming Yin3ee55c62014-08-04 14:23:35 -07002527 return true;
2528 }
2529
2530 return false;
2531}
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002532
2533int platform_set_snd_device_backend(snd_device_t device, const char *backend)
2534{
2535 int ret = 0;
2536
2537 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2538 ALOGE("%s: Invalid snd_device = %d",
2539 __func__, device);
2540 ret = -EINVAL;
2541 goto done;
2542 }
2543
2544 if (backend_table[device]) {
2545 free(backend_table[device]);
2546 }
2547 backend_table[device] = strdup(backend);
2548done:
2549 return ret;
2550}
2551
2552int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2553{
2554 int ret = 0;
2555 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2556 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2557 ret = -EINVAL;
2558 goto done;
2559 }
2560
2561 if ((type != 0) && (type != 1)) {
2562 ALOGE("%s: invalid usecase type", __func__);
2563 ret = -EINVAL;
2564 }
2565 pcm_device_table[usecase][type] = pcm_id;
2566done:
2567 return ret;
2568}