xref: /utopia/UTPA2-700.0.x/modules/vdec_v1/hal/messi/mvd/halMVD.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 #ifndef _DEV_MVD_H_
96 #define _DEV_MVD_H_
97 
98 #include "mvd4_interface.h" //firmware header
99 #include "halVPU.h"
100 
101 //-------------------------------------------------------------------------------------------------
102 //  Macro and Define
103 //-------------------------------------------------------------------------------------------------
104 
105 //#define MVD_ENABLE_ISR    //unmark this to enable MVD ISR
106 
107 #ifndef __MDRV_TYPES_H__
108 #define BIT0    BIT(0)
109 #define BIT1    BIT(1)
110 #define BIT2    BIT(2)
111 #define BIT3    BIT(3)
112 #define BIT4    BIT(4)
113 #define BIT5    BIT(5)
114 #define BIT6    BIT(6)
115 #define BIT7    BIT(7)
116 #endif
117 
118 #define H_DWORD(x)            (MS_U8)(((x)>>24)&0xff)
119 #define L_DWORD(x)            (MS_U8)(((x)>>16)&0xff)
120 #define H_WORD(x)             (MS_U8)(((x)>>8 )&0xff)
121 #define L_WORD(x)             (MS_U8)((x)&0xff)
122 #define COMBM16(hi,lo)        ((((MS_U16)(hi))<<8) | ((MS_U16)(lo)))
123 #define COMBU32(hh,hl,lh,ll)  ((((MS_U32)(hh))<<24) | (((MS_U32)(hl))<<16) | (((MS_U32)(lh))<<8) | ((MS_U32)(ll)))
124 #ifndef MemAlign
125 #define MemAlign(n, unit)     ( (((n)+(unit)-1)/(unit)) * (unit) )
126 #endif
127 
128 //Init command arguments
129 #define SETUP_CMDARG(x)     \
130             do {            \
131                 x.Arg0 = 0; \
132                 x.Arg1 = 0; \
133                 x.Arg2 = 0; \
134                 x.Arg3 = 0; \
135                 x.Arg4 = 0; \
136                 x.Arg5 = 0; \
137                } while(0)
138 
139 //Set command arguments
140 #define SET_CMDARG(cmd, u32val)             \
141             do {                            \
142                 cmd.Arg0 = L_WORD(u32val);  \
143                 cmd.Arg1 = H_WORD(u32val);  \
144                 cmd.Arg2 = L_DWORD(u32val); \
145                 cmd.Arg3 = H_DWORD(u32val); \
146                 cmd.Arg4 = 0;               \
147                 cmd.Arg5 = 0;               \
148                } while(0)
149 
150 void HAL_MVD_RegSetBase(MS_U32 u32Base);
151 MS_U8 HAL_MVD_RegReadByte(MS_U32 u32Reg);
152 void HAL_MVD_RegWriteByte(MS_U32 u32Reg, MS_U8 u8Val);
153 void HAL_MVD_RegWriteBit(MS_U32 u32Reg, MS_BOOL bEnable, MS_U8 u8Mask);
154 void HAL_MVD_RegWriteByteMask(MS_U32 u32Reg, MS_U8 u8Val, MS_U8 u8Msk);
155 void HAL_MVD_RegWrite4Byte(MS_U32 u32Reg, MS_U32 u32Val);
156 
157 // Mutex function for HI interface
158 #define HAL_MVD_LockHiIfMutex()
159 #define HAL_MVD_UnlockHiIfMutex()
160 
161 #define HAL_MVD_SetVpuFwDecoder(x) HAL_VPU_SetFWDecoder(x)
162 
163 #define MVD_SUPPORT_MPEG2 0x01
164 #define MVD_SUPPORT_MPEG4 0x02
165 #define MVD_SUPPORT_VC1   0x04
166 
167 #define MVD_FW_VERSION   FW_VERSION
168 #define MVD_FW_CODE_LEN                    (0x40000UL)  //256K
169 #define MVD_SYNC_DONE    1
170 
171 typedef enum
172 {
173     E_MVD_VER_ERR = 0x0,
174     E_MVD_VER_4  = 0x1,
175     E_MVD_VER_5  = 0x10,
176     E_MVD_VER_6  = 0x100,
177     E_MVD_VER_MAX =0x11111111
178 } MVD_VER_Type;
179 //------------------------------------------------------------------------------//
180 //MVD Engine family description (from mvd4 ~ mvd ??)
181 //*****
182 //MVD 4
183 //==>T3 ,U3, JANUS,T4 ,U4 , K1, M10
184 //
185 //#define MVD_HW_VER E_MVD_VER_4
186 //#define MVD_SLQ_TBL_ENTRY_LENS 0x0FFFFFFF
187 //#define MVD_SLQ_TBL_ENTRY_SIZES 28
188 //#define MVD_SLQ_TBL_SHIFT_MASK 0xff
189 //#define MVD_SLQ_TBL_SHIFT_BIT1 24
190 //#define MVD_SLQ_TBL_SHIFT_BIT2  4
191 //#define MVD_TILE_MODE_MASK 0x0007
192 //#define MVD_TILE_MODE_PITCH_LENS 8
193 //#define MVD_TILE_MODE_PITCH_SIZES  3
194 //
195 //MVD 5
196 //==>T8 ,T9, J2 ,T11 ,T12 ,T13
197 //
198 //#define MVD_HW_VER (E_MVD_VER_5|E_MVD_VER_4)
199 //#define MVD_SLQ_TBL_ENTRY_LENS 0x1FFFFFFF
200 //#define MVD_SLQ_TBL_ENTRY_SIZES 29
201 //#define MVD_SLQ_TBL_SHIFT_MASK 0x3f
202 //#define MVD_SLQ_TBL_SHIFT_BIT1 26
203 //#define MVD_SLQ_TBL_SHIFT_BIT2 3
204 //#define MVD_TILE_MODE_MASK 0x000f
205 //#define MVD_TILE_MODE_PITCH_LENS 16
206 //#define MVD_TILE_MODE_PITCH_SIZES 4
207 //
208 //MVD 6
209 //==>A1 ,A2 ,A5
210 //
211 //#define MVD_HW_(E_MVD_VER_6|E_MVD_VER_5|E_MVD_VER_4)
212 //#define MVD_SLQ_TBL_ENTRY_LENS 0x1FFFFFFF
213 //#define MVD_SLQ_TBL_ENTRY_SIZES 29
214 //#define MVD_SLQ_TBL_SHIFT_MASK 0x3f
215 //#define MVD_SLQ_TBL_SHIFT_BIT1 26
216 //#define MVD_SLQ_TBL_SHIFT_BIT2 3
217 //#define MVD_TILE_MODE_MASK 0x000f
218 //#define MVD_TILE_MODE_PITCH_LENS 16
219 //#define MVD_TILE_MODE_PITCH_SIZES 4
220 //
221 //------------------------------------------------------------------------------//
222 #if defined(CHIP_MONET)
223 #define MVD_HW_VER (E_MVD_VER_6|E_MVD_VER_5|E_MVD_VER_4)
224 #define MVD_SLQ_TBL_ENTRY_LENS 0x7FFFFFFF
225 #define MVD_SLQ_TBL_ENTRY_SIZES 31
226 #define MVD_SLQ_TBL_SHIFT_MASK 0x0
227 #define MVD_SLQ_TBL_SHIFT_BIT1 0
228 #define MVD_SLQ_TBL_SHIFT_BIT2 0
229 #define MVD_TILE_MODE_MASK 0x000f
230 #define MVD_TILE_MODE_PITCH_LENS 16
231 #define MVD_TILE_MODE_PITCH_SIZES 4
232 #define MVD_SUPPORT_DHD 1
233 #else
234     #error "The CHIP version not verify yet ,Plz contact MVD owner !!"
235 #endif
236 
237 #ifdef REDLION_LINUX_KERNEL_ENVI
238 #if defined(CHIP_T3)
239 #define MVD_MIU1_BASE_ADDRESS   0x08000000UL//0x10000000UL
240 #else
241 #define MVD_MIU1_BASE_ADDRESS   0x08000000UL
242 #endif
243 #endif
244 
245 //-------------------------------------------------------------------------------------------------
246 //  Type and Structure
247 //-------------------------------------------------------------------------------------------------
248 typedef enum
249 {
250     E_MVD_MMAP_FW  = 0, //firmware
251     E_MVD_MMAP_BS  = 1, //bitstream buffer
252     E_MVD_MMAP_FB  = 2, //framebuffer
253     E_MVD_MMAP_ALL = 3,
254     E_MVD_MMAP_DRV = 4  //driver processing buffer
255 } MVD_MMAP_Type;
256 
257 
258 typedef struct _MVD_DrvCfg
259 {
260     MS_U32 u32fmVerNum;//firmware version number
261     MS_U16 u16fmSrcID; //firmware bin source id
262     MS_U8  u8fbMode;   //framebuffer mode: HD or SD
263 } MVD_DrvCfg;
264 
265 #if 0
266 typedef struct _MVD_HWCfg
267 {
268     MS_U32 MVD_HWVER;
269     MS_U32 u32MvdSlqTabLens;
270     MS_U32 u32MvdSlqTabSizes;
271     MS_U32 u32MvdSlqTabShiftMask;
272     MS_U32 u32MvdSlqTabShiftBit1;
273     MS_U32 u32MvdSlqTabShiftBit2;
274 
275     MS_U16 u16MvdTileModeMask;
276     MS_U16 u16MvdTileModePitchLens;
277     MS_U16 u16MvdTileModePitchSize;
278 
279 } MVD_HWCfg;
280 #endif
281 
282 //-------------------------------------------------------------------------------------------------
283 //  Function and Variable
284 //-------------------------------------------------------------------------------------------------
285 MS_U8 HAL_MVD_GetCaps(void);
286 void HAL_MVD_MemSetMap(MS_U8 u8type, MS_U32 u32addr, MS_U32 u32len);
287 void HAL_MVD_MemGetMap(MS_U8 u8type, MS_U32* pu32addr, MS_U32* pu32len);
288 MS_U32 HAL_MVD_MemRead4Byte(MS_U32 u32Address);
289 MS_U16 HAL_MVD_MemRead2Byte(MS_U32 u32Address);
290 MS_U8 HAL_MVD_MemReadByte(MS_U32 u32Address);
291 MS_BOOL HAL_MVD_MemWrite4Byte(MS_U32 u32Address, MS_U32 u32Value);
292 MS_BOOL HAL_MVD_MemWrite2Byte(MS_U32 u32Address, MS_U16 u16Value);
293 MS_BOOL HAL_MVD_MemWriteByte(MS_U32 u32Address, MS_U8 u8Value);
294 void HAL_MVD_SetReqMask(MS_BOOL bEnMask);
295 
296 MS_PHYADDR  HAL_MVD_PA2NonCacheSeg(MS_PHYADDR u32PhyAddr);
297 MS_U32      HAL_MVD_GetTime(void);
298 void        HAL_MVD_Delayms(MS_U32 u32msecs);
299 void        HAL_MVD_CPU_Sync(void);
300 void        HAL_MVD_FlushMemory(void);
301 void        HAL_MVD_ReadMemory(void);
302 
303 MS_BOOL HAL_MVD_RstHW(void);
304 MS_BOOL HAL_MVD_ReleaseFW(void);
305 MS_BOOL HAL_MVD_LoadCode(void);
306 void HAL_MVD_SetFWBinID(MS_U32 u32SrcID);
307 
308 MS_U8 HAL_MVD_GetChipMajorID(void);
309 
310 void HAL_MVD_PowerCtrl(MS_BOOL bOn);
311 MS_BOOL HAL_MVD_TimeOut(void);
312 MS_BOOL HAL_MVD_MVDCommand(MS_U8 u8cmd, MVD_CmdArg *pstCmdArg);
313 MS_BOOL HAL_MVD_InitHW(void);
314 MS_BOOL HAL_MVD_InitFW(void);
315 MS_U32 HAL_MVD_GetFWVer(void);
316 MS_BOOL HAL_MVD_SoftRstHW(void);
317 void HAL_MVD_ClearIRQ(void);
318 
319 MS_BOOL HAL_MVD_SetSpeed(MVD_SpeedType eSpeedType, MS_U8 u8Multiple);
320 MS_BOOL HAL_MVD_EnableForcePlay(void);
321 void HAL_MVD_SetFrameBuffAddr(MS_U32 u32addr, MS_U8 u8fbMode);
322 void HAL_MVD_SetHeaderBufferAddr(MS_U32 u32addr);
323 void HAL_MVD_SetVolInfoBufferAddr(MS_U32 u32addr);
324 void HAL_MVD_SetFrameInfoBufferAddr(MS_U32 u32addr);
325 void HAL_MVD_SetIAPBufferAddr(MS_U32 u32addr);
326 void HAL_MVD_SetDPBufferAddr(MS_U32 u32addr);
327 void HAL_MVD_SetMVBufferAddr(MS_U32 u32addr);
328 void HAL_MVD_SetUserDataBuf(MS_U32 u32addr, MS_U32 u32size);
329 void HAL_MVD_SetSLQTblBufStartEnd(MS_U32 u32start, MS_U32 u32end);
330 MS_BOOL HAL_MVD_StepDisp(void);
331 MS_BOOL HAL_MVD_EnableLastFrameShow(MS_BOOL bEnable);
332 MS_BOOL HAL_MVD_SlqTblRst(void);
333 MS_BOOL HAL_MVD_SeekToPTS(MS_U32 u32Pts);
334 MS_BOOL HAL_MVD_SkipToPTS(MS_U32 u32Pts);
335 MS_BOOL HAL_MVD_SetFileModeAVSync(MVD_TIMESTAMP_TYPE eSyncMode);
336 MS_BOOL HAL_MVD_SetPtsTblAddr(MS_U32 u32addr);
337 MS_BOOL HAL_MVD_SetScalerInfoAddr(MS_U32 u32addr);
338 MS_BOOL HAL_MVD_SetDynamicScaleAddr(MS_U32 u32addr);
339 MS_BOOL HAL_MVD_SetVirtualBox(MS_U16 u16Width, MS_U16 u16Height);
340 MS_BOOL HAL_MVD_EnableDynamicScale(void);
341 MS_BOOL HAL_MVD_SetBlueScreen(MS_BOOL bEn);
342 MS_BOOL HAL_MVD_Resume(void);
343 MS_BOOL HAL_MVD_SetFreezeDisp(MS_BOOL bEn);
344 void HAL_MVD_SetDecFrmInfoAddr(MS_U32 u32addr);
345 MS_U32 HAL_MVD_GetIntState(void);
346 MS_U8 HAL_MVD_GetAVSyncStatus(void);
347 void HAL_MVD_SlqTblLoadWrPtr(MS_U32 u32WrPtr);
348 MS_U32 HAL_MVD_SlqTblProbeWrPtr(void);
349 MS_U32 HAL_MVD_SlqTblProbeRdPtr(void);
350 MS_BOOL HAL_MVD_SetMStreamerMode(MS_U8 u8Mode);
351 MS_BOOL HAL_MVD_FrameOpt(MS_U8 u8FrmIdx, MVD_FrmOpt eOpt);
352 MS_BOOL HAL_MVD_UpdatePts(void);
353 MS_BOOL HAL_MVD_FrameCapture(MS_U8 u8FrmIdx, MS_BOOL bEnable);
354 MS_BOOL HAL_MVD_GetFrmRateIsSupported(MS_U16 u16HSize, MS_U16 u16VSize, MS_U32 u32FrmRate);
355 
356 void HAL_MVD_SetDbgLevel(MS_U8 level);
357 //MS_BOOL HAL_MVD_GetMVDEngineCfg(MVD_HWCfg* MvdHWCfg);
358 
359 #endif // _DEV_MVD_H_
360