blob: 5ab6dc5d288fa83b99f74de676517e9d2c269c10 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002 * Copyright (C) 2013-2014 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "msm8974_platform"
18/*#define LOG_NDEBUG 0*/
19#define LOG_NDDEBUG 0
20
21#include <stdlib.h>
22#include <dlfcn.h>
23#include <cutils/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070024#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070025#include <cutils/properties.h>
26#include <audio_hw.h>
27#include <platform_api.h>
28#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070029#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070030#include <linux/msm_audio.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070031
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070032#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Eric Laurentb23d5282013-05-14 15:27:20 -070033#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070034#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090035#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070036
37#define DUALMIC_CONFIG_NONE 0 /* Target does not contain 2 mics */
38#define DUALMIC_CONFIG_ENDFIRE 1
39#define DUALMIC_CONFIG_BROADSIDE 2
40
41/*
Eric Laurentb23d5282013-05-14 15:27:20 -070042 * This file will have a maximum of 38 bytes:
43 *
44 * 4 bytes: number of audio blocks
45 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
46 * Maximum 10 * 3 bytes: SAD blocks
47 */
48#define MAX_SAD_BLOCKS 10
49#define SAD_BLOCK_SIZE 3
50
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090051#define MAX_CVD_VERSION_STRING_SIZE 100
52
Eric Laurentb23d5282013-05-14 15:27:20 -070053/* EDID format ID for LPCM audio */
54#define EDID_FORMAT_LPCM 1
55
sangwoo1b9f4b32013-06-21 18:22:55 -070056/* Retry for delay in FW loading*/
57#define RETRY_NUMBER 10
58#define RETRY_US 500000
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070059#define MAX_SND_CARD 8
sangwoo53b2cf02013-07-25 19:18:44 -070060
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070061#define MAX_SND_CARD_NAME_LEN 31
62
vivek mehta1a9b7c02015-06-25 11:49:38 -070063#define DEFAULT_APP_TYPE_RX_PATH 0x11130
64
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090065#define TOSTRING_(x) #x
66#define TOSTRING(x) TOSTRING_(x)
67
Eric Laurentb23d5282013-05-14 15:27:20 -070068struct audio_block_header
69{
70 int reserved;
71 int length;
72};
73
vivek mehta1a9b7c02015-06-25 11:49:38 -070074enum {
75 CAL_MODE_SEND = 0x1,
76 CAL_MODE_PERSIST = 0x2,
77 CAL_MODE_RTAC = 0x4
78};
79
keunhui.park2f7306a2015-07-16 16:48:06 +090080#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
81
82struct operator_info {
83 struct listnode list;
84 char *name;
85 char *mccmnc;
86};
87
88struct operator_specific_device {
89 struct listnode list;
90 char *operator;
91 char *mixer_path;
92 int acdb_id;
93};
94
95static struct listnode operator_info_list;
96static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
97
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070098/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -070099typedef void (*acdb_deallocate_t)();
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900100typedef int (*acdb_init_v2_cvd_t)(char *, char *);
101typedef int (*acdb_init_v2_t)(char *);
Eric Laurentb23d5282013-05-14 15:27:20 -0700102typedef int (*acdb_init_t)();
103typedef void (*acdb_send_audio_cal_t)(int, int);
104typedef void (*acdb_send_voice_cal_t)(int, int);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700105typedef int (*acdb_reload_vocvoltable_t)(int);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700106typedef int (*acdb_send_gain_dep_cal_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700107
108/* Audio calibration related functions */
109struct platform_data {
110 struct audio_device *adev;
111 bool fluence_in_spkr_mode;
112 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700113 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700114 bool fluence_in_voice_rec;
115 int dualmic_config;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700116 bool speaker_lr_swap;
117
Eric Laurentb23d5282013-05-14 15:27:20 -0700118 void *acdb_handle;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700119 acdb_deallocate_t acdb_deallocate;
120 acdb_send_audio_cal_t acdb_send_audio_cal;
121 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700122 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700123 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700124 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800125 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700126
127 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900128 int max_vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -0700129};
130
Haynes Mathew George98c95622014-06-20 19:14:25 -0700131static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700132 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
133 DEEP_BUFFER_PCM_DEVICE},
134 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
135 LOWLATENCY_PCM_DEVICE},
136 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
137 MULTIMEDIA2_PCM_DEVICE},
138 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
139 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamandaf78a4d92015-04-24 15:18:23 -0700140 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA3_PCM_DEVICE,
141 MULTIMEDIA3_PCM_DEVICE},
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700142 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
143 AUDIO_RECORD_PCM_DEVICE},
144 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
145 LOWLATENCY_PCM_DEVICE},
146 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
147 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700148 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
149 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
150 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
151 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
152 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
153 AUDIO_RECORD_PCM_DEVICE},
154 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
155 AUDIO_RECORD_PCM_DEVICE},
156 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
157 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800158 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700159
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700160 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
161 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
162
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700163 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
164 AFE_PROXY_RECORD_PCM_DEVICE},
165 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
166 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800167 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700168
Eric Laurentb23d5282013-05-14 15:27:20 -0700169};
170
171/* Array to store sound devices */
172static const char * const device_table[SND_DEVICE_MAX] = {
173 [SND_DEVICE_NONE] = "none",
174 /* Playback sound devices */
175 [SND_DEVICE_OUT_HANDSET] = "handset",
176 [SND_DEVICE_OUT_SPEAKER] = "speaker",
177 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700178 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700179 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500180 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700181 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700182 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500183 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700184 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700185 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500186 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700187 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
188 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500189 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700190 [SND_DEVICE_OUT_HDMI] = "hdmi",
191 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
192 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700193 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700194 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
195 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
196 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
197 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700198 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700199 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
200 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Eric Laurentb23d5282013-05-14 15:27:20 -0700201
202 /* Capture sound devices */
203 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700204 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700205 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
206 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
207 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
208 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
209 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
210 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
211 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
212
213 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
214 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
215 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
216 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
217 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
218 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
219 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
220 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
221 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
222
223 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500224 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700225
Eric Laurentb23d5282013-05-14 15:27:20 -0700226 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
227 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700228 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700229 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700230 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700231 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700232
233 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
234 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
235 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
236 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
237 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700238 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
239 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
240 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700241
Eric Laurentb23d5282013-05-14 15:27:20 -0700242 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700243 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
244 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
245 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700246
247 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700248
249 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Eric Laurentb23d5282013-05-14 15:27:20 -0700250};
251
252/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700253static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700254 [SND_DEVICE_NONE] = -1,
255 [SND_DEVICE_OUT_HANDSET] = 7,
256 [SND_DEVICE_OUT_SPEAKER] = 15,
257 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700258 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700259 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500260 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700261 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700262 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500263 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700264 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700265 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
266 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500267 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700268 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500269 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700270 [SND_DEVICE_OUT_HDMI] = 18,
271 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
272 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700273 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700274 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700275 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
276 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
277 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700278 [SND_DEVICE_OUT_VOICE_TX] = 45,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700279 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
280 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Eric Laurentb23d5282013-05-14 15:27:20 -0700281
282 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700283 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
284 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
285 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
286 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
287 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
288 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
289 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
290 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
291
292 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
293 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
294 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
295 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
296 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
297 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
298 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
299 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
300 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
301
Eric Laurentb23d5282013-05-14 15:27:20 -0700302 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500303 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700304
Eric Laurentb23d5282013-05-14 15:27:20 -0700305 [SND_DEVICE_IN_HDMI_MIC] = 4,
306 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700307 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700308 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700309 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700310 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700311
312 [SND_DEVICE_IN_VOICE_DMIC] = 41,
313 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
314 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
315 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
316 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
Eric Laurentb23d5282013-05-14 15:27:20 -0700317 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
318 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
319 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700320
Eric Laurentb23d5282013-05-14 15:27:20 -0700321 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700322 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
323 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
324 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700325
326 [SND_DEVICE_IN_VOICE_RX] = 44,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700327
328 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Eric Laurentb23d5282013-05-14 15:27:20 -0700329};
330
Haynes Mathew George98c95622014-06-20 19:14:25 -0700331struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700332 char name[100];
333 unsigned int index;
334};
335
336#define TO_NAME_INDEX(X) #X, X
337
Haynes Mathew George98c95622014-06-20 19:14:25 -0700338/* Used to get index from parsed string */
339static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
340 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700341 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
342 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
343 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700344 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700345 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500346 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700347 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700348 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500349 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700350 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700351 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
352 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
353 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500354 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700355 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
356 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
357 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
358 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700359 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500360 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700361 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
362 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
363 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700364
365 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700366 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
367 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700368 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700369 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700370 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
371 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
372 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
373 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
374 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
375 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
376 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
377
378 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700379 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700380 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
381 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
382 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
383 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
384 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
385 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
386 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
387
388 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700389 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700390
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700391 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
392 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700393 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700394 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700395 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700396 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700397
398 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
399 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
400 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
401 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
402 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700403 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
404 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
405 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700406
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700407 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700408 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
409 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
410 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700411
412 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700413};
414
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700415static char * backend_tag_table[SND_DEVICE_MAX] = {0};
416static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700417
418static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
419 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
420 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
421 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
422 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
423 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
424 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
425 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
426 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
427 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
428 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
429 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
430 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
431 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
432 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
433 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700434};
435
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700436#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
437#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
438
Eric Laurentb23d5282013-05-14 15:27:20 -0700439static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
440static bool is_tmus = false;
441
442static void check_operator()
443{
444 char value[PROPERTY_VALUE_MAX];
445 int mccmnc;
446 property_get("gsm.sim.operator.numeric",value,"0");
447 mccmnc = atoi(value);
448 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
449 switch(mccmnc) {
450 /* TMUS MCC(310), MNC(490, 260, 026) */
451 case 310490:
452 case 310260:
453 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900454 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
455 case 310800:
456 case 310660:
457 case 310580:
458 case 310310:
459 case 310270:
460 case 310250:
461 case 310240:
462 case 310230:
463 case 310220:
464 case 310210:
465 case 310200:
466 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700467 is_tmus = true;
468 break;
469 }
470}
471
472bool is_operator_tmus()
473{
474 pthread_once(&check_op_once_ctl, check_operator);
475 return is_tmus;
476}
477
keunhui.park2f7306a2015-07-16 16:48:06 +0900478static char *get_current_operator()
479{
480 struct listnode *node;
481 struct operator_info *info_item;
482 char mccmnc[PROPERTY_VALUE_MAX];
483 char *ret = NULL;
484
485 property_get("gsm.sim.operator.numeric",mccmnc,"0");
486
487 list_for_each(node, &operator_info_list) {
488 info_item = node_to_item(node, struct operator_info, list);
489 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
490 ret = info_item->name;
491 }
492 }
493
494 return ret;
495}
496
497static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
498{
499 struct listnode *node;
500 struct operator_specific_device *ret = NULL;
501 struct operator_specific_device *device_item;
502 char *operator_name;
503
504 operator_name = get_current_operator();
505 if (operator_name == NULL)
506 return ret;
507
508 list_for_each(node, operator_specific_device_table[snd_device]) {
509 device_item = node_to_item(node, struct operator_specific_device, list);
510 if (strcmp(operator_name, device_item->operator) == 0) {
511 ret = device_item;
512 }
513 }
514
515 return ret;
516}
517
518
519static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
520{
521 struct operator_specific_device *device;
522 int ret = acdb_device_table[snd_device];
523
524 device = get_operator_specific_device(snd_device);
525 if (device != NULL)
526 ret = device->acdb_id;
527
528 return ret;
529}
530
531static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
532{
533 struct operator_specific_device *device;
534 const char *ret = device_table[snd_device];
535
536 device = get_operator_specific_device(snd_device);
537 if (device != NULL)
538 ret = device->mixer_path;
539
540 return ret;
541}
542
vivek mehta1a9b7c02015-06-25 11:49:38 -0700543bool platform_send_gain_dep_cal(void *platform, int level)
544{
545 bool ret_val = false;
546 struct platform_data *my_data = (struct platform_data *)platform;
547 struct audio_device *adev = my_data->adev;
548 int acdb_dev_id, app_type;
549 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
550 int mode = CAL_MODE_RTAC;
551 struct listnode *node;
552 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700553
554 if (my_data->acdb_send_gain_dep_cal == NULL) {
555 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
556 return ret_val;
557 }
558
559 if (!voice_is_in_call(adev)) {
560 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
561 __func__, level);
562 app_type = DEFAULT_APP_TYPE_RX_PATH;
563
564 // find the current active sound device
565 list_for_each(node, &adev->usecase_list) {
566 usecase = node_to_item(node, struct audio_usecase, list);
567
568 if (usecase != NULL &&
569 usecase->type == PCM_PLAYBACK &&
570 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
571
572 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700573 if (audio_extn_spkr_prot_is_enabled()) {
574 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
575 } else {
576 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
577 }
578
vivek mehta1a9b7c02015-06-25 11:49:38 -0700579 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
580 acdb_dev_type, mode, level)) {
581 // set ret_val true if at least one calibration is set successfully
582 ret_val = true;
583 } else {
584 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
585 }
586 } else {
587 ALOGW("%s: Usecase list is empty", __func__);
588 }
589 }
590 } else {
591 ALOGW("%s: Voice call in progress .. ignore setting new cal",
592 __func__);
593 }
594 return ret_val;
595}
596
Eric Laurentcefbbac2014-09-04 13:54:10 -0500597void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700598{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800599 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500600 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700601
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800602 if (strcmp(my_data->ec_ref_mixer_path, "")) {
603 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
604 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500605 }
606
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800607 if (enable) {
608 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
609 if (out_device != AUDIO_DEVICE_NONE) {
610 snd_device = platform_get_output_snd_device(adev->platform, out_device);
611 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
612 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500613
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800614 ALOGD("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
615 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
616 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700617}
618
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700619static struct csd_data *open_csd_client(bool i2s_ext_modem)
620{
621 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
622
623 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
624 if (csd->csd_client == NULL) {
625 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
626 goto error;
627 } else {
628 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
629
630 csd->deinit = (deinit_t)dlsym(csd->csd_client,
631 "csd_client_deinit");
632 if (csd->deinit == NULL) {
633 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
634 dlerror());
635 goto error;
636 }
637 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
638 "csd_client_disable_device");
639 if (csd->disable_device == NULL) {
640 ALOGE("%s: dlsym error %s for csd_client_disable_device",
641 __func__, dlerror());
642 goto error;
643 }
644 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
645 "csd_client_enable_device_config");
646 if (csd->enable_device_config == NULL) {
647 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
648 __func__, dlerror());
649 goto error;
650 }
651 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
652 "csd_client_enable_device");
653 if (csd->enable_device == NULL) {
654 ALOGE("%s: dlsym error %s for csd_client_enable_device",
655 __func__, dlerror());
656 goto error;
657 }
658 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
659 "csd_client_start_voice");
660 if (csd->start_voice == NULL) {
661 ALOGE("%s: dlsym error %s for csd_client_start_voice",
662 __func__, dlerror());
663 goto error;
664 }
665 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
666 "csd_client_stop_voice");
667 if (csd->stop_voice == NULL) {
668 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
669 __func__, dlerror());
670 goto error;
671 }
672 csd->volume = (volume_t)dlsym(csd->csd_client,
673 "csd_client_volume");
674 if (csd->volume == NULL) {
675 ALOGE("%s: dlsym error %s for csd_client_volume",
676 __func__, dlerror());
677 goto error;
678 }
679 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
680 "csd_client_mic_mute");
681 if (csd->mic_mute == NULL) {
682 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
683 __func__, dlerror());
684 goto error;
685 }
686 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
687 "csd_client_slow_talk");
688 if (csd->slow_talk == NULL) {
689 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
690 __func__, dlerror());
691 goto error;
692 }
693 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
694 "csd_client_start_playback");
695 if (csd->start_playback == NULL) {
696 ALOGE("%s: dlsym error %s for csd_client_start_playback",
697 __func__, dlerror());
698 goto error;
699 }
700 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
701 "csd_client_stop_playback");
702 if (csd->stop_playback == NULL) {
703 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
704 __func__, dlerror());
705 goto error;
706 }
707 csd->start_record = (start_record_t)dlsym(csd->csd_client,
708 "csd_client_start_record");
709 if (csd->start_record == NULL) {
710 ALOGE("%s: dlsym error %s for csd_client_start_record",
711 __func__, dlerror());
712 goto error;
713 }
714 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
715 "csd_client_stop_record");
716 if (csd->stop_record == NULL) {
717 ALOGE("%s: dlsym error %s for csd_client_stop_record",
718 __func__, dlerror());
719 goto error;
720 }
721
722 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
723 "csd_client_get_sample_rate");
724 if (csd->get_sample_rate == NULL) {
725 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
726 __func__, dlerror());
727
728 goto error;
729 }
730
731 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
732
733 if (csd->init == NULL) {
734 ALOGE("%s: dlsym error %s for csd_client_init",
735 __func__, dlerror());
736 goto error;
737 } else {
738 csd->init(i2s_ext_modem);
739 }
740 }
741 return csd;
742
743error:
744 free(csd);
745 csd = NULL;
746 return csd;
747}
748
749void close_csd_client(struct csd_data *csd)
750{
751 if (csd != NULL) {
752 csd->deinit();
753 dlclose(csd->csd_client);
754 free(csd);
755 csd = NULL;
756 }
757}
758
759static void platform_csd_init(struct platform_data *my_data)
760{
761#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700762 int32_t modems, (*count_modems)(void);
763 const char *name = "libdetectmodem.so";
764 const char *func = "count_modems";
765 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700766
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700767 my_data->csd = NULL;
768
769 void *lib = dlopen(name, RTLD_NOW);
770 error = dlerror();
771 if (!lib) {
772 ALOGE("%s: could not find %s: %s", __func__, name, error);
773 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700774 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700775
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700776 count_modems = NULL;
777 *(void **)(&count_modems) = dlsym(lib, func);
778 error = dlerror();
779 if (!count_modems) {
780 ALOGE("%s: could not find symbol %s in %s: %s",
781 __func__, func, name, error);
782 goto done;
783 }
784
785 modems = count_modems();
786 if (modems < 0) {
787 ALOGE("%s: count_modems failed\n", __func__);
788 goto done;
789 }
790
791 ALOGD("%s: num_modems %d\n", __func__, modems);
792 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700793 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700794
795done:
796 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700797#else
798 my_data->csd = NULL;
799#endif
800}
801
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700802static void set_platform_defaults(struct platform_data * my_data __unused)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700803{
804 int32_t dev;
805 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700806 backend_tag_table[dev] = NULL;
807 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900808 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700809 }
810
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700811 // To overwrite these go to the audio_platform_info.xml file.
812 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700813 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700814 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
815 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
816 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
817 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
818 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700819 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700820 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
821 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700822
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700823 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
824 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
825 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
826 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
827 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
828 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
829 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700830 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700831 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700832 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700833 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
834 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
835 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
836 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
837 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
838 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
839 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
840 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
841 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
842 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
843 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
844 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
845 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
846 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
847 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
848 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700849}
850
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900851void get_cvd_version(char *cvd_version, struct audio_device *adev)
852{
853 struct mixer_ctl *ctl;
854 int count;
855 int ret = 0;
856
857 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
858 if (!ctl) {
859 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
860 goto done;
861 }
862 mixer_ctl_update(ctl);
863
864 count = mixer_ctl_get_num_values(ctl);
865 if (count > MAX_CVD_VERSION_STRING_SIZE)
866 count = MAX_CVD_VERSION_STRING_SIZE - 1;
867
868 ret = mixer_ctl_get_array(ctl, cvd_version, count);
869 if (ret != 0) {
870 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
871 goto done;
872 }
873
874done:
875 return;
876}
877
Eric Laurentb23d5282013-05-14 15:27:20 -0700878void *platform_init(struct audio_device *adev)
879{
880 char value[PROPERTY_VALUE_MAX];
881 struct platform_data *my_data;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700882 int retry_num = 0, snd_card_num = 0;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700883 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900884 char *cvd_version = NULL;
sangwoo1b9f4b32013-06-21 18:22:55 -0700885
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700886 my_data = calloc(1, sizeof(struct platform_data));
887
888 my_data->adev = adev;
889
keunhui.park2f7306a2015-07-16 16:48:06 +0900890 list_init(&operator_info_list);
891
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700892 set_platform_defaults(my_data);
893
894 /* Initialize platform specific ids and/or backends*/
895 platform_info_init(my_data);
896
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700897 while (snd_card_num < MAX_SND_CARD) {
898 adev->mixer = mixer_open(snd_card_num);
sangwoo1b9f4b32013-06-21 18:22:55 -0700899
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700900 while (!adev->mixer && retry_num < RETRY_NUMBER) {
901 usleep(RETRY_US);
902 adev->mixer = mixer_open(snd_card_num);
903 retry_num++;
904 }
905
906 if (!adev->mixer) {
907 ALOGE("%s: Unable to open the mixer card: %d", __func__,
908 snd_card_num);
909 retry_num = 0;
910 snd_card_num++;
911 continue;
912 }
913
914 snd_card_name = mixer_get_name(adev->mixer);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700915
916 /* validate the sound card name */
917 if (my_data->snd_card_name != NULL &&
918 strncmp(snd_card_name, my_data->snd_card_name, MAX_SND_CARD_NAME_LEN) != 0) {
919 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
920 __func__, snd_card_name, my_data->snd_card_name);
921 retry_num = 0;
922 snd_card_num++;
923 continue;
924 }
925
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700926 ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);
927
928 adev->audio_route = audio_route_init(snd_card_num, MIXER_XML_PATH);
929 if (!adev->audio_route) {
930 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700931 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700932 }
933 adev->snd_card = snd_card_num;
934 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
935 break;
sangwoo1b9f4b32013-06-21 18:22:55 -0700936 }
937
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700938 if (snd_card_num >= MAX_SND_CARD) {
939 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700940 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -0700941 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700942
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900943 //set max volume step for voice call
944 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
945 my_data->max_vol_index = atoi(value);
946
Eric Laurentb23d5282013-05-14 15:27:20 -0700947 my_data->dualmic_config = DUALMIC_CONFIG_NONE;
948 my_data->fluence_in_spkr_mode = false;
949 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700950 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -0700951 my_data->fluence_in_voice_rec = false;
952
953 property_get("persist.audio.dualmic.config",value,"");
954 if (!strcmp("broadside", value)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700955 ALOGE("%s: Unsupported dualmic configuration", __func__);
Eric Laurentb23d5282013-05-14 15:27:20 -0700956 } else if (!strcmp("endfire", value)) {
957 my_data->dualmic_config = DUALMIC_CONFIG_ENDFIRE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700958 }
959
960 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
961 property_get("persist.audio.fluence.voicecall",value,"");
962 if (!strcmp("true", value)) {
963 my_data->fluence_in_voice_call = true;
964 }
965
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700966 property_get("persist.audio.fluence.voicecomm",value,"");
967 if (!strcmp("true", value)) {
968 my_data->fluence_in_voice_comm = true;
969 }
970
Eric Laurentb23d5282013-05-14 15:27:20 -0700971 property_get("persist.audio.fluence.voicerec",value,"");
972 if (!strcmp("true", value)) {
973 my_data->fluence_in_voice_rec = true;
974 }
975
976 property_get("persist.audio.fluence.speaker",value,"");
977 if (!strcmp("true", value)) {
978 my_data->fluence_in_spkr_mode = true;
979 }
980 }
981
982 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
983 if (my_data->acdb_handle == NULL) {
984 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
985 } else {
986 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
987 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
988 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700989 if (!my_data->acdb_deallocate)
990 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
991 __func__, LIB_ACDB_LOADER);
992
Eric Laurentb23d5282013-05-14 15:27:20 -0700993 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
994 "acdb_loader_send_audio_cal");
995 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700996 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -0700997 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700998
Eric Laurentb23d5282013-05-14 15:27:20 -0700999 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1000 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001001 if (!my_data->acdb_send_voice_cal)
1002 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1003 __func__, LIB_ACDB_LOADER);
1004
1005 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1006 "acdb_loader_reload_vocvoltable");
1007 if (!my_data->acdb_reload_vocvoltable)
1008 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1009 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001010
1011 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1012 "acdb_loader_send_gain_dep_cal");
1013 if (!my_data->acdb_send_gain_dep_cal)
1014 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1015 __func__, LIB_ACDB_LOADER);
1016
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001017#if defined (PLATFORM_MSM8994)
1018 acdb_init_v2_cvd_t acdb_init;
1019 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1020 "acdb_loader_init_v2");
1021 if (acdb_init == NULL) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001022 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001023 goto acdb_init_fail;
1024 }
1025
1026 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1027 get_cvd_version(cvd_version, adev);
1028 if (!cvd_version)
1029 ALOGE("failed to allocate cvd_version");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001030 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001031 acdb_init((char *)snd_card_name, cvd_version);
1032 free(cvd_version);
1033#elif defined (PLATFORM_MSM8084)
1034 acdb_init_v2_t acdb_init;
1035 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1036 "acdb_loader_init_v2");
1037 if (acdb_init == NULL) {
1038 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
1039 goto acdb_init_fail;
1040 }
1041 acdb_init((char *)snd_card_name);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001042#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001043 acdb_init_t acdb_init;
1044 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001045 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001046 if (acdb_init == NULL)
Eric Laurentb23d5282013-05-14 15:27:20 -07001047 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
1048 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001049 acdb_init();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001050#endif
Eric Laurentb23d5282013-05-14 15:27:20 -07001051 }
1052
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001053acdb_init_fail:
1054
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001055 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001056
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001057 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1058
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001059 /* load csd client */
1060 platform_csd_init(my_data);
1061
Eric Laurentb23d5282013-05-14 15:27:20 -07001062 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001063
1064init_failed:
1065 if (my_data)
1066 free(my_data);
1067 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001068}
1069
1070void platform_deinit(void *platform)
1071{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001072 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001073 struct operator_info *info_item;
1074 struct operator_specific_device *device_item;
1075 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001076
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001077 struct platform_data *my_data = (struct platform_data *)platform;
1078 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001079
1080 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1081 if (backend_tag_table[dev])
1082 free(backend_tag_table[dev]);
1083 if (hw_interface_table[dev])
1084 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001085 if (operator_specific_device_table[dev]) {
1086 while (!list_empty(operator_specific_device_table[dev])) {
1087 node = list_head(operator_specific_device_table[dev]);
1088 list_remove(node);
1089 device_item = node_to_item(node, struct operator_specific_device, list);
1090 free(device_item->operator);
1091 free(device_item->mixer_path);
1092 free(device_item);
1093 }
1094 free(operator_specific_device_table[dev]);
1095 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001096 }
1097
1098 if (my_data->snd_card_name)
1099 free(my_data->snd_card_name);
1100
keunhui.park2f7306a2015-07-16 16:48:06 +09001101 while (!list_empty(&operator_info_list)) {
1102 node = list_head(&operator_info_list);
1103 list_remove(node);
1104 info_item = node_to_item(node, struct operator_info, list);
1105 free(info_item->name);
1106 free(info_item->mccmnc);
1107 free(info_item);
1108 }
1109
Eric Laurentb23d5282013-05-14 15:27:20 -07001110 free(platform);
1111}
1112
1113const char *platform_get_snd_device_name(snd_device_t snd_device)
1114{
keunhui.park2f7306a2015-07-16 16:48:06 +09001115 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1116 if (operator_specific_device_table[snd_device] != NULL) {
1117 return get_operator_specific_device_mixer_path(snd_device);
1118 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001119 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001120 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001121 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001122}
1123
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001124void platform_add_backend_name(void *platform, char *mixer_path,
1125 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001126{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001127 struct platform_data *my_data = (struct platform_data *)platform;
1128
Haynes Mathew George98c95622014-06-20 19:14:25 -07001129 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1130 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1131 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001132 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001133
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001134 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001135
1136 if (suffix != NULL) {
1137 strcat(mixer_path, " ");
1138 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001139 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001140}
1141
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001142bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1143{
1144 bool result = true;
1145
1146 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1147 platform_get_snd_device_name(snd_device1),
1148 platform_get_snd_device_name(snd_device2));
1149
1150 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1151 ALOGE("%s: Invalid snd_device = %s", __func__,
1152 platform_get_snd_device_name(snd_device1));
1153 return false;
1154 }
1155 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1156 ALOGE("%s: Invalid snd_device = %s", __func__,
1157 platform_get_snd_device_name(snd_device2));
1158 return false;
1159 }
1160 const char * be_itf1 = hw_interface_table[snd_device1];
1161 const char * be_itf2 = hw_interface_table[snd_device2];
1162
1163 if (NULL != be_itf1 && NULL != be_itf2) {
1164 if (0 != strcmp(be_itf1, be_itf2))
1165 result = false;
1166 }
1167
1168 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1169 return result;
1170}
1171
Eric Laurentb23d5282013-05-14 15:27:20 -07001172int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1173{
1174 int device_id;
1175 if (device_type == PCM_PLAYBACK)
1176 device_id = pcm_device_table[usecase][0];
1177 else
1178 device_id = pcm_device_table[usecase][1];
1179 return device_id;
1180}
1181
Haynes Mathew George98c95622014-06-20 19:14:25 -07001182static int find_index(const struct name_to_index * table, int32_t len,
1183 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001184{
1185 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001186 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001187
Haynes Mathew George98c95622014-06-20 19:14:25 -07001188 if (table == NULL) {
1189 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001190 ret = -ENODEV;
1191 goto done;
1192 }
1193
Haynes Mathew George98c95622014-06-20 19:14:25 -07001194 if (name == NULL) {
1195 ALOGE("null key");
1196 ret = -ENODEV;
1197 goto done;
1198 }
1199
1200 for (i=0; i < len; i++) {
1201 if (!strcmp(table[i].name, name)) {
1202 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001203 goto done;
1204 }
1205 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001206 ALOGE("%s: Could not find index for name = %s",
1207 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001208 ret = -ENODEV;
1209done:
1210 return ret;
1211}
1212
Haynes Mathew George98c95622014-06-20 19:14:25 -07001213int platform_get_snd_device_index(char *device_name)
1214{
1215 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1216}
1217
1218int platform_get_usecase_index(const char *usecase_name)
1219{
1220 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1221}
1222
keunhui.park2f7306a2015-07-16 16:48:06 +09001223void platform_add_operator_specific_device(snd_device_t snd_device,
1224 const char *operator,
1225 const char *mixer_path,
1226 unsigned int acdb_id)
1227{
1228 struct operator_specific_device *device;
1229
1230 if (operator_specific_device_table[snd_device] == NULL) {
1231 operator_specific_device_table[snd_device] =
1232 (struct listnode *)calloc(1, sizeof(struct listnode));
1233 list_init(operator_specific_device_table[snd_device]);
1234 }
1235
1236 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1237
1238 device->operator = strdup(operator);
1239 device->mixer_path = strdup(mixer_path);
1240 device->acdb_id = acdb_id;
1241
1242 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1243
1244 ALOGD("%s : deivce[%s] -> operator[%s] mixer_path[%s] acdb_id [%d]", __func__,
1245 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1246
1247}
1248
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001249int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1250{
1251 int ret = 0;
1252
1253 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1254 ALOGE("%s: Invalid snd_device = %d",
1255 __func__, snd_device);
1256 ret = -EINVAL;
1257 goto done;
1258 }
1259
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001260 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1261 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001262 acdb_device_table[snd_device] = acdb_id;
1263done:
1264 return ret;
1265}
1266
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001267int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1268{
1269 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1270 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1271 return -EINVAL;
1272 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001273
1274 if (operator_specific_device_table[snd_device] != NULL)
1275 return get_operator_specific_device_acdb_id(snd_device);
1276 else
1277 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001278}
1279
Eric Laurentb23d5282013-05-14 15:27:20 -07001280int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1281{
1282 struct platform_data *my_data = (struct platform_data *)platform;
1283 int acdb_dev_id, acdb_dev_type;
1284
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001285 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001286 if (acdb_dev_id < 0) {
1287 ALOGE("%s: Could not find acdb id for device(%d)",
1288 __func__, snd_device);
1289 return -EINVAL;
1290 }
1291 if (my_data->acdb_send_audio_cal) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001292 ALOGD("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001293 __func__, snd_device, acdb_dev_id);
1294 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1295 snd_device < SND_DEVICE_OUT_END)
1296 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1297 else
1298 acdb_dev_type = ACDB_DEV_TYPE_IN;
1299 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1300 }
1301 return 0;
1302}
1303
1304int platform_switch_voice_call_device_pre(void *platform)
1305{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001306 struct platform_data *my_data = (struct platform_data *)platform;
1307 int ret = 0;
1308
1309 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001310 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001311 /* This must be called before disabling mixer controls on APQ side */
1312 ret = my_data->csd->disable_device();
1313 if (ret < 0) {
1314 ALOGE("%s: csd_client_disable_device, failed, error %d",
1315 __func__, ret);
1316 }
1317 }
1318 return ret;
1319}
1320
1321int platform_switch_voice_call_enable_device_config(void *platform,
1322 snd_device_t out_snd_device,
1323 snd_device_t in_snd_device)
1324{
1325 struct platform_data *my_data = (struct platform_data *)platform;
1326 int acdb_rx_id, acdb_tx_id;
1327 int ret = 0;
1328
1329 if (my_data->csd == NULL)
1330 return ret;
1331
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001332 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1333 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001334 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001335 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001336 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001337
keunhui.park2f7306a2015-07-16 16:48:06 +09001338 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001339
1340 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1341 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1342 if (ret < 0) {
1343 ALOGE("%s: csd_enable_device_config, failed, error %d",
1344 __func__, ret);
1345 }
1346 } else {
1347 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1348 acdb_rx_id, acdb_tx_id);
1349 }
1350
1351 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001352}
1353
1354int platform_switch_voice_call_device_post(void *platform,
1355 snd_device_t out_snd_device,
1356 snd_device_t in_snd_device)
1357{
1358 struct platform_data *my_data = (struct platform_data *)platform;
1359 int acdb_rx_id, acdb_tx_id;
1360
1361 if (my_data->acdb_send_voice_cal == NULL) {
1362 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1363 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001364 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1365 audio_extn_spkr_prot_is_enabled())
1366 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1367
keunhui.park2f7306a2015-07-16 16:48:06 +09001368 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1369 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001370
1371 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1372 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1373 else
1374 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1375 acdb_rx_id, acdb_tx_id);
1376 }
1377
1378 return 0;
1379}
1380
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001381int platform_switch_voice_call_usecase_route_post(void *platform,
1382 snd_device_t out_snd_device,
1383 snd_device_t in_snd_device)
1384{
1385 struct platform_data *my_data = (struct platform_data *)platform;
1386 int acdb_rx_id, acdb_tx_id;
1387 int ret = 0;
1388
1389 if (my_data->csd == NULL)
1390 return ret;
1391
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001392 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1393 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001394 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001395 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001396 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001397
keunhui.park2f7306a2015-07-16 16:48:06 +09001398 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001399
1400 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1401 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1402 my_data->adev->acdb_settings);
1403 if (ret < 0) {
1404 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1405 }
1406 } else {
1407 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1408 acdb_rx_id, acdb_tx_id);
1409 }
1410
1411 return ret;
1412}
1413
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001414int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001415{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001416 struct platform_data *my_data = (struct platform_data *)platform;
1417 int ret = 0;
1418
1419 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001420 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001421 if (ret < 0) {
1422 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1423 }
1424 }
1425 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001426}
1427
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001428int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001429{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001430 struct platform_data *my_data = (struct platform_data *)platform;
1431 int ret = 0;
1432
1433 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001434 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001435 if (ret < 0) {
1436 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1437 }
1438 }
1439 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001440}
1441
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001442int platform_get_sample_rate(void *platform, uint32_t *rate)
1443{
1444 struct platform_data *my_data = (struct platform_data *)platform;
1445 int ret = 0;
1446
1447 if (my_data->csd != NULL) {
1448 ret = my_data->csd->get_sample_rate(rate);
1449 if (ret < 0) {
1450 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1451 }
1452 }
1453 return ret;
1454}
1455
Eric Laurentb23d5282013-05-14 15:27:20 -07001456int platform_set_voice_volume(void *platform, int volume)
1457{
1458 struct platform_data *my_data = (struct platform_data *)platform;
1459 struct audio_device *adev = my_data->adev;
1460 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001461 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001462 int vol_index = 0, ret = 0;
1463 uint32_t set_values[ ] = {0,
1464 ALL_SESSION_VSID,
1465 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001466
1467 // Voice volume levels are mapped to adsp volume levels as follows.
1468 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1469 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001470 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001471 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001472
1473 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1474 if (!ctl) {
1475 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1476 __func__, mixer_ctl_name);
1477 return -EINVAL;
1478 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001479 ALOGV("Setting voice volume index: %d", set_values[0]);
1480 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1481
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001482 if (my_data->csd != NULL) {
1483 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1484 DEFAULT_VOLUME_RAMP_DURATION_MS);
1485 if (ret < 0) {
1486 ALOGE("%s: csd_volume error %d", __func__, ret);
1487 }
1488 }
1489 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001490}
1491
1492int platform_set_mic_mute(void *platform, bool state)
1493{
1494 struct platform_data *my_data = (struct platform_data *)platform;
1495 struct audio_device *adev = my_data->adev;
1496 struct mixer_ctl *ctl;
1497 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001498 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001499 uint32_t set_values[ ] = {0,
1500 ALL_SESSION_VSID,
1501 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001502
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001503 if (adev->mode != AUDIO_MODE_IN_CALL)
1504 return 0;
1505
1506 set_values[0] = state;
1507 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1508 if (!ctl) {
1509 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1510 __func__, mixer_ctl_name);
1511 return -EINVAL;
1512 }
1513 ALOGV("Setting voice mute state: %d", state);
1514 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1515
1516 if (my_data->csd != NULL) {
1517 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1518 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001519 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001520 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001521 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001522 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001523 return ret;
1524}
Eric Laurentb23d5282013-05-14 15:27:20 -07001525
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001526int platform_set_device_mute(void *platform, bool state, char *dir)
1527{
1528 struct platform_data *my_data = (struct platform_data *)platform;
1529 struct audio_device *adev = my_data->adev;
1530 struct mixer_ctl *ctl;
1531 char *mixer_ctl_name = NULL;
1532 int ret = 0;
1533 uint32_t set_values[ ] = {0,
1534 ALL_SESSION_VSID,
1535 0};
1536 if(dir == NULL) {
1537 ALOGE("%s: Invalid direction:%s", __func__, dir);
1538 return -EINVAL;
1539 }
1540
1541 if (!strncmp("rx", dir, sizeof("rx"))) {
1542 mixer_ctl_name = "Voice Rx Device Mute";
1543 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1544 mixer_ctl_name = "Voice Tx Device Mute";
1545 } else {
1546 return -EINVAL;
1547 }
1548
1549 set_values[0] = state;
1550 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1551 if (!ctl) {
1552 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1553 __func__, mixer_ctl_name);
1554 return -EINVAL;
1555 }
1556
1557 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1558 __func__,state, mixer_ctl_name);
1559 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1560
1561 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001562}
1563
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001564bool platform_can_split_snd_device(snd_device_t snd_device,
1565 int *num_devices,
1566 snd_device_t *new_snd_devices)
1567{
1568 bool status = false;
1569
1570 if (NULL == num_devices || NULL == new_snd_devices) {
1571 ALOGE("%s: NULL pointer ..", __func__);
1572 return false;
1573 }
1574
1575 /*
1576 * If wired headset/headphones/line devices share the same backend
1577 * with speaker/earpiece this routine returns false.
1578 */
1579 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1580 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1581 *num_devices = 2;
1582 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1583 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1584 status = true;
1585 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1586 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1587 *num_devices = 2;
1588 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1589 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1590 status = true;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001591 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1592 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1593 *num_devices = 2;
1594 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1595 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1596 status = true;
1597 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1598 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1599 *num_devices = 2;
1600 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1601 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1602 status = true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001603 }
1604 return status;
1605}
1606
Eric Laurentb23d5282013-05-14 15:27:20 -07001607snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1608{
1609 struct platform_data *my_data = (struct platform_data *)platform;
1610 struct audio_device *adev = my_data->adev;
1611 audio_mode_t mode = adev->mode;
1612 snd_device_t snd_device = SND_DEVICE_NONE;
1613
1614 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1615 if (devices == AUDIO_DEVICE_NONE ||
1616 devices & AUDIO_DEVICE_BIT_IN) {
1617 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1618 goto exit;
1619 }
1620
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001621 if (voice_is_in_call(adev) || adev->enable_voicerx) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001622 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001623 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1624 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001625 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001626 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001627 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001628 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001629 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001630 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001631 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001632 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001633 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001634 else {
1635 if (devices & AUDIO_DEVICE_OUT_LINE)
1636 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1637 else
1638 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1639 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001640 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001641 if (adev->bt_wb_speech_enabled) {
1642 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1643 } else {
1644 snd_device = SND_DEVICE_OUT_BT_SCO;
1645 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001646 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001647 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1648 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001649 if(adev->voice.hac)
1650 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1651 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07001652 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1653 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05001654 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001655 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1656 snd_device = SND_DEVICE_OUT_VOICE_TX;
1657
Eric Laurentb23d5282013-05-14 15:27:20 -07001658 if (snd_device != SND_DEVICE_NONE) {
1659 goto exit;
1660 }
1661 }
1662
1663 if (popcount(devices) == 2) {
1664 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001665 AUDIO_DEVICE_OUT_SPEAKER) ||
1666 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1667 AUDIO_DEVICE_OUT_SPEAKER)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001668 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Eric Laurent744996b2014-10-01 11:40:40 -05001669 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1670 AUDIO_DEVICE_OUT_SPEAKER)) {
1671 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001672 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1673 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1674 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1675 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1676 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1677 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1678 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1679 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001680 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1681 AUDIO_DEVICE_OUT_SPEAKER)) {
1682 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1683 } else {
1684 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1685 goto exit;
1686 }
1687 if (snd_device != SND_DEVICE_NONE) {
1688 goto exit;
1689 }
1690 }
1691
1692 if (popcount(devices) != 1) {
1693 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1694 goto exit;
1695 }
1696
1697 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1698 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1699 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001700 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1701 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001702 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
1703 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001704 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001705 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07001706 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1707 else
1708 snd_device = SND_DEVICE_OUT_SPEAKER;
1709 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001710 if (adev->bt_wb_speech_enabled) {
1711 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1712 } else {
1713 snd_device = SND_DEVICE_OUT_BT_SCO;
1714 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001715 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1716 snd_device = SND_DEVICE_OUT_HDMI ;
1717 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001718 /*HAC support for voice-ish audio (eg visual voicemail)*/
1719 if(adev->voice.hac)
1720 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1721 else
1722 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001723 } else {
1724 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1725 }
1726exit:
1727 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1728 return snd_device;
1729}
1730
1731snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1732{
1733 struct platform_data *my_data = (struct platform_data *)platform;
1734 struct audio_device *adev = my_data->adev;
1735 audio_source_t source = (adev->active_input == NULL) ?
1736 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1737
1738 audio_mode_t mode = adev->mode;
1739 audio_devices_t in_device = ((adev->active_input == NULL) ?
1740 AUDIO_DEVICE_NONE : adev->active_input->device)
1741 & ~AUDIO_DEVICE_BIT_IN;
1742 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1743 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1744 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001745 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001746
1747 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1748 __func__, out_device, in_device);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001749 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001750 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001751 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001752 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1753 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001754 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001755 case TTY_MODE_FULL:
1756 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1757 break;
1758 case TTY_MODE_VCO:
1759 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1760 break;
1761 case TTY_MODE_HCO:
1762 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1763 break;
1764 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001765 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07001766 }
1767 goto exit;
1768 }
1769 }
Eric Laurentb991fb02014-08-29 15:23:17 -05001770 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001771 if (my_data->fluence_in_voice_call == false) {
1772 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1773 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001774 if (is_operator_tmus())
1775 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07001776 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001777 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001778 }
1779 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1780 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1781 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001782 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001783 if (adev->bluetooth_nrec)
1784 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1785 else
1786 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001787 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001788 if (adev->bluetooth_nrec)
1789 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1790 else
1791 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001792 }
Eric Laurentb991fb02014-08-29 15:23:17 -05001793 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001794 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Eric Laurentb991fb02014-08-29 15:23:17 -05001795 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1796 out_device & AUDIO_DEVICE_OUT_LINE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001797 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001798 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
1799 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001800 } else {
1801 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1802 }
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001803 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1804 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurentb23d5282013-05-14 15:27:20 -07001805 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1806 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1807 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1808 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1809 }
1810 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1811 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001812 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001813 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001814 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1815 else if (my_data->fluence_in_voice_rec &&
1816 adev->active_input->enable_ns)
1817 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001818 }
1819
1820 if (snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001821 if (adev->active_input->enable_ns)
1822 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1823 else
1824 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001825 }
1826 }
1827 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001828 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07001829 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1830 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001831 if (adev->active_input->enable_aec &&
1832 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001833 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001834 if (my_data->fluence_in_spkr_mode &&
1835 my_data->fluence_in_voice_comm &&
1836 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
1837 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
1838 } else
1839 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Eric Laurentb23d5282013-05-14 15:27:20 -07001840 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001841 if (my_data->fluence_in_voice_comm &&
1842 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
1843 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
1844 } else
1845 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Eric Laurentcefbbac2014-09-04 13:54:10 -05001846 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1847 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001848 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001849 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001850 } else if (adev->active_input->enable_aec) {
1851 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1852 if (my_data->fluence_in_spkr_mode &&
1853 my_data->fluence_in_voice_comm &&
1854 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
1855 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
1856 } else
1857 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1858 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1859 if (my_data->fluence_in_voice_comm &&
1860 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
1861 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
1862 } else
1863 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05001864 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1865 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
1866 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001867 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001868 } else if (adev->active_input->enable_ns) {
1869 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1870 if (my_data->fluence_in_spkr_mode &&
1871 my_data->fluence_in_voice_comm &&
1872 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
1873 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
1874 } else
1875 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1876 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1877 if (my_data->fluence_in_voice_comm &&
1878 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
1879 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
1880 } else
1881 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1882 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001883 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001884 }
1885 } else if (source == AUDIO_SOURCE_DEFAULT) {
1886 goto exit;
1887 }
1888
1889
1890 if (snd_device != SND_DEVICE_NONE) {
1891 goto exit;
1892 }
1893
1894 if (in_device != AUDIO_DEVICE_NONE &&
1895 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1896 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1897 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001898 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE &&
1899 channel_count == 2)
1900 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
1901 else
1902 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001903 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001904 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE &&
1905 channel_count == 2)
1906 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
1907 else
1908 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001909 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1910 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1911 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001912 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001913 if (adev->bluetooth_nrec)
1914 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1915 else
1916 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001917 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001918 if (adev->bluetooth_nrec)
1919 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1920 else
1921 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001922 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001923 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1924 snd_device = SND_DEVICE_IN_HDMI_MIC;
1925 } else {
1926 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1927 ALOGW("%s: Using default handset-mic", __func__);
1928 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1929 }
1930 } else {
1931 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1932 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1933 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1934 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001935 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001936 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001937 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001938 out_device & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001939 if (channel_count == 2)
1940 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
1941 else
1942 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001943 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001944 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001945 if (adev->bluetooth_nrec)
1946 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1947 else
1948 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001949 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001950 if (adev->bluetooth_nrec)
1951 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1952 else
1953 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001954 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001955 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1956 snd_device = SND_DEVICE_IN_HDMI_MIC;
1957 } else {
1958 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1959 ALOGW("%s: Using default handset-mic", __func__);
1960 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1961 }
1962 }
1963exit:
1964 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1965 return snd_device;
1966}
1967
1968int platform_set_hdmi_channels(void *platform, int channel_count)
1969{
1970 struct platform_data *my_data = (struct platform_data *)platform;
1971 struct audio_device *adev = my_data->adev;
1972 struct mixer_ctl *ctl;
1973 const char *channel_cnt_str = NULL;
1974 const char *mixer_ctl_name = "HDMI_RX Channels";
1975 switch (channel_count) {
1976 case 8:
1977 channel_cnt_str = "Eight"; break;
1978 case 7:
1979 channel_cnt_str = "Seven"; break;
1980 case 6:
1981 channel_cnt_str = "Six"; break;
1982 case 5:
1983 channel_cnt_str = "Five"; break;
1984 case 4:
1985 channel_cnt_str = "Four"; break;
1986 case 3:
1987 channel_cnt_str = "Three"; break;
1988 default:
1989 channel_cnt_str = "Two"; break;
1990 }
1991 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1992 if (!ctl) {
1993 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1994 __func__, mixer_ctl_name);
1995 return -EINVAL;
1996 }
1997 ALOGV("HDMI channel count: %s", channel_cnt_str);
1998 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1999 return 0;
2000}
2001
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002002int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002003{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002004 struct platform_data *my_data = (struct platform_data *)platform;
2005 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002006 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2007 char *sad = block;
2008 int num_audio_blocks;
2009 int channel_count;
2010 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002011 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002012
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002013 struct mixer_ctl *ctl;
2014
2015 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2016 if (!ctl) {
2017 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2018 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002019 return 0;
2020 }
2021
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002022 mixer_ctl_update(ctl);
2023
2024 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002025
2026 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002027 if (count > (int)sizeof(block))
2028 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002029
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002030 ret = mixer_ctl_get_array(ctl, block, count);
2031 if (ret != 0) {
2032 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2033 return 0;
2034 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002035
2036 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002037 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002038
2039 for (i = 0; i < num_audio_blocks; i++) {
2040 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002041 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2042 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002043 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002044 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002045
2046 channel_count = (sad[0] & 0x7) + 1;
2047 if (channel_count > max_channels)
2048 max_channels = channel_count;
2049
2050 /* Advance to next block */
2051 sad += 3;
2052 }
2053
2054 return max_channels;
2055}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002056
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002057int platform_set_incall_recording_session_id(void *platform,
2058 uint32_t session_id, int rec_mode)
2059{
2060 int ret = 0;
2061 struct platform_data *my_data = (struct platform_data *)platform;
2062 struct audio_device *adev = my_data->adev;
2063 struct mixer_ctl *ctl;
2064 const char *mixer_ctl_name = "Voc VSID";
2065 int num_ctl_values;
2066 int i;
2067
2068 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2069 if (!ctl) {
2070 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2071 __func__, mixer_ctl_name);
2072 ret = -EINVAL;
2073 } else {
2074 num_ctl_values = mixer_ctl_get_num_values(ctl);
2075 for (i = 0; i < num_ctl_values; i++) {
2076 if (mixer_ctl_set_value(ctl, i, session_id)) {
2077 ALOGV("Error: invalid session_id: %x", session_id);
2078 ret = -EINVAL;
2079 break;
2080 }
2081 }
2082 }
2083
2084 if (my_data->csd != NULL) {
2085 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2086 if (ret < 0) {
2087 ALOGE("%s: csd_client_start_record failed, error %d",
2088 __func__, ret);
2089 }
2090 }
2091
2092 return ret;
2093}
2094
2095int platform_stop_incall_recording_usecase(void *platform)
2096{
2097 int ret = 0;
2098 struct platform_data *my_data = (struct platform_data *)platform;
2099
2100 if (my_data->csd != NULL) {
2101 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2102 if (ret < 0) {
2103 ALOGE("%s: csd_client_stop_record failed, error %d",
2104 __func__, ret);
2105 }
2106 }
2107
2108 return ret;
2109}
2110
2111int platform_start_incall_music_usecase(void *platform)
2112{
2113 int ret = 0;
2114 struct platform_data *my_data = (struct platform_data *)platform;
2115
2116 if (my_data->csd != NULL) {
2117 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2118 if (ret < 0) {
2119 ALOGE("%s: csd_client_start_playback failed, error %d",
2120 __func__, ret);
2121 }
2122 }
2123
2124 return ret;
2125}
2126
2127int platform_stop_incall_music_usecase(void *platform)
2128{
2129 int ret = 0;
2130 struct platform_data *my_data = (struct platform_data *)platform;
2131
2132 if (my_data->csd != NULL) {
2133 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2134 if (ret < 0) {
2135 ALOGE("%s: csd_client_stop_playback failed, error %d",
2136 __func__, ret);
2137 }
2138 }
2139
2140 return ret;
2141}
2142
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002143int platform_set_parameters(void *platform, struct str_parms *parms)
2144{
2145 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002146 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002147 char *kv_pairs = str_parms_to_str(parms);
2148 int ret = 0, err;
2149
2150 if (kv_pairs == NULL) {
2151 ret = -EINVAL;
2152 ALOGE("%s: key-value pair is NULL",__func__);
2153 goto done;
2154 }
2155
2156 ALOGV("%s: enter: %s", __func__, kv_pairs);
2157
2158 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2159 value, sizeof(value));
2160 if (err >= 0) {
2161 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2162 my_data->snd_card_name = strdup(value);
2163 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2164 }
2165
keunhui.park2f7306a2015-07-16 16:48:06 +09002166 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2167 value, sizeof(value));
2168 if (err >= 0) {
2169 struct operator_info *info;
2170 char *str = value;
2171 char *name;
2172
2173 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2174 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2175 name = strtok(str, ";");
2176 info->name = strdup(name);
2177 info->mccmnc = strdup(str + strlen(name) + 1);
2178
2179 list_add_tail(&operator_info_list, &info->list);
2180 ALOGD("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
2181 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002182done:
2183 ALOGV("%s: exit with code(%d)", __func__, ret);
2184 if (kv_pairs != NULL)
2185 free(kv_pairs);
2186
2187 return ret;
2188}
2189
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002190/* Delay in Us */
2191int64_t platform_render_latency(audio_usecase_t usecase)
2192{
2193 switch (usecase) {
2194 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2195 return DEEP_BUFFER_PLATFORM_DELAY;
2196 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2197 return LOW_LATENCY_PLATFORM_DELAY;
2198 default:
2199 return 0;
2200 }
2201}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002202
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002203int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2204 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002205{
2206 int ret = 0;
2207
2208 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2209 ALOGE("%s: Invalid snd_device = %d",
2210 __func__, device);
2211 ret = -EINVAL;
2212 goto done;
2213 }
2214
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002215 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2216 platform_get_snd_device_name(device),
2217 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2218 if (backend_tag_table[device]) {
2219 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002220 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002221 backend_tag_table[device] = strdup(backend_tag);
2222
2223 if (hw_interface != NULL) {
2224 if (hw_interface_table[device])
2225 free(hw_interface_table[device]);
2226 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2227 hw_interface_table[device] = strdup(hw_interface);
2228 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002229done:
2230 return ret;
2231}
2232
2233int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2234{
2235 int ret = 0;
2236 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2237 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2238 ret = -EINVAL;
2239 goto done;
2240 }
2241
2242 if ((type != 0) && (type != 1)) {
2243 ALOGE("%s: invalid usecase type", __func__);
2244 ret = -EINVAL;
2245 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002246 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002247 pcm_device_table[usecase][type] = pcm_id;
2248done:
2249 return ret;
2250}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002251
2252int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2253{
2254 // only update if there is active pcm playback on speaker
2255 struct audio_usecase *usecase;
2256 struct listnode *node;
2257 struct platform_data *my_data = (struct platform_data *)adev->platform;
2258
2259 if (my_data->speaker_lr_swap != swap_channels) {
2260 my_data->speaker_lr_swap = swap_channels;
2261
2262 list_for_each(node, &adev->usecase_list) {
2263 usecase = node_to_item(node, struct audio_usecase, list);
2264 if (usecase->type == PCM_PLAYBACK &&
2265 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2266 const char *mixer_path;
2267 if (swap_channels) {
2268 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2269 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2270 } else {
2271 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2272 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2273 }
2274 break;
2275 }
2276 }
2277 }
2278 return 0;
2279}