blob: 906c23493458fe6f1b3dda5ee556e88cbfbaee75 [file] [log] [blame]
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -08001/*
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302 * Copyright (c) 2011-2017, 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>
Weiyin Jiang2995f662019-04-17 14:25:12 +080025#include <cutils/str_parms.h>
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -080026#include <stdlib.h>
27#include <dlfcn.h>
Weiyin Jiang2995f662019-04-17 14:25:12 +080028#include <log/log.h>
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -080029
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
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053037#ifdef DYNAMIC_LOG_ENABLED
38#include <log_xml_parser.h>
39#define LOG_MASK HAL_MOD_FILE_DOLBY
40#include <log_utils.h>
41#endif
42
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -080043#ifdef DS1_DOLBY_DDP_ENABLED
44
45#define AUDIO_PARAMETER_DDP_DEV "ddp_device"
46#define AUDIO_PARAMETER_DDP_CH_CAP "ddp_chancap"
47#define AUDIO_PARAMETER_DDP_MAX_OUT_CHAN "ddp_maxoutchan"
48#define AUDIO_PARAMETER_DDP_OUT_MODE "ddp_outmode"
49#define AUDIO_PARAMETER_DDP_OUT_LFE_ON "ddp_outlfeon"
50#define AUDIO_PARAMETER_DDP_COMP_MODE "ddp_compmode"
51#define AUDIO_PARAMETER_DDP_STEREO_MODE "ddp_stereomode"
52
53#define PARAM_ID_MAX_OUTPUT_CHANNELS 0x00010DE2
54#define PARAM_ID_CTL_RUNNING_MODE 0x0
55#define PARAM_ID_CTL_ERROR_CONCEAL 0x00010DE3
56#define PARAM_ID_CTL_ERROR_MAX_RPTS 0x00010DE4
57#define PARAM_ID_CNV_ERROR_CONCEAL 0x00010DE5
58#define PARAM_ID_CTL_SUBSTREAM_SELECT 0x00010DE6
59#define PARAM_ID_CTL_INPUT_MODE 0x0
60#define PARAM_ID_OUT_CTL_OUTMODE 0x00010DE0
61#define PARAM_ID_OUT_CTL_OUTLFE_ON 0x00010DE1
62#define PARAM_ID_OUT_CTL_COMPMODE 0x00010D74
63#define PARAM_ID_OUT_CTL_STEREO_MODE 0x00010D76
64#define PARAM_ID_OUT_CTL_DUAL_MODE 0x00010D75
65#define PARAM_ID_OUT_CTL_DRCSCALE_HIGH 0x00010D7A
66#define PARAM_ID_OUT_CTL_DRCSCALE_LOW 0x00010D79
67#define PARAM_ID_OUT_CTL_OUT_PCMSCALE 0x00010D78
68#define PARAM_ID_OUT_CTL_MDCT_BANDLIMIT 0x00010DE7
69#define PARAM_ID_OUT_CTL_DRC_SUPPRESS 0x00010DE8
70
71/* DS1-DDP Endp Params */
72#define DDP_ENDP_NUM_PARAMS 17
Mingming Yin0acba992014-06-02 22:38:35 -070073#define DDP_ENDP_NUM_DEVICES 21
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -080074static int ddp_endp_params_id[DDP_ENDP_NUM_PARAMS] = {
75 PARAM_ID_MAX_OUTPUT_CHANNELS, PARAM_ID_CTL_RUNNING_MODE,
76 PARAM_ID_CTL_ERROR_CONCEAL, PARAM_ID_CTL_ERROR_MAX_RPTS,
77 PARAM_ID_CNV_ERROR_CONCEAL, PARAM_ID_CTL_SUBSTREAM_SELECT,
78 PARAM_ID_CTL_INPUT_MODE, PARAM_ID_OUT_CTL_OUTMODE,
79 PARAM_ID_OUT_CTL_OUTLFE_ON, PARAM_ID_OUT_CTL_COMPMODE,
80 PARAM_ID_OUT_CTL_STEREO_MODE, PARAM_ID_OUT_CTL_DUAL_MODE,
81 PARAM_ID_OUT_CTL_DRCSCALE_HIGH, PARAM_ID_OUT_CTL_DRCSCALE_LOW,
82 PARAM_ID_OUT_CTL_OUT_PCMSCALE, PARAM_ID_OUT_CTL_MDCT_BANDLIMIT,
83 PARAM_ID_OUT_CTL_DRC_SUPPRESS
84};
85
86static struct ddp_endp_params {
87 int device;
88 int dev_ch_cap;
89 int param_val[DDP_ENDP_NUM_PARAMS];
90 bool is_param_valid[DDP_ENDP_NUM_PARAMS];
91} ddp_endp_params[DDP_ENDP_NUM_DEVICES] = {
92 {AUDIO_DEVICE_OUT_EARPIECE, 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_SPEAKER, 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_WIRED_HEADSET, 2,
99 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 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0, 0, 0, 0, 0, 0, 0},
142 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
143 {AUDIO_DEVICE_OUT_FM, 2,
144 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 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_FM_TX, 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} },
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800149 {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,
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700196 bool set_cache __unused)
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800197{
198 int idx, i;
Manish Dewangan338c50a2017-09-12 15:22:03 +0530199 long ddp_endp_params_data[2*DDP_ENDP_NUM_PARAMS + 1];
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800200 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) ||
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700252 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3) ||
253 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC))) {
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800254 send_ddp_endp_params_stream(usecase->stream.out, ddp_dev,
255 dev_ch_cap, false /* set cache */);
256 }
257 }
258}
259
260void audio_extn_dolby_send_ddp_endp_params(struct audio_device *adev)
261{
262 struct listnode *node;
263 struct audio_usecase *usecase;
264 list_for_each(node, &adev->usecase_list) {
265 usecase = node_to_item(node, struct audio_usecase, list);
266 if ((usecase->type == PCM_PLAYBACK) &&
267 (usecase->devices & AUDIO_DEVICE_OUT_ALL) &&
268 (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
269 ((usecase->stream.out->format == AUDIO_FORMAT_AC3) ||
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700270 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3) ||
271 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC))) {
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800272 /*
273 * Use wfd /hdmi sink channel cap for dolby params if device is wfd
274 * or hdmi. Otherwise use stereo configuration
275 */
276 int channel_cap = usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ?
277 adev->cur_hdmi_channels :
278 usecase->devices & AUDIO_DEVICE_OUT_PROXY ?
279 adev->cur_wfd_channels : 2;
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800280 send_ddp_endp_params_stream(usecase->stream.out, usecase->devices,
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800281 channel_cap, false /* set cache */);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800282 }
283 }
284}
285
286void audio_extn_ddp_set_parameters(struct audio_device *adev,
287 struct str_parms *parms)
288{
289 int ddp_dev, dev_ch_cap;
290 int val, ret;
291 char value[32]={0};
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530292
293 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SND_CARD_STATUS, value,
294 sizeof(value));
295 if (ret >= 0) {
296 char *snd_card_status = value + 2;
297 if (strncmp(snd_card_status, "ONLINE", sizeof("ONLINE")) == 0)
298 audio_extn_dolby_set_license(adev);
299 }
300
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800301 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_DEV, value,
302 sizeof(value));
303 if (ret >= 0) {
304 ddp_dev = atoi(value);
305 if (!(AUDIO_DEVICE_OUT_ALL & ddp_dev))
306 return;
307 } else
308 return;
309
310 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_CH_CAP, value,
311 sizeof(value));
312 if (ret >= 0) {
313 dev_ch_cap = atoi(value);
314 if ((dev_ch_cap != 2) && (dev_ch_cap != 6) && (dev_ch_cap != 8))
315 return;
316 } else
317 return;
318
319 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_MAX_OUT_CHAN, value,
320 sizeof(value));
321 if (ret >= 0) {
322 val = atoi(value);
323 update_ddp_endp_table(ddp_dev, dev_ch_cap,
324 PARAM_ID_MAX_OUTPUT_CHANNELS, val);
325 }
326
327 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_OUT_MODE, value,
328 sizeof(value));
329 if (ret >= 0) {
330 val = atoi(value);
331 update_ddp_endp_table(ddp_dev, dev_ch_cap,
332 PARAM_ID_OUT_CTL_OUTMODE, val);
333 }
334
335 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_OUT_LFE_ON, value,
336 sizeof(value));
337 if (ret >= 0) {
338 val = atoi(value);
339 update_ddp_endp_table(ddp_dev, dev_ch_cap,
340 PARAM_ID_OUT_CTL_OUTLFE_ON, val);
341 }
342
343 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_COMP_MODE, value,
344 sizeof(value));
345 if (ret >= 0) {
346 val = atoi(value);
347 update_ddp_endp_table(ddp_dev, dev_ch_cap,
348 PARAM_ID_OUT_CTL_COMPMODE, val);
349 }
350
351 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_STEREO_MODE, value,
352 sizeof(value));
353 if (ret >= 0) {
354 val = atoi(value);
355 update_ddp_endp_table(ddp_dev, dev_ch_cap,
356 PARAM_ID_OUT_CTL_STEREO_MODE, val);
357 }
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800358 /* TODO: Do we need device channel caps here?
359 * We dont have that information as this is from dolby modules
360 */
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800361 send_ddp_endp_params(adev, ddp_dev, dev_ch_cap);
362}
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700363#endif /* DS1_DOLBY_DDP_ENABLED */
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800364
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800365#ifdef DS1_DOLBY_DAP_ENABLED
366void audio_extn_dolby_set_endpoint(struct audio_device *adev)
367{
368 struct listnode *node;
369 struct audio_usecase *usecase;
370 struct mixer_ctl *ctl;
371 const char *mixer_ctl_name = "DS1 DAP Endpoint";
372 int endpoint = 0, ret;
373 bool send = false;
374
375 list_for_each(node, &adev->usecase_list) {
376 usecase = node_to_item(node, struct audio_usecase, list);
377 if ((usecase->type == PCM_PLAYBACK) &&
378 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY)) {
379 endpoint |= usecase->devices & AUDIO_DEVICE_OUT_ALL;
380 send = true;
381 }
382 }
383 if (!send)
384 return;
385
386 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
387 if (!ctl) {
388 ALOGE("%s: Could not get ctl for mixer cmd - %s",
389 __func__, mixer_ctl_name);
390 return;
391 }
392 ret = mixer_ctl_set_value(ctl, 0, endpoint);
393 if (ret)
394 ALOGE("%s: Dolby set endpint cannot be set error:%d",__func__, ret);
395
396 return;
397}
398#endif /* DS1_DOLBY_DAP_ENABLED */
399
400
401#if defined(DS1_DOLBY_DDP_ENABLED) || defined(DS1_DOLBY_DAP_ENABLED)
402void audio_extn_dolby_set_dmid(struct audio_device *adev)
403{
404 struct listnode *node;
405 struct audio_usecase *usecase;
406 struct mixer_ctl *ctl;
407 const char *mixer_ctl_name = "DS1 Security";
408 char c_dmid[128] = {0};
409 int i_dmid, ret;
410 bool send = false;
411
412 list_for_each(node, &adev->usecase_list) {
413 usecase = node_to_item(node, struct audio_usecase, list);
Mingming Yinc7d048a2014-02-25 13:34:07 -0800414 if (usecase->type == PCM_PLAYBACK)
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800415 send = true;
416 }
417 if (!send)
418 return;
419
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700420 property_get("vendor.audio.dmid",c_dmid,"0");
Ashish Jain1dff3212015-02-10 12:16:48 +0530421 i_dmid = atoll(c_dmid);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800422
423 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
424 if (!ctl) {
425 ALOGE("%s: Could not get ctl for mixer cmd - %s",
426 __func__, mixer_ctl_name);
427 return;
428 }
429 ALOGV("%s Dolby device manufacturer id is:%d",__func__,i_dmid);
430 ret = mixer_ctl_set_value(ctl, 0, i_dmid);
431 if (ret)
432 ALOGE("%s: Dolby DMID cannot be set error:%d",__func__, ret);
433
434 return;
435}
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530436
Ashish Jainedb6a912014-10-16 13:56:28 +0530437#ifndef DS2_DOLBY_DAP_ENABLED
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530438void audio_extn_dolby_set_license(struct audio_device *adev)
439{
440 int ret, key=0;
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530441 struct mixer_ctl *ctl;
442 const char *mixer_ctl_name = "DS1 License";
443
444 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
445 if (!ctl) {
446 ALOGE("%s: Could not get ctl for mixer cmd - %s",
447 __func__, mixer_ctl_name);
448 return;
449 }
450
Ashish Jainedb6a912014-10-16 13:56:28 +0530451#ifdef DOLBY_ACDB_LICENSE
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530452 key = platform_get_meta_info_key_from_list(adev->platform, "dolby");
Ashish Jainedb6a912014-10-16 13:56:28 +0530453#else
454 key = 0;
455#endif
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530456 ALOGV("%s Setting DS1 License, key:0x%x",__func__, key);
457 ret = mixer_ctl_set_value(ctl, 0, key);
458 if (ret)
459 ALOGE("%s: cannot set license, error:%d",__func__, ret);
460
461 return;
462}
Ashish Jainedb6a912014-10-16 13:56:28 +0530463#endif
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800464#endif /* DS1_DOLBY_DDP_ENABLED || DS1_DOLBY_DAP_ENABLED */
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700465
466#ifdef DS2_DOLBY_DAP_ENABLED
467struct ds2_extn_module {
468 void *ds2_handle;
469 dap_hal_set_hw_info_t dap_hal_set_hw_info;
470};
471
472static struct ds2_extn_module ds2extnmod = {
473 .ds2_handle = NULL,
474 .dap_hal_set_hw_info = NULL,
475};
476
477int audio_extn_dap_hal_init(int snd_card) {
Sharad Sangle1f705a72016-10-05 20:01:39 +0530478 int ret = -EINVAL;
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700479 dap_hal_device_be_id_map_t device_be_id_map;
480
481 ALOGV("%s: opening DAP HAL lib\n", __func__);
482 ds2extnmod.ds2_handle = dlopen(LIB_DS2_DAP_HAL, RTLD_NOW);
483 if (ds2extnmod.ds2_handle == NULL) {
484 ALOGE("%s: DLOPEN failed for %s error %s", __func__, LIB_DS2_DAP_HAL,
485 dlerror());
486 goto ret;
487 }
488 ds2extnmod.dap_hal_set_hw_info = (dap_hal_set_hw_info_t)dlsym(ds2extnmod.ds2_handle, SET_HW_INFO_FUNC);
489 if (ds2extnmod.dap_hal_set_hw_info == NULL) {
490 ALOGE("%s: dlsym error %s for %s", __func__, SET_HW_INFO_FUNC,
491 dlerror());
492 goto close;
493 }
494 ds2extnmod.dap_hal_set_hw_info(SND_CARD, (void*)(&snd_card));
495 ALOGV("%s Sound card number is:%d",__func__,snd_card);
496
Alexy Josephb1379942016-01-29 15:49:38 -0800497 platform_get_device_to_be_id_map((int**)&device_be_id_map.device_id_to_be_id,
498 &device_be_id_map.len);
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700499 ds2extnmod.dap_hal_set_hw_info(DEVICE_BE_ID_MAP, (void*)(&device_be_id_map));
500 ALOGV("%s Set be id map len:%d",__func__,device_be_id_map.len);
501 ret = 0;
502 goto ret;
503
504close:
505 dlclose(ds2extnmod.ds2_handle);
506 ds2extnmod.ds2_handle = NULL;
507 ds2extnmod.dap_hal_set_hw_info = NULL;
508ret:
509 return ret;
510}
511
512int audio_extn_dap_hal_deinit() {
513 if (ds2extnmod.ds2_handle != NULL) {
514 dlclose(ds2extnmod.ds2_handle);
515 ds2extnmod.ds2_handle = NULL;
516 }
517 ds2extnmod.dap_hal_set_hw_info = NULL;
518 return 0;
519}
520
521void audio_extn_dolby_ds2_set_endpoint(struct audio_device *adev) {
522 struct listnode *node;
523 struct audio_usecase *usecase;
Sharad Sangle1f705a72016-10-05 20:01:39 +0530524 int endpoint = 0;
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700525 bool send = false;
526
527 list_for_each(node, &adev->usecase_list) {
528 usecase = node_to_item(node, struct audio_usecase, list);
529 if ((usecase->type == PCM_PLAYBACK) &&
530 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY)) {
531 endpoint |= usecase->devices & AUDIO_DEVICE_OUT_ALL;
532 send = true;
533 }
534 }
535 if (!send)
536 return;
537
538 if (ds2extnmod.dap_hal_set_hw_info) {
539 ds2extnmod.dap_hal_set_hw_info(HW_ENDPOINT, (void*)(&endpoint));
540 ALOGE("%s: Dolby set endpint :0x%x",__func__, endpoint);
541 } else {
542 ALOGE("%s: dap_hal_set_hw_info is NULL",__func__);
543 }
544
545 return;
546}
547
548int audio_extn_ds2_enable(struct audio_device *adev) {
549
550 char value[PROPERTY_VALUE_MAX] = {0};
551 bool ds2_enabled = false;
552 const char *mixer_ctl_name = "DS2 OnOff";
553 struct mixer_ctl *ctl;
554
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700555 property_get("vendor.audio.dolby.ds2.enabled", value, NULL);
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700556 ds2_enabled = atoi(value) || !strncmp("true", value, 4);
557
558 ALOGV("%s:", __func__);
559 if(ds2_enabled) {
560 ALOGD("%s:ds2_enabled %d", __func__, ds2_enabled);
561 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
562 if (!ctl) {
563 ALOGE("%s: Could not get ctl for mixer cmd - %s",
564 __func__, mixer_ctl_name);
565 return -EINVAL;
566 }
567
568 if (mixer_ctl_set_value(ctl, 0, ds2_enabled) < 0) {
569 ALOGE("%s: Could not set ds2 enable %d",
570 __func__, ds2_enabled);
571 return -EINVAL;
572 }
573 }
574 return 0;
575}
576
Sharad Sangle1f705a72016-10-05 20:01:39 +0530577int audio_extn_dolby_set_dap_bypass(struct audio_device *adev __unused, int state) {
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700578
579 ALOGV("%s: state %d", __func__, state);
580 if (ds2extnmod.dap_hal_set_hw_info) {
581 ds2extnmod.dap_hal_set_hw_info(DAP_BYPASS, (void*)(&state));
582 ALOGV("%s: Dolby set bypas :0x%x", __func__, state);
583 } else {
584 ALOGV("%s: dap_hal_set_hw_info is NULL", __func__);
585 }
586 return 0;
587}
Ashish Jainedb6a912014-10-16 13:56:28 +0530588
Sharad Sangle1f705a72016-10-05 20:01:39 +0530589void audio_extn_dolby_set_license(struct audio_device *adev __unused)
Ashish Jainedb6a912014-10-16 13:56:28 +0530590{
591 int i_key=0;
Ashish Jainedb6a912014-10-16 13:56:28 +0530592 char c_dmid[128] = {0};
Sharad Sangle1f705a72016-10-05 20:01:39 +0530593 int i_dmid;
Ashish Jainedb6a912014-10-16 13:56:28 +0530594 struct dolby_param_license dolby_license;
595
596#ifdef DOLBY_ACDB_LICENSE
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530597 i_key = platform_get_meta_info_key_from_list(adev->platform, "dolby");
Ashish Jainedb6a912014-10-16 13:56:28 +0530598#else
599 /* As ACDB based license mechanism is disabled, force set the license key to 0*/
600 i_key = 0;
601#endif
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700602 property_get("vendor.audio.dmid",c_dmid,"0");
Ashish Jain1dff3212015-02-10 12:16:48 +0530603 i_dmid = atoll(c_dmid);
Ashish Jainedb6a912014-10-16 13:56:28 +0530604 ALOGV("%s Setting DS1 License, key:0x%x dmid %d",__func__, i_key,i_dmid);
605 dolby_license.dmid = i_dmid;
606 dolby_license.license_key = i_key;
607 if (ds2extnmod.dap_hal_set_hw_info) {
608 ds2extnmod.dap_hal_set_hw_info(DMID, (void*)(&dolby_license.dmid));
609 } else {
Alexy Josephb1379942016-01-29 15:49:38 -0800610 ALOGE("%s: dap_hal_set_hw_info is NULL", __func__);
Ashish Jainedb6a912014-10-16 13:56:28 +0530611 }
Alexy Josephb1379942016-01-29 15:49:38 -0800612 return;
Ashish Jainedb6a912014-10-16 13:56:28 +0530613}
614
615
616void audio_extn_ds2_set_parameters(struct audio_device *adev,
617 struct str_parms *parms)
618{
Sharad Sangle1f705a72016-10-05 20:01:39 +0530619 int ret;
Ashish Jainedb6a912014-10-16 13:56:28 +0530620 char value[32]={0};
621
622 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SND_CARD_STATUS, value,
623 sizeof(value));
624 if (ret >= 0) {
625 char *snd_card_status = value + 2;
626 if (strncmp(snd_card_status, "ONLINE", sizeof("ONLINE")) == 0){
627 audio_extn_dolby_set_license(adev);
628 }
629 }
630}
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700631#endif