xref: /utopia/UTPA2-700.0.x/modules/vdec_v2/drv/mvd_ex/mvd_cc_EX.c (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 /// @file  drvmvd_cc.h
94 /// @brief Driver interface for accessing the MPEG Closed Caption decoder.
95 /// @author MStar Semiconductor Inc.
96 ///
97 ///- Providing MPEG Closed Caption decoder command functions for controlling firmware.
98 ///- MPEG Closed Caption decoder provides Digital 608 & 708 CC Data via accessing Ring Buffer
99 ///
100 ////////////////////////////////////////////////////////////////////////////////
101 
102 //--------------------------------------------------------------------------------------------------
103 //  Include Files
104 //--------------------------------------------------------------------------------------------------
105 // Common Definition
106 #ifdef REDLION_LINUX_KERNEL_ENVI
107 #include "drvMVD_Common.h"
108 #else
109 #include "MsCommon.h"
110 #endif
111 #include "drvMVD_EX.h"
112 
113 // Internal Definition
114 #include "halMVD_EX.h"
115 #include "drvmvd_cc.h"
116 #include "mvd4_interface.h" //firmware header
117 #include "string.h"
118 #include "halCHIP.h"
119 #if !defined(MSOS_TYPE_NUTTX) || defined(SUPPORT_X_MODEL_FEATURE)
120 
121 //--------------------------------------------------------------------------------------------------
122 //  Local Defines
123 //--------------------------------------------------------------------------------------------------
124 #define MVDCC_EXHANDLE(y)     y
125 
126 //----------------------------------------------------------------------------
127 /* MVD Command register - Command Definitions */
128 //----------------------------------------------------------------------------
129 #define CMD_SET_CCBUF_STARTHWADDR       CMD_USER_BUF_START
130 #define CMD_SET_CCBUF_TOTALSIZE         CMD_USER_BUF_SIZE
131 #define CMD_SET_CCTYPE_PARSING          CMD_USER_BUF_SIZE
132 #define CMD_GET_CCBUF_HWADDR            CMD_RD_USER_WP
133 #define CMD_GET_CCBUF_WRAPCOUNT         CMD_RD_USER_WP
134 
135 #define CMD_SET_CCBUF_SWADDR            CMD_WD_USER_RP
136 #define CMD_GET_CCBUF_PACKETCOUNT       CMD_RD_CC_PKTCNT
137 #define CMD_GET_OVERFLOW_STATUS         CMD_RD_CC_OV
138 
139 void MDrv_CC_CM_SetMVDRB_SWAddr(MS_U32 u32Id, MS_U32 u32ReadAddress, MS_U8 u8CC608);
140 MS_U32 MDrv_CC_CM_GetMVDRB_HWAddr(MS_U32 u32Id, MS_U8 u8CC608);
141 extern MS_U8 MVD_GetHalIdx(MS_U32 u32Id);
142 
143 //******************************************************************************/
144 //* Local definition
145 //******************************************************************************/
146 #define MVD_READY_TEST_COUNT        10000
147 #define MVD_CCRB_PACKET_LENGTH      8
148 
149 //******************************************************************************/
150 //* Declaring Variable
151 //******************************************************************************/
152 MS_U32 CCMVD_RINGBUFFER_START_ADR[2];
153 MS_U32 CCMVD_RINGBUFFER_LEN[2];
154 
155 static MS_U32 volatile u32SW_Address[2], u32HW_Address[2];
156 static MS_U8 u8ParsingStatus = 0xff;
157 
158 static MS_BOOL bCC708Enable; //fixme
159 
160 // SH@20110111, Fixed the issues that move CC buffer from MIU0 to MIU1
161 // MIU1: buffer to MVD IP, don't need to add the MIU1's offset(512 Mb), but to CC flow's buffer, need to add up
162 
163 #if defined(CHIP_MONACO)
164 static MS_U8 u8BufSelMiu = 0xff;
165 #define MVD_ON_MIU     HAL_MVD_GetFWSelMiu()
166 #else
167 static MS_BOOL bBufMiu0 = 0xff;
168 #define MIU1_BASEADDR   HAL_MVD_GetMiu1BaseAdd()
169 #define MVD_ON_MIU1     HAL_MVD_GetFWSelMiu1()
170 #endif
171 
172 #define _IS_MSTAR_CC(x) ((0==(x)) || (1==(x)))
173 ///////////////////////////////////////////////////////////////////////////////
174 /// Closed Caption Driver Initialization
175 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_Init(MS_U32 u32Id)176 void MDrv_CC_Init(MS_U32 u32Id)
177 {
178     if (u8ParsingStatus == 0xff)
179         u8ParsingStatus = 0x00;
180 }
181 
182 ///////////////////////////////////////////////////////////////////////////////
183 /// Set MVD Ring Buffer's Address
184 /// @param u32StartAddress \b IN Ring Buffer's Address
185 /// @param u8CC608 \b IN
186 ///   - # TRUE for CC608 parser
187 ///   - # FALSE for CC708 parser
188 ///////////////////////////////////////////////////////////////////////////////
189 #if defined(CHIP_MONACO)
MDrv_CC_CM_SetMVDRB_HWAddr(MS_U32 u32Id,MS_U32 u32StartAddress,MS_U8 u8CC608)190 void MDrv_CC_CM_SetMVDRB_HWAddr(MS_U32 u32Id, MS_U32 u32StartAddress, MS_U8 u8CC608)
191 {
192     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
193     MS_U32 u32MVDCC_Temp1 = 0;
194     MVD_CmdArg mvdcmd;
195     MS_U32 u32StartOffset;
196     MS_U8  u8MiuSel;
197 
198     MS_U32 u32Miu1_base = 0;
199     MS_U32 u32Miu2_base = 0;
200     MS_U32 u32Miu3_base = 0;
201 
202     _miu_offset_to_phy(E_CHIP_MIU_1,0,u32Miu1_base);
203     _miu_offset_to_phy(E_CHIP_MIU_2,0,u32Miu2_base);
204     _miu_offset_to_phy(E_CHIP_MIU_3,0,u32Miu3_base);
205 
206     memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
207 
208     // SH@20110111, get the first HW buffer to determine the MIU0 or MIU1 for CC buffer. Only once
209     if(u8BufSelMiu == 0xff)
210     {
211         _phy_to_miu_offset(u8MiuSel, u32StartOffset, u32StartAddress);
212 
213         u8BufSelMiu = u8MiuSel;
214     }
215 
216     if(MVD_ON_MIU == E_CHIP_MIU_0)
217     {
218         if(u8BufSelMiu == E_CHIP_MIU_0)
219         {
220             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress;
221         }
222         else if(u8BufSelMiu == E_CHIP_MIU_1)
223         {
224             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress;
225         }
226         else if(u8BufSelMiu == E_CHIP_MIU_2)
227         {
228             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress;
229         }
230         else if(u8BufSelMiu == E_CHIP_MIU_3)
231         {
232             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress;
233         }
234     }
235     else if(MVD_ON_MIU == E_CHIP_MIU_1)    // SH@20110111, mvd code binary in MIU1
236     {
237         if(u8BufSelMiu == E_CHIP_MIU_0)
238         {
239             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress | u32Miu1_base;
240         }
241         else if(u8BufSelMiu == E_CHIP_MIU_1)
242         {
243             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress;
244         }
245         else if(u8BufSelMiu == E_CHIP_MIU_2)
246         {
247             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress | u32Miu1_base;
248         }
249         else if(u8BufSelMiu == E_CHIP_MIU_3)
250         {
251             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress | u32Miu1_base;
252         }
253     }
254     else if(MVD_ON_MIU == E_CHIP_MIU_2)    // SH@20110111, mvd code binary in MIU1
255     {
256         if(u8BufSelMiu == E_CHIP_MIU_0)
257         {
258             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress | u32Miu2_base;
259         }
260         else if(u8BufSelMiu == E_CHIP_MIU_1)
261         {
262             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress | u32Miu2_base;
263         }
264         else if(u8BufSelMiu == E_CHIP_MIU_2)
265         {
266             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress ;
267         }
268         else if(u8BufSelMiu == E_CHIP_MIU_3)
269         {
270             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress | u32Miu2_base;
271         }
272     }
273     else if(MVD_ON_MIU == E_CHIP_MIU_3)    // SH@20110111, mvd code binary in MIU1
274     {
275         if(u8BufSelMiu == E_CHIP_MIU_0)
276         {
277             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress | u32Miu3_base;
278         }
279         else if(u8BufSelMiu == E_CHIP_MIU_1)
280         {
281             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress | u32Miu3_base;
282         }
283         else if(u8BufSelMiu == E_CHIP_MIU_2)
284         {
285             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress | u32Miu3_base;
286         }
287         else if(u8BufSelMiu == E_CHIP_MIU_3)
288         {
289             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress ;
290         }
291     }
292 
293     if(u8BufSelMiu == E_CHIP_MIU_0)
294     {
295         u32MVDCC_Temp1 = (u32StartAddress >> 3);
296     }
297     else if(u8BufSelMiu == E_CHIP_MIU_1)
298     {
299         u32MVDCC_Temp1 = u32StartAddress - u32Miu1_base ;
300         u32MVDCC_Temp1 = (u32MVDCC_Temp1 >> 3);
301     }
302     else if(u8BufSelMiu == E_CHIP_MIU_2)
303     {
304         u32MVDCC_Temp1 = u32StartAddress - u32Miu2_base ;
305         u32MVDCC_Temp1 = (u32MVDCC_Temp1 >> 3);
306     }
307     else if(u8BufSelMiu == E_CHIP_MIU_3)
308     {
309         u32MVDCC_Temp1 = u32StartAddress - u32Miu3_base ;
310         u32MVDCC_Temp1 = (u32MVDCC_Temp1 >> 3);
311     }
312 
313 
314     mvdcmd.Arg4 = H_DWORD(u32MVDCC_Temp1);
315     mvdcmd.Arg3 = (MS_U8)u8CC608;
316     mvdcmd.Arg2 = L_DWORD(u32MVDCC_Temp1);
317     mvdcmd.Arg1 = H_WORD(u32MVDCC_Temp1);
318     mvdcmd.Arg0 = L_WORD(u32MVDCC_Temp1);
319     SET_DECNUM(mvdcmd, u8HalIdx);
320     if (HAL_MVD_MVDCommand(CMD_SET_CCBUF_STARTHWADDR, &mvdcmd)== TRUE)
321     {
322         u32SW_Address[u8CC608] = u32StartAddress;
323         u32HW_Address[u8CC608] = u32StartAddress;
324         MDrv_CC_CM_SetMVDRB_SWAddr(u32Id, u32StartAddress, u8CC608);
325     }
326     else
327     {
328         MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_SET_CCBUF_STARTHWADDR));
329         MVDCC_EXHANDLE(printf("\nF:S-HA"));
330     }
331 }
332 #else
MDrv_CC_CM_SetMVDRB_HWAddr(MS_U32 u32Id,MS_U32 u32StartAddress,MS_U8 u8CC608)333 void MDrv_CC_CM_SetMVDRB_HWAddr(MS_U32 u32Id, MS_U32 u32StartAddress, MS_U8 u8CC608)
334 {
335     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
336     MS_U32 u32MVDCC_Temp1 = 0;
337     MVD_CmdArg mvdcmd;
338     memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
339 
340     // SH@20110111, get the first HW buffer to determine the MIU0 or MIU1 for CC buffer. Only once
341     if(bBufMiu0 == 0xff)
342     {
343         if((u32StartAddress&MIU1_BASEADDR) == MIU1_BASEADDR)
344         {
345             bBufMiu0 = false;
346         }
347         else
348         {
349             bBufMiu0 = true;
350         }
351     }
352 
353     if(MVD_ON_MIU1)    // SH@20110111, mvd code binary in MIU1
354     {
355         if(bBufMiu0) // SH@20110111, if CC buffer in MIU0, enable here
356         {
357             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress | MIU1_BASEADDR;
358         }
359         else // CC buffer in MIU1
360         {
361             CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress;
362         }
363     }
364     else
365     {
366         CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress;
367     }
368 
369     if(bBufMiu0)
370     {
371         u32MVDCC_Temp1 = (u32StartAddress >> 3);
372     }
373     else // CC buffer in MIU1
374     {
375         u32MVDCC_Temp1 = u32StartAddress - MIU1_BASEADDR ;
376         u32MVDCC_Temp1 = (u32MVDCC_Temp1 >> 3);
377     }
378 
379     mvdcmd.Arg4 = H_DWORD(u32MVDCC_Temp1);
380     mvdcmd.Arg3 = (MS_U8)u8CC608;
381     mvdcmd.Arg2 = L_DWORD(u32MVDCC_Temp1);
382     mvdcmd.Arg1 = H_WORD(u32MVDCC_Temp1);
383     mvdcmd.Arg0 = L_WORD(u32MVDCC_Temp1);
384     SET_DECNUM(mvdcmd, u8HalIdx);
385     if (HAL_MVD_MVDCommand(CMD_SET_CCBUF_STARTHWADDR, &mvdcmd)== TRUE)
386     {
387         u32SW_Address[u8CC608] = u32StartAddress;
388         u32HW_Address[u8CC608] = u32StartAddress;
389         MDrv_CC_CM_SetMVDRB_SWAddr(u32Id, u32StartAddress, u8CC608);
390     }
391     else
392     {
393         MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_SET_CCBUF_STARTHWADDR));
394         MVDCC_EXHANDLE(printf("\nF:S-HA"));
395     }
396 }
397 #endif
398 ///////////////////////////////////////////////////////////////////////////////
399 /// Set MVD Ring Buffer's SW Address as HW Address
400 /// @param u8CC608 \b IN
401 ///   - # TRUE for CC608 parser
402 ///   - # FALSE for CC708 parser
403 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_CM_SyncMVDRB_SWAddr2HWAddr(MS_U32 u32Id,MS_U8 u8CC608)404 void MDrv_CC_CM_SyncMVDRB_SWAddr2HWAddr(MS_U32 u32Id, MS_U8 u8CC608)
405 {
406     MDrv_CC_CM_SetMVDRB_SWAddr(u32Id, u32HW_Address[u8CC608], u8CC608);
407 }
408 
409 ///////////////////////////////////////////////////////////////////////////////
410 /// Set CC Type to MVD CC FW Driver
411 /// @param u8Operation \b IN Digital Closed Caption Type
412 /// @param u16BufferSize \b IN buffer size of the given hardware parser
413 /// @param u8CC608 \b IN
414 ///   - # TRUE for CC608 parser
415 ///   - # FALSE for CC708 parser
416 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_CM_SetParsingType(MS_U32 u32Id,MS_U8 u8Operation,MS_U16 u16BufferSize,MS_U8 u8CC608)417 void MDrv_CC_CM_SetParsingType(MS_U32 u32Id, MS_U8 u8Operation, MS_U16 u16BufferSize, MS_U8 u8CC608)
418 {
419     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
420     MS_U16 u16MVDCC_Temp1 = 0;
421     MVD_CmdArg mvdcmd;
422     memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
423     CCMVD_RINGBUFFER_LEN[u8CC608] = u16BufferSize;
424     u16MVDCC_Temp1 = (u16BufferSize >> 3);
425 
426     u8ParsingStatus |= u8Operation;
427     u8ParsingStatus &= 0x07;
428     mvdcmd.Arg1 = H_WORD(u16MVDCC_Temp1);
429     mvdcmd.Arg0 = L_WORD(u16MVDCC_Temp1);
430     mvdcmd.Arg2 = (MS_U8)(u8ParsingStatus);
431     mvdcmd.Arg3 = (MS_U8)u8CC608;
432     SET_DECNUM(mvdcmd, u8HalIdx);
433     if (HAL_MVD_MVDCommand(CMD_SET_CCTYPE_PARSING, &mvdcmd) != TRUE)
434     {
435         MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_SET_CCTYPE_PARSING));
436         MVDCC_EXHANDLE(printf("\nF:SPT"));
437     }
438     else
439     {
440         if (u8CC608==0x00)
441         {
442             bCC708Enable = TRUE;
443         }
444     }
445 }
446 
447 ///////////////////////////////////////////////////////////////////////////////
448 /// Stop MVD CC FW Driver
449 /// @param u8CC608 \b IN
450 ///   - # TRUE for CC608 parser
451 ///   - # FALSE for CC708 parser
452 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_CM_DisableParsing(MS_U32 u32Id,MS_U8 u8CC608)453 void MDrv_CC_CM_DisableParsing(MS_U32 u32Id, MS_U8 u8CC608)
454 {
455     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
456     MS_U16 u16MVDCC_Temp1 = 0;
457     MVD_CmdArg mvdcmd;
458     memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
459     u16MVDCC_Temp1 = CCMVD_RINGBUFFER_LEN[u8CC608];
460     u16MVDCC_Temp1 = (u16MVDCC_Temp1 >> 3);
461 
462     mvdcmd.Arg1 = H_WORD(u16MVDCC_Temp1);
463     mvdcmd.Arg0 = L_WORD(u16MVDCC_Temp1);
464 
465     if (u8CC608==0)
466     {
467         u8ParsingStatus &= ~0x04;
468         bCC708Enable = FALSE;
469     }
470     else
471         u8ParsingStatus &= ~0x03;
472 
473     u8ParsingStatus &= 0x07;
474     mvdcmd.Arg3 = (MS_U8)u8CC608;
475     mvdcmd.Arg2 = (MS_U8)(u8ParsingStatus);
476     SET_DECNUM(mvdcmd, u8HalIdx);
477     if (HAL_MVD_MVDCommand(CMD_SET_CCTYPE_PARSING, &mvdcmd) != TRUE)
478     {
479         MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_SET_CCTYPE_PARSING));
480         MVDCC_EXHANDLE(printf("\nF:DisP"));
481     }
482 }
483 
484 ///////////////////////////////////////////////////////////////////////////////
485 /// Get Hardware Pointer of MVD CC Ring Buffer
486 /// Return value:: The HW Pointer Address of MVD CC Ring Buffer
487 /// @param u8CC608 \b IN
488 ///   - # TRUE for CC608 parser
489 ///   - # FALSE for CC708 parser
490 ///////////////////////////////////////////////////////////////////////////////
491 #if defined(CHIP_MONACO)
MDrv_CC_CM_GetMVDRB_HWAddr(MS_U32 u32Id,MS_U8 u8CC608)492 MS_U32 MDrv_CC_CM_GetMVDRB_HWAddr(MS_U32 u32Id, MS_U8 u8CC608)
493 {
494     MS_U32 u32MVDCC_Temp1 = 0;
495     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
496     MVD_CmdArg mvdcmd;
497     MS_U32 u32Miu1_base = 0;
498     MS_U32 u32Miu2_base = 0;
499     MS_U32 u32Miu3_base = 0;
500 
501     _miu_offset_to_phy(E_CHIP_MIU_1,0,u32Miu1_base);
502     _miu_offset_to_phy(E_CHIP_MIU_2,0,u32Miu2_base);
503     _miu_offset_to_phy(E_CHIP_MIU_3,0,u32Miu3_base);
504 
505     memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
506     mvdcmd.Arg3 = (MS_U8)u8CC608;
507     SET_DECNUM(mvdcmd, u8HalIdx);
508     if (HAL_MVD_MVDCommand(CMD_GET_CCBUF_HWADDR, &mvdcmd)== TRUE)
509     {
510         if (_IS_MSTAR_CC(u8CC608))
511         {
512             u32MVDCC_Temp1 = COMBU32(mvdcmd.Arg4, mvdcmd.Arg2, mvdcmd.Arg1, mvdcmd.Arg0);
513         }
514         else //u8CC608 is 2 or 3
515         {
516             u32MVDCC_Temp1 = COMBU32(mvdcmd.Arg3, mvdcmd.Arg2, mvdcmd.Arg1, mvdcmd.Arg0);
517         }
518         u32MVDCC_Temp1 = (u32MVDCC_Temp1 << 3);
519 
520         if(u8BufSelMiu == E_CHIP_MIU_0)  // SH@20110111, if CC buffer in MIU0, enable here
521         {
522             return (u32MVDCC_Temp1);
523         }
524         else if(u8BufSelMiu == E_CHIP_MIU_1)  // SH@20110111, if CC buffer in MIU0, enable here
525         {
526             return (u32MVDCC_Temp1|u32Miu1_base);
527         }
528         else if(u8BufSelMiu == E_CHIP_MIU_2)  // SH@20110111, if CC buffer in MIU0, enable here
529         {
530             return (u32MVDCC_Temp1|u32Miu2_base);
531         }
532         else if(u8BufSelMiu == E_CHIP_MIU_3)  // SH@20110111, if CC buffer in MIU0, enable here
533         {
534             return (u32MVDCC_Temp1|u32Miu3_base);
535         }
536     }
537     else
538     {
539         MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_GET_CCBUF_HWADDR));
540         MVDCC_EXHANDLE(printf("\nF:GHAV"));
541     }
542 
543     return 0xffffffff;
544 }
545 #else
MDrv_CC_CM_GetMVDRB_HWAddr(MS_U32 u32Id,MS_U8 u8CC608)546 MS_U32 MDrv_CC_CM_GetMVDRB_HWAddr(MS_U32 u32Id, MS_U8 u8CC608)
547 {
548     MS_U32 u32MVDCC_Temp1 = 0;
549     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
550     MVD_CmdArg mvdcmd;
551     memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
552     mvdcmd.Arg3 = (MS_U8)u8CC608;
553     SET_DECNUM(mvdcmd, u8HalIdx);
554     if (HAL_MVD_MVDCommand(CMD_GET_CCBUF_HWADDR, &mvdcmd)== TRUE)
555     {
556         if (_IS_MSTAR_CC(u8CC608))
557         {
558             u32MVDCC_Temp1 = COMBU32(mvdcmd.Arg4, mvdcmd.Arg2, mvdcmd.Arg1, mvdcmd.Arg0);
559         }
560         else //u8CC608 is 2 or 3
561         {
562             u32MVDCC_Temp1 = COMBU32(mvdcmd.Arg3, mvdcmd.Arg2, mvdcmd.Arg1, mvdcmd.Arg0);
563         }
564         u32MVDCC_Temp1 = (u32MVDCC_Temp1 << 3);
565         if(bBufMiu0)  // SH@20110111, if CC buffer in MIU0, enable here
566         {
567             return (u32MVDCC_Temp1);
568         }
569         else // CC buffer in MIU1
570         {
571             return (u32MVDCC_Temp1|MIU1_BASEADDR);
572         }
573     }
574     else
575     {
576         MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_GET_CCBUF_HWADDR));
577         MVDCC_EXHANDLE(printf("\nF:GHAV"));
578     }
579 
580     return 0xffffffff;
581 }
582 #endif
583 ///////////////////////////////////////////////////////////////////////////////
584 /// Get Overflow Status of MVD CC FW Driver
585 /// @param u8CC608 \b IN
586 ///   - # TRUE for CC608 parser
587 ///   - # FALSE for CC708 parser
588 /// Return value:: Overflow Status Flag
589 ////////////////////////////////////////////////////////////////////////////////
MDrv_CC_CM_GetOverflowStatus(MS_U32 u32Id,MS_U8 u8CC608)590 MS_U8 MDrv_CC_CM_GetOverflowStatus(MS_U32 u32Id, MS_U8 u8CC608)
591 {
592     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
593     MVD_CmdArg mvdcmd;
594     memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
595     mvdcmd.Arg3 = (MS_U8)u8CC608;
596     SET_DECNUM(mvdcmd, u8HalIdx);
597     if (HAL_MVD_MVDCommand(CMD_GET_OVERFLOW_STATUS, &mvdcmd) == TRUE)
598     {
599         if ((mvdcmd.Arg0& 0x01) == 0)
600             return (FALSE);
601         else
602             return (TRUE);
603     }
604     else
605     {
606         MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_GET_OVERFLOW_STATUS));
607         MVDCC_EXHANDLE(printf("\nF:GOV"));
608     }
609     return (FALSE);
610 }
611 
612 ///////////////////////////////////////////////////////////////////////////////
613 /// Set Software Pointer of MVD CC Ring Buffer
614 /// @param u32ReadAddress \b IN SW Pointer Address
615 /// @param u8CC608 \b IN
616 ///   - # TRUE for CC608 parser
617 ///   - # FALSE for CC708 parser
618 ///////////////////////////////////////////////////////////////////////////////
619 #if defined(CHIP_MONACO)
MDrv_CC_CM_SetMVDRB_SWAddr(MS_U32 u32Id,MS_U32 u32ReadAddress,MS_U8 u8CC608)620 void MDrv_CC_CM_SetMVDRB_SWAddr(MS_U32 u32Id, MS_U32 u32ReadAddress, MS_U8 u8CC608)
621 {
622     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
623     MS_U32 u32MVDCC_Temp1 = 0;
624     MVD_CmdArg mvdcmd;
625     MS_U32 u32Miu1_base = 0;
626     MS_U32 u32Miu2_base = 0;
627     MS_U32 u32Miu3_base = 0;
628 
629     _miu_offset_to_phy(E_CHIP_MIU_1,0,u32Miu1_base);
630     _miu_offset_to_phy(E_CHIP_MIU_2,0,u32Miu2_base);
631     _miu_offset_to_phy(E_CHIP_MIU_3,0,u32Miu3_base);
632 
633     memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
634 
635     u32SW_Address[u8CC608] = u32ReadAddress;
636 
637     if(u8BufSelMiu == E_CHIP_MIU_0)  // SH@20110111, if CC buffer in MIU0, enable here
638     {
639         u32MVDCC_Temp1 = (u32ReadAddress >> 3);
640     }
641     else if(u8BufSelMiu == E_CHIP_MIU_1)  // SH@20110111, if CC buffer in MIU0, enable here
642     {
643         u32MVDCC_Temp1 = u32ReadAddress - u32Miu1_base;
644         u32MVDCC_Temp1 = (u32MVDCC_Temp1 >> 3);
645     }
646     else if(u8BufSelMiu == E_CHIP_MIU_2)  // SH@20110111, if CC buffer in MIU0, enable here
647     {
648         u32MVDCC_Temp1 = u32ReadAddress - u32Miu2_base;
649         u32MVDCC_Temp1 = (u32MVDCC_Temp1 >> 3);
650     }
651     else if(u8BufSelMiu == E_CHIP_MIU_3)  // SH@20110111, if CC buffer in MIU0, enable here
652     {
653         u32MVDCC_Temp1 = u32ReadAddress - u32Miu3_base;
654         u32MVDCC_Temp1 = (u32MVDCC_Temp1 >> 3);
655     }
656 
657     mvdcmd.Arg3 = (MS_U8)u8CC608;
658     mvdcmd.Arg2 = L_DWORD(u32MVDCC_Temp1);
659     mvdcmd.Arg1 = H_WORD(u32MVDCC_Temp1);
660     mvdcmd.Arg0 = L_WORD(u32MVDCC_Temp1);
661     SET_DECNUM(mvdcmd, u8HalIdx);
662     if (HAL_MVD_MVDCommand(CMD_SET_CCBUF_SWADDR, &mvdcmd) != TRUE)
663     {
664         MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_SET_CCBUF_SWADDR));
665         MVDCC_EXHANDLE(printf("\nF:SSA"));
666     }
667 }
668 #else
MDrv_CC_CM_SetMVDRB_SWAddr(MS_U32 u32Id,MS_U32 u32ReadAddress,MS_U8 u8CC608)669 void MDrv_CC_CM_SetMVDRB_SWAddr(MS_U32 u32Id, MS_U32 u32ReadAddress, MS_U8 u8CC608)
670 {
671     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
672     MS_U32 u32MVDCC_Temp1 = 0;
673     MVD_CmdArg mvdcmd;
674     memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
675 
676     u32SW_Address[u8CC608] = u32ReadAddress;
677 
678     if(bBufMiu0)  // SH@20110111, if CC buffer in MIU0, enable here
679     {
680         u32MVDCC_Temp1 = (u32ReadAddress >> 3);
681     }
682     else // CC buffer in MIU1
683     {
684         u32MVDCC_Temp1 = u32ReadAddress - MIU1_BASEADDR;
685         u32MVDCC_Temp1 = (u32MVDCC_Temp1 >> 3);
686     }
687 
688     mvdcmd.Arg3 = (MS_U8)u8CC608;
689     mvdcmd.Arg2 = L_DWORD(u32MVDCC_Temp1);
690     mvdcmd.Arg1 = H_WORD(u32MVDCC_Temp1);
691     mvdcmd.Arg0 = L_WORD(u32MVDCC_Temp1);
692     SET_DECNUM(mvdcmd, u8HalIdx);
693     if (HAL_MVD_MVDCommand(CMD_SET_CCBUF_SWADDR, &mvdcmd) != TRUE)
694     {
695         MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_SET_CCBUF_SWADDR));
696         MVDCC_EXHANDLE(printf("\nF:SSA"));
697     }
698 }
699 #endif
700 
701 #if defined(CHIP_MONACO)
702 #else
703 #define __Offset2PA(x)      ((MVD_ON_MIU1)?((x)|MIU1_BASEADDR):(x))
704 #endif
705 ///////////////////////////////////////////////////////////////////////////////
706 /// Get HW Pointer Address of MVD CC FW Driver
707 /// @param u8CC608 \b IN
708 ///   - # TRUE for CC608 parser
709 ///   - # FALSE for CC708 parser
710 /// Return value:: HW Pointer Address
711 ///////////////////////////////////////////////////////////////////////////////
712 
713 #if defined(CHIP_MONACO)
MDrv_CC_PM_GetMVDRB_WriteAddr(MS_U32 u32Id,MS_U8 u8CC608)714 MS_U32 MDrv_CC_PM_GetMVDRB_WriteAddr(MS_U32 u32Id, MS_U8 u8CC608)
715 {
716     MS_U32 u32Miu1_base = 0;
717     MS_U32 u32Miu2_base = 0;
718     MS_U32 u32Miu3_base = 0;
719 
720     _miu_offset_to_phy(E_CHIP_MIU_1,0,u32Miu1_base);
721     _miu_offset_to_phy(E_CHIP_MIU_2,0,u32Miu2_base);
722     _miu_offset_to_phy(E_CHIP_MIU_3,0,u32Miu3_base);
723 
724     u32HW_Address[u8CC608] = MDrv_CC_CM_GetMVDRB_HWAddr(u32Id, u8CC608);
725 
726     if(u8BufSelMiu == E_CHIP_MIU_0)  // SH@20110111, if CC buffer in MIU0, enable here
727     {
728         if(MVD_ON_MIU == E_CHIP_MIU_0)
729         {
730             return (MS_U32)(u32HW_Address[u8CC608]);
731         }
732         else if(MVD_ON_MIU == E_CHIP_MIU_1)
733         {
734             return (MS_U32)(u32HW_Address[u8CC608]|u32Miu1_base);
735         }
736         else if(MVD_ON_MIU == E_CHIP_MIU_2)
737         {
738             return (MS_U32)(u32HW_Address[u8CC608]|u32Miu2_base);
739         }
740         else if(MVD_ON_MIU == E_CHIP_MIU_3)
741         {
742             return (MS_U32)(u32HW_Address[u8CC608]|u32Miu3_base);
743         }
744         else
745         {
746             return 0;
747         }
748     }
749     else if(u8BufSelMiu == E_CHIP_MIU_1)  // SH@20110111, if CC buffer in MIU0, enable here
750     {
751         if(MVD_ON_MIU == E_CHIP_MIU_0)
752         {
753             return (MS_U32)(u32HW_Address[u8CC608]);
754         }
755         else if(MVD_ON_MIU == E_CHIP_MIU_1)
756         {
757             return (MS_U32)(u32HW_Address[u8CC608]);
758         }
759         else if(MVD_ON_MIU == E_CHIP_MIU_2)
760         {
761             return (MS_U32)(u32HW_Address[u8CC608]|u32Miu2_base);
762         }
763         else if(MVD_ON_MIU == E_CHIP_MIU_3)
764         {
765             return (MS_U32)(u32HW_Address[u8CC608]|u32Miu3_base);
766         }
767         else
768         {
769             return 0;
770         }
771     }
772     else if(u8BufSelMiu == E_CHIP_MIU_2)  // SH@20110111, if CC buffer in MIU0, enable here
773     {
774         if(MVD_ON_MIU == E_CHIP_MIU_0)
775         {
776             return (MS_U32)(u32HW_Address[u8CC608]);
777         }
778         else if(MVD_ON_MIU == E_CHIP_MIU_1)
779         {
780             return (MS_U32)(u32HW_Address[u8CC608]|u32Miu1_base);
781         }
782         else if(MVD_ON_MIU == E_CHIP_MIU_2)
783         {
784             return (MS_U32)(u32HW_Address[u8CC608]);
785         }
786         else if(MVD_ON_MIU == E_CHIP_MIU_3)
787         {
788             return (MS_U32)(u32HW_Address[u8CC608]|u32Miu3_base);
789         }
790         else
791         {
792             return 0;
793         }
794     }
795     else if(u8BufSelMiu == E_CHIP_MIU_3)  // SH@20110111, if CC buffer in MIU0, enable here
796     {
797         if(MVD_ON_MIU == E_CHIP_MIU_0)
798         {
799             return (MS_U32)(u32HW_Address[u8CC608]);
800         }
801         else if(MVD_ON_MIU == E_CHIP_MIU_1)
802         {
803             return (MS_U32)(u32HW_Address[u8CC608]|u32Miu1_base);
804         }
805         else if(MVD_ON_MIU == E_CHIP_MIU_2)
806         {
807             return (MS_U32)(u32HW_Address[u8CC608]|u32Miu2_base);
808         }
809         else if(MVD_ON_MIU == E_CHIP_MIU_3)
810         {
811             return (MS_U32)(u32HW_Address[u8CC608]);
812         }
813         else
814         {
815             return 0;
816         }
817     }
818     else
819     {
820         return 0;
821     }
822 }
823 #else
MDrv_CC_PM_GetMVDRB_WriteAddr(MS_U32 u32Id,MS_U8 u8CC608)824 MS_U32 MDrv_CC_PM_GetMVDRB_WriteAddr(MS_U32 u32Id, MS_U8 u8CC608)
825 {
826     u32HW_Address[u8CC608] = MDrv_CC_CM_GetMVDRB_HWAddr(u32Id, u8CC608);
827 
828     if(bBufMiu0)
829     {
830         return (MS_U32)__Offset2PA(u32HW_Address[u8CC608]);
831     }
832     else
833     {
834         return (MS_U32)(u32HW_Address[u8CC608]);
835     }
836 }
837 #endif
838 ///////////////////////////////////////////////////////////////////////////////
839 /// Get SW Pointer Address of MVD CC FW Driver
840 /// @param u8CC608 \b IN
841 ///   - # TRUE for CC608 parser
842 ///   - # FALSE for CC708 parser
843 /// Return value:: SW Pointer Address
844 ///////////////////////////////////////////////////////////////////////////////
845 
846 #if defined(CHIP_MONACO)
MDrv_CC_PM_GetMVDRB_ReadAddr(MS_U32 u32Id,MS_U8 u8CC608)847 MS_U32 MDrv_CC_PM_GetMVDRB_ReadAddr(MS_U32 u32Id, MS_U8 u8CC608)
848 {
849     MS_U32 u32Miu1_base = 0;
850     MS_U32 u32Miu2_base = 0;
851     MS_U32 u32Miu3_base = 0;
852 
853     _miu_offset_to_phy(E_CHIP_MIU_1,0,u32Miu1_base);
854     _miu_offset_to_phy(E_CHIP_MIU_2,0,u32Miu2_base);
855     _miu_offset_to_phy(E_CHIP_MIU_3,0,u32Miu3_base);
856 
857     if(u8BufSelMiu == E_CHIP_MIU_0)  // SH@20110111, if CC buffer in MIU0, enable here
858     {
859         if(MVD_ON_MIU == E_CHIP_MIU_0)
860         {
861             return (MS_U32)(u32SW_Address[u8CC608]);
862         }
863         else if(MVD_ON_MIU == E_CHIP_MIU_1)
864         {
865             return (MS_U32)(u32SW_Address[u8CC608]|u32Miu1_base);
866         }
867         else if(MVD_ON_MIU == E_CHIP_MIU_2)
868         {
869             return (MS_U32)(u32SW_Address[u8CC608]|u32Miu2_base);
870         }
871         else if(MVD_ON_MIU == E_CHIP_MIU_3)
872         {
873             return (MS_U32)(u32SW_Address[u8CC608]|u32Miu3_base);
874         }
875         else
876         {
877             return 0;
878         }
879     }
880     else if(u8BufSelMiu == E_CHIP_MIU_1)  // SH@20110111, if CC buffer in MIU0, enable here
881     {
882         if(MVD_ON_MIU == E_CHIP_MIU_0)
883         {
884             return (MS_U32)(u32SW_Address[u8CC608]);
885         }
886         else if(MVD_ON_MIU == E_CHIP_MIU_1)
887         {
888             return (MS_U32)(u32SW_Address[u8CC608]);
889         }
890         else if(MVD_ON_MIU == E_CHIP_MIU_2)
891         {
892             return (MS_U32)(u32SW_Address[u8CC608]|u32Miu2_base);
893         }
894         else if(MVD_ON_MIU == E_CHIP_MIU_3)
895         {
896             return (MS_U32)(u32SW_Address[u8CC608]|u32Miu3_base);
897         }
898         else
899         {
900             return 0;
901         }
902     }
903     else if(u8BufSelMiu == E_CHIP_MIU_2)  // SH@20110111, if CC buffer in MIU0, enable here
904     {
905         if(MVD_ON_MIU == E_CHIP_MIU_0)
906         {
907             return (MS_U32)(u32SW_Address[u8CC608]);
908         }
909         else if(MVD_ON_MIU == E_CHIP_MIU_1)
910         {
911             return (MS_U32)(u32SW_Address[u8CC608]|u32Miu1_base);
912         }
913         else if(MVD_ON_MIU == E_CHIP_MIU_2)
914         {
915             return (MS_U32)(u32SW_Address[u8CC608]);
916         }
917         else if(MVD_ON_MIU == E_CHIP_MIU_3)
918         {
919             return (MS_U32)(u32SW_Address[u8CC608]|u32Miu3_base);
920         }
921         else
922         {
923             return 0;
924         }
925     }
926     else if(u8BufSelMiu == E_CHIP_MIU_3)  // SH@20110111, if CC buffer in MIU0, enable here
927     {
928         if(MVD_ON_MIU == E_CHIP_MIU_0)
929         {
930             return (MS_U32)(u32SW_Address[u8CC608]);
931         }
932         else if(MVD_ON_MIU == E_CHIP_MIU_1)
933         {
934             return (MS_U32)(u32SW_Address[u8CC608]|u32Miu1_base);
935         }
936         else if(MVD_ON_MIU == E_CHIP_MIU_2)
937         {
938             return (MS_U32)(u32SW_Address[u8CC608]|u32Miu2_base);
939         }
940         else if(MVD_ON_MIU == E_CHIP_MIU_3)
941         {
942             return (MS_U32)(u32SW_Address[u8CC608]);
943         }
944         else
945         {
946             return 0;
947         }
948 
949     }
950     else
951     {
952         return 0;
953     }
954 }
955 #else
MDrv_CC_PM_GetMVDRB_ReadAddr(MS_U32 u32Id,MS_U8 u8CC608)956 MS_U32 MDrv_CC_PM_GetMVDRB_ReadAddr(MS_U32 u32Id, MS_U8 u8CC608)
957 {
958     if(bBufMiu0)
959     {
960         return (MS_U32)__Offset2PA(u32SW_Address[u8CC608]);
961     }
962     else
963     {
964         return (MS_U32)(u32SW_Address[u8CC608]);
965     }
966 }
967 #endif
968 ///////////////////////////////////////////////////////////////////////////////
969 /// Set Software Pointer of MVD CC Ring Buffer to MVD CC FW Driver
970 /// @param u32EachPacketSize \b IN SW Pointer Address
971 /// @param u8CC608 \b IN
972 ///   - # TRUE for CC608 parser
973 ///   - # FALSE for CC708 parser
974 ///////////////////////////////////////////////////////////////////////////////
975 #if defined(CHIP_MONACO)
MDrv_CC_PM_SetMVDRB_ReadAddr(MS_U32 u32Id,MS_U32 u32EachPacketSize,MS_U8 u8CC608)976 void MDrv_CC_PM_SetMVDRB_ReadAddr(MS_U32 u32Id, MS_U32 u32EachPacketSize, MS_U8 u8CC608)
977 {
978     MS_U32 u32MVDCC_Temp1 = 0;
979     MS_U32 u32ParsedDataSize;
980     MS_U32 u32Miu1_base = 0;
981     MS_U32 u32Miu2_base = 0;
982     MS_U32 u32Miu3_base = 0;
983 
984     _miu_offset_to_phy(E_CHIP_MIU_1,0,u32Miu1_base);
985     _miu_offset_to_phy(E_CHIP_MIU_2,0,u32Miu2_base);
986     _miu_offset_to_phy(E_CHIP_MIU_3,0,u32Miu3_base);
987 
988     // Get the Parsed Data Size
989     if ((u32EachPacketSize % MVD_CCRB_PACKET_LENGTH) != 0)
990     {
991         u32ParsedDataSize = MVD_CCRB_PACKET_LENGTH * ((u32EachPacketSize / MVD_CCRB_PACKET_LENGTH)+1);
992     }
993     else
994     {
995         u32ParsedDataSize = u32EachPacketSize;
996     }
997 
998     // Add the SW Address
999     if(MVD_ON_MIU == E_CHIP_MIU_0)
1000     {
1001         if(u8BufSelMiu == E_CHIP_MIU_0)  // SH@20110111, if CC buffer in MIU0, enable here
1002         {
1003             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] ;//& (MIU1_BASEADDR - 1); // to Phy address
1004         }
1005         else if(u8BufSelMiu == E_CHIP_MIU_1)  // SH@20110111, if CC buffer in MIU0, enable here
1006         {
1007             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] ;//& (MIU1_BASEADDR - 1); // to Phy address
1008         }
1009         else if(u8BufSelMiu == E_CHIP_MIU_2)  // SH@20110111, if CC buffer in MIU0, enable here
1010         {
1011             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] ;//& (MIU1_BASEADDR - 1); // to Phy address
1012         }
1013         else if(u8BufSelMiu == E_CHIP_MIU_3)  // SH@20110111, if CC buffer in MIU0, enable here
1014         {
1015             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] ;//& (MIU1_BASEADDR - 1); // to Phy address
1016         }
1017     }
1018     else if(MVD_ON_MIU == E_CHIP_MIU_1)
1019     {
1020         if(u8BufSelMiu == E_CHIP_MIU_0)  // SH@20110111, if CC buffer in MIU0, enable here
1021         {
1022             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] & (u32Miu1_base - 1); // to Phy address
1023         }
1024         else if(u8BufSelMiu == E_CHIP_MIU_1)  // SH@20110111, if CC buffer in MIU0, enable here
1025         {
1026             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] ;//& (MIU1_BASEADDR - 1); // to Phy address
1027         }
1028         else if(u8BufSelMiu == E_CHIP_MIU_2)  // SH@20110111, if CC buffer in MIU0, enable here
1029         {
1030             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] & (u32Miu1_base - 1); // to Phy address
1031         }
1032         else if(u8BufSelMiu == E_CHIP_MIU_3)  // SH@20110111, if CC buffer in MIU0, enable here
1033         {
1034             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] & (u32Miu1_base - 1); // to Phy address
1035         }
1036     }
1037     else if(MVD_ON_MIU == E_CHIP_MIU_2)
1038     {
1039         if(u8BufSelMiu == E_CHIP_MIU_0)  // SH@20110111, if CC buffer in MIU0, enable here
1040         {
1041             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] & (u32Miu2_base - 1); // to Phy address
1042         }
1043         else if(u8BufSelMiu == E_CHIP_MIU_1)  // SH@20110111, if CC buffer in MIU0, enable here
1044         {
1045             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] & (u32Miu2_base - 1); // to Phy address
1046         }
1047         else if(u8BufSelMiu == E_CHIP_MIU_2)  // SH@20110111, if CC buffer in MIU0, enable here
1048         {
1049             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] ;//& (MIU1_BASEADDR - 1); // to Phy address
1050         }
1051         else if(u8BufSelMiu == E_CHIP_MIU_3)  // SH@20110111, if CC buffer in MIU0, enable here
1052         {
1053             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] & (u32Miu2_base - 1); // to Phy address
1054         }
1055     }
1056     else if(MVD_ON_MIU == E_CHIP_MIU_3)
1057     {
1058         if(u8BufSelMiu == E_CHIP_MIU_0)  // SH@20110111, if CC buffer in MIU0, enable here
1059         {
1060             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] & (u32Miu3_base - 1); // to Phy address
1061         }
1062         else if(u8BufSelMiu == E_CHIP_MIU_1)  // SH@20110111, if CC buffer in MIU0, enable here
1063         {
1064             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] & (u32Miu3_base - 1); // to Phy address
1065         }
1066         else if(u8BufSelMiu == E_CHIP_MIU_2)  // SH@20110111, if CC buffer in MIU0, enable here
1067         {
1068             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] & (u32Miu3_base - 1); // to Phy address
1069         }
1070         else if(u8BufSelMiu == E_CHIP_MIU_3)  // SH@20110111, if CC buffer in MIU0, enable here
1071         {
1072             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] ;//& (MIU1_BASEADDR - 1); // to Phy address
1073         }
1074     }
1075 
1076     if ((u32SW_Address[u8CC608] + u32ParsedDataSize) < (u32MVDCC_Temp1 + CCMVD_RINGBUFFER_LEN[u8CC608]))
1077     {
1078         u32SW_Address[u8CC608] += u32ParsedDataSize;
1079     }
1080     else
1081     {
1082         u32SW_Address[u8CC608] = (u32ParsedDataSize + u32SW_Address[u8CC608] - CCMVD_RINGBUFFER_LEN[u8CC608]);
1083     }
1084 
1085 #if 0
1086     if(u32HW_Address - u32SW_Address >= 512)
1087     {
1088         printf("Sync:0x%08Lx", u32SW_Address);
1089         u32SW_Address = u32HW_Address;
1090         printf("-->0x%08Lx\n", u32SW_Address);
1091     }
1092 #endif
1093 
1094     MDrv_CC_CM_SetMVDRB_SWAddr(u32Id, u32SW_Address[u8CC608], u8CC608);
1095 }
1096 #else
MDrv_CC_PM_SetMVDRB_ReadAddr(MS_U32 u32Id,MS_U32 u32EachPacketSize,MS_U8 u8CC608)1097 void MDrv_CC_PM_SetMVDRB_ReadAddr(MS_U32 u32Id, MS_U32 u32EachPacketSize, MS_U8 u8CC608)
1098 {
1099     MS_U32 u32MVDCC_Temp1 = 0;
1100     MS_U32 u32ParsedDataSize;
1101 
1102     // Get the Parsed Data Size
1103     if ((u32EachPacketSize % MVD_CCRB_PACKET_LENGTH) != 0)
1104     {
1105         u32ParsedDataSize = MVD_CCRB_PACKET_LENGTH * ((u32EachPacketSize / MVD_CCRB_PACKET_LENGTH)+1);
1106     }
1107     else
1108     {
1109         u32ParsedDataSize = u32EachPacketSize;
1110     }
1111 
1112     // Add the SW Address
1113     if(MVD_ON_MIU1)
1114     {
1115         if(bBufMiu0)  // SH@20110111, if CC buffer in MIU0, enable here
1116         {
1117             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] & (MIU1_BASEADDR - 1); // to Phy address
1118         }
1119         else // CC buffer in MIU1
1120         {
1121             u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] ;//& (MIU1_BASEADDR - 1); // to Phy address
1122         }
1123     }
1124     else
1125     {
1126         u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608];
1127     }
1128 
1129     if ((u32SW_Address[u8CC608] + u32ParsedDataSize) < (u32MVDCC_Temp1 + CCMVD_RINGBUFFER_LEN[u8CC608]))
1130     {
1131         u32SW_Address[u8CC608] += u32ParsedDataSize;
1132     }
1133     else
1134     {
1135         u32SW_Address[u8CC608] = (u32ParsedDataSize + u32SW_Address[u8CC608] - CCMVD_RINGBUFFER_LEN[u8CC608]);
1136     }
1137 
1138 #if 0
1139     if(u32HW_Address - u32SW_Address >= 512)
1140     {
1141         printf("Sync:0x%08Lx", u32SW_Address);
1142         u32SW_Address = u32HW_Address;
1143         printf("-->0x%08Lx\n", u32SW_Address);
1144     }
1145 #endif
1146 
1147     MDrv_CC_CM_SetMVDRB_SWAddr(u32Id, u32SW_Address[u8CC608], u8CC608);
1148 }
1149 #endif
MDrv_CC_CM_GetInfo(MS_U32 u32Id,MS_U32 selector,MS_U8 type,MS_U32 * p1,MS_U32 * p2)1150 void MDrv_CC_CM_GetInfo(MS_U32 u32Id, MS_U32 selector, MS_U8 type, MS_U32 *p1, MS_U32 *p2)
1151 {
1152     // Functionality select
1153     switch (selector)
1154     {
1155         case CC_SELECTOR_708_SW:
1156             *p1 = (MS_U32)bCC708Enable;
1157             break;
1158 
1159 #if defined( MSOS_TYPE_LINUX )
1160         case CC_SELECTOR_CCMVD_RINGBUFFER:
1161             *p1 = (MS_U32)CCMVD_RINGBUFFER_START_ADR[type];
1162             *p2 = (MS_U32)CCMVD_RINGBUFFER_LEN[type];
1163             break;
1164 #endif
1165 
1166         default:
1167             *p1 = *p2 = 0;
1168             break;
1169     }
1170 }
1171 
MDrv_CC_CM_Get708Sw(MS_U32 u32Id)1172 MS_BOOL MDrv_CC_CM_Get708Sw(MS_U32 u32Id)
1173 {
1174     return bCC708Enable;
1175 }
1176 
MDrv_CC_CM_IsMvdRstDone(MS_U32 u32Id,MS_U8 type)1177 MS_BOOL MDrv_CC_CM_IsMvdRstDone(MS_U32 u32Id, MS_U8 type)
1178 {
1179     MS_BOOL bRet = FALSE;
1180     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1181 
1182     if(type == E_CC_MVD_TYPE_608)   // CC608
1183     {
1184         if(!HAL_MVD_IsCmdFinished(u8HalIdx, MVD_HANDSHAKE_RST_CC608))
1185         {
1186             bRet = TRUE;
1187         }
1188     }
1189     else            // CC708
1190     {
1191         if(!HAL_MVD_IsCmdFinished(u8HalIdx, MVD_HANDSHAKE_RST_CC708))
1192         {
1193             bRet = TRUE;
1194         }
1195     }
1196 
1197     return bRet;
1198 }
1199 
1200 
1201 ///////////////////////////////////////////////////////////////////////////////
1202 /// Enhance CC info mode, only support cc608
1203 /// @param bEnable \b IN
1204 ///   - # TRUE for enhance to dump the pts/tmp_ref info
1205 ///   - # FALSE for original
1206 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_InfoEnhanceMode(MS_U32 u32Id,MS_BOOL bEnable)1207 MS_BOOL MDrv_CC_InfoEnhanceMode(MS_U32 u32Id,MS_BOOL bEnable)
1208 {
1209     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1210     MS_U8 u8Type = E_CC_MVD_TYPE_608;
1211     MVD_CmdArg mvdcmd;
1212     memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
1213 
1214     mvdcmd.Arg0 = bEnable;
1215     mvdcmd.Arg3 = u8Type;
1216     SET_DECNUM(mvdcmd, u8HalIdx);
1217 
1218     if (HAL_MVD_MVDCommand(CMD_EN_CC_INFO_ENHANCE, &mvdcmd) != TRUE)
1219     {
1220         MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_EN_CC_INFO_ENHANCE));
1221         return FALSE;
1222     }
1223 
1224     return TRUE;
1225 }
1226 #endif
1227