blob: 650104c280672a274fd2b4baf7d3657da81446f2 [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
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, 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, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
104 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT, 2,
105 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
106 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
107 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP, 2,
108 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
109 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
110 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES, 2,
111 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
112 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
113 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER, 2,
114 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
115 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
116 {AUDIO_DEVICE_OUT_AUX_DIGITAL, 2,
117 {8, 0, 0, 0, 0, 0, 0, 21, 1, 2, 0, 0, 0, 0, 0, 0, 0},
118 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
119 {AUDIO_DEVICE_OUT_AUX_DIGITAL, 6,
120 {8, 0, 0, 0, 0, 0, 0, 21, 1, 2, 0, 0, 0, 0, 0, 0, 0},
121 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
122 {AUDIO_DEVICE_OUT_AUX_DIGITAL, 8,
123 {8, 0, 0, 0, 0, 0, 0, 21, 1, 2, 0, 0, 0, 0, 0, 0, 0},
124 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
125 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET, 2,
126 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
127 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
128 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET, 2,
129 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
130 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
131 {AUDIO_DEVICE_OUT_USB_ACCESSORY, 2,
132 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
133 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
134 {AUDIO_DEVICE_OUT_USB_DEVICE, 2,
135 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
136 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
137 {AUDIO_DEVICE_OUT_FM, 2,
138 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
139 {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
140 {AUDIO_DEVICE_OUT_FM_TX, 2,
141 {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 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} },
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,
190 bool set_cache)
191{
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) ||
Mingming Yinae3530f2014-07-03 16:50:18 -0700246 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3))) {
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800247 send_ddp_endp_params_stream(usecase->stream.out, ddp_dev,
248 dev_ch_cap, false /* set cache */);
249 }
250 }
251}
252
253void audio_extn_dolby_send_ddp_endp_params(struct audio_device *adev)
254{
255 struct listnode *node;
256 struct audio_usecase *usecase;
257 list_for_each(node, &adev->usecase_list) {
258 usecase = node_to_item(node, struct audio_usecase, list);
259 if ((usecase->type == PCM_PLAYBACK) &&
260 (usecase->devices & AUDIO_DEVICE_OUT_ALL) &&
261 (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
262 ((usecase->stream.out->format == AUDIO_FORMAT_AC3) ||
Mingming Yinae3530f2014-07-03 16:50:18 -0700263 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3))) {
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800264 /*
265 * Use wfd /hdmi sink channel cap for dolby params if device is wfd
266 * or hdmi. Otherwise use stereo configuration
267 */
268 int channel_cap = usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ?
269 adev->cur_hdmi_channels :
270 usecase->devices & AUDIO_DEVICE_OUT_PROXY ?
271 adev->cur_wfd_channels : 2;
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800272 send_ddp_endp_params_stream(usecase->stream.out, usecase->devices,
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800273 channel_cap, false /* set cache */);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800274 }
275 }
276}
277
278void audio_extn_ddp_set_parameters(struct audio_device *adev,
279 struct str_parms *parms)
280{
281 int ddp_dev, dev_ch_cap;
282 int val, ret;
283 char value[32]={0};
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530284
285 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SND_CARD_STATUS, value,
286 sizeof(value));
287 if (ret >= 0) {
288 char *snd_card_status = value + 2;
289 if (strncmp(snd_card_status, "ONLINE", sizeof("ONLINE")) == 0)
290 audio_extn_dolby_set_license(adev);
291 }
292
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800293 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_DEV, value,
294 sizeof(value));
295 if (ret >= 0) {
296 ddp_dev = atoi(value);
297 if (!(AUDIO_DEVICE_OUT_ALL & ddp_dev))
298 return;
299 } else
300 return;
301
302 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_CH_CAP, value,
303 sizeof(value));
304 if (ret >= 0) {
305 dev_ch_cap = atoi(value);
306 if ((dev_ch_cap != 2) && (dev_ch_cap != 6) && (dev_ch_cap != 8))
307 return;
308 } else
309 return;
310
311 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_MAX_OUT_CHAN, value,
312 sizeof(value));
313 if (ret >= 0) {
314 val = atoi(value);
315 update_ddp_endp_table(ddp_dev, dev_ch_cap,
316 PARAM_ID_MAX_OUTPUT_CHANNELS, val);
317 }
318
319 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_OUT_MODE, 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_OUT_CTL_OUTMODE, val);
325 }
326
327 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_OUT_LFE_ON, 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_OUTLFE_ON, val);
333 }
334
335 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_COMP_MODE, 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_COMPMODE, val);
341 }
342
343 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_STEREO_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_STEREO_MODE, val);
349 }
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800350 /* TODO: Do we need device channel caps here?
351 * We dont have that information as this is from dolby modules
352 */
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800353 send_ddp_endp_params(adev, ddp_dev, dev_ch_cap);
354}
355
356int audio_extn_dolby_get_snd_codec_id(struct audio_device *adev,
357 struct stream_out *out,
358 audio_format_t format)
359{
360 int id = 0;
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800361 /*
362 * Use wfd /hdmi sink channel cap for dolby params if device is wfd
363 * or hdmi. Otherwise use stereo configuration
364 */
365 int channel_cap = out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ?
366 adev->cur_hdmi_channels :
367 out->devices & AUDIO_DEVICE_OUT_PROXY ?
368 adev->cur_wfd_channels : 2;
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800369
370 switch (format) {
371 case AUDIO_FORMAT_AC3:
372 id = SND_AUDIOCODEC_AC3;
373 send_ddp_endp_params_stream(out, out->devices,
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800374 channel_cap, true /* set_cache */);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800375#ifndef DS1_DOLBY_DAP_ENABLED
376 audio_extn_dolby_set_dmid(adev);
377#endif
378 break;
Mingming Yinae3530f2014-07-03 16:50:18 -0700379 case AUDIO_FORMAT_E_AC3:
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800380 id = SND_AUDIOCODEC_EAC3;
381 send_ddp_endp_params_stream(out, out->devices,
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800382 channel_cap, true /* set_cache */);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800383#ifndef DS1_DOLBY_DAP_ENABLED
384 audio_extn_dolby_set_dmid(adev);
385#endif
386 break;
387 default:
388 ALOGE("%s: Unsupported audio format :%x", __func__, format);
389 }
390
391 return id;
392}
393
394bool audio_extn_is_dolby_format(audio_format_t format)
395{
396 if (format == AUDIO_FORMAT_AC3 ||
Mingming Yinae3530f2014-07-03 16:50:18 -0700397 format == AUDIO_FORMAT_E_AC3)
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800398 return true;
399 else
400 return false;
401}
402
403#endif /* DS1_DOLBY_DDP_ENABLED */
404
405#ifdef DS1_DOLBY_DAP_ENABLED
406void audio_extn_dolby_set_endpoint(struct audio_device *adev)
407{
408 struct listnode *node;
409 struct audio_usecase *usecase;
410 struct mixer_ctl *ctl;
411 const char *mixer_ctl_name = "DS1 DAP Endpoint";
412 int endpoint = 0, ret;
413 bool send = false;
414
415 list_for_each(node, &adev->usecase_list) {
416 usecase = node_to_item(node, struct audio_usecase, list);
417 if ((usecase->type == PCM_PLAYBACK) &&
418 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY)) {
419 endpoint |= usecase->devices & AUDIO_DEVICE_OUT_ALL;
420 send = true;
421 }
422 }
423 if (!send)
424 return;
425
426 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
427 if (!ctl) {
428 ALOGE("%s: Could not get ctl for mixer cmd - %s",
429 __func__, mixer_ctl_name);
430 return;
431 }
432 ret = mixer_ctl_set_value(ctl, 0, endpoint);
433 if (ret)
434 ALOGE("%s: Dolby set endpint cannot be set error:%d",__func__, ret);
435
436 return;
437}
438#endif /* DS1_DOLBY_DAP_ENABLED */
439
440
441#if defined(DS1_DOLBY_DDP_ENABLED) || defined(DS1_DOLBY_DAP_ENABLED)
442void audio_extn_dolby_set_dmid(struct audio_device *adev)
443{
444 struct listnode *node;
445 struct audio_usecase *usecase;
446 struct mixer_ctl *ctl;
447 const char *mixer_ctl_name = "DS1 Security";
448 char c_dmid[128] = {0};
449 int i_dmid, ret;
450 bool send = false;
451
452 list_for_each(node, &adev->usecase_list) {
453 usecase = node_to_item(node, struct audio_usecase, list);
Mingming Yinc7d048a2014-02-25 13:34:07 -0800454 if (usecase->type == PCM_PLAYBACK)
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800455 send = true;
456 }
457 if (!send)
458 return;
459
460 property_get("dmid",c_dmid,"0");
461 i_dmid = atoi(c_dmid);
462
463 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
464 if (!ctl) {
465 ALOGE("%s: Could not get ctl for mixer cmd - %s",
466 __func__, mixer_ctl_name);
467 return;
468 }
469 ALOGV("%s Dolby device manufacturer id is:%d",__func__,i_dmid);
470 ret = mixer_ctl_set_value(ctl, 0, i_dmid);
471 if (ret)
472 ALOGE("%s: Dolby DMID cannot be set error:%d",__func__, ret);
473
474 return;
475}
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530476
477void audio_extn_dolby_set_license(struct audio_device *adev)
478{
479 int ret, key=0;
480 char value[128] = {0};
481 struct mixer_ctl *ctl;
482 const char *mixer_ctl_name = "DS1 License";
483
484 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
485 if (!ctl) {
486 ALOGE("%s: Could not get ctl for mixer cmd - %s",
487 __func__, mixer_ctl_name);
488 return;
489 }
490
491 property_get("audio.ds1.metainfo.key",value,"0");
492 key = atoi(value);
493
494 ALOGV("%s Setting DS1 License, key:0x%x",__func__, key);
495 ret = mixer_ctl_set_value(ctl, 0, key);
496 if (ret)
497 ALOGE("%s: cannot set license, error:%d",__func__, ret);
498
499 return;
500}
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800501#endif /* DS1_DOLBY_DDP_ENABLED || DS1_DOLBY_DAP_ENABLED */