blob: 1471213228756a373e45acc352422d7cc81180e7 [file] [log] [blame]
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -08001/*
Aniket Kumar Lata0e6e1e52019-11-14 21:43:55 -08002 * Copyright (c) 2011-2017, 2020, 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
Aniket Kumar Lata544846d2019-12-09 12:56:29 -080073#define DDP_ENDP_NUM_DEVICES 20
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} },
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800146 {AUDIO_DEVICE_OUT_PROXY, 2,
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800147 {8, 0, 0, 0, 0, 0, 0, 21, 1, 2, 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, 6,
150 {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 -0800151 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
152};
153
154int update_ddp_endp_table(int device, int dev_ch_cap, int param_id,
155 int param_val)
156{
157 int idx = 0;
158 int param_idx = 0;
159 ALOGV("%s: dev 0x%x dev_ch_cap %d param_id 0x%x param_val %d",
160 __func__, device, dev_ch_cap , param_id, param_val);
161
162 for(idx=0; idx<DDP_ENDP_NUM_DEVICES; idx++) {
163 if(ddp_endp_params[idx].device == device) {
164 if(ddp_endp_params[idx].dev_ch_cap == dev_ch_cap) {
165 break;
166 }
167 }
168 }
169
170 if(idx>=DDP_ENDP_NUM_DEVICES) {
171 ALOGE("%s: device not available in DDP endp config table", __func__);
172 return -EINVAL;
173 }
174
175 for(param_idx=0; param_idx<DDP_ENDP_NUM_PARAMS; param_idx++) {
176 if (ddp_endp_params_id[param_idx] == param_id) {
177 break;
178 }
179 }
180
181 if(param_idx>=DDP_ENDP_NUM_PARAMS) {
182 ALOGE("param not available in DDP endp config table");
183 return -EINVAL;
184 }
185
186 ALOGV("ddp_endp_params[%d].param_val[%d] = %d", idx, param_idx, param_val);
187 ddp_endp_params[idx].param_val[param_idx] = param_val;
188 return 0;
189}
190
191void send_ddp_endp_params_stream(struct stream_out *out,
192 int device, int dev_ch_cap,
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700193 bool set_cache __unused)
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800194{
195 int idx, i;
Manish Dewangan338c50a2017-09-12 15:22:03 +0530196 long ddp_endp_params_data[2*DDP_ENDP_NUM_PARAMS + 1];
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800197 int length = 0;
198 for(idx=0; idx<DDP_ENDP_NUM_DEVICES; idx++) {
199 if(ddp_endp_params[idx].device & device) {
200 if(ddp_endp_params[idx].dev_ch_cap == dev_ch_cap) {
201 break;
202 }
203 }
204 }
205 if(idx>=DDP_ENDP_NUM_DEVICES) {
206 ALOGE("device not available in DDP endp config table");
207 return;
208 }
209
210 length += 1; /* offset 0 is for num of parameter. increase offset by 1 */
211 for (i=0; i<DDP_ENDP_NUM_PARAMS; i++) {
212 if(ddp_endp_params[idx].is_param_valid[i]) {
213 ddp_endp_params_data[length++] = ddp_endp_params_id[i];
214 ddp_endp_params_data[length++] = ddp_endp_params[idx].param_val[i];
215 }
216 }
217 ddp_endp_params_data[0] = (length-1)/2;
218 if(length) {
219 char mixer_ctl_name[128];
220 struct audio_device *adev = out->dev;
221 struct mixer_ctl *ctl;
222 int pcm_device_id = platform_get_pcm_device_id(out->usecase,
223 PCM_PLAYBACK);
224 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
225 "Audio Stream %d Dec Params", pcm_device_id);
226 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
227 if (!ctl) {
228 ALOGE("%s: Could not get ctl for mixer cmd - %s",
229 __func__, mixer_ctl_name);
230 return;
231 }
232 mixer_ctl_set_array(ctl, ddp_endp_params_data, length);
233 }
234 return;
235}
236
237void send_ddp_endp_params(struct audio_device *adev,
238 int ddp_dev, int dev_ch_cap)
239{
240 struct listnode *node;
241 struct audio_usecase *usecase;
242
243 list_for_each(node, &adev->usecase_list) {
244 usecase = node_to_item(node, struct audio_usecase, list);
Sujin Panicker390724d2019-04-26 10:43:36 +0530245 if (usecase->stream.out && (usecase->type == PCM_PLAYBACK) &&
Aniket Kumar Lata0e6e1e52019-11-14 21:43:55 -0800246 (compare_device_type(&usecase->device_list, ddp_dev)) &&
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800247 (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
248 ((usecase->stream.out->format == AUDIO_FORMAT_AC3) ||
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700249 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3) ||
250 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC))) {
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800251 send_ddp_endp_params_stream(usecase->stream.out, ddp_dev,
252 dev_ch_cap, false /* set cache */);
253 }
254 }
255}
256
257void audio_extn_dolby_send_ddp_endp_params(struct audio_device *adev)
258{
259 struct listnode *node;
260 struct audio_usecase *usecase;
261 list_for_each(node, &adev->usecase_list) {
262 usecase = node_to_item(node, struct audio_usecase, list);
Sujin Panicker390724d2019-04-26 10:43:36 +0530263 if (usecase->stream.out && (usecase->type == PCM_PLAYBACK) &&
Aniket Kumar Lata0e6e1e52019-11-14 21:43:55 -0800264 is_audio_out_device_type(&usecase->device_list) &&
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800265 (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
266 ((usecase->stream.out->format == AUDIO_FORMAT_AC3) ||
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700267 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3) ||
268 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC))) {
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800269 /*
270 * Use wfd /hdmi sink channel cap for dolby params if device is wfd
271 * or hdmi. Otherwise use stereo configuration
272 */
Aniket Kumar Lata0e6e1e52019-11-14 21:43:55 -0800273 int channel_cap = compare_device_type(&usecase->device_list,
274 AUDIO_DEVICE_OUT_AUX_DIGITAL) ?
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800275 adev->cur_hdmi_channels :
Aniket Kumar Lata0e6e1e52019-11-14 21:43:55 -0800276 compare_device_type(&usecase->device_list,
277 AUDIO_DEVICE_OUT_PROXY) ?
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800278 adev->cur_wfd_channels : 2;
Aniket Kumar Lata0e6e1e52019-11-14 21:43:55 -0800279 send_ddp_endp_params_stream(usecase->stream.out,
280 get_device_types(&usecase->device_list),
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);
Aniket Kumar Lata0e6e1e52019-11-14 21:43:55 -0800305 if (!audio_is_output_device(ddp_dev))
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800306 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;
Aniket Kumar Lata9c2fd892020-01-22 22:20:00 -0800370 struct listnode devices;
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800371 struct mixer_ctl *ctl;
372 const char *mixer_ctl_name = "DS1 DAP Endpoint";
373 int endpoint = 0, ret;
374 bool send = false;
375
Aniket Kumar Lata9c2fd892020-01-22 22:20:00 -0800376 list_init(&devices);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800377 list_for_each(node, &adev->usecase_list) {
378 usecase = node_to_item(node, struct audio_usecase, list);
379 if ((usecase->type == PCM_PLAYBACK) &&
380 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY)) {
Aniket Kumar Lata9c2fd892020-01-22 22:20:00 -0800381 append_devices(&devices, &usecase->device_list);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800382 send = true;
383 }
384 }
385 if (!send)
386 return;
387
388 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
389 if (!ctl) {
390 ALOGE("%s: Could not get ctl for mixer cmd - %s",
391 __func__, mixer_ctl_name);
392 return;
393 }
Aniket Kumar Lata9c2fd892020-01-22 22:20:00 -0800394 // FIXME: It is not recommended to store more than one device on bitfields
395 // This handling should be updated here and in driver code.
396 endpoint = get_device_types(&devices);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800397 ret = mixer_ctl_set_value(ctl, 0, endpoint);
398 if (ret)
399 ALOGE("%s: Dolby set endpint cannot be set error:%d",__func__, ret);
400
401 return;
402}
403#endif /* DS1_DOLBY_DAP_ENABLED */
404
405
406#if defined(DS1_DOLBY_DDP_ENABLED) || defined(DS1_DOLBY_DAP_ENABLED)
407void audio_extn_dolby_set_dmid(struct audio_device *adev)
408{
409 struct listnode *node;
410 struct audio_usecase *usecase;
411 struct mixer_ctl *ctl;
412 const char *mixer_ctl_name = "DS1 Security";
413 char c_dmid[128] = {0};
414 int i_dmid, ret;
415 bool send = false;
416
417 list_for_each(node, &adev->usecase_list) {
418 usecase = node_to_item(node, struct audio_usecase, list);
Mingming Yinc7d048a2014-02-25 13:34:07 -0800419 if (usecase->type == PCM_PLAYBACK)
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800420 send = true;
421 }
422 if (!send)
423 return;
424
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700425 property_get("vendor.audio.dmid",c_dmid,"0");
Ashish Jain1dff3212015-02-10 12:16:48 +0530426 i_dmid = atoll(c_dmid);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800427
428 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
429 if (!ctl) {
430 ALOGE("%s: Could not get ctl for mixer cmd - %s",
431 __func__, mixer_ctl_name);
432 return;
433 }
434 ALOGV("%s Dolby device manufacturer id is:%d",__func__,i_dmid);
435 ret = mixer_ctl_set_value(ctl, 0, i_dmid);
436 if (ret)
437 ALOGE("%s: Dolby DMID cannot be set error:%d",__func__, ret);
438
439 return;
440}
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530441
Ashish Jainedb6a912014-10-16 13:56:28 +0530442#ifndef DS2_DOLBY_DAP_ENABLED
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530443void audio_extn_dolby_set_license(struct audio_device *adev)
444{
445 int ret, key=0;
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530446 struct mixer_ctl *ctl;
447 const char *mixer_ctl_name = "DS1 License";
448
449 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
450 if (!ctl) {
451 ALOGE("%s: Could not get ctl for mixer cmd - %s",
452 __func__, mixer_ctl_name);
453 return;
454 }
455
Ashish Jainedb6a912014-10-16 13:56:28 +0530456#ifdef DOLBY_ACDB_LICENSE
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530457 key = platform_get_meta_info_key_from_list(adev->platform, "dolby");
Ashish Jainedb6a912014-10-16 13:56:28 +0530458#else
459 key = 0;
460#endif
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530461 ALOGV("%s Setting DS1 License, key:0x%x",__func__, key);
462 ret = mixer_ctl_set_value(ctl, 0, key);
463 if (ret)
464 ALOGE("%s: cannot set license, error:%d",__func__, ret);
465
466 return;
467}
Ashish Jainedb6a912014-10-16 13:56:28 +0530468#endif
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800469#endif /* DS1_DOLBY_DDP_ENABLED || DS1_DOLBY_DAP_ENABLED */
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700470
471#ifdef DS2_DOLBY_DAP_ENABLED
472struct ds2_extn_module {
473 void *ds2_handle;
474 dap_hal_set_hw_info_t dap_hal_set_hw_info;
475};
476
477static struct ds2_extn_module ds2extnmod = {
478 .ds2_handle = NULL,
479 .dap_hal_set_hw_info = NULL,
480};
481
482int audio_extn_dap_hal_init(int snd_card) {
Sharad Sangle1f705a72016-10-05 20:01:39 +0530483 int ret = -EINVAL;
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700484 dap_hal_device_be_id_map_t device_be_id_map;
485
486 ALOGV("%s: opening DAP HAL lib\n", __func__);
487 ds2extnmod.ds2_handle = dlopen(LIB_DS2_DAP_HAL, RTLD_NOW);
488 if (ds2extnmod.ds2_handle == NULL) {
489 ALOGE("%s: DLOPEN failed for %s error %s", __func__, LIB_DS2_DAP_HAL,
490 dlerror());
491 goto ret;
492 }
493 ds2extnmod.dap_hal_set_hw_info = (dap_hal_set_hw_info_t)dlsym(ds2extnmod.ds2_handle, SET_HW_INFO_FUNC);
494 if (ds2extnmod.dap_hal_set_hw_info == NULL) {
495 ALOGE("%s: dlsym error %s for %s", __func__, SET_HW_INFO_FUNC,
496 dlerror());
497 goto close;
498 }
499 ds2extnmod.dap_hal_set_hw_info(SND_CARD, (void*)(&snd_card));
500 ALOGV("%s Sound card number is:%d",__func__,snd_card);
501
Alexy Josephb1379942016-01-29 15:49:38 -0800502 platform_get_device_to_be_id_map((int**)&device_be_id_map.device_id_to_be_id,
503 &device_be_id_map.len);
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700504 ds2extnmod.dap_hal_set_hw_info(DEVICE_BE_ID_MAP, (void*)(&device_be_id_map));
505 ALOGV("%s Set be id map len:%d",__func__,device_be_id_map.len);
506 ret = 0;
507 goto ret;
508
509close:
510 dlclose(ds2extnmod.ds2_handle);
511 ds2extnmod.ds2_handle = NULL;
512 ds2extnmod.dap_hal_set_hw_info = NULL;
513ret:
514 return ret;
515}
516
517int audio_extn_dap_hal_deinit() {
518 if (ds2extnmod.ds2_handle != NULL) {
519 dlclose(ds2extnmod.ds2_handle);
520 ds2extnmod.ds2_handle = NULL;
521 }
522 ds2extnmod.dap_hal_set_hw_info = NULL;
523 return 0;
524}
525
526void audio_extn_dolby_ds2_set_endpoint(struct audio_device *adev) {
527 struct listnode *node;
528 struct audio_usecase *usecase;
Aniket Kumar Lata9c2fd892020-01-22 22:20:00 -0800529 struct listnode devices;
Sharad Sangle1f705a72016-10-05 20:01:39 +0530530 int endpoint = 0;
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700531 bool send = false;
532
Aniket Kumar Lata9c2fd892020-01-22 22:20:00 -0800533 list_init(&devices);
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700534 list_for_each(node, &adev->usecase_list) {
535 usecase = node_to_item(node, struct audio_usecase, list);
536 if ((usecase->type == PCM_PLAYBACK) &&
537 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY)) {
Aniket Kumar Lata9c2fd892020-01-22 22:20:00 -0800538 append_devices(&devices, &usecase->device_list);
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700539 send = true;
540 }
541 }
542 if (!send)
543 return;
544
Aniket Kumar Lata9c2fd892020-01-22 22:20:00 -0800545 // FIXME: It is not recommended to store more than one device on bitfields
546 // This handling should be updated here and in driver code.
547 endpoint = get_device_types(&devices);
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700548 if (ds2extnmod.dap_hal_set_hw_info) {
549 ds2extnmod.dap_hal_set_hw_info(HW_ENDPOINT, (void*)(&endpoint));
550 ALOGE("%s: Dolby set endpint :0x%x",__func__, endpoint);
551 } else {
552 ALOGE("%s: dap_hal_set_hw_info is NULL",__func__);
553 }
554
555 return;
556}
557
558int audio_extn_ds2_enable(struct audio_device *adev) {
559
560 char value[PROPERTY_VALUE_MAX] = {0};
561 bool ds2_enabled = false;
562 const char *mixer_ctl_name = "DS2 OnOff";
563 struct mixer_ctl *ctl;
564
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700565 property_get("vendor.audio.dolby.ds2.enabled", value, NULL);
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700566 ds2_enabled = atoi(value) || !strncmp("true", value, 4);
567
568 ALOGV("%s:", __func__);
569 if(ds2_enabled) {
570 ALOGD("%s:ds2_enabled %d", __func__, ds2_enabled);
571 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
572 if (!ctl) {
573 ALOGE("%s: Could not get ctl for mixer cmd - %s",
574 __func__, mixer_ctl_name);
575 return -EINVAL;
576 }
577
578 if (mixer_ctl_set_value(ctl, 0, ds2_enabled) < 0) {
579 ALOGE("%s: Could not set ds2 enable %d",
580 __func__, ds2_enabled);
581 return -EINVAL;
582 }
583 }
584 return 0;
585}
586
Sharad Sangle1f705a72016-10-05 20:01:39 +0530587int audio_extn_dolby_set_dap_bypass(struct audio_device *adev __unused, int state) {
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700588
589 ALOGV("%s: state %d", __func__, state);
590 if (ds2extnmod.dap_hal_set_hw_info) {
591 ds2extnmod.dap_hal_set_hw_info(DAP_BYPASS, (void*)(&state));
592 ALOGV("%s: Dolby set bypas :0x%x", __func__, state);
593 } else {
594 ALOGV("%s: dap_hal_set_hw_info is NULL", __func__);
595 }
596 return 0;
597}
Ashish Jainedb6a912014-10-16 13:56:28 +0530598
Sharad Sangle1f705a72016-10-05 20:01:39 +0530599void audio_extn_dolby_set_license(struct audio_device *adev __unused)
Ashish Jainedb6a912014-10-16 13:56:28 +0530600{
601 int i_key=0;
Ashish Jainedb6a912014-10-16 13:56:28 +0530602 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
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530607 i_key = platform_get_meta_info_key_from_list(adev->platform, "dolby");
Ashish Jainedb6a912014-10-16 13:56:28 +0530608#else
609 /* As ACDB based license mechanism is disabled, force set the license key to 0*/
610 i_key = 0;
611#endif
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700612 property_get("vendor.audio.dmid",c_dmid,"0");
Ashish Jain1dff3212015-02-10 12:16:48 +0530613 i_dmid = atoll(c_dmid);
Ashish Jainedb6a912014-10-16 13:56:28 +0530614 ALOGV("%s Setting DS1 License, key:0x%x dmid %d",__func__, i_key,i_dmid);
615 dolby_license.dmid = i_dmid;
616 dolby_license.license_key = i_key;
617 if (ds2extnmod.dap_hal_set_hw_info) {
618 ds2extnmod.dap_hal_set_hw_info(DMID, (void*)(&dolby_license.dmid));
619 } else {
Alexy Josephb1379942016-01-29 15:49:38 -0800620 ALOGE("%s: dap_hal_set_hw_info is NULL", __func__);
Ashish Jainedb6a912014-10-16 13:56:28 +0530621 }
Alexy Josephb1379942016-01-29 15:49:38 -0800622 return;
Ashish Jainedb6a912014-10-16 13:56:28 +0530623}
624
625
626void audio_extn_ds2_set_parameters(struct audio_device *adev,
627 struct str_parms *parms)
628{
Sharad Sangle1f705a72016-10-05 20:01:39 +0530629 int ret;
Ashish Jainedb6a912014-10-16 13:56:28 +0530630 char value[32]={0};
631
632 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SND_CARD_STATUS, value,
633 sizeof(value));
634 if (ret >= 0) {
635 char *snd_card_status = value + 2;
636 if (strncmp(snd_card_status, "ONLINE", sizeof("ONLINE")) == 0){
637 audio_extn_dolby_set_license(adev);
638 }
639 }
640}
Pradnya Chaphekar659affa2014-09-09 09:49:10 -0700641#endif