blob: 02940b4c297314b36b4e914d6f13ff61df05cd0f [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
3 * Not a Contribution.
4 *
Eric Laurentb23d5282013-05-14 15:27:20 -07005 * Copyright (C) 2013 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#define LOG_TAG "msm8974_platform"
21/*#define LOG_NDEBUG 0*/
22#define LOG_NDDEBUG 0
23
24#include <stdlib.h>
25#include <dlfcn.h>
26#include <cutils/log.h>
27#include <cutils/properties.h>
28#include <audio_hw.h>
29#include <platform_api.h>
30#include "platform.h"
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -070031#include "audio_extn.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070032
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070033#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Eric Laurentb23d5282013-05-14 15:27:20 -070034#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070035#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Eric Laurentb23d5282013-05-14 15:27:20 -070036
Eric Laurentb23d5282013-05-14 15:27:20 -070037/*
Eric Laurentb23d5282013-05-14 15:27:20 -070038 * This file will have a maximum of 38 bytes:
39 *
40 * 4 bytes: number of audio blocks
41 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
42 * Maximum 10 * 3 bytes: SAD blocks
43 */
44#define MAX_SAD_BLOCKS 10
45#define SAD_BLOCK_SIZE 3
46
47/* EDID format ID for LPCM audio */
48#define EDID_FORMAT_LPCM 1
49
sangwoo1b9f4b32013-06-21 18:22:55 -070050/* Retry for delay in FW loading*/
51#define RETRY_NUMBER 10
52#define RETRY_US 500000
53
sangwoo53b2cf02013-07-25 19:18:44 -070054#define MAX_VOL_INDEX 5
55#define MIN_VOL_INDEX 0
56#define percent_to_index(val, min, max) \
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -070057 ((val) * ((max) - (min)) * 0.01 + (min) + .5)
sangwoo53b2cf02013-07-25 19:18:44 -070058
Eric Laurentb23d5282013-05-14 15:27:20 -070059struct audio_block_header
60{
61 int reserved;
62 int length;
63};
64
65typedef void (*acdb_deallocate_t)();
66typedef int (*acdb_init_t)();
67typedef void (*acdb_send_audio_cal_t)(int, int);
68typedef void (*acdb_send_voice_cal_t)(int, int);
69
70/* Audio calibration related functions */
71struct platform_data {
72 struct audio_device *adev;
73 bool fluence_in_spkr_mode;
74 bool fluence_in_voice_call;
75 bool fluence_in_voice_rec;
Mingming Yin8e5a4f62013-10-07 15:23:41 -070076 int fluence_type;
Eric Laurentb23d5282013-05-14 15:27:20 -070077
78 void *acdb_handle;
79 acdb_init_t acdb_init;
80 acdb_deallocate_t acdb_deallocate;
81 acdb_send_audio_cal_t acdb_send_audio_cal;
82 acdb_send_voice_cal_t acdb_send_voice_cal;
83};
84
85static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Mingming Yin8e5a4f62013-10-07 15:23:41 -070086 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
87 DEEP_BUFFER_PCM_DEVICE},
88 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
89 LOWLATENCY_PCM_DEVICE},
90 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTI_CHANNEL_PCM_DEVICE,
91 MULTI_CHANNEL_PCM_DEVICE},
92 [USECASE_AUDIO_RECORD] = {DEEP_BUFFER_PCM_DEVICE, DEEP_BUFFER_PCM_DEVICE},
93 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
94 LOWLATENCY_PCM_DEVICE},
95 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -070096 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -070097};
98
99/* Array to store sound devices */
100static const char * const device_table[SND_DEVICE_MAX] = {
101 [SND_DEVICE_NONE] = "none",
102 /* Playback sound devices */
103 [SND_DEVICE_OUT_HANDSET] = "handset",
104 [SND_DEVICE_OUT_SPEAKER] = "speaker",
105 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
106 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
107 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
108 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
109 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
110 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
111 [SND_DEVICE_OUT_HDMI] = "hdmi",
112 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
113 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
114 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
115 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
116 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
117 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700118 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700119 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
120 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
121 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
122 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
123 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
124 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700125
126 /* Capture sound devices */
127 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
128 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
129 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
130 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
131 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic",
132 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
133 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
134 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
135 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
136 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
137 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700138 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
139 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
140 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Eric Laurentb23d5282013-05-14 15:27:20 -0700141 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
142 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
143 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
144 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700145 [SND_DEVICE_IN_VOICE_REC_DMIC] = "voice-rec-dmic-ef",
146 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700147 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700148 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700149};
150
151/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
152static const int acdb_device_table[SND_DEVICE_MAX] = {
153 [SND_DEVICE_NONE] = -1,
154 [SND_DEVICE_OUT_HANDSET] = 7,
155 [SND_DEVICE_OUT_SPEAKER] = 15,
156 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
157 [SND_DEVICE_OUT_HEADPHONES] = 10,
158 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
159 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
160 [SND_DEVICE_OUT_VOICE_SPEAKER] = 15,
161 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
162 [SND_DEVICE_OUT_HDMI] = 18,
163 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
164 [SND_DEVICE_OUT_BT_SCO] = 22,
sangwooc69476f2013-07-26 16:57:26 -0700165 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 88,
Eric Laurentb23d5282013-05-14 15:27:20 -0700166 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
167 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
168 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700169 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700170 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
171 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 26,
172 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
173 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 26,
174 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
175 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Eric Laurentb23d5282013-05-14 15:27:20 -0700176
177 [SND_DEVICE_IN_HANDSET_MIC] = 4,
178 [SND_DEVICE_IN_SPEAKER_MIC] = 4, /* ToDo: Check if this needs to changed to 11 */
179 [SND_DEVICE_IN_HEADSET_MIC] = 8,
180 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
181 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
182 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
183 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
184 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
185 [SND_DEVICE_IN_HDMI_MIC] = 4,
186 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
187 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700188 [SND_DEVICE_IN_VOICE_DMIC] = 41,
189 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = 89,
190 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
Eric Laurentb23d5282013-05-14 15:27:20 -0700191 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
192 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
193 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
194 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700195 [SND_DEVICE_IN_CAPTURE_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700196 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
Eric Laurentb23d5282013-05-14 15:27:20 -0700197 /* TODO: Update with proper acdb ids */
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700198 [SND_DEVICE_IN_VOICE_REC_DMIC] = 62,
199 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 6,
Eric Laurentb23d5282013-05-14 15:27:20 -0700200};
201
202static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
203static bool is_tmus = false;
204
205static void check_operator()
206{
207 char value[PROPERTY_VALUE_MAX];
208 int mccmnc;
209 property_get("gsm.sim.operator.numeric",value,"0");
210 mccmnc = atoi(value);
211 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
212 switch(mccmnc) {
213 /* TMUS MCC(310), MNC(490, 260, 026) */
214 case 310490:
215 case 310260:
216 case 310026:
217 is_tmus = true;
218 break;
219 }
220}
221
222bool is_operator_tmus()
223{
224 pthread_once(&check_op_once_ctl, check_operator);
225 return is_tmus;
226}
227
sangwoo53b2cf02013-07-25 19:18:44 -0700228static int set_volume_values(int type, int volume, int* values)
229{
230 values[0] = volume;
231 values[1] = ALL_SESSION_VSID;
232
233 switch(type) {
234 case VOLUME_SET:
235 values[2] = DEFAULT_VOLUME_RAMP_DURATION_MS;
236 break;
237 case MUTE_SET:
238 values[2] = DEFAULT_MUTE_RAMP_DURATION;
239 break;
240 default:
241 return -EINVAL;
242 }
243 return 0;
244}
245
Eric Laurentb23d5282013-05-14 15:27:20 -0700246static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
247{
248 struct mixer_ctl *ctl;
249 const char *mixer_ctl_name = "EC_REF_RX";
250
251 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
252 if (!ctl) {
253 ALOGE("%s: Could not get ctl for mixer cmd - %s",
254 __func__, mixer_ctl_name);
255 return -EINVAL;
256 }
257 ALOGV("Setting EC Reference: %s", ec_ref);
258 mixer_ctl_set_enum_by_string(ctl, ec_ref);
259 return 0;
260}
261
262void *platform_init(struct audio_device *adev)
263{
264 char value[PROPERTY_VALUE_MAX];
265 struct platform_data *my_data;
sangwoo1b9f4b32013-06-21 18:22:55 -0700266 int retry_num = 0;
267
268 adev->mixer = mixer_open(MIXER_CARD);
269
270 while (!adev->mixer && retry_num < RETRY_NUMBER) {
271 usleep(RETRY_US);
272 adev->mixer = mixer_open(MIXER_CARD);
273 retry_num++;
274 }
275
276 if (!adev->mixer) {
277 ALOGE("Unable to open the mixer, aborting.");
278 return NULL;
279 }
280
281 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
282 if (!adev->audio_route) {
283 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
284 return NULL;
285 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700286
287 my_data = calloc(1, sizeof(struct platform_data));
288
289 my_data->adev = adev;
Eric Laurentb23d5282013-05-14 15:27:20 -0700290 my_data->fluence_in_spkr_mode = false;
291 my_data->fluence_in_voice_call = false;
292 my_data->fluence_in_voice_rec = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700293 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700294
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700295 property_get("ro.qc.sdk.audio.fluencetype", value, "");
296 if (!strncmp("fluencepro", value, sizeof("fluencepro"))) {
297 my_data->fluence_type = FLUENCE_QUAD_MIC;
298 } else if (!strncmp("fluence", value, sizeof("fluence"))) {
299 my_data->fluence_type = FLUENCE_DUAL_MIC;
300 } else {
301 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700302 }
303
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700304 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700305 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700306 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700307 my_data->fluence_in_voice_call = true;
308 }
309
310 property_get("persist.audio.fluence.voicerec",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700311 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700312 my_data->fluence_in_voice_rec = true;
313 }
314
315 property_get("persist.audio.fluence.speaker",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700316 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700317 my_data->fluence_in_spkr_mode = true;
318 }
319 }
320
321 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
322 if (my_data->acdb_handle == NULL) {
323 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
324 } else {
325 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
326 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
327 "acdb_loader_deallocate_ACDB");
328 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
329 "acdb_loader_send_audio_cal");
330 if (!my_data->acdb_send_audio_cal)
331 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
332 __func__, LIB_ACDB_LOADER);
333 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
334 "acdb_loader_send_voice_cal");
335 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
336 "acdb_loader_init_ACDB");
337 if (my_data->acdb_init == NULL)
338 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
339 else
340 my_data->acdb_init();
341 }
342
343 return my_data;
344}
345
346void platform_deinit(void *platform)
347{
348 free(platform);
349}
350
351const char *platform_get_snd_device_name(snd_device_t snd_device)
352{
353 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
354 return device_table[snd_device];
355 else
356 return "";
357}
358
359void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
360{
361 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
362 strcat(mixer_path, " bt-sco");
363 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
364 strcat(mixer_path, " bt-sco");
365 else if (snd_device == SND_DEVICE_OUT_HDMI)
366 strcat(mixer_path, " hdmi");
367 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
368 strcat(mixer_path, " speaker-and-hdmi");
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700369 else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
370 strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
371 else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
372 strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
Eric Laurentb23d5282013-05-14 15:27:20 -0700373}
374
375int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
376{
377 int device_id;
378 if (device_type == PCM_PLAYBACK)
379 device_id = pcm_device_table[usecase][0];
380 else
381 device_id = pcm_device_table[usecase][1];
382 return device_id;
383}
384
385int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
386{
387 struct platform_data *my_data = (struct platform_data *)platform;
388 int acdb_dev_id, acdb_dev_type;
389
390 acdb_dev_id = acdb_device_table[snd_device];
391 if (acdb_dev_id < 0) {
392 ALOGE("%s: Could not find acdb id for device(%d)",
393 __func__, snd_device);
394 return -EINVAL;
395 }
396 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700397 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700398 __func__, snd_device, acdb_dev_id);
399 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
400 snd_device < SND_DEVICE_OUT_END)
401 acdb_dev_type = ACDB_DEV_TYPE_OUT;
402 else
403 acdb_dev_type = ACDB_DEV_TYPE_IN;
404 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
405 }
406 return 0;
407}
408
409int platform_switch_voice_call_device_pre(void *platform)
410{
411 return 0;
412}
413
414int platform_switch_voice_call_device_post(void *platform,
415 snd_device_t out_snd_device,
416 snd_device_t in_snd_device)
417{
418 struct platform_data *my_data = (struct platform_data *)platform;
419 int acdb_rx_id, acdb_tx_id;
420
421 if (my_data->acdb_send_voice_cal == NULL) {
422 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
423 } else {
424 acdb_rx_id = acdb_device_table[out_snd_device];
425 acdb_tx_id = acdb_device_table[in_snd_device];
426
427 if (acdb_rx_id > 0 && acdb_tx_id > 0)
428 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
429 else
430 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
431 acdb_rx_id, acdb_tx_id);
432 }
433
434 return 0;
435}
436
437int platform_start_voice_call(void *platform)
438{
439 return 0;
440}
441
442int platform_stop_voice_call(void *platform)
443{
444 return 0;
445}
446
447int platform_set_voice_volume(void *platform, int volume)
448{
449 struct platform_data *my_data = (struct platform_data *)platform;
450 struct audio_device *adev = my_data->adev;
451 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -0700452 const char *mixer_ctl_name = "Voice Rx Gain";
453 int values[VOLUME_CTL_PARAM_NUM];
454 int ret = 0;
Eric Laurentb23d5282013-05-14 15:27:20 -0700455
456 // Voice volume levels are mapped to adsp volume levels as follows.
457 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
458 // But this values don't changed in kernel. So, below change is need.
sangwoo53b2cf02013-07-25 19:18:44 -0700459 volume = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
Eric Laurentb23d5282013-05-14 15:27:20 -0700460
461 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
462 if (!ctl) {
463 ALOGE("%s: Could not get ctl for mixer cmd - %s",
464 __func__, mixer_ctl_name);
465 return -EINVAL;
466 }
sangwoo53b2cf02013-07-25 19:18:44 -0700467 ret = set_volume_values(VOLUME_SET, volume, values);
468 if (ret < 0) {
469 ALOGV("%s: failed setting volume by incorrect type", __func__);
470 return -EINVAL;
471 }
472 ret = mixer_ctl_set_array(ctl, values, sizeof(values)/sizeof(int));
473 if (ret < 0) {
474 ALOGV("%s: failed set mixer ctl by %d", __func__, ret);
475 return -EINVAL;
476 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700477
478 return 0;
479}
480
481int platform_set_mic_mute(void *platform, bool state)
482{
483 struct platform_data *my_data = (struct platform_data *)platform;
484 struct audio_device *adev = my_data->adev;
485 struct mixer_ctl *ctl;
486 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -0700487 int values[VOLUME_CTL_PARAM_NUM];
488 int ret = 0;
Eric Laurentb23d5282013-05-14 15:27:20 -0700489
490 if (adev->mode == AUDIO_MODE_IN_CALL) {
491 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
492 if (!ctl) {
493 ALOGE("%s: Could not get ctl for mixer cmd - %s",
494 __func__, mixer_ctl_name);
495 return -EINVAL;
496 }
497 ALOGV("Setting mic mute: %d", state);
sangwoo53b2cf02013-07-25 19:18:44 -0700498 ret = set_volume_values(MUTE_SET, state, values);
499 if (ret < 0) {
500 ALOGV("%s: failed setting mute by incorrect type", __func__);
501 return -EINVAL;
502 }
503 ret = mixer_ctl_set_array(ctl, values, sizeof(values)/sizeof(int));
504 if (ret < 0) {
505 ALOGV("%s: failed set mixer ctl by %d", __func__, ret);
506 return -EINVAL;
507 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700508 }
509
510 return 0;
511}
512
513snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
514{
515 struct platform_data *my_data = (struct platform_data *)platform;
516 struct audio_device *adev = my_data->adev;
517 audio_mode_t mode = adev->mode;
518 snd_device_t snd_device = SND_DEVICE_NONE;
519
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700520 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
521 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
522 int channel_count = popcount(channel_mask);
523
Eric Laurentb23d5282013-05-14 15:27:20 -0700524 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
525 if (devices == AUDIO_DEVICE_NONE ||
526 devices & AUDIO_DEVICE_BIT_IN) {
527 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
528 goto exit;
529 }
530
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700531 if(devices & AUDIO_DEVICE_OUT_PROXY) {
532 ALOGD("%s: setting sink capability for Proxy", __func__);
533 audio_extn_set_afe_proxy_channel_mixer(adev);
534 }
535
Eric Laurentb23d5282013-05-14 15:27:20 -0700536 if (mode == AUDIO_MODE_IN_CALL) {
537 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
538 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
539 if (adev->tty_mode == TTY_MODE_FULL)
540 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
541 else if (adev->tty_mode == TTY_MODE_VCO)
542 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
543 else if (adev->tty_mode == TTY_MODE_HCO)
544 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700545 else if (audio_extn_get_anc_enabled()) {
546 if (audio_extn_should_use_fb_anc())
547 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
548 else
549 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
550 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700551 else
552 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
553 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
554 snd_device = SND_DEVICE_OUT_BT_SCO;
555 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
556 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700557 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
558 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -0700559 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
560 if (is_operator_tmus())
561 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700562 else if (audio_extn_should_use_handset_anc(channel_count))
563 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700564 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700565 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700566 }
567 if (snd_device != SND_DEVICE_NONE) {
568 goto exit;
569 }
570 }
571
572 if (popcount(devices) == 2) {
573 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
574 AUDIO_DEVICE_OUT_SPEAKER)) {
575 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
576 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
577 AUDIO_DEVICE_OUT_SPEAKER)) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700578 if (audio_extn_get_anc_enabled())
579 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
580 else
581 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Eric Laurentb23d5282013-05-14 15:27:20 -0700582 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
583 AUDIO_DEVICE_OUT_SPEAKER)) {
584 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
585 } else {
586 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
587 goto exit;
588 }
589 if (snd_device != SND_DEVICE_NONE) {
590 goto exit;
591 }
592 }
593
594 if (popcount(devices) != 1) {
595 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
596 goto exit;
597 }
598
599 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
600 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700601 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
602 && audio_extn_get_anc_enabled()) {
603 if (audio_extn_should_use_fb_anc())
604 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
605 else
606 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
607 }
608 else
609 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurentb23d5282013-05-14 15:27:20 -0700610 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
611 if (adev->speaker_lr_swap)
612 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
613 else
614 snd_device = SND_DEVICE_OUT_SPEAKER;
615 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
616 snd_device = SND_DEVICE_OUT_BT_SCO;
617 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
618 snd_device = SND_DEVICE_OUT_HDMI ;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700619 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
620 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -0700621 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
622 snd_device = SND_DEVICE_OUT_HANDSET;
623 } else {
624 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
625 }
626exit:
627 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
628 return snd_device;
629}
630
631snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
632{
633 struct platform_data *my_data = (struct platform_data *)platform;
634 struct audio_device *adev = my_data->adev;
635 audio_source_t source = (adev->active_input == NULL) ?
636 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
637
638 audio_mode_t mode = adev->mode;
639 audio_devices_t in_device = ((adev->active_input == NULL) ?
640 AUDIO_DEVICE_NONE : adev->active_input->device)
641 & ~AUDIO_DEVICE_BIT_IN;
642 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
643 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
644 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700645 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -0700646
647 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
648 __func__, out_device, in_device);
649 if (mode == AUDIO_MODE_IN_CALL) {
650 if (out_device == AUDIO_DEVICE_NONE) {
651 ALOGE("%s: No output device set for voice call", __func__);
652 goto exit;
653 }
654 if (adev->tty_mode != TTY_MODE_OFF) {
655 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
656 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
657 switch (adev->tty_mode) {
658 case TTY_MODE_FULL:
659 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
660 break;
661 case TTY_MODE_VCO:
662 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
663 break;
664 case TTY_MODE_HCO:
665 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
666 break;
667 default:
668 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->tty_mode);
669 }
670 goto exit;
671 }
672 }
673 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
674 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700675 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
676 audio_extn_should_use_handset_anc(channel_count)) {
677 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
678 } else if (my_data->fluence_type == FLUENCE_NONE ||
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700679 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700680 snd_device = SND_DEVICE_IN_HANDSET_MIC;
681 } else {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700682 if (is_operator_tmus())
683 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -0700684 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700685 snd_device = SND_DEVICE_IN_VOICE_DMIC;
686 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700687 }
688 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
689 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
690 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
691 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
692 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700693 if (my_data->fluence_type != FLUENCE_NONE &&
694 my_data->fluence_in_voice_call &&
695 my_data->fluence_in_spkr_mode) {
696 if(my_data->fluence_type == FLUENCE_DUAL_MIC) {
697 adev->acdb_settings |= DMIC_FLAG;
698 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
699 } else {
700 adev->acdb_settings |= QMIC_FLAG;
701 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
702 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700703 } else {
704 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
705 }
706 }
707 } else if (source == AUDIO_SOURCE_CAMCORDER) {
708 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
709 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
710 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
711 }
712 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
713 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700714 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
715 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC;
716 else if (my_data->fluence_in_voice_rec)
717 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700718
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700719 if (snd_device == SND_DEVICE_NONE)
Eric Laurentb23d5282013-05-14 15:27:20 -0700720 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700721 else
722 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700723 }
724 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
725 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
726 in_device = AUDIO_DEVICE_IN_BACK_MIC;
727 if (adev->active_input) {
728 if (adev->active_input->enable_aec) {
729 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
730 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
731 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
732 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
733 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
734 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
735 }
736 set_echo_reference(adev->mixer, "SLIM_RX");
737 } else
738 set_echo_reference(adev->mixer, "NONE");
739 }
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700740 } else if (source == AUDIO_SOURCE_FM_RX) {
741 if (in_device & AUDIO_DEVICE_IN_FM_RX) {
742 snd_device = SND_DEVICE_IN_CAPTURE_FM;
743 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700744 } else if (source == AUDIO_SOURCE_DEFAULT) {
745 goto exit;
746 }
747
748
749 if (snd_device != SND_DEVICE_NONE) {
750 goto exit;
751 }
752
753 if (in_device != AUDIO_DEVICE_NONE &&
754 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
755 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
756 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
757 snd_device = SND_DEVICE_IN_HANDSET_MIC;
758 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
759 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
760 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
761 snd_device = SND_DEVICE_IN_HEADSET_MIC;
762 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
763 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
764 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
765 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700766 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
767 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -0700768 } else {
769 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
770 ALOGW("%s: Using default handset-mic", __func__);
771 snd_device = SND_DEVICE_IN_HANDSET_MIC;
772 }
773 } else {
774 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
775 snd_device = SND_DEVICE_IN_HANDSET_MIC;
776 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
777 snd_device = SND_DEVICE_IN_HEADSET_MIC;
778 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
779 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
780 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
781 snd_device = SND_DEVICE_IN_HANDSET_MIC;
782 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
783 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
784 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
785 snd_device = SND_DEVICE_IN_HDMI_MIC;
786 } else {
787 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
788 ALOGW("%s: Using default handset-mic", __func__);
789 snd_device = SND_DEVICE_IN_HANDSET_MIC;
790 }
791 }
792exit:
793 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
794 return snd_device;
795}
796
797int platform_set_hdmi_channels(void *platform, int channel_count)
798{
799 struct platform_data *my_data = (struct platform_data *)platform;
800 struct audio_device *adev = my_data->adev;
801 struct mixer_ctl *ctl;
802 const char *channel_cnt_str = NULL;
803 const char *mixer_ctl_name = "HDMI_RX Channels";
804 switch (channel_count) {
805 case 8:
806 channel_cnt_str = "Eight"; break;
807 case 7:
808 channel_cnt_str = "Seven"; break;
809 case 6:
810 channel_cnt_str = "Six"; break;
811 case 5:
812 channel_cnt_str = "Five"; break;
813 case 4:
814 channel_cnt_str = "Four"; break;
815 case 3:
816 channel_cnt_str = "Three"; break;
817 default:
818 channel_cnt_str = "Two"; break;
819 }
820 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
821 if (!ctl) {
822 ALOGE("%s: Could not get ctl for mixer cmd - %s",
823 __func__, mixer_ctl_name);
824 return -EINVAL;
825 }
826 ALOGV("HDMI channel count: %s", channel_cnt_str);
827 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
828 return 0;
829}
830
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700831int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -0700832{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700833 struct platform_data *my_data = (struct platform_data *)platform;
834 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -0700835 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
836 char *sad = block;
837 int num_audio_blocks;
838 int channel_count;
839 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700840 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -0700841
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700842 struct mixer_ctl *ctl;
843
844 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
845 if (!ctl) {
846 ALOGE("%s: Could not get ctl for mixer cmd - %s",
847 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -0700848 return 0;
849 }
850
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700851 mixer_ctl_update(ctl);
852
853 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -0700854
855 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700856 if (count > (int)sizeof(block))
857 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -0700858
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700859 ret = mixer_ctl_get_array(ctl, block, count);
860 if (ret != 0) {
861 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
862 return 0;
863 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700864
865 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700866 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700867
868 for (i = 0; i < num_audio_blocks; i++) {
869 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700870 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
871 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -0700872 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700873 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700874
875 channel_count = (sad[0] & 0x7) + 1;
876 if (channel_count > max_channels)
877 max_channels = channel_count;
878
879 /* Advance to next block */
880 sad += 3;
881 }
882
883 return max_channels;
884}