xref: /utopia/UTPA2-700.0.x/modules/ve/hal/curry/ve/include/mhal_tvencoder.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) 2006-2008 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 #ifndef _MHALTVENCODER_H
95 #define _MHALTVENCODER_H
96 
97 #ifdef __cplusplus
98 extern "C"
99 {
100 #endif
101 
102 #include "MsCommon.h"
103 
104 //-------------------------------------------------------------------------------------------------
105 //  Macro and Define
106 //-------------------------------------------------------------------------------------------------
107 //Video Encoder Capability
108 #define VE_SUPPORTED            TRUE
109 #define ENABLE_VE_SUBTITLE      TRUE
110 //Feature for: ve support isr from TVS(VE Source), and HW will report current VE Write frame index
111 #define VE_TVS_ISR_SUPPORT      FALSE
112 
113 //Feature: predownscaling before TVS
114 #define VE_PRESCALE_SUPPORT     FALSE
115 
116 #define ENABLE_VE_FIELD_INV       1
117 
118 #define VE_DE_HEND_MASK 0x1FFF //0x3B13
119 #define VE_DE_VEND_MASK 0xFFF  //0x3B15
120 
121 #define VE_MIU_WIDTH 32 //32bytes,256bits
122 
123 #define BYTE_PER_WORD           8
124 
125 //Video Encoder Capability
126 #define VE_SUPPORT_SOURCE_SCALER_OP 0
127 
128 //VE customized table max size
129 #define VE_CUSTBL_MAX_SIZE 64 //4bytes * 16sets (include end of table)
130 
131 //#define REG_CKG_VE_IN           0x1E38
132 #define CKG_VE_IN_GATED         BIT(0)
133 #define CKG_VE_IN_INVERT        BIT(1)
134 #define CKG_VE_IN_MASK          (BIT(5) | BIT(4) | BIT(3) | BIT(2))
135 #define CKG_VE_IN_ODCLK         (0 << 2)
136 #define CKG_VE_IN_EDCLK         (2 << 2)
137 #define CKG_VE_IN_FCLK          (4 << 2)
138 
139 #define VE_NTSC_FRAME_SIZE  ((MS_U32)(720ul * 480ul)>>2) // 720*480*16bits/64bits
140 #define VE_PAL_FRAME_SIZE   ((MS_U32)(720ul * 576ul)>>2) // 720*576*16bits/64bits
141 
142  //VE out
143 #define VE_OUT_CVBS_YCC         0x00
144 #define VE_OUT_CVBS_YCbCr       0x01
145 #define VE_OUT_CVBS_RGB         0x02
146 #define VE_OUT_NONE             0xFF
147 
148 #define VE_V_SCALE_DOWN_RATIO(IN, OUT)  (((MS_U32)(OUT) * 2048ul / (MS_U32)(IN))+1)
149 #define VE_H_SCALE_DOWN_RATIO(IN, OUT)  ((MS_U32)(OUT) * 2048ul / (MS_U32)(IN))
150 #define VE_V_SCALE_UP_RATIO(IN, OUT)  ((MS_U32)(IN - 1) * 0x10000ul / (MS_U32)(OUT - 1))
151 #define VE_H_SCALE_UP_RATIO(IN, OUT)  ((MS_U32)(IN - 1) * 0x10000ul/ (MS_U32)(OUT - 1))
152 
153 typedef enum
154 {
155     EN_VE_DEMODE         = 0x01,
156     EN_VE_CCIR656_IN     = 0x02,
157     EN_VE_RGB_IN         = 0x04,
158     EN_VE_INVERSE_HSYNC  = 0x08,
159 }EN_VE_DISPLAY_STATUS;
160 
161 //MV Type
162 typedef enum
163 {
164     MS_VE_MV_NTSC_START = 0,
165     MS_VE_MV_NTSC_TYPE1 = MS_VE_MV_NTSC_START,
166     MS_VE_MV_NTSC_TYPE2,
167     MS_VE_MV_NTSC_TYPE3,
168     MS_VE_MV_NTSC_TEST_N01,
169     MS_VE_MV_NTSC_TEST_N02,
170     MS_VE_MV_NTSC_TYPE2_TTX,
171     MS_VE_MV_NTSC_TEST_N01_TTX,
172     MS_VE_MV_PAL_START = 0x10,
173     MS_VE_MV_PAL_TYPE1 = MS_VE_MV_PAL_START,
174     MS_VE_MV_PAL_TYPE2,
175     MS_VE_MV_PAL_TYPE3,
176     MS_VE_MV_PAL_TEST_P01,
177     MS_VE_MV_PAL_TEST_P02,
178     MS_VE_MV_PAL_TYPE2_TTX,
179     MS_VE_MV_PAL_TEST_P01_TTX,
180 } MS_VE_MV_TYPE;
181 
182 /*
183  * This Enum type was defined base on DCS for composite (CVBS) and component outputs
184  */
185 typedef enum
186 {
187     MS_VE_DCS_TYPE_MIN = 0,
188 
189     MS_VE_DCS_CVBS_MIN = MS_VE_DCS_TYPE_MIN,
190     MS_VE_DCS_CVBS_NTSC = MS_VE_DCS_CVBS_MIN,
191     MS_VE_DCS_CVBS_PAL,
192     MS_VE_DCS_CVBS_MAX = MS_VE_DCS_CVBS_PAL,
193 
194     MS_VE_DCS_COMPONENT_MIN = 0x10,
195     MS_VE_DCS_COMPONENT_480I = MS_VE_DCS_COMPONENT_MIN,
196     MS_VE_DCS_COMPONENT_480P,
197     MS_VE_DCS_COMPONENT_576I,
198     MS_VE_DCS_COMPONENT_576P,
199     MS_VE_DCS_COMPONENT_720P_24,
200     MS_VE_DCS_COMPONENT_720P_25,
201     MS_VE_DCS_COMPONENT_720P_30,
202     MS_VE_DCS_COMPONENT_720P_50,
203     MS_VE_DCS_COMPONENT_720P_60,
204     MS_VE_DCS_COMPONENT_1080I_50,
205     MS_VE_DCS_COMPONENT_1080I_60,
206     MS_VE_DCS_COMPONENT_1080P_24,
207     MS_VE_DCS_COMPONENT_1080P_25,
208     MS_VE_DCS_COMPONENT_1080P_30,
209     MS_VE_DCS_COMPONENT_1080P_50,
210     MS_VE_DCS_COMPONENT_1080P_60,
211     MS_VE_DCS_COMPONENT_MAX = MS_VE_DCS_COMPONENT_1080P_60,
212 
213     MS_VE_DCS_TYPE_MAX = MS_VE_DCS_COMPONENT_MAX,
214 } MS_VE_DCS_TYPE;
215 
216 //VE capability struct
217 typedef struct
218 {
219     MS_BOOL bSupport_UpScale;
220     MS_BOOL bSupport_CropMode;
221     MS_BOOL bSupport_DolbyVerifier;
222 }MS_VE_Cap;
223 
224 typedef enum
225 {
226     MS_VE_DRAM_FORMAT_Y8C8 = 0,
227     MS_VE_DRAM_FORMAT_Y8C8M4,
228 }MS_VE_DRAM_FORMAT;
229 
230 typedef struct
231 {
232     MS_U8   u8CPC[2];
233     MS_U8   u8CPS[34];
234 }MS_VE_MV_ByteInfo;
235 
236 typedef struct
237 {
238     //Versioning
239     MS_U32  u32VE_MV_BitControl_version;     ///<Version of current structure.
240     MS_U32  u32VE_MV_BitControl_Length;      ///<Length of this structure, u32VE_MV_BitControl_Length=sizeof(MS_VE_MV_BitControl)
241     //Data
242     MS_BOOL bIsYPbPr;
243     union
244     {
245         MS_U8              u8MV_ByteInfo[36];
246         MS_VE_MV_ByteInfo  MV_ByteInfo;
247     }__attribute__ ((__packed__)) ;
248 }MS_VE_MV_BitControl;
249 
250 //-------------------------------------------------------------------------------------------------
251 //  Function and Variable
252 //-------------------------------------------------------------------------------------------------
253 
254 void MDrv_VE_PowerOn(void);
255 void MDrv_VE_PowerOff(void);
256 void Hal_VE_set_fix_color_out(MS_BOOL ben, MS_U8 u8color_y, MS_U8 u8color_cb, MS_U8 u8color_cr);
257 
258 void Hal_VE_set_wss_data(MS_BOOL ben, MS_U16 u16wssdata);
259 MS_U16 Hal_VE_get_wss_data(void);
260 void Hal_VE_set_color_convert(MS_VE_VIDEOSYS VideoSys, MS_U8 u8DACType);
261 
262 void Hal_VE_init(void);
263 MS_BOOL Hal_VE_set_output_video_std(MS_VE_VIDEOSYS VideoSystem);
264 MS_VE_VIDEOSYS Hal_VE_Get_Output_Video_Std(void);
265 
266 MS_BOOL Hal_VE_SetCusTable(MS_VE_VIDEOSYS VideoSystem, MS_U8* pu8Tbl, MS_U16 u16size);
267 void Hal_VE_EnableCusTable(MS_BOOL bEnable);
268 
269 void Hal_VE_set_capture_window(MS_U16 u16hstart, MS_U16 u16hend, MS_U16 u16vstart, MS_U16 u16vend);
270 void Hal_VE_set_hsync_inverse(MS_BOOL bEn);
271 void Hal_VE_set_cvbs_buffer_out(MS_U16 u16chnl, MS_U16 u16mux, MS_U16 u16clamp, MS_U16 u16test);
272 void Hal_VE_set_frc(MS_BOOL bfulldrop, MS_U32 u32fullnum, MS_U32 u32emptynum, MS_BOOL binterlace, MS_BOOL b3FrameMode);
273 void Hal_VE_set_field_inverse(MS_BOOL ben);
274 void Hal_VE_set_ccir656_out_pal(MS_BOOL bpal);
275 void Hal_VE_sofeware_reset(MS_BOOL ben);
276 void Hal_VE_set_vbi(MS_BOOL ben);
277 void Hal_VE_set_reg_load(MS_BOOL ben);
278 void Hal_VE_set_ctrl(MS_U16 u16enval);
279 void Hal_VE_set_h_scaling(MS_BOOL ben, MS_U16 u16ratio);
280 void Hal_VE_set_v_scaling(MS_BOOL ben, MS_U16 u16ratio);
281 void Hal_VE_set_v_scaling_Traditional(MS_BOOL ben, MS_U16 u16ratio);
282 #define Hal_VE_set_v_initfactor(args...)
283 void Hal_VE_set_out_sel(MS_U8 u8out_sel);
284 void Hal_VE_set_source_sync_inv(MS_U8 u8val, MS_U8 u8Mask);
285 void Hal_VE_set_sog(MS_BOOL ben);
286 void Hal_VE_set_inputsource(PMS_VE_InputSrc_Info pInputSrcInfo);
287 void Hal_VE_set_mux(MS_U8 u8clk, MS_U8 u8data);
288 void Hal_VE_set_rgb_in(MS_BOOL ben);
289 void Hal_VE_set_ccir656_in(MS_BOOL ben);
290 void Hal_VE_set_source_interlace(MS_BOOL ben);
291 void Hal_VE_set_ve_on_off(MS_BOOL ben);
292 void Hal_VE_set_clk_on_off(MS_BOOL ben);
293 void Hal_VE_set_blackscreen(MS_BOOL ben);
294 MS_BOOL Hal_VE_is_blackscreen_enabled(void);
295 void Hal_VE_init_riu_base(MS_VIRT virtRiu_Base);
296 void Hal_VE_EnableTtx(MS_BOOL bEnable);
297 void Hal_VE_Set_ttx_Buffer(MS_PHY phyStartAddr, MS_U32 u32Size);
298 void Hal_VE_Clear_ttxReadDoneStatus(void);
299 MS_BOOL Hal_VE_Get_ttxReadDoneStatus(void);
300 void Hal_VE_Set_VbiTtxActiveLines(MS_U8 u8LinePerField);
301 void Hal_VE_SetVbiTtxRange(MS_U16 odd_start, MS_U16 odd_end,
302                          MS_U16 even_start, MS_U16 enen_end);
303 void Hal_VE_Set_VbiTtxActiveLinesBitmap(MS_U32 u32Bitmap);
304 
305 void Hal_VE_EnableCcSw(MS_BOOL bEnable);
306 void Hal_VE_SetCcRange(MS_U16 odd_start, MS_U16 odd_end, MS_U16 even_start, MS_U16 enen_end);
307 void Hal_VE_SendCcData(MS_BOOL bIsOdd, MS_U16 data);
308 
309 void Hal_VE_Set_winodw_offset(MS_PHY phyOffsetAddr);
310 MS_U32 Hal_VE_ConvertARGB2YUV(MS_U32 u32aRGB);
311 VE_Result Hal_VE_SetFrameColor(MS_U32 u32aRGB);
312 void Hal_VE_Set_OSD(MS_BOOL bEnable);
313 VE_Result Hal_VE_Set_OSDLayer(MS_VE_OSD_LAYER_SEL eVideoOSDLayer);
314 MS_VE_OSD_LAYER_SEL Hal_VE_Get_OSDLayer(void);
315 VE_Result Hal_VE_Set_VideoAlpha(MS_U8 u8Val);
316 VE_Result Hal_VE_Get_VideoAlpha(MS_U8 *pu8Val);
317 void Hal_VE_Set_TestPattern(MS_BOOL ben);
318 
319 void Hal_VE_W2BYTE_MSK(MS_U32 u32Reg, MS_U16 u16Val, MS_U16 u16Mask);
320 MS_U16 Hal_VE_R2BYTE_MSK(MS_U32 u32Reg, MS_U16 u16Mask);
321 void Hal_VE_CCIR_PAD_Sel(void);
322 
323 //Dump Table
324 void Hal_VE_DumpTable(MS_U8 *pVeTable, MS_U8 u8TableType);
325 
326 //Set MV
327 VE_Result Hal_VE_SetMV(MS_BOOL bEnable, MS_VE_MV_TYPE eMvType);
328 VE_Result Hal_VE_SetMV_BitControl(MS_BOOL bEnable, MS_VE_MV_BitControl MV_BitControl_Data);
329 
330 //Set DCS
331 VE_Result Hal_VE_DCS_SetType(MS_BOOL bEnable, MS_VE_DCS_TYPE eDCSType);
332 VE_Result Hal_VE_DCS_SetActivationKey(MS_U8 *pu8ActivationKeyTbl, MS_U8 u8ActivationKeyTblSize);
333 
334 MS_BOOL Hal_VE_DisableRegWrite_GetCaps(void);
335 
336 // show internal color bar
337 void Hal_VE_ShowColorBar(MS_BOOL bEnable);
338 VE_Result Hal_VE_AdjustPositionBase(MS_S32 s32WAddrAdjustment, MS_S32 s32RAddrAdjustment);
339 void Hal_VE_set_field_size(MS_U16 u16FieldSize);
340 void Hal_VE_SelMIU(MS_BOOL bMIU1);
341 void Hal_VE_SetMemAddr(MS_PHY *pphyRDAddress, MS_PHY *pphyWRAddress);
342 VE_Result HAL_VE_SetFrameLock(MS_U32 u32IDclk, MS_U32 u32ODclk, MS_U32 u32InitPll, MS_BOOL bEnable);
343 VE_Result Hal_VE_GetCaps(MS_VE_Cap *cap);
344 void Hal_VE_set_h_upscaling(MS_BOOL ben, MS_U32 u32ratio);
345 void Hal_VE_set_v_upscaling(MS_BOOL ben, MS_U32 u32ratio);
346 MS_VE_DRAM_FORMAT Hal_VE_Get_DRAM_Format(void);
347 void Hal_VE_Set_DRAM_Format(MS_VE_DRAM_FORMAT fmt);
348 MS_U8 Hal_VE_Get_Pack_Num_Per_Line(void);
349 void Hal_VE_Set_Pack_Num_Per_Line(MS_U8 PackNumPerLine);
350 MS_U16 Hal_VE_Get_Field_Line_Number(void);
351 void Hal_VE_Set_Field_Line_Number(MS_U16 FieldLineNumber);
352 void Hal_VE_Set_Crop_OSD_Offset(MS_U16 hstart, MS_U16 vstart);
353 void Hal_VE_Set_VScale_Output_Line_Number(MS_U16 line);
354 void Hal_VE_Set_HScale_Output_Line_Number(MS_U16 line);
355 VE_Result Hal_VE_Adjust_FrameStart(MS_S16 pixel_offset);
356 VE_Result Hal_VE_set_wss525_data(MS_BOOL ben, MS_U32 u32wssdata);
357 MS_U32 Hal_VE_get_wss525_data(void);
358 void Hal_VE_OnOffWSS(MS_BOOL ben);
359 MS_BOOL Hal_VE_GetWSSStatus(void);
360 void Hal_VE_OnOffMV(MS_BOOL ben);
361 MS_BOOL Hal_VE_GetMVStatus(void);
362 void Hal_VE_OnOffDCS(MS_BOOL ben);
363 MS_BOOL Hal_VE_GetDCSStatus(void);
364 void Hal_VE_set_dolby_verifier_addr(MS_PHY u32Addr);
365 MS_U32 Hal_VE_get_dolby_verifier_buf_size(void);
366 #define Hal_VE_Set_PreHSD(args...)
367 VE_Result Hal_VE_ReloadSetting(void);
368 
369 #ifdef __cplusplus
370 }
371 #endif
372 
373 #endif
374 
375