source: svn/newcon3bcm2_21bu/magnum/portinginterface/ape/7552/bape_spdif_input.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: 57.6 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2006-2012, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bape_spdif_input.c $
11 * $brcm_Revision: Hydra_Software_Devel/26 $
12 * $brcm_Date: 3/23/12 10:43a $
13 *
14 * Module Description: SPDIF Audio Input Interface
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/portinginterface/ape/7422/bape_spdif_input.c $
19 *
20 * Hydra_Software_Devel/26   3/23/12 10:43a gskerl
21 * SW7429-18: Fixed compile error on 7425 and 7435.
22 *
23 * Hydra_Software_Devel/25   3/22/12 3:08p gskerl
24 * SW7429-18: Moved preamble C parsing logic into
25 * BAPE_InputPort_P_BurstPreambleToCodec().
26 *
27 * Hydra_Software_Devel/24   3/8/12 5:41p gskerl
28 * SW7429-18: Lots of cleanup, reorganization, and refactoring.
29 *
30 * Hydra_Software_Devel/23   2/9/12 11:21a jgarrett
31 * SW7425-2074: Enabling input halt and revising MAI shutown for
32 * multichannel PCM
33 *
34 * Hydra_Software_Devel/22   2/2/12 6:58p gskerl
35 * SW7429-18: Merged to Hydra_Software_Devel branch.
36 *
37 * Hydra_Software_Devel/SW7429-18_20120120/4   2/2/12 6:53p gskerl
38 * SW7429-18: Added debug prints for goodBiPhase, leftValidity, and
39 * rightValidity fields of the BAPE_SpdifInputFormatDetectionStatus
40 * struct.
41 *
42 * Hydra_Software_Devel/SW7429-18_20120120/3   2/1/12 4:46p gskerl
43 * SW7429-18: Added some code to update our local state with whatever
44 * we're reporting through the status change callback. Misc cleanup
45 *
46 * Hydra_Software_Devel/SW7429-18_20120120/2   1/23/12 5:31p gskerl
47 * SW7429-18: Added an abstract name for the SPDIF receiver control
48 * register.
49 *
50 * Hydra_Software_Devel/SW7429-18_20120120/1   1/20/12 12:36p gskerl
51 * SW7429-18: Started refactoring and cleanup... Compiles on 7425
52 *
53 * Hydra_Software_Devel/20   1/6/12 2:38p jgarrett
54 * SW7435-24: Merge to main branch
55 *
56 * Hydra_Software_Devel/SW7435-24/3   12/15/11 4:34p mward
57 * SW7435-24:  Merge from main.
58 *
59 * Hydra_Software_Devel/SW7435-24/2   11/30/11 12:11p mward
60 * SW7435-24:  Merge from main.
61 *
62 * Hydra_Software_Devel/SW7435-24/1   11/3/11 4:34p mward
63 * SW7435-24:  Add 7435.
64 *
65 * Hydra_Software_Devel/19   11/30/11 4:26p jgarrett
66 * SW7429-18: Adding stubs for SPDIF/MAI inputs on 7429
67 *
68 * Hydra_Software_Devel/18   11/14/11 3:38p gskerl
69 * SW7429-18: Merging 7429 changes back to main branch.
70 *
71 * Hydra_Software_Devel/SW7429-18/2   11/4/11 5:37p gskerl
72 * SW7429-18: Added conditional include for bchp_int_id_aio_inth.h to fix
73 * compile errors on 7425
74 *
75 * Hydra_Software_Devel/SW7429-18/1   10/26/11 12:44p jgarrett
76 * SW7429-18: Merging latest changes from main branch
77 *
78 * Hydra_Software_Devel/17   10/26/11 6:00p gskerl
79 * SW7231-129: Added stub version of
80 * BAPE_SpdifInput_P_PrepareForStandby().
81 *
82 * Hydra_Software_Devel/16   10/26/11 5:34p gskerl
83 * SW7231-129: Added BAPE_SpdifInput_P_PrepareForStandby() to disable
84 * interrupts before entering standby.
85 *
86 * Hydra_Software_Devel/15   10/26/11 3:43p gskerl
87 * SW7231-129: Added code to invalidate the saved SPDIF receiver state
88 * before reinitializing the SPDIF receiver hardware.
89 *
90 * Hydra_Software_Devel/14   10/25/11 1:25p gskerl
91 * SW7231-129: Added stub version of BAPE_SpdifInput_P_ResumeFromStandby()
92 *
93 * Hydra_Software_Devel/13   10/12/11 4:49p gskerl
94 * SW7231-129: Added support for recovering hardware state after power
95 * standby/resume.
96 *
97 * Hydra_Software_Devel/12   8/24/11 1:44p jgarrett
98 * SWDTV-8271: Reversing SPDIF/HDMI input ISRs on 352xx
99 *
100 * Hydra_Software_Devel/11   8/16/11 4:10p jgarrett
101 * SWDTV-8271: Correcting IOP Capture ID for STB
102 *
103 * Hydra_Software_Devel/10   8/10/11 9:30a venkatr
104 * SWDTV-6584 : [35233] Add ADC Input for APE
105 *
106 * Hydra_Software_Devel/9   5/12/11 11:42a gskerl
107 * SW7422-354: Fixed to support compilation on 35230
108 *
109 * Hydra_Software_Devel/8   5/2/11 5:28p gskerl
110 * SW7422-354: Removed explicit setting of handle->connector.type because
111 * it was already set by the BAPE_P_InitInputPort macro
112 *
113 * Hydra_Software_Devel/7   4/16/11 12:16p jgarrett
114 * SW7425-371: Removing tab characters
115 *
116 * Hydra_Software_Devel/6   4/12/11 9:22a jgarrett
117 * SW7422-365: Fixing build issues
118 *
119 * Hydra_Software_Devel/5   4/11/11 6:24p gskerl
120 * SW7422-365: Fixed a compile error
121 *
122 * Hydra_Software_Devel/4   4/8/11 3:39p piyushg
123 * SW7422-365: Added support for the SPDIF input handling and format
124 * detection in APE
125 *
126 * Hydra_Software_Devel/3   2/22/11 5:43p jgarrett
127 * SW7422-146: Implemented type renaming based on filter graph review
128 * comments
129 *
130 * Hydra_Software_Devel/2   1/18/11 11:04a jgarrett
131 * SW7422-146: Adding handle to input open routines
132 *
133 * Hydra_Software_Devel/1   1/12/11 4:24p jgarrett
134 * SW7422-146: Adding additional APIs
135 *
136 ***************************************************************************/
137
138#include "bape.h"
139#include "bape_priv.h"
140
141#ifdef BCHP_AIO_INTH_REG_START
142    #include "bchp_int_id_aio_inth.h"
143#endif
144
145#ifdef BCHP_AUD_INTH_REG_START
146    #include "bchp_int_id_aud_inth.h"
147#endif
148
149BDBG_MODULE(bape_spdif_input);
150
151BDBG_OBJECT_ID(BAPE_SpdifInput);
152
153#if BAPE_CHIP_MAX_SPDIF_INPUTS > 0
154
155typedef struct BAPE_SpdifInput
156{
157    BDBG_OBJECT(BAPE_SpdifInput)
158    BAPE_Handle deviceHandle;
159    BAPE_SpdifInputSettings settings;
160    unsigned index;                 
161    BAPE_InputPortObject inputPort;
162    uint32_t offset; 
163    BAPE_SpdifInputFormatDetectionSettings clientFormatDetectionSettings;
164    bool                            localFormatDetectionEnabled;
165    bool                            formatDetectionEnabled;
166    uint32_t outFormatEna;      /* last value written to OUT_FORMAT_ENA field. */
167    bool enable;
168    char name[12];   /* SPDIF IN %d */
169
170    BINT_CallbackHandle spdifRxCallback;
171
172    BAPE_SpdifInputFormatDetectionStatus  lastFormatDetectionStatus;
173} BAPE_SpdifInput;
174
175
176#if BCHP_CHIP == 7422 || BCHP_CHIP == 7425 || BCHP_CHIP == 7435
177#define BAPE_SPDIF_INPUT_CAPTURE_ID() (9)
178#elif BCHP_CHIP == 35230 || BCHP_CHIP == 35125 || BCHP_CHIP == 35233 || BCHP_CHIP == 35126
179#define BAPE_SPDIF_INPUT_CAPTURE_ID() (11)
180#elif defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN
181/* 7429-style chips do not need this hardcoded */
182#else
183#error SPDIF capture ID not defined
184#endif
185
186/* Build some abstract register names and map them to the chip's real names. */
187#if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN
188    #define BAPE_P_SPDIF_RX_STATUS_REGADDR        BCHP_AUD_FMM_IOP_IN_SPDIF_0_STATUS
189    #define BAPE_P_SPDIF_RX_STATUS_REGNAME             AUD_FMM_IOP_IN_SPDIF_0_STATUS
190    #define BAPE_P_SPDIF_RX_CONFIG_REGADDR        BCHP_AUD_FMM_IOP_IN_SPDIF_0_CONFIG
191    #define BAPE_P_SPDIF_RX_CONFIG_REGNAME             AUD_FMM_IOP_IN_SPDIF_0_CONFIG
192#endif
193#if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY
194    #define BAPE_P_SPDIF_RX_STATUS_REGADDR       BCHP_SPDIF_RCVR_CTRL_STATUS
195    #define BAPE_P_SPDIF_RX_STATUS_REGNAME            SPDIF_RCVR_CTRL_STATUS
196    #define BAPE_P_SPDIF_RX_CONFIG_REGADDR       BCHP_SPDIF_RCVR_CTRL_CONFIG
197    #define BAPE_P_SPDIF_RX_CONFIG_REGNAME            SPDIF_RCVR_CTRL_CONFIG
198#endif
199
200
201/* Static function prototypes */
202static BERR_Code    BAPE_SpdifInput_P_OpenHw(BAPE_SpdifInputHandle hSpdifInput);
203static BERR_Code    BAPE_SpdifInput_P_ApplySettings(BAPE_SpdifInputHandle hSpdifInput);
204static void         BAPE_SpdifInput_P_DetectInputChange_isr (BAPE_SpdifInputHandle    hSpdifInput);
205static BERR_Code    BAPE_SpdifInput_P_GetFormatDetectionStatus_isr(BAPE_SpdifInputHandle hSpdifInput, BAPE_SpdifInputFormatDetectionStatus *pStatus );
206static void         BAPE_P_SPDIF_RX_isr (void * pParm1, int iParm2); 
207static void         BAPE_SpdifInput_P_SetReceiverOutputFormat_isr (BAPE_SpdifInputHandle hSpdifInput, BAPE_SpdifInputFormatDetectionStatus *pFormatDetectionStatus);
208static BERR_Code    BAPE_SpdifInput_P_SetFormatDetection(BAPE_SpdifInputHandle hSpdifInput);
209static void         BAPE_SpdifInput_P_UpdateInputPortFormatFields_isr (BAPE_SpdifInputHandle hSpdifInput, BAPE_SpdifInputFormatDetectionStatus *pFormatDetectionStatus);
210
211/* Input port callbacks */
212static void         BAPE_SpdifInput_P_Enable(BAPE_InputPort inputPort);
213static void         BAPE_SpdifInput_P_Disable(BAPE_InputPort inputPort);
214static void         BAPE_SpdifInput_P_Halt_isr(BAPE_InputPort inputPort);
215static BERR_Code    BAPE_SpdifInput_P_ConsumerAttached(BAPE_InputPort inputPort, BAPE_PathNode *pConsumer);
216static void         BAPE_SpdifInput_P_ConsumerDetached(BAPE_InputPort inputPort, BAPE_PathNode *pConsumer);
217
218/***************************************************************************
219        Public APIs: From bape_input.h
220***************************************************************************/
221void BAPE_SpdifInput_GetDefaultSettings(
222    BAPE_SpdifInputSettings *pSettings        /* [out] */
223    )
224{
225    BDBG_ASSERT(NULL != pSettings);
226    BKNI_Memset(pSettings, 0, sizeof(*pSettings));
227
228    pSettings->errorInsertion = BAPE_SpdifInputErrorInsertion_eNone;
229    pSettings->ignoreCompressedParity = true;
230    pSettings->ignorePcmParity = true;
231    pSettings->ignoreValidity = true;
232    pSettings->timebase = BAVC_Timebase_e0; 
233}
234
235/**************************************************************************/
236
237BERR_Code BAPE_SpdifInput_Open(
238    BAPE_Handle hApe,
239    unsigned index,
240    const BAPE_SpdifInputSettings *pSettings,
241    BAPE_SpdifInputHandle *phSpdifInput              /* [out] */
242    )
243{
244    BERR_Code errCode;
245    BAPE_SpdifInputHandle hSpdifInput;
246    BAPE_SpdifInputSettings defaultSettings;
247
248    BDBG_OBJECT_ASSERT(hApe, BAPE_Device);
249    BDBG_ASSERT(NULL != phSpdifInput);
250   
251    BDBG_MSG(("%s: Opening SPDIF Input: %u", __FUNCTION__, index));
252
253    *phSpdifInput = NULL;
254
255    if ( index >= BAPE_CHIP_MAX_SPDIF_INPUTS )
256    {
257        BDBG_ERR(("Request to open SPDIF input %d but chip only has %u SPDIF inputs", index, BAPE_CHIP_MAX_SPDIF_INPUTS ));
258        return BERR_TRACE(BERR_INVALID_PARAMETER);
259    }
260
261    if ( hApe->spdifInputs[index] )
262    {
263        BDBG_ERR(("SPDIF input %d already open", index));
264        return BERR_TRACE(BERR_INVALID_PARAMETER);
265    }
266
267    /* Allocate the device structure, then fill in all the fields. */
268    hSpdifInput = BKNI_Malloc(sizeof(BAPE_SpdifInput));
269    if ( NULL == hSpdifInput )
270    {
271        return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
272    }
273
274    /* Init to specified settings */
275    if ( NULL == pSettings )
276    {
277        BAPE_SpdifInput_GetDefaultSettings(&defaultSettings);
278        pSettings = &defaultSettings;
279    }
280
281    BKNI_Memset(hSpdifInput, 0, sizeof(BAPE_SpdifInput));
282    BDBG_OBJECT_SET(hSpdifInput, BAPE_SpdifInput);
283    BAPE_P_InitInputPort(&hSpdifInput->inputPort, BAPE_InputPortType_eSpdif, index, hSpdifInput);
284    hSpdifInput->spdifRxCallback = NULL;
285    hSpdifInput->deviceHandle = hApe;
286    hSpdifInput->index = index;
287    #ifdef BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN
288    {
289        uint32_t regVal = BAPE_Reg_P_Read(hApe, BCHP_AUD_FMM_IOP_IN_SPDIF_0_CAPTURE_FCI_ID_TABLE);
290        regVal = BCHP_GET_FIELD_DATA(regVal, AUD_FMM_IOP_IN_SPDIF_0_CAPTURE_FCI_ID_TABLE, START_FCI_ID);
291        hSpdifInput->inputPort.streamId[BAPE_ChannelPair_eLeftRight] = regVal;
292    }
293    #endif
294    #ifdef BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY
295        hSpdifInput->inputPort.streamId[BAPE_ChannelPair_eLeftRight] = BAPE_SPDIF_INPUT_CAPTURE_ID();
296    #endif
297    hSpdifInput->inputPort.enable = BAPE_SpdifInput_P_Enable;
298    hSpdifInput->inputPort.disable = BAPE_SpdifInput_P_Disable;
299    hSpdifInput->inputPort.consumerAttached = BAPE_SpdifInput_P_ConsumerAttached;
300    hSpdifInput->inputPort.consumerDetached = BAPE_SpdifInput_P_ConsumerDetached;
301    hSpdifInput->inputPort.numChannelPairs = 1;
302    hSpdifInput->inputPort.sampleRate = 48000;
303    hSpdifInput->inputPort.compressed = false;
304    BKNI_Snprintf(hSpdifInput->name, sizeof(hSpdifInput->name), "SPDIF IN %u", index);
305    hSpdifInput->inputPort.pName = hSpdifInput->name;
306
307    /* Currently we only support one SPDIF input, this can be expanded later if we support more */
308    #if BAPE_CHIP_MAX_SPDIF_INPUTS > 1
309        #error "Need to support more SPDIF inputs"
310    #endif
311    hSpdifInput->offset = 0;
312
313    BDBG_ASSERT(hSpdifInput->offset == 0);
314
315    errCode = BAPE_SpdifInput_P_OpenHw(hSpdifInput);
316    if ( errCode )
317    {
318        BAPE_SpdifInput_Close(hSpdifInput);
319        return BERR_TRACE(errCode);
320    }
321
322    errCode = BAPE_SpdifInput_SetSettings(hSpdifInput, pSettings);
323    if ( errCode )
324    {
325        BAPE_SpdifInput_Close(hSpdifInput);
326        return BERR_TRACE(errCode);
327    }
328
329    *phSpdifInput = hSpdifInput;
330    hSpdifInput->deviceHandle->spdifInputs[index] = hSpdifInput;
331    return BERR_SUCCESS;
332}
333
334/**************************************************************************/
335
336void BAPE_SpdifInput_Close(
337    BAPE_SpdifInputHandle hSpdifInput
338    )
339{
340    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
341
342    /* Make sure we're not still connected to anything */
343    if ( hSpdifInput->inputPort.pConsumer )
344    {
345        BDBG_ERR(("Cannot close SPDIF input %p (%d), still connected to %s", hSpdifInput, hSpdifInput->index, hSpdifInput->inputPort.pConsumer->pName));
346        BDBG_ASSERT(NULL == hSpdifInput->inputPort.pConsumer);
347        return;
348    }
349
350    if ( hSpdifInput->spdifRxCallback ) {
351        BINT_DestroyCallback(hSpdifInput->spdifRxCallback);
352    }
353
354    hSpdifInput->deviceHandle->spdifInputs[hSpdifInput->index] = NULL;
355    BDBG_OBJECT_DESTROY(hSpdifInput, BAPE_SpdifInput);
356    BKNI_Free(hSpdifInput);   
357}
358
359/**************************************************************************/
360
361void BAPE_SpdifInput_GetSettings(
362    BAPE_SpdifInputHandle hSpdifInput,
363    BAPE_SpdifInputSettings *pSettings        /* [out] */
364    )
365{
366    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
367    BDBG_ASSERT(NULL != pSettings);
368    *pSettings = hSpdifInput->settings;
369}
370
371/**************************************************************************/
372
373BERR_Code BAPE_SpdifInput_SetSettings(
374    BAPE_SpdifInputHandle hSpdifInput,
375    const BAPE_SpdifInputSettings *pSettings
376    )
377{
378    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
379    BDBG_ASSERT(NULL != pSettings);
380    hSpdifInput->settings = *pSettings;
381
382    return BAPE_SpdifInput_P_ApplySettings(hSpdifInput);
383}
384
385/**************************************************************************/
386
387void BAPE_SpdifInput_GetInputPort(
388    BAPE_SpdifInputHandle hSpdifInput,
389    BAPE_InputPort *pPort
390    )
391{
392    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
393    BDBG_ASSERT(NULL != pPort);
394    *pPort = &hSpdifInput->inputPort;
395}
396
397/**************************************************************************/
398
399void BAPE_SpdifInput_GetFormatDetectionSettings(
400    BAPE_SpdifInputHandle hSpdifInput,
401    BAPE_SpdifInputFormatDetectionSettings *pSettings   /* [out] */
402    )
403{
404    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
405    BDBG_ASSERT(NULL != pSettings);
406
407    {   /* Start Critical Section */
408        BKNI_EnterCriticalSection();
409        *pSettings = hSpdifInput->clientFormatDetectionSettings;
410        BKNI_LeaveCriticalSection();
411    }   /* End Critical Section */
412}
413
414/**************************************************************************/
415
416BERR_Code BAPE_SpdifInput_SetFormatDetectionSettings(
417    BAPE_SpdifInputHandle hSpdifInput,
418    const BAPE_SpdifInputFormatDetectionSettings *pSettings
419    )
420{
421    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
422    BDBG_ASSERT(NULL != pSettings);
423
424    {  /* Start Critical Section */
425        BKNI_EnterCriticalSection();
426        hSpdifInput->clientFormatDetectionSettings = *pSettings;
427        BKNI_LeaveCriticalSection();
428    }  /* End Critical Section */
429
430    BAPE_SpdifInput_P_SetFormatDetection(hSpdifInput);
431
432    return BERR_SUCCESS;
433}
434
435/**************************************************************************/
436
437BERR_Code BAPE_SpdifInput_GetFormatDetectionStatus(
438    BAPE_SpdifInputHandle hSpdifInput,
439    BAPE_SpdifInputFormatDetectionStatus *pStatus
440    )
441{
442    BERR_Code ret = BERR_SUCCESS;
443   
444    BDBG_ENTER(BAPE_SpdifInput_GetFormatDetectionStatus);
445   
446    BDBG_ASSERT(hSpdifInput);
447    BDBG_ASSERT(pStatus);
448
449    if ( hSpdifInput->formatDetectionEnabled )
450    {
451        /* If Format Detection is enabled, we can just return a copy of whats
452         * in the handle's lastFormatDectionStatus structure (since it's being
453         * kept up to date). */
454        BDBG_CASSERT(sizeof (*pStatus) == sizeof (hSpdifInput->lastFormatDetectionStatus));
455        BKNI_Memcpy(pStatus, &hSpdifInput->lastFormatDetectionStatus, sizeof (*pStatus));
456    }
457    else
458    {
459        /* Format Detection is not enabled, so build a fresh format detection status
460           structure by reading the hardware.  */
461        {  /* Start Critical Section */
462            BKNI_EnterCriticalSection();
463            BAPE_SpdifInput_P_GetFormatDetectionStatus_isr(hSpdifInput, pStatus);
464            BKNI_LeaveCriticalSection();
465        }  /* End Critical Section */
466    }
467
468    BDBG_LEAVE(BAPE_SpdifInput_GetFormatDetectionStatus);
469
470    return ret;
471}
472
473/***************************************************************************
474        BAPE Internal APIs: From bape_fmm_priv.h
475***************************************************************************/
476
477BERR_Code BAPE_SpdifInput_P_PrepareForStandby(BAPE_Handle hApe)
478{
479    BERR_Code   errCode = BERR_SUCCESS;
480    unsigned    spdifInputIndex;
481
482    BDBG_OBJECT_ASSERT(hApe, BAPE_Device);
483
484    /* For each opened SpdifInput... */
485    for ( spdifInputIndex=0 ; spdifInputIndex<BAPE_CHIP_MAX_SPDIF_INPUTS ; spdifInputIndex++ )
486    {
487        if ( hApe->spdifInputs[spdifInputIndex] )       /* If this SpdifInput is open... */
488        {
489            BAPE_SpdifInputHandle hSpdifInput = hApe->spdifInputs[spdifInputIndex];
490
491            /* If we already have a callback (interrupt), make sure that it's disabled, then destroy it. */
492            if( hSpdifInput->spdifRxCallback )
493            {
494                errCode = BINT_DisableCallback(hSpdifInput->spdifRxCallback);
495                if (errCode != BERR_SUCCESS)                             
496                {                                                   
497                    BDBG_ERR(("Unable to Disable SPDIF RX callback")); 
498                }
499
500                BINT_DestroyCallback(hSpdifInput->spdifRxCallback);
501                hSpdifInput->spdifRxCallback = NULL;
502            }
503        }
504    }
505    return errCode;
506}
507
508/**************************************************************************/
509
510BERR_Code BAPE_SpdifInput_P_ResumeFromStandby(BAPE_Handle bapeHandle)
511{
512    BERR_Code   errCode = BERR_SUCCESS;
513    unsigned    spdifInputIndex;
514
515    BDBG_OBJECT_ASSERT(bapeHandle, BAPE_Device);
516
517    /* For each opened SpdifInput, call the functions necessary to restore the hardware to it's appropriate state. */
518    for ( spdifInputIndex=0 ; spdifInputIndex<BAPE_CHIP_MAX_SPDIF_INPUTS ; spdifInputIndex++ )
519    {
520        if ( bapeHandle->spdifInputs[spdifInputIndex] )       /* If this SpdifInput is open... */
521        {
522            BAPE_SpdifInputHandle hSpdifInput = bapeHandle->spdifInputs[spdifInputIndex];
523
524            /* Put the HW into the generic open state. */
525            errCode = BAPE_SpdifInput_P_OpenHw(hSpdifInput);
526            if ( errCode ) return BERR_TRACE(errCode);
527           
528            /* Now apply changes for the settings struct. */
529            errCode = BAPE_SpdifInput_SetSettings(hSpdifInput, &hSpdifInput->settings);
530            if ( errCode ) return BERR_TRACE(errCode);
531
532            /* Now restore the dynamic stuff from the values saved in the device struct. */
533            errCode = BAPE_SpdifInput_SetFormatDetectionSettings(hSpdifInput, &hSpdifInput->clientFormatDetectionSettings);
534            if ( errCode ) return BERR_TRACE(errCode);
535        }
536    }
537    return errCode;
538}
539
540/***************************************************************************
541        Private callbacks: Protyped above
542***************************************************************************/
543static void BAPE_SpdifInput_P_Enable(BAPE_InputPort inputPort)
544{
545    BAPE_SpdifInputHandle hSpdifInput;
546
547    BDBG_OBJECT_ASSERT(inputPort, BAPE_InputPort);
548    hSpdifInput = inputPort->pHandle;
549    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
550    BDBG_ASSERT(false == hSpdifInput->enable);
551
552    BDBG_MSG(("Enabling %s", hSpdifInput->name));
553
554    /* Enable capture */
555    #if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN  /* Local (SPDIF-specific) STREAM_CFG register */
556        BAPE_Reg_P_UpdateField(hSpdifInput->deviceHandle, BCHP_AUD_FMM_IOP_IN_SPDIF_0_CAP_STREAM_CFG_0,
557                                                               AUD_FMM_IOP_IN_SPDIF_0_CAP_STREAM_CFG_0, CAP_ENA, 1);
558    #elif defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY  /* Shared pool of STREAM_CFG registers in IOP */
559        BAPE_Iop_P_EnableCapture( hSpdifInput->deviceHandle, inputPort->streamId[0], inputPort->numChannelPairs );
560    #else
561        #error "Unknown SPDIF register format"
562    #endif /* if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN... BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY */
563
564    /* Enable output FIFO */
565    {  /* Start Critical Section */
566        BKNI_EnterCriticalSection();
567        BAPE_Reg_P_UpdateEnum_isr(hSpdifInput->deviceHandle, BAPE_P_SPDIF_RX_CONFIG_REGADDR,
568                                                             BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUTFIFO_ENA, Enable);
569        hSpdifInput->enable = true;
570        BKNI_LeaveCriticalSection();
571    }  /* End Critical Section */
572}
573
574/**************************************************************************/
575
576static void BAPE_SpdifInput_P_Disable(BAPE_InputPort inputPort)
577{
578    BAPE_SpdifInputHandle hSpdifInput;
579
580    BDBG_OBJECT_ASSERT(inputPort, BAPE_InputPort);
581    hSpdifInput = inputPort->pHandle;
582    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
583
584    BDBG_MSG(("Disabling %s", hSpdifInput->name));
585
586    /* Disable output FIFO */
587    {  /* Start Critical Section */
588        BKNI_EnterCriticalSection();
589        BAPE_Reg_P_UpdateEnum_isr(hSpdifInput->deviceHandle, BAPE_P_SPDIF_RX_CONFIG_REGADDR,
590                                                             BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUTFIFO_ENA, Disable);
591        hSpdifInput->enable = false;
592        BKNI_LeaveCriticalSection();
593    }  /* End Critical Section */
594
595    /* Disable capture */
596    #if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN  /* Local (SPDIF-specific) STREAM_CFG register */
597        BAPE_Reg_P_UpdateField(hSpdifInput->deviceHandle, BCHP_AUD_FMM_IOP_IN_SPDIF_0_CAP_STREAM_CFG_0,
598                                                               AUD_FMM_IOP_IN_SPDIF_0_CAP_STREAM_CFG_0, CAP_ENA, 0);
599
600    #elif defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY  /* Shared pool of STREAM_CFG registers in IOP */
601        BAPE_Iop_P_DisableCapture( hSpdifInput->deviceHandle, inputPort->streamId[0], inputPort->numChannelPairs );
602    #else
603        #error "Unknown SPDIF register format"
604    #endif /* if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN... BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY */
605}
606
607/**************************************************************************/
608
609static void BAPE_SpdifInput_P_Halt_isr(BAPE_InputPort inputPort)
610{
611    BAPE_SpdifInputHandle hSpdifInput;
612
613    BKNI_ASSERT_ISR_CONTEXT();
614    BDBG_OBJECT_ASSERT(inputPort, BAPE_InputPort);
615    hSpdifInput = inputPort->pHandle;
616    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
617
618    BDBG_MSG(("Halting %s", hSpdifInput->name));
619
620    /* Disable the output FIFO. */
621    if ( hSpdifInput->enable )
622    {
623        BAPE_Reg_P_UpdateEnum_isr(hSpdifInput->deviceHandle, BAPE_P_SPDIF_RX_CONFIG_REGADDR,
624                                                             BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUTFIFO_ENA, Disable);
625    }
626}
627
628/**************************************************************************/
629
630static BERR_Code BAPE_SpdifInput_P_ConsumerAttached(BAPE_InputPort inputPort, BAPE_PathNode *pConsumer)
631{
632    BAPE_SpdifInputHandle hSpdifInput;
633
634    BDBG_OBJECT_ASSERT(inputPort, BAPE_InputPort);
635    hSpdifInput = inputPort->pHandle;
636    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
637
638    BDBG_MSG(("Attaching consumer %s", pConsumer->pName));
639
640    switch ( pConsumer->type )
641    {
642    case BAPE_PathNodeType_eDecoder:
643    case BAPE_PathNodeType_eInputCapture:
644        break;
645    default:
646        BDBG_ERR(("Node %u is not a valid consumer for SPDIF Input", pConsumer->pName));
647        return BERR_TRACE(BERR_NOT_SUPPORTED);
648    }
649
650    BDBG_ASSERT(inputPort->pConsumer == pConsumer);
651
652    /* Enable format detection interupts.  After this, the current input format
653     * will be maintained in the handle's lastFormatDetectionStatus struct.  */
654    hSpdifInput->localFormatDetectionEnabled = true;
655    BAPE_SpdifInput_P_SetFormatDetection(hSpdifInput);
656
657    {  /* Start Critical Section */
658        BKNI_EnterCriticalSection();
659
660        /* Update the InputPort's fields to match the current input format. */
661        BAPE_SpdifInput_P_UpdateInputPortFormatFields_isr (hSpdifInput, &hSpdifInput->lastFormatDetectionStatus);
662        BAPE_SpdifInput_P_SetReceiverOutputFormat_isr (hSpdifInput, &hSpdifInput->lastFormatDetectionStatus);
663
664        BKNI_LeaveCriticalSection();
665    }  /* End Critical Section */
666
667    return BERR_SUCCESS;
668}
669
670/**************************************************************************/
671
672static void BAPE_SpdifInput_P_ConsumerDetached(BAPE_InputPort inputPort, BAPE_PathNode *pConsumer)
673{
674    BAPE_SpdifInputHandle hSpdifInput;
675
676    BSTD_UNUSED(pConsumer);
677
678    BDBG_OBJECT_ASSERT(inputPort, BAPE_InputPort);
679    hSpdifInput = inputPort->pHandle;
680    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
681
682    /* Disable local format detection. */
683    hSpdifInput->localFormatDetectionEnabled = false;
684    BAPE_SpdifInput_P_SetFormatDetection(hSpdifInput);
685
686    return;
687}
688
689/***************************************************************************
690        Private functions: Protyped above
691***************************************************************************/
692
693static BERR_Code BAPE_SpdifInput_P_OpenHw(BAPE_SpdifInputHandle hSpdifInput)
694{
695
696    BAPE_Handle hApe;
697    BAPE_Reg_P_FieldList regFieldList;
698    BERR_Code errCode = BERR_SUCCESS;
699
700    /* Currently we only support one SPDIF input, this can be expanded later if we support more */
701    #if BAPE_CHIP_MAX_SPDIF_INPUTS > 1
702        #error "Need to support more SPDIF inputs"
703    #endif
704
705    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
706
707    hApe = hSpdifInput->deviceHandle;
708    BDBG_OBJECT_ASSERT(hApe, BAPE_Device);
709
710    /* Taken from RAP PI (regarding ALLOW_NZ_STUFFING=Nonzero_Ok) -->                                                                       
711    PR 35668: Some Blu Ray DVD Players send Non Zero values between compressed
712    frames. This was getting treated as PCM data and causing confusion in 3563
713    and a workaround was put. In 3548 this has been fixed in hardware.       
714    Enabling the bit here.                                                   
715    */                                                                       
716
717    BAPE_Reg_P_InitFieldList(hApe, &regFieldList);
718
719    if(hSpdifInput->inputPort.compressed)
720    {           
721        /* Set the output format ena to PES */
722        BAPE_Reg_P_AddEnumToFieldList(&regFieldList, BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUT_FORMAT_ENA, PES);
723        hSpdifInput->outFormatEna = BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUT_FORMAT_ENA, PES);  /* Remember OUT_FORMAT_ENA setting. */
724    }
725    else
726    {
727        /* Set the output format ena to PCM */
728        BAPE_Reg_P_AddEnumToFieldList(&regFieldList, BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUT_FORMAT_ENA, PCM);
729        hSpdifInput->outFormatEna = BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUT_FORMAT_ENA, PCM);  /* Remember OUT_FORMAT_ENA setting. */
730    }
731
732    BAPE_Reg_P_AddEnumToFieldList(&regFieldList, BAPE_P_SPDIF_RX_CONFIG_REGNAME, ALLOW_NZ_STUFFING, Nonzero_OK);
733
734    #if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY
735        BAPE_Reg_P_AddEnumToFieldList(&regFieldList, BAPE_P_SPDIF_RX_CONFIG_REGNAME, SOURCE_SEL, SPDIF);
736    #endif /* if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY */
737
738    BAPE_Reg_P_ApplyFieldList(&regFieldList, BAPE_P_SPDIF_RX_CONFIG_REGADDR);
739
740    /* Clear the interrupts before enabling any callbacks */
741    #if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN
742        /* Clear and unmask L3 interrupts. */
743        BAPE_Reg_P_Write(hApe, BCHP_AUD_FMM_IOP_IN_SPDIF_0_ESR_MASK_SET,     0xffffffff);
744        BAPE_Reg_P_Write(hApe, BCHP_AUD_FMM_IOP_IN_SPDIF_0_ESR_STATUS_CLEAR, 0xffffffff);
745        BAPE_Reg_P_Write(hApe, BCHP_AUD_FMM_IOP_IN_SPDIF_0_ESR_MASK_CLEAR,  BCHP_MASK( AUD_FMM_IOP_IN_SPDIF_0_ESR_MASK_CLEAR, SPDIFRX_CHAN_STAT_MASK) |
746                                                                            BCHP_MASK( AUD_FMM_IOP_IN_SPDIF_0_ESR_MASK_CLEAR, SPDIFRX_V_CHANGE_MASK)  |
747                                                                            BCHP_MASK( AUD_FMM_IOP_IN_SPDIF_0_ESR_MASK_CLEAR, SPDIFRX_PC_CHANGE_MASK) |
748                                                                            BCHP_MASK( AUD_FMM_IOP_IN_SPDIF_0_ESR_MASK_CLEAR, SPDIFRX_GOOD_FMT_MASK)  |
749                                                                            BCHP_MASK( AUD_FMM_IOP_IN_SPDIF_0_ESR_MASK_CLEAR, SPDIFRX_FMT_ERR_MASK)   |
750                                                                            BCHP_MASK( AUD_FMM_IOP_IN_SPDIF_0_ESR_MASK_CLEAR, SPDIFRX_RATE_CHANGE_MASK) );
751
752        /* Clear and unmask L2 interrupt. */
753        BAPE_Reg_P_Write(hApe, BCHP_AUD_FMM_IOP_MISC_ESR_MASK_SET,     BCHP_MASK( AUD_FMM_IOP_MISC_ESR_MASK_SET,     IOP_INTERRUPT_IN_SPDIF_0));
754        BAPE_Reg_P_Write(hApe, BCHP_AUD_FMM_IOP_MISC_ESR_STATUS_CLEAR, BCHP_MASK( AUD_FMM_IOP_MISC_ESR_STATUS_CLEAR, IOP_INTERRUPT_IN_SPDIF_0));
755        BAPE_Reg_P_Write(hApe, BCHP_AUD_FMM_IOP_MISC_ESR_MASK_CLEAR,   BCHP_MASK( AUD_FMM_IOP_MISC_ESR_MASK_CLEAR,   IOP_INTERRUPT_IN_SPDIF_0));
756
757    #endif /* if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN */
758    #if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY
759    /* Clear and unmask L2 interrupts. */
760    BAPE_Reg_P_Write(hApe, BCHP_SPDIF_RCVR_ESR_MASK_SET,   0xffffffff);
761    BAPE_Reg_P_Write(hApe, BCHP_SPDIF_RCVR_ESR_STATUS_CLEAR, 0xffffffff);
762    BAPE_Reg_P_Write(hApe, BCHP_SPDIF_RCVR_ESR_MASK_CLEAR, BCHP_MASK( SPDIF_RCVR_ESR_MASK_CLEAR, SPDIFRX_CHAN_STAT_MASK ) |
763                                                           BCHP_MASK( SPDIF_RCVR_ESR_MASK_CLEAR, SPDIFRX_V_CHANGE_MASK )  |
764                                                           BCHP_MASK( SPDIF_RCVR_ESR_MASK_CLEAR, SPDIFRX_PC_CHANGE_MASK ) |
765                                                           BCHP_MASK( SPDIF_RCVR_ESR_MASK_CLEAR, SPDIFRX_GOOD_FMT_MASK )  |
766                                                           BCHP_MASK( SPDIF_RCVR_ESR_MASK_CLEAR, SPDIFRX_FMT_ERR_MASK )   |
767                                                           BCHP_MASK( SPDIF_RCVR_ESR_MASK_CLEAR, SPDIFRX_RATE_CHANGE_MASK ));
768    #endif /* if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY */
769
770    {
771        #if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN
772            BINT_Id             intId = BCHP_INT_ID_AUD_IOP; 
773        #endif /* if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN */
774        #if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY
775            BINT_Id             intId = BCHP_INT_ID_SPDIFRX; 
776        #endif /* if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY */
777
778        errCode = BINT_CreateCallback( &hSpdifInput->spdifRxCallback,
779                                       hApe->intHandle, 
780                                       intId, 
781                                       BAPE_P_SPDIF_RX_isr, 
782                                       (void*)hSpdifInput,         
783                                       0 /* Not used*/       
784                                      );
785    }
786    if (errCode != BERR_SUCCESS) 
787    {
788        BDBG_ERR(("Unable to create SPDIF RX callback"));
789        return errCode;
790    }
791
792    return errCode;
793}
794
795/**************************************************************************/
796
797static BERR_Code BAPE_SpdifInput_P_ApplySettings(BAPE_SpdifInputHandle hSpdifInput)
798{
799    BAPE_Reg_P_FieldList regFieldList;
800    const BAPE_SpdifInputSettings *pSettings = &hSpdifInput->settings;
801
802    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
803    BDBG_ASSERT(NULL != pSettings);
804
805    BAPE_Reg_P_InitFieldList(hSpdifInput->deviceHandle, &regFieldList);
806    BAPE_Reg_P_AddToFieldList(&regFieldList, BAPE_P_SPDIF_RX_CONFIG_REGNAME, IGNORE_VALID_PCM, pSettings->ignoreValidity);
807    BAPE_Reg_P_AddToFieldList(&regFieldList, BAPE_P_SPDIF_RX_CONFIG_REGNAME, IGNORE_PERR_PCM,  pSettings->ignorePcmParity);
808    BAPE_Reg_P_AddToFieldList(&regFieldList, BAPE_P_SPDIF_RX_CONFIG_REGNAME, IGNORE_PERR_COMP, pSettings->ignoreCompressedParity);
809    BAPE_Reg_P_AddToFieldList(&regFieldList, BAPE_P_SPDIF_RX_CONFIG_REGNAME, TIMEBASE_SEL,     pSettings->timebase);
810
811    switch ( pSettings->errorInsertion ) 
812    {
813    case BAPE_SpdifInputErrorInsertion_eNone:
814        BAPE_Reg_P_AddEnumToFieldList(&regFieldList, BAPE_P_SPDIF_RX_CONFIG_REGNAME, INSERT_MODE, No_insert);
815        break;
816    case BAPE_SpdifInputErrorInsertion_eZero:
817        BAPE_Reg_P_AddEnumToFieldList(&regFieldList, BAPE_P_SPDIF_RX_CONFIG_REGNAME, INSERT_MODE, Insert_zero);
818        break;
819    case BAPE_SpdifInputErrorInsertion_eRepeat:
820        BAPE_Reg_P_AddEnumToFieldList(&regFieldList, BAPE_P_SPDIF_RX_CONFIG_REGNAME, INSERT_MODE, Insert_repeat);
821        break;
822    default:
823        BDBG_ERR(("Invalid Error Insertion Mode %d", pSettings->errorInsertion));
824        return BERR_TRACE(BERR_INVALID_PARAMETER);
825    }
826
827    {  /* Start Critical Section */
828        BKNI_EnterCriticalSection();
829        BAPE_Reg_P_ApplyFieldList(&regFieldList, BAPE_P_SPDIF_RX_CONFIG_REGADDR);
830        BKNI_LeaveCriticalSection();
831    }  /* End Critical Section */
832
833    return BERR_SUCCESS;
834}
835
836/**************************************************************************/
837
838static void BAPE_P_SPDIF_RX_isr (
839        void * pParm1, /* [in] channel handle */
840        int    iParm2  /* [in] Not used */       
841)
842{
843    BAPE_SpdifInputHandle   hSpdifInput = NULL;
844    uint32_t                ui32IntStatus=0;
845    uint32_t                ui32MaskStatus=0;
846
847    BDBG_ENTER (BAPE_P_SPDIF_RX_isr);
848
849    BKNI_ASSERT_ISR_CONTEXT();
850    BDBG_ASSERT (pParm1);
851    BSTD_UNUSED(iParm2);
852
853    hSpdifInput = (BAPE_SpdifInputHandle) pParm1;
854
855    #if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN
856        ui32IntStatus = BAPE_Reg_P_Read_isr(hSpdifInput->deviceHandle,  BCHP_AUD_FMM_IOP_IN_SPDIF_0_ESR_STATUS);
857        ui32MaskStatus = BAPE_Reg_P_Read_isr(hSpdifInput->deviceHandle, BCHP_AUD_FMM_IOP_IN_SPDIF_0_ESR_MASK);
858    #endif
859    #if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY
860        ui32IntStatus = BAPE_Reg_P_Read_isr(hSpdifInput->deviceHandle,  BCHP_SPDIF_RCVR_ESR_STATUS);
861        ui32MaskStatus = BAPE_Reg_P_Read_isr(hSpdifInput->deviceHandle, BCHP_SPDIF_RCVR_ESR_MASK);
862    #endif
863
864    ui32IntStatus &= ~ui32MaskStatus;
865
866    BDBG_MSG(("SPDIF_RX_ISR: ESR_STATUS (unmasked): 0x%x", ui32IntStatus));
867
868    if (ui32IntStatus)
869    {
870        #if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN
871            BAPE_Reg_P_Write_isr(hSpdifInput->deviceHandle, BCHP_AUD_FMM_IOP_MISC_ESR_STATUS_CLEAR, BCHP_MASK( AUD_FMM_IOP_MISC_ESR_STATUS_CLEAR, IOP_INTERRUPT_IN_SPDIF_0));
872            BAPE_Reg_P_Write_isr(hSpdifInput->deviceHandle, BCHP_AUD_FMM_IOP_IN_SPDIF_0_ESR_STATUS_CLEAR, ui32IntStatus);
873        #endif
874        #if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY
875            BAPE_Reg_P_Write_isr(hSpdifInput->deviceHandle, BCHP_SPDIF_RCVR_ESR_STATUS_CLEAR, ui32IntStatus);
876        #endif
877
878        BAPE_SpdifInput_P_DetectInputChange_isr(hSpdifInput);
879    }
880    BDBG_LEAVE (BAPE_P_SPDIF_RX_isr);
881    return;   
882}
883
884/**************************************************************************/
885
886static BERR_Code BAPE_SpdifInput_P_SetFormatDetection(
887    BAPE_SpdifInputHandle hSpdifInput
888    )
889{
890    BERR_Code ret = BERR_SUCCESS;
891    bool formatDetectionRequired = false;
892
893    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
894
895
896    /* There are two reasons for enabling format detection.  First, when the input is enabled, we need
897     * to use format detection for setting up the receiver's output format, and to halt the outfifo
898     * in the case of a format change that can't be handled on-the-fly.  Secondly, the client (Nexus)
899     * can enable format detection to keep track of the current input format.
900     * So start by checking to see if anybody needs format detection on. */
901
902    /* Check to see if our client needs format detection. */
903    if ( hSpdifInput->clientFormatDetectionSettings.enabled == true && 
904         hSpdifInput->clientFormatDetectionSettings.formatChangeInterrupt.pCallback_isr) {
905
906        formatDetectionRequired = true;
907    }
908
909    /* Now see if we need it internally.  */
910    if ( hSpdifInput->localFormatDetectionEnabled )
911    {
912        formatDetectionRequired = true;
913    }
914
915    /* If it's not enabled and somebody needs it, then turn it on. */
916    if (! hSpdifInput->formatDetectionEnabled && formatDetectionRequired )
917    {
918        {  /* Start Critical Section */
919            BKNI_EnterCriticalSection();
920
921            /* Make a call to BAPE_SpdifInput_P_GetFormatDetectionStatus_isr() to get a
922             * fresh snapshot of the current state of things from the hardware
923             * (so that we can detect a change when interrupts occur later.   */ 
924            BAPE_SpdifInput_P_GetFormatDetectionStatus_isr(hSpdifInput, &hSpdifInput->lastFormatDetectionStatus);
925
926            BKNI_LeaveCriticalSection();
927        }  /* End Critical Section */
928
929        BINT_EnableCallback(hSpdifInput->spdifRxCallback);
930        hSpdifInput->formatDetectionEnabled = true;
931    }
932
933    /* If format detection is enabled, but nobody needs it, then turn if off.  */
934    if ( hSpdifInput->formatDetectionEnabled && ! formatDetectionRequired )
935    {
936        if( hSpdifInput->spdifRxCallback )
937        {
938            hSpdifInput->formatDetectionEnabled = false;
939            ret = BINT_DisableCallback(hSpdifInput->spdifRxCallback);
940            if (ret != BERR_SUCCESS)                             
941            {                                                   
942                BDBG_ERR(("Unable to Disable SPDIF RX callback")); 
943            }                                                   
944        }
945    }
946
947    return BERR_SUCCESS;
948}
949
950/**************************************************************************/
951
952static BERR_Code BAPE_SpdifInput_P_GetFormatDetectionStatus_isr(BAPE_SpdifInputHandle hSpdifInput, BAPE_SpdifInputFormatDetectionStatus *pStatus)
953{
954    uint32_t        receiverStatusRegVal = 0;
955    uint32_t        receiverStatusStreamType = 0;
956    uint32_t        receiverStatusSampleRate = 0;
957    uint32_t        receiverStatusBurstPreamble = 0;   
958
959    BDBG_ENTER(BAPE_SpdifInput_P_GetFormatDetectionStatus_isr);
960
961    BKNI_ASSERT_ISR_CONTEXT();
962    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
963    BDBG_ASSERT(pStatus);   
964
965    /* Clear out the destination buffer. */
966    BKNI_Memset(pStatus, 0, sizeof (*pStatus));
967
968    /* Set some default values in case we don't find a reason to change them. */
969    pStatus->codec            = BAVC_AudioCompressionStd_eMax;
970    pStatus->numPcmChannels   = 0;
971
972    /* Let them know if the format change interrupts are enabled.  */
973    pStatus->detectionEnabled   = false;
974    if (hSpdifInput->clientFormatDetectionSettings.enabled == true && hSpdifInput->clientFormatDetectionSettings.formatChangeInterrupt.pCallback_isr) {
975        pStatus->detectionEnabled   = true;
976    }
977
978    receiverStatusRegVal     = BAPE_Reg_P_Read(hSpdifInput->deviceHandle, BAPE_P_SPDIF_RX_STATUS_REGADDR );
979
980#if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_IOPIN
981    BDBG_MSG(("RCVR_STATUS: BURST_PC:0x%u BPC_VLD:%u CSTAT_VLD:%u GOOD_BP:%u STREAM_TYPE:%u VALIDITY R/L:%u/%u SIG_PRES:%u SAMP_RATE:%u",
982               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, BURST_PREAM_C),
983               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, BPC_VALID),
984               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, CHAN_STAT_VALID),
985               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, GOOD_BIPHASE),
986               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, STREAM_TYPE),
987               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, VALIDITY_R),
988               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, VALIDITY_L),
989               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, SIGNAL_PRESENT),
990               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE)  ));
991#endif
992#if defined BAPE_CHIP_SPDIF_INPUT_TYPE_IS_LEGACY
993    BDBG_MSG(("RCVR_STATUS: BURST_PC:0x%u BPC_VLD:%u GOOD_BP:%u STREAM_TYPE:%u VALIDITY R/L:%u/%u SIG_PRES:%u SAMP_RATE:%u",
994               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, BURST_PREAM_C),
995               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, BPC_VALID),
996               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, GOOD_BIPHASE),
997               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, STREAM_TYPE),
998               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, VALIDITY_R),
999               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, VALIDITY_L),
1000               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, SIGNAL_PRESENT),
1001               BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE)  ));
1002#endif
1003
1004    pStatus->goodBiphase     = BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, GOOD_BIPHASE);
1005    pStatus->pcValid         = BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, BPC_VALID);
1006    pStatus->signalPresent   = BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, SIGNAL_PRESENT);
1007    pStatus->leftValidity    = BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, VALIDITY_L);
1008    pStatus->rightValidity   = BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, VALIDITY_R);
1009    receiverStatusStreamType = BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, STREAM_TYPE);
1010    pStatus->compressed = (receiverStatusStreamType == BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_STATUS_REGNAME, STREAM_TYPE, Compressed)) ? true : false;
1011
1012    /* Get the sample rate and convert to an integer. */
1013    receiverStatusSampleRate = BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE);
1014
1015    switch (receiverStatusSampleRate)
1016    {
1017        case BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE, SR_16000Hz ):      pStatus->sampleRate =   16000;     break;
1018        case BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE, SR_22050Hz ):      pStatus->sampleRate =   22050;     break;
1019        case BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE, SR_24000Hz ):      pStatus->sampleRate =   24000;     break;
1020        case BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE, SR_32000Hz ):      pStatus->sampleRate =   32000;     break;
1021        case BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE, SR_44100Hz ):      pStatus->sampleRate =   44100;     break;
1022        case BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE, SR_48000Hz ):      pStatus->sampleRate =   48000;     break;
1023        case BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE, SR_64000Hz ):      pStatus->sampleRate =   64000;     break;
1024        case BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE, SR_88200Hz ):      pStatus->sampleRate =   88200;     break;
1025        case BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE, SR_96000Hz ):      pStatus->sampleRate =   96000;     break;
1026        case BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE, SR_128000Hz):      pStatus->sampleRate =  128000;     break;
1027        case BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE, SR_176400Hz):      pStatus->sampleRate =  176400;     break;
1028        case BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_STATUS_REGNAME, SAMPLE_RATE, SR_192000Hz):      pStatus->sampleRate =  192000;     break;
1029        default:                                                                              pStatus->sampleRate =       0;     break;
1030    }           
1031
1032    if ( pStatus->sampleRate == 0 )
1033    {
1034        BDBG_MSG (("SPDIF_RCVR_CTRL_STATUS : Sample Rate is Unknown"));
1035    }
1036    else
1037    {
1038        BDBG_MSG (("SPDIF_RCVR_CTRL_STATUS : Sample Rate is %u", pStatus->sampleRate ));
1039    }
1040
1041    if ( ! pStatus->compressed )
1042    {
1043        pStatus->codec = BAVC_AudioCompressionStd_ePcm;
1044        BDBG_MSG (("SPDIF_RCVR_CTRL_STATUS : Uncompressed => BAVC_AudioCompressionStd_ePcm"));
1045        pStatus->numPcmChannels = 2;
1046    }
1047    else  /* must be compressed */
1048    {
1049            BDBG_MSG (("SPDIF_RCVR_CTRL_STATUS : Compressed... Need to check Preamble C bits"));
1050            if (!pStatus->pcValid)   /* If Preamble C is not valid */
1051            {
1052                pStatus->codec = BAVC_AudioCompressionStd_eMax;
1053                BDBG_MSG (("Preamble C: Not yet valid: BAVC_AudioCompressionStd_eMax"));
1054            }       
1055            else /* if preamble C is valid... */
1056            {
1057                receiverStatusBurstPreamble = BCHP_GET_FIELD_DATA(receiverStatusRegVal, BAPE_P_SPDIF_RX_STATUS_REGNAME, BURST_PREAM_C);
1058
1059                BAPE_InputPort_P_BurstPreambleToCodec(receiverStatusBurstPreamble, &pStatus->codec );
1060
1061            } /* End if preambleC is valid */
1062    } /* End if not linear PCM */
1063
1064    BDBG_LEAVE(BAPE_SpdifInput_P_GetFormatDetectionStatus_isr);   
1065
1066    return BERR_SUCCESS;
1067}
1068
1069/**************************************************************************/
1070
1071static void BAPE_SpdifInput_P_DetectInputChange_isr (BAPE_SpdifInputHandle    hSpdifInput)
1072{
1073    BAPE_SpdifInputFormatDetectionStatus  oldFormatDetectionStatus, *pOldFormatDetectionStatus, *pNewFormatDetectionStatus;
1074    BERR_Code errCode;
1075
1076    BDBG_ENTER(BAPE_SpdifInput_P_DetectInputChange_isr);
1077
1078    BKNI_ASSERT_ISR_CONTEXT();
1079    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
1080
1081    pOldFormatDetectionStatus = &oldFormatDetectionStatus;
1082    pNewFormatDetectionStatus = &hSpdifInput->lastFormatDetectionStatus;
1083
1084    /* Make a copy of the current "old" format detection snapshot. */
1085    BKNI_Memcpy_isr(pOldFormatDetectionStatus, pNewFormatDetectionStatus, sizeof hSpdifInput->lastFormatDetectionStatus);
1086
1087    /* Now build a "new" format detection snapshot by reading the hardware. */
1088    BAPE_SpdifInput_P_GetFormatDetectionStatus_isr(hSpdifInput, pNewFormatDetectionStatus);
1089
1090
1091#if 0  /* ==================== Start: Legacy code left here for reference ==================== */
1092    {
1093        uint32_t    chanStatL0 = 0;
1094
1095        chanStatL0 = BAPE_Reg_P_Read(hSpdifInput->deviceHandle, BCHP_SPDIF_RCVR_CTRL_CHAN_STAT_L0);
1096
1097        bGoodBiphase = (bool) BCHP_GET_FIELD_DATA ( ui32SpdifRxCtrlStatus, SPDIF_RCVR_CTRL0_STATUS, GOOD_BIPHASE);
1098
1099        bValidLeft = (bool) BCHP_GET_FIELD_DATA ( ui32SpdifRxCtrlStatus, SPDIF_RCVR_CTRL0_STATUS, VALIDITY_L);
1100
1101        ui32SampleRate = (uint32_t) BCHP_GET_FIELD_DATA ( ui32SpdifRxCtrlStatus, SPDIF_RCVR_CTRL0_STATUS, SAMPLE_RATE);
1102
1103        if ((bGoodBiphase) || (ui32SampleRate > 11))
1104        {
1105            /* No Good input or Rate Not Indicated */
1106            eInputState = BAPE_P_SpdifRx_InputState_eStreamNone;
1107        }
1108        else if ((bValidLeft) || (ui32ChanStatus & CBITS_STREAMTYPE))
1109        {
1110            /* One Validity bit set or CBIT 1 set indicates compressed */
1111            eInputState = BAPE_P_SpdifRx_InputState_eStreamPendingCompress;
1112        }
1113        else
1114        {
1115            eInputState = BAPE_P_SpdifRx_InputState_eStreamPCM;   
1116        }
1117
1118    }
1119#endif   /* ==================== End: Legacy code left here for reference ==================== */
1120
1121    BAPE_SpdifInput_P_SetReceiverOutputFormat_isr (hSpdifInput, pNewFormatDetectionStatus);
1122
1123    if (BKNI_Memcmp_isr(pNewFormatDetectionStatus, pOldFormatDetectionStatus, sizeof (*pNewFormatDetectionStatus)) != 0)
1124    {
1125        BAPE_SpdifInput_P_UpdateInputPortFormatFields_isr (hSpdifInput, pNewFormatDetectionStatus);
1126
1127        /* Let the consumer know about the format change. */
1128        errCode = BAPE_InputPort_P_FormatChanged_isr(&hSpdifInput->inputPort);
1129        if ( errCode )
1130        {
1131            /* The format change can't be handled on-the-fly, so stop the capture. */
1132            BAPE_SpdifInput_P_Halt_isr(&hSpdifInput->inputPort);
1133        }
1134
1135        if (hSpdifInput->clientFormatDetectionSettings.enabled == true && hSpdifInput->clientFormatDetectionSettings.formatChangeInterrupt.pCallback_isr) 
1136        {
1137            BDBG_MSG(("Calling format change callback ", __FUNCTION__, __LINE__   ));
1138            hSpdifInput->clientFormatDetectionSettings.formatChangeInterrupt.pCallback_isr(
1139                                        hSpdifInput->clientFormatDetectionSettings.formatChangeInterrupt.pParam1,
1140                                        hSpdifInput->clientFormatDetectionSettings.formatChangeInterrupt.param2);
1141        }
1142
1143        /* Done with the important stuff,  now print out each of the fields and indicate whether they've changed. */
1144        #define BAPE_PRINT_CHANGE(name, pfmt, old, new)                                  \
1145                (  (old) != (new)                                                                                                        \
1146                        ?          BDBG_MSG(("%s: " pfmt " -> " pfmt , name,     (old),  (new )))    \
1147                        :          BDBG_MSG(("%s: " pfmt, name, (new) ))                                             \
1148                )
1149
1150        BDBG_MSG(("--------SPDIF Input Format Change Detection ---- begin ----"));
1151
1152        BAPE_PRINT_CHANGE("  Codec from Preamble C", "%s",     BAPE_P_GetCodecName(pOldFormatDetectionStatus->codec),                   BAPE_P_GetCodecName(pNewFormatDetectionStatus->codec)  ); 
1153        BAPE_PRINT_CHANGE("  Num Chans (PCM only) ", "%u",     pOldFormatDetectionStatus->numPcmChannels,   pNewFormatDetectionStatus->numPcmChannels );
1154        BAPE_PRINT_CHANGE("  Sample Rate          ", "%u",     pOldFormatDetectionStatus->sampleRate,       pNewFormatDetectionStatus->sampleRate );
1155        BAPE_PRINT_CHANGE("  Signal Present       ", "%s",     pOldFormatDetectionStatus->signalPresent    ? "TRUE" : "false", pNewFormatDetectionStatus->signalPresent    ? "TRUE" : "false" );
1156        BAPE_PRINT_CHANGE("  Compressed Flag      ", "%s",     pOldFormatDetectionStatus->compressed       ? "TRUE" : "false",       pNewFormatDetectionStatus->compressed ? "TRUE" : "false" );
1157        BAPE_PRINT_CHANGE("  Preamble C Valid     ", "%s",     pOldFormatDetectionStatus->pcValid          ? "TRUE" : "false", pNewFormatDetectionStatus->pcValid          ? "TRUE" : "false" );
1158        BAPE_PRINT_CHANGE("  Good BiPhase         ", "%s",     pOldFormatDetectionStatus->goodBiphase      ? "TRUE" : "false", pNewFormatDetectionStatus->goodBiphase      ? "TRUE" : "false" );
1159        BAPE_PRINT_CHANGE("  Left Validity        ", "%s",     pOldFormatDetectionStatus->leftValidity     ? "TRUE" : "false", pNewFormatDetectionStatus->leftValidity     ? "TRUE" : "false" );
1160        BAPE_PRINT_CHANGE("  Right Validity       ", "%s",     pOldFormatDetectionStatus->rightValidity    ? "TRUE" : "false", pNewFormatDetectionStatus->rightValidity    ? "TRUE" : "false" );
1161        BAPE_PRINT_CHANGE("  Detection Enabled    ", "%s",     pOldFormatDetectionStatus->detectionEnabled ? "TRUE" : "false", pNewFormatDetectionStatus->detectionEnabled ? "TRUE" : "false" );
1162
1163        BDBG_MSG(("--------SPDIF Input Format Change Detection ---- end ----"));
1164    }
1165
1166    BDBG_LEAVE (BAPE_SpdifInput_P_DetectInputChange_isr);   
1167    return;
1168}
1169
1170/**************************************************************************/
1171
1172static void BAPE_SpdifInput_P_SetReceiverOutputFormat_isr (BAPE_SpdifInputHandle hSpdifInput, BAPE_SpdifInputFormatDetectionStatus *pFormatDetectionStatus)
1173{
1174    uint32_t  outFormatEna;
1175
1176    BDBG_ENTER(BAPE_SpdifInput_P_SetReceiverOutputFormat_isr);
1177
1178    BKNI_ASSERT_ISR_CONTEXT();
1179    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
1180
1181    if ( pFormatDetectionStatus->compressed)
1182    {
1183        if ( hSpdifInput->inputPort.pConsumer && hSpdifInput->inputPort.pConsumer->type == BAPE_PathNodeType_eInputCapture )
1184        {
1185            outFormatEna =  BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUT_FORMAT_ENA, COMP);
1186        }
1187        else
1188        {
1189            outFormatEna =  BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUT_FORMAT_ENA, PES);
1190        }
1191    }
1192    else
1193    {
1194        outFormatEna =  BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUT_FORMAT_ENA, PCM);
1195    }
1196
1197    if ( outFormatEna != hSpdifInput->outFormatEna )
1198    {
1199        hSpdifInput->outFormatEna = outFormatEna; /* Update the saved state in the handle. */
1200
1201        BDBG_MSG (("Switching SPDIF Receiver output format to %s", 
1202                   (outFormatEna ==  BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUT_FORMAT_ENA, COMP) ) ? "COMP" :
1203                   (outFormatEna ==  BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUT_FORMAT_ENA, PES) )  ? "PES"  :
1204                   (outFormatEna ==  BAPE_P_BCHP_ENUM(BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUT_FORMAT_ENA, PCM) )  ? "PCM"  :
1205                                                                                                            "Unknown" ));
1206
1207        BAPE_Reg_P_UpdateField_isr(hSpdifInput->deviceHandle, 
1208                                  BAPE_P_SPDIF_RX_CONFIG_REGADDR, 
1209                                  BAPE_P_SPDIF_RX_CONFIG_REGNAME, OUT_FORMAT_ENA, outFormatEna);
1210    }
1211    BDBG_LEAVE (BAPE_SpdifInput_P_SetReceiverOutputFormat_isr);   
1212    return;
1213}
1214
1215/**************************************************************************/
1216
1217static void BAPE_SpdifInput_P_UpdateInputPortFormatFields_isr (BAPE_SpdifInputHandle hSpdifInput, BAPE_SpdifInputFormatDetectionStatus *pFormatDetectionStatus)
1218{
1219    BAPE_InputPort  inputPort;
1220    BDBG_ENTER(BAPE_SpdifInput_P_UpdateInputPortFormatFields_isr);
1221
1222    BKNI_ASSERT_ISR_CONTEXT();
1223    BDBG_OBJECT_ASSERT(hSpdifInput, BAPE_SpdifInput);
1224
1225    inputPort = &hSpdifInput->inputPort;
1226    BDBG_OBJECT_ASSERT(inputPort, BAPE_InputPort);
1227
1228    inputPort->sampleRate = pFormatDetectionStatus->sampleRate;
1229    inputPort->compressed = pFormatDetectionStatus->compressed;
1230
1231    if ( pFormatDetectionStatus->compressed )
1232    {
1233        inputPort->numChannelPairs = 1;
1234    }
1235    else if ( pFormatDetectionStatus->numPcmChannels > 0  )
1236    {
1237        inputPort->numChannelPairs = (((pFormatDetectionStatus->numPcmChannels - 1) / 2) + 1);
1238    }
1239    else
1240    {
1241        inputPort->numChannelPairs = 1;   /* Probably idle or unknown format... just default to 1 pair. */
1242    }
1243    BDBG_MSG (("Updated InputPort format fields: sampleRate:%u, numChannelPairs:%u, compressed:%s", 
1244               inputPort->sampleRate, 
1245               inputPort->numChannelPairs, 
1246               inputPort->compressed ? "TRUE" : "false" ));
1247
1248    BDBG_LEAVE (BAPE_SpdifInput_P_UpdateInputPortFormatFields_isr);   
1249    return;
1250}
1251
1252/***************************************************************************
1253    Define stub functions for when there are no SPDIF inputs.
1254***************************************************************************/
1255#else /* BAPE_CHIP_MAX_SPDIF_INPUTS > 0 */
1256    /* No SPDIF inputs, just use stubbed out functions. */
1257
1258/**************************************************************************/
1259void BAPE_SpdifInput_GetDefaultSettings(
1260    BAPE_SpdifInputSettings *pSettings        /* [out] */
1261    )
1262{
1263    BSTD_UNUSED(pSettings);
1264}
1265
1266/**************************************************************************/
1267
1268BERR_Code BAPE_SpdifInput_Open(
1269    BAPE_Handle deviceHandle,
1270    unsigned index,
1271    const BAPE_SpdifInputSettings *pSettings,
1272    BAPE_SpdifInputHandle *pHandle              /* [out] */
1273    )
1274{
1275    BSTD_UNUSED(deviceHandle);
1276    BSTD_UNUSED(index);
1277    BSTD_UNUSED(pSettings);
1278    BSTD_UNUSED(pHandle);
1279    return BERR_TRACE(BERR_NOT_SUPPORTED);
1280}
1281
1282/**************************************************************************/
1283
1284void BAPE_SpdifInput_Close(
1285    BAPE_SpdifInputHandle handle
1286    )
1287{
1288    BSTD_UNUSED(handle);
1289}
1290
1291/**************************************************************************/
1292
1293void BAPE_SpdifInput_GetSettings(
1294    BAPE_SpdifInputHandle handle,
1295    BAPE_SpdifInputSettings *pSettings        /* [out] */
1296    )
1297{
1298    BSTD_UNUSED(handle);
1299    BSTD_UNUSED(pSettings);
1300}
1301
1302/**************************************************************************/
1303
1304BERR_Code BAPE_SpdifInput_SetSettings(
1305    BAPE_SpdifInputHandle handle,
1306    const BAPE_SpdifInputSettings *pSettings
1307    )
1308{
1309    BSTD_UNUSED(handle);
1310    BSTD_UNUSED(pSettings);
1311    return BERR_TRACE(BERR_NOT_SUPPORTED);
1312}
1313
1314/**************************************************************************/
1315
1316void BAPE_SpdifInput_GetInputPort(
1317    BAPE_SpdifInputHandle handle,
1318    BAPE_InputPort *pPort
1319    )
1320{
1321    BSTD_UNUSED(handle);
1322    BSTD_UNUSED(pPort);
1323}
1324
1325/**************************************************************************/
1326
1327void BAPE_SpdifInput_GetFormatDetectionSettings(
1328    BAPE_SpdifInputHandle handle,
1329    BAPE_SpdifInputFormatDetectionSettings *pSettings   /* [out] */
1330    )
1331{
1332    BSTD_UNUSED(handle);
1333    BSTD_UNUSED(pSettings);
1334}
1335
1336/**************************************************************************/
1337
1338BERR_Code BAPE_SpdifInput_SetFormatDetectionSettings(
1339    BAPE_SpdifInputHandle handle,
1340    const BAPE_SpdifInputFormatDetectionSettings *pSettings
1341    )
1342{
1343    BSTD_UNUSED(handle);
1344    BSTD_UNUSED(pSettings);
1345    return BERR_TRACE(BERR_NOT_SUPPORTED);
1346}
1347
1348/**************************************************************************/
1349
1350BERR_Code BAPE_SpdifInput_GetFormatDetectionStatus(
1351    BAPE_SpdifInputHandle handle,
1352    BAPE_SpdifInputFormatDetectionStatus *pStatus
1353    )
1354{
1355    BSTD_UNUSED(handle);
1356    BSTD_UNUSED(pStatus);
1357    return BERR_TRACE(BERR_NOT_SUPPORTED);
1358}
1359
1360/**************************************************************************/
1361
1362BERR_Code BAPE_SpdifInput_P_PrepareForStandby(BAPE_Handle bapeHandle)
1363{
1364    BSTD_UNUSED(bapeHandle);
1365    return BERR_SUCCESS;
1366}
1367
1368/**************************************************************************/
1369
1370BERR_Code BAPE_SpdifInput_P_ResumeFromStandby(BAPE_Handle bapeHandle)
1371{
1372    BSTD_UNUSED(bapeHandle);
1373    return BERR_SUCCESS;
1374}
1375
1376#endif
Note: See TracBrowser for help on using the repository browser.