xref: /utopia/UTPA2-700.0.x/modules/vdec_v1/drv/mjpeg/drvMJPEG.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   drvMJPEG.h
98 /// @brief  MJPEG Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 #ifndef _DRV_MJPEG_H_
103 #define _DRV_MJPEG_H_
104 
105 #ifdef __cplusplus
106 extern "C"
107 {
108 #endif
109 
110 //-------------------------------------------------------------------------------------------------
111 //  Hardware Capability
112 //-------------------------------------------------------------------------------------------------
113 #define JPD_DISP_QUEUE_MAX_SIZE         32
114 
115 // Chip Define
116 typedef enum
117 {
118     E_MJPEG_MSTAR_CHIP_NONE = 0,
119     E_MJPEG_MSTAR_CHIP_U3,
120     E_MJPEG_MSTAR_CHIP_T3,
121     E_MJPEG_MSTAR_CHIP_T4,
122     E_MJPEG_MSTAR_CHIP_JANUS,
123     E_MJPEG_MSTAR_CHIP_U4,
124     E_MJPEG_MSTAR_CHIP_T8,
125     E_MJPEG_MSTAR_CHIP_T9,
126     E_MJPEG_MSTAR_CHIP_T13,
127     E_MJPEG_MSTAR_CHIP_A1,
128     E_MJPEG_MSTAR_CHIP_A6,
129     E_MJPEG_MSTAR_CHIP_A7,
130     E_MJPEG_MSTAR_CHIP_AMETHYST,
131     E_MJPEG_MSTAR_CHIP_EAGLE,
132     E_MJPEG_MSTAR_CHIP_J2,
133     E_MJPEG_MSTAR_CHIP_EMERALD,
134     E_MJPEG_MSTAR_CHIP_M12,
135 } MJPEG_MSTAR_CHIP_ID;
136 
137 // Mimic fwJPD_if.h
138 typedef enum
139 {
140     // Invalid cmd
141     E_MJPEG_CMD_INVALID = 0xffffffffUL,
142 
143     E_MJPEG_CMD_GO                             = 0x00, // Start to show
144     E_MJPEG_CMD_SET_FRAME_BUFF_START_ADDR      = 0x01, // Set frame buffer address
145     E_MJPEG_CMD_SET_FRAME_BUFF_UNIT_SIZE       = 0x02, // Set frame buffer size
146     E_MJPEG_CMD_SET_FRAME_BUFF_TOTAL_NUM       = 0x03, // Set total number of frame buffer
147     E_MJPEG_CMD_SET_FRAME_BUFF_IDX             = 0x04, // Set frame buffer index
148     E_MJPEG_CMD_SET_FRAME_BUFF_IDX_READY       = 0x05, // Set frame buffer index ready for display
149     E_MJPEG_CMD_SET_WIDTH                      = 0x06, // Set frame width
150     E_MJPEG_CMD_SET_HEIGHT                     = 0x07, // Set frame height
151     E_MJPEG_CMD_SET_PITCH                      = 0x08, // Set pitch
152     E_MJPEG_CMD_SET_FRAME_ID_L                 = 0x09, // Set frame ID_L
153     E_MJPEG_CMD_SET_FRAME_ID_H                 = 0x0A, // Set frame ID_H
154     E_MJPEG_CMD_SET_TIMESTAMP                  = 0x0B, // Set Time Stamp
155     E_MJPEG_CMD_SET_FRAMERATE                  = 0x0C, // Set FrameRate
156     E_MJPEG_CMD_SET_FRAMERATE_BASE             = 0x0D, // Set FrameRate Base
157     E_MJPEG_CMD_SET_FRAME_BUFF_IDX_VALID       = 0x0E, // Set frame buffer index available
158     E_MJPEG_CMD_SET_CHIP_ID                    = 0x0F, // Set frame buffer index available
159 
160     E_MJPEG_CMD_PLAY                           = 0x20, // Play
161     E_MJPEG_CMD_PAUSE                          = 0x21, // Pause
162     E_MJPEG_CMD_RESUME                         = 0x22, // Resume
163     E_MJPEG_CMD_STEP_PLAY                      = 0x23, // Step play
164     E_MJPEG_CMD_SET_SPEED_TYPE                 = 0x24, // Set play speed type: default, fast, slow
165     E_MJPEG_CMD_SET_SPEED                      = 0x25, // Set play speed
166     E_MJPEG_CMD_FLUSH_DISP_QUEUE               = 0X26, // Flush display queue
167     E_MJPEG_CMD_FREEZE_DISP                    = 0x27, // Freeze display
168     E_MJPEG_CMD_ENABLE_AVSYNC                  = 0x28, // Enable AV sync
169     E_MJPEG_CMD_SET_AVSYNC_DELAY               = 0x29, // Set AV sync delay
170     E_MJPEG_CMD_SET_AVSYNC_TOLERENCE           = 0x2A, // Set AV sync tolerence
171     E_MJPEG_CMD_SET_PTS_BASE                   = 0x2B, // Set PTS base
172     E_MJPEG_CMD_SET_STC_BASE                   = 0x2C, // Set STC base
173     E_MJPEG_CMD_SET_BLUE_SCREEN                = 0x2D, // Set Blue Screen
174 
175     E_MJPEG_CMD_GET_NEXT_FREE_FRAME_BUFF_IDX   = 0x40, // Get next free frame buffer index
176     E_MJPEG_CMD_COMPENSATE_PTS                 = 0x41, // Ask firmware to compensate PTS
177 
178     // Display Command Queue
179     E_MJPEG_CMD_ENABLE_DISP_CMD_QUEUE          = 0x80, // Enable Display Command Queue
180     E_MJPEG_CMD_PUSH_DISP_CMD                  = 0x81, // Push Display Command
181     E_MJPEG_CMD_GET_DISP_CMD_Q_VACANCY         = 0x82, // Check if the display command queue full or not
182 
183     E_MJPEG_CMD_IS_STEP_PLAY_DONE              = 0xFF, //
184     E_MJPEG_CMD_IS_DISP_FINISH                 = 0xFE, //
185     E_MJPEG_CMD_IS_PLAYING                     = 0xFC, //
186     E_MJPEG_CMD_IS_DISPLAY_QUEUE_FULL          = 0xFB, //
187     E_MJPEG_CMD_IS_AVSYNC_ON                   = 0xFA, //
188     E_MJPEG_CMD_IS_REACH_AVSYNC                = 0xF9, //
189     E_MJPEG_CMD_IS_FLUSH_DONE                  = 0xF8, // Check if flush done
190 
191 } MJPEG_User_Cmd;
192 
193 // JPD debug level enum
194 typedef enum
195 {
196     E_JPD_DEBUG_DRV_NONE = 0x0
197   , E_JPD_DEBUG_DRV_MSG  = 0x02
198   , E_JPD_DEBUG_DRV_ERR  = 0x08
199 } JPD_DrvDbgLevel;
200 
201 typedef enum
202 {
203     E_JPD_FAILED        = 0
204   , E_JPD_OK            = 1
205   , E_JPD_INVALID_PARAM = 2
206 } JPD_Return;
207 
208 // Command
209 typedef enum
210 {
211     // Invalid cmd
212     E_JPD_CMD_INVALID = 0xffffffffUL,
213 
214     E_JPD_CMD_GO                             = 0x00, // Start to show
215     E_JPD_CMD_SET_FRAME_BUFF_START_ADDR      = 0x01, // Set frame buffer address
216     E_JPD_CMD_SET_FRAME_BUFF_UNIT_SIZE       = 0x02, // Set frame buffer size
217     E_JPD_CMD_SET_FRAME_BUFF_TOTAL_NUM       = 0x03, // Set total number of frame buffer
218     E_JPD_CMD_SET_FRAME_BUFF_IDX             = 0x04, // Set frame buffer index
219     E_JPD_CMD_SET_FRAME_BUFF_IDX_READY       = 0x05, // Set frame buffer index ready for display
220     E_JPD_CMD_SET_WIDTH                      = 0x06, // Set frame width
221     E_JPD_CMD_SET_HEIGHT                     = 0x07, // Set frame height
222     E_JPD_CMD_SET_PITCH                      = 0x08, // Set pitch
223     E_JPD_CMD_SET_FRAME_ID_L                 = 0x09, // Set frame ID_L
224     E_JPD_CMD_SET_FRAME_ID_H                 = 0x0A, // Set frame ID_H
225     E_JPD_CMD_SET_TIMESTAMP                  = 0x0B, // Set Time Stamp
226     E_JPD_CMD_SET_FRAMERATE                  = 0x0C, // Set FrameRate
227     E_JPD_CMD_SET_FRAMERATE_BASE             = 0x0D, // Set FrameRate Base
228     E_JPD_CMD_SET_FRAME_BUFF_IDX_VALID       = 0x0E, // Set frame buffer index available
229     E_JPD_CMD_SET_CHIP_ID                    = 0x0F, // Set Chip ID
230 
231     E_JPD_CMD_PLAY                           = 0x20, // Play
232     E_JPD_CMD_PAUSE                          = 0x21, // Pause
233     E_JPD_CMD_RESUME                         = 0x22, // Resume
234     E_JPD_CMD_STEP_PLAY                      = 0x23, // Step play
235     E_JPD_CMD_SET_SPEED_TYPE                 = 0x24, // Set play speed type: default, fast, slow
236     E_JPD_CMD_SET_SPEED                      = 0x25, // Set play speed
237     E_JPD_CMD_FLUSH_DISP_QUEUE               = 0X26, // Flush display queue
238     E_JPD_CMD_FREEZE_DISP                    = 0x27, // Freeze display
239     E_JPD_CMD_ENABLE_AVSYNC                  = 0x28, // Enable AV Sync
240     E_JPD_CMD_SET_AVSYNC_DELAY               = 0x29, // Set AV sync delay
241     E_JPD_CMD_SET_AVSYNC_TOLERENCE           = 0x2A, // Set AV sync tolerence
242     E_JPD_CMD_SET_PTS_BASE                   = 0x2B, // Set PTS base
243     E_JPD_CMD_SET_STC_BASE                   = 0x2C, // Set STC base
244     E_JPD_CMD_SET_BLUE_SCREEN                = 0x2D, // Set Blue Screen
245 
246     E_JPD_CMD_GET_NEXT_FREE_FRAME_BUFF_IDX   = 0x40, // Get next free frame buffer index
247     E_JPD_CMD_COMPENSATE_PTS                 = 0x41, // Ask firmware to compensate PTS
248 
249     // Display Command Queue
250     E_JPD_CMD_ENABLE_DISP_CMD_QUEUE          = 0x80, // Enable Display Command Queue
251     E_JPD_CMD_PUSH_DISP_CMD                  = 0x81, // Push Display Command
252     E_JPD_CMD_GET_DISP_CMD_Q_VACANCY         = 0x82, // Check if the display command queue full or not
253 
254     E_JPD_CMD_IS_STEP_PLAY_DONE              = 0xFF, //
255     E_JPD_CMD_IS_DISP_FINISH                 = 0xFE, //
256     E_JPD_CMD_IS_PLAYING                     = 0xFC, //
257     E_JPD_CMD_IS_DISPLAY_QUEUE_FULL          = 0xFB, //
258     E_JPD_CMD_IS_AVSYNC_ON                   = 0xFA, //
259     E_JPD_CMD_IS_REACH_AVSYNC                = 0xF9, //
260     E_JPD_CMD_IS_FLUSH_DONE                  = 0xF8, // Check if flush done
261 
262 } JPD_User_Cmd;
263 
264 typedef enum
265 {
266     E_JPD_DISPQ_STATUS_NONE = 0,            //FW
267     E_JPD_DISPQ_STATUS_INIT,                //FW
268     E_JPD_DISPQ_STATUS_VIEW,                //HK
269     E_JPD_DISPQ_STATUS_DISP,                //HK
270     E_JPD_DISPQ_STATUS_FREE,                //HK
271 } JPD_DISPQ_STATUS;
272 
273 /// frame information
274 typedef struct
275 {
276     /// frame buffer base + the start offset of current displayed luma data. Unit: byte.
277     MS_U32 u32LumaAddr;
278     /// frame buffer base + the start offset of current displayed chroma data. Unit: byte.
279     MS_U32 u32ChromaAddr;
280     /// Time stamp(DTS, PTS) of current displayed frame. Unit: ms (todo: 90khz)
281     MS_U32 u32TimeStamp;
282     /// low part of ID number
283     MS_U32 u32ID_L;
284     /// high part of ID number
285     MS_U32 u32ID_H;
286     /// pitch
287     MS_U16 u16Pitch;
288     /// width
289     MS_U16 u16Width;
290     /// hight
291     MS_U16 u16Height;
292     ///< Frame type: I, P, B frame
293     MS_U8 u8FrameType;
294     /// 4-byte alignment
295     MS_U8 u8Reserved;
296     ///< 0:None, 1:Init, 2:View, 3:Disp, 4:Free
297     MS_U32 u32Status;
298 } MJPG_FrameInfo;
299 
300 // Share Memory
301 typedef struct
302 {
303     // HK -> FW
304 //    MS_U32 u32FrameBufAddr;
305 //    MS_U32 u32FrameBufSize;
306 
307     // FW -> HK
308     MS_U32 u32FWVersionID;              // FW version ID
309 
310     //
311 //    MS_U32 u32DispBufAddr;
312     MJPG_FrameInfo infoDispFrame;      // Information of currently displayed frame
313 
314 
315     // PTS table
316 //    MS_U32 u32TimeStamp;            // current PTS
317 //    MS_U32 u32PTStableWptrAddr;     // The address of PTS table write pointer.
318 //    MS_U32 u32PTStableRptrAddr;     // The address of PTS table read pointer.
319 
320     MS_U32 u16DispQSize;
321     MS_U16 u16DispQNumb;
322     MS_U16 u16DispQPtr;
323     MJPG_FrameInfo DispQueue[JPD_DISP_QUEUE_MAX_SIZE];
324 } JPD_ShareMem;
325 
326 //#define HVD_PTS_TABLE_ST_OFFSET     0x50000
327 #define JPD_PTS_TABLE_ST_OFFSET     0x70000
328 //#define HVD_SHARE_MEM_ST_OFFSET     0x79000
329 #define JPD_SHARE_MEM_ST_OFFSET     0x80000
330 #define JPD_DEBUG_MEM_ST_OFFSET     0x81000
331 
332 
333 /* =============================== MJPEG =====================================*/
334 void MDrv_MJPEG_SetDbgLevel(MS_U8 u8DbgLevel);
335 void MDrv_JPD_StopVPU(void);
336 MS_BOOL MDrv_JPD_RstVPU(void);
337 void MDrv_JPD_ReleaseVPU(void);
338 MS_BOOL MDrv_JPD_LoadCode(MS_PHYADDR u32Addr, MS_U32 u32Size, MS_U32 u32BinAddr, MS_U8 u8FwSrcType);
339 void MDrv_JPD_ConfigVPU(MS_PHYADDR u32StAddr, MS_U8 u8dlend_en);
340 MS_BOOL MDrv_JPD_IsFirmwareReady(void);
341 
342 #if 0
343 MS_BOOL MDrv_JPD_SetVPUCmd(MS_U32 u32Cmd);
344 MS_BOOL MDrv_JPD_SetVPUCmdArg(MS_U32 u32Arg);
345 MS_U32 MDrv_JPD_CheckVPUStatus(MS_U32 u32Cmd);
346 MS_U32 MDrv_JPD_GetNextFreeFrameBuffIdx(void);
347 #endif
348 MS_U32 MDrv_JPD_SendVPUCommand(MJPEG_User_Cmd eCmd, MS_U32 u32Arg);
349 
350 MS_BOOL MDrv_JPD_IsVPUOnMiu1(void);
351 MS_U32 MDrv_JPD_GetMiuBase(void);
352 MS_U32 MDrv_JPD_GetShareMemAddr(void);
353 void MDrv_JPD_ClearShareMemory(void);
354 MS_U32 MDrv_JPD_GetPtsTableAddr(void);
355 
356 MS_BOOL MDrv_JPD_ResetPTS(MS_U32 u32PtsBase);
357 MS_U32 MDrv_JPD_GetPTS(void);
358 void MDrv_JPD_GetDispFrameInfo(void *pInfo);
359 
360 void MDrv_JPD_DispFrame(MS_U32 u32DispIdx);
361 void MDrv_JPD_FreeFrame(MS_U32 u32DispIdx);
362 void* MDrv_JPD_GetNextDispFrame(void);
363 MS_U32 MDrv_JPD_GetNextDispQPtr(void);
364 
365 void MDrv_JPD_EnableTurboFWMode(MS_BOOL bEnable);
366 
367 JPD_Return MDrv_JPD_InitFw(MS_PHYADDR u32Addr, MS_U32 u32Size, MS_PHYADDR u32BinAddr, MS_U8 u8FwSrcType);
368 MJPEG_MSTAR_CHIP_ID MDrv_JPD_Get_Chip_ID(void);
369 
370 
371 #ifdef __cplusplus
372 }
373 #endif
374 
375 #endif // _DRV_MJPEG_H_
376 
377