blob: b958bf6376839fdbeb4b209a1e0581c8d7336bf4 [file] [log] [blame]
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -08001/*
Leena Winterrowdf98e42f2016-01-26 13:47:36 -08002 * Copyright (c) 2011-2016, The Linux Foundation. All rights reserved.
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -08003 * 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"
Ashish Jain8ec50472014-10-16 13:56:28 +053021//#define LOG_NDEBUG 0
22//#define LOG_NDDEBUG 0
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -080023#include <errno.h>
24#include <cutils/properties.h>
25#include <stdlib.h>
26#include <dlfcn.h>
27#include <cutils/str_parms.h>
28#include <cutils/log.h>
29
30#include "audio_hw.h"
31#include "platform.h"
32#include "platform_api.h"
33#include "audio_extn.h"
34#include "sound/compress_params.h"
Ashish Jainedb6a912014-10-16 13:56:28 +053035#include "sound/devdep_params.h"
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -080036
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
Mingming Yin0acba992014-06-02 22:38:35 -070067#define DDP_ENDP_NUM_DEVICES 21
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,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, 0, 0, 0, 0, 0},
142 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800143 {AUDIO_DEVICE_OUT_PROXY, 2,
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800144 {8, 0, 0, 0, 0, 0, 0, 21, 1, 2, 0, 0, 0, 0, 0, 0, 0},
145 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
146 {AUDIO_DEVICE_OUT_PROXY, 6,
147 {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 -0800148 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
149};
150
151int update_ddp_endp_table(int device, int dev_ch_cap, int param_id,
152 int param_val)
153{
154 int idx = 0;
155 int param_idx = 0;
156 ALOGV("%s: dev 0x%x dev_ch_cap %d param_id 0x%x param_val %d",
157 __func__, device, dev_ch_cap , param_id, param_val);
158
159 for(idx=0; idx<DDP_ENDP_NUM_DEVICES; idx++) {
160 if(ddp_endp_params[idx].device == device) {
161 if(ddp_endp_params[idx].dev_ch_cap == dev_ch_cap) {
162 break;
163 }
164 }
165 }
166
167 if(idx>=DDP_ENDP_NUM_DEVICES) {
168 ALOGE("%s: device not available in DDP endp config table", __func__);
169 return -EINVAL;
170 }
171
172 for(param_idx=0; param_idx<DDP_ENDP_NUM_PARAMS; param_idx++) {
173 if (ddp_endp_params_id[param_idx] == param_id) {
174 break;
175 }
176 }
177
178 if(param_idx>=DDP_ENDP_NUM_PARAMS) {
179 ALOGE("param not available in DDP endp config table");
180 return -EINVAL;
181 }
182
183 ALOGV("ddp_endp_params[%d].param_val[%d] = %d", idx, param_idx, param_val);
184 ddp_endp_params[idx].param_val[param_idx] = param_val;
185 return 0;
186}
187
188void send_ddp_endp_params_stream(struct stream_out *out,
189 int device, int dev_ch_cap,
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700190 bool set_cache __unused)
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800191{
192 int idx, i;
193 int ddp_endp_params_data[2*DDP_ENDP_NUM_PARAMS + 1];
194 int length = 0;
195 for(idx=0; idx<DDP_ENDP_NUM_DEVICES; idx++) {
196 if(ddp_endp_params[idx].device & device) {
197 if(ddp_endp_params[idx].dev_ch_cap == dev_ch_cap) {
198 break;
199 }
200 }
201 }
202 if(idx>=DDP_ENDP_NUM_DEVICES) {
203 ALOGE("device not available in DDP endp config table");
204 return;
205 }
206
207 length += 1; /* offset 0 is for num of parameter. increase offset by 1 */
208 for (i=0; i<DDP_ENDP_NUM_PARAMS; i++) {
209 if(ddp_endp_params[idx].is_param_valid[i]) {
210 ddp_endp_params_data[length++] = ddp_endp_params_id[i];
211 ddp_endp_params_data[length++] = ddp_endp_params[idx].param_val[i];
212 }
213 }
214 ddp_endp_params_data[0] = (length-1)/2;
215 if(length) {
216 char mixer_ctl_name[128];
217 struct audio_device *adev = out->dev;
218 struct mixer_ctl *ctl;
219 int pcm_device_id = platform_get_pcm_device_id(out->usecase,
220 PCM_PLAYBACK);
221 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
222 "Audio Stream %d Dec Params", pcm_device_id);
223 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
224 if (!ctl) {
225 ALOGE("%s: Could not get ctl for mixer cmd - %s",
226 __func__, mixer_ctl_name);
227 return;
228 }
229 mixer_ctl_set_array(ctl, ddp_endp_params_data, length);
230 }
231 return;
232}
233
234void send_ddp_endp_params(struct audio_device *adev,
235 int ddp_dev, int dev_ch_cap)
236{
237 struct listnode *node;
238 struct audio_usecase *usecase;
239
240 list_for_each(node, &adev->usecase_list) {
241 usecase = node_to_item(node, struct audio_usecase, list);
242 if ((usecase->type == PCM_PLAYBACK) &&
243 (usecase->devices & ddp_dev) &&
244 (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
245 ((usecase->stream.out->format == AUDIO_FORMAT_AC3) ||
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700246 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3) ||
247 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC))) {
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800248 send_ddp_endp_params_stream(usecase->stream.out, ddp_dev,
249 dev_ch_cap, false /* set cache */);
250 }
251 }
252}
253
254void audio_extn_dolby_send_ddp_endp_params(struct audio_device *adev)
255{
256 struct listnode *node;
257 struct audio_usecase *usecase;
258 list_for_each(node, &adev->usecase_list) {
259 usecase = node_to_item(node, struct audio_usecase, list);
260 if ((usecase->type == PCM_PLAYBACK) &&
261 (usecase->devices & AUDIO_DEVICE_OUT_ALL) &&
262 (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
263 ((usecase->stream.out->format == AUDIO_FORMAT_AC3) ||
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700264 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3) ||
265 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC))) {
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800266 /*
267 * Use wfd /hdmi sink channel cap for dolby params if device is wfd
268 * or hdmi. Otherwise use stereo configuration
269 */
270 int channel_cap = usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ?
271 adev->cur_hdmi_channels :
272 usecase->devices & AUDIO_DEVICE_OUT_PROXY ?
273 adev->cur_wfd_channels : 2;
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800274 send_ddp_endp_params_stream(usecase->stream.out, usecase->devices,
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800275 channel_cap, false /* set cache */);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800276 }
277 }
278}
279
280void audio_extn_ddp_set_parameters(struct audio_device *adev,
281 struct str_parms *parms)
282{
283 int ddp_dev, dev_ch_cap;
284 int val, ret;
285 char value[32]={0};
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530286
287 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SND_CARD_STATUS, value,
288 sizeof(value));
289 if (ret >= 0) {
290 char *snd_card_status = value + 2;
291 if (strncmp(snd_card_status, "ONLINE", sizeof("ONLINE")) == 0)
292 audio_extn_dolby_set_license(adev);
293 }
294
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800295 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_DEV, value,
296 sizeof(value));
297 if (ret >= 0) {
298 ddp_dev = atoi(value);
299 if (!(AUDIO_DEVICE_OUT_ALL & ddp_dev))
300 return;
301 } else
302 return;
303
304 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_CH_CAP, value,
305 sizeof(value));
306 if (ret >= 0) {
307 dev_ch_cap = atoi(value);
308 if ((dev_ch_cap != 2) && (dev_ch_cap != 6) && (dev_ch_cap != 8))
309 return;
310 } else
311 return;
312
313 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_MAX_OUT_CHAN, value,
314 sizeof(value));
315 if (ret >= 0) {
316 val = atoi(value);
317 update_ddp_endp_table(ddp_dev, dev_ch_cap,
318 PARAM_ID_MAX_OUTPUT_CHANNELS, val);
319 }
320
321 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_OUT_MODE, value,
322 sizeof(value));
323 if (ret >= 0) {
324 val = atoi(value);
325 update_ddp_endp_table(ddp_dev, dev_ch_cap,
326 PARAM_ID_OUT_CTL_OUTMODE, val);
327 }
328
329 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_OUT_LFE_ON, value,
330 sizeof(value));
331 if (ret >= 0) {
332 val = atoi(value);
333 update_ddp_endp_table(ddp_dev, dev_ch_cap,
334 PARAM_ID_OUT_CTL_OUTLFE_ON, val);
335 }
336
337 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_COMP_MODE, value,
338 sizeof(value));
339 if (ret >= 0) {
340 val = atoi(value);
341 update_ddp_endp_table(ddp_dev, dev_ch_cap,
342 PARAM_ID_OUT_CTL_COMPMODE, val);
343 }
344
345 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_STEREO_MODE, value,
346 sizeof(value));
347 if (ret >= 0) {
348 val = atoi(value);
349 update_ddp_endp_table(ddp_dev, dev_ch_cap,
350 PARAM_ID_OUT_CTL_STEREO_MODE, val);
351 }
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800352 /* TODO: Do we need device channel caps here?
353 * We dont have that information as this is from dolby modules
354 */
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800355 send_ddp_endp_params(adev, ddp_dev, dev_ch_cap);
356}
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700357#endif /* DS1_DOLBY_DDP_ENABLED */
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800358
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700359#if defined(DS1_DOLBY_DDP_ENABLED) || defined(DS2_DOLBY_DAP_ENABLED)
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800360bool audio_extn_is_dolby_format(audio_format_t format)
361{
362 if (format == AUDIO_FORMAT_AC3 ||
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700363 format == AUDIO_FORMAT_E_AC3 ||
364 format == AUDIO_FORMAT_E_AC3_JOC)
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800365 return true;
366 else
367 return false;
368}
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700369#endif /* DS1_DOLBY_DDP_ENABLED || DS2_DOLBY_DAP_ENABLED */
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800370
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700371
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800372#ifdef DS1_DOLBY_DAP_ENABLED
373void audio_extn_dolby_set_endpoint(struct audio_device *adev)
374{
375 struct listnode *node;
376 struct audio_usecase *usecase;
377 struct mixer_ctl *ctl;
378 const char *mixer_ctl_name = "DS1 DAP Endpoint";
379 int endpoint = 0, ret;
380 bool send = false;
381
382 list_for_each(node, &adev->usecase_list) {
383 usecase = node_to_item(node, struct audio_usecase, list);
384 if ((usecase->type == PCM_PLAYBACK) &&
385 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY)) {
386 endpoint |= usecase->devices & AUDIO_DEVICE_OUT_ALL;
387 send = true;
388 }
389 }
390 if (!send)
391 return;
392
393 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
394 if (!ctl) {
395 ALOGE("%s: Could not get ctl for mixer cmd - %s",
396 __func__, mixer_ctl_name);
397 return;
398 }
399 ret = mixer_ctl_set_value(ctl, 0, endpoint);
400 if (ret)
401 ALOGE("%s: Dolby set endpint cannot be set error:%d",__func__, ret);
402
403 return;
404}
405#endif /* DS1_DOLBY_DAP_ENABLED */
406
407
408#if defined(DS1_DOLBY_DDP_ENABLED) || defined(DS1_DOLBY_DAP_ENABLED)
409void audio_extn_dolby_set_dmid(struct audio_device *adev)
410{
411 struct listnode *node;
412 struct audio_usecase *usecase;
413 struct mixer_ctl *ctl;
414 const char *mixer_ctl_name = "DS1 Security";
415 char c_dmid[128] = {0};
416 int i_dmid, ret;
417 bool send = false;
418
419 list_for_each(node, &adev->usecase_list) {
420 usecase = node_to_item(node, struct audio_usecase, list);
Mingming Yinc7d048a2014-02-25 13:34:07 -0800421 if (usecase->type == PCM_PLAYBACK)
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800422 send = true;
423 }
424 if (!send)
425 return;
426
427 property_get("dmid",c_dmid,"0");
Ashish Jain1dff3212015-02-10 12:16:48 +0530428 i_dmid = atoll(c_dmid);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800429
430 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
431 if (!ctl) {
432 ALOGE("%s: Could not get ctl for mixer cmd - %s",
433 __func__, mixer_ctl_name);
434 return;
435 }
436 ALOGV("%s Dolby device manufacturer id is:%d",__func__,i_dmid);
437 ret = mixer_ctl_set_value(ctl, 0, i_dmid);
438 if (ret)
439 ALOGE("%s: Dolby DMID cannot be set error:%d",__func__, ret);
440
441 return;
442}
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530443
Ashish Jainedb6a912014-10-16 13:56:28 +0530444#ifndef DS2_DOLBY_DAP_ENABLED
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530445void audio_extn_dolby_set_license(struct audio_device *adev)
446{
447 int ret, key=0;
448 char value[128] = {0};
449 struct mixer_ctl *ctl;
450 const char *mixer_ctl_name = "DS1 License";
451
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;
457 }
458
459 property_get("audio.ds1.metainfo.key",value,"0");
Ashish Jainedb6a912014-10-16 13:56:28 +0530460#ifdef DOLBY_ACDB_LICENSE
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530461 key = atoi(value);
Ashish Jainedb6a912014-10-16 13:56:28 +0530462#else
463 key = 0;
464#endif
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530465 ALOGV("%s Setting DS1 License, key:0x%x",__func__, key);
466 ret = mixer_ctl_set_value(ctl, 0, key);
467 if (ret)
468 ALOGE("%s: cannot set license, error:%d",__func__, ret);
469
470 return;
471}
Ashish Jainedb6a912014-10-16 13:56:28 +0530472#endif
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800473#endif /* DS1_DOLBY_DDP_ENABLED || DS1_DOLBY_DAP_ENABLED */
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700474
475#ifdef DS2_DOLBY_DAP_ENABLED
476struct ds2_extn_module {
477 void *ds2_handle;
478 dap_hal_set_hw_info_t dap_hal_set_hw_info;
479};
480
481static struct ds2_extn_module ds2extnmod = {
482 .ds2_handle = NULL,
483 .dap_hal_set_hw_info = NULL,
484};
485
486int audio_extn_dap_hal_init(int snd_card) {
Sharad Sangle1f705a72016-10-05 20:01:39 +0530487 int ret = -EINVAL;
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700488 dap_hal_device_be_id_map_t device_be_id_map;
489
490 ALOGV("%s: opening DAP HAL lib\n", __func__);
491 ds2extnmod.ds2_handle = dlopen(LIB_DS2_DAP_HAL, RTLD_NOW);
492 if (ds2extnmod.ds2_handle == NULL) {
493 ALOGE("%s: DLOPEN failed for %s error %s", __func__, LIB_DS2_DAP_HAL,
494 dlerror());
495 goto ret;
496 }
497 ds2extnmod.dap_hal_set_hw_info = (dap_hal_set_hw_info_t)dlsym(ds2extnmod.ds2_handle, SET_HW_INFO_FUNC);
498 if (ds2extnmod.dap_hal_set_hw_info == NULL) {
499 ALOGE("%s: dlsym error %s for %s", __func__, SET_HW_INFO_FUNC,
500 dlerror());
501 goto close;
502 }
503 ds2extnmod.dap_hal_set_hw_info(SND_CARD, (void*)(&snd_card));
504 ALOGV("%s Sound card number is:%d",__func__,snd_card);
505
Alexy Josephb1379942016-01-29 15:49:38 -0800506 platform_get_device_to_be_id_map((int**)&device_be_id_map.device_id_to_be_id,
507 &device_be_id_map.len);
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700508 ds2extnmod.dap_hal_set_hw_info(DEVICE_BE_ID_MAP, (void*)(&device_be_id_map));
509 ALOGV("%s Set be id map len:%d",__func__,device_be_id_map.len);
510 ret = 0;
511 goto ret;
512
513close:
514 dlclose(ds2extnmod.ds2_handle);
515 ds2extnmod.ds2_handle = NULL;
516 ds2extnmod.dap_hal_set_hw_info = NULL;
517ret:
518 return ret;
519}
520
521int audio_extn_dap_hal_deinit() {
522 if (ds2extnmod.ds2_handle != NULL) {
523 dlclose(ds2extnmod.ds2_handle);
524 ds2extnmod.ds2_handle = NULL;
525 }
526 ds2extnmod.dap_hal_set_hw_info = NULL;
527 return 0;
528}
529
530void audio_extn_dolby_ds2_set_endpoint(struct audio_device *adev) {
531 struct listnode *node;
532 struct audio_usecase *usecase;
Sharad Sangle1f705a72016-10-05 20:01:39 +0530533 int endpoint = 0;
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700534 bool send = false;
535
536 list_for_each(node, &adev->usecase_list) {
537 usecase = node_to_item(node, struct audio_usecase, list);
538 if ((usecase->type == PCM_PLAYBACK) &&
539 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY)) {
540 endpoint |= usecase->devices & AUDIO_DEVICE_OUT_ALL;
541 send = true;
542 }
543 }
544 if (!send)
545 return;
546
547 if (ds2extnmod.dap_hal_set_hw_info) {
548 ds2extnmod.dap_hal_set_hw_info(HW_ENDPOINT, (void*)(&endpoint));
549 ALOGE("%s: Dolby set endpint :0x%x",__func__, endpoint);
550 } else {
551 ALOGE("%s: dap_hal_set_hw_info is NULL",__func__);
552 }
553
554 return;
555}
556
557int audio_extn_ds2_enable(struct audio_device *adev) {
558
559 char value[PROPERTY_VALUE_MAX] = {0};
560 bool ds2_enabled = false;
561 const char *mixer_ctl_name = "DS2 OnOff";
562 struct mixer_ctl *ctl;
563
564 property_get("audio.dolby.ds2.enabled", value, NULL);
565 ds2_enabled = atoi(value) || !strncmp("true", value, 4);
566
567 ALOGV("%s:", __func__);
568 if(ds2_enabled) {
569 ALOGD("%s:ds2_enabled %d", __func__, ds2_enabled);
570 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
571 if (!ctl) {
572 ALOGE("%s: Could not get ctl for mixer cmd - %s",
573 __func__, mixer_ctl_name);
574 return -EINVAL;
575 }
576
577 if (mixer_ctl_set_value(ctl, 0, ds2_enabled) < 0) {
578 ALOGE("%s: Could not set ds2 enable %d",
579 __func__, ds2_enabled);
580 return -EINVAL;
581 }
582 }
583 return 0;
584}
585
Sharad Sangle1f705a72016-10-05 20:01:39 +0530586int audio_extn_dolby_set_dap_bypass(struct audio_device *adev __unused, int state) {
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700587
588 ALOGV("%s: state %d", __func__, state);
589 if (ds2extnmod.dap_hal_set_hw_info) {
590 ds2extnmod.dap_hal_set_hw_info(DAP_BYPASS, (void*)(&state));
591 ALOGV("%s: Dolby set bypas :0x%x", __func__, state);
592 } else {
593 ALOGV("%s: dap_hal_set_hw_info is NULL", __func__);
594 }
595 return 0;
596}
Ashish Jainedb6a912014-10-16 13:56:28 +0530597
Sharad Sangle1f705a72016-10-05 20:01:39 +0530598void audio_extn_dolby_set_license(struct audio_device *adev __unused)
Ashish Jainedb6a912014-10-16 13:56:28 +0530599{
600 int i_key=0;
601 char c_key[128] = {0};
602 char c_dmid[128] = {0};
Sharad Sangle1f705a72016-10-05 20:01:39 +0530603 int i_dmid;
Ashish Jainedb6a912014-10-16 13:56:28 +0530604 struct dolby_param_license dolby_license;
605
606#ifdef DOLBY_ACDB_LICENSE
607 property_get("audio.ds1.metainfo.key",c_key,"0");
608 i_key = atoi(c_key);
609#else
610 /* As ACDB based license mechanism is disabled, force set the license key to 0*/
611 i_key = 0;
612#endif
613 property_get("dmid",c_dmid,"0");
Ashish Jain1dff3212015-02-10 12:16:48 +0530614 i_dmid = atoll(c_dmid);
Ashish Jainedb6a912014-10-16 13:56:28 +0530615 ALOGV("%s Setting DS1 License, key:0x%x dmid %d",__func__, i_key,i_dmid);
616 dolby_license.dmid = i_dmid;
617 dolby_license.license_key = i_key;
618 if (ds2extnmod.dap_hal_set_hw_info) {
619 ds2extnmod.dap_hal_set_hw_info(DMID, (void*)(&dolby_license.dmid));
620 } else {
Alexy Josephb1379942016-01-29 15:49:38 -0800621 ALOGE("%s: dap_hal_set_hw_info is NULL", __func__);
Ashish Jainedb6a912014-10-16 13:56:28 +0530622 }
Alexy Josephb1379942016-01-29 15:49:38 -0800623 return;
Ashish Jainedb6a912014-10-16 13:56:28 +0530624}
625
626
627void audio_extn_ds2_set_parameters(struct audio_device *adev,
628 struct str_parms *parms)
629{
Sharad Sangle1f705a72016-10-05 20:01:39 +0530630 int ret;
Ashish Jainedb6a912014-10-16 13:56:28 +0530631 char value[32]={0};
632
633 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SND_CARD_STATUS, value,
634 sizeof(value));
635 if (ret >= 0) {
636 char *snd_card_status = value + 2;
637 if (strncmp(snd_card_status, "ONLINE", sizeof("ONLINE")) == 0){
638 audio_extn_dolby_set_license(adev);
639 }
640 }
641}
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700642#endif