blob: cb747153019149d21d0e3264e7db7cdd02e4b741 [file] [log] [blame]
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -08001/*
2 * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
3 * Not a Contribution.
4 *
5 * Copyright (C) 2010 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 "audio_hw_dolby"
21/*#define LOG_NDEBUG 0*/
22#define LOG_NDDEBUG 0
23
24#include <errno.h>
25#include <cutils/properties.h>
26#include <stdlib.h>
27#include <dlfcn.h>
28#include <cutils/str_parms.h>
29#include <cutils/log.h>
30
31#include "audio_hw.h"
32#include "platform.h"
33#include "platform_api.h"
34#include "audio_extn.h"
35#include "sound/compress_params.h"
36
37#ifdef DS1_DOLBY_DDP_ENABLED
38
39#define AUDIO_PARAMETER_DDP_DEV "ddp_device"
40#define AUDIO_PARAMETER_DDP_CH_CAP "ddp_chancap"
41#define AUDIO_PARAMETER_DDP_MAX_OUT_CHAN "ddp_maxoutchan"
42#define AUDIO_PARAMETER_DDP_OUT_MODE "ddp_outmode"
43#define AUDIO_PARAMETER_DDP_OUT_LFE_ON "ddp_outlfeon"
44#define AUDIO_PARAMETER_DDP_COMP_MODE "ddp_compmode"
45#define AUDIO_PARAMETER_DDP_STEREO_MODE "ddp_stereomode"
46
47#define PARAM_ID_MAX_OUTPUT_CHANNELS 0x00010DE2
48#define PARAM_ID_CTL_RUNNING_MODE 0x0
49#define PARAM_ID_CTL_ERROR_CONCEAL 0x00010DE3
50#define PARAM_ID_CTL_ERROR_MAX_RPTS 0x00010DE4
51#define PARAM_ID_CNV_ERROR_CONCEAL 0x00010DE5
52#define PARAM_ID_CTL_SUBSTREAM_SELECT 0x00010DE6
53#define PARAM_ID_CTL_INPUT_MODE 0x0
54#define PARAM_ID_OUT_CTL_OUTMODE 0x00010DE0
55#define PARAM_ID_OUT_CTL_OUTLFE_ON 0x00010DE1
56#define PARAM_ID_OUT_CTL_COMPMODE 0x00010D74
57#define PARAM_ID_OUT_CTL_STEREO_MODE 0x00010D76
58#define PARAM_ID_OUT_CTL_DUAL_MODE 0x00010D75
59#define PARAM_ID_OUT_CTL_DRCSCALE_HIGH 0x00010D7A
60#define PARAM_ID_OUT_CTL_DRCSCALE_LOW 0x00010D79
61#define PARAM_ID_OUT_CTL_OUT_PCMSCALE 0x00010D78
62#define PARAM_ID_OUT_CTL_MDCT_BANDLIMIT 0x00010DE7
63#define PARAM_ID_OUT_CTL_DRC_SUPPRESS 0x00010DE8
64
65/* DS1-DDP Endp Params */
66#define DDP_ENDP_NUM_PARAMS 17
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -080067#define DDP_ENDP_NUM_DEVICES 23
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -080068static int ddp_endp_params_id[DDP_ENDP_NUM_PARAMS] = {
69 PARAM_ID_MAX_OUTPUT_CHANNELS, PARAM_ID_CTL_RUNNING_MODE,
70 PARAM_ID_CTL_ERROR_CONCEAL, PARAM_ID_CTL_ERROR_MAX_RPTS,
71 PARAM_ID_CNV_ERROR_CONCEAL, PARAM_ID_CTL_SUBSTREAM_SELECT,
72 PARAM_ID_CTL_INPUT_MODE, PARAM_ID_OUT_CTL_OUTMODE,
73 PARAM_ID_OUT_CTL_OUTLFE_ON, PARAM_ID_OUT_CTL_COMPMODE,
74 PARAM_ID_OUT_CTL_STEREO_MODE, PARAM_ID_OUT_CTL_DUAL_MODE,
75 PARAM_ID_OUT_CTL_DRCSCALE_HIGH, PARAM_ID_OUT_CTL_DRCSCALE_LOW,
76 PARAM_ID_OUT_CTL_OUT_PCMSCALE, PARAM_ID_OUT_CTL_MDCT_BANDLIMIT,
77 PARAM_ID_OUT_CTL_DRC_SUPPRESS
78};
79
80static struct ddp_endp_params {
81 int device;
82 int dev_ch_cap;
83 int param_val[DDP_ENDP_NUM_PARAMS];
84 bool is_param_valid[DDP_ENDP_NUM_PARAMS];
85} ddp_endp_params[DDP_ENDP_NUM_DEVICES] = {
86 {AUDIO_DEVICE_OUT_EARPIECE, 2,
87 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
88 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 } },
89 {AUDIO_DEVICE_OUT_SPEAKER, 2,
90 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
91 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
92 {AUDIO_DEVICE_OUT_WIRED_HEADSET, 2,
93 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
94 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
95 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE, 2,
96 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
97 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
98 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO, 2,
99 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
100 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
101 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET, 2,
102 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
103 {1, 0, 0, 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 1, 0, 0, 0, 0, 0, 0} },
146 {AUDIO_DEVICE_OUT_ANC_HEADPHONE, 2,
147 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
148 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
149 {AUDIO_DEVICE_OUT_PROXY, 2,
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800150 {8, 0, 0, 0, 0, 0, 0, 21, 1, 2, 0, 0, 0, 0, 0, 0, 0},
151 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
152 {AUDIO_DEVICE_OUT_PROXY, 6,
153 {8, 0, 0, 0, 0, 0, 0, 21, 1, 2, 0, 0, 0, 0, 0, 0, 0},
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800154 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
155};
156
157int update_ddp_endp_table(int device, int dev_ch_cap, int param_id,
158 int param_val)
159{
160 int idx = 0;
161 int param_idx = 0;
162 ALOGV("%s: dev 0x%x dev_ch_cap %d param_id 0x%x param_val %d",
163 __func__, device, dev_ch_cap , param_id, param_val);
164
165 for(idx=0; idx<DDP_ENDP_NUM_DEVICES; idx++) {
166 if(ddp_endp_params[idx].device == device) {
167 if(ddp_endp_params[idx].dev_ch_cap == dev_ch_cap) {
168 break;
169 }
170 }
171 }
172
173 if(idx>=DDP_ENDP_NUM_DEVICES) {
174 ALOGE("%s: device not available in DDP endp config table", __func__);
175 return -EINVAL;
176 }
177
178 for(param_idx=0; param_idx<DDP_ENDP_NUM_PARAMS; param_idx++) {
179 if (ddp_endp_params_id[param_idx] == param_id) {
180 break;
181 }
182 }
183
184 if(param_idx>=DDP_ENDP_NUM_PARAMS) {
185 ALOGE("param not available in DDP endp config table");
186 return -EINVAL;
187 }
188
189 ALOGV("ddp_endp_params[%d].param_val[%d] = %d", idx, param_idx, param_val);
190 ddp_endp_params[idx].param_val[param_idx] = param_val;
191 return 0;
192}
193
194void send_ddp_endp_params_stream(struct stream_out *out,
195 int device, int dev_ch_cap,
196 bool set_cache)
197{
198 int idx, i;
199 int ddp_endp_params_data[2*DDP_ENDP_NUM_PARAMS + 1];
200 int length = 0;
201 for(idx=0; idx<DDP_ENDP_NUM_DEVICES; idx++) {
202 if(ddp_endp_params[idx].device & device) {
203 if(ddp_endp_params[idx].dev_ch_cap == dev_ch_cap) {
204 break;
205 }
206 }
207 }
208 if(idx>=DDP_ENDP_NUM_DEVICES) {
209 ALOGE("device not available in DDP endp config table");
210 return;
211 }
212
213 length += 1; /* offset 0 is for num of parameter. increase offset by 1 */
214 for (i=0; i<DDP_ENDP_NUM_PARAMS; i++) {
215 if(ddp_endp_params[idx].is_param_valid[i]) {
216 ddp_endp_params_data[length++] = ddp_endp_params_id[i];
217 ddp_endp_params_data[length++] = ddp_endp_params[idx].param_val[i];
218 }
219 }
220 ddp_endp_params_data[0] = (length-1)/2;
221 if(length) {
222 char mixer_ctl_name[128];
223 struct audio_device *adev = out->dev;
224 struct mixer_ctl *ctl;
225 int pcm_device_id = platform_get_pcm_device_id(out->usecase,
226 PCM_PLAYBACK);
227 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
228 "Audio Stream %d Dec Params", pcm_device_id);
229 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
230 if (!ctl) {
231 ALOGE("%s: Could not get ctl for mixer cmd - %s",
232 __func__, mixer_ctl_name);
233 return;
234 }
235 mixer_ctl_set_array(ctl, ddp_endp_params_data, length);
236 }
237 return;
238}
239
240void send_ddp_endp_params(struct audio_device *adev,
241 int ddp_dev, int dev_ch_cap)
242{
243 struct listnode *node;
244 struct audio_usecase *usecase;
245
246 list_for_each(node, &adev->usecase_list) {
247 usecase = node_to_item(node, struct audio_usecase, list);
248 if ((usecase->type == PCM_PLAYBACK) &&
249 (usecase->devices & ddp_dev) &&
250 (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
251 ((usecase->stream.out->format == AUDIO_FORMAT_AC3) ||
252 (usecase->stream.out->format == AUDIO_FORMAT_EAC3))) {
253 send_ddp_endp_params_stream(usecase->stream.out, ddp_dev,
254 dev_ch_cap, false /* set cache */);
255 }
256 }
257}
258
259void audio_extn_dolby_send_ddp_endp_params(struct audio_device *adev)
260{
261 struct listnode *node;
262 struct audio_usecase *usecase;
263 list_for_each(node, &adev->usecase_list) {
264 usecase = node_to_item(node, struct audio_usecase, list);
265 if ((usecase->type == PCM_PLAYBACK) &&
266 (usecase->devices & AUDIO_DEVICE_OUT_ALL) &&
267 (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
268 ((usecase->stream.out->format == AUDIO_FORMAT_AC3) ||
269 (usecase->stream.out->format == AUDIO_FORMAT_EAC3))) {
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800270 /*
271 * Use wfd /hdmi sink channel cap for dolby params if device is wfd
272 * or hdmi. Otherwise use stereo configuration
273 */
274 int channel_cap = usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ?
275 adev->cur_hdmi_channels :
276 usecase->devices & AUDIO_DEVICE_OUT_PROXY ?
277 adev->cur_wfd_channels : 2;
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800278 send_ddp_endp_params_stream(usecase->stream.out, usecase->devices,
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800279 channel_cap, false /* set cache */);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800280 }
281 }
282}
283
284void audio_extn_ddp_set_parameters(struct audio_device *adev,
285 struct str_parms *parms)
286{
287 int ddp_dev, dev_ch_cap;
288 int val, ret;
289 char value[32]={0};
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530290
291 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SND_CARD_STATUS, value,
292 sizeof(value));
293 if (ret >= 0) {
294 char *snd_card_status = value + 2;
295 if (strncmp(snd_card_status, "ONLINE", sizeof("ONLINE")) == 0)
296 audio_extn_dolby_set_license(adev);
297 }
298
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800299 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_DEV, value,
300 sizeof(value));
301 if (ret >= 0) {
302 ddp_dev = atoi(value);
303 if (!(AUDIO_DEVICE_OUT_ALL & ddp_dev))
304 return;
305 } else
306 return;
307
308 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_CH_CAP, value,
309 sizeof(value));
310 if (ret >= 0) {
311 dev_ch_cap = atoi(value);
312 if ((dev_ch_cap != 2) && (dev_ch_cap != 6) && (dev_ch_cap != 8))
313 return;
314 } else
315 return;
316
317 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_MAX_OUT_CHAN, value,
318 sizeof(value));
319 if (ret >= 0) {
320 val = atoi(value);
321 update_ddp_endp_table(ddp_dev, dev_ch_cap,
322 PARAM_ID_MAX_OUTPUT_CHANNELS, val);
323 }
324
325 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_OUT_MODE, value,
326 sizeof(value));
327 if (ret >= 0) {
328 val = atoi(value);
329 update_ddp_endp_table(ddp_dev, dev_ch_cap,
330 PARAM_ID_OUT_CTL_OUTMODE, val);
331 }
332
333 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_OUT_LFE_ON, value,
334 sizeof(value));
335 if (ret >= 0) {
336 val = atoi(value);
337 update_ddp_endp_table(ddp_dev, dev_ch_cap,
338 PARAM_ID_OUT_CTL_OUTLFE_ON, val);
339 }
340
341 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_COMP_MODE, value,
342 sizeof(value));
343 if (ret >= 0) {
344 val = atoi(value);
345 update_ddp_endp_table(ddp_dev, dev_ch_cap,
346 PARAM_ID_OUT_CTL_COMPMODE, val);
347 }
348
349 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_STEREO_MODE, value,
350 sizeof(value));
351 if (ret >= 0) {
352 val = atoi(value);
353 update_ddp_endp_table(ddp_dev, dev_ch_cap,
354 PARAM_ID_OUT_CTL_STEREO_MODE, val);
355 }
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800356 /* TODO: Do we need device channel caps here?
357 * We dont have that information as this is from dolby modules
358 */
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800359 send_ddp_endp_params(adev, ddp_dev, dev_ch_cap);
360}
361
362int audio_extn_dolby_get_snd_codec_id(struct audio_device *adev,
363 struct stream_out *out,
364 audio_format_t format)
365{
366 int id = 0;
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800367 /*
368 * Use wfd /hdmi sink channel cap for dolby params if device is wfd
369 * or hdmi. Otherwise use stereo configuration
370 */
371 int channel_cap = out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ?
372 adev->cur_hdmi_channels :
373 out->devices & AUDIO_DEVICE_OUT_PROXY ?
374 adev->cur_wfd_channels : 2;
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800375
376 switch (format) {
377 case AUDIO_FORMAT_AC3:
378 id = SND_AUDIOCODEC_AC3;
379 send_ddp_endp_params_stream(out, out->devices,
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800380 channel_cap, true /* set_cache */);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800381#ifndef DS1_DOLBY_DAP_ENABLED
382 audio_extn_dolby_set_dmid(adev);
383#endif
384 break;
385 case AUDIO_FORMAT_EAC3:
386 id = SND_AUDIOCODEC_EAC3;
387 send_ddp_endp_params_stream(out, out->devices,
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800388 channel_cap, true /* set_cache */);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800389#ifndef DS1_DOLBY_DAP_ENABLED
390 audio_extn_dolby_set_dmid(adev);
391#endif
392 break;
393 default:
394 ALOGE("%s: Unsupported audio format :%x", __func__, format);
395 }
396
397 return id;
398}
399
400bool audio_extn_is_dolby_format(audio_format_t format)
401{
402 if (format == AUDIO_FORMAT_AC3 ||
403 format == AUDIO_FORMAT_EAC3)
404 return true;
405 else
406 return false;
407}
408
409#endif /* DS1_DOLBY_DDP_ENABLED */
410
411#ifdef DS1_DOLBY_DAP_ENABLED
412void audio_extn_dolby_set_endpoint(struct audio_device *adev)
413{
414 struct listnode *node;
415 struct audio_usecase *usecase;
416 struct mixer_ctl *ctl;
417 const char *mixer_ctl_name = "DS1 DAP Endpoint";
418 int endpoint = 0, ret;
419 bool send = false;
420
421 list_for_each(node, &adev->usecase_list) {
422 usecase = node_to_item(node, struct audio_usecase, list);
423 if ((usecase->type == PCM_PLAYBACK) &&
424 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY)) {
425 endpoint |= usecase->devices & AUDIO_DEVICE_OUT_ALL;
426 send = true;
427 }
428 }
429 if (!send)
430 return;
431
432 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
433 if (!ctl) {
434 ALOGE("%s: Could not get ctl for mixer cmd - %s",
435 __func__, mixer_ctl_name);
436 return;
437 }
438 ret = mixer_ctl_set_value(ctl, 0, endpoint);
439 if (ret)
440 ALOGE("%s: Dolby set endpint cannot be set error:%d",__func__, ret);
441
442 return;
443}
444#endif /* DS1_DOLBY_DAP_ENABLED */
445
446
447#if defined(DS1_DOLBY_DDP_ENABLED) || defined(DS1_DOLBY_DAP_ENABLED)
448void audio_extn_dolby_set_dmid(struct audio_device *adev)
449{
450 struct listnode *node;
451 struct audio_usecase *usecase;
452 struct mixer_ctl *ctl;
453 const char *mixer_ctl_name = "DS1 Security";
454 char c_dmid[128] = {0};
455 int i_dmid, ret;
456 bool send = false;
457
458 list_for_each(node, &adev->usecase_list) {
459 usecase = node_to_item(node, struct audio_usecase, list);
Mingming Yinc7d048a2014-02-25 13:34:07 -0800460 if (usecase->type == PCM_PLAYBACK)
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800461 send = true;
462 }
463 if (!send)
464 return;
465
466 property_get("dmid",c_dmid,"0");
467 i_dmid = atoi(c_dmid);
468
469 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
470 if (!ctl) {
471 ALOGE("%s: Could not get ctl for mixer cmd - %s",
472 __func__, mixer_ctl_name);
473 return;
474 }
475 ALOGV("%s Dolby device manufacturer id is:%d",__func__,i_dmid);
476 ret = mixer_ctl_set_value(ctl, 0, i_dmid);
477 if (ret)
478 ALOGE("%s: Dolby DMID cannot be set error:%d",__func__, ret);
479
480 return;
481}
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530482
483void audio_extn_dolby_set_license(struct audio_device *adev)
484{
485 int ret, key=0;
486 char value[128] = {0};
487 struct mixer_ctl *ctl;
488 const char *mixer_ctl_name = "DS1 License";
489
490 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
491 if (!ctl) {
492 ALOGE("%s: Could not get ctl for mixer cmd - %s",
493 __func__, mixer_ctl_name);
494 return;
495 }
496
497 property_get("audio.ds1.metainfo.key",value,"0");
498 key = atoi(value);
499
500 ALOGV("%s Setting DS1 License, key:0x%x",__func__, key);
501 ret = mixer_ctl_set_value(ctl, 0, key);
502 if (ret)
503 ALOGE("%s: cannot set license, error:%d",__func__, ret);
504
505 return;
506}
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800507#endif /* DS1_DOLBY_DDP_ENABLED || DS1_DOLBY_DAP_ENABLED */