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.h"
112
113 // Internal Definition
114 #include "regMVD.h"
115 #include "halMVD.h"
116 #include "drvmvd_cc.h"
117
118 #include "string.h"
119
120 //--------------------------------------------------------------------------------------------------
121 // Local Defines
122 //--------------------------------------------------------------------------------------------------
123 #define MVDCC_EXHANDLE(y) y
124
125 //----------------------------------------------------------------------------
126 /* MVD Command register - Command Definitions */
127 //----------------------------------------------------------------------------
128 #define CMD_SET_CCBUF_STARTHWADDR CMD_USER_BUF_START
129 #define CMD_SET_CCBUF_TOTALSIZE CMD_USER_BUF_SIZE
130 #define CMD_SET_CCTYPE_PARSING CMD_USER_BUF_SIZE
131 #define CMD_GET_CCBUF_HWADDR CMD_RD_USER_WP
132 #define CMD_GET_CCBUF_WRAPCOUNT CMD_RD_USER_WP
133
134 #define CMD_SET_CCBUF_SWADDR CMD_WD_USER_RP
135 #define CMD_GET_CCBUF_PACKETCOUNT CMD_RD_CC_PKTCNT
136 #define CMD_GET_OVERFLOW_STATUS CMD_RD_CC_OV
137
138 void MDrv_CC_CM_SetMVDRB_SWAddr(MS_U32 u32ReadAddress, MS_U8 u8CC608);
139 MS_U32 MDrv_CC_CM_GetMVDRB_HWAddr(MS_U8 u8CC608);
140
141 //******************************************************************************/
142 //* Local definition
143 //******************************************************************************/
144 #define MVD_READY_TEST_COUNT 10000
145 #define MVD_CCRB_PACKET_LENGTH 8
146
147 //******************************************************************************/
148 //* Declaring Variable
149 //******************************************************************************/
150 MS_U32 CCMVD_RINGBUFFER_START_ADR[2];
151 MS_U32 CCMVD_RINGBUFFER_LEN[2];
152
153 static MS_U32 volatile u32SW_Address[2], u32HW_Address[2];
154 static MS_U8 u8ParsingStatus = 0xff;
155
156 static MS_BOOL bCC708Enable; //fixme
157
158 // SH@20110111, Fixed the issues that move CC buffer from MIU0 to MIU1
159 // 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
160 static MS_BOOL bBufMiu0 = 0xff;
161
162 extern MVD_MEMCfg stMemCfg;
163
164 #define MIU1_BASEADDR stMemCfg.u32Miu1BaseAddr
165 #define MVD_ON_MIU1 (stMemCfg.bFWMiuSel == MIU_SEL_1)
166 #define _IS_MSTAR_CC(x) ((0==(x)) || (1==(x)))
167
168
169 ///////////////////////////////////////////////////////////////////////////////
170 /// Closed Caption Driver Initialization
171 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_Init(void)172 void MDrv_CC_Init(void)
173 {
174 if (u8ParsingStatus == 0xff)
175 u8ParsingStatus = 0x00;
176 }
177
178 ///////////////////////////////////////////////////////////////////////////////
179 /// Set MVD Ring Buffer's Address
180 /// @param u32StartAddress \b IN Ring Buffer's Address
181 /// @param u8CC608 \b IN
182 /// - # TRUE for CC608 parser
183 /// - # FALSE for CC708 parser
184 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_CM_SetMVDRB_HWAddr(MS_U32 u32StartAddress,MS_U8 u8CC608)185 void MDrv_CC_CM_SetMVDRB_HWAddr(MS_U32 u32StartAddress, MS_U8 u8CC608)
186 {
187 MS_U32 u32MVDCC_Temp1 = 0;
188 MVD_CmdArg mvdcmd;
189 memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
190
191 // SH@20110111, get the first HW buffer to determine the MIU0 or MIU1 for CC buffer. Only once
192 if(bBufMiu0 == 0xff)
193 {
194 if((u32StartAddress&MIU1_BASEADDR) == MIU1_BASEADDR)
195 {
196 bBufMiu0 = false;
197 }
198 else
199 {
200 bBufMiu0 = true;
201 }
202 }
203
204 if(MVD_ON_MIU1) // SH@20110111, mvd code binary in MIU1
205 {
206 if(bBufMiu0) // SH@20110111, if CC buffer in MIU0, enable here
207 {
208 CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress | MIU1_BASEADDR;
209 }
210 else // CC buffer in MIU1
211 {
212 CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress;
213 }
214 }
215 else
216 {
217 CCMVD_RINGBUFFER_START_ADR[u8CC608] = u32StartAddress;
218 }
219
220 if(bBufMiu0)
221 {
222 u32MVDCC_Temp1 = (u32StartAddress >> 3);
223 }
224 else // CC buffer in MIU1
225 {
226 u32MVDCC_Temp1 = u32StartAddress - MIU1_BASEADDR;
227 u32MVDCC_Temp1 = (u32MVDCC_Temp1 >> 3);
228 }
229
230 mvdcmd.Arg4 = H_DWORD(u32MVDCC_Temp1);
231 mvdcmd.Arg3 = (MS_U8)u8CC608;
232 mvdcmd.Arg2 = L_DWORD(u32MVDCC_Temp1);
233 mvdcmd.Arg1 = H_WORD(u32MVDCC_Temp1);
234 mvdcmd.Arg0 = L_WORD(u32MVDCC_Temp1);
235
236 if (HAL_MVD_MVDCommand(CMD_SET_CCBUF_STARTHWADDR, &mvdcmd) == TRUE)
237 {
238 u32SW_Address[u8CC608] = u32StartAddress;
239 u32HW_Address[u8CC608] = u32StartAddress;
240 MDrv_CC_CM_SetMVDRB_SWAddr(u32StartAddress, u8CC608);
241 }
242 else
243 {
244 MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_SET_CCBUF_STARTHWADDR));
245 MVDCC_EXHANDLE(printf("\nF:S-HA"));
246 }
247 }
248
249 ///////////////////////////////////////////////////////////////////////////////
250 /// Set MVD Ring Buffer's SW Address as HW Address
251 /// @param u8CC608 \b IN
252 /// - # TRUE for CC608 parser
253 /// - # FALSE for CC708 parser
254 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_CM_SyncMVDRB_SWAddr2HWAddr(MS_U8 u8CC608)255 void MDrv_CC_CM_SyncMVDRB_SWAddr2HWAddr(MS_U8 u8CC608)
256 {
257 MDrv_CC_CM_SetMVDRB_SWAddr(u32HW_Address[u8CC608], u8CC608);
258 }
259
260 ///////////////////////////////////////////////////////////////////////////////
261 /// Set CC Type to MVD CC FW Driver
262 /// @param u8Operation \b IN Digital Closed Caption Type
263 /// @param u16BufferSize \b IN buffer size of the given hardware parser
264 /// @param u8CC608 \b IN
265 /// - # TRUE for CC608 parser
266 /// - # FALSE for CC708 parser
267 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_CM_SetParsingType(MS_U8 u8Operation,MS_U16 u16BufferSize,MS_U8 u8CC608)268 void MDrv_CC_CM_SetParsingType(MS_U8 u8Operation, MS_U16 u16BufferSize, MS_U8 u8CC608)
269 {
270 MS_U16 u16MVDCC_Temp1 = 0;
271 MVD_CmdArg mvdcmd;
272 memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
273 CCMVD_RINGBUFFER_LEN[u8CC608] = u16BufferSize;
274 u16MVDCC_Temp1 = (u16BufferSize >> 3);
275
276 u8ParsingStatus |= u8Operation;
277 u8ParsingStatus &= 0x07;
278 mvdcmd.Arg1 = H_WORD(u16MVDCC_Temp1);
279 mvdcmd.Arg0 = L_WORD(u16MVDCC_Temp1);
280 mvdcmd.Arg2 = (MS_U8)(u8ParsingStatus);
281 mvdcmd.Arg3 = (MS_U8)u8CC608;
282
283 if (HAL_MVD_MVDCommand(CMD_SET_CCTYPE_PARSING, &mvdcmd) != TRUE)
284 {
285 MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_SET_CCTYPE_PARSING));
286 MVDCC_EXHANDLE(printf("\nF:SPT"));
287 }
288 else
289 {
290 if (u8CC608==0x00)
291 {
292 bCC708Enable = TRUE;
293 }
294 }
295 }
296
297 ///////////////////////////////////////////////////////////////////////////////
298 /// Stop MVD CC FW Driver
299 /// @param u8CC608 \b IN
300 /// - # TRUE for CC608 parser
301 /// - # FALSE for CC708 parser
302 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_CM_DisableParsing(MS_U8 u8CC608)303 void MDrv_CC_CM_DisableParsing(MS_U8 u8CC608)
304 {
305 MS_U16 u16MVDCC_Temp1 = 0;
306 MVD_CmdArg mvdcmd;
307 memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
308 u16MVDCC_Temp1 = CCMVD_RINGBUFFER_LEN[u8CC608];
309 u16MVDCC_Temp1 = (u16MVDCC_Temp1 >> 3);
310
311 mvdcmd.Arg1 = H_WORD(u16MVDCC_Temp1);
312 mvdcmd.Arg0 = L_WORD(u16MVDCC_Temp1);
313
314 if (u8CC608==0)
315 {
316 u8ParsingStatus &= ~0x04;
317 bCC708Enable = FALSE;
318 }
319 else
320 u8ParsingStatus &= ~0x03;
321
322 u8ParsingStatus &= 0x07;
323 mvdcmd.Arg3 = (MS_U8)u8CC608;
324 mvdcmd.Arg2 = (MS_U8)(u8ParsingStatus);
325
326 if (HAL_MVD_MVDCommand(CMD_SET_CCTYPE_PARSING, &mvdcmd) != TRUE)
327 {
328 MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_SET_CCTYPE_PARSING));
329 MVDCC_EXHANDLE(printf("\nF:DisP"));
330 }
331 }
332
333 ///////////////////////////////////////////////////////////////////////////////
334 /// Get Hardware Pointer of MVD CC Ring Buffer
335 /// Return value:: The HW Pointer Address of MVD CC Ring Buffer
336 /// @param u8CC608 \b IN
337 /// - # TRUE for CC608 parser
338 /// - # FALSE for CC708 parser
339 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_CM_GetMVDRB_HWAddr(MS_U8 u8CC608)340 MS_U32 MDrv_CC_CM_GetMVDRB_HWAddr(MS_U8 u8CC608)
341 {
342 MS_U32 u32MVDCC_Temp1 = 0;
343 MVD_CmdArg mvdcmd;
344 memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
345 mvdcmd.Arg3 = (MS_U8)u8CC608;
346 if (HAL_MVD_MVDCommand(CMD_GET_CCBUF_HWADDR, &mvdcmd)== TRUE)
347 {
348 if (_IS_MSTAR_CC(u8CC608))
349 {
350 u32MVDCC_Temp1 = COMBU32(mvdcmd.Arg4, mvdcmd.Arg2, mvdcmd.Arg1, mvdcmd.Arg0);
351 }
352 else //u8CC608 is 2 or 3
353 {
354 u32MVDCC_Temp1 = COMBU32(mvdcmd.Arg3, mvdcmd.Arg2, mvdcmd.Arg1, mvdcmd.Arg0);
355 }
356 u32MVDCC_Temp1 = (u32MVDCC_Temp1 << 3);
357 //printf("___CC_HWAddr= %x %x %x %x\n", mvdcmd.Arg0, mvdcmd.Arg1, mvdcmd.Arg2, mvdcmd.Arg3);
358 if(bBufMiu0) // SH@20110111, if CC buffer in MIU0, enable here
359 {
360 return (u32MVDCC_Temp1);
361 }
362 else // CC buffer in MIU1
363 {
364 return (u32MVDCC_Temp1|MIU1_BASEADDR);
365 }
366 }
367 else
368 {
369 MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_GET_CCBUF_HWADDR));
370 MVDCC_EXHANDLE(printf("\nF:GHAV"));
371 }
372
373 return 0xffffffff;
374 }
375
376 ///////////////////////////////////////////////////////////////////////////////
377 /// Get Overflow Status of MVD CC FW Driver
378 /// @param u8CC608 \b IN
379 /// - # TRUE for CC608 parser
380 /// - # FALSE for CC708 parser
381 /// Return value:: Overflow Status Flag
382 ////////////////////////////////////////////////////////////////////////////////
MDrv_CC_CM_GetOverflowStatus(MS_U8 u8CC608)383 MS_U8 MDrv_CC_CM_GetOverflowStatus(MS_U8 u8CC608)
384 {
385 MVD_CmdArg mvdcmd;
386 memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
387 mvdcmd.Arg3 = (MS_U8)u8CC608;
388 if (HAL_MVD_MVDCommand(CMD_GET_OVERFLOW_STATUS, &mvdcmd) == TRUE)
389 {
390 if ((mvdcmd.Arg0& 0x01) == 0)
391 return (FALSE);
392 else
393 return (TRUE);
394 }
395 else
396 {
397 MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_GET_OVERFLOW_STATUS));
398 MVDCC_EXHANDLE(printf("\nF:GOV"));
399 }
400 return (FALSE);
401 }
402
403 ///////////////////////////////////////////////////////////////////////////////
404 /// Set Software Pointer of MVD CC Ring Buffer
405 /// @param u32ReadAddress \b IN SW Pointer Address
406 /// @param u8CC608 \b IN
407 /// - # TRUE for CC608 parser
408 /// - # FALSE for CC708 parser
409 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_CM_SetMVDRB_SWAddr(MS_U32 u32ReadAddress,MS_U8 u8CC608)410 void MDrv_CC_CM_SetMVDRB_SWAddr(MS_U32 u32ReadAddress, MS_U8 u8CC608)
411 {
412 MS_U32 u32MVDCC_Temp1 = 0;
413 MVD_CmdArg mvdcmd;
414 memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
415
416 u32SW_Address[u8CC608] = u32ReadAddress;
417
418 if (bBufMiu0) // SH@20110111, if CC buffer in MIU0, enable here
419 {
420 u32MVDCC_Temp1 = (u32ReadAddress >> 3);
421 }
422 else // CC buffer in MIU1
423 {
424 u32MVDCC_Temp1 = u32ReadAddress - MIU1_BASEADDR ;
425 u32MVDCC_Temp1 = (u32MVDCC_Temp1 >> 3);
426 }
427
428 mvdcmd.Arg3 = (MS_U8)u8CC608;
429 mvdcmd.Arg2 = L_DWORD(u32MVDCC_Temp1);
430 mvdcmd.Arg1 = H_WORD(u32MVDCC_Temp1);
431 mvdcmd.Arg0 = L_WORD(u32MVDCC_Temp1);
432 if (HAL_MVD_MVDCommand(CMD_SET_CCBUF_SWADDR, &mvdcmd) != TRUE)
433 {
434 MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_SET_CCBUF_SWADDR));
435 MVDCC_EXHANDLE(printf("\nF:SSA"));
436 }
437 }
438
439
440 #define __Offset2PA(x) ((MVD_ON_MIU1)?((x)|MIU1_BASEADDR):(x))
441 ///////////////////////////////////////////////////////////////////////////////
442 /// Get HW Pointer Address of MVD CC FW Driver
443 /// @param u8CC608 \b IN
444 /// - # TRUE for CC608 parser
445 /// - # FALSE for CC708 parser
446 /// Return value:: HW Pointer Address
447 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_PM_GetMVDRB_WriteAddr(MS_U8 u8CC608)448 MS_U32 MDrv_CC_PM_GetMVDRB_WriteAddr(MS_U8 u8CC608)
449 {
450 u32HW_Address[u8CC608] = MDrv_CC_CM_GetMVDRB_HWAddr(u8CC608);
451
452 if(bBufMiu0)
453 {
454 return (MS_U32)__Offset2PA(u32HW_Address[u8CC608]);
455 }
456 else
457 {
458 return (MS_U32)(u32HW_Address[u8CC608]);
459 }
460 }
461
462 ///////////////////////////////////////////////////////////////////////////////
463 /// Get SW Pointer Address of MVD CC FW Driver
464 /// @param u8CC608 \b IN
465 /// - # TRUE for CC608 parser
466 /// - # FALSE for CC708 parser
467 /// Return value:: SW Pointer Address
468 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_PM_GetMVDRB_ReadAddr(MS_U8 u8CC608)469 MS_U32 MDrv_CC_PM_GetMVDRB_ReadAddr(MS_U8 u8CC608)
470 {
471 if(bBufMiu0)
472 {
473 return (MS_U32)__Offset2PA(u32SW_Address[u8CC608]);
474 }
475 else
476 {
477 return (MS_U32)(u32SW_Address[u8CC608]);
478 }
479 }
480
481 ///////////////////////////////////////////////////////////////////////////////
482 /// Set Software Pointer of MVD CC Ring Buffer to MVD CC FW Driver
483 /// @param u32EachPacketSize \b IN SW Pointer Address
484 /// @param u8CC608 \b IN
485 /// - # TRUE for CC608 parser
486 /// - # FALSE for CC708 parser
487 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_PM_SetMVDRB_ReadAddr(MS_U32 u32EachPacketSize,MS_U8 u8CC608)488 void MDrv_CC_PM_SetMVDRB_ReadAddr(MS_U32 u32EachPacketSize, MS_U8 u8CC608)
489 {
490 MS_U32 u32MVDCC_Temp1 = 0;
491 MS_U32 u32ParsedDataSize;
492
493 // Get the Parsed Data Size
494 if ((u32EachPacketSize % MVD_CCRB_PACKET_LENGTH) != 0)
495 {
496 u32ParsedDataSize = MVD_CCRB_PACKET_LENGTH * ((u32EachPacketSize / MVD_CCRB_PACKET_LENGTH)+1);
497 }
498 else
499 {
500 u32ParsedDataSize = u32EachPacketSize;
501 }
502
503 // Add the SW Address
504 if(MVD_ON_MIU1)
505 {
506 if(bBufMiu0) // SH@20110111, if CC buffer in MIU0, enable here
507 {
508 u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] & (MIU1_BASEADDR - 1); // to Phy address
509 }
510 else // CC buffer in MIU1
511 {
512 u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608] ;//& (MIU1_BASEADDR - 1); // to Phy address
513 }
514 }
515 else
516 {
517 u32MVDCC_Temp1 = CCMVD_RINGBUFFER_START_ADR[u8CC608];
518 }
519
520 if ((u32SW_Address[u8CC608] + u32ParsedDataSize) < (u32MVDCC_Temp1 + CCMVD_RINGBUFFER_LEN[u8CC608]))
521 {
522 u32SW_Address[u8CC608] += u32ParsedDataSize;
523 }
524 else
525 {
526 u32SW_Address[u8CC608] = (u32ParsedDataSize + u32SW_Address[u8CC608] - CCMVD_RINGBUFFER_LEN[u8CC608]);
527 }
528
529 #if 0
530 if(u32HW_Address - u32SW_Address >= 512)
531 {
532 printf("Sync:0x%08Lx", u32SW_Address);
533 u32SW_Address = u32HW_Address;
534 printf("-->0x%08Lx\n", u32SW_Address);
535 }
536 #endif
537
538 MDrv_CC_CM_SetMVDRB_SWAddr(u32SW_Address[u8CC608], u8CC608);
539 }
540
MDrv_CC_CM_GetInfo(MS_U32 selector,MS_U8 type,MS_U32 * p1,MS_U32 * p2)541 void MDrv_CC_CM_GetInfo(MS_U32 selector, MS_U8 type, MS_U32 *p1, MS_U32 *p2)
542 {
543 // Functionality select
544 switch (selector)
545 {
546 case CC_SELECTOR_708_SW:
547 *p1 = (MS_U32)bCC708Enable;
548 break;
549
550 #if defined( MSOS_TYPE_LINUX )
551 case CC_SELECTOR_CCMVD_RINGBUFFER:
552 *p1 = (MS_U32)CCMVD_RINGBUFFER_START_ADR[type];
553 *p2 = (MS_U32)CCMVD_RINGBUFFER_LEN[type];
554 break;
555 #endif
556
557 default:
558 *p1 = *p2 = 0;
559 break;
560 }
561 }
562
MDrv_CC_CM_Get708Sw(void)563 MS_BOOL MDrv_CC_CM_Get708Sw(void)
564 {
565 return bCC708Enable;
566 }
567
MDrv_CC_CM_IsMvdRstDone(MS_U8 type)568 MS_BOOL MDrv_CC_CM_IsMvdRstDone(MS_U8 type)
569 {
570 MS_BOOL bRet = FALSE;
571
572 if(type == E_CC_MVD_TYPE_608) // CC608
573 {
574 if(!MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_RST_CC608))
575 {
576 bRet = TRUE;
577 }
578 }
579 else // CC708
580 {
581 if(!MDrv_MVD_IsCmdFinished(MVD_HANDSHAKE_RST_CC708))
582 {
583 bRet = TRUE;
584 }
585 }
586
587 return bRet;
588 }
589
590 ///////////////////////////////////////////////////////////////////////////////
591 /// Enhance CC info mode, only support cc608
592 /// @param bEnable \b IN
593 /// - # TRUE for enhance to dump the pts/tmp_ref info
594 /// - # FALSE for original
595 ///////////////////////////////////////////////////////////////////////////////
MDrv_CC_InfoEnhanceMode(MS_BOOL bEnable)596 MS_BOOL MDrv_CC_InfoEnhanceMode(MS_BOOL bEnable)
597 {
598 MS_U8 u8Type = E_CC_MVD_TYPE_608;
599 MVD_CmdArg mvdcmd;
600 memset((void *)&mvdcmd, 0, sizeof(MVD_CmdArg));
601
602 mvdcmd.Arg0 = bEnable;
603 mvdcmd.Arg3 = u8Type;
604
605 if (HAL_MVD_MVDCommand(CMD_EN_CC_INFO_ENHANCE, &mvdcmd) != TRUE)
606 {
607 MVDCC_EXHANDLE(printf("%s: cmd 0x%x fail!!\n", __FUNCTION__, CMD_EN_CC_INFO_ENHANCE));
608 return FALSE;
609 }
610
611 return TRUE;
612 }
613
614