blob: 85c57fce7545b5aedd591e20781d3d036f683b58 [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},
Eric Laurentb23d5282013-05-14 15:27:20 -070096};
97
98/* Array to store sound devices */
99static const char * const device_table[SND_DEVICE_MAX] = {
100 [SND_DEVICE_NONE] = "none",
101 /* Playback sound devices */
102 [SND_DEVICE_OUT_HANDSET] = "handset",
103 [SND_DEVICE_OUT_SPEAKER] = "speaker",
104 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
105 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
106 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
107 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
108 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
109 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
110 [SND_DEVICE_OUT_HDMI] = "hdmi",
111 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
112 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
113 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
114 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
115 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
116 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700117 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
118 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
119 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
120 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
121 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
122 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700123
124 /* Capture sound devices */
125 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
126 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
127 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
128 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
129 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic",
130 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
131 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
132 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
133 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
134 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
135 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700136 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
137 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
138 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Eric Laurentb23d5282013-05-14 15:27:20 -0700139 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
140 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
141 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
142 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700143 [SND_DEVICE_IN_VOICE_REC_DMIC] = "voice-rec-dmic-ef",
144 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700145 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700146};
147
148/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
149static const int acdb_device_table[SND_DEVICE_MAX] = {
150 [SND_DEVICE_NONE] = -1,
151 [SND_DEVICE_OUT_HANDSET] = 7,
152 [SND_DEVICE_OUT_SPEAKER] = 15,
153 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
154 [SND_DEVICE_OUT_HEADPHONES] = 10,
155 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
156 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
157 [SND_DEVICE_OUT_VOICE_SPEAKER] = 15,
158 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
159 [SND_DEVICE_OUT_HDMI] = 18,
160 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
161 [SND_DEVICE_OUT_BT_SCO] = 22,
sangwooc69476f2013-07-26 16:57:26 -0700162 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 88,
Eric Laurentb23d5282013-05-14 15:27:20 -0700163 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
164 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
165 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700166 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
167 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 26,
168 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
169 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 26,
170 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
171 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Eric Laurentb23d5282013-05-14 15:27:20 -0700172
173 [SND_DEVICE_IN_HANDSET_MIC] = 4,
174 [SND_DEVICE_IN_SPEAKER_MIC] = 4, /* ToDo: Check if this needs to changed to 11 */
175 [SND_DEVICE_IN_HEADSET_MIC] = 8,
176 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
177 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
178 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
179 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
180 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
181 [SND_DEVICE_IN_HDMI_MIC] = 4,
182 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
183 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700184 [SND_DEVICE_IN_VOICE_DMIC] = 41,
185 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = 89,
186 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
Eric Laurentb23d5282013-05-14 15:27:20 -0700187 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
188 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
189 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
190 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700191 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
Eric Laurentb23d5282013-05-14 15:27:20 -0700192 /* TODO: Update with proper acdb ids */
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700193 [SND_DEVICE_IN_VOICE_REC_DMIC] = 62,
194 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 6,
Eric Laurentb23d5282013-05-14 15:27:20 -0700195};
196
197static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
198static bool is_tmus = false;
199
200static void check_operator()
201{
202 char value[PROPERTY_VALUE_MAX];
203 int mccmnc;
204 property_get("gsm.sim.operator.numeric",value,"0");
205 mccmnc = atoi(value);
206 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
207 switch(mccmnc) {
208 /* TMUS MCC(310), MNC(490, 260, 026) */
209 case 310490:
210 case 310260:
211 case 310026:
212 is_tmus = true;
213 break;
214 }
215}
216
217bool is_operator_tmus()
218{
219 pthread_once(&check_op_once_ctl, check_operator);
220 return is_tmus;
221}
222
sangwoo53b2cf02013-07-25 19:18:44 -0700223static int set_volume_values(int type, int volume, int* values)
224{
225 values[0] = volume;
226 values[1] = ALL_SESSION_VSID;
227
228 switch(type) {
229 case VOLUME_SET:
230 values[2] = DEFAULT_VOLUME_RAMP_DURATION_MS;
231 break;
232 case MUTE_SET:
233 values[2] = DEFAULT_MUTE_RAMP_DURATION;
234 break;
235 default:
236 return -EINVAL;
237 }
238 return 0;
239}
240
Eric Laurentb23d5282013-05-14 15:27:20 -0700241static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
242{
243 struct mixer_ctl *ctl;
244 const char *mixer_ctl_name = "EC_REF_RX";
245
246 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
247 if (!ctl) {
248 ALOGE("%s: Could not get ctl for mixer cmd - %s",
249 __func__, mixer_ctl_name);
250 return -EINVAL;
251 }
252 ALOGV("Setting EC Reference: %s", ec_ref);
253 mixer_ctl_set_enum_by_string(ctl, ec_ref);
254 return 0;
255}
256
257void *platform_init(struct audio_device *adev)
258{
259 char value[PROPERTY_VALUE_MAX];
260 struct platform_data *my_data;
sangwoo1b9f4b32013-06-21 18:22:55 -0700261 int retry_num = 0;
262
263 adev->mixer = mixer_open(MIXER_CARD);
264
265 while (!adev->mixer && retry_num < RETRY_NUMBER) {
266 usleep(RETRY_US);
267 adev->mixer = mixer_open(MIXER_CARD);
268 retry_num++;
269 }
270
271 if (!adev->mixer) {
272 ALOGE("Unable to open the mixer, aborting.");
273 return NULL;
274 }
275
276 adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
277 if (!adev->audio_route) {
278 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
279 return NULL;
280 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700281
282 my_data = calloc(1, sizeof(struct platform_data));
283
284 my_data->adev = adev;
Eric Laurentb23d5282013-05-14 15:27:20 -0700285 my_data->fluence_in_spkr_mode = false;
286 my_data->fluence_in_voice_call = false;
287 my_data->fluence_in_voice_rec = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700288 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700289
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700290 property_get("ro.qc.sdk.audio.fluencetype", value, "");
291 if (!strncmp("fluencepro", value, sizeof("fluencepro"))) {
292 my_data->fluence_type = FLUENCE_QUAD_MIC;
293 } else if (!strncmp("fluence", value, sizeof("fluence"))) {
294 my_data->fluence_type = FLUENCE_DUAL_MIC;
295 } else {
296 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700297 }
298
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700299 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700300 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700301 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700302 my_data->fluence_in_voice_call = true;
303 }
304
305 property_get("persist.audio.fluence.voicerec",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_rec = true;
308 }
309
310 property_get("persist.audio.fluence.speaker",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_spkr_mode = true;
313 }
314 }
315
316 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
317 if (my_data->acdb_handle == NULL) {
318 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
319 } else {
320 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
321 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
322 "acdb_loader_deallocate_ACDB");
323 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
324 "acdb_loader_send_audio_cal");
325 if (!my_data->acdb_send_audio_cal)
326 ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s",
327 __func__, LIB_ACDB_LOADER);
328 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
329 "acdb_loader_send_voice_cal");
330 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
331 "acdb_loader_init_ACDB");
332 if (my_data->acdb_init == NULL)
333 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
334 else
335 my_data->acdb_init();
336 }
337
338 return my_data;
339}
340
341void platform_deinit(void *platform)
342{
343 free(platform);
344}
345
346const char *platform_get_snd_device_name(snd_device_t snd_device)
347{
348 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
349 return device_table[snd_device];
350 else
351 return "";
352}
353
354void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
355{
356 if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
357 strcat(mixer_path, " bt-sco");
358 else if(snd_device == SND_DEVICE_OUT_BT_SCO)
359 strcat(mixer_path, " bt-sco");
360 else if (snd_device == SND_DEVICE_OUT_HDMI)
361 strcat(mixer_path, " hdmi");
362 else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
363 strcat(mixer_path, " speaker-and-hdmi");
364}
365
366int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
367{
368 int device_id;
369 if (device_type == PCM_PLAYBACK)
370 device_id = pcm_device_table[usecase][0];
371 else
372 device_id = pcm_device_table[usecase][1];
373 return device_id;
374}
375
376int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
377{
378 struct platform_data *my_data = (struct platform_data *)platform;
379 int acdb_dev_id, acdb_dev_type;
380
381 acdb_dev_id = acdb_device_table[snd_device];
382 if (acdb_dev_id < 0) {
383 ALOGE("%s: Could not find acdb id for device(%d)",
384 __func__, snd_device);
385 return -EINVAL;
386 }
387 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700388 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700389 __func__, snd_device, acdb_dev_id);
390 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
391 snd_device < SND_DEVICE_OUT_END)
392 acdb_dev_type = ACDB_DEV_TYPE_OUT;
393 else
394 acdb_dev_type = ACDB_DEV_TYPE_IN;
395 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
396 }
397 return 0;
398}
399
400int platform_switch_voice_call_device_pre(void *platform)
401{
402 return 0;
403}
404
405int platform_switch_voice_call_device_post(void *platform,
406 snd_device_t out_snd_device,
407 snd_device_t in_snd_device)
408{
409 struct platform_data *my_data = (struct platform_data *)platform;
410 int acdb_rx_id, acdb_tx_id;
411
412 if (my_data->acdb_send_voice_cal == NULL) {
413 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
414 } else {
415 acdb_rx_id = acdb_device_table[out_snd_device];
416 acdb_tx_id = acdb_device_table[in_snd_device];
417
418 if (acdb_rx_id > 0 && acdb_tx_id > 0)
419 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
420 else
421 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
422 acdb_rx_id, acdb_tx_id);
423 }
424
425 return 0;
426}
427
428int platform_start_voice_call(void *platform)
429{
430 return 0;
431}
432
433int platform_stop_voice_call(void *platform)
434{
435 return 0;
436}
437
438int platform_set_voice_volume(void *platform, int volume)
439{
440 struct platform_data *my_data = (struct platform_data *)platform;
441 struct audio_device *adev = my_data->adev;
442 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -0700443 const char *mixer_ctl_name = "Voice Rx Gain";
444 int values[VOLUME_CTL_PARAM_NUM];
445 int ret = 0;
Eric Laurentb23d5282013-05-14 15:27:20 -0700446
447 // Voice volume levels are mapped to adsp volume levels as follows.
448 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
449 // But this values don't changed in kernel. So, below change is need.
sangwoo53b2cf02013-07-25 19:18:44 -0700450 volume = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
Eric Laurentb23d5282013-05-14 15:27:20 -0700451
452 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
453 if (!ctl) {
454 ALOGE("%s: Could not get ctl for mixer cmd - %s",
455 __func__, mixer_ctl_name);
456 return -EINVAL;
457 }
sangwoo53b2cf02013-07-25 19:18:44 -0700458 ret = set_volume_values(VOLUME_SET, volume, values);
459 if (ret < 0) {
460 ALOGV("%s: failed setting volume by incorrect type", __func__);
461 return -EINVAL;
462 }
463 ret = mixer_ctl_set_array(ctl, values, sizeof(values)/sizeof(int));
464 if (ret < 0) {
465 ALOGV("%s: failed set mixer ctl by %d", __func__, ret);
466 return -EINVAL;
467 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700468
469 return 0;
470}
471
472int platform_set_mic_mute(void *platform, bool state)
473{
474 struct platform_data *my_data = (struct platform_data *)platform;
475 struct audio_device *adev = my_data->adev;
476 struct mixer_ctl *ctl;
477 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -0700478 int values[VOLUME_CTL_PARAM_NUM];
479 int ret = 0;
Eric Laurentb23d5282013-05-14 15:27:20 -0700480
481 if (adev->mode == AUDIO_MODE_IN_CALL) {
482 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
483 if (!ctl) {
484 ALOGE("%s: Could not get ctl for mixer cmd - %s",
485 __func__, mixer_ctl_name);
486 return -EINVAL;
487 }
488 ALOGV("Setting mic mute: %d", state);
sangwoo53b2cf02013-07-25 19:18:44 -0700489 ret = set_volume_values(MUTE_SET, state, values);
490 if (ret < 0) {
491 ALOGV("%s: failed setting mute by incorrect type", __func__);
492 return -EINVAL;
493 }
494 ret = mixer_ctl_set_array(ctl, values, sizeof(values)/sizeof(int));
495 if (ret < 0) {
496 ALOGV("%s: failed set mixer ctl by %d", __func__, ret);
497 return -EINVAL;
498 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700499 }
500
501 return 0;
502}
503
504snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
505{
506 struct platform_data *my_data = (struct platform_data *)platform;
507 struct audio_device *adev = my_data->adev;
508 audio_mode_t mode = adev->mode;
509 snd_device_t snd_device = SND_DEVICE_NONE;
510
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700511 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
512 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
513 int channel_count = popcount(channel_mask);
514
Eric Laurentb23d5282013-05-14 15:27:20 -0700515 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
516 if (devices == AUDIO_DEVICE_NONE ||
517 devices & AUDIO_DEVICE_BIT_IN) {
518 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
519 goto exit;
520 }
521
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700522 if(devices & AUDIO_DEVICE_OUT_PROXY) {
523 ALOGD("%s: setting sink capability for Proxy", __func__);
524 audio_extn_set_afe_proxy_channel_mixer(adev);
525 }
526
Eric Laurentb23d5282013-05-14 15:27:20 -0700527 if (mode == AUDIO_MODE_IN_CALL) {
528 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
529 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
530 if (adev->tty_mode == TTY_MODE_FULL)
531 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
532 else if (adev->tty_mode == TTY_MODE_VCO)
533 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
534 else if (adev->tty_mode == TTY_MODE_HCO)
535 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700536 else if (audio_extn_get_anc_enabled()) {
537 if (audio_extn_should_use_fb_anc())
538 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
539 else
540 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
541 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700542 else
543 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
544 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
545 snd_device = SND_DEVICE_OUT_BT_SCO;
546 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
547 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
548 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
549 if (is_operator_tmus())
550 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700551 else if (audio_extn_should_use_handset_anc(channel_count))
552 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700553 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700554 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -0700555 }
556 if (snd_device != SND_DEVICE_NONE) {
557 goto exit;
558 }
559 }
560
561 if (popcount(devices) == 2) {
562 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
563 AUDIO_DEVICE_OUT_SPEAKER)) {
564 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
565 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
566 AUDIO_DEVICE_OUT_SPEAKER)) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700567 if (audio_extn_get_anc_enabled())
568 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
569 else
570 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Eric Laurentb23d5282013-05-14 15:27:20 -0700571 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
572 AUDIO_DEVICE_OUT_SPEAKER)) {
573 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
574 } else {
575 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
576 goto exit;
577 }
578 if (snd_device != SND_DEVICE_NONE) {
579 goto exit;
580 }
581 }
582
583 if (popcount(devices) != 1) {
584 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
585 goto exit;
586 }
587
588 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
589 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700590 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
591 && audio_extn_get_anc_enabled()) {
592 if (audio_extn_should_use_fb_anc())
593 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
594 else
595 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
596 }
597 else
598 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurentb23d5282013-05-14 15:27:20 -0700599 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
600 if (adev->speaker_lr_swap)
601 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
602 else
603 snd_device = SND_DEVICE_OUT_SPEAKER;
604 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
605 snd_device = SND_DEVICE_OUT_BT_SCO;
606 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
607 snd_device = SND_DEVICE_OUT_HDMI ;
608 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
609 snd_device = SND_DEVICE_OUT_HANDSET;
610 } else {
611 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
612 }
613exit:
614 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
615 return snd_device;
616}
617
618snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
619{
620 struct platform_data *my_data = (struct platform_data *)platform;
621 struct audio_device *adev = my_data->adev;
622 audio_source_t source = (adev->active_input == NULL) ?
623 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
624
625 audio_mode_t mode = adev->mode;
626 audio_devices_t in_device = ((adev->active_input == NULL) ?
627 AUDIO_DEVICE_NONE : adev->active_input->device)
628 & ~AUDIO_DEVICE_BIT_IN;
629 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
630 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
631 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700632 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -0700633
634 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
635 __func__, out_device, in_device);
636 if (mode == AUDIO_MODE_IN_CALL) {
637 if (out_device == AUDIO_DEVICE_NONE) {
638 ALOGE("%s: No output device set for voice call", __func__);
639 goto exit;
640 }
641 if (adev->tty_mode != TTY_MODE_OFF) {
642 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
643 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
644 switch (adev->tty_mode) {
645 case TTY_MODE_FULL:
646 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
647 break;
648 case TTY_MODE_VCO:
649 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
650 break;
651 case TTY_MODE_HCO:
652 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
653 break;
654 default:
655 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->tty_mode);
656 }
657 goto exit;
658 }
659 }
660 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
661 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700662 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
663 audio_extn_should_use_handset_anc(channel_count)) {
664 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
665 } else if (my_data->fluence_type == FLUENCE_NONE ||
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700666 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700667 snd_device = SND_DEVICE_IN_HANDSET_MIC;
668 } else {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700669 if (is_operator_tmus())
670 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -0700671 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700672 snd_device = SND_DEVICE_IN_VOICE_DMIC;
673 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700674 }
675 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
676 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
677 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
678 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
679 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700680 if (my_data->fluence_type != FLUENCE_NONE &&
681 my_data->fluence_in_voice_call &&
682 my_data->fluence_in_spkr_mode) {
683 if(my_data->fluence_type == FLUENCE_DUAL_MIC) {
684 adev->acdb_settings |= DMIC_FLAG;
685 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
686 } else {
687 adev->acdb_settings |= QMIC_FLAG;
688 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
689 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700690 } else {
691 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
692 }
693 }
694 } else if (source == AUDIO_SOURCE_CAMCORDER) {
695 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
696 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
697 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
698 }
699 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
700 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700701 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
702 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC;
703 else if (my_data->fluence_in_voice_rec)
704 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700705
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700706 if (snd_device == SND_DEVICE_NONE)
Eric Laurentb23d5282013-05-14 15:27:20 -0700707 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700708 else
709 adev->acdb_settings |= DMIC_FLAG;
Eric Laurentb23d5282013-05-14 15:27:20 -0700710 }
711 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
712 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
713 in_device = AUDIO_DEVICE_IN_BACK_MIC;
714 if (adev->active_input) {
715 if (adev->active_input->enable_aec) {
716 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
717 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
718 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
719 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
720 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
721 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
722 }
723 set_echo_reference(adev->mixer, "SLIM_RX");
724 } else
725 set_echo_reference(adev->mixer, "NONE");
726 }
727 } else if (source == AUDIO_SOURCE_DEFAULT) {
728 goto exit;
729 }
730
731
732 if (snd_device != SND_DEVICE_NONE) {
733 goto exit;
734 }
735
736 if (in_device != AUDIO_DEVICE_NONE &&
737 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
738 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
739 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
740 snd_device = SND_DEVICE_IN_HANDSET_MIC;
741 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
742 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
743 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
744 snd_device = SND_DEVICE_IN_HEADSET_MIC;
745 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
746 snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
747 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
748 snd_device = SND_DEVICE_IN_HDMI_MIC;
749 } else {
750 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
751 ALOGW("%s: Using default handset-mic", __func__);
752 snd_device = SND_DEVICE_IN_HANDSET_MIC;
753 }
754 } else {
755 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
756 snd_device = SND_DEVICE_IN_HANDSET_MIC;
757 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
758 snd_device = SND_DEVICE_IN_HEADSET_MIC;
759 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
760 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
761 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
762 snd_device = SND_DEVICE_IN_HANDSET_MIC;
763 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
764 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
765 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
766 snd_device = SND_DEVICE_IN_HDMI_MIC;
767 } else {
768 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
769 ALOGW("%s: Using default handset-mic", __func__);
770 snd_device = SND_DEVICE_IN_HANDSET_MIC;
771 }
772 }
773exit:
774 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
775 return snd_device;
776}
777
778int platform_set_hdmi_channels(void *platform, int channel_count)
779{
780 struct platform_data *my_data = (struct platform_data *)platform;
781 struct audio_device *adev = my_data->adev;
782 struct mixer_ctl *ctl;
783 const char *channel_cnt_str = NULL;
784 const char *mixer_ctl_name = "HDMI_RX Channels";
785 switch (channel_count) {
786 case 8:
787 channel_cnt_str = "Eight"; break;
788 case 7:
789 channel_cnt_str = "Seven"; break;
790 case 6:
791 channel_cnt_str = "Six"; break;
792 case 5:
793 channel_cnt_str = "Five"; break;
794 case 4:
795 channel_cnt_str = "Four"; break;
796 case 3:
797 channel_cnt_str = "Three"; break;
798 default:
799 channel_cnt_str = "Two"; break;
800 }
801 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
802 if (!ctl) {
803 ALOGE("%s: Could not get ctl for mixer cmd - %s",
804 __func__, mixer_ctl_name);
805 return -EINVAL;
806 }
807 ALOGV("HDMI channel count: %s", channel_cnt_str);
808 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
809 return 0;
810}
811
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700812int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -0700813{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700814 struct platform_data *my_data = (struct platform_data *)platform;
815 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -0700816 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
817 char *sad = block;
818 int num_audio_blocks;
819 int channel_count;
820 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700821 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -0700822
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700823 struct mixer_ctl *ctl;
824
825 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
826 if (!ctl) {
827 ALOGE("%s: Could not get ctl for mixer cmd - %s",
828 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -0700829 return 0;
830 }
831
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700832 mixer_ctl_update(ctl);
833
834 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -0700835
836 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700837 if (count > (int)sizeof(block))
838 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -0700839
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700840 ret = mixer_ctl_get_array(ctl, block, count);
841 if (ret != 0) {
842 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
843 return 0;
844 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700845
846 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700847 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700848
849 for (i = 0; i < num_audio_blocks; i++) {
850 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700851 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
852 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -0700853 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700854 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700855
856 channel_count = (sad[0] & 0x7) + 1;
857 if (channel_count > max_channels)
858 max_channels = channel_count;
859
860 /* Advance to next block */
861 sad += 3;
862 }
863
864 return max_channels;
865}