xref: /utopia/UTPA2-700.0.x/mxlib/include/drvAVD.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// @file   drvAVD.h
98 /// @brief  AVD Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 /*! \defgroup VDEC VDEC modules
103 
104  *! \defgroup AVD AVD interface (drvAVD.h)
105  *  \ingroup VDEC
106 
107      AVD (Analog Video Decoder) gets CVBS signal status from VDMCU through VD mailbox. VDMCU reports information like H/V sync status, video standard...\n
108      AVD separate CVBS signal into Y/C signal by using 2D/3D COMB filter.
109 
110      <b>Features</b>
111 
112      - detect CVBS signal status and video stadnard
113      - 3D COMB filter
114      - Get signal Noise
115      - CVBS color on/off
116 
117      <b> AVD Block Diagram: </b> \n
118      \image html drvAVD_1.png
119 
120      <b> AVD Code Flow: </b> \n
121      \image html drvAVD_2.png
122 
123  *! \defgroup VDMCU VDMCU
124  *  \ingroup AVD
125 
126  *! \defgroup VD_Info VD_Info
127  *  \ingroup AVD
128 
129  *! \defgroup VD_Task VD_Task
130  *  \ingroup AVD
131 
132  *! \defgroup COMB COMB relative
133  *  \ingroup AVD
134 
135  *! \defgroup AVD_ToBeModified AVD api to be modified
136  *  \ingroup AVD
137 
138  *! \defgroup AVD_ToBeRemove AVD api to be removed
139  *  \ingroup AVD
140 
141  *! \defgroup Get_VD_Info Get_VD_Info
142  *  \ingroup VD_Info
143 
144  *! \defgroup Set_VD_Info Set_VD_Info
145  *  \ingroup VD_Info
146 
147  */
148 
149 
150 #ifndef _DRV_AVD_H_
151 #define _DRV_AVD_H_
152 
153 #include "MsCommon.h"
154 
155 #ifdef __cplusplus
156 extern "C"
157 {
158 #endif
159 
160 
161 //-------------------------------------------------------------------------------------------------
162 //  Driver Capability
163 //-------------------------------------------------------------------------------------------------
164 
165 
166 //-------------------------------------------------------------------------------------------------
167 //  Macro and Define
168 //-------------------------------------------------------------------------------------------------
169 #define MSIF_AVD_LIB_CODE                   {'A','V','D','_'} //Lib code
170 #define MSIF_AVD_LIBVER                        {'1','1'}      //LIB version
171 #define MSIF_AVD_BUILDNUM                 {'0','0' }    //Build Number
172 #define MSIF_AVD_CHANGELIST             {'0','0','6','1','6','9','9','1'} //P4 ChangeList Number
173 
174 #define AVD_VER                 /* Character String for DRV/API version             */  \
175     MSIF_TAG,                           /* 'MSIF'                                           */  \
176     MSIF_CLASS,                         /* '00'                                             */  \
177     MSIF_CUS,                           /* 0x0000                                           */  \
178     MSIF_MOD,                           /* 0x0000                                           */  \
179     MSIF_CHIP,                                                                                  \
180     MSIF_CPU,                                                                                   \
181     MSIF_AVD_LIB_CODE,                  /* IP__                                             */  \
182     MSIF_AVD_LIBVER,                       /* 0.0 ~ Z.Z                                        */  \
183     MSIF_AVD_BUILDNUM,                 /* 00 ~ 99                                          */  \
184     MSIF_AVD_CHANGELIST,             /* CL#                                              */  \
185     MSIF_OS
186 
187 // video decoder status
188 #define VD_SYNC_LOCKED                  ((BIT_(15)))
189 #define VD_HSYNC_LOCKED                 ((BIT_(14)))
190 #define VD_INTERLACED                   ((BIT_(13)))
191 #define VD_VSYNC_50HZ                   ((BIT_(12)))
192 #define VD_RESET_ON                     ((BIT_(11)))
193 #define VD_COLOR_LOCKED                 ((BIT_(10)))
194 #define VD_PAL_SWITCH                   ((BIT_(9)))
195 #define VD_FSC_TYPE                     ((BIT_(7))|(BIT_(6))|(BIT_(5)))
196 #define VD_FSC_3579                     ((BIT_(6)))              // NTSC
197 #define VD_FSC_3575                     ((BIT_(7)))              // PAL(M)
198 #define VD_FSC_3582                     ((BIT_(7))|(BIT_(6)))         // PAL(Nc)
199 #define VD_FSC_4433                     (0)                 // PAL or NTSC443
200 #define VD_FSC_4285                     (BIT_(5))              // SECAM
201 #define VD_VCR_MODE                     (BIT_(4))
202 #define VD_VCR_PAUSE                    (BIT_(3))
203 #define VD_MACROVISION                  (BIT_(2))
204 #define VD_BURST_ON                        (BIT_(1))
205 #define VD_STATUS_RDY                   (BIT_(0))
206 #define VD_MODE_DETECT_MASK             (VD_SYNC_LOCKED|VD_HSYNC_LOCKED|VD_VSYNC_50HZ|VD_FSC_TYPE|VD_RESET_ON) // 20100331 remove BURST check first because too many burst on/off issues
207 
208 // Gain Control (Auto/Fix/Mix) Define
209 #define VD_USE_FIX_GAIN                 0
210 #define VD_USE_AUTO_GAIN                1
211 // Gain Control (Auto/Fix/Mix) Define
212 //#define AVD_AGC_ENABLE                              0x00
213 //#define AVD_AGC_DISABLE                             0x03
214 
215 
216 #define IS_BITS_SET(val, bits)                  (((val)&(bits)) == (bits))
217 #define VD_MODE_STANDARD_MASK                   (VD_VSYNC_50HZ | VD_PAL_SWITCH | VD_FSC_TYPE | VD_STATUS_RDY)
218 
219 #define FSC_AUTO_DET_ENABLE                     0x00
220 #define FSC_AUTO_DET_DISABLE                    0x01
221 
222 #define VD_USE_FB                               0
223 
224 // VD Check Hsync Thresholdffff
225 #define VD_CHK_HSYNC_WAIT                1         // ms
226 #define VD_CHK_HSYNC_CONT                60//40        // timeout=VD_CHK_HSYNC_CONT*VD_CHK_HSYNC_WAIT=20ms
227 #define VD_CHK_HSYNC_OK_THR             2   //7
228 #define VD_CHK_DEBOUNCE_WAIT         20        // ms
229 #define VD_CHK_DEBOUNCE_CONT         40        // timeout=VD_CHK_COLOR_CONT*VD_CHK_COLOR_WAIT=800ms
230 #define VD_CHK_NSPL_WAIT                   1       //ms
231 #define VD_CHK_NSPL_CONT                   500       //timeout=VD_CHK_NSPL_WAIT*VD_CHK_NSPL_CONT=400ms
232 #define VD_CHK_NSPL_OK_THR              20//10
233 #define VD_CHK_VideoSys_CONT                   250       //timeout=VD_CHK_NSPL_WAIT*VD_CHK_NSPL_CONT=400ms
234 
235 #define DSP_VER_OFFSET 255
236 
237 
238 //-------------------------------------------------------------------------------------------------
239 //  Type and Structure
240 //-------------------------------------------------------------------------------------------------
241 typedef enum
242 {
243     AVD_LOAD_CODE_BDMA_FROM_SPI,
244     AVD_LOAD_CODE_BDMA_FROM_DRAM,
245     AVD_LOAD_CODE_BYTE_WRITE,
246 } AVD_LoadCodeType;
247 
248 typedef enum
249 {
250     DEMODE_NORMAL                   = 0,
251     DEMODE_MSTAR_VIF                = 1,
252     DEMODE_MSTAR_VIF_MSB1210        = 2,
253 } AVD_DemodType;
254 
255 typedef enum
256 {
257     E_VIDEO_SYSTEM_ATSC,
258     E_VIDEO_SYSTEM_DVB
259 } AVD_VideoSystem;
260 
261 typedef enum
262 {
263     E_VIDEO_FQ_NOSIGNAL             = 0,     // Video Frequency No signal
264     E_VIDEO_FQ_50Hz                 = 50,    // Video Frequency 50Hz
265     E_VIDEO_FQ_60Hz                 = 60     // Video Frequency 60Hz
266 } AVD_VideoFreq;
267 
268 typedef enum
269 {
270     E_FREERUN_FQ_AUTO               = 0x00,
271     E_FREERUN_FQ_50Hz               = 0x01,
272     E_FREERUN_FQ_60Hz               = 0x02,
273     E_FREERUN_FQ_MAX
274 } AVD_FreeRunFreq;
275 
276 typedef enum
277 {
278     E_VIDEOSTANDARD_PAL_BGHI        = 0x00,        // Video standard PAL BGHI
279     E_VIDEOSTANDARD_NTSC_M          = 0x01,        // Video standard NTSC M
280     E_VIDEOSTANDARD_SECAM           = 0x02,        // Video standard SECAM
281     E_VIDEOSTANDARD_NTSC_44         = 0x03,        // Video standard  NTSC 44
282     E_VIDEOSTANDARD_PAL_M           = 0x04,        // Video standard  PAL M
283     E_VIDEOSTANDARD_PAL_N           = 0x05,        // Video standard  PAL N
284     E_VIDEOSTANDARD_PAL_60          = 0x06,        // Video standard PAL 60
285     E_VIDEOSTANDARD_NOTSTANDARD     = 0x07,        // NOT Video standard
286     E_VIDEOSTANDARD_AUTO            = 0x08,         // Video standard AUTO
287     E_VIDEOSTANDARD_MAX                                // Max Number
288 } AVD_VideoStandardType;
289 
290 typedef enum
291 {
292     E_INPUT_SOURCE_INVALID                  =   0x00,               // Video source Invalid
293     E_INPUT_SOURCE_ATV                      =   0x01,               // Video source ATV
294     E_INPUT_SOURCE_CVBS1                    =   0x02,               // Video source CVBS 1
295     E_INPUT_SOURCE_CVBS2                    =   0x03,               // Video source CVBS 2
296     E_INPUT_SOURCE_CVBS3                    =   0x04,               // Video source CVBS 2
297     E_INPUT_SOURCE_SVIDEO1                  =   0x05,               // Video source SVIDEO 1
298     E_INPUT_SOURCE_SVIDEO2                  =   0x06,               // Video source SVIDEO 2
299     E_INPUT_SOURCE_SCART1                   =   0x07,               // Video source SCART 1
300     E_INPUT_SOURCE_SCART2                   =   0x08,               // Video source SCART 2
301     E_INPUT_SOURCE_YPbPr                    =   0x09,               // Video source YPbPr
302     E_INPUT_SOURCE_THROUGH_3DCOMB           =   0x50,               // Video source through 3D Comb
303     E_INPUT_SOURCE_THROUGH_3DCOMB_ATV       =   (E_INPUT_SOURCE_THROUGH_3DCOMB | E_INPUT_SOURCE_ATV),   // through 3D Comb ATV
304     E_INPUT_SOURCE_THROUGH_3DCOMB_CVBS1     =   (E_INPUT_SOURCE_THROUGH_3DCOMB | E_INPUT_SOURCE_CVBS1),// through 3D Comb CVBS1
305     E_INPUT_SOURCE_THROUGH_3DCOMB_CVBS2     =   (E_INPUT_SOURCE_THROUGH_3DCOMB | E_INPUT_SOURCE_CVBS2),// through 3D Comb CVBS2
306     E_INPUT_SOURCE_THROUGH_3DCOMB_SCART1    =   (E_INPUT_SOURCE_THROUGH_3DCOMB | E_INPUT_SOURCE_SCART1),// through 3D Comb SCART1
307     E_INPUT_SOURCE_THROUGH_3DCOMB_SCART2    =   (E_INPUT_SOURCE_THROUGH_3DCOMB | E_INPUT_SOURCE_SCART2),// through 3D Comb SCART2
308     E_INPUT_SOURCE_MAX                      =   0x60
309 } AVD_InputSourceType;
310 
311 /// Auto AV Source type
312 typedef enum
313 {
314     E_AUTOAV_SOURCE_1   =   E_INPUT_SOURCE_SCART1,       // Auto AV source SCART 1
315     E_AUTOAV_SOURCE_2   =   E_INPUT_SOURCE_SCART2,       // Auto AV source SCART 2
316     E_AUTOAV_SOURCE_ALL =   0xFF                // Auto AV source ALL
317 } AVD_AutoAVSourceType;
318 
319 typedef enum    // 0x2580[5:4]
320 {
321     SCART_FB_NONE = 0x00,
322     SCART_FB0,
323     SCART_FB1,
324     SCART_FB2,
325 } AVD_INPUT_SCART_FB;
326 
327 typedef enum
328 {
329     E_ATV_CLK_ORIGIN_43P2MHZ   =    0x00,
330     E_ATV_CLK_TYPE1_42MHZ         =    0x01,
331     E_ATV_CLK_TYPE2_44P4MHZ     =    0x02,
332 }AVD_ATV_CLK_TYPE;
333 
334 typedef struct
335 {
336     MS_U8 u8DetectWinBeforeLock;
337     MS_U8 u8DetectWinAfterLock;
338     MS_U8 u8CNTRFailBeforeLock;
339     MS_U8 u8CNTRSyncBeforeLock;
340     MS_U8 u8CNTRSyncAfterLock;
341 } VD_HSYNC_SENSITIVITY;
342 
343 typedef enum
344 {
345     AVD_DBGLV_NONE,    // disable all the debug message
346     AVD_DBGLV_INFO,    // information
347     AVD_DBGLV_NOTICE,  // normal but significant condition
348     AVD_DBGLV_WARNING, // warning conditions
349     AVD_DBGLV_ERR,     // error conditions
350     AVD_DBGLV_CRIT,    // critical conditions
351     AVD_DBGLV_ALERT,   // action must be taken immediately
352     AVD_DBGLV_EMERG,   // system is unusable
353     AVD_DBGLV_DEBUG,   // debug-level messages
354 } AVD_DbgLv;
355 
356 #define AVD_PATCH_NONE 0
357 #define AVD_PATCH_NTSC_50 BIT_(0)
358 #define AVD_PATCH_FINE_TUNE_FH_DOT BIT_(1)
359 #define AVD_PATCH_FINE_TUNE_COMB_F2 BIT_(2)
360 #define AVD_PATCH_FINE_TUNE_3D_COMB BIT_(3)
361 #define AVD_PATCH_FINE_TUNE_FSC_SHIFT BIT_(4)
362 #define AVD_PATCH_NON_STANDARD_VTOTAL BIT_(5)
363 #define AVD_PATCH_FINE_TUNE_STILL_IMAGE BIT_(6)
364 
365 #define AVD_PATCH_HTOTAL_1135_MUL_15 0
366 #define AVD_PATCH_HTOTAL_1135 BIT_(8)
367 #define AVD_PATCH_HTOTAL_DYNAMIC BIT_(9)
368 #define AVD_PATCH_HTOTAL_USER (BIT_(9)|BIT_(8))
369 #define AVD_PATCH_HTOTAL_MASK (BIT_(9)|BIT_(8))
370 #define AVD_PATCH_SCART_SVIDEO (BIT_(10))
371 #define AVD_PATCH_CVBS_NEGATIVESIG (BIT_(11))
372 
373 #define AVD_PATCH_DISABLE_PWS BIT_(24)    // used to store ENABLE_PWS
374 #define AVD_PATCH_DSPCODE_0x24_ATSC BIT_(25) //L_ATSC
375 #define AVD_PATCH_DSPCODE_0x25 BIT_(26) //L_MSTAR
376 #define AVD_PATCH_DSPCODE_0x21_ATSC BIT_(27) //S_ATSC
377 #define AVD_PATCH_DSPCODE_0x21 BIT_(28) //S
378 
379 /// For vd init
380 typedef struct __attribute__((__packed__))
381 {
382         // register init
383     MS_U8 *u8VdDecInitializeExt; // TODO use system variable type
384     #if !defined (__aarch64__)
385     MS_U32 u32AlignDummy;
386     #endif
387 
388     MS_U32 u32XTAL_Clock;
389     AVD_LoadCodeType eLoadCodeType;
390     MS_U32 u32VD_DSP_Code_Address;
391     MS_U8 *pu8VD_DSP_Code_Address;
392     #if !defined (__aarch64__)
393     MS_U32 u32AlignDummy1;
394     #endif
395 
396     MS_U32 u32VD_DSP_Code_Len;
397     // VIF related
398     AVD_DemodType eDemodType;
399 
400     // afec related
401     MS_U16 u16VDDSPBinID;
402     MS_U8 bRFGainSel;
403     MS_U8 bAVGainSel;
404     MS_U8 u8RFGain;
405     MS_U8 u8AVGain;
406     MS_U32  u32VDPatchFlag;
407     MS_U8 u8ColorKillHighBound;
408     MS_U8 u8ColorKillLowBound;
409     MS_U8 u8SwingThreshold;
410     VD_HSYNC_SENSITIVITY eVDHsyncSensitivityNormal;
411     VD_HSYNC_SENSITIVITY eVDHsyncSensitivityTuning;
412 
413     // comb related
414     MS_PHY u32COMB_3D_ADR;
415     MS_U32 u32COMB_3D_LEN;
416 
417 } VD_INITDATA;
418 
419 typedef enum
420 {
421     E_AVD_FAIL=0,
422     E_AVD_OK=1
423 } AVD_Result;
424 
425 
426 typedef struct
427 {
428     AVD_InputSourceType eVDInputSource;
429     AVD_VideoStandardType eVideoSystem;
430     AVD_VideoStandardType eLastStandard;
431     MS_U8  u8AutoDetMode;
432     MS_U16 u16CurVDStatus;
433     MS_U8 u8AutoTuningIsProgress;
434 } AVD_Info;
435 
436 typedef struct
437 {
438     MS_U8 u8Threshold1;
439     MS_U8 u8Threshold2;
440     MS_U8 u8Threshold3;
441     MS_U8 u8Threshold4;
442 
443     MS_U8 u8Str1_COMB37;
444     MS_U8 u8Str1_COMB38;
445     MS_U8 u8Str1_COMB7C;
446     MS_U8 u8Str1_COMBED;
447 
448     MS_U8 u8Str2_COMB37;
449     MS_U8 u8Str2_COMB38;
450     MS_U8 u8Str2_COMB7C;
451     MS_U8 u8Str2_COMBED;
452 
453     MS_U8 u8Str3_COMB37;
454     MS_U8 u8Str3_COMB38;
455     MS_U8 u8Str3_COMB7C;
456     MS_U8 u8Str3_COMBED;
457 
458     MS_BOOL bMessageOn;
459 } AVD_Still_Image_Param;
460 
461 typedef enum
462 {
463     E_FACTORY_PARA_AFEC_D4,
464     E_FACTORY_PARA_AFEC_D8,
465     E_FACTORY_PARA_AFEC_D5_BIT2,
466     E_FACTORY_PARA_AFEC_D9_BIT0,
467     E_FACTORY_PARA_AFEC_A0,
468     E_FACTORY_PARA_AFEC_A1,
469     E_FACTORY_PARA_AFEC_66_BIT67,
470     E_FACTORY_PARA_AFEC_6E_BIT7654,
471     E_FACTORY_PARA_AFEC_6E_BIT3210,
472     E_FACTORY_PARA_AFEC_43,
473     E_FACTORY_PARA_AFEC_44,
474     E_FACTORY_PARA_AFEC_CB,
475     E_FACTORY_PARA_AFEC_CF_BIT2,
476     E_FACTORY_PARA_AFEC_D5_BIT3,
477     E_FACTORY_PARA_AFEC_D7_HIGH,
478     E_FACTORY_PARA_AFEC_D7_LOW,
479     E_FACTORY_PARA_AFEC_MAX
480 }AVD_Factory_Para;
481 
482 //typedef void(*P_AVD_ISR_Proc)(MS_U8 u8AVDID);
483 
484 
485 //-------------------------------------------------------------------------------------------------
486 //  Function and Variable
487 //-------------------------------------------------------------------------------------------------
488 //-------------------------------------------------------------------------------------------------
489 /// Set VDMCU freeze
490 /// @ingroup VDMCU
491 /// @param  bEnable   \b IN: MCU freeze enable
492 /// @return NA
493 //-------------------------------------------------------------------------------------------------
494 extern void MDrv_AVD_MCUFreeze(MS_BOOL bEnable);
495 
496 //-------------------------------------------------------------------------------------------------
497 /// Turn OFF AVD
498 /// @ingroup VD_Task
499 /// @return NA
500 //-------------------------------------------------------------------------------------------------
501 extern void MDrv_AVD_Exit(void);
502 ////////////////////////////////////////////////////////////////////////////////
503 /// To initialize Video Decoder.\n
504 /// When turning power on or waking up from power saving mode,\n
505 /// this function should be called before using all funcions\n
506 /// MS_U32 u32XTAL_Clock        : external crystal clock.\n
507 /// MS_U32 u32VD_DSP_Code_Address        : absolute flash address of VDDSP bin file\n
508 /// MS_U8 *pu8VD_DSP_Code_Address        : address of VDDSP code\n
509 /// MS_U32 u32VD_DSP_Code_Len        : VDDSP code length.\n
510 /// AVD_DemodType eDemodType        : analog Demod. type.\n
511 /// MS_U16 u16VDDSPBinID     : binary ID of VD DSP code.\n
512 /// MS_U8 bRFGainSel        : RF auto/fix gain selection\n
513 /// MS_U8 bAVGainSel        : AV auto/fix gain selection\n
514 /// MS_U8 u8RFGain        : when RF is fix gain, u8RFGain will set gain value\n
515 /// MS_U8 u8AVGain        : when AV is fix gain, u8AVGain will set gain value\n
516 /// MS_U32 u32VDPatchFlag        : set AVD control flag\n
517 /// MS_U8 u8ColorKillHighBound        : when color burst is detected and color burst S/N is lower than u8ColorKillLowBound, turn off color.\n
518 /// MS_U8 u8ColorKillLowBound        : when color burst is not detected and color burst S/N is higher than u8ColorKillHighBound, turn on color.\n
519 ///                                                                          u8ColorKillHighBound should be larger than u8ColorKillLowBound for hysteresis\n
520 /// MS_U8 u8SwingThreshold        : when signal swing(top-bottom) is smaller than u8SwingThreshold*16mV, report no sync\n
521 ///                                                                      this threshold is used to filter out false channel, but the value should be set to 0 at channel scan to prevent channel lost\n
522 /// VD_HSYNC_SENSITIVITY eVDHsyncSensitivityNormal        : hsync sensitivity at normal condition\n
523 /// VD_HSYNC_SENSITIVITY eVDHsyncSensitivityTuning        : hsync sensitivity at channel scan\n
524 /// MS_U32 u32COMB_3D_ADR    : 3D COMB protected memory buffer start address.\n
525 /// MS_U32 u32COMB_3D_LEN    : 3D COMB protected memory length.\n
526 /// MS_U8 *u8VdDecInitializeExt    : additional initial table for different project requirements\n
527 ///
528 /// MS_U32 u32InitDataLen : used to check data size correct or not
529 ////////////////////////////////////////////////////////////////////////////////
530 //-------------------------------------------------------------------------------------------------
531 /// Initialize AVD
532 /// @ingroup VD_Task
533 /// @param  pVD_InitData   \b IN: AVD initialize parameters
534 /// @param  u32InitDataLen   \b IN: InitData length
535 /// @return NA
536 //-------------------------------------------------------------------------------------------------
537 extern AVD_Result MDrv_AVD_Init(VD_INITDATA *pVD_InitData, MS_U32 u32InitDataLen);
538 
539 //-------------------------------------------------------------------------------------------------
540 /// Reset VDMCU
541 /// @ingroup VDMCU
542 /// @return TRUE : succeed
543 /// @return FALSE : fail
544 //-------------------------------------------------------------------------------------------------
545 extern MS_BOOL MDrv_AVD_McuReset(void);
546 ////////////////////////////////////////////////////////////////////////////////
547 /// Get video decoder status
548 /// VD_SYNC_LOCKED                  ((BIT(15)))\n
549 /// VD_HSYNC_LOCKED                 ((BIT(14)))\n
550 /// VD_INTERLACED                   ((BIT(13)))\n
551 /// VD_VSYNC_50HZ                   ((BIT(12)))\n
552 /// VD_RESET_ON                     ((BIT(11)))\n
553 /// VD_COLOR_LOCKED                 ((BIT(10)))\n
554 /// VD_PAL_SWITCH                   ((BIT(9)))\n
555 /// VD_FSC_TYPE                     ((BIT(7))|(BIT(6))|(BIT(5)))\n
556 /// VD_FSC_3579                     ((BIT(6)))              // NTSC\n
557 /// VD_FSC_3575                     ((BIT(7)))              // PAL(M)\n
558 /// VD_FSC_3582                     ((BIT(7))|(BIT(6)))         // PAL(Nc)\n
559 /// VD_FSC_4433                     (0)                 // PAL or NTSC443\n
560 /// VD_FSC_4285                     (BIT(5))              // SECAM\n
561 /// VD_VCR_MODE                     (BIT(4))\n
562 /// VD_VCR_PAUSE                    (BIT(3))\n
563 /// VD_MACROVISION                  (BIT(2))\n
564 /// VD_BURST_ON                        (BIT(1))\n
565 /// VD_STATUS_RDY                   (BIT(0))\n
566 ////////////////////////////////////////////////////////////////////////////////
567 //-------------------------------------------------------------------------------------------------
568 /// Get VD Status
569 /// @ingroup Get_VD_Info
570 /// @return U16 parameters : AVD U16 Status
571 //-------------------------------------------------------------------------------------------------
572 extern MS_U16 MDrv_AVD_GetStatus(void);
573 //-------------------------------------------------------------------------------------------------
574 /// Get VD Status
575 /// @ingroup AVD_ToBeRemove
576 /// @return U16 parameters : AVD U16 Status
577 //-------------------------------------------------------------------------------------------------
578 extern AVD_Result MDrv_AVD_GetLibVer(const MSIF_Version **ppVersion);
579 //-------------------------------------------------------------------------------------------------
580 /// Set AVD debug parameters
581 /// @ingroup Set_VD_Info
582 /// @param  u8DbgLevel   \b IN: debug parameters
583 /// @return TRUE : succeed
584 /// @return FALSE : fail
585 //-------------------------------------------------------------------------------------------------
586 extern MS_BOOL MDrv_AVD_SetDbgLevel(AVD_DbgLv u8DbgLevel);
587 
588 //-------------------------------------------------------------------------------------------------
589 /// Get AVD Info(standard, source type, VD status)
590 /// @ingroup Get_VD_Info
591 /// @return : AVD Info struct
592 //-------------------------------------------------------------------------------------------------
593 extern const AVD_Info* MDrv_AVD_GetInfo(void);
594 
595 //-------------------------------------------------------------------------------------------------
596 /// Get Hsync lock information
597 /// @ingroup Get_VD_Info
598 /// @return TRUE: Hsync lock
599 /// @return FALSE: Hsync unlock
600 //-------------------------------------------------------------------------------------------------
601 extern MS_BOOL MDrv_AVD_IsSyncLocked(void);
602 #if 0 // use MDrv_AVD_IsHsyncLocked
603 extern MS_BOOL MDrv_VD_IsSyncDetected(void);
604 #endif
605 //-------------------------------------------------------------------------------------------------
606 /// Get Hsync lock information while ATV auto-tuning
607 /// @ingroup Get_VD_Info
608 /// @param  u8HtotalTolerance   \b IN: Htotal tolerance for Hsync lock detection
609 /// @return TRUE : Find legal channel while auto-tuning
610 /// @return FALSE : No legal channel while auto-tuning
611 //-------------------------------------------------------------------------------------------------
612 extern MS_U16 MDrv_AVD_Scan_HsyncCheck(MS_U8 u8HtotalTolerance); //TODO should add delay between register read
613 
614 //-------------------------------------------------------------------------------------------------
615 /// Get VD Status
616 /// @ingroup AVD_ToBeRemove
617 /// @return U16 parameters : AVD U16 Status
618 //-------------------------------------------------------------------------------------------------
619 extern MS_BOOL MDrv_AVD_IsSignalInterlaced(void);
620 
621 //-------------------------------------------------------------------------------------------------
622 /// Get VD Status
623 /// @ingroup AVD_ToBeRemove
624 /// @return U16 parameters : AVD U16 Status
625 //-------------------------------------------------------------------------------------------------
626 extern MS_BOOL MDrv_AVD_IsColorOn(void);
627 #if 0 // BY 20090403 unused function
628 MS_BOOL MDrv_VD_IsStandardValid(void);
629 #endif
630 //-------------------------------------------------------------------------------------------------
631 /// Get Vsync freq information
632 /// @ingroup Get_VD_Info
633 /// @return Vsync frequency
634 //-------------------------------------------------------------------------------------------------
635 extern AVD_VideoFreq MDrv_AVD_GetVerticalFreq(void);
636 
637 //-------------------------------------------------------------------------------------------------
638 /// Get V total
639 /// @ingroup Get_VD_Info
640 /// @return U16 Vtotal
641 //-------------------------------------------------------------------------------------------------
642 extern MS_U16 MDrv_AVD_GetVTotal(void);
643 
644 //-------------------------------------------------------------------------------------------------
645 /// Get Noise magnitude
646 /// @ingroup Get_VD_Info
647 /// @return U8 Noise
648 //-------------------------------------------------------------------------------------------------
649 extern MS_U8 MDrv_AVD_GetNoiseMag(void);
650 
651 //-------------------------------------------------------------------------------------------------
652 /// Set Input source and MUX
653 /// @ingroup VD_Task
654 /// @param  eSource   \b IN: Input source type
655 /// @param  u8ScartFB   \b IN: Fast blanking setting
656 /// @return TRUE: succeed
657 /// @return FALSE: fail
658 //-------------------------------------------------------------------------------------------------
659 extern MS_BOOL MDrv_AVD_SetInput(AVD_InputSourceType eSource, MS_U8 u8ScartFB);
660 
661 //-------------------------------------------------------------------------------------------------
662 /// Set Video standard
663 /// @ingroup Set_VD_Info
664 /// @param  eStandard   \b IN: Input video standard type
665 /// @param  bIsInAutoTuning   \b IN: Auto-tuning flag
666 /// @return TRUE: succeed
667 /// @return FALSE: fail
668 //-------------------------------------------------------------------------------------------------
669 extern MS_BOOL MDrv_AVD_SetVideoStandard(AVD_VideoStandardType eStandard, MS_BOOL bIsInAutoTuning);
670 
671 //-------------------------------------------------------------------------------------------------
672 /// Set auto standard detection from force standard
673 /// @ingroup Set_VD_Info
674 /// @return NA
675 //-------------------------------------------------------------------------------------------------
676 extern void MDrv_AVD_StartAutoStandardDetection(void);
677 #if 0 // BY 20090403 unused function
678 extern void MDrv_VD_StopAutoStandardDetection(void);
679 #endif
680 //-------------------------------------------------------------------------------------------------
681 /// Force video standard and disable auto standard detection
682 /// @ingroup Set_VD_Info
683 /// @param  eVideoStandardType   \b IN: Force video standard type
684 /// @return TRUE: succeed
685 /// @return FALSE: fail
686 //-------------------------------------------------------------------------------------------------
687 extern MS_BOOL MDrv_AVD_ForceVideoStandard(AVD_VideoStandardType eVideoStandardType);
688 #if 0 // BY 20090403 use MDrv_VD_StartAutoStandardDetection, not supported
689 extern void MDrv_VD_DisableForceMode(void);
690 #endif
691 #if 0 // BY 20090403 use MDrv_VD_GetStandardDetection, not supported
692 extern AVD_VIDEOSTANDARD_TYPE MDrv_VD_GetResultOfAutoStandardDetection(void);
693 #endif
694 //-------------------------------------------------------------------------------------------------
695 /// Get video standard
696 /// @ingroup Get_VD_Info
697 /// @param  u16LatchStatus   \b IN: AVD status
698 /// @return AVD video standard
699 //-------------------------------------------------------------------------------------------------
700 extern AVD_VideoStandardType MDrv_AVD_GetStandardDetection(MS_U16 *u16LatchStatus);
701 #if 0 // BY 20090408 unused function
702 extern AVD_VIDEOSTANDARD_TYPE MDrv_VD_DetectStandardAutomatically(void);
703 #endif
704 //-------------------------------------------------------------------------------------------------
705 /// Get VD Status
706 /// @ingroup AVD_ToBeRemove
707 /// @return U16 parameters : AVD U16 Status
708 //-------------------------------------------------------------------------------------------------
709 extern AVD_VideoStandardType MDrv_AVD_GetLastDetectedStandard(void);
710 #if 0 // BY 20090403 unused function
711 extern void MDrv_VD_EnableAutoGainControl(MS_BOOL bEnable);
712 #endif
713 //-------------------------------------------------------------------------------------------------
714 /// Set 3D COMB para
715 /// @ingroup COMB relative
716 /// @param  bEnable   \b IN: set 3D COMB enable
717 //-------------------------------------------------------------------------------------------------
718 extern void MDrv_AVD_Set3dComb(MS_BOOL bEnable);
719 
720 //-------------------------------------------------------------------------------------------------
721 /// Set 3D COMB speed up settings
722 /// @ingroup COMB relative
723 //-------------------------------------------------------------------------------------------------
724 extern void MDrv_AVD_3DCombSpeedup(void);
725 
726 //-------------------------------------------------------------------------------------------------
727 /// Get VD Status
728 /// @ingroup AVD_ToBeRemove
729 /// @return U16 parameters : AVD U16 Status
730 //-------------------------------------------------------------------------------------------------
731 extern void MDrv_AVD_SetFreerunPLL(AVD_VideoFreq eVideoFreq);// 060508 chris
732 
733 //-------------------------------------------------------------------------------------------------
734 /// Set free run vertical lines
735 /// @ingroup COMB relative
736 /// @param  eFreerunfreq   \b IN: input freen run frequency
737 //-------------------------------------------------------------------------------------------------
738 extern void MDrv_AVD_SetFreerunFreq(AVD_FreeRunFreq eFreerunfreq);
739 
740 //-------------------------------------------------------------------------------------------------
741 /// Set register from DSP and monitor register settings
742 /// @ingroup VD_Task
743 //-------------------------------------------------------------------------------------------------
744 extern void MDrv_AVD_SetRegFromDSP(void);
745 
746 //-------------------------------------------------------------------------------------------------
747 /// Set AVD patch flag
748 /// @ingroup Set_VD_Info
749 /// @param  u32VDPatchFlag   \b IN: AVD patch flag
750 //-------------------------------------------------------------------------------------------------
751 extern void MDrv_AVD_SetFlag(MS_U32  u32VDPatchFlag);
752 
753 //-------------------------------------------------------------------------------------------------
754 /// Get AVD patch flag
755 /// @ingroup Get_VD_Info
756 /// @return AVD patch flag
757 //-------------------------------------------------------------------------------------------------
758 extern MS_U32 MDrv_AVD_GetFlag(void);
759 
760 //-------------------------------------------------------------------------------------------------
761 /// Set output sampling htotal by user
762 /// @ingroup Set_VD_Info
763 /// @param  u16Htt   \b IN: output htotal
764 //-------------------------------------------------------------------------------------------------
765 extern void MDrv_AVD_Set_Htt_UserMD(MS_U16 u16Htt);
766 
767 //-------------------------------------------------------------------------------------------------
768 /// Reset DSP AGC duriing ATV channel change
769 /// @ingroup Set_VD_Info
770 //-------------------------------------------------------------------------------------------------
771 extern void MDrv_AVD_SetChannelChange(void);
772 
773 //-------------------------------------------------------------------------------------------------
774 /// Set Hsync lock sensitivity for auto-tuning/normal
775 /// @ingroup Set_VD_Info
776 /// @param  bEnable   \b IN: auto-tuning:1  normal:0   Hsync sensitivity settings
777 //-------------------------------------------------------------------------------------------------
778 extern void MDrv_AVD_SetHsyncDetectionForTuning(MS_BOOL bEnable);
779 
780 //-------------------------------------------------------------------------------------------------
781 /// Set AVD register
782 /// @ingroup Set_VD_Info
783 /// @param  u16Addr   \b IN: register address
784 /// @param  u8Value   \b IN: register value
785 //-------------------------------------------------------------------------------------------------
786 extern void MDrv_AVD_SetRegValue(MS_U16 u16Addr,MS_U8 u8Value);
787 
788 //-------------------------------------------------------------------------------------------------
789 /// Get AVD register value
790 /// @ingroup Get_VD_Info
791 /// @param  u16Addr   \b IN: register address
792 /// @return register value
793 //-------------------------------------------------------------------------------------------------
794 extern MS_U8 MDrv_AVD_GetRegValue(MS_U16 u16Addr);
795 
796 //-------------------------------------------------------------------------------------------------
797 /// Load VD DSP code
798 /// @ingroup AVD_ToBeRemove
799 //-------------------------------------------------------------------------------------------------
800 extern void MDrv_AVD_LoadDSP(MS_U8 *pu8VD_DSP, MS_U32 len);
801 
802 //-------------------------------------------------------------------------------------------------
803 /// Set fixed gain enable
804 /// @ingroup AVD_ToBeRemove
805 //-------------------------------------------------------------------------------------------------
806 extern void MDrv_AVD_SetPQFineTune(void);
807 
808 //-------------------------------------------------------------------------------------------------
809 /// Set 3D COMB speed para
810 /// @ingroup COMB relative
811 /// @param  u8COMB57   \b IN: set BK_COMB_57 value
812 /// @param  u8COMB58   \b IN: set BK_COMB_58 value
813 //-------------------------------------------------------------------------------------------------
814 extern void MDrv_AVD_Set3dCombSpeed(MS_U8 u8COMB57, MS_U8 u8COMB58);
815 
816 //-------------------------------------------------------------------------------------------------
817 /// Get capture window
818 /// @ingroup AVD_ToBeRemove
819 //-------------------------------------------------------------------------------------------------
820 extern void MDrv_AVD_GetCaptureWindow(void *stCapWin, AVD_VideoStandardType eVideoStandardType);
821 
822 //-------------------------------------------------------------------------------------------------
823 /// Read value from VD mailbox
824 /// @ingroup AVD_ToBeRemove
825 //-------------------------------------------------------------------------------------------------
826 extern MS_U8 MDrv_AVD_MBX_ReadByteByVDMbox(MS_U8 u8Addr);
827 
828 //-------------------------------------------------------------------------------------------------
829 /// Get Hsync edge
830 /// @ingroup Get_VD_Info
831 /// @return Hsync edge
832 //-------------------------------------------------------------------------------------------------
833 extern MS_U8 MDrv_AVD_GetHsyncEdge(void);
834 
835 //-------------------------------------------------------------------------------------------------
836 /// Set 3D COMB stillimage parameters
837 /// @ingroup COMB relative
838 /// @param  param   \b IN: Stillimage parameters
839 //-------------------------------------------------------------------------------------------------
840 extern void MDrv_AVD_SetStillImageParam(AVD_Still_Image_Param param);
841 
842 //-------------------------------------------------------------------------------------------------
843 /// Set BK_AFEC_D4 value
844 /// @ingroup AVD_ToBeRemove
845 //-------------------------------------------------------------------------------------------------
846 extern void MDrv_AVD_SetAFECD4Factory(MS_U8 u8Value);
847 
848 //-------------------------------------------------------------------------------------------------
849 /// Set 2D/3D COMB patch
850 /// @ingroup AVD_ToBeRemove
851 //-------------------------------------------------------------------------------------------------
852 extern void MDrv_AVD_Set2D3DPatchOnOff(MS_BOOL bEnable);
853 
854 //-------------------------------------------------------------------------------------------------
855 /// Set back porch position
856 /// @ingroup AVD_ToBeRemove
857 //-------------------------------------------------------------------------------------------------
858 extern void MDrv_AVD_BackPorchWindowPositon(MS_BOOL bEnable , MS_U8 u8Value);
859 
860 //-------------------------------------------------------------------------------------------------
861 /// Set AVD factory parameters
862 /// @ingroup Set_VD_Info
863 /// @param  FactoryPara   \b IN: factory parameters/register
864 /// @param  u8Value   \b IN: setting value
865 //-------------------------------------------------------------------------------------------------
866 extern void MDrv_AVD_SetFactoryPara(AVD_Factory_Para FactoryPara,MS_U8 u8Value);
867 
868 //-------------------------------------------------------------------------------------------------
869 /// Set fixed gain
870 /// @ingroup AVD_ToBeRemove
871 //-------------------------------------------------------------------------------------------------
872 extern MS_U8 MDrv_AVD_SetAutoFineGainToFixed(void);
873 
874 //-------------------------------------------------------------------------------------------------
875 /// Get DSP fine gain value
876 /// @ingroup Get_VD_Info
877 /// @return fine gain
878 //-------------------------------------------------------------------------------------------------
879 extern MS_U8 MDrv_AVD_GetDSPFineGain(void);
880 
881 //-------------------------------------------------------------------------------------------------
882 /// Get DSP version
883 /// @ingroup Get_VD_Info
884 /// @return DSP version
885 //-------------------------------------------------------------------------------------------------
886 extern MS_U16 MDrv_AVD_GetDSPVersion(void);
887 
888 //-------------------------------------------------------------------------------------------------
889 /// Shift clock function
890 /// @ingroup AVD_ToBeRemove
891 //-------------------------------------------------------------------------------------------------
892 extern void MDrv_AVD_ShiftClk(AVD_ATV_CLK_TYPE eShiftMode);
893 
894 //-------------------------------------------------------------------------------------------------
895 /// Set shift clock parameters
896 /// @ingroup Set_VD_Info
897 /// @param  bEnable   \b IN: shift clock enable
898 /// @param  eShiftMode   \b IN: shift clock mode
899 //-------------------------------------------------------------------------------------------------
900 extern void MDrv_AVD_SetShiftClk(MS_BOOL bEnable,AVD_ATV_CLK_TYPE eShiftMode);
901 
902 //-------------------------------------------------------------------------------------------------
903 /// shift clock monitor function
904 /// @ingroup VD_Task
905 //-------------------------------------------------------------------------------------------------
906 extern void MDrv_AVD_ShifClk_Monitor(void);
907 
908 //-------------------------------------------------------------------------------------------------
909 /// SCART monitor function
910 /// @ingroup VD_Task
911 //-------------------------------------------------------------------------------------------------
912 extern void MDrv_AVD_SCART_Monitor(void);
913 
914 //-------------------------------------------------------------------------------------------------
915 /// Set AVD STR(resume/suspend) state
916 /// @ingroup Set_VD_Info
917 /// @param  u16PowerState   \b IN: STR state
918 /// @return status
919 //-------------------------------------------------------------------------------------------------
920 extern MS_U32 MDrv_AVD_SetPowerState(EN_POWER_MODE u16PowerState);
921 
922 //-------------------------------------------------------------------------------------------------
923 /// Get MacroVision detection
924 /// @ingroup Get_VD_Info
925 /// @return Macro Vision detection status
926 //-------------------------------------------------------------------------------------------------
927 extern MS_BOOL MDrv_AVD_GetMacroVisionDetect(void);
928 
929 //-------------------------------------------------------------------------------------------------
930 /// Get VBI CGMS detection
931 /// @ingroup Get_VD_Info
932 /// @return CGMS detection status
933 //-------------------------------------------------------------------------------------------------
934 extern MS_BOOL MDrv_AVD_GetCGMSDetect(void);
935 
936 //-------------------------------------------------------------------------------------------------
937 /// Set Burst Window detection
938 /// @ingroup Get_VD_Info
939 //-------------------------------------------------------------------------------------------------
940 extern void SYMBOL_WEAK MDrv_AVD_SetBurstWinStart(MS_U8 u8BusrtStartPosition);
941 
942 //-------------------------------------------------------------------------------------------------
943 /// Check VD lock audio carrier
944 /// @ingroup Get_VD_Info
945 /// @return TRUE: lock in audio carrier
946 /// @return FALSE:unlock in audio carrier
947 //-------------------------------------------------------------------------------------------------
948 extern MS_BOOL SYMBOL_WEAK MDrv_AVD_IsLockAudioCarrier(void);
949 
950 #ifdef __cplusplus
951 }
952 #endif
953 
954 
955 #endif // _DRV_AVD_H_
956