blob: 8670367ed6203ad22a0f518b0e6029f61dd634c7 [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,
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 Chaphekar8a9dcd82014-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 Chaphekar8a9dcd82014-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 Chaphekar8a9dcd82014-09-09 09:49:10 -0700357#endif /* DS1_DOLBY_DDP_ENABLED */
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800358
Pradnya Chaphekar8a9dcd82014-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 -0800360int audio_extn_dolby_get_snd_codec_id(struct audio_device *adev,
361 struct stream_out *out,
362 audio_format_t format)
363{
364 int id = 0;
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800365 /*
366 * Use wfd /hdmi sink channel cap for dolby params if device is wfd
367 * or hdmi. Otherwise use stereo configuration
368 */
369 int channel_cap = out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ?
370 adev->cur_hdmi_channels :
371 out->devices & AUDIO_DEVICE_OUT_PROXY ?
372 adev->cur_wfd_channels : 2;
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800373
374 switch (format) {
375 case AUDIO_FORMAT_AC3:
376 id = SND_AUDIOCODEC_AC3;
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700377#ifdef DS1_DOLBY_DDP_ENABLED
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800378 send_ddp_endp_params_stream(out, out->devices,
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -0800379 channel_cap, true /* set_cache */);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800380#endif
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700381 audio_extn_dolby_set_dmid(adev);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800382 break;
Mingming Yinae3530f2014-07-03 16:50:18 -0700383 case AUDIO_FORMAT_E_AC3:
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700384 case AUDIO_FORMAT_E_AC3_JOC:
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800385 id = SND_AUDIOCODEC_EAC3;
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700386#ifdef DS1_DOLBY_DDP_ENABLED
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800387 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#endif
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700390 audio_extn_dolby_set_dmid(adev);
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800391 break;
392 default:
393 ALOGE("%s: Unsupported audio format :%x", __func__, format);
394 }
395
396 return id;
397}
398
399bool audio_extn_is_dolby_format(audio_format_t format)
400{
401 if (format == AUDIO_FORMAT_AC3 ||
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700402 format == AUDIO_FORMAT_E_AC3 ||
403 format == AUDIO_FORMAT_E_AC3_JOC)
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800404 return true;
405 else
406 return false;
407}
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700408#endif /* DS1_DOLBY_DDP_ENABLED || DS2_DOLBY_DAP_ENABLED */
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800409
410#ifdef DS1_DOLBY_DAP_ENABLED
411void audio_extn_dolby_set_endpoint(struct audio_device *adev)
412{
413 struct listnode *node;
414 struct audio_usecase *usecase;
415 struct mixer_ctl *ctl;
416 const char *mixer_ctl_name = "DS1 DAP Endpoint";
417 int endpoint = 0, ret;
418 bool send = false;
419
420 list_for_each(node, &adev->usecase_list) {
421 usecase = node_to_item(node, struct audio_usecase, list);
422 if ((usecase->type == PCM_PLAYBACK) &&
423 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY)) {
424 endpoint |= usecase->devices & AUDIO_DEVICE_OUT_ALL;
425 send = true;
426 }
427 }
428 if (!send)
429 return;
430
431 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
432 if (!ctl) {
433 ALOGE("%s: Could not get ctl for mixer cmd - %s",
434 __func__, mixer_ctl_name);
435 return;
436 }
437 ret = mixer_ctl_set_value(ctl, 0, endpoint);
438 if (ret)
439 ALOGE("%s: Dolby set endpint cannot be set error:%d",__func__, ret);
440
441 return;
442}
443#endif /* DS1_DOLBY_DAP_ENABLED */
444
445
446#if defined(DS1_DOLBY_DDP_ENABLED) || defined(DS1_DOLBY_DAP_ENABLED)
447void audio_extn_dolby_set_dmid(struct audio_device *adev)
448{
449 struct listnode *node;
450 struct audio_usecase *usecase;
451 struct mixer_ctl *ctl;
452 const char *mixer_ctl_name = "DS1 Security";
453 char c_dmid[128] = {0};
454 int i_dmid, ret;
455 bool send = false;
456
457 list_for_each(node, &adev->usecase_list) {
458 usecase = node_to_item(node, struct audio_usecase, list);
Mingming Yinc7d048a2014-02-25 13:34:07 -0800459 if (usecase->type == PCM_PLAYBACK)
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800460 send = true;
461 }
462 if (!send)
463 return;
464
465 property_get("dmid",c_dmid,"0");
466 i_dmid = atoi(c_dmid);
467
468 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
469 if (!ctl) {
470 ALOGE("%s: Could not get ctl for mixer cmd - %s",
471 __func__, mixer_ctl_name);
472 return;
473 }
474 ALOGV("%s Dolby device manufacturer id is:%d",__func__,i_dmid);
475 ret = mixer_ctl_set_value(ctl, 0, i_dmid);
476 if (ret)
477 ALOGE("%s: Dolby DMID cannot be set error:%d",__func__, ret);
478
479 return;
480}
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +0530481
482void audio_extn_dolby_set_license(struct audio_device *adev)
483{
484 int ret, key=0;
485 char value[128] = {0};
486 struct mixer_ctl *ctl;
487 const char *mixer_ctl_name = "DS1 License";
488
489 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
490 if (!ctl) {
491 ALOGE("%s: Could not get ctl for mixer cmd - %s",
492 __func__, mixer_ctl_name);
493 return;
494 }
495
496 property_get("audio.ds1.metainfo.key",value,"0");
497 key = atoi(value);
498
499 ALOGV("%s Setting DS1 License, key:0x%x",__func__, key);
500 ret = mixer_ctl_set_value(ctl, 0, key);
501 if (ret)
502 ALOGE("%s: cannot set license, error:%d",__func__, ret);
503
504 return;
505}
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800506#endif /* DS1_DOLBY_DDP_ENABLED || DS1_DOLBY_DAP_ENABLED */
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700507
508#ifdef DS2_DOLBY_DAP_ENABLED
509struct ds2_extn_module {
510 void *ds2_handle;
511 dap_hal_set_hw_info_t dap_hal_set_hw_info;
512};
513
514static struct ds2_extn_module ds2extnmod = {
515 .ds2_handle = NULL,
516 .dap_hal_set_hw_info = NULL,
517};
518
519int audio_extn_dap_hal_init(int snd_card) {
520 char c_dmid[128] = {0};
521 void *handle = NULL;
522 int i_dmid, ret = -EINVAL;
523 dap_hal_device_be_id_map_t device_be_id_map;
524
525 ALOGV("%s: opening DAP HAL lib\n", __func__);
526 ds2extnmod.ds2_handle = dlopen(LIB_DS2_DAP_HAL, RTLD_NOW);
527 if (ds2extnmod.ds2_handle == NULL) {
528 ALOGE("%s: DLOPEN failed for %s error %s", __func__, LIB_DS2_DAP_HAL,
529 dlerror());
530 goto ret;
531 }
532 ds2extnmod.dap_hal_set_hw_info = (dap_hal_set_hw_info_t)dlsym(ds2extnmod.ds2_handle, SET_HW_INFO_FUNC);
533 if (ds2extnmod.dap_hal_set_hw_info == NULL) {
534 ALOGE("%s: dlsym error %s for %s", __func__, SET_HW_INFO_FUNC,
535 dlerror());
536 goto close;
537 }
538 ds2extnmod.dap_hal_set_hw_info(SND_CARD, (void*)(&snd_card));
539 ALOGV("%s Sound card number is:%d",__func__,snd_card);
540
541 property_get("dmid",c_dmid,"0");
542 i_dmid = atoi(c_dmid);
543 ds2extnmod.dap_hal_set_hw_info(DMID, (void*)(&i_dmid));
544 ALOGV("%s Dolby device manufacturer id is:%d",__func__,i_dmid);
545
546 platform_get_device_to_be_id_map(&device_be_id_map.device_id_to_be_id, &device_be_id_map.len);
547 ds2extnmod.dap_hal_set_hw_info(DEVICE_BE_ID_MAP, (void*)(&device_be_id_map));
548 ALOGV("%s Set be id map len:%d",__func__,device_be_id_map.len);
549 ret = 0;
550 goto ret;
551
552close:
553 dlclose(ds2extnmod.ds2_handle);
554 ds2extnmod.ds2_handle = NULL;
555 ds2extnmod.dap_hal_set_hw_info = NULL;
556ret:
557 return ret;
558}
559
560int audio_extn_dap_hal_deinit() {
561 if (ds2extnmod.ds2_handle != NULL) {
562 dlclose(ds2extnmod.ds2_handle);
563 ds2extnmod.ds2_handle = NULL;
564 }
565 ds2extnmod.dap_hal_set_hw_info = NULL;
566 return 0;
567}
568
569void audio_extn_dolby_ds2_set_endpoint(struct audio_device *adev) {
570 struct listnode *node;
571 struct audio_usecase *usecase;
572 struct mixer_ctl *ctl;
573 const char *mixer_ctl_name = "DS1 DAP Endpoint";
574 int endpoint = 0, ret;
575 bool send = false;
576
577 list_for_each(node, &adev->usecase_list) {
578 usecase = node_to_item(node, struct audio_usecase, list);
579 if ((usecase->type == PCM_PLAYBACK) &&
580 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY)) {
581 endpoint |= usecase->devices & AUDIO_DEVICE_OUT_ALL;
582 send = true;
583 }
584 }
585 if (!send)
586 return;
587
588 if (ds2extnmod.dap_hal_set_hw_info) {
589 ds2extnmod.dap_hal_set_hw_info(HW_ENDPOINT, (void*)(&endpoint));
590 ALOGE("%s: Dolby set endpint :0x%x",__func__, endpoint);
591 } else {
592 ALOGE("%s: dap_hal_set_hw_info is NULL",__func__);
593 }
594
595 return;
596}
597
598int audio_extn_ds2_enable(struct audio_device *adev) {
599
600 char value[PROPERTY_VALUE_MAX] = {0};
601 bool ds2_enabled = false;
602 const char *mixer_ctl_name = "DS2 OnOff";
603 struct mixer_ctl *ctl;
604
605 property_get("audio.dolby.ds2.enabled", value, NULL);
606 ds2_enabled = atoi(value) || !strncmp("true", value, 4);
607
608 ALOGV("%s:", __func__);
609 if(ds2_enabled) {
610 ALOGD("%s:ds2_enabled %d", __func__, ds2_enabled);
611 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
612 if (!ctl) {
613 ALOGE("%s: Could not get ctl for mixer cmd - %s",
614 __func__, mixer_ctl_name);
615 return -EINVAL;
616 }
617
618 if (mixer_ctl_set_value(ctl, 0, ds2_enabled) < 0) {
619 ALOGE("%s: Could not set ds2 enable %d",
620 __func__, ds2_enabled);
621 return -EINVAL;
622 }
623 }
624 return 0;
625}
626
627int audio_extn_dolby_set_dap_bypass(struct audio_device *adev, int state) {
628
629 ALOGV("%s: state %d", __func__, state);
630 if (ds2extnmod.dap_hal_set_hw_info) {
631 ds2extnmod.dap_hal_set_hw_info(DAP_BYPASS, (void*)(&state));
632 ALOGV("%s: Dolby set bypas :0x%x", __func__, state);
633 } else {
634 ALOGV("%s: dap_hal_set_hw_info is NULL", __func__);
635 }
636 return 0;
637}
638#endif