blob: 84daaada99fc067a77260390582e55c5d7494dca [file] [log] [blame]
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
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 "audio_hw_primary"
18/*#define LOG_NDEBUG 0*/
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -080019#define LOG_NDDEBUG 0
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080020
21#include <errno.h>
22#include <pthread.h>
23#include <stdint.h>
24#include <sys/time.h>
25#include <stdlib.h>
26#include <dlfcn.h>
27#include <math.h>
28
29#include <cutils/log.h>
30#include <cutils/str_parms.h>
31#include <cutils/properties.h>
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -080032#include <cutils/list.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080033
34#include "audio_hw.h"
35
Sungmin Choi75ebaa02013-05-22 13:14:28 -070036#define LIB_ACDB_LOADER "libacdbloader.so"
37#define LIB_CSD_CLIENT "libcsd-client.so"
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080038#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
39#define MIXER_CARD 0
40
41#define STRING_TO_ENUM(string) { #string, string }
42
43/* Flags used to initialize acdb_settings variable that goes to ACDB library */
44#define DMIC_FLAG 0x00000002
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -080045#define TTY_MODE_OFF 0x00000010
46#define TTY_MODE_FULL 0x00000020
47#define TTY_MODE_VCO 0x00000040
48#define TTY_MODE_HCO 0x00000080
49#define TTY_MODE_CLEAR 0xFFFFFF0F
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080050
51struct string_to_enum {
52 const char *name;
53 uint32_t value;
54};
55
56static const struct string_to_enum out_channels_name_to_enum_table[] = {
57 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_STEREO),
58 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_5POINT1),
59 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1),
60};
61
62static const char * const use_case_table[AUDIO_USECASE_MAX] = {
63 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback",
64 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback",
65 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback",
66 [USECASE_AUDIO_RECORD] = "audio-record",
67 [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record",
68 [USECASE_VOICE_CALL] = "voice-call",
69};
70
71static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
72 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {0, 0},
Sungmin Choi5195a4b2013-04-03 21:54:22 -070073#ifdef MSM8974
74 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {15, 15},
75#else
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080076 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {14, 14},
Sungmin Choi5195a4b2013-04-03 21:54:22 -070077#endif
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080078 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {1, 1},
79 [USECASE_AUDIO_RECORD] = {0, 0},
80 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {14, 14},
Shashank Mittald2f3c3b2013-05-02 20:27:47 -070081#ifdef MSM8974
82 [USECASE_VOICE_CALL] = {2, 2},
83#else
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080084 [USECASE_VOICE_CALL] = {12, 12},
Shashank Mittald2f3c3b2013-05-02 20:27:47 -070085#endif
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080086};
87
88/* Array to store sound devices */
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -080089static const char * const device_table[SND_DEVICE_MAX] = {
90 [SND_DEVICE_NONE] = "none",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080091 /* Playback sound devices */
92 [SND_DEVICE_OUT_HANDSET] = "handset",
93 [SND_DEVICE_OUT_SPEAKER] = "speaker",
Jean-Michel Trivic56336b2013-05-24 16:55:17 -070094 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080095 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
96 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -070097 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080098 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
99 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800100 [SND_DEVICE_OUT_HDMI] = "hdmi",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800101 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
102 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800103 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800104 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
105 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
106 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800107
108 /* Capture sound devices */
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800109 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800110 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
111 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -0700112 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
113 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic",
114 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800115 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
116 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
117 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800118 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800119 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800120 [SND_DEVICE_IN_VOICE_DMIC_EF] = "voice-dmic-ef",
121 [SND_DEVICE_IN_VOICE_DMIC_BS] = "voice-dmic-bs",
122 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = "voice-dmic-ef-tmus",
123 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = "voice-speaker-dmic-ef",
124 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = "voice-speaker-dmic-bs",
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800125 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
126 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
127 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800128 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800129 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = "voice-rec-dmic-ef",
130 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = "voice-rec-dmic-bs",
Eric Laurentc8400632013-02-14 19:04:54 -0800131 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = "voice-rec-dmic-ef-fluence",
132 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = "voice-rec-dmic-bs-fluence",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800133};
134
Eric Laurentc8400632013-02-14 19:04:54 -0800135/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800136static const int acdb_device_table[SND_DEVICE_MAX] = {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700137 [SND_DEVICE_NONE] = -1,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800138 [SND_DEVICE_OUT_HANDSET] = 7,
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -0700139#ifdef MSM8974
140 [SND_DEVICE_OUT_SPEAKER] = 15,
141#else
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800142 [SND_DEVICE_OUT_SPEAKER] = 14,
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -0700143#endif
Jean-Michel Trivic56336b2013-05-24 16:55:17 -0700144 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800145 [SND_DEVICE_OUT_HEADPHONES] = 10,
146 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -0700147 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
148#ifdef MSM8974
149 [SND_DEVICE_OUT_VOICE_SPEAKER] = 15,
150#else
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800151 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -0700152#endif
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800153 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800154 [SND_DEVICE_OUT_HDMI] = 18,
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -0700155#ifdef MSM8974
156 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
157#else
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800158 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -0700159#endif
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800160 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800161 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 81,
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800162 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
163 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
164 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800165
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800166 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -0700167 [SND_DEVICE_IN_SPEAKER_MIC] = 4, /* ToDo: Check if this needs to changed to 11 */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800168 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -0700169 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
170 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
171 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800172 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
173 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
174 [SND_DEVICE_IN_HDMI_MIC] = 4,
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800175 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800176 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
sangwooea6ef9d2013-06-03 10:37:22 +0900177#ifdef MSM8974
178 [SND_DEVICE_IN_VOICE_DMIC_EF] = 41,
179#else
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800180 [SND_DEVICE_IN_VOICE_DMIC_EF] = 6,
sangwooea6ef9d2013-06-03 10:37:22 +0900181#endif
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800182 [SND_DEVICE_IN_VOICE_DMIC_BS] = 5,
183 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = 91,
sangwooea6ef9d2013-06-03 10:37:22 +0900184#ifdef MSM8974
185 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = 43,
186#else
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800187 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = 13,
sangwooea6ef9d2013-06-03 10:37:22 +0900188#endif
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800189 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = 12,
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800190 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
191 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
192 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800193 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -0700194 /* TODO: Update with proper acdb ids */
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800195 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = 62,
196 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = 62,
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -0700197 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = 6,
198 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = 5,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800199};
200
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800201int edid_get_max_channels(void);
202
Ravi Kumar Alamanda37718842013-02-22 18:44:45 -0800203static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
204static bool is_tmus = false;
205
206static void check_operator()
207{
208 char value[PROPERTY_VALUE_MAX];
209 int mccmnc;
210 property_get("gsm.sim.operator.numeric",value,"0");
211 mccmnc = atoi(value);
212 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
213 switch(mccmnc) {
214 /* TMUS MCC(310), MNC(490, 260, 026) */
215 case 310490:
216 case 310260:
217 case 310026:
218 is_tmus = true;
219 break;
220 }
221}
222
223static bool is_operator_tmus()
224{
225 pthread_once(&check_op_once_ctl, check_operator);
226 return is_tmus;
227}
228
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800229static int get_pcm_device_id(struct audio_route *ar,
230 audio_usecase_t usecase,
231 int device_type)
232{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800233 int device_id;
234 if (device_type == PCM_PLAYBACK)
235 device_id = pcm_device_table[usecase][0];
236 else
237 device_id = pcm_device_table[usecase][1];
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800238 return device_id;
239}
240
241static int get_acdb_device_id(snd_device_t snd_device)
242{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700243 return acdb_device_table[snd_device];
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800244}
245
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800246static void add_backend_name(char *mixer_path,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700247 snd_device_t snd_device)
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800248{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700249 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
250 strcat(mixer_path, " bt-sco");
251 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
252 strcat(mixer_path, " bt-sco");
253 else if (snd_device == SND_DEVICE_OUT_HDMI)
254 strcat(mixer_path, " hdmi");
255 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
256 strcat(mixer_path, " speaker-and-hdmi");
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800257}
258
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700259static int enable_audio_route(struct audio_device *adev,
260 struct audio_usecase *usecase,
261 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800262{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700263 snd_device_t snd_device;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800264 char mixer_path[50];
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800265
266 if (usecase == NULL)
267 return -EINVAL;
268
269 ALOGV("%s: enter: usecase(%d)", __func__, usecase->id);
270
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800271 if (usecase->type == PCM_CAPTURE)
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700272 snd_device = usecase->in_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800273 else
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700274 snd_device = usecase->out_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800275
276 strcpy(mixer_path, use_case_table[usecase->id]);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700277 add_backend_name(mixer_path, snd_device);
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800278 ALOGD("%s: apply mixer path: %s", __func__, mixer_path);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700279 audio_route_apply_path(adev->audio_route, mixer_path);
280 if (update_mixer)
281 audio_route_update_mixer(adev->audio_route);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800282
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800283 ALOGV("%s: exit", __func__);
284 return 0;
285}
286
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700287static int disable_audio_route(struct audio_device *adev,
288 struct audio_usecase *usecase,
289 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800290{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700291 snd_device_t snd_device;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800292 char mixer_path[50];
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800293
294 if (usecase == NULL)
295 return -EINVAL;
296
297 ALOGV("%s: enter: usecase(%d)", __func__, usecase->id);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700298 if (usecase->type == PCM_CAPTURE)
299 snd_device = usecase->in_snd_device;
300 else
301 snd_device = usecase->out_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800302 strcpy(mixer_path, use_case_table[usecase->id]);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700303 add_backend_name(mixer_path, snd_device);
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800304 ALOGD("%s: reset mixer path: %s", __func__, mixer_path);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700305 audio_route_reset_path(adev->audio_route, mixer_path);
306 if (update_mixer)
307 audio_route_update_mixer(adev->audio_route);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800308
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800309 ALOGV("%s: exit", __func__);
310 return 0;
311}
312
313static int enable_snd_device(struct audio_device *adev,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700314 snd_device_t snd_device,
315 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800316{
317 int acdb_dev_id, acdb_dev_type;
318
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800319 if (snd_device < SND_DEVICE_MIN ||
320 snd_device >= SND_DEVICE_MAX) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800321 ALOGE("%s: Invalid sound device %d", __func__, snd_device);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800322 return -EINVAL;
323 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700324
325 adev->snd_dev_ref_cnt[snd_device]++;
326 if (adev->snd_dev_ref_cnt[snd_device] > 1) {
327 ALOGD("%s: snd_device(%d: %s) is already active",
328 __func__, snd_device, device_table[snd_device]);
329 return 0;
330 }
331
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800332 acdb_dev_id = get_acdb_device_id(snd_device);
333 if (acdb_dev_id < 0) {
334 ALOGE("%s: Could not find acdb id for device(%d)",
335 __func__, snd_device);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700336 adev->snd_dev_ref_cnt[snd_device]--;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800337 return -EINVAL;
338 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800339 if (adev->acdb_send_audio_cal) {
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -0700340 ALOGD("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800341 __func__, snd_device, acdb_dev_id);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700342 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
343 snd_device < SND_DEVICE_OUT_END)
344 acdb_dev_type = ACDB_DEV_TYPE_OUT;
345 else
346 acdb_dev_type = ACDB_DEV_TYPE_IN;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800347 adev->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
348 } else {
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700349 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800350 __func__, LIB_ACDB_LOADER);
351 }
352
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700353 ALOGD("%s: snd_device(%d: %s)", __func__,
354 snd_device, device_table[snd_device]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800355 audio_route_apply_path(adev->audio_route, device_table[snd_device]);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700356 if (update_mixer)
357 audio_route_update_mixer(adev->audio_route);
358
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800359 return 0;
360}
361
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700362static int disable_snd_device(struct audio_device *adev,
363 snd_device_t snd_device,
364 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800365{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800366 if (snd_device < SND_DEVICE_MIN ||
367 snd_device >= SND_DEVICE_MAX) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800368 ALOGE("%s: Invalid sound device %d", __func__, snd_device);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800369 return -EINVAL;
370 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700371 if (adev->snd_dev_ref_cnt[snd_device] <= 0) {
372 ALOGE("%s: device ref cnt is already 0", __func__);
373 return -EINVAL;
374 }
375 adev->snd_dev_ref_cnt[snd_device]--;
376 if (adev->snd_dev_ref_cnt[snd_device] == 0) {
377 ALOGD("%s: snd_device(%d: %s)", __func__,
378 snd_device, device_table[snd_device]);
379 audio_route_reset_path(adev->audio_route, device_table[snd_device]);
380 if (update_mixer)
381 audio_route_update_mixer(adev->audio_route);
382 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800383 return 0;
384}
385
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700386static void check_usecases_codec_backend(struct audio_device *adev,
387 struct audio_usecase *uc_info,
388 snd_device_t snd_device)
389{
390 struct listnode *node;
391 struct audio_usecase *usecase;
392 bool switch_device[AUDIO_USECASE_MAX];
393 int i, num_uc_to_switch = 0;
394
395 /*
396 * This function is to make sure that all the usecases that are active on
397 * the hardware codec backend are always routed to any one device that is
398 * handled by the hardware codec.
399 * For example, if low-latency and deep-buffer usecases are currently active
400 * on speaker and out_set_parameters(headset) is received on low-latency
401 * output, then we have to make sure deep-buffer is also switched to headset,
402 * because of the limitation that both the devices cannot be enabled
403 * at the same time as they share the same backend.
404 */
405 /* Disable all the usecases on the shared backend other than the
406 specified usecase */
407 for (i = 0; i < AUDIO_USECASE_MAX; i++)
408 switch_device[i] = false;
409
410 list_for_each(node, &adev->usecase_list) {
411 usecase = node_to_item(node, struct audio_usecase, list);
412 if (usecase->type != PCM_CAPTURE &&
413 usecase != uc_info &&
414 usecase->out_snd_device != snd_device &&
415 usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) {
416 ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
417 __func__, use_case_table[usecase->id],
418 device_table[usecase->out_snd_device]);
419 disable_audio_route(adev, usecase, false);
420 switch_device[usecase->id] = true;
421 num_uc_to_switch++;
422 }
423 }
424
425 if (num_uc_to_switch) {
426 /* Make sure all the streams are de-routed before disabling the device */
427 audio_route_update_mixer(adev->audio_route);
428
429 list_for_each(node, &adev->usecase_list) {
430 usecase = node_to_item(node, struct audio_usecase, list);
431 if (switch_device[usecase->id]) {
432 disable_snd_device(adev, usecase->out_snd_device, false);
433 enable_snd_device(adev, snd_device, false);
434 }
435 }
436
437 /* Make sure new snd device is enabled before re-routing the streams */
438 audio_route_update_mixer(adev->audio_route);
439
440 /* Re-route all the usecases on the shared backend other than the
441 specified usecase to new snd devices */
442 list_for_each(node, &adev->usecase_list) {
443 usecase = node_to_item(node, struct audio_usecase, list);
444 /* Update the out_snd_device only before enabling the audio route */
445 if (switch_device[usecase->id] ) {
446 usecase->out_snd_device = snd_device;
447 enable_audio_route(adev, usecase, false);
448 }
449 }
450
451 audio_route_update_mixer(adev->audio_route);
452 }
453}
454
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -0700455static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
456{
457 struct mixer_ctl *ctl;
458 const char *mixer_ctl_name = "EC_REF_RX";
459
460 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
461 if (!ctl) {
462 ALOGE("%s: Could not get ctl for mixer cmd - %s",
463 __func__, mixer_ctl_name);
464 return -EINVAL;
465 }
466 ALOGV("Setting EC Reference: %s", ec_ref);
467 mixer_ctl_set_enum_by_string(ctl, ec_ref);
468 return 0;
469}
470
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800471static int set_hdmi_channels(struct mixer *mixer,
472 int channel_count)
473{
474 struct mixer_ctl *ctl;
475 const char *channel_cnt_str = NULL;
476 const char *mixer_ctl_name = "HDMI_RX Channels";
477 switch (channel_count) {
478 case 8:
479 channel_cnt_str = "Eight"; break;
480 case 7:
481 channel_cnt_str = "Seven"; break;
482 case 6:
483 channel_cnt_str = "Six"; break;
484 case 5:
485 channel_cnt_str = "Five"; break;
486 case 4:
487 channel_cnt_str = "Four"; break;
488 case 3:
489 channel_cnt_str = "Three"; break;
490 default:
491 channel_cnt_str = "Two"; break;
492 }
493 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
494 if (!ctl) {
495 ALOGE("%s: Could not get ctl for mixer cmd - %s",
496 __func__, mixer_ctl_name);
497 return -EINVAL;
498 }
499 ALOGV("HDMI channel count: %s", channel_cnt_str);
500 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
501 return 0;
502}
503
504/* must be called with hw device mutex locked */
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700505static int read_hdmi_channel_masks(struct stream_out *out)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800506{
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700507 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800508 int channels = edid_get_max_channels();
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800509
510 switch (channels) {
511 /*
512 * Do not handle stereo output in Multi-channel cases
513 * Stereo case is handled in normal playback path
514 */
515 case 6:
516 ALOGV("%s: HDMI supports 5.1", __func__);
517 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
518 break;
519 case 8:
520 ALOGV("%s: HDMI supports 5.1 and 7.1 channels", __func__);
521 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
522 out->supported_channel_masks[1] = AUDIO_CHANNEL_OUT_7POINT1;
523 break;
524 default:
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700525 ALOGE("HDMI does not support multi channel playback");
526 ret = -ENOSYS;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800527 break;
528 }
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700529 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800530}
531
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -0700532static int set_voice_volume(struct mixer *mixer,
533 int volume)
534{
535 struct mixer_ctl *ctl;
536 const char *mixer_ctl_name = "Voice Rx Volume";
sangwoofbf5d512013-05-20 11:38:45 +0900537
538 // Voice volume levels are mapped to adsp volume levels as follows.
539 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
540 // But this values don't changed in kernel. So, below change is need.
541 volume = volume / 20;
542
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -0700543 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
544 if (!ctl) {
545 ALOGE("%s: Could not get ctl for mixer cmd - %s",
546 __func__, mixer_ctl_name);
547 return -EINVAL;
548 }
549 ALOGV("Setting voice volume: %d", volume);
550 mixer_ctl_set_value(ctl, 0, volume);
551 return 0;
552}
553
554static int set_mic_mute(struct mixer *mixer,
555 int mute)
556{
557 struct mixer_ctl *ctl;
558 const char *mixer_ctl_name = "Voice Tx Mute";
559 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
560 if (!ctl) {
561 ALOGE("%s: Could not get ctl for mixer cmd - %s",
562 __func__, mixer_ctl_name);
563 return -EINVAL;
564 }
565 ALOGV("Setting mic mute: %d", mute);
566 mixer_ctl_set_value(ctl, 0, mute);
567 return 0;
568}
569
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700570static snd_device_t get_output_snd_device(struct audio_device *adev,
571 audio_devices_t devices)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800572{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700573 audio_mode_t mode = adev->mode;
574 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800575
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800576 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800577 if (devices == AUDIO_DEVICE_NONE ||
578 devices & AUDIO_DEVICE_BIT_IN) {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800579 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800580 goto exit;
581 }
582
583 if (mode == AUDIO_MODE_IN_CALL) {
584 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
585 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800586 if (adev->tty_mode == TTY_MODE_FULL)
587 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
588 else if (adev->tty_mode == TTY_MODE_VCO)
589 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
590 else if (adev->tty_mode == TTY_MODE_HCO)
591 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
592 else
593 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800594 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
595 snd_device = SND_DEVICE_OUT_BT_SCO;
596 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
597 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
598 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamanda37718842013-02-22 18:44:45 -0800599 if (is_operator_tmus())
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800600 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
601 else
602 snd_device = SND_DEVICE_OUT_HANDSET;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800603 }
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800604 if (snd_device != SND_DEVICE_NONE) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800605 goto exit;
606 }
607 }
608
609 if (popcount(devices) == 2) {
610 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
611 AUDIO_DEVICE_OUT_SPEAKER)) {
612 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
613 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
614 AUDIO_DEVICE_OUT_SPEAKER)) {
615 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
616 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
617 AUDIO_DEVICE_OUT_SPEAKER)) {
618 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
619 } else {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800620 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800621 goto exit;
622 }
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800623 if (snd_device != SND_DEVICE_NONE) {
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800624 goto exit;
625 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800626 }
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800627
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800628 if (popcount(devices) != 1) {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800629 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800630 goto exit;
631 }
632
633 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
634 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
635 snd_device = SND_DEVICE_OUT_HEADPHONES;
636 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Jean-Michel Trivic56336b2013-05-24 16:55:17 -0700637 if (adev->speaker_lr_swap) {
638 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
639 } else {
640 snd_device = SND_DEVICE_OUT_SPEAKER;
641 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800642 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
643 snd_device = SND_DEVICE_OUT_BT_SCO;
644 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
645 snd_device = SND_DEVICE_OUT_HDMI ;
646 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
647 snd_device = SND_DEVICE_OUT_HANDSET;
648 } else {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800649 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800650 }
651exit:
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800652 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800653 return snd_device;
654}
655
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700656static snd_device_t get_input_snd_device(struct audio_device *adev,
657 audio_devices_t out_device)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800658{
Eric Laurentc8400632013-02-14 19:04:54 -0800659 audio_source_t source = (adev->active_input == NULL) ?
660 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
661
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800662 audio_mode_t mode = adev->mode;
Eric Laurentc8400632013-02-14 19:04:54 -0800663 audio_devices_t in_device = ((adev->active_input == NULL) ?
664 AUDIO_DEVICE_NONE : adev->active_input->device)
665 & ~AUDIO_DEVICE_BIT_IN;
666 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
667 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800668 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800669
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800670 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800671 __func__, out_device, in_device);
672 if (mode == AUDIO_MODE_IN_CALL) {
673 if (out_device == AUDIO_DEVICE_NONE) {
674 ALOGE("%s: No output device set for voice call", __func__);
675 goto exit;
676 }
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800677 if (adev->tty_mode != TTY_MODE_OFF) {
678 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
679 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
680 switch (adev->tty_mode) {
681 case TTY_MODE_FULL:
682 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
683 break;
684 case TTY_MODE_VCO:
685 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
686 break;
687 case TTY_MODE_HCO:
688 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
689 break;
690 default:
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800691 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->tty_mode);
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800692 }
693 goto exit;
694 }
695 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800696 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
697 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800698 if (adev->mic_type_analog || adev->fluence_in_voice_call == false) {
699 snd_device = SND_DEVICE_IN_HANDSET_MIC;
700 } else {
701 if (adev->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
Ravi Kumar Alamanda37718842013-02-22 18:44:45 -0800702 if (is_operator_tmus())
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800703 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS;
704 else
705 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF;
706 } else if(adev->dualmic_config == DUALMIC_CONFIG_BROADSIDE)
707 snd_device = SND_DEVICE_IN_VOICE_DMIC_BS;
708 else
709 snd_device = SND_DEVICE_IN_HANDSET_MIC;
710 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800711 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
712 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
713 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
714 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
715 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda02317792013-03-04 20:56:50 -0800716 if (adev->fluence_in_voice_call && adev->fluence_in_spkr_mode &&
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800717 adev->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
718 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF;
Ravi Kumar Alamanda02317792013-03-04 20:56:50 -0800719 } else if (adev->fluence_in_voice_call && adev->fluence_in_spkr_mode &&
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800720 adev->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
721 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS;
722 } else {
723 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
724 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800725 }
726 } else if (source == AUDIO_SOURCE_CAMCORDER) {
727 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
728 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
729 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
730 }
731 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
732 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Eric Laurentc8400632013-02-14 19:04:54 -0800733 if (adev->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
734 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
735 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF;
736 else if (adev->fluence_in_voice_rec)
737 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE;
Eric Laurentc8400632013-02-14 19:04:54 -0800738 } else if (adev->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
739 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
740 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS;
741 else if (adev->fluence_in_voice_rec)
742 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE;
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -0700743 }
744
745 if (snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800746 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -0700747 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800748 }
Ravi Kumar Alamanda8455fa72013-02-19 14:53:19 -0800749 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
750 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
751 in_device = AUDIO_DEVICE_IN_BACK_MIC;
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -0700752 if (adev->active_input) {
753 if (adev->active_input->enable_aec) {
754 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
755 if (adev->mic_type_analog)
756 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
757 else
758 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
759 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
760 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
761 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
762 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
763 }
764 set_echo_reference(adev->mixer, "SLIM_RX");
765 } else
766 set_echo_reference(adev->mixer, "NONE");
767 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800768 } else if (source == AUDIO_SOURCE_DEFAULT) {
769 goto exit;
770 }
771
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -0700772
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800773 if (snd_device != SND_DEVICE_NONE) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800774 goto exit;
775 }
776
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800777 if (in_device != AUDIO_DEVICE_NONE &&
Ravi Kumar Alamanda8455fa72013-02-19 14:53:19 -0800778 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
779 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800780 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800781 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800782 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800783 if (adev->mic_type_analog)
784 snd_device = SND_DEVICE_IN_HANDSET_MIC;
785 else
786 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800787 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
788 snd_device = SND_DEVICE_IN_HEADSET_MIC;
789 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
790 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
791 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
792 snd_device = SND_DEVICE_IN_HDMI_MIC;
793 } else {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800794 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800795 ALOGW("%s: Using default handset-mic", __func__);
796 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800797 }
798 } else {
799 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800800 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800801 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
802 snd_device = SND_DEVICE_IN_HEADSET_MIC;
803 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
804 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
805 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800806 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800807 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800808 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800809 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
810 snd_device = SND_DEVICE_IN_HDMI_MIC;
811 } else {
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800812 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -0800813 ALOGW("%s: Using default handset-mic", __func__);
814 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800815 }
816 }
817exit:
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800818 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800819 return snd_device;
820}
821
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700822static struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
823 audio_usecase_t uc_id)
824{
825 struct audio_usecase *usecase;
826 struct listnode *node;
827
828 list_for_each(node, &adev->usecase_list) {
829 usecase = node_to_item(node, struct audio_usecase, list);
830 if (usecase->id == uc_id)
831 return usecase;
832 }
833 return NULL;
834}
835
836static int select_devices(struct audio_device *adev,
837 audio_usecase_t uc_id)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800838{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800839 snd_device_t out_snd_device = SND_DEVICE_NONE;
840 snd_device_t in_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700841 struct audio_usecase *usecase = NULL;
842 struct audio_usecase *vc_usecase = NULL;
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800843 struct listnode *node;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800844 int acdb_rx_id, acdb_tx_id;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700845 int status = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800846
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700847 usecase = get_usecase_from_list(adev, uc_id);
848 if (usecase == NULL) {
849 ALOGE("%s: Could not find the usecase(%d)", __func__, uc_id);
850 return -EINVAL;
851 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800852
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700853 if (usecase->type == VOICE_CALL) {
854 out_snd_device = get_output_snd_device(adev, usecase->stream.out->devices);
855 in_snd_device = get_input_snd_device(adev, usecase->stream.out->devices);
856 usecase->devices = usecase->stream.out->devices;
857 } else {
858 /*
859 * If the voice call is active, use the sound devices of voice call usecase
860 * so that it would not result any device switch. All the usecases will
861 * be switched to new device when select_devices() is called for voice call
862 * usecase. This is to avoid switching devices for voice call when
863 * check_usecases_codec_backend() is called below.
864 */
865 if (adev->in_call) {
866 vc_usecase = get_usecase_from_list(adev, USECASE_VOICE_CALL);
867 if (vc_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) {
868 in_snd_device = vc_usecase->in_snd_device;
869 out_snd_device = vc_usecase->out_snd_device;
870 }
871 }
872 if (usecase->type == PCM_PLAYBACK) {
873 usecase->devices = usecase->stream.out->devices;
874 in_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700875 if (out_snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700876 out_snd_device = get_output_snd_device(adev,
877 usecase->stream.out->devices);
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700878 if (usecase->stream.out == adev->primary_output &&
879 adev->active_input &&
880 adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
881 select_devices(adev, adev->active_input->usecase);
882 }
883 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700884 } else if (usecase->type == PCM_CAPTURE) {
885 usecase->devices = usecase->stream.in->device;
886 out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700887 if (in_snd_device == SND_DEVICE_NONE) {
888 if (adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION &&
889 adev->primary_output && !adev->primary_output->standby) {
890 in_snd_device = get_input_snd_device(adev,
891 adev->primary_output->devices);
892 } else {
893 in_snd_device = get_input_snd_device(adev, AUDIO_DEVICE_NONE);
894 }
895 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700896 }
897 }
898
899 if (out_snd_device == usecase->out_snd_device &&
900 in_snd_device == usecase->in_snd_device) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800901 return 0;
902 }
903
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800904 ALOGD("%s: out_snd_device(%d: %s) in_snd_device(%d: %s)", __func__,
905 out_snd_device, device_table[out_snd_device],
906 in_snd_device, device_table[in_snd_device]);
907
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800908 /*
909 * Limitation: While in call, to do a device switch we need to disable
910 * and enable both RX and TX devices though one of them is same as current
911 * device.
912 */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700913 if (usecase->type == VOICE_CALL && adev->csd_client != NULL &&
914 usecase->in_snd_device != SND_DEVICE_NONE &&
915 usecase->out_snd_device != SND_DEVICE_NONE) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800916 /* This must be called before disabling the mixer controls on APQ side */
917 if (adev->csd_disable_device == NULL) {
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800918 ALOGE("%s: dlsym error for csd_client_disable_device", __func__);
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800919 } else {
920 status = adev->csd_disable_device();
921 if (status < 0) {
922 ALOGE("%s: csd_client_disable_device, failed, error %d",
923 __func__, status);
924 }
925 }
926 }
927
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700928 /* Disable current sound devices */
929 if (usecase->out_snd_device != SND_DEVICE_NONE) {
930 disable_audio_route(adev, usecase, true);
931 disable_snd_device(adev, usecase->out_snd_device, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800932 }
933
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700934 if (usecase->in_snd_device != SND_DEVICE_NONE) {
935 disable_audio_route(adev, usecase, true);
936 disable_snd_device(adev, usecase->in_snd_device, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800937 }
938
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700939 /* Enable new sound devices */
940 if (out_snd_device != SND_DEVICE_NONE) {
941 if (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)
942 check_usecases_codec_backend(adev, usecase, out_snd_device);
943 enable_snd_device(adev, out_snd_device, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800944 }
945
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700946 if (in_snd_device != SND_DEVICE_NONE)
947 enable_snd_device(adev, in_snd_device, false);
948
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800949 audio_route_update_mixer(adev->audio_route);
950
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700951 usecase->in_snd_device = in_snd_device;
952 usecase->out_snd_device = out_snd_device;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800953
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700954 enable_audio_route(adev, usecase, true);
955
956 if (usecase->type == VOICE_CALL && adev->csd_client) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800957 if (adev->csd_enable_device == NULL) {
958 ALOGE("%s: dlsym error for csd_client_enable_device",
959 __func__);
960 } else {
961 acdb_rx_id = get_acdb_device_id(out_snd_device);
962 acdb_tx_id = get_acdb_device_id(in_snd_device);
963
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700964 if (acdb_rx_id > 0 || acdb_tx_id > 0) {
965 status = adev->csd_enable_device(acdb_rx_id, acdb_tx_id,
966 adev->acdb_settings);
967 if (status < 0) {
968 ALOGE("%s: csd_client_enable_device, failed, error %d",
969 __func__, status);
970 }
971 } else {
972 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
973 acdb_rx_id, acdb_tx_id);
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800974 }
975 }
sangwoofbf5d512013-05-20 11:38:45 +0900976 } else if (usecase->type == VOICE_CALL) {
977 if (adev->acdb_send_voice_cal == NULL) {
978 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
979 } else {
980 acdb_rx_id = get_acdb_device_id(out_snd_device);
981 acdb_tx_id = get_acdb_device_id(in_snd_device);
982
983 if (acdb_rx_id > 0 && acdb_tx_id > 0)
984 adev->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
985 else
986 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
987 acdb_rx_id, acdb_tx_id);
988 }
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800989 }
990
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800991 return status;
992}
993
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800994static int stop_input_stream(struct stream_in *in)
995{
996 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800997 struct audio_usecase *uc_info;
998 struct audio_device *adev = in->dev;
999
Eric Laurentc8400632013-02-14 19:04:54 -08001000 adev->active_input = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001001
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001002 ALOGD("%s: enter: usecase(%d: %s)", __func__,
1003 in->usecase, use_case_table[in->usecase]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001004 uc_info = get_usecase_from_list(adev, in->usecase);
1005 if (uc_info == NULL) {
1006 ALOGE("%s: Could not find the usecase (%d) in the list",
1007 __func__, in->usecase);
1008 return -EINVAL;
1009 }
1010
Eric Laurent150dbfe2013-02-27 14:31:02 -08001011 /* 1. Disable stream specific mixer controls */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001012 disable_audio_route(adev, uc_info, true);
1013
1014 /* 2. Disable the tx device */
1015 disable_snd_device(adev, uc_info->in_snd_device, true);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001016
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08001017 list_remove(&uc_info->list);
1018 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001019
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001020 ALOGD("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001021 return ret;
1022}
1023
1024int start_input_stream(struct stream_in *in)
1025{
1026 /* 1. Enable output device and stream routing controls */
Eric Laurentc8400632013-02-14 19:04:54 -08001027 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001028 struct audio_usecase *uc_info;
1029 struct audio_device *adev = in->dev;
1030
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001031 ALOGD("%s: enter: usecase(%d)", __func__, in->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001032 in->pcm_device_id = get_pcm_device_id(adev->audio_route,
1033 in->usecase,
1034 PCM_CAPTURE);
1035 if (in->pcm_device_id < 0) {
1036 ALOGE("%s: Could not find PCM device id for the usecase(%d)",
1037 __func__, in->usecase);
Eric Laurentc8400632013-02-14 19:04:54 -08001038 ret = -EINVAL;
1039 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001040 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001041
1042 adev->active_input = in;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001043 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
1044 uc_info->id = in->usecase;
1045 uc_info->type = PCM_CAPTURE;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001046 uc_info->stream.in = in;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001047 uc_info->devices = in->device;
1048 uc_info->in_snd_device = SND_DEVICE_NONE;
1049 uc_info->out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001050
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08001051 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001052 select_devices(adev, in->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001053
Eric Laurentc8400632013-02-14 19:04:54 -08001054 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d), channels %d",
1055 __func__, SOUND_CARD, in->pcm_device_id, in->config.channels);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001056 in->pcm = pcm_open(SOUND_CARD, in->pcm_device_id,
1057 PCM_IN, &in->config);
1058 if (in->pcm && !pcm_is_ready(in->pcm)) {
1059 ALOGE("%s: %s", __func__, pcm_get_error(in->pcm));
1060 pcm_close(in->pcm);
1061 in->pcm = NULL;
Eric Laurentc8400632013-02-14 19:04:54 -08001062 ret = -EIO;
1063 goto error_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001064 }
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001065 ALOGD("%s: exit", __func__);
Eric Laurentc8400632013-02-14 19:04:54 -08001066 return ret;
1067
1068error_open:
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001069 stop_input_stream(in);
Eric Laurentc8400632013-02-14 19:04:54 -08001070
1071error_config:
1072 adev->active_input = NULL;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001073 ALOGD("%s: exit: status(%d)", __func__, ret);
Eric Laurentc8400632013-02-14 19:04:54 -08001074
1075 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001076}
1077
1078static int stop_output_stream(struct stream_out *out)
1079{
1080 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001081 struct audio_usecase *uc_info;
1082 struct audio_device *adev = out->dev;
1083
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001084 ALOGD("%s: enter: usecase(%d: %s)", __func__,
1085 out->usecase, use_case_table[out->usecase]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001086 uc_info = get_usecase_from_list(adev, out->usecase);
1087 if (uc_info == NULL) {
1088 ALOGE("%s: Could not find the usecase (%d) in the list",
1089 __func__, out->usecase);
1090 return -EINVAL;
1091 }
1092
Eric Laurent150dbfe2013-02-27 14:31:02 -08001093 /* 1. Get and set stream specific mixer controls */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001094 disable_audio_route(adev, uc_info, true);
1095
1096 /* 2. Disable the rx device */
1097 disable_snd_device(adev, uc_info->out_snd_device, true);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001098
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08001099 list_remove(&uc_info->list);
1100 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001101
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001102 ALOGD("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001103 return ret;
1104}
1105
1106int start_output_stream(struct stream_out *out)
1107{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001108 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001109 struct audio_usecase *uc_info;
1110 struct audio_device *adev = out->dev;
1111
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001112 ALOGD("%s: enter: usecase(%d: %s) devices(%#x)",
1113 __func__, out->usecase, use_case_table[out->usecase], out->devices);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001114 out->pcm_device_id = get_pcm_device_id(adev->audio_route,
1115 out->usecase,
1116 PCM_PLAYBACK);
1117 if (out->pcm_device_id < 0) {
1118 ALOGE("%s: Invalid PCM device id(%d) for the usecase(%d)",
1119 __func__, out->pcm_device_id, out->usecase);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001120 ret = -EINVAL;
1121 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001122 }
1123
1124 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
1125 uc_info->id = out->usecase;
1126 uc_info->type = PCM_PLAYBACK;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001127 uc_info->stream.out = out;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001128 uc_info->devices = out->devices;
1129 uc_info->in_snd_device = SND_DEVICE_NONE;
1130 uc_info->out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001131
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08001132 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001133
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001134 select_devices(adev, out->usecase);
1135
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001136 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d)",
1137 __func__, 0, out->pcm_device_id);
1138 out->pcm = pcm_open(SOUND_CARD, out->pcm_device_id,
1139 PCM_OUT, &out->config);
1140 if (out->pcm && !pcm_is_ready(out->pcm)) {
1141 ALOGE("%s: %s", __func__, pcm_get_error(out->pcm));
1142 pcm_close(out->pcm);
1143 out->pcm = NULL;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001144 ret = -EIO;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001145 goto error_pcm_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001146 }
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001147 ALOGD("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001148 return 0;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001149error_pcm_open:
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001150 stop_output_stream(out);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001151error_config:
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001152 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001153}
1154
1155static int stop_voice_call(struct audio_device *adev)
1156{
1157 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001158 struct audio_usecase *uc_info;
1159
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001160 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001161 adev->in_call = false;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001162 if (adev->csd_client) {
1163 if (adev->csd_stop_voice == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08001164 ALOGE("dlsym error for csd_client_disable_device");
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001165 } else {
1166 ret = adev->csd_stop_voice();
1167 if (ret < 0) {
1168 ALOGE("%s: csd_client error %d\n", __func__, ret);
1169 }
1170 }
1171 }
1172
1173 /* 1. Close the PCM devices */
1174 if (adev->voice_call_rx) {
1175 pcm_close(adev->voice_call_rx);
1176 adev->voice_call_rx = NULL;
1177 }
1178 if (adev->voice_call_tx) {
1179 pcm_close(adev->voice_call_tx);
1180 adev->voice_call_tx = NULL;
1181 }
1182
1183 uc_info = get_usecase_from_list(adev, USECASE_VOICE_CALL);
1184 if (uc_info == NULL) {
1185 ALOGE("%s: Could not find the usecase (%d) in the list",
1186 __func__, USECASE_VOICE_CALL);
1187 return -EINVAL;
1188 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001189
1190 /* 2. Get and set stream specific mixer controls */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001191 disable_audio_route(adev, uc_info, true);
1192
1193 /* 3. Disable the rx and tx devices */
1194 disable_snd_device(adev, uc_info->out_snd_device, false);
1195 disable_snd_device(adev, uc_info->in_snd_device, true);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001196
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08001197 list_remove(&uc_info->list);
1198 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001199
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001200 ALOGD("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001201 return ret;
1202}
1203
1204static int start_voice_call(struct audio_device *adev)
1205{
1206 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001207 struct audio_usecase *uc_info;
1208 int pcm_dev_rx_id, pcm_dev_tx_id;
1209
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001210 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001211
1212 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
1213 uc_info->id = USECASE_VOICE_CALL;
1214 uc_info->type = VOICE_CALL;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001215 uc_info->stream.out = adev->primary_output;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001216 uc_info->devices = adev->primary_output->devices;
1217 uc_info->in_snd_device = SND_DEVICE_NONE;
1218 uc_info->out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001219
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08001220 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001221
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001222 select_devices(adev, USECASE_VOICE_CALL);
1223
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001224 pcm_dev_rx_id = get_pcm_device_id(adev->audio_route, uc_info->id,
1225 PCM_PLAYBACK);
1226 pcm_dev_tx_id = get_pcm_device_id(adev->audio_route, uc_info->id,
1227 PCM_CAPTURE);
1228
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001229 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
1230 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
1231 __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001232 ret = -EIO;
1233 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001234 }
1235
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001236 ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001237 __func__, SOUND_CARD, pcm_dev_rx_id);
1238 adev->voice_call_rx = pcm_open(SOUND_CARD,
1239 pcm_dev_rx_id,
1240 PCM_OUT, &pcm_config_voice_call);
1241 if (adev->voice_call_rx && !pcm_is_ready(adev->voice_call_rx)) {
1242 ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_rx));
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001243 ret = -EIO;
1244 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001245 }
1246
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001247 ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001248 __func__, SOUND_CARD, pcm_dev_tx_id);
1249 adev->voice_call_tx = pcm_open(SOUND_CARD,
1250 pcm_dev_tx_id,
1251 PCM_IN, &pcm_config_voice_call);
1252 if (adev->voice_call_tx && !pcm_is_ready(adev->voice_call_tx)) {
1253 ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_tx));
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001254 ret = -EIO;
1255 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001256 }
1257 pcm_start(adev->voice_call_rx);
1258 pcm_start(adev->voice_call_tx);
1259
1260 if (adev->csd_client) {
1261 if (adev->csd_start_voice == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08001262 ALOGE("dlsym error for csd_client_start_voice");
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001263 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001264 } else {
1265 ret = adev->csd_start_voice();
1266 if (ret < 0) {
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001267 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1268 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001269 }
1270 }
1271 }
1272
1273 adev->in_call = true;
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -08001274 return 0;
1275
1276error_start_voice:
1277 stop_voice_call(adev);
1278
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001279 ALOGD("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001280 return ret;
1281}
1282
1283static int check_input_parameters(uint32_t sample_rate,
1284 audio_format_t format,
1285 int channel_count)
1286{
1287 if (format != AUDIO_FORMAT_PCM_16_BIT) return -EINVAL;
1288
1289 if ((channel_count < 1) || (channel_count > 2)) return -EINVAL;
1290
1291 switch (sample_rate) {
1292 case 8000:
1293 case 11025:
1294 case 12000:
1295 case 16000:
1296 case 22050:
1297 case 24000:
1298 case 32000:
1299 case 44100:
1300 case 48000:
1301 break;
1302 default:
1303 return -EINVAL;
1304 }
1305
1306 return 0;
1307}
1308
1309static size_t get_input_buffer_size(uint32_t sample_rate,
1310 audio_format_t format,
1311 int channel_count)
1312{
1313 size_t size = 0;
1314
1315 if (check_input_parameters(sample_rate, format, channel_count) != 0) return 0;
1316
1317 if (sample_rate == 8000 || sample_rate == 16000 || sample_rate == 32000) {
1318 size = (sample_rate * 20) / 1000;
1319 } else if (sample_rate == 11025 || sample_rate == 12000) {
1320 size = 256;
1321 } else if (sample_rate == 22050 || sample_rate == 24000) {
1322 size = 512;
1323 } else if (sample_rate == 44100 || sample_rate == 48000) {
1324 size = 1024;
1325 }
1326
1327 return size * sizeof(short) * channel_count;
1328}
1329
1330static uint32_t out_get_sample_rate(const struct audio_stream *stream)
1331{
1332 struct stream_out *out = (struct stream_out *)stream;
1333
1334 return out->config.rate;
1335}
1336
1337static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
1338{
1339 return -ENOSYS;
1340}
1341
1342static size_t out_get_buffer_size(const struct audio_stream *stream)
1343{
1344 struct stream_out *out = (struct stream_out *)stream;
1345
1346 return out->config.period_size * audio_stream_frame_size(stream);
1347}
1348
1349static uint32_t out_get_channels(const struct audio_stream *stream)
1350{
1351 struct stream_out *out = (struct stream_out *)stream;
1352
1353 return out->channel_mask;
1354}
1355
1356static audio_format_t out_get_format(const struct audio_stream *stream)
1357{
1358 return AUDIO_FORMAT_PCM_16_BIT;
1359}
1360
1361static int out_set_format(struct audio_stream *stream, audio_format_t format)
1362{
1363 return -ENOSYS;
1364}
1365
1366static int out_standby(struct audio_stream *stream)
1367{
1368 struct stream_out *out = (struct stream_out *)stream;
1369 struct audio_device *adev = out->dev;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001370 ALOGD("%s: enter: usecase(%d: %s)", __func__,
1371 out->usecase, use_case_table[out->usecase]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001372 pthread_mutex_lock(&out->lock);
1373
1374 if (!out->standby) {
1375 out->standby = true;
Eric Laurent150dbfe2013-02-27 14:31:02 -08001376 if (out->pcm) {
1377 pcm_close(out->pcm);
1378 out->pcm = NULL;
1379 }
1380 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001381 stop_output_stream(out);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001382 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001383 }
1384 pthread_mutex_unlock(&out->lock);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001385 ALOGD("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001386 return 0;
1387}
1388
1389static int out_dump(const struct audio_stream *stream, int fd)
1390{
1391 return 0;
1392}
1393
1394static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
1395{
1396 struct stream_out *out = (struct stream_out *)stream;
1397 struct audio_device *adev = out->dev;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001398 struct audio_usecase *usecase;
1399 struct listnode *node;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001400 struct str_parms *parms;
1401 char value[32];
1402 int ret, val = 0;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001403 bool select_new_device = false;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001404
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001405 ALOGD("%s: enter: usecase(%d: %s) kvpairs: %s",
1406 __func__, out->usecase, use_case_table[out->usecase], kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001407 parms = str_parms_create_str(kvpairs);
1408 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
1409 if (ret >= 0) {
1410 val = atoi(value);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001411 pthread_mutex_lock(&out->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001412 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001413
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001414 /*
1415 * When HDMI cable is unplugged the music playback is paused and
1416 * the policy manager sends routing=0. But the audioflinger
1417 * continues to write data until standby time (3sec).
1418 * As the HDMI core is turned off, the write gets blocked.
1419 * Avoid this by routing audio to speaker until standby.
1420 */
1421 if (out->devices == AUDIO_DEVICE_OUT_AUX_DIGITAL &&
1422 val == AUDIO_DEVICE_NONE) {
1423 val = AUDIO_DEVICE_OUT_SPEAKER;
1424 }
1425
1426 /*
1427 * select_devices() call below switches all the usecases on the same
1428 * backend to the new device. Refer to check_usecases_codec_backend() in
1429 * the select_devices(). But how do we undo this?
1430 *
1431 * For example, music playback is active on headset (deep-buffer usecase)
1432 * and if we go to ringtones and select a ringtone, low-latency usecase
1433 * will be started on headset+speaker. As we can't enable headset+speaker
1434 * and headset devices at the same time, select_devices() switches the music
1435 * playback to headset+speaker while starting low-lateny usecase for ringtone.
1436 * So when the ringtone playback is completed, how do we undo the same?
1437 *
1438 * We are relying on the out_set_parameters() call on deep-buffer output,
1439 * once the ringtone playback is ended.
1440 * NOTE: We should not check if the current devices are same as new devices.
1441 * Because select_devices() must be called to switch back the music
1442 * playback to headset.
1443 */
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001444 if (val != 0) {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001445 out->devices = val;
1446
1447 if (!out->standby)
1448 select_devices(adev, out->usecase);
1449
1450 if ((adev->mode == AUDIO_MODE_IN_CALL) && !adev->in_call &&
1451 (out == adev->primary_output)) {
1452 start_voice_call(adev);
1453 } else if ((adev->mode == AUDIO_MODE_IN_CALL) && adev->in_call &&
1454 (out == adev->primary_output)) {
1455 select_devices(adev, USECASE_VOICE_CALL);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001456 }
1457 }
1458
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001459 if ((adev->mode != AUDIO_MODE_IN_CALL) && adev->in_call &&
1460 (out == adev->primary_output)) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001461 stop_voice_call(adev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001462 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001463
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001464 pthread_mutex_unlock(&adev->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001465 pthread_mutex_unlock(&out->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001466 }
1467 str_parms_destroy(parms);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001468 ALOGD("%s: exit: code(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001469 return ret;
1470}
1471
1472static char* out_get_parameters(const struct audio_stream *stream, const char *keys)
1473{
1474 struct stream_out *out = (struct stream_out *)stream;
1475 struct str_parms *query = str_parms_create_str(keys);
1476 char *str;
1477 char value[256];
1478 struct str_parms *reply = str_parms_create();
1479 size_t i, j;
1480 int ret;
1481 bool first = true;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001482 ALOGD("%s: enter: keys - %s", __func__, keys);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001483 ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value, sizeof(value));
1484 if (ret >= 0) {
1485 value[0] = '\0';
1486 i = 0;
1487 while (out->supported_channel_masks[i] != 0) {
1488 for (j = 0; j < ARRAY_SIZE(out_channels_name_to_enum_table); j++) {
1489 if (out_channels_name_to_enum_table[j].value == out->supported_channel_masks[i]) {
1490 if (!first) {
1491 strcat(value, "|");
1492 }
1493 strcat(value, out_channels_name_to_enum_table[j].name);
1494 first = false;
1495 break;
1496 }
1497 }
1498 i++;
1499 }
1500 str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value);
1501 str = str_parms_to_str(reply);
1502 } else {
1503 str = strdup(keys);
1504 }
1505 str_parms_destroy(query);
1506 str_parms_destroy(reply);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001507 ALOGD("%s: exit: returns - %s", __func__, str);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001508 return str;
1509}
1510
1511static uint32_t out_get_latency(const struct audio_stream_out *stream)
1512{
1513 struct stream_out *out = (struct stream_out *)stream;
1514
1515 return (out->config.period_count * out->config.period_size * 1000) / (out->config.rate);
1516}
1517
1518static int out_set_volume(struct audio_stream_out *stream, float left,
1519 float right)
1520{
Eric Laurenta9024de2013-04-04 09:19:12 -07001521 struct stream_out *out = (struct stream_out *)stream;
1522 if (out->usecase == USECASE_AUDIO_PLAYBACK_MULTI_CH) {
1523 /* only take left channel into account: the API is for stereo anyway */
1524 out->muted = (left == 0.0f);
1525 return 0;
1526 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001527 return -ENOSYS;
1528}
1529
1530static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
1531 size_t bytes)
1532{
1533 struct stream_out *out = (struct stream_out *)stream;
1534 struct audio_device *adev = out->dev;
1535 int i, ret = -1;
1536
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001537 pthread_mutex_lock(&out->lock);
1538 if (out->standby) {
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -07001539 out->standby = false;
Eric Laurent150dbfe2013-02-27 14:31:02 -08001540 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001541 ret = start_output_stream(out);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001542 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001543 if (ret != 0) {
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -07001544 out->standby = true;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001545 goto exit;
1546 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001547 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001548
1549 if (out->pcm) {
Eric Laurenta9024de2013-04-04 09:19:12 -07001550 if (out->muted)
1551 memset((void *)buffer, 0, bytes);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001552 //ALOGV("%s: writing buffer (%d bytes) to pcm device", __func__, bytes);
1553 ret = pcm_write(out->pcm, (void *)buffer, bytes);
1554 }
1555
1556exit:
1557 pthread_mutex_unlock(&out->lock);
1558
1559 if (ret != 0) {
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001560 if (out->pcm)
1561 ALOGE("%s: error %d - %s", __func__, ret, pcm_get_error(out->pcm));
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001562 out_standby(&out->stream.common);
1563 usleep(bytes * 1000000 / audio_stream_frame_size(&out->stream.common) /
1564 out_get_sample_rate(&out->stream.common));
1565 }
1566 return bytes;
1567}
1568
1569static int out_get_render_position(const struct audio_stream_out *stream,
1570 uint32_t *dsp_frames)
1571{
1572 return -EINVAL;
1573}
1574
1575static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1576{
1577 return 0;
1578}
1579
1580static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1581{
1582 return 0;
1583}
1584
1585static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
1586 int64_t *timestamp)
1587{
1588 return -EINVAL;
1589}
1590
1591/** audio_stream_in implementation **/
1592static uint32_t in_get_sample_rate(const struct audio_stream *stream)
1593{
1594 struct stream_in *in = (struct stream_in *)stream;
1595
1596 return in->config.rate;
1597}
1598
1599static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
1600{
1601 return -ENOSYS;
1602}
1603
1604static size_t in_get_buffer_size(const struct audio_stream *stream)
1605{
1606 struct stream_in *in = (struct stream_in *)stream;
1607
1608 return in->config.period_size * audio_stream_frame_size(stream);
1609}
1610
1611static uint32_t in_get_channels(const struct audio_stream *stream)
1612{
1613 struct stream_in *in = (struct stream_in *)stream;
1614
1615 return in->channel_mask;
1616}
1617
1618static audio_format_t in_get_format(const struct audio_stream *stream)
1619{
1620 return AUDIO_FORMAT_PCM_16_BIT;
1621}
1622
1623static int in_set_format(struct audio_stream *stream, audio_format_t format)
1624{
1625 return -ENOSYS;
1626}
1627
1628static int in_standby(struct audio_stream *stream)
1629{
1630 struct stream_in *in = (struct stream_in *)stream;
1631 struct audio_device *adev = in->dev;
1632 int status = 0;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001633 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001634 pthread_mutex_lock(&in->lock);
1635 if (!in->standby) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001636 in->standby = true;
Eric Laurent150dbfe2013-02-27 14:31:02 -08001637 if (in->pcm) {
1638 pcm_close(in->pcm);
1639 in->pcm = NULL;
1640 }
1641 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001642 status = stop_input_stream(in);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001643 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001644 }
1645 pthread_mutex_unlock(&in->lock);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001646 ALOGD("%s: exit: status(%d)", __func__, status);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001647 return status;
1648}
1649
1650static int in_dump(const struct audio_stream *stream, int fd)
1651{
1652 return 0;
1653}
1654
1655static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
1656{
1657 struct stream_in *in = (struct stream_in *)stream;
1658 struct audio_device *adev = in->dev;
1659 struct str_parms *parms;
1660 char *str;
1661 char value[32];
1662 int ret, val = 0;
1663
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001664 ALOGD("%s: enter: kvpairs=%s", __func__, kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001665 parms = str_parms_create_str(kvpairs);
1666
1667 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_INPUT_SOURCE, value, sizeof(value));
1668
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001669 pthread_mutex_lock(&in->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001670 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001671 if (ret >= 0) {
1672 val = atoi(value);
1673 /* no audio source uses val == 0 */
1674 if ((in->source != val) && (val != 0)) {
1675 in->source = val;
1676 }
1677 }
1678
1679 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
1680 if (ret >= 0) {
1681 val = atoi(value);
1682 if ((in->device != val) && (val != 0)) {
1683 in->device = val;
1684 /* If recording is in progress, change the tx device to new device */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001685 if (!in->standby)
1686 ret = select_devices(adev, in->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001687 }
1688 }
1689
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001690 pthread_mutex_unlock(&adev->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001691 pthread_mutex_unlock(&in->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001692
1693 str_parms_destroy(parms);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001694 ALOGD("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001695 return ret;
1696}
1697
1698static char* in_get_parameters(const struct audio_stream *stream,
1699 const char *keys)
1700{
1701 return strdup("");
1702}
1703
1704static int in_set_gain(struct audio_stream_in *stream, float gain)
1705{
1706 return 0;
1707}
1708
1709static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
1710 size_t bytes)
1711{
1712 struct stream_in *in = (struct stream_in *)stream;
1713 struct audio_device *adev = in->dev;
1714 int i, ret = -1;
1715
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001716 pthread_mutex_lock(&in->lock);
1717 if (in->standby) {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001718 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001719 ret = start_input_stream(in);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001720 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001721 if (ret != 0) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001722 goto exit;
1723 }
1724 in->standby = 0;
1725 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001726
1727 if (in->pcm) {
1728 ret = pcm_read(in->pcm, buffer, bytes);
1729 }
1730
1731 /*
1732 * Instead of writing zeroes here, we could trust the hardware
1733 * to always provide zeroes when muted.
1734 */
1735 if (ret == 0 && adev->mic_mute)
1736 memset(buffer, 0, bytes);
1737
1738exit:
1739 pthread_mutex_unlock(&in->lock);
1740
1741 if (ret != 0) {
1742 in_standby(&in->stream.common);
1743 ALOGV("%s: read failed - sleeping for buffer duration", __func__);
1744 usleep(bytes * 1000000 / audio_stream_frame_size(&in->stream.common) /
1745 in_get_sample_rate(&in->stream.common));
1746 }
1747 return bytes;
1748}
1749
1750static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
1751{
1752 return 0;
1753}
1754
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001755static int add_remove_audio_effect(const struct audio_stream *stream,
1756 effect_handle_t effect,
1757 bool enable)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001758{
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001759 struct stream_in *in = (struct stream_in *)stream;
1760 int status = 0;
1761 effect_descriptor_t desc;
1762
1763 status = (*effect)->get_descriptor(effect, &desc);
1764 if (status != 0)
1765 return status;
1766
1767 pthread_mutex_lock(&in->lock);
1768 pthread_mutex_lock(&in->dev->lock);
1769 if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) &&
1770 in->enable_aec != enable &&
1771 (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0)) {
1772 in->enable_aec = enable;
1773 if (!in->standby)
1774 select_devices(in->dev, in->usecase);
1775 }
1776 pthread_mutex_unlock(&in->dev->lock);
1777 pthread_mutex_unlock(&in->lock);
1778
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001779 return 0;
1780}
1781
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001782static int in_add_audio_effect(const struct audio_stream *stream,
1783 effect_handle_t effect)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001784{
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001785 ALOGD("%s: effect %p", __func__, effect);
1786 return add_remove_audio_effect(stream, effect, true);
1787}
1788
1789static int in_remove_audio_effect(const struct audio_stream *stream,
1790 effect_handle_t effect)
1791{
1792 ALOGD("%s: effect %p", __func__, effect);
1793 return add_remove_audio_effect(stream, effect, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001794}
1795
1796static int adev_open_output_stream(struct audio_hw_device *dev,
1797 audio_io_handle_t handle,
1798 audio_devices_t devices,
1799 audio_output_flags_t flags,
1800 struct audio_config *config,
1801 struct audio_stream_out **stream_out)
1802{
1803 struct audio_device *adev = (struct audio_device *)dev;
1804 struct stream_out *out;
1805 int i, ret;
1806
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001807 ALOGD("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001808 __func__, config->sample_rate, config->channel_mask, devices, flags);
1809 *stream_out = NULL;
1810 out = (struct stream_out *)calloc(1, sizeof(struct stream_out));
1811
1812 if (devices == AUDIO_DEVICE_NONE)
1813 devices = AUDIO_DEVICE_OUT_SPEAKER;
1814
1815 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO;
1816 out->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
1817 out->flags = flags;
1818 out->devices = devices;
1819
1820 /* Init use case and pcm_config */
1821 if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT &&
1822 out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001823 pthread_mutex_lock(&adev->lock);
1824 ret = read_hdmi_channel_masks(out);
1825 pthread_mutex_unlock(&adev->lock);
1826 if (ret != 0) {
1827 /* If HDMI does not support multi channel playback, set the default */
1828 out->config.channels = popcount(out->channel_mask);
1829 set_hdmi_channels(adev->mixer, out->config.channels);
1830 goto error_open;
1831 }
1832
1833 if (config->sample_rate == 0)
1834 config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
1835 if (config->channel_mask == 0)
1836 config->channel_mask = AUDIO_CHANNEL_OUT_5POINT1;
1837
1838 out->channel_mask = config->channel_mask;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001839 out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH;
1840 out->config = pcm_config_hdmi_multi;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001841 out->config.rate = config->sample_rate;
1842 out->config.channels = popcount(out->channel_mask);
1843 out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2);
1844 set_hdmi_channels(adev->mixer, out->config.channels);
1845 } else if (out->flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) {
1846 out->usecase = USECASE_AUDIO_PLAYBACK_DEEP_BUFFER;
1847 out->config = pcm_config_deep_buffer;
1848 } else {
1849 out->usecase = USECASE_AUDIO_PLAYBACK_LOW_LATENCY;
1850 out->config = pcm_config_low_latency;
1851 }
1852
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001853 if (flags & AUDIO_OUTPUT_FLAG_PRIMARY) {
1854 if(adev->primary_output == NULL)
1855 adev->primary_output = out;
1856 else {
1857 ALOGE("%s: Primary output is already opened", __func__);
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001858 ret = -EEXIST;
1859 goto error_open;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001860 }
1861 }
1862
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001863 /* Check if this usecase is already existing */
1864 pthread_mutex_lock(&adev->lock);
1865 if (get_usecase_from_list(adev, out->usecase) != NULL) {
1866 ALOGE("%s: Usecase (%d) is already present", __func__, out->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001867 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001868 ret = -EEXIST;
1869 goto error_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001870 }
1871 pthread_mutex_unlock(&adev->lock);
1872
1873 out->stream.common.get_sample_rate = out_get_sample_rate;
1874 out->stream.common.set_sample_rate = out_set_sample_rate;
1875 out->stream.common.get_buffer_size = out_get_buffer_size;
1876 out->stream.common.get_channels = out_get_channels;
1877 out->stream.common.get_format = out_get_format;
1878 out->stream.common.set_format = out_set_format;
1879 out->stream.common.standby = out_standby;
1880 out->stream.common.dump = out_dump;
1881 out->stream.common.set_parameters = out_set_parameters;
1882 out->stream.common.get_parameters = out_get_parameters;
1883 out->stream.common.add_audio_effect = out_add_audio_effect;
1884 out->stream.common.remove_audio_effect = out_remove_audio_effect;
1885 out->stream.get_latency = out_get_latency;
1886 out->stream.set_volume = out_set_volume;
1887 out->stream.write = out_write;
1888 out->stream.get_render_position = out_get_render_position;
1889 out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
1890
1891 out->dev = adev;
1892 out->standby = 1;
Eric Laurenta9024de2013-04-04 09:19:12 -07001893 /* out->muted = false; by calloc() */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001894
1895 config->format = out->stream.common.get_format(&out->stream.common);
1896 config->channel_mask = out->stream.common.get_channels(&out->stream.common);
1897 config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common);
1898
1899 *stream_out = &out->stream;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001900 ALOGD("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001901 return 0;
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001902
1903error_open:
1904 free(out);
1905 *stream_out = NULL;
1906 ALOGD("%s: exit: ret %d", __func__, ret);
1907 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001908}
1909
1910static void adev_close_output_stream(struct audio_hw_device *dev,
1911 struct audio_stream_out *stream)
1912{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001913 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001914 out_standby(&stream->common);
1915 free(stream);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001916 ALOGD("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001917}
1918
1919static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
1920{
1921 struct audio_device *adev = (struct audio_device *)dev;
1922 struct str_parms *parms;
1923 char *str;
1924 char value[32];
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07001925 int val;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001926 int ret;
1927
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001928 ALOGD("%s: enter: %s", __func__, kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001929
1930 parms = str_parms_create_str(kvpairs);
1931 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
1932 if (ret >= 0) {
1933 int tty_mode;
1934
1935 if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
1936 tty_mode = TTY_MODE_OFF;
1937 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
1938 tty_mode = TTY_MODE_VCO;
1939 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
1940 tty_mode = TTY_MODE_HCO;
1941 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
1942 tty_mode = TTY_MODE_FULL;
1943 else
1944 return -EINVAL;
1945
1946 pthread_mutex_lock(&adev->lock);
1947 if (tty_mode != adev->tty_mode) {
1948 adev->tty_mode = tty_mode;
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -08001949 adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
1950 if (adev->in_call)
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001951 select_devices(adev, USECASE_VOICE_CALL);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001952 }
1953 pthread_mutex_unlock(&adev->lock);
1954 }
1955
1956 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value));
1957 if (ret >= 0) {
1958 /* When set to false, HAL should disable EC and NS
1959 * But it is currently not supported.
1960 */
1961 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
1962 adev->bluetooth_nrec = true;
1963 else
1964 adev->bluetooth_nrec = false;
1965 }
1966
1967 ret = str_parms_get_str(parms, "screen_state", value, sizeof(value));
1968 if (ret >= 0) {
1969 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
1970 adev->screen_off = false;
1971 else
1972 adev->screen_off = true;
1973 }
1974
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07001975 ret = str_parms_get_int(parms, "rotation", &val);
1976 if (ret >= 0) {
1977 bool reverse_speakers = false;
1978 switch(val) {
1979 // FIXME: note that the code below assumes that the speakers are in the correct placement
1980 // relative to the user when the device is rotated 90deg from its default rotation. This
1981 // assumption is device-specific, not platform-specific like this code.
1982 case 270:
1983 reverse_speakers = true;
1984 break;
1985 case 0:
1986 case 90:
1987 case 180:
1988 break;
1989 default:
1990 ALOGE("%s: unexpected rotation of %d", __func__, val);
1991 }
1992 pthread_mutex_lock(&adev->lock);
1993 if (adev->speaker_lr_swap != reverse_speakers) {
1994 adev->speaker_lr_swap = reverse_speakers;
1995 // only update the selected device if there is active pcm playback
1996 struct audio_usecase *usecase;
1997 struct listnode *node;
1998 list_for_each(node, &adev->usecase_list) {
1999 usecase = node_to_item(node, struct audio_usecase, list);
2000 if (usecase->type == PCM_PLAYBACK) {
2001 select_devices(adev, usecase->id);
2002 break;
2003 }
2004 }
2005 }
2006 pthread_mutex_unlock(&adev->lock);
2007 }
2008
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002009 str_parms_destroy(parms);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08002010 ALOGD("%s: exit with code(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002011 return ret;
2012}
2013
2014static char* adev_get_parameters(const struct audio_hw_device *dev,
2015 const char *keys)
2016{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002017 return strdup("");
2018}
2019
2020static int adev_init_check(const struct audio_hw_device *dev)
2021{
2022 return 0;
2023}
2024
2025static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
2026{
2027 struct audio_device *adev = (struct audio_device *)dev;
2028 int vol, err = 0;
2029
2030 pthread_mutex_lock(&adev->lock);
2031 adev->voice_volume = volume;
2032 if (adev->mode == AUDIO_MODE_IN_CALL) {
2033 if (volume < 0.0) {
2034 volume = 0.0;
2035 } else if (volume > 1.0) {
2036 volume = 1.0;
2037 }
2038
2039 vol = lrint(volume * 100.0);
2040
2041 // Voice volume levels from android are mapped to driver volume levels as follows.
2042 // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
2043 // So adjust the volume to get the correct volume index in driver
2044 vol = 100 - vol;
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -07002045#ifdef MSM8974
2046 set_voice_volume(adev->mixer, vol);
2047#else
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002048 if (adev->csd_client) {
2049 if (adev->csd_volume == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002050 ALOGE("%s: dlsym error for csd_client_volume", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002051 } else {
2052 err = adev->csd_volume(vol);
2053 if (err < 0) {
2054 ALOGE("%s: csd_client error %d", __func__, err);
2055 }
2056 }
2057 } else {
2058 ALOGE("%s: No CSD Client present", __func__);
2059 }
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -07002060#endif
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002061 }
2062 pthread_mutex_unlock(&adev->lock);
2063 return err;
2064}
2065
2066static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
2067{
2068 return -ENOSYS;
2069}
2070
2071static int adev_get_master_volume(struct audio_hw_device *dev,
2072 float *volume)
2073{
2074 return -ENOSYS;
2075}
2076
2077static int adev_set_master_mute(struct audio_hw_device *dev, bool muted)
2078{
2079 return -ENOSYS;
2080}
2081
2082static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted)
2083{
2084 return -ENOSYS;
2085}
2086
2087static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
2088{
2089 struct audio_device *adev = (struct audio_device *)dev;
2090
2091 pthread_mutex_lock(&adev->lock);
2092 if (adev->mode != mode) {
2093 adev->mode = mode;
2094 }
2095 pthread_mutex_unlock(&adev->lock);
2096 return 0;
2097}
2098
2099static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
2100{
2101 struct audio_device *adev = (struct audio_device *)dev;
2102 int err = 0;
2103
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002104 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002105 adev->mic_mute = state;
2106 if (adev->mode == AUDIO_MODE_IN_CALL) {
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -07002107#ifdef MSM8974
2108 set_mic_mute(adev->mixer, state);
2109#else
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002110 if (adev->csd_client) {
2111 if (adev->csd_mic_mute == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002112 ALOGE("%s: dlsym error for csd_mic_mute", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002113 } else {
2114 err = adev->csd_mic_mute(state);
2115 if (err < 0) {
2116 ALOGE("%s: csd_client error %d", __func__, err);
2117 }
2118 }
2119 } else {
2120 ALOGE("%s: No CSD Client present", __func__);
2121 }
Ravi Kumar Alamanda87f6ee02013-05-07 14:20:11 -07002122#endif
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002123 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002124 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002125 return err;
2126}
2127
2128static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
2129{
2130 struct audio_device *adev = (struct audio_device *)dev;
2131
2132 *state = adev->mic_mute;
2133
2134 return 0;
2135}
2136
2137static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
2138 const struct audio_config *config)
2139{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002140 int channel_count = popcount(config->channel_mask);
2141
2142 return get_input_buffer_size(config->sample_rate, config->format, channel_count);
2143}
2144
2145static int adev_open_input_stream(struct audio_hw_device *dev,
2146 audio_io_handle_t handle,
2147 audio_devices_t devices,
2148 struct audio_config *config,
2149 struct audio_stream_in **stream_in)
2150{
2151 struct audio_device *adev = (struct audio_device *)dev;
2152 struct stream_in *in;
2153 int ret, buffer_size, frame_size;
2154 int channel_count = popcount(config->channel_mask);
2155
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08002156 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002157 *stream_in = NULL;
2158 if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0)
2159 return -EINVAL;
2160
2161 in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
2162
2163 in->stream.common.get_sample_rate = in_get_sample_rate;
2164 in->stream.common.set_sample_rate = in_set_sample_rate;
2165 in->stream.common.get_buffer_size = in_get_buffer_size;
2166 in->stream.common.get_channels = in_get_channels;
2167 in->stream.common.get_format = in_get_format;
2168 in->stream.common.set_format = in_set_format;
2169 in->stream.common.standby = in_standby;
2170 in->stream.common.dump = in_dump;
2171 in->stream.common.set_parameters = in_set_parameters;
2172 in->stream.common.get_parameters = in_get_parameters;
2173 in->stream.common.add_audio_effect = in_add_audio_effect;
2174 in->stream.common.remove_audio_effect = in_remove_audio_effect;
2175 in->stream.set_gain = in_set_gain;
2176 in->stream.read = in_read;
2177 in->stream.get_input_frames_lost = in_get_input_frames_lost;
2178
2179 in->device = devices;
2180 in->source = AUDIO_SOURCE_DEFAULT;
2181 in->dev = adev;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002182 in->standby = 1;
2183 in->channel_mask = config->channel_mask;
2184
2185 /* Update config params with the requested sample rate and channels */
2186 in->usecase = USECASE_AUDIO_RECORD;
2187 in->config = pcm_config_audio_capture;
2188 in->config.channels = channel_count;
2189 in->config.rate = config->sample_rate;
2190
2191 frame_size = audio_stream_frame_size((struct audio_stream *)in);
2192 buffer_size = get_input_buffer_size(config->sample_rate,
2193 config->format,
2194 channel_count);
2195 in->config.period_size = buffer_size / frame_size;
2196
2197 *stream_in = &in->stream;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08002198 ALOGD("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002199 return 0;
2200
2201err_open:
2202 free(in);
2203 *stream_in = NULL;
2204 return ret;
2205}
2206
2207static void adev_close_input_stream(struct audio_hw_device *dev,
2208 struct audio_stream_in *stream)
2209{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08002210 ALOGD("%s", __func__);
2211
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002212 in_standby(&stream->common);
2213 free(stream);
2214
2215 return;
2216}
2217
2218static int adev_dump(const audio_hw_device_t *device, int fd)
2219{
2220 return 0;
2221}
2222
2223static int adev_close(hw_device_t *device)
2224{
2225 struct audio_device *adev = (struct audio_device *)device;
2226 audio_route_free(adev->audio_route);
2227 free(device);
2228 return 0;
2229}
2230
2231static void init_platform_data(struct audio_device *adev)
2232{
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -08002233 char platform[PROPERTY_VALUE_MAX];
2234 char baseband[PROPERTY_VALUE_MAX];
2235 char value[PROPERTY_VALUE_MAX];
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -08002236
2237 adev->dualmic_config = DUALMIC_CONFIG_NONE;
Ravi Kumar Alamanda02317792013-03-04 20:56:50 -08002238 adev->fluence_in_spkr_mode = false;
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -08002239 adev->fluence_in_voice_call = false;
2240 adev->fluence_in_voice_rec = false;
2241 adev->mic_type_analog = false;
2242
2243 property_get("persist.audio.handset.mic.type",value,"");
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002244 if (!strcmp("analog", value))
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -08002245 adev->mic_type_analog = true;
2246
2247 property_get("persist.audio.dualmic.config",value,"");
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002248 if (!strcmp("broadside", value)) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -08002249 adev->dualmic_config = DUALMIC_CONFIG_BROADSIDE;
2250 adev->acdb_settings |= DMIC_FLAG;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002251 } else if (!strcmp("endfire", value)) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -08002252 adev->dualmic_config = DUALMIC_CONFIG_ENDFIRE;
2253 adev->acdb_settings |= DMIC_FLAG;
2254 }
2255
2256 if (adev->dualmic_config != DUALMIC_CONFIG_NONE) {
2257 property_get("persist.audio.fluence.voicecall",value,"");
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002258 if (!strcmp("true", value)) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -08002259 adev->fluence_in_voice_call = true;
2260 }
2261
2262 property_get("persist.audio.fluence.voicerec",value,"");
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002263 if (!strcmp("true", value)) {
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -08002264 adev->fluence_in_voice_rec = true;
2265 }
Ravi Kumar Alamanda02317792013-03-04 20:56:50 -08002266
2267 property_get("persist.audio.fluence.speaker",value,"");
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002268 if (!strcmp("true", value)) {
Ravi Kumar Alamanda02317792013-03-04 20:56:50 -08002269 adev->fluence_in_spkr_mode = true;
2270 }
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -08002271 }
2272
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002273 adev->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
2274 if (adev->acdb_handle == NULL) {
2275 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
2276 } else {
2277 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002278 adev->acdb_deallocate = (acdb_deallocate_t)dlsym(adev->acdb_handle,
2279 "acdb_loader_deallocate_ACDB");
2280 adev->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(adev->acdb_handle,
2281 "acdb_loader_send_audio_cal");
2282 adev->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(adev->acdb_handle,
2283 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002284 adev->acdb_init = (acdb_init_t)dlsym(adev->acdb_handle,
2285 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002286 if (adev->acdb_init == NULL)
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002287 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002288 else
2289 adev->acdb_init();
2290 }
2291
2292 /* If platform is Fusion3, load CSD Client specific symbols
2293 * Voice call is handled by MDM and apps processor talks to
2294 * MDM through CSD Client
2295 */
2296 property_get("ro.board.platform", platform, "");
2297 property_get("ro.baseband", baseband, "");
2298 if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) {
2299 adev->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
2300 if (adev->csd_client == NULL)
2301 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
2302 }
2303
2304 if (adev->csd_client) {
2305 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002306 adev->csd_client_deinit = (csd_client_deinit_t)dlsym(adev->csd_client,
2307 "csd_client_deinit");
2308 adev->csd_disable_device = (csd_disable_device_t)dlsym(adev->csd_client,
2309 "csd_client_disable_device");
2310 adev->csd_enable_device = (csd_enable_device_t)dlsym(adev->csd_client,
2311 "csd_client_enable_device");
2312 adev->csd_start_voice = (csd_start_voice_t)dlsym(adev->csd_client,
2313 "csd_client_start_voice");
2314 adev->csd_stop_voice = (csd_stop_voice_t)dlsym(adev->csd_client,
2315 "csd_client_stop_voice");
2316 adev->csd_volume = (csd_volume_t)dlsym(adev->csd_client,
2317 "csd_client_volume");
2318 adev->csd_mic_mute = (csd_mic_mute_t)dlsym(adev->csd_client,
2319 "csd_client_mic_mute");
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002320 adev->csd_client_init = (csd_client_init_t)dlsym(adev->csd_client,
2321 "csd_client_init");
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002322
2323 if (adev->csd_client_init == NULL) {
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -08002324 ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror());
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002325 } else {
2326 adev->csd_client_init();
2327 }
2328 }
2329}
2330
2331static int adev_open(const hw_module_t *module, const char *name,
2332 hw_device_t **device)
2333{
2334 struct audio_device *adev;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002335 int i, ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002336
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08002337 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002338 if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL;
2339
2340 adev = calloc(1, sizeof(struct audio_device));
2341
2342 adev->mixer = mixer_open(MIXER_CARD);
2343 if (!adev->mixer) {
2344 ALOGE("Unable to open the mixer, aborting.");
2345 return -ENOSYS;
2346 }
2347
2348 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
2349 if (!adev->audio_route) {
2350 free(adev);
2351 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
2352 *device = NULL;
2353 return -EINVAL;
2354 }
2355
2356 adev->device.common.tag = HARDWARE_DEVICE_TAG;
2357 adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
2358 adev->device.common.module = (struct hw_module_t *)module;
2359 adev->device.common.close = adev_close;
2360
2361 adev->device.init_check = adev_init_check;
2362 adev->device.set_voice_volume = adev_set_voice_volume;
2363 adev->device.set_master_volume = adev_set_master_volume;
2364 adev->device.get_master_volume = adev_get_master_volume;
2365 adev->device.set_master_mute = adev_set_master_mute;
2366 adev->device.get_master_mute = adev_get_master_mute;
2367 adev->device.set_mode = adev_set_mode;
2368 adev->device.set_mic_mute = adev_set_mic_mute;
2369 adev->device.get_mic_mute = adev_get_mic_mute;
2370 adev->device.set_parameters = adev_set_parameters;
2371 adev->device.get_parameters = adev_get_parameters;
2372 adev->device.get_input_buffer_size = adev_get_input_buffer_size;
2373 adev->device.open_output_stream = adev_open_output_stream;
2374 adev->device.close_output_stream = adev_close_output_stream;
2375 adev->device.open_input_stream = adev_open_input_stream;
2376 adev->device.close_input_stream = adev_close_input_stream;
2377 adev->device.dump = adev_dump;
2378
2379 /* Set the default route before the PCM stream is opened */
2380 pthread_mutex_lock(&adev->lock);
2381 adev->mode = AUDIO_MODE_NORMAL;
Eric Laurentc8400632013-02-14 19:04:54 -08002382 adev->active_input = NULL;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08002383 adev->primary_output = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002384 adev->out_device = AUDIO_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002385 adev->voice_call_rx = NULL;
2386 adev->voice_call_tx = NULL;
2387 adev->voice_volume = 1.0f;
2388 adev->tty_mode = TTY_MODE_OFF;
2389 adev->bluetooth_nrec = true;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002390 adev->in_call = false;
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -08002391 adev->acdb_settings = TTY_MODE_OFF;
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07002392 adev->speaker_lr_swap = false;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002393 for (i = 0; i < SND_DEVICE_MAX; i++) {
2394 adev->snd_dev_ref_cnt[i] = 0;
2395 }
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08002396 list_init(&adev->usecase_list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002397 pthread_mutex_unlock(&adev->lock);
2398
2399 /* Loads platform specific libraries dynamically */
2400 init_platform_data(adev);
2401
2402 *device = &adev->device.common;
2403
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08002404 ALOGD("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002405 return 0;
2406}
2407
2408static struct hw_module_methods_t hal_module_methods = {
2409 .open = adev_open,
2410};
2411
2412struct audio_module HAL_MODULE_INFO_SYM = {
2413 .common = {
2414 .tag = HARDWARE_MODULE_TAG,
2415 .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
2416 .hal_api_version = HARDWARE_HAL_API_VERSION,
2417 .id = AUDIO_HARDWARE_MODULE_ID,
2418 .name = "QCOM Audio HAL",
2419 .author = "Code Aurora Forum",
2420 .methods = &hal_module_methods,
2421 },
2422};