source: svn/newcon3bcm2_21bu/nexus/modules/audio/7552/src/nexus_audio_module.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 17.2 KB
Line 
1/***************************************************************************
2*     (c)2004-2011 Broadcom Corporation
3*
4*  This program is the proprietary software of Broadcom Corporation and/or its licensors,
5*  and may only be used, duplicated, modified or distributed pursuant to the terms and
6*  conditions of a separate, written license agreement executed between you and Broadcom
7*  (an "Authorized License").  Except as set forth in an Authorized License, Broadcom grants
8*  no license (express or implied), right to use, or waiver of any kind with respect to the
9*  Software, and Broadcom expressly reserves all rights in and to the Software and all
10*  intellectual property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU
11*  HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY
12*  NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
13*
14*  Except as expressly set forth in the Authorized License,
15*
16*  1.     This program, including its structure, sequence and organization, constitutes the valuable trade
17*  secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof,
18*  and to use this information only in connection with your use of Broadcom integrated circuit products.
19*
20*  2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
21*  AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
22*  WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
23*  THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES
24*  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE,
25*  LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION
26*  OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF
27*  USE OR PERFORMANCE OF THE SOFTWARE.
28*
29*  3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
30*  LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR
31*  EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR
32*  USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF
33*  THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT
34*  ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
35*  LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF
36*  ANY LIMITED REMEDY.
37*
38* $brcm_Workfile: nexus_audio_module.c $
39* $brcm_Revision: 25 $
40* $brcm_Date: 12/20/11 4:13p $
41*
42* API Description:
43*   API name: Audio Module
44*    Top-Level Audio Module APIs
45*
46* Revision History:
47*
48* $brcm_Log: /nexus/modules/audio/7422/src/nexus_audio_module.c $
49*
50* 25   12/20/11 4:13p jgarrett
51* SW7425-1018: Adding initial A/85 implementation
52*
53* 24   12/14/11 4:52p jgarrett
54* SW7425-1950: Consolidating audio codec conversion routines into core
55*  module
56*
57* 23   11/21/11 2:48p jgarrett
58* SW7425-1406: Adding Vorbis audio support
59*
60* VORBIS_DEVEL/2   11/16/11 1:51p jgarrett
61* SW7425-1406: Merging latest main branch changes
62*
63* 22   11/3/11 6:53p jgarrett
64* SW7422-400: Enabling audio debug logs on 40nm APE chips
65*
66* VORBIS_DEVEL/1   10/4/11 3:53p jgarrett
67* SW7425-1406: Adding Vorbis support
68*
69* 21   9/27/11 4:36p jgarrett
70* SW7408-304: Destroying IMG context on shutdown
71*
72* 20   8/18/11 5:51p jgarrett
73* SWDTV-6306: Merge DTV APE changes to main branch
74*
75* Nexus_APE_Integration/2   8/10/11 5:17p jgarrett
76* SWDTV-6306: Enabling implicit capture to DSP instead of FMM by default
77*  for DTV
78*
79* Nexus_APE_Integration/1   8/10/11 5:16p jgarrett
80* SWDTV-6306: Adding implicit capture to DSP instead of FMM for DTV
81*
82* 19   8/4/11 7:33p mphillip
83* SW7422-404: Update audio region verification code
84*
85* 18   7/21/11 4:13p gmohile
86* SW7125-1014 : Rework power management
87*
88* SW7125-1014/1   7/20/11 4:37p gmohile
89* SW7125-1014 : Rework power management
90*
91* 17   7/1/11 4:03p jgarrett
92* SW7231-274: Adding optional audio firmware heap
93*
94* 16   7/1/11 9:59a jgarrett
95* SW7405-5072: Adding WMA TS Support
96*
97* 15   6/27/11 5:42p jgarrett
98* SW7231-97: Enabling DtsLegacy
99*
100* 14   6/24/11 11:38a gmohile
101* SW7231-128 : Add BDSP standby
102*
103* 13   6/20/11 5:42p jgarrett
104* SW7425-409: Merging VP6 support to main branch
105*
106* SW7425-409/2   6/8/11 6:58p jgarrett
107* SW7425-409: Fixing linker issue if DSP video decoder extension is not
108*  defined
109*
110* SW7425-409/1   6/6/11 7:23p jgarrett
111* SW7425-409: Adding init hooks for VDE
112*
113* 12   5/13/11 5:17p gmohile
114* SW7231-128 : Add Standby support
115*
116* 11   4/19/11 6:07p jgarrett
117* SW7425-386: Enabling control of audio memory allocation
118*
119* 10   4/19/11 5:32p jgarrett
120* SW7422-408: Adding additional codecs
121*
122* 9   4/18/11 10:14p gskerl
123* SW7425-364: Added BAPE_Pll_EnableExternalMclk() API to APE, then called
124*  it from NEXUS_AudioModule_EnableExternalMclk()
125*
126* 8   3/23/11 6:28p jgarrett
127* SW7422-352: adding HDMI input support to nexus
128*
129* 7   2/22/11 5:30p jgarrett
130* SW7422-146: Fixing build errors
131*
132* 6   1/19/11 3:01p jgarrett
133* SW7422-146: Initial decode/passthrough of ac3
134*
135* 5   1/13/11 5:25p jgarrett
136* SW7422-146: Adding encoder hooks
137*
138* 4   1/10/11 5:21p jgarrett
139* SW7422-146: Fixing module comments
140*
141* 3   1/10/11 5:19p jgarrett
142* SW7422-146: Adding ramp step APIs
143*
144* 2   1/10/11 4:20p jgarrett
145* SW7422-146: Adding missing module-level routines
146*
147* 1   12/17/10 3:56p jgarrett
148* SW7422-146: Adding initial nexus on APE for 7422
149*
150***************************************************************************/
151#include "nexus_audio_module.h"
152#define RAAGA_DEBUG_LOG_CHANGES 1
153#include "bdsp_raaga.h"
154#ifdef NEXUS_SECURITY_AUDIO_VERIFICATION
155#include "nexus_audio_decoder_security.h"
156#endif
157
158BDBG_MODULE(nexus_audio_module);
159
160NEXUS_ModuleHandle g_NEXUS_audioModule;
161NEXUS_AudioModuleData g_NEXUS_audioModuleData;
162
163static void NEXUS_AudioModule_Print(void)
164{
165    BDBG_MSG(("Audio:"));
166    #if 0   /* TODO */
167    BDBG_MSG((" handles: xpt:%p hdmi in:%p hdmi out:%p fe:%p rap:%p",g_NEXUS_audioModuleData.transport,g_NEXUS_audioModuleData.hdmiInput,g_NEXUS_audioModuleData.hdmiOutput,g_NEXUS_audioModuleData.frontend,g_NEXUS_audioModuleData.hRap));
168    BDBG_MSG((" img: ctxt:%p i:%p",g_NEXUS_audioModuleData.img_context,g_NEXUS_audioModuleData.img_interface));
169    BDBG_MSG((" settings: wd:%d id:%d hbre:%d maxpb:%d",g_NEXUS_audioModuleData.moduleSettings.watchdogEnabled,g_NEXUS_audioModuleData.moduleSettings.independentDelay,g_NEXUS_audioModuleData.moduleSettings.hbrEnabled,g_NEXUS_audioModuleData.moduleSettings.maximumProcessingBranches));
170    #endif
171}
172
173void NEXUS_AudioModule_GetDefaultSettings(
174    NEXUS_AudioModuleSettings *pSettings    /* [out] */
175    )
176{
177    BAPE_Settings apeSettings;
178    BDSP_RaagaSettings raagaSettings;
179    unsigned i;
180
181    BKNI_Memset(pSettings, 0, sizeof(NEXUS_AudioModuleSettings));
182    BAPE_GetDefaultSettings(&apeSettings);
183    pSettings->watchdogEnabled = true;
184    pSettings->maxAudioDspTasks = apeSettings.maxDspTasks;
185    pSettings->maxIndependentDelay = apeSettings.maxIndependentDelay;
186    pSettings->maxPcmSampleRate = apeSettings.maxPcmSampleRate;
187    pSettings->hbrEnabled = apeSettings.highBitRateEnabled;
188    pSettings->numCompressedBuffers = apeSettings.numCompressedBuffers;
189    pSettings->numPcmBuffers = apeSettings.numPcmBuffers;
190    pSettings->independentDelay = pSettings->maxIndependentDelay > 0 ? true : false;
191#if 0 /* JPF */
192    BDBG_CASSERT(NEXUS_AudioLoudnessEquivalenceMode_eNone == (int)BAPE_LoudnessEquivalenceMode_eNone);
193    BDBG_CASSERT(NEXUS_AudioLoudnessEquivalenceMode_eAtscA85 == (int)BAPE_LoudnessEquivalenceMode_eAtscA85);
194    BDBG_CASSERT(NEXUS_AudioLoudnessEquivalenceMode_eEbuR128 == (int)BAPE_LoudnessEquivalenceMode_eEbuR128);
195    BDBG_CASSERT(NEXUS_AudioLoudnessEquivalenceMode_eMax == (int)BAPE_LoudnessEquivalenceMode_eMax);
196    pSettings->loudnessMode = (NEXUS_AudioLoudnessEquivalenceMode)apeSettings.loudnessMode;
197#endif
198    #if NEXUS_DTV_PLATFORM
199    pSettings->routeInputsToDsp = true;
200    #endif
201
202    BDSP_Raaga_GetDefaultSettings(&raagaSettings);
203    for ( i = 0; i < NEXUS_AudioDspDebugType_eMax; i++ )
204    {
205        pSettings->dspDebugSettings.typeSettings[i].enabled = false;    /* Disable all debug by default */
206        pSettings->dspDebugSettings.typeSettings[i].bufferSize = raagaSettings.debugSettings[i].bufferSize;
207    }
208}
209
210NEXUS_ModuleHandle NEXUS_AudioModule_Init(
211    const NEXUS_AudioModuleSettings *pSettings  /* NULL will use default settings */
212    )
213{
214    BERR_Code errCode;
215    NEXUS_ModuleSettings moduleSettings;
216    BAPE_Settings apeSettings;
217    BDSP_RaagaSettings raagaSettings;
218    NEXUS_AudioModuleSettings audioModuleSettings;
219    BMEM_Heap_Handle fwHeap = g_pCoreHandles->heap[0];
220    unsigned i;
221
222    NEXUS_Module_GetDefaultSettings(&moduleSettings);
223    moduleSettings.priority = NEXUS_ModulePriority_eLow; /* decoder interface is slow */
224    moduleSettings.dbgPrint = NEXUS_AudioModule_Print;
225    moduleSettings.dbgModules = "nexus_audio_module";
226    g_NEXUS_audioModule = NEXUS_Module_Create("audio", &moduleSettings);
227
228    if ( NULL == g_NEXUS_audioModule )
229    {
230        errCode=BERR_TRACE(BERR_OS_ERROR);
231        goto err_module;
232    }
233
234    if ( NULL == pSettings )
235    {
236        NEXUS_AudioModule_GetDefaultSettings(&audioModuleSettings);
237        pSettings = &audioModuleSettings;
238    }
239
240    g_NEXUS_audioModuleData.settings = *pSettings;
241
242    BDSP_Raaga_GetDefaultSettings(&raagaSettings);
243
244    #if 1
245    {
246        static BIMG_Interface imgInterface;
247        /* TODO: Connect IMG to DSP interface */
248        if ( Nexus_Core_P_Img_Create(NEXUS_CORE_IMG_ID_RAP, &g_NEXUS_audioModuleData.pImageContext, &imgInterface) == NEXUS_SUCCESS )
249        {
250            BDBG_WRN(("FW download used"));
251            raagaSettings.pImageContext = g_NEXUS_audioModuleData.pImageContext;
252            raagaSettings.pImageInterface = &imgInterface;
253        }
254    }
255    #endif
256
257    if ( pSettings->firmwareHeap )
258    {
259        fwHeap = NEXUS_Heap_GetMemHandle(pSettings->firmwareHeap);
260        if ( NULL == fwHeap )
261        {
262            (void)BERR_TRACE(BERR_INVALID_PARAMETER);
263            goto err_dsp;
264        }
265    }
266#ifdef NEXUS_SECURITY_AUDIO_VERIFICATION
267    NEXUS_Audio_P_EnableFwVerification(&raagaSettings);
268#endif
269
270    for ( i = 0; i < NEXUS_AudioDspDebugType_eMax; i++ )
271    {
272        raagaSettings.debugSettings[i].enabled = pSettings->dspDebugSettings.typeSettings[i].enabled;
273        raagaSettings.debugSettings[i].bufferSize = pSettings->dspDebugSettings.typeSettings[i].bufferSize;
274
275        if ( pSettings->dspDebugSettings.typeSettings[i].enabled )
276        {
277            BDBG_WRN(("Enabling audio FW debug type %u [%s]", i, (i == NEXUS_AudioDspDebugType_eDramMessage)?"DRAM Message":
278                                                                 (i == NEXUS_AudioDspDebugType_eUartMessage)?"UART Message":
279                                                                 "Core Dump"));
280        }
281    }
282
283    errCode = BDSP_Raaga_Open(&g_NEXUS_audioModuleData.dspHandle,
284                              g_pCoreHandles->chp,
285                              g_pCoreHandles->reg,
286                              fwHeap,
287                              g_pCoreHandles->bint,
288                              g_pCoreHandles->tmr,
289                              &raagaSettings);
290    if ( errCode )
291    {
292        (void)BERR_TRACE(errCode);
293        goto err_dsp;
294    }
295#ifdef NEXUS_SECURITY_AUDIO_VERIFICATION
296    errCode = NEXUS_Audio_P_FwVerification (g_NEXUS_audioModuleData.dspHandle);
297    if ( errCode )
298    {
299        (void)BERR_TRACE(errCode);
300        return NULL;
301    }
302#endif
303
304    BAPE_GetDefaultSettings(&apeSettings);
305    apeSettings.maxDspTasks = pSettings->maxAudioDspTasks;
306    apeSettings.maxIndependentDelay = pSettings->independentDelay ? pSettings->maxIndependentDelay : 0;
307    apeSettings.maxPcmSampleRate = pSettings->maxPcmSampleRate;
308    apeSettings.highBitRateEnabled = pSettings->hbrEnabled;
309    apeSettings.numCompressedBuffers = pSettings->numCompressedBuffers;
310    apeSettings.numPcmBuffers = pSettings->numPcmBuffers;
311// JPF    apeSettings.loudnessMode = (BAPE_LoudnessEquivalenceMode)pSettings->loudnessMode;
312
313    if ( NEXUS_GetEnv("audio_ramp_disabled") )
314    {
315        apeSettings.rampPcmSamples = false;
316    }
317
318    errCode = BAPE_Open(&NEXUS_AUDIO_DEVICE_HANDLE,
319                        g_pCoreHandles->chp,
320                        g_pCoreHandles->reg,
321                        g_pCoreHandles->heap[0],
322                        g_pCoreHandles->bint,
323                        g_pCoreHandles->tmr,
324                        g_NEXUS_audioModuleData.dspHandle,
325                        &apeSettings);
326
327    if ( errCode )
328    {
329        (void)BERR_TRACE(errCode);
330        goto err_ape;
331    }
332
333    errCode = NEXUS_AudioDecoder_P_Init();
334    if ( errCode )
335    {
336        (void)BERR_TRACE(errCode);
337        goto err_decoder;
338    }
339
340    errCode = NEXUS_AudioInput_P_Init();
341    if ( errCode )
342    {
343        (void)BERR_TRACE(errCode);
344        goto err_input;
345    }
346
347#if NEXUS_NUM_DSP_VIDEO_DECODERS
348    errCode = NEXUS_AudioModule_P_InitDspVideoDecoder();
349    if ( errCode )
350    {
351        (void)BERR_TRACE(errCode);
352        goto err_video;
353    }
354#endif
355
356    return g_NEXUS_audioModule;
357
358#if NEXUS_NUM_DSP_VIDEO_DECODERS
359err_video:
360    NEXUS_AudioInput_P_Uninit();
361#endif
362err_input:
363    NEXUS_AudioDecoder_P_Uninit();
364err_decoder:
365    BAPE_Close(NEXUS_AUDIO_DEVICE_HANDLE);
366err_ape:
367    BDSP_Close(g_NEXUS_audioModuleData.dspHandle);
368err_dsp:
369    NEXUS_Module_Destroy(g_NEXUS_audioModule);
370err_module:
371    return NULL;
372}
373
374void NEXUS_AudioModule_Uninit(void)
375{
376#if NEXUS_NUM_DSP_VIDEO_DECODERS
377    NEXUS_AudioModule_P_UninitDspVideoDecoder();
378#endif
379    NEXUS_AudioInput_P_Uninit();
380    NEXUS_AudioDecoder_P_Uninit();
381
382    if ( NEXUS_AUDIO_DEVICE_HANDLE )
383    {
384        BAPE_Close(NEXUS_AUDIO_DEVICE_HANDLE);
385    }
386    if ( g_NEXUS_audioModuleData.dspHandle )
387    {
388        BDSP_Close(g_NEXUS_audioModuleData.dspHandle);
389    }
390#ifdef NEXUS_SECURITY_AUDIO_VERIFICATION
391    NEXUS_Audio_P_DisableFwVerification ();
392#endif
393
394    if (g_NEXUS_audioModuleData.pImageContext) {
395        Nexus_Core_P_Img_Destroy(g_NEXUS_audioModuleData.pImageContext);
396    }
397
398    if ( g_NEXUS_audioModule )
399    {
400        NEXUS_Module_Destroy(g_NEXUS_audioModule);
401    }
402}
403
404void NEXUS_AudioModule_GetRampStepSettings(
405    NEXUS_AudioRampStepSettings *pRampStepSettings      /* [out] ramping step size for scale change for all output ports */
406    )
407{
408    uint32_t val;
409    if ( NULL == pRampStepSettings )
410    {
411        return;
412    }
413    BAPE_GetOutputVolumeRampStep(NEXUS_AUDIO_DEVICE_HANDLE, &val);
414    pRampStepSettings->mixerRampStep = val;
415    BAPE_GetSampleRateConverterRampStep(NEXUS_AUDIO_DEVICE_HANDLE, &val);
416    pRampStepSettings->srcRampStep = val;
417}
418
419NEXUS_Error NEXUS_AudioModule_SetRampStepSettings(
420    const NEXUS_AudioRampStepSettings *pRampStepSettings  /* ramping step size for scale change for all output ports */
421    )
422{
423    BERR_Code errCode;
424
425    if ( NULL == pRampStepSettings )
426    {
427        return BERR_TRACE(BERR_INVALID_PARAMETER);
428    }
429
430    errCode = BAPE_SetOutputVolumeRampStep(NEXUS_AUDIO_DEVICE_HANDLE, pRampStepSettings->mixerRampStep);
431    if ( errCode )
432    {
433        return BERR_TRACE(errCode);
434    }
435
436    errCode = BAPE_SetSampleRateConverterRampStep(NEXUS_AUDIO_DEVICE_HANDLE, pRampStepSettings->srcRampStep);
437    if ( errCode )
438    {
439        return BERR_TRACE(errCode);
440    }
441
442    return BERR_SUCCESS;
443}
444
445NEXUS_Error NEXUS_AudioModule_EnableExternalMclk(
446    unsigned mclkIndex,
447    unsigned pllIndex,
448    NEXUS_ExternalMclkRate mclkRate
449    )
450{
451    BERR_Code       errCode;
452    BAPE_Pll        bapePll;
453    BAPE_MclkRate   bapeMclkRate;
454
455    switch ( pllIndex )
456    {
457    case 0:
458        bapePll = BAPE_Pll_e0;
459        break;
460    case 1:
461        bapePll = BAPE_Pll_e1;
462        break;
463    case 2:
464        bapePll = BAPE_Pll_e2;
465        break;
466
467    default:
468        BDBG_ERR(("pllIndex:%lu is invalid", pllIndex));
469        return BERR_TRACE(BERR_INVALID_PARAMETER);
470    }
471
472    switch( mclkRate )
473    {
474    case NEXUS_ExternalMclkRate_e128Fs:
475        bapeMclkRate = BAPE_MclkRate_e128Fs;
476        break;
477
478    case NEXUS_ExternalMclkRate_e256Fs:
479        bapeMclkRate = BAPE_MclkRate_e256Fs;
480        break;
481
482    case NEXUS_ExternalMclkRate_e384Fs:
483        bapeMclkRate = BAPE_MclkRate_e384Fs;
484        break;
485
486    case NEXUS_ExternalMclkRate_e512Fs:
487        bapeMclkRate = BAPE_MclkRate_e512Fs;
488        break;
489
490    default:
491        BDBG_ERR(("mclkRate:%lu is invalid", mclkRate));
492        return BERR_TRACE(BERR_INVALID_PARAMETER);
493    }
494
495    errCode = BAPE_Pll_EnableExternalMclk( NEXUS_AUDIO_DEVICE_HANDLE, bapePll, mclkIndex, bapeMclkRate );
496    if ( errCode )
497    {
498        return BERR_TRACE(errCode);
499    }
500    return BERR_SUCCESS;
501}
502
503BAVC_AudioCompressionStd NEXUS_Audio_P_CodecToMagnum(NEXUS_AudioCodec codec)
504{
505    return NEXUS_P_AudioCodec_ToMagnum(codec);
506}
507
508NEXUS_AudioCodec NEXUS_Audio_P_MagnumToCodec(BAVC_AudioCompressionStd codec)
509{
510    return NEXUS_P_AudioCodec_FromMagnum(codec);
511}
512
513NEXUS_Error NEXUS_AudioModule_Standby_priv(
514    bool enabled,
515    const NEXUS_StandbySettings *pSettings
516    )
517{
518    BERR_Code rc = NEXUS_SUCCESS;
519
520    BSTD_UNUSED(pSettings);
521
522#if NEXUS_POWER_MANAGEMENT
523    if(enabled) {
524        rc = BAPE_Standby(g_NEXUS_audioModuleData.apeHandle, NULL);
525        rc = BDSP_Standby(g_NEXUS_audioModuleData.dspHandle, NULL);
526    } else {
527        rc = BDSP_Resume(g_NEXUS_audioModuleData.dspHandle);
528        rc = BAPE_Resume(g_NEXUS_audioModuleData.apeHandle);
529    }
530#else
531    BSTD_UNUSED(enabled);
532#endif
533
534    return rc;
535}
536
Note: See TracBrowser for help on using the repository browser.