source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/vbi/7552/bvbi_wssd.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 10.9 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2009, 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: bvbi_wssd.c $
11 * $brcm_Revision: Hydra_Software_Devel/2 $
12 * $brcm_Date: 12/21/09 7:07p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/portinginterface/vbi/7400/bvbi_wssd.c $
19 *
20 * Hydra_Software_Devel/2   12/21/09 7:07p darnstein
21 * SW7550-120: Add support for SECAM variants.
22 *
23 * Hydra_Software_Devel/1   12/3/08 8:03p darnstein
24 * PR45819:
25 *
26 ***************************************************************************/
27
28#include "bstd.h"           /* standard types */
29#include "bdbg.h"           /* Dbglib */
30#include "bvbi.h"           /* VBI processing, this module. */
31#include "bkni.h"                       /* For critical sections */
32#include "bvbi_priv.h"      /* VBI internal data structures */
33#if (BVBI_P_NUM_VDEC >= 1)
34#include "bchp_wssd_0.h"    /* RDB info for WSSD core */
35#endif
36#if (BVBI_P_NUM_VDEC >= 2)
37#include "bchp_wssd_1.h"    /* RDB info for WSSD core */
38#endif
39
40BDBG_MODULE(BVBI);
41
42
43/***************************************************************************
44* Forward declarations of static (private) functions
45***************************************************************************/
46
47#define BCHP_WSSD_0_Status_DATA_OVERRUN_WSSD_CLEAR_STATUS 0x1
48#define BCHP_WSSD_0_Status_DATA_LOCK_WSSD_CLEAR_STATUS    0x1
49#define BCHP_WSSD_0_Status_PARITY_ERROR_WSSD_CLEAR_STATUS 0x1
50#define BCHP_WSSD_0_Status_DIFFERENCE_WSSD_CLEAR_STATUS   0x1
51
52
53/***************************************************************************
54* Implementation of supporting WSS functions that are not in API
55***************************************************************************/
56
57#if (BVBI_P_NUM_VDEC >= 1) /** { **/
58
59/***************************************************************************
60 *
61 */
62void BVBI_P_WSS_Dec_Init (BREG_Handle hReg, uint32_t ulCoreOffset)
63{
64        uint32_t ulResetReg;
65        uint32_t ulControlReg;
66        uint32_t ulStatusReg;
67        uint32_t ulThresholdReg;
68        uint32_t ulThresholdVal;
69        uint32_t ulSyncLevelVal;
70
71        BDBG_ENTER(BVBI_P_WSS_Dec_Init);
72
73#if (BCHP_CHIP == 3548)
74        /* Brad Grossman
75        ulThresholdVal = 0x230;
76        ulSyncLevelVal = 0x79;
77        */
78        /* David Arnstein */
79        ulThresholdVal = 0x180;
80        ulSyncLevelVal = 0x7D;
81#elif (BCHP_CHIP == 3556) && (BCHP_VER == BCHP_VER_A0)
82        /* Same as above case */
83        ulThresholdVal = 0x180;
84        ulSyncLevelVal = 0x7D;
85#elif (BCHP_CHIP == 3556) && (BCHP_VER >= BCHP_VER_B0)
86        /* This may need tuning */
87        ulThresholdVal = 0x180;
88        ulSyncLevelVal = 0x7B;
89#else
90        ulThresholdVal = 0x150;
91        ulSyncLevelVal = 0x7e;
92#endif
93
94        BKNI_EnterCriticalSection();
95
96        /* Start by resetting the whole core */
97        ulResetReg = 0x0;
98        BREG_Write32 (hReg, BCHP_WSSD_0_Reset + ulCoreOffset, ulResetReg);
99
100        /* Program the control register */
101        ulControlReg = BREG_Read32 (hReg, BCHP_WSSD_0_Control + ulCoreOffset);
102        ulControlReg &= ~(
103                BCHP_MASK       (WSSD_0_Control, DISABLE_WINDOW               ) |
104                BCHP_MASK       (WSSD_0_Control, SYNC_LEVEL                   ) |
105                BCHP_MASK       (WSSD_0_Control, WSS_FIELD                    ) |
106                BCHP_MASK       (WSSD_0_Control, LINE_OFFSET                  ) |
107                BCHP_MASK       (WSSD_0_Control, HSYNC_DELAY                  ) |
108                BCHP_MASK       (WSSD_0_Control, ENABLE_WSS_DECODE            ) );
109        ulControlReg |= (
110                BCHP_FIELD_ENUM (WSSD_0_Control, DISABLE_WINDOW, ENABLE_WINDOW) |
111                BCHP_FIELD_DATA (WSSD_0_Control, SYNC_LEVEL,    ulSyncLevelVal) |
112                BCHP_FIELD_DATA (WSSD_0_Control, WSS_FIELD,                  0) |
113                BCHP_FIELD_DATA (WSSD_0_Control, LINE_OFFSET,             0x17) |
114                BCHP_FIELD_DATA (WSSD_0_Control, HSYNC_DELAY,            0x040) |
115                BCHP_FIELD_ENUM (WSSD_0_Control, ENABLE_WSS_DECODE,   DISABLED) );
116        BREG_Write32 (hReg, BCHP_WSSD_0_Control + ulCoreOffset, ulControlReg);
117
118        /* Clear the status register */
119        ulStatusReg = 0x0;
120        ulStatusReg |= (
121                BCHP_FIELD_ENUM (WSSD_0_Status, DATA_OVERRUN, WSSD_CLEAR_STATUS) |
122                BCHP_FIELD_ENUM (WSSD_0_Status, DATA_LOCK,    WSSD_CLEAR_STATUS) |
123                BCHP_FIELD_ENUM (WSSD_0_Status, PARITY_ERROR, WSSD_CLEAR_STATUS) |
124                BCHP_FIELD_ENUM (WSSD_0_Status, DIFFERENCE,   WSSD_CLEAR_STATUS) );
125        BREG_Write32 (hReg, BCHP_WSSD_0_Status + ulCoreOffset, ulStatusReg);
126
127        /* Program threshold values */
128        ulThresholdReg = BREG_Read32 (hReg, BCHP_WSSD_0_Threshold + ulCoreOffset);
129        ulThresholdReg &= ~(
130                BCHP_MASK       (WSSD_0_Threshold, ADAPT_THRESHOLD       ) |
131                BCHP_MASK       (WSSD_0_Threshold, THRESHOLD             ) );
132        ulThresholdReg |= (
133#ifdef BVBI_P_WSSD_VER2
134                BCHP_FIELD_ENUM (WSSD_0_Threshold, ADAPT_THRESHOLD,    ADAPT) |
135#else
136                BCHP_FIELD_ENUM (WSSD_0_Threshold, ADAPT_THRESHOLD,     HOLD) |
137#endif
138                BCHP_FIELD_DATA (WSSD_0_Threshold, THRESHOLD, ulThresholdVal) );
139        BREG_Write32 (hReg, BCHP_WSSD_0_Threshold + ulCoreOffset, ulThresholdReg);
140
141        BKNI_LeaveCriticalSection();
142
143        BDBG_LEAVE(BVBI_P_WSS_Dec_Init);
144}
145
146/***************************************************************************
147 *
148 */
149BERR_Code BVBI_P_WSS_Dec_Program (
150        BREG_Handle hReg,
151        BAVC_SourceId eSource,
152        bool bActive,
153        BFMT_VideoFmt eVideoFormat,
154        uint16_t wssVline576i)
155{
156        uint32_t ulControlReg;
157        uint32_t ulStatusReg;
158        uint32_t ulOffset;
159        uint32_t line_offset;
160
161        BDBG_ENTER(BVBI_P_WSS_Dec_Program);
162
163        /* Complain if video format is not supported */
164        switch (eVideoFormat)
165        {
166        /* NTSC case is just for testing */
167    case BFMT_VideoFmt_eNTSC:
168                line_offset = 0;
169                break;
170
171    case BFMT_VideoFmt_ePAL_B:
172    case BFMT_VideoFmt_ePAL_B1:
173    case BFMT_VideoFmt_ePAL_D:
174    case BFMT_VideoFmt_ePAL_D1:
175    case BFMT_VideoFmt_ePAL_G:
176    case BFMT_VideoFmt_ePAL_H:
177    case BFMT_VideoFmt_ePAL_K:
178    case BFMT_VideoFmt_ePAL_I:
179    case BFMT_VideoFmt_ePAL_N:
180    case BFMT_VideoFmt_ePAL_NC:
181    case BFMT_VideoFmt_eSECAM_L:
182    case BFMT_VideoFmt_eSECAM_B:
183    case BFMT_VideoFmt_eSECAM_G:
184    case BFMT_VideoFmt_eSECAM_D:
185    case BFMT_VideoFmt_eSECAM_K:
186    case BFMT_VideoFmt_eSECAM_H:
187#if (BVDC_P_3DCOMB_TTD_CONFLICT)
188                line_offset = wssVline576i - 1;
189#else
190                line_offset = wssVline576i;
191#endif
192                break;
193
194    case BFMT_VideoFmt_ePAL_M:
195                /* TODO: verify this! */
196#if (BVDC_P_3DCOMB_TTD_CONFLICT)
197                line_offset = wssVline576i - 1;
198#else
199                line_offset = wssVline576i;
200#endif
201                break;
202
203        default:
204                line_offset = 0;
205                if (bActive)
206                        return BERR_TRACE (BVBI_ERR_VFMT_CONFLICT);
207        }
208
209        /* Figure out which decoder core to use */
210        switch (eSource)
211        {
212        case BAVC_SourceId_eVdec0:
213                ulOffset = 0;
214                break;
215#if (BVBI_P_NUM_VDEC > 1)
216        case BAVC_SourceId_eVdec1:
217                ulOffset = BCHP_WSSD_1_Reset - BCHP_WSSD_0_Reset;
218                break;
219#endif
220        default:
221                /* This should never happen!  This parameter was checked by
222                   BVBI_Decode_Create() */
223                BDBG_LEAVE(BVBI_P_WSS_Dec_Program);
224                return BERR_TRACE(BERR_INVALID_PARAMETER);
225                break;
226        }
227
228        BKNI_EnterCriticalSection();
229
230        /* Program the control register */
231        ulControlReg = BREG_Read32 (hReg, BCHP_WSSD_0_Control + ulOffset);
232        ulControlReg &= ~(
233                BCHP_MASK       (WSSD_0_Control, LINE_OFFSET                  ) |
234                BCHP_MASK       (WSSD_0_Control, ENABLE_WSS_DECODE            ) );
235        if (bActive)
236        {
237                /* Will enable decoding */
238                ulControlReg |= (
239                        BCHP_FIELD_DATA (WSSD_0_Control, LINE_OFFSET,      line_offset) |
240                        BCHP_FIELD_ENUM (WSSD_0_Control, ENABLE_WSS_DECODE,    ENABLED) );
241
242                /* Clear the status register */
243                ulStatusReg = 0x0;
244                ulStatusReg |= (
245                        BCHP_FIELD_ENUM (WSSD_0_Status, DATA_OVERRUN, WSSD_CLEAR_STATUS) |
246                        BCHP_FIELD_ENUM (WSSD_0_Status, DATA_LOCK,    WSSD_CLEAR_STATUS) |
247                        BCHP_FIELD_ENUM (WSSD_0_Status, PARITY_ERROR, WSSD_CLEAR_STATUS) |
248                        BCHP_FIELD_ENUM (WSSD_0_Status, DIFFERENCE,   WSSD_CLEAR_STATUS) );
249                BREG_Write32 (hReg, BCHP_WSSD_0_Status + ulOffset, ulStatusReg);
250        }
251        else
252        {
253                /* Will disable decoding */
254                ulControlReg |= (
255                        BCHP_FIELD_ENUM (WSSD_0_Control, ENABLE_WSS_DECODE,   DISABLED) );
256        }
257
258        /* Finish programming the control register */
259        BREG_Write32 (hReg, BCHP_WSSD_0_Control + ulOffset, ulControlReg);
260
261        BKNI_LeaveCriticalSection();
262
263        BDBG_LEAVE(BVBI_P_WSS_Dec_Program);
264        return BERR_SUCCESS;
265}
266
267
268/***************************************************************************
269 *
270 */
271uint32_t BVBI_P_WSS_Decode_Data_isr ( 
272        BREG_Handle hReg, 
273    BAVC_SourceId eSource,
274        BAVC_Polarity polarity,
275        uint16_t *pusData) 
276{
277/*
278        Programming note: the implementation here assumes that the bitfield layout
279        within registers is the same for all WSS decoder cores in the chip. 
280
281        If a chip is built that has multiple WSS decoder cores that are not
282        identical, then this routine will have to be redesigned.
283*/
284        uint32_t H_Status;
285        uint32_t ulStatusReg;
286        uint32_t ulErrInfo = 0;
287        uint16_t usData;
288        uint8_t ucLockFlag;
289        uint8_t ucParityFlag;
290        uint8_t ucOverrunFlag;
291
292        BDBG_ENTER(BVBI_P_WSS_Decode_Data_isr);
293
294        /* Figure out which decoder core to use */
295        switch (eSource)
296        {
297        case BAVC_SourceId_eVdec0:
298                H_Status   = BCHP_WSSD_0_Status;
299                break;
300#if (BVBI_P_NUM_VDEC > 1)
301        case BAVC_SourceId_eVdec1:
302                H_Status   = BCHP_WSSD_1_Status;
303                break;
304#endif
305        default:
306                /* This should never happen!  This parameter was checked by
307                   BVBI_Decode_Create() */
308                BDBG_LEAVE(BVBI_P_WSS_Decode_Data_isr);
309                return (-1);
310                break;
311        }
312
313        /* WSS is for top field only */
314        if (polarity != BAVC_Polarity_eTopField)
315        {
316                return BVBI_LINE_ERROR_PARITY_CONFLICT | BVBI_LINE_ERROR_WSS_NODATA;
317        }
318
319
320        /* Pull status info out of the hardware */
321        ulStatusReg = BREG_Read32 ( hReg, H_Status );
322        ucLockFlag    = 
323                (uint8_t)BCHP_GET_FIELD_DATA (ulStatusReg, WSSD_0_Status, DATA_LOCK   );
324        ucParityFlag  = 
325                (uint8_t)BCHP_GET_FIELD_DATA (ulStatusReg, WSSD_0_Status, PARITY_ERROR);
326        ucOverrunFlag = 
327                (uint8_t)BCHP_GET_FIELD_DATA (ulStatusReg, WSSD_0_Status, DATA_OVERRUN);
328
329        /* Got data? */
330        if (ucLockFlag == BCHP_WSSD_0_Status_DATA_LOCK_DATA_FOUND)
331        {
332                /* read the data */
333                usData = 
334                        (uint16_t)BCHP_GET_FIELD_DATA(ulStatusReg, WSSD_0_Status, WSS_DATA);
335
336                /* provide the decoded data to higher level software */
337                *pusData = usData;
338        }
339        else /* No data */
340        {
341                ulErrInfo |= BVBI_LINE_ERROR_WSS_NODATA;
342        }
343
344        /* Report other error conditions */
345        if (ucParityFlag == BCHP_WSSD_0_Status_PARITY_ERROR_ERROR)
346        {
347                ulErrInfo |= BVBI_LINE_ERROR_WSS_PARITY;
348        }
349        if (ucOverrunFlag == BCHP_WSSD_0_Status_DATA_OVERRUN_ERROR)
350        {
351                ulErrInfo |= BVBI_LINE_ERROR_WSS_OVERRUN;
352        }
353
354        /* Clear status bits in hardware */
355        ulStatusReg = (
356                BCHP_MASK (WSSD_0_Status, PARITY_ERROR) | 
357                BCHP_MASK (WSSD_0_Status, DATA_OVERRUN) |
358                BCHP_MASK (WSSD_0_Status, DATA_LOCK   ) |
359                BCHP_MASK (WSSD_0_Status, DIFFERENCE  )   );
360        BREG_Write32 ( hReg, H_Status, ulStatusReg );
361
362        BDBG_LEAVE(BVBI_P_WSS_Decode_Data_isr);
363        return ulErrInfo;
364}
365
366#endif /** } (BVBI_P_NUM_VDEC >= 1) **/
367
368
369/***************************************************************************
370* Static (private) functions
371***************************************************************************/
Note: See TracBrowser for help on using the repository browser.