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 /// file Drvtvencoder.c
97 /// @brief TV encoder.
98 /// @author MStar Semiconductor Inc.
99 ///////////////////////////////////////////////////////////////////////////////////////////////////
100
101 #ifndef _DRVTVENCODER_C
102 #define _DRVTVENCODER_C
103
104 //-------------------------------------------------------------------------------------------------
105 // Include Files
106 //-------------------------------------------------------------------------------------------------
107 // Common Definition
108 #ifdef MSOS_TYPE_LINUX_KERNEL
109 #include <linux/string.h>
110 #include <linux/delay.h>
111 #include <asm/div64.h>
112 #include <linux/slab.h>
113 #else
114 #include <string.h>
115 #define do_div(x,y) ((x)/=(y))
116 #endif
117 #ifdef MSOS_TYPE_LINUX
118 #include <sys/ioctl.h>
119 #include <unistd.h>
120 #include <fcntl.h> // O_RDWR
121 #endif
122 #include "MsDevice.h"
123 #include "MsCommon.h"
124 #include "MsVersion.h"
125 #include "MsIRQ.h"
126 #include "MsOS.h"
127 #include "drvXC_IOPort.h"
128 #include "apiXC.h"
129 #include "drvMMIO.h"
130 #include "halCHIP.h"
131
132 // Internal Definition
133 #include "ve_Analog_Reg.h"
134 #include "drvTVEncoder.h"
135 #include "mhal_tvencoder.h"
136 #include "mdrv_gflip_ve_io.h"
137
138 #include "utopia.h"
139 //#include "utopia_core.h"
140 #include "utopia_dapi.h"
141 #include "tvencoder_private.h"
142 #include "tvencoder.h"
143 #include "ULog.h"
144 //#include "MsXC_Common_Internal.h"
145
146 //-------------------------------------------------------------------------------------------------
147 // Driver Compiler Options
148 //-------------------------------------------------------------------------------------------------
149
150
151 //-------------------------------------------------------------------------------------------------
152 // Local Defines
153 //-------------------------------------------------------------------------------------------------
154 extern MS_U32 _VE_RIU_BASE; // This should be inited before XC library starting.
155 // Need to Refine
156
157 extern void* pUtopiaTVEncoder;
158
159 //#define ENABLE_VE_FIELD_INV 1
160
161 #define VE_FRC_TOLERANT 10
162
163 #ifndef CONFIG_MBOOT
164 #define TVENCODER_UTOPIA2 1
165 #else
166 #define TVENCODER_UTOPIA2 0
167 #endif
168
169 #define _SC_PK_L_(bank, addr) (((MS_U16)(bank) << 8) | (MS_U16)((addr)*2))
170 #define _SC_PK_H_(bank, addr) (((MS_U16)(bank) << 8) | (MS_U16)((addr)*2+1))
171
172 //-------------------------------------------------------------------------------------------------
173 // Local Structurs
174 //-------------------------------------------------------------------------------------------------
175 typedef struct
176 {
177 //ve out timing
178 MS_U16 u16VttOut; //VttOut
179 MS_U16 u16HttOut; //HttOut
180 MS_U16 u16HdeOut; //HdeOut
181 MS_U16 u16VdeOut; //Vdeout
182
183 MS_BOOL bInterlace;
184
185 }MS_VE_PLL_OutCfg;
186
187 typedef struct
188 {
189 MS_VE_PLL_InCfg InCfg;
190 MS_VE_PLL_OutCfg OutCfg;
191
192 MS_U32 u32IDclk;
193 MS_U32 u32ODclk;
194 MS_U32 u32InitPll;
195 }MS_VE_PLL_INFO;
196
197 //-------------------------------------------------------------------------------------------------
198 // Global Variables
199 //-------------------------------------------------------------------------------------------------
200 MS_BOOL g_bVeDisableRegWrite = FALSE;
201
202 //-------------------------------------------------------------------------------------------------
203 // Local Variables
204 //-------------------------------------------------------------------------------------------------
205 static MSIF_Version _drv_ve_version = {
206 .DDI = { VE_DRV_VERSION },
207 };
208
209 static MS_PHY _phyVEMIUBaseAddr = 0;
210 static MS_U16 _gu16DbgLevel = FALSE;
211 static VE_DrvInfo _stVE_DrvInfo;
212 static MS_VE_PLL_INFO _stVE_PllInfo;
213
214 //VE
215 typedef struct
216 {
217 MS_VE_OUTPUT_DEST_TYPE OutputDestType[2]; // output device
218 MS_VE_INPUT_SRC_TYPE InputSrcType; // input source
219 MS_VE_INPUT_SRC_TYPE InputSrcOfMixedSrc; // The real input source for mixed "InputSrcType" of VE,
220 // eg. Real InputSrc of "MS_VE_SRC_MAIN", "MS_VE_SRC_SUB", "MS_VE_SRC_SCALER" etc.
221 MS_VE_VIDEOSYS VideoSystem; // video std of output signal
222 MS_U8 u8DACType;
223 MS_U16 u16inputVfreq;
224 MS_VE_Backup_Reg BackupReg;
225 MS_U16 u16H_CapStart;
226 MS_U16 u16H_CapSize;
227 MS_U16 u16V_CapStart;
228 MS_U16 u16V_CapSize;
229 MS_U16 u16H_SC_CapStart;
230 MS_U16 u16H_SC_CapSize;
231 MS_U16 u16V_SC_CapStart;
232 MS_U16 u16V_SC_CapSize;
233 MS_U8 u8VE_DisplayStatus;
234 MS_BOOL bHDuplicate;
235 MS_BOOL bSrcInterlace;
236 MS_BOOL bForceCaptureMode;
237
238 MS_U16 u16OutputWidth; //Downscaling output H size
239 MS_U16 u16Outputheight; //Downscaling output V size
240 MS_PHY phyMiuBaseAddr; //base address without miu offset
241 MS_BOOL bMemAddrInMIU1;
242 MS_U32 u32MemSize;
243 MS_BOOL bVECapture; ///< TRUE/FALSE, enable/disable VE as a capture device
244 MS_VE_CusScalingInfo stVECusScalingInfo;
245 MS_S32 s32FdGFlip;
246 }MS_VE_Info, *PMS_VE_Info;
247
248 static MS_VE_Info g_VEInfo={.s32FdGFlip=-1,}; //Init the file descriptor to avoid unused duplicate open of "/dev/gflip"
249
250 MS_VE_Cap g_VECap; // ve capability structure
251
252 #if TVENCODER_UTOPIA2
253 static void* pu32TvencoderInst = NULL;
254 #endif
255
256 //-------------------------------------------------------------------------------------------------
257 // Debug Functions
258 //-------------------------------------------------------------------------------------------------
259 #if (defined CONFIG_MLOG)
260 #define MSG_DRV_VE(fmt,_args...) \
261 do{\
262 if(_gu16DbgLevel ) \
263 {\
264 ULOGD("VE_DBG","[%s,%5d] ",__FUNCTION__,__LINE__);\
265 ULOGD("VE_DBG",fmt,##_args);\
266 }\
267 } while(0)
268 #else
269 #define MSG_DRV_VE(fmt,...) \
270 do{\
271 if(_gu16DbgLevel ) \
272 {\
273 printf("[VE_DBG]:");\
274 printf("%s: %d" fmt, __FUNCTION__, __LINE__, ## __VA_ARGS__);\
275 }\
276 } while(0)
277 #endif
278
279 //-------------------------------------------------------------------------------------------------
280 // Local Functions
281 //-------------------------------------------------------------------------------------------------
_GCD(MS_U32 u32A,MS_U32 u32B)282 static MS_U32 _GCD(MS_U32 u32A,MS_U32 u32B)
283 {
284 MS_U32 u32R;
285
286 u32R = u32A % u32B;
287 do{
288 u32A = u32B;
289 u32B = u32R;
290 u32R = u32A % u32B;
291 }while(u32R != 0);
292
293 return u32B;
294 }
295
_ReductionFrac(MS_U32 * pu32A,MS_U32 * pu32B)296 static MS_BOOL _ReductionFrac (MS_U32 *pu32A,MS_U32 *pu32B)
297 {
298 MS_U32 u32GCD;
299 while(1)
300 {
301 if( (*pu32A<3000) && (*pu32B<3000))
302 {
303 return TRUE;
304 }
305
306 u32GCD = _GCD(*pu32A,*pu32B);
307 if(u32GCD == 1)
308 return TRUE;
309
310 do_div(*pu32A, u32GCD);
311 do_div(*pu32B, u32GCD);
312 }
313 return TRUE;
314 }
315
_MultiplFrac(MS_U32 * pu32A,MS_U32 * pu32B)316 static MS_BOOL _MultiplFrac(MS_U32 *pu32A,MS_U32 *pu32B)
317 {
318 while(1)
319 {
320 if( ( (*pu32A<<1)<3000) && ( (*pu32B<<1) <3000))
321 {
322 *pu32A<<=1;
323 *pu32B<<=1;
324 }
325 else
326 {
327 return TRUE;
328 }
329 }
330 return TRUE;
331 }
332
_PreHscaleDown(MS_BOOL ben,MS_U16 In,MS_U16 Out)333 static void _PreHscaleDown(MS_BOOL ben, MS_U16 In, MS_U16 Out)
334 {
335 #if VE_PRESCALE_SUPPORT
336 MS_U32 u32H_Ratio = 0;
337
338 if(ben)
339 {
340 u32H_Ratio = (MS_U32)VE_H_PRESCALE_DOWN_RATIO(In, Out);
341 u32H_Ratio |= BIT(23); //enable H scale
342 MApi_XC_W4BYTE(_SC_PK_L_(0x62, 0x1), u32H_Ratio); //scale_ratio
343 }
344 else
345 {
346 MApi_XC_W4BYTE(_SC_PK_L_(0x62, 0x1), 0x0); //scale_ratio
347 }
348
349 MApi_XC_W2BYTE(_SC_PK_L_(0x62, 0x6), In); //hsize_in
350
351 if(Out > In)
352 {
353 MApi_XC_W2BYTE(_SC_PK_L_(0x62, 0x7), In); //hsize_out
354 }
355 else
356 {
357 MApi_XC_W2BYTE(_SC_PK_L_(0x62, 0x7), Out); //hsize_out
358 MApi_XC_W2BYTE(_SC_PK_L_(0x62, 0x43), Out-1); //VSP_hsize_in
359 MApi_XC_W2BYTE(_SC_PK_L_(0x62, 0x5e), Out); //VSP_hsize_out
360 }
361 #endif
362 }
363
_PreVscaleDown(MS_BOOL ben,MS_U16 In,MS_U16 Out)364 static void _PreVscaleDown(MS_BOOL ben, MS_U16 In, MS_U16 Out)
365 {
366 #if VE_PRESCALE_SUPPORT
367 MS_U32 u32V_Ratio = 0;
368
369 if(ben)
370 {
371 u32V_Ratio = (MS_U32)VE_V_PRESCALE_DOWN_RATIO(In, Out);
372 MApi_XC_W4BYTE(_SC_PK_L_(0x62, 0x47), u32V_Ratio); //scale_ratio
373 MApi_XC_W2BYTEMSK(_SC_PK_L_(0x62, 0x45), 0x0, BIT(1)|BIT(9)); //enable
374 MApi_XC_W2BYTEMSK(_SC_PK_L_(0x62, 0x5F), 0x0, BIT(1)); //enable
375 }
376 else
377 {
378 u32V_Ratio = 0x100000;
379 MApi_XC_W4BYTE(_SC_PK_L_(0x62, 0x47), u32V_Ratio); //scale_ratio
380 MApi_XC_W2BYTEMSK(_SC_PK_L_(0x62, 0x45), 0x0, BIT(1)|BIT(9)); //enable filter
381 MApi_XC_W2BYTEMSK(_SC_PK_L_(0x62, 0x5F), 0x0, BIT(1)); //enable VSD
382 }
383
384 MApi_XC_W2BYTE(_SC_PK_L_(0x62, 0x42), In-1); //Vsize_in
385
386 if(Out > In)
387 {
388 MApi_XC_W2BYTE(_SC_PK_L_(0x62, 0x44), In-1); //Vsize_out
389 }
390 else
391 {
392 MApi_XC_W2BYTE(_SC_PK_L_(0x62, 0x44), Out-1); //Vsize_out
393 }
394 #endif
395 }
396
397 //-------------------------------------------------------------------------------------------------
398 // Global Functions
399 //-------------------------------------------------------------------------------------------------
400 //-------------------------------------------------------------------------------------------------
401 /// @brief \b Function \b Name: MDrv_VE_GetLibVer
402 /// @brief \b Function \b Description: Show the VE driver version
403 /// @param ppVersion \b Out: Library version string
404 /// @return @ref VE_Result
405 //-------------------------------------------------------------------------------------------------
MDrv_VE_GetLibVer(const MSIF_Version ** ppVersion)406 VE_Result MDrv_VE_GetLibVer(const MSIF_Version **ppVersion)
407 {
408
409 if (!ppVersion)
410 {
411 return E_VE_FAIL;
412 }
413
414 *ppVersion = &_drv_ve_version;
415 return E_VE_OK;
416 }
417
418 //-------------------------------------------------------------------------------------------------
419 /// Get VE Information
420 /// @return @ref VE_DrvInfo return the VE information in this member
421 //-------------------------------------------------------------------------------------------------
_MDrv_VE_GetInfo(void)422 const VE_DrvInfo * _MDrv_VE_GetInfo(void)
423 {
424 MDrv_VE_GetCaps(&_stVE_DrvInfo.stCaps);
425 return &_stVE_DrvInfo;
426 }
427
MDrv_VE_GetInfo(void)428 const VE_DrvInfo * MDrv_VE_GetInfo(void)
429 {
430 #if TVENCODER_UTOPIA2
431 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
432 static VE_DrvInfo ve_drv_info;
433 TVE_GETINFO Args ;
434 memset(&Args, 0, sizeof(TVE_GETINFO));
435 Args.pVE_DrvInfo = &ve_drv_info;
436
437 if(pu32TvencoderInst == NULL)
438 {
439 return E_VE_FAIL;
440 }
441
442 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_GetInfo, (void*)&Args);
443 if(UTOPIA_STATUS_SUCCESS != u32Ret)
444 {
445 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
446 }
447
448 return Args.pVE_DrvInfo;
449 #else
450 return _MDrv_VE_GetInfo();
451 #endif
452 }
453 //-------------------------------------------------------------------------------------------------
454 /// Get VE Status
455 /// @param pDrvStatus \b OUT: store the status
456 /// @return @ref VE_Result
457 //-------------------------------------------------------------------------------------------------
_MDrv_VE_GetStatus(VE_DrvStatus * pDrvStatus)458 VE_Result _MDrv_VE_GetStatus(VE_DrvStatus* pDrvStatus)
459 {
460 pDrvStatus->u16H_CapStart = g_VEInfo.u16H_CapStart;
461 pDrvStatus->u16H_CapSize = g_VEInfo.u16H_CapSize;
462 pDrvStatus->u16V_CapStart = g_VEInfo.u16V_CapStart;
463 pDrvStatus->u16V_CapSize = g_VEInfo.u16V_CapSize;
464 pDrvStatus->VideoSystem = g_VEInfo.VideoSystem;
465 return E_VE_OK;
466 }
467
MDrv_VE_GetStatus(VE_DrvStatus * pDrvStatus)468 VE_Result MDrv_VE_GetStatus(VE_DrvStatus* pDrvStatus)
469 {
470 #if TVENCODER_UTOPIA2
471 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
472 PTVE_GETSTATUS pArgs = NULL;
473 if(pu32TvencoderInst == NULL)
474 {
475 return E_VE_FAIL;
476 }
477 pArgs = (PTVE_GETSTATUS)malloc(sizeof(TVE_GETSTATUS));
478
479 if(NULL == pArgs)
480 return E_VE_FAIL;
481 pArgs->pStaus = pDrvStatus;
482 pArgs->eRet = E_TVENCODER_FAIL;
483
484 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_GetStatues, (void*)pArgs);
485 if(UTOPIA_STATUS_SUCCESS != u32Ret)
486 {
487 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
488 }
489
490 if(E_TVENCODER_OK == pArgs->eRet)
491 {
492 free(pArgs);
493 return E_VE_OK;
494 }
495 else
496 {
497 free(pArgs);
498 return E_VE_FAIL;
499 }
500 #else
501 return _MDrv_VE_GetStatus(pDrvStatus);
502 #endif
503 }
_MDrv_VE_SetDbgLevel(MS_U16 level)504 void _MDrv_VE_SetDbgLevel(MS_U16 level)
505 {
506 _gu16DbgLevel = level;
507 }
508
MDrv_VE_SetDbgLevel(MS_U16 level)509 void MDrv_VE_SetDbgLevel(MS_U16 level)
510 {
511 #if TVENCODER_UTOPIA2
512 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
513 PTVE_SETDBGLEVEL pArgs = NULL;
514 if(pu32TvencoderInst == NULL)
515 {
516 if(UtopiaOpen(MODULE_TVENCODER, (void**)&pu32TvencoderInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
517 {
518 return ;
519 }
520 }
521 pArgs = (PTVE_SETDBGLEVEL)malloc(sizeof(TVE_SETDBGLEVEL));
522
523 if(NULL == pArgs)
524 return ;
525 pArgs->u16Level = level;
526 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SetDbgLevel, (void*)pArgs);
527 if(UTOPIA_STATUS_SUCCESS != u32Ret)
528 {
529 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
530 }
531 free(pArgs);
532 #else
533 _MDrv_VE_SetDbgLevel(level);
534 #endif
535 }
536
537 //Clear SW variable for VE
MDrv_VE_VariableInit(void)538 static void MDrv_VE_VariableInit(void)
539 {
540 MS_S32 s32FdGFlip = g_VEInfo.s32FdGFlip;
541
542 memset(&g_VEInfo, 0, sizeof(MS_VE_Info));
543 memset(&g_VECap, 0, sizeof(MS_VE_Cap));
544 memset(&_stVE_PllInfo, 0, sizeof(MS_VE_PLL_INFO));
545 memset(&_stVE_DrvInfo, 0, sizeof(VE_DrvInfo));
546
547 //Restore the file descriptor to avoid unused duplicate open of "/dev/gflip"
548 g_VEInfo.s32FdGFlip = s32FdGFlip;
549 g_VEInfo.InputSrcType = MS_VE_SRC_NONE;
550 g_VEInfo.InputSrcOfMixedSrc = MS_VE_SRC_NONE;
551 }
552
MDrv_VE_SetIOMapBase(void)553 MS_BOOL MDrv_VE_SetIOMapBase(void)
554 {
555 MS_VIRT _VERIUBaseAddress=0;
556 MS_PHY phyNonPMBankSize = 0;
557 if(MDrv_MMIO_GetBASE( &_VERIUBaseAddress, &phyNonPMBankSize, MS_MODULE_PM ) != TRUE)
558 {
559 MSG_DRV_VE("MDrv_VE_Init GetBASE failure\n");
560 MS_ASSERT(0);
561 return FALSE;
562 }
563
564 Hal_VE_init_riu_base( _VERIUBaseAddress );
565
566 return TRUE;
567 }
568
569 //------------------------------------------------------------------------------
570 /// Set VE FB memory base address
571 /// @param[in] u32MIUAddress \b IN: The FB address for VE
572 /// @return none
573 //------------------------------------------------------------------------------
_MDrv_VE_SetMemoryBaseAddr(MS_PHY phyMIUAddress,MS_U32 u32MIUSize)574 void _MDrv_VE_SetMemoryBaseAddr(MS_PHY phyMIUAddress, MS_U32 u32MIUSize)
575 {
576 MS_PHY phyStartOffset;
577 MS_U8 u8MiuSel = 0;
578 #if defined(__aarch64__)
579 MSG_DRV_VE("Change VE MemoryBase: Address=0x%lx Size=0x%x \n",phyMIUAddress, u32MIUSize);
580 #else
581 MSG_DRV_VE("Change VE MemoryBase: Address=0x%tx Size=0x%tx \n",(ptrdiff_t)phyMIUAddress,(ptrdiff_t) u32MIUSize);
582 #endif
583 //u32MIUAddress = 0x0000100000+HAL_MIU1_BASE;
584
585 // transfer u32MIUAddress
586 _phy_to_miu_offset(u8MiuSel, phyStartOffset, phyMIUAddress);
587
588 Hal_VE_SelMIU(u8MiuSel);
589 if(u8MiuSel == E_CHIP_MIU_1)
590 {
591 g_VEInfo.bMemAddrInMIU1 = TRUE;
592 }
593 else
594 {
595 g_VEInfo.bMemAddrInMIU1 = FALSE;
596 }
597
598 #ifndef CONFIG_MBOOT
599 if(g_VECap.bSupport_DolbyVerifier)
600 {
601 Hal_VE_set_dolby_verifier_addr(phyStartOffset);
602 phyStartOffset += Hal_VE_get_dolby_verifier_buf_size();
603 }
604 #endif
605
606 //g_VEInfo.u32MemSize = u32MIUSize/(BYTE_PER_WORD>>1); //Now only used in VEC, Change like this later to avoid not enable 3 frame mode
607 g_VEInfo.u32MemSize = u32MIUSize;
608 g_VEInfo.phyMiuBaseAddr = phyStartOffset;
609 #if defined (__aarch64__)
610 MSG_DRV_VE("Final VE MemoryBase: Address=0x%lx, size=0x%x \n",g_VEInfo.phyMiuBaseAddr, g_VEInfo.u32MemSize);
611 #else
612 MSG_DRV_VE("Final VE MemoryBase: Address=0x%tx, size=0x%tx \n",(ptrdiff_t)g_VEInfo.phyMiuBaseAddr,(ptrdiff_t) g_VEInfo.u32MemSize);
613 #endif
614 Hal_VE_SetMemAddr(&phyStartOffset, &phyStartOffset);
615 }
616
617 //------------------------------------------------------------------------------
618 /// Set VE FB memory base address
619 /// @param[in] u32MIUAddress \b IN: The FB address for VE
620 /// @return none
621 //------------------------------------------------------------------------------
MDrv_VE_SetMemoryBaseAddr(MS_PHY phyMIUAddress,MS_U32 u32MIUSize)622 void MDrv_VE_SetMemoryBaseAddr(MS_PHY phyMIUAddress, MS_U32 u32MIUSize)
623 {
624 #if TVENCODER_UTOPIA2
625 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
626 PTVE_SETMEMORYBASEADDR pArgs = NULL;
627 if(pu32TvencoderInst == NULL)
628 {
629 return;
630 }
631 pArgs = (PTVE_SETMEMORYBASEADDR)malloc(sizeof(TVE_SETMEMORYBASEADDR));
632
633 if(NULL == pArgs)
634 return;
635 pArgs->phyMIUAddress = phyMIUAddress;
636 pArgs->u32MIUSize = u32MIUSize;
637
638 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SetOutputVideoStd, (void*)pArgs);
639 if(UTOPIA_STATUS_SUCCESS != u32Ret)
640 {
641 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
642 }
643 free(pArgs);
644 return;
645 #else
646 return _MDrv_VE_SetMemoryBaseAddr(phyMIUAddress,u32MIUSize);
647 #endif
648
649 }
650
651
652 //-------------------------------------------------------------------------------------------------
653 /// GFlip Init for VE capture, get handler for VEC
654 /// @return TRUE: success/fail
655 /// @attention
656 /// <b>[Mxlib] <em></em></b>
657 //-------------------------------------------------------------------------------------------------
MDrv_VEC_GFLIPInit(void)658 MS_BOOL MDrv_VEC_GFLIPInit(void)
659 {
660 #ifdef MSOS_TYPE_LINUX
661 if(0> g_VEInfo.s32FdGFlip)
662 {
663 g_VEInfo.s32FdGFlip = open("/dev/gflip", O_RDWR);
664 if(0> g_VEInfo.s32FdGFlip)
665 {
666 printf("[%s][%d] open fail /dev/gflip\n", __FUNCTION__, __LINE__);
667 return FALSE;
668 }
669 }
670 #endif
671 return TRUE;
672 }
673
674 //------------------------------------------------------------------------------
675 /// Initiate VE
676 /// @param[in] u32MIUAddress \b IN: The address reserved for VE
677 /// @return none
678 //------------------------------------------------------------------------------
679 // initiate video encoder
_MDrv_VE_Init(MS_PHY u32MIUAddress)680 void _MDrv_VE_Init(MS_PHY u32MIUAddress)
681 {
682 // This should be the first function of VE.
683 MDrv_VE_VariableInit();
684 if (MDrv_VE_SetIOMapBase() != TRUE)
685 {
686 MSG_DRV_VE("VE: MDrv_VE_Init MDrv_VE_SetIOMapBase() failure\n");
687 return;
688 }
689 //u32MIUAddress = 0x0000100000+HAL_MIU1_BASE;
690 #if defined (__aarch64__)
691 MSG_DRV_VE("VE input u32MIUAddress=0x%lx \n",u32MIUAddress);
692 #else
693 MSG_DRV_VE("VE input u32MIUAddress=0x%tx \n",(ptrdiff_t)u32MIUAddress);
694 #endif
695
696 //get chip capability
697 Hal_VE_GetCaps(&g_VECap);
698
699 _MDrv_VE_SetMemoryBaseAddr(u32MIUAddress, 0);
700 _phyVEMIUBaseAddr = u32MIUAddress;
701
702 Hal_VE_init();
703 }
MDrv_VE_Init(MS_PHY u32MIUAddress)704 void MDrv_VE_Init(MS_PHY u32MIUAddress)
705 {
706 #if TVENCODER_UTOPIA2
707 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
708 PTVE_INIT pArgs = NULL;
709
710 if(pu32TvencoderInst ==NULL)
711 {
712 if(UtopiaOpen(MODULE_TVENCODER, (void**)&pu32TvencoderInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
713 {
714 printf("UtopiaOpen TVE failed\n");
715 return ;
716 }
717 }
718 pArgs = (PTVE_INIT)malloc(sizeof(TVE_INIT));
719
720 if(NULL == pArgs)
721 return ;
722 pArgs->u32MIUAddress = u32MIUAddress;
723 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_Init, (void*)pArgs);
724 if(UTOPIA_STATUS_SUCCESS != u32Ret)
725 {
726 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
727 }
728 free(pArgs);
729 #else
730 /*
731 * special case, in utopia2.0, if address assigned to NULL it means this process will wait here
732 * until another process initialize VE SW/HW successfully.
733 * For SW and use case back/forword compatible, in utopia1.0 return before setting physical address to HW.
734 */
735 if (u32MIUAddress == (MS_PHY)NULL)
736 {
737 return;
738 }
739 _MDrv_VE_Init(u32MIUAddress);
740 #endif
741 }
742
_MDrv_VE_GetConfig(void * pInstance,MS_PHY * pMIUAddress)743 MS_BOOL _MDrv_VE_GetConfig(void* pInstance, MS_PHY *pMIUAddress)
744 {
745 #if TVENCODER_UTOPIA2
746 void* psResource = NULL;
747 TVENCODER_INSTANT_PRIVATE* psTVENCODERInstPri = NULL;
748 TVENCODER_RESOURCE_PRIVATE * pstResPri = NULL;
749
750 UtopiaInstanceGetPrivate(pInstance, (void**)&psTVENCODERInstPri);
751
752 if(UtopiaResourceObtain(pUtopiaTVEncoder, E_TVENCODER_POOL_ID_VE0, &psResource) != UTOPIA_STATUS_SUCCESS)
753 {
754 printf("UtopiaResourceObtain fail,%s,%d\n",__FUNCTION__,__LINE__);
755 return E_TVENCODER_FAIL;
756 }
757
758 UtopiaResourceGetPrivate(psResource, (void**)&pstResPri);
759 *pMIUAddress = pstResPri->u32MIUAddress;
760
761 //Ready to do VE Init
762 pstResPri->bInited_Drv = FALSE;
763
764 UtopiaResourceRelease(psResource);
765 #endif
766 return TRUE;
767 }
768
MDrv_VE_GetConfig(MS_PHY * pMIUAddress)769 MS_BOOL MDrv_VE_GetConfig(MS_PHY *pMIUAddress)
770 {
771 #if TVENCODER_UTOPIA2
772 MS_U32 u32Ret = UTOPIA_STATUS_FAIL;
773 PTVE_GETCONFIG pArgs = NULL;
774
775 if(pu32TvencoderInst ==NULL)
776 {
777 if(UtopiaOpen(MODULE_TVENCODER, (void**)&pu32TvencoderInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
778 {
779 printf("UtopiaOpen TVE failed\n");
780 return FALSE;
781 }
782 }
783
784 pArgs = (PTVE_GETCONFIG)malloc(sizeof(TVE_GETCONFIG));
785
786 if(NULL == pArgs)
787 {
788 return FALSE;
789 }
790
791 pArgs->pMIUAddress = pMIUAddress;
792 pArgs->eRet = E_TVENCODER_FAIL;
793 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_GetConfig, (void*)pArgs);
794 if(UTOPIA_STATUS_SUCCESS != u32Ret)
795 {
796 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
797 }
798
799 if(E_TVENCODER_OK == pArgs->eRet)
800 {
801 free(pArgs);
802 return TRUE;
803 }
804 else
805 {
806 free(pArgs);
807 return FALSE;
808 }
809 #else
810 return FALSE;
811 #endif
812 }
813
_MDrv_VE_Exit(void)814 MS_BOOL _MDrv_VE_Exit(void)
815 {
816 MS_VE_Output_Ctrl OutputCtrl;
817 // Turn off VE
818 OutputCtrl.bEnable = FALSE;
819 OutputCtrl.OutputType = MS_VE_OUT_TVENCODER;
820 _MDrv_VE_SetOutputCtrl(&OutputCtrl);
821 return TRUE;
822 }
823
MDrv_VE_Exit(void)824 MS_BOOL MDrv_VE_Exit(void)
825 {
826 #if TVENCODER_UTOPIA2
827 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
828 PTVE_EXIT pArgs = NULL;
829 if(pu32TvencoderInst == NULL)
830 {
831 return FALSE;
832 }
833 pArgs = (PTVE_EXIT)malloc(sizeof(TVE_EXIT));
834
835 if(NULL == pArgs)
836 {
837 return E_TVENCODER_FAIL;
838 }
839 pArgs->eRet = E_TVENCODER_FAIL;
840
841 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_Exit, (void*)pArgs);
842 if(UTOPIA_STATUS_SUCCESS != u32Ret)
843 {
844 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
845 }
846
847 if(E_TVENCODER_OK == pArgs->eRet)
848 {
849 free(pArgs);
850 return TRUE;
851 }
852 else
853 {
854 free(pArgs);
855 return FALSE;
856 }
857 #else
858 return _MDrv_VE_Exit();
859 #endif
860 }
861
862 //------------------------------------------------------------------------------
863 /// set the output destination of video encoder
864 ///
865 /// None SCART CVBS SVIDEO YPbPr
866 /// None O O O O O
867 /// SCART O - X X X
868 /// CVBS O X - O O
869 /// S_VIDE O O X O - X
870 /// YPbPr O X O X -
871 ///
872 /// @param -pSwitchInfo \b IN/OUT: the information of switching output destination of TV encodeer
873 /// @return None
874 //------------------------------------------------------------------------------
_MDrv_VE_SwitchOuputDest(PMS_Switch_VE_Dest_Info pSwitchInfo)875 void _MDrv_VE_SwitchOuputDest(PMS_Switch_VE_Dest_Info pSwitchInfo)
876 {
877 if((pSwitchInfo->OutputDstType != MS_VE_DEST_SCART) &&
878 (pSwitchInfo->OutputDstType != MS_VE_DEST_YPBPR) &&
879 (pSwitchInfo->OutputDstType != MS_VE_DEST_CVBS) &&
880 (pSwitchInfo->OutputDstType != MS_VE_DEST_SVIDEO))
881 {
882 pSwitchInfo->Status = MS_VE_SWITCH_DST_INVALID_PARAM;
883 return;
884 }
885
886 pSwitchInfo->Status = MS_VE_SWITCH_DST_SUCCESS;
887
888 if(pSwitchInfo->OutputDstType == MS_VE_DEST_SCART)
889 g_VEInfo.u8DACType = VE_OUT_CVBS_RGB;
890 else if(pSwitchInfo->OutputDstType == MS_VE_DEST_YPBPR)
891 g_VEInfo.u8DACType = VE_OUT_CVBS_YCbCr;
892 else
893 g_VEInfo.u8DACType = VE_OUT_CVBS_YCC;
894
895 Hal_VE_set_out_sel(g_VEInfo.u8DACType);
896 Hal_VE_set_color_convert(g_VEInfo.VideoSystem, g_VEInfo.u8DACType);
897 }
898
MDrv_VE_SwitchOuputDest(PMS_Switch_VE_Dest_Info pSwitchInfo)899 void MDrv_VE_SwitchOuputDest(PMS_Switch_VE_Dest_Info pSwitchInfo)
900 {
901 #if TVENCODER_UTOPIA2
902 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
903 PTVE_SWITCHOUTPUTDEST pArgs = NULL;
904 if(pu32TvencoderInst == NULL)
905 {
906 return ;
907 }
908 pArgs = (PTVE_SWITCHOUTPUTDEST)malloc(sizeof(TVE_SWITCHOUTPUTDEST));
909
910 if(NULL == pArgs)
911 return ;
912 pArgs->pSwitchInfo = pSwitchInfo;
913 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SwitchOutputDest, (void*)pArgs);
914 if(UTOPIA_STATUS_SUCCESS != u32Ret)
915 {
916 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
917 }
918 free(pArgs);
919 #else
920 _MDrv_VE_SwitchOuputDest( pSwitchInfo);
921 #endif
922 }
923
924 //------------------------------------------------------------------------------
925 /// Get u8VE_DisplayStatus for set the input source of video encoder
926 ///
927 /// @param -pSwitchInfo \b IN/OUT: the information of switching input destination of TV encodeer
928 /// @return None
929 //------------------------------------------------------------------------------
MDrv_VE_SetSrcDispStatus(PMS_VE_InputSrc_Info pInputSrcInfo)930 static void MDrv_VE_SetSrcDispStatus(PMS_VE_InputSrc_Info pInputSrcInfo)
931 {
932 MS_VE_INPUT_SRC_TYPE eInputSrc;
933 g_VEInfo.u8VE_DisplayStatus &= ~(EN_VE_CCIR656_IN | EN_VE_RGB_IN | EN_VE_DEMODE);
934 if((pInputSrcInfo->eInputSrcType == MS_VE_SRC_SUB) ||
935 (pInputSrcInfo->eInputSrcType == MS_VE_SRC_MAIN))
936 {
937 eInputSrc = pInputSrcInfo->eInputSrcOfMixedSrc;
938 }
939 else
940 {
941 eInputSrc = pInputSrcInfo->eInputSrcType;
942 }
943
944 switch(eInputSrc)
945 {
946 case MS_VE_SRC_DTV:
947 // for Agate new design, it need to use the DE mode!!
948 //if(pInputSrcInfo->eInputSrcType == MS_VE_SRC_SUB)
949 {
950 //By now, DTV is always goes with capture mode in AV output
951 //For SRC_SUB, we used in vecapture function, so use DE mode
952 g_VEInfo.u8VE_DisplayStatus |= EN_VE_DEMODE;
953 }
954 break;
955
956 case MS_VE_SRC_DSUB:
957 //g_VEInfo.u8VE_DisplayStatus |= EN_VE_RGB_IN; //Move AP to control this according to SC_IP2's CSC setting
958 g_VEInfo.u8VE_DisplayStatus |= EN_VE_DEMODE;
959 break;
960
961 case MS_VE_SRC_COMP:
962 g_VEInfo.u8VE_DisplayStatus |= EN_VE_DEMODE;
963 break;
964
965 case MS_VE_SRC_ATV:
966 case MS_VE_SRC_CVBS0:
967 case MS_VE_SRC_CVBS1:
968 case MS_VE_SRC_CVBS2:
969 case MS_VE_SRC_CVBS3:
970 case MS_VE_SRC_SVIDEO:
971 break;
972
973 case MS_VE_SRC_HDMI_A:
974 case MS_VE_SRC_HDMI_B:
975 case MS_VE_SRC_HDMI_C:
976 //g_VEInfo.u8VE_DisplayStatus |= EN_VE_RGB_IN; //For DVI/HDMI, control this in AP layer
977 g_VEInfo.u8VE_DisplayStatus |= EN_VE_DEMODE;
978 break;
979
980 case MS_VE_SRC_SCALER:
981 // set input color at HAL layer
982 //g_VEInfo.u8VE_DisplayStatus |= EN_VE_RGB_IN;
983 if(!g_VEInfo.bForceCaptureMode)
984 g_VEInfo.u8VE_DisplayStatus |= EN_VE_DEMODE;
985 else
986 g_VEInfo.u8VE_DisplayStatus &= ~EN_VE_DEMODE;
987 break;
988
989 case MS_VE_SRC_DI:
990 if(!g_VEInfo.bForceCaptureMode)
991 g_VEInfo.u8VE_DisplayStatus |= EN_VE_DEMODE;
992 else
993 g_VEInfo.u8VE_DisplayStatus &= ~EN_VE_DEMODE;
994 break;
995
996 case MS_VE_SRC_DNR:
997 if(!g_VEInfo.bForceCaptureMode)
998 g_VEInfo.u8VE_DisplayStatus |= EN_VE_DEMODE;
999 else
1000 g_VEInfo.u8VE_DisplayStatus &= ~EN_VE_DEMODE;
1001 break;
1002
1003 case MS_VE_SRC_DTV_FROM_MVOP:
1004 g_VEInfo.u8VE_DisplayStatus |= EN_VE_DEMODE;
1005 break;
1006
1007 case MS_VE_SRC_BT656:
1008 if(!g_VEInfo.bForceCaptureMode)
1009 g_VEInfo.u8VE_DisplayStatus |= EN_VE_DEMODE;
1010 else
1011 g_VEInfo.u8VE_DisplayStatus &= ~EN_VE_DEMODE;
1012 g_VEInfo.u8VE_DisplayStatus |= EN_VE_CCIR656_IN;
1013 break;
1014
1015 default:
1016 break;
1017 }
1018 MSG_DRV_VE("VE: %s:%d status=%x eInputSrc=%u\n", __FUNCTION__, __LINE__, g_VEInfo.u8VE_DisplayStatus, eInputSrc);
1019 }
1020
1021
1022 //------------------------------------------------------------------------------
1023 /// Extended API for set the input source of video encoder(To Expand&Replace MDrv_VE_SwitchInputSource)
1024 ///
1025 /// @param -pSwitchInfo \b IN/OUT: the information of switching input destination of TV encodeer
1026 /// @return @ref MS_SWITCH_VE_SRC_STATUS
1027 //------------------------------------------------------------------------------
_MDrv_VE_SetInputSource(PMS_VE_InputSrc_Info pInputSrcInfo)1028 MS_SWITCH_VE_SRC_STATUS _MDrv_VE_SetInputSource(PMS_VE_InputSrc_Info pInputSrcInfo)
1029 {
1030 MSG_DRV_VE("VE: %s, Src = %d, %d\n", __FUNCTION__, pInputSrcInfo->eInputSrcType, pInputSrcInfo->eInputSrcOfMixedSrc);
1031
1032 g_VEInfo.InputSrcType = pInputSrcInfo->eInputSrcType;
1033 g_VEInfo.InputSrcOfMixedSrc = pInputSrcInfo->eInputSrcOfMixedSrc;
1034 MDrv_VE_SetSrcDispStatus(pInputSrcInfo);
1035 switch(pInputSrcInfo->eInputSrcType)
1036 {
1037 case MS_VE_SRC_COMP:
1038 Hal_VE_set_source_sync_inv(0x12, 0xFF);// set the sync polarity
1039 Hal_VE_set_sog(ENABLE); // enable sog
1040 break;
1041
1042 case MS_VE_SRC_DTV_FROM_MVOP:
1043 case MS_VE_SRC_SUB:
1044 case MS_VE_SRC_DTV:
1045 Hal_VE_set_source_sync_inv(0x12, 0xFF);// set the sync polarity
1046 break;
1047 default:
1048 break;
1049 }
1050 if(g_VEInfo.u8VE_DisplayStatus & EN_VE_RGB_IN)
1051 Hal_VE_set_rgb_in(ENABLE); // enable RGB in
1052 else
1053 Hal_VE_set_rgb_in(DISABLE);// disable RGB in
1054
1055 if(g_VEInfo.u8VE_DisplayStatus & EN_VE_CCIR656_IN)
1056 Hal_VE_set_ccir656_in(ENABLE);
1057 else
1058 Hal_VE_set_ccir656_in(DISABLE);
1059
1060 Hal_VE_set_inputsource(pInputSrcInfo);
1061 return MS_VE_SWITCH_SRC_SUCCESS;
1062 }
1063
MDrv_VE_SetInputSource(PMS_VE_InputSrc_Info pInputSrcInfo)1064 MS_SWITCH_VE_SRC_STATUS MDrv_VE_SetInputSource(PMS_VE_InputSrc_Info pInputSrcInfo)
1065 {
1066 #if TVENCODER_UTOPIA2
1067 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1068 PTVE_SETINPUTSRC pArgs = NULL;
1069 if(pu32TvencoderInst == NULL)
1070 {
1071 return MS_VE_SWITCH_SRC_FAIL;
1072 }
1073 pArgs = (PTVE_SETINPUTSRC)malloc(sizeof(TVE_SETINPUTSRC));
1074
1075 if(NULL == pArgs)
1076 return MS_VE_SWITCH_SRC_FAIL;
1077 pArgs->pInputSrcInfo= pInputSrcInfo;
1078 pArgs->eRet = E_TVENCODER_FAIL;
1079
1080 u32Ret = UtopiaIoctl(pu32TvencoderInst,E_MDRV_CMD_TVE_SetInputSRC,(void*)pArgs);
1081 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1082 {
1083 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
1084 }
1085
1086 if(E_TVENCODER_OK == pArgs->eRet)
1087 {
1088 free(pArgs);
1089 return MS_VE_SWITCH_SRC_SUCCESS;
1090 }
1091 else
1092 {
1093 free(pArgs);
1094 return MS_VE_SWITCH_SRC_FAIL;
1095 }
1096 #else
1097 return _MDrv_VE_SetInputSource(pInputSrcInfo);
1098 #endif
1099 }
1100 //------------------------------------------------------------------------------
1101 /// set the input source of video encoder
1102 ///
1103 /// @param -pSwitchInfo \b IN/OUT: the information of switching input destination of TV encodeer
1104 /// @return None
1105 //------------------------------------------------------------------------------
_MDrv_VE_SwitchInputSource(PMS_Switch_VE_Src_Info pSwitchInfo)1106 void _MDrv_VE_SwitchInputSource(PMS_Switch_VE_Src_Info pSwitchInfo)
1107 {
1108 if((pSwitchInfo->InputSrcType == MS_VE_SRC_SUB) || (pSwitchInfo->InputSrcType == MS_VE_SRC_MAIN))
1109 {
1110 printf("!!!ALERT, FATAL ERROR: Non supported argument[%d] for [%s], try [MDrv_VE_SetInputSource]\n", pSwitchInfo->InputSrcType, __FUNCTION__);
1111 }
1112 else
1113 {
1114 MS_VE_InputSrc_Info InputSrcInfo;
1115 memset(&InputSrcInfo, 0, sizeof(MS_VE_InputSrc_Info));
1116 InputSrcInfo.u16Version = 0; //It is old version interface
1117 InputSrcInfo.eInputSrcType = pSwitchInfo->InputSrcType;
1118 InputSrcInfo.eInputSrcOfMixedSrc = MS_VE_SRC_NONE;
1119 _MDrv_VE_SetInputSource(&InputSrcInfo);
1120 }
1121 }
1122
MDrv_VE_SwitchInputSource(PMS_Switch_VE_Src_Info pSwitchInfo)1123 void MDrv_VE_SwitchInputSource(PMS_Switch_VE_Src_Info pSwitchInfo)
1124 {
1125 #if TVENCODER_UTOPIA2
1126 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1127 PTVE_SWITCH_SRC_INFO pArgs = NULL;
1128 if(pu32TvencoderInst == NULL)
1129 {
1130 return ;
1131 }
1132 pArgs = (PTVE_SWITCH_SRC_INFO)malloc(sizeof(TVE_SWITCH_SRC_INFO));
1133
1134 if(NULL == pArgs)
1135 return ;
1136 pArgs->pSwithcSrc_info = pSwitchInfo;
1137 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SwitchInputSRC, (void*)pArgs);
1138 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1139 {
1140 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
1141 }
1142 free(pArgs);
1143 #else
1144 _MDrv_VE_SwitchInputSource(pSwitchInfo);
1145 #endif
1146 }
1147
1148 //------------------------------------------------------------------------------
1149 /// control the output of video encoder
1150 ///
1151 /// @param -pOutputCtrl \b IN: the control information of VE
1152 /// @return none
1153 //------------------------------------------------------------------------------
_MDrv_VE_SetOutputCtrl(PMS_VE_Output_Ctrl pOutputCtrl)1154 void _MDrv_VE_SetOutputCtrl(PMS_VE_Output_Ctrl pOutputCtrl)
1155 {
1156 MS_BOOL bOutCCIR656 = FALSE, bOutTVE=FALSE, bFieldInv;
1157 MS_U16 u16EnVal;
1158
1159 //(printf("-------- this is VE out 2009 /04/29-------\n") );
1160
1161 if(pOutputCtrl->bEnable)
1162 {
1163 if(pOutputCtrl->OutputType == MS_VE_OUT_TVENCODER)
1164 {
1165 bOutTVE = TRUE;
1166 }
1167 else if(pOutputCtrl->OutputType == MS_VE_OUT_CCIR656)
1168 {
1169 //When CCIR is on, TV encoder is also needed to be enabled
1170 bOutTVE = TRUE;
1171 bOutCCIR656 = TRUE;
1172 }
1173
1174 if((g_VEInfo.InputSrcType == MS_VE_SRC_SCALER) ||
1175 (g_VEInfo.InputSrcType == MS_VE_SRC_DI) ||
1176 (g_VEInfo.InputSrcType == MS_VE_SRC_BT656) ||
1177 (g_VEInfo.InputSrcType == MS_VE_SRC_DNR) ||
1178 ((g_VEInfo.InputSrcType >= MS_VE_SRC_ATV) && (g_VEInfo.InputSrcType <= MS_VE_SRC_SVIDEO)) ||
1179 ((g_VEInfo.InputSrcOfMixedSrc >= MS_VE_SRC_ATV) && (g_VEInfo.InputSrcOfMixedSrc <= MS_VE_SRC_SVIDEO))
1180 )
1181 {
1182 if(!g_VEInfo.bForceCaptureMode)
1183 u16EnVal = BIT(7)|(bOutTVE << 2)|(bOutCCIR656 << 1)|(bOutCCIR656 << 6); // Enable DE mode when input source is Scaler OP/DI or VD
1184 else
1185 u16EnVal = (bOutTVE << 2)|(bOutCCIR656 << 1)|(bOutCCIR656 << 6); // Disable DE mode when input source is Scaler OP
1186 }
1187 else
1188 {
1189 u16EnVal = ((g_VEInfo.u8VE_DisplayStatus & EN_VE_DEMODE)<< 7) |
1190 (bOutTVE << 2) |
1191 (bOutCCIR656 << 1)|
1192 (bOutCCIR656 << 6);
1193 }
1194 MSG_DRV_VE("VE Power on: bOutCCIR656=0x%x, bOutTVE=0x%x, u16EnVal=0x%x \n", bOutCCIR656, bOutTVE, u16EnVal);
1195 if(bOutCCIR656)
1196 {
1197 Hal_VE_set_source_sync_inv(0, BIT(4));
1198 if(g_VEInfo.VideoSystem <= MS_VE_PAL_M)
1199 { // NTSC
1200 Hal_VE_set_ccir656_out_pal(0);
1201 }
1202 else
1203 { // PAL
1204 Hal_VE_set_ccir656_out_pal(1);
1205 }
1206 }
1207
1208 // Field Invert
1209 if(g_VEInfo.InputSrcType == MS_VE_SRC_DTV_FROM_MVOP)
1210 {
1211 Hal_VE_set_field_inverse(0);
1212 }
1213 else if(g_VEInfo.InputSrcType == MS_VE_SRC_COMP)
1214 {
1215 bFieldInv = (g_VEInfo.u16V_SC_CapStart & 0x01) ?
1216 ENABLE_VE_FIELD_INV : ~ENABLE_VE_FIELD_INV;
1217 bFieldInv = g_VEInfo.bSrcInterlace ? bFieldInv : 0;
1218 Hal_VE_set_field_inverse((bFieldInv & 0x01));
1219 }
1220 else
1221 {
1222 if(g_VEInfo.u8VE_DisplayStatus & EN_VE_DEMODE)
1223 {
1224 bFieldInv = (g_VEInfo.bSrcInterlace) ? ENABLE_VE_FIELD_INV : 0;
1225 Hal_VE_set_field_inverse((bFieldInv & 0x01));
1226 }
1227 else
1228 {
1229 bFieldInv = (g_VEInfo.u16V_SC_CapStart & 0x01) ?
1230 ~ENABLE_VE_FIELD_INV : ENABLE_VE_FIELD_INV;
1231 bFieldInv = g_VEInfo.bSrcInterlace ? bFieldInv : 0;
1232 Hal_VE_set_field_inverse((bFieldInv & 0x01));
1233 }
1234 }
1235
1236 Hal_VE_set_clk_on_off(ENABLE);
1237 Hal_VE_set_ctrl(u16EnVal);
1238 if(!g_VEInfo.bVECapture)
1239 {
1240 Hal_VE_set_vbi(ENABLE);
1241 }
1242
1243 //OS_DELAY_TASK(300);
1244 Hal_VE_sofeware_reset(ENABLE); // software reset
1245 Hal_VE_set_reg_load(ENABLE);// load register,but not affect bit3(VBI output)
1246
1247 // For Mboot boot time optimization
1248 #if ( ! defined (STB) || ! defined (MBOOT))
1249 //MsOS_DelayTask(5) ; // delay 5 ms
1250 OS_DELAY_TASK(30);
1251
1252 // TELETEXT
1253
1254 Hal_VE_set_reg_load(DISABLE);// load register,but not affect bit3(VBI output)
1255 OS_DELAY_TASK(5);
1256 Hal_VE_sofeware_reset(DISABLE); // software reset
1257 #endif
1258
1259 if(pOutputCtrl->OutputType != MS_VE_OUT_CAPTURE)
1260 {
1261 //For VEC, turn on it in kernel
1262 OS_DELAY_TASK(5);
1263 Hal_VE_set_ve_on_off(ENABLE);
1264 }
1265 }
1266 else
1267 {
1268 //Hal_VE_set_cvbs_buffer_out(0x0F, 0, 0, 0);
1269 MSG_DRV_VE("VE Power off\n");
1270 Hal_VE_set_ctrl(0);
1271 Hal_VE_set_vbi(DISABLE);
1272 Hal_VE_set_ve_on_off(DISABLE);
1273 Hal_VE_set_clk_on_off(DISABLE);
1274 //When disable VE
1275 //1.DE mode just set 0x103B00[0] to 0.
1276 //2. non-DE mode ,set 0x103B00[0] to 0,H capture window start (0x103B12) ¤£¥i¥H³]0
1277 Hal_VE_set_capture_window(0x010, VE_DE_HEND_MASK, 0x000, VE_DE_VEND_MASK);
1278 }
1279
1280 //workaround to pass parasoft test:
1281 //[2]A pointer parameter in a function prototype should be declared as pointer to const if the pointer is not used to modify the addressed object (JSF-118-4)
1282 pOutputCtrl->bEnable += 0;
1283 }
1284
MDrv_VE_SetOutputCtrl(PMS_VE_Output_Ctrl pOutputCtrl)1285 void MDrv_VE_SetOutputCtrl(PMS_VE_Output_Ctrl pOutputCtrl)
1286 {
1287 #if TVENCODER_UTOPIA2
1288 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1289 PTVE_SETOUTPUTCTRL pArgs = NULL;
1290 if(pu32TvencoderInst == NULL)
1291 {
1292 return ;
1293 }
1294 pArgs = (PTVE_SETOUTPUTCTRL)malloc(sizeof(TVE_SETOUTPUTCTRL));
1295
1296 if(NULL == pArgs)
1297 return ;
1298 pArgs->pOutputCtrl = pOutputCtrl;
1299 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SetOutputCtrl, (void*)pArgs);
1300 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1301 {
1302 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
1303 }
1304 free(pArgs);
1305 #else
1306 _MDrv_VE_SetOutputCtrl(pOutputCtrl);
1307 #endif
1308 }
1309 //------------------------------------------------------------------------------
1310 /// set the output video standard of video encoder
1311 ///
1312 /// @param -VideoSystem \b IN: the video standard
1313 /// @return TRUE: supported and success, FALSE: unsupported or unsuccess
1314 //------------------------------------------------------------------------------
_MDrv_VE_SetOutputVideoStd(MS_VE_VIDEOSYS VideoSystem)1315 MS_BOOL _MDrv_VE_SetOutputVideoStd(MS_VE_VIDEOSYS VideoSystem)
1316 {
1317 MS_BOOL bRet;
1318 MSG_DRV_VE("VE Standard: VideoSystem=%d\n", VideoSystem);
1319 g_VEInfo.VideoSystem = VideoSystem;
1320
1321 bRet = Hal_VE_set_output_video_std(VideoSystem);
1322
1323 return bRet;
1324 }
1325
MDrv_VE_SetOutputVideoStd(MS_VE_VIDEOSYS VideoSystem)1326 MS_BOOL MDrv_VE_SetOutputVideoStd(MS_VE_VIDEOSYS VideoSystem)
1327 {
1328 #if TVENCODER_UTOPIA2
1329 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1330 PTVE_SETOUTPUTVIDEOSTD pArgs = NULL;
1331 if(pu32TvencoderInst == NULL)
1332 {
1333 return FALSE;
1334 }
1335 pArgs = (PTVE_SETOUTPUTVIDEOSTD)malloc(sizeof(TVE_SETOUTPUTVIDEOSTD));
1336
1337 if(NULL == pArgs)
1338 return FALSE;
1339 pArgs->VideoSystem = VideoSystem;
1340 pArgs->eRet = E_TVENCODER_FAIL;
1341
1342 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SetOutputVideoStd, (void*)pArgs);
1343 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1344 {
1345 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
1346 }
1347
1348 if(E_TVENCODER_OK == pArgs->eRet)
1349 {
1350 free(pArgs);
1351 return TRUE;
1352 }
1353 else
1354 {
1355 free(pArgs);
1356 return FALSE;
1357 }
1358 #else
1359 return _MDrv_VE_SetOutputVideoStd(VideoSystem);
1360 #endif
1361 }
1362
1363 #define END_OF_CUS_TABLE_VALUE 0xffffff
1364 #define COLUMN_NUM_OF_ONE_CUS_CMD 4
_MDrv_VE_SetCusTable(MS_VE_VIDEOSYS VideoSystem,MS_U8 * pTbl)1365 MS_BOOL _MDrv_VE_SetCusTable(MS_VE_VIDEOSYS VideoSystem, MS_U8* pTbl)
1366 {
1367 if (pTbl == NULL)
1368 {
1369 printf("[%s] pTbl error\n.", __FUNCTION__);
1370 return FALSE;
1371 }
1372
1373 if(VideoSystem >= MS_VE_VIDEOSYS_NUM)
1374 {
1375 printf("[%s] VideoSystem error\n.", __FUNCTION__);
1376 return FALSE;
1377 }
1378
1379 MS_U32 u32Index = 0;
1380 MS_U16 u16Counter = 0;
1381 const MS_U16 u16Cols = COLUMN_NUM_OF_ONE_CUS_CMD;
1382 MS_BOOL bEnd = FALSE;
1383
1384 while (u16Counter*u16Cols < VE_CUSTBL_MAX_SIZE)
1385 {
1386 u16Counter++;
1387 u32Index = ((pTbl[u16Cols*u16Counter+0] << 16) + (pTbl[u16Cols*u16Counter+1] << 8) + pTbl[u16Cols*u16Counter+2]);
1388 if (u32Index == END_OF_CUS_TABLE_VALUE) // check end of table
1389 {
1390 bEnd = TRUE;
1391 break;
1392 }
1393 }
1394
1395 if(FALSE == bEnd)
1396 {
1397 printf("Error: [%s] Table size too large than VE_CUSTBL_MAX_SIZE = %d \n.", __FUNCTION__, VE_CUSTBL_MAX_SIZE);
1398 return FALSE;
1399 }
1400
1401 Hal_VE_SetCusTable(VideoSystem,pTbl,u16Counter*u16Cols);
1402
1403 return TRUE;
1404 }
1405
MDrv_VE_SetCusTable(MS_VE_VIDEOSYS VideoSystem,MS_U8 * pTbl)1406 MS_BOOL MDrv_VE_SetCusTable(MS_VE_VIDEOSYS VideoSystem, MS_U8* pTbl)
1407 {
1408 #if TVENCODER_UTOPIA2
1409 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1410 PTVE_SETCUSTABLE pArgs = NULL;
1411 if(pu32TvencoderInst == NULL)
1412 {
1413 return FALSE;
1414 }
1415 pArgs = (PTVE_SETCUSTABLE)malloc(sizeof(TVE_SETCUSTABLE));
1416
1417 if(NULL == pArgs)
1418 return FALSE;
1419 pArgs->VideoSystem = VideoSystem;
1420 pArgs->pTbl = pTbl;
1421 pArgs->eRet = E_TVENCODER_FAIL;
1422
1423 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_Set_CusTable, (void*)pArgs);
1424 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1425 {
1426 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
1427 }
1428
1429 if(E_TVENCODER_OK == pArgs->eRet)
1430 {
1431 free(pArgs);
1432 return TRUE;
1433 }
1434 else
1435 {
1436 free(pArgs);
1437 return FALSE;
1438 }
1439 #else
1440 return _MDrv_VE_SetCusTable(VideoSystem, pTbl);
1441 #endif
1442
1443 }
1444
_MDrv_VE_EnableCusTable(MS_BOOL bEnable)1445 void _MDrv_VE_EnableCusTable(MS_BOOL bEnable)
1446 {
1447 Hal_VE_EnableCusTable(bEnable);
1448 }
1449
MDrv_VE_EnableCusTable(MS_BOOL bEnable)1450 void MDrv_VE_EnableCusTable(MS_BOOL bEnable)
1451 {
1452 #if TVENCODER_UTOPIA2
1453 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1454 PTVE_ENABLECUSTABLE pArgs = NULL;
1455 if(pu32TvencoderInst == NULL)
1456 {
1457 return;
1458 }
1459 pArgs = (PTVE_ENABLECUSTABLE)malloc(sizeof(TVE_ENABLECUSTABLE));
1460
1461 if(NULL == pArgs)
1462 return ;
1463 pArgs->bEnable = bEnable;
1464
1465 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_EnableCusTable, (void*)pArgs);
1466 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1467 {
1468 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
1469 }
1470
1471 free(pArgs);
1472
1473 #else
1474 return _MDrv_VE_EnableCusTable(bEnable);
1475 #endif
1476
1477 }
1478
1479
_MDrv_VE_SetWSSData(MS_BOOL bEn,MS_U16 u16WSSData)1480 void _MDrv_VE_SetWSSData(MS_BOOL bEn, MS_U16 u16WSSData) // 071204
1481 {
1482 // MSG_DRV_VE("WSSData=%d, data=%u\n", bEn, u16WSSData));
1483 Hal_VE_set_wss_data(bEn, u16WSSData);
1484 }
1485
MDrv_VE_SetWSSData(MS_BOOL bEn,MS_U16 u16WSSData)1486 void MDrv_VE_SetWSSData(MS_BOOL bEn, MS_U16 u16WSSData)
1487 {
1488 #if TVENCODER_UTOPIA2
1489 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1490 PTVE_SETWSSDATA pArgs = NULL;
1491 if(pu32TvencoderInst == NULL)
1492 {
1493 return ;
1494 }
1495 pArgs = (PTVE_SETWSSDATA)malloc(sizeof(TVE_SETWSSDATA));
1496
1497 if(NULL == pArgs)
1498 return ;
1499 pArgs->bEn = bEn;
1500 pArgs->u16WSSData = u16WSSData;
1501 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SetWSSData, (void*)pArgs);
1502 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1503 {
1504 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
1505 }
1506 free(pArgs);
1507 #else
1508 _MDrv_VE_SetWSSData(bEn, u16WSSData);
1509 #endif
1510 }
1511
_MDrv_VE_GetWSSData(void)1512 MS_U16 _MDrv_VE_GetWSSData(void)
1513 {
1514 return Hal_VE_get_wss_data();
1515 }
1516
MDrv_VE_GetWSSData(void)1517 MS_U16 MDrv_VE_GetWSSData(void)
1518 {
1519 #if TVENCODER_UTOPIA2
1520 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1521 TVE_GETWSSDATA pArgs;
1522 if(pu32TvencoderInst == NULL)
1523 {
1524 return 0xFF;
1525 }
1526
1527 memset(&pArgs, 0, sizeof(TVE_GETWSSDATA));
1528 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_GetWSSData, (void*)&pArgs);
1529 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1530 {
1531 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
1532 }
1533
1534 return pArgs.u16WSSData;
1535 #else
1536 return _MDrv_VE_GetWSSData();
1537 #endif
1538 }
1539 //Small adjust Hratio for HW design rule:
1540 //tmp = ratio*input pixel, then tmp[31:11] = Number of output pixel, must adjust ratio to make this value even
1541 //Ex : ratio = 0x155, input pixel = 1920, tmp = 0x9FD80, here tmp[11]=1,then set ratio=ratio+1
1542 #define MAX_TRY_HRATIOAROUND 100
MDrv_VE_HRatioAround(MS_U16 * pu16In_Hsize,MS_U32 * pu32H_Ratio)1543 void MDrv_VE_HRatioAround(MS_U16 *pu16In_Hsize, MS_U32 *pu32H_Ratio)
1544 {
1545 MS_U32 u32OutputPixel;
1546 MS_U8 i = 0;
1547 do
1548 {
1549 i++;
1550 u32OutputPixel = *pu16In_Hsize * (*pu32H_Ratio+i);
1551 }while((u32OutputPixel & BIT(11)) && (i<MAX_TRY_HRATIOAROUND));
1552
1553 if(i < MAX_TRY_HRATIOAROUND)
1554 {
1555 if(i != 0)
1556 {
1557 *pu32H_Ratio +=i;
1558 MSG_DRV_VE("VE Scaling: HRatio Around=%d\n", (int)*pu32H_Ratio);
1559 }
1560 }
1561 else
1562 {
1563 printf("!!!Alert: VE HRatio Around fail!!!\n");
1564 }
1565
1566 //workaround to pass parasoft test:
1567 //[2]A pointer parameter in a function prototype should be declared as pointer to const if the pointer is not used to modify the addressed object (JSF-118-4)
1568 *pu16In_Hsize += 0;
1569 }
1570
_MDrv_VE_Set_Customer_Scaling(MS_VE_CusScalingInfo * pstVECusScalingInfo)1571 VE_Result _MDrv_VE_Set_Customer_Scaling(MS_VE_CusScalingInfo *pstVECusScalingInfo)
1572 {
1573 memcpy(&g_VEInfo.stVECusScalingInfo, pstVECusScalingInfo, sizeof(MS_VE_CusScalingInfo));
1574 return E_VE_OK;
1575 }
1576
MDrv_VE_Set_Customer_Scaling(MS_VE_CusScalingInfo * pstVECusScalingInfo)1577 VE_Result MDrv_VE_Set_Customer_Scaling(MS_VE_CusScalingInfo *pstVECusScalingInfo)
1578 {
1579 #if TVENCODER_UTOPIA2
1580 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1581 PTVE_SETCUSSCALING pArgs = NULL;
1582 if(pu32TvencoderInst == NULL)
1583 {
1584 return E_VE_FAIL;
1585 }
1586 pArgs = (PTVE_SETCUSSCALING)malloc(sizeof(TVE_SETCUSSCALING));
1587
1588 if(NULL == pArgs)
1589 return E_VE_FAIL;
1590 pArgs->pstVECusScalingInfo = pstVECusScalingInfo;
1591 pArgs->eRet = E_TVENCODER_FAIL;
1592
1593 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_Set_Customer_Scaling, (void*)pArgs);
1594 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1595 {
1596 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
1597 }
1598
1599 if(E_TVENCODER_FAIL == pArgs->eRet)
1600 {
1601 free(pArgs);
1602 return E_VE_FAIL;
1603 }
1604 else
1605 {
1606 free(pArgs);
1607 return E_VE_OK;
1608 }
1609 #else
1610 return MDrv_VE_Set_Customer_Scaling(pstVECusScalingInfo);
1611 #endif
1612 }
1613
MDrv_VE_set_scaling_ratio(MS_U16 u16Out_Hsize,MS_U16 u16Out_Vsize)1614 void MDrv_VE_set_scaling_ratio(MS_U16 u16Out_Hsize, MS_U16 u16Out_Vsize)
1615 {
1616 MS_U32 u32H_Ratio = 0, u32V_Ratio = 0;
1617 MS_U16 u16In_Vsize, u16In_Hsize;
1618
1619 if(g_VEInfo.stVECusScalingInfo.bHCusScalingEnable==ENABLE)
1620 {
1621 u16In_Hsize = g_VEInfo.stVECusScalingInfo.u16HScalingsrc;
1622 u16Out_Hsize= g_VEInfo.stVECusScalingInfo.u16HScalingdst;
1623 }
1624 else
1625 {
1626 #ifdef VE_SOURCE_AFTER_DI
1627 if (g_VEInfo.bHDuplicate)
1628 {
1629 u16In_Hsize = g_VEInfo.u16H_CapSize/2; //MApi_XC_R2BYTE(_SC_PK_L_(0x12, 0x1F)); //hsize_in
1630 }
1631 else
1632 {
1633 u16In_Hsize = g_VEInfo.u16H_CapSize;
1634 }
1635 #else
1636 u16In_Hsize = g_VEInfo.u16H_CapSize;
1637 #endif
1638 }
1639 if(g_VEInfo.stVECusScalingInfo.bVCusScalingEnable==ENABLE)
1640 {
1641 u16In_Vsize = g_VEInfo.stVECusScalingInfo.u16VScalingsrc;
1642 u16Out_Vsize= g_VEInfo.stVECusScalingInfo.u16VScalingdst;
1643 }
1644 else
1645 {
1646 u16In_Vsize = g_VEInfo.u16V_CapSize;
1647 }
1648 MSG_DRV_VE("VE Scaling: bHCusScaling=%u, bVCusScaling=%u, In_Hsize =%d, In_Vsize = %d, Out_Hsize =%d, Out_Vsize = %d,\n",
1649 g_VEInfo.stVECusScalingInfo.bHCusScalingEnable, g_VEInfo.stVECusScalingInfo.bVCusScalingEnable, u16In_Hsize, u16In_Vsize, u16Out_Hsize, u16Out_Vsize);
1650
1651 // for Monaco 4kx2k or from OP case
1652 Hal_VE_Set_PreHSD(g_VEInfo.InputSrcType,&u16In_Hsize,&u16In_Vsize);
1653
1654 if(u16Out_Hsize != u16In_Hsize)
1655 {
1656 if(u16In_Hsize > u16Out_Hsize)
1657 {
1658 if((g_VEInfo.InputSrcType == MS_VE_SRC_SCALER) && VE_PRESCALE_SUPPORT)
1659 {
1660 _PreHscaleDown(ENABLE, u16In_Hsize, u16Out_Hsize);
1661 Hal_VE_set_h_scaling(DISABLE, 0x0000);
1662 }
1663 else
1664 {
1665 u32H_Ratio = (MS_U16)VE_H_SCALE_DOWN_RATIO(u16In_Hsize, u16Out_Hsize);
1666 MDrv_VE_HRatioAround(&u16In_Hsize, &u32H_Ratio);
1667 Hal_VE_set_h_scaling(ENABLE, u32H_Ratio);
1668 }
1669
1670 if (g_VECap.bSupport_UpScale)
1671 {
1672 #ifdef VE_SOURCE_AFTER_DI
1673 Hal_VE_set_h_upscaling(ENABLE, 0x100000); // set to no-scale
1674 #else
1675 Hal_VE_set_h_upscaling(ENABLE, 0x10000); // set to no-scale
1676 #endif
1677 }
1678 }
1679 else
1680 {
1681 if (!g_VECap.bSupport_UpScale)
1682 {
1683 //VE not support upscale,just bypass it
1684 if(g_VEInfo.u16H_CapSize ==544)//DVB DTV 544x576 needs fine tune by hand
1685 {
1686 Hal_VE_set_h_scaling(ENABLE, 0x7FF);
1687 }
1688 else
1689 {
1690 _PreHscaleDown(DISABLE, u16In_Hsize, u16Out_Hsize);
1691 Hal_VE_set_h_scaling(DISABLE, 0x0000);
1692 }
1693 }
1694 else
1695 {
1696 //do h upscale
1697 u32H_Ratio = VE_H_SCALE_UP_RATIO(u16In_Hsize, u16Out_Hsize);
1698 Hal_VE_set_h_upscaling(ENABLE, u32H_Ratio);
1699
1700 _PreHscaleDown(DISABLE, u16In_Hsize, u16Out_Hsize);
1701 Hal_VE_set_h_scaling(DISABLE, 0x0000);
1702 MSG_DRV_VE("VE H upscale ratio: u32H_Ratio =%d\n", (int)u32H_Ratio);
1703 }
1704 }
1705 }
1706 else
1707 {
1708 _PreHscaleDown(DISABLE, u16In_Hsize, u16Out_Hsize);
1709 Hal_VE_set_h_scaling(DISABLE, 0x0000);
1710 if (g_VECap.bSupport_UpScale)
1711 {
1712 #ifdef VE_SOURCE_AFTER_DI
1713 Hal_VE_set_h_upscaling(ENABLE, 0x100000); // set to no-scale
1714 #else
1715 Hal_VE_set_h_upscaling(ENABLE, 0x10000); // set to no-scale
1716 #endif
1717 }
1718 }
1719
1720 if(u16Out_Vsize != u16In_Vsize)
1721 {
1722 if(u16In_Vsize > u16Out_Vsize)
1723 {
1724 if((g_VEInfo.InputSrcType == MS_VE_SRC_SCALER) && VE_PRESCALE_SUPPORT)
1725 {
1726 _PreVscaleDown(ENABLE, u16In_Vsize, u16Out_Vsize);
1727 Hal_VE_set_v_scaling(DISABLE, 0x0000);
1728 }
1729 else
1730 {
1731 u32V_Ratio = (MS_U16)VE_V_SCALE_DOWN_RATIO(u16In_Vsize, u16Out_Vsize);
1732
1733 Hal_VE_set_v_initfactor(g_VEInfo.bSrcInterlace,u32V_Ratio);
1734
1735 if(g_VEInfo.stVECusScalingInfo.bVCusScalingEnable==ENABLE)
1736 {
1737 Hal_VE_set_v_scaling(ENABLE, u32V_Ratio);//For customer scaling, just set it as requested
1738 }
1739 else
1740 {
1741 Hal_VE_set_v_scaling_Traditional(ENABLE, u32V_Ratio);//For traditional V scaling, need considering the recevier's overscan
1742 }
1743 }
1744
1745 if (g_VECap.bSupport_UpScale)
1746 {
1747 Hal_VE_set_v_upscaling(ENABLE, 0x10000);
1748 }
1749 }
1750 else
1751 {
1752 if (!g_VECap.bSupport_UpScale)
1753 {
1754 //VE not support upscale,just bypass it
1755 Hal_VE_set_v_scaling(DISABLE, 0x0000);
1756 _PreVscaleDown(DISABLE, u16In_Vsize, u16Out_Vsize);
1757 Hal_VE_set_v_initfactor(g_VEInfo.bSrcInterlace,u32V_Ratio);
1758 }
1759 else
1760 {
1761 //do v upscale
1762 u32V_Ratio = VE_V_SCALE_UP_RATIO(u16In_Vsize, u16Out_Vsize);
1763 Hal_VE_set_v_upscaling(ENABLE, u32V_Ratio);
1764
1765 _PreVscaleDown(DISABLE, u16In_Vsize, u16Out_Vsize);
1766 Hal_VE_set_v_scaling(DISABLE, 0x0000);
1767 MSG_DRV_VE("VE V upscale ratio: u32V_Ratio =%d\n", (int)u32V_Ratio);
1768 }
1769 }
1770 }
1771 else
1772 {
1773 if(g_VEInfo.u16H_CapSize ==544)//DVB DTV 544x576 needs fine tune by hand
1774 {
1775 Hal_VE_set_v_scaling(ENABLE, 0x0750);
1776 }
1777 else
1778 {
1779 _PreVscaleDown(DISABLE, u16In_Vsize, u16Out_Vsize);
1780 Hal_VE_set_v_scaling(DISABLE, 0x0000);
1781 if (g_VECap.bSupport_UpScale)
1782 {
1783 Hal_VE_set_v_upscaling(ENABLE, 0x10000);
1784 }
1785 }
1786 Hal_VE_set_v_initfactor(g_VEInfo.bSrcInterlace,u32V_Ratio);
1787 }
1788 MSG_DRV_VE("VE Scaling: u32H_Ratio =%d, u32V_Ratio = %d \n", (int)u32H_Ratio, (int)u32V_Ratio);
1789 }
1790
1791 //------------------------------------------------------------------------------
1792 /// VE Set display windows
1793 /// @return none
1794 //------------------------------------------------------------------------------
_MDrv_VE_set_display_window(MS_VE_WINDOW_TYPE stDispWin)1795 void _MDrv_VE_set_display_window(MS_VE_WINDOW_TYPE stDispWin)
1796 {
1797 MS_U16 u16Out_Hsize= (((g_VEInfo.bHDuplicate) && (g_VEInfo.InputSrcType == MS_VE_SRC_DTV)) ? 704 : 720);
1798 MS_U16 u16Out_Vsize = ((g_VEInfo.VideoSystem <= MS_VE_PAL_M) ? 480 : 576);
1799 MS_PHY phyMIUOffsetAddr = 0;
1800
1801 //Check display window location and size.
1802 if(stDispWin.x > u16Out_Hsize) {stDispWin.x = 0 ; MSG_DRV_VE("x >> width,please check x range \n");}
1803 if(stDispWin.y > u16Out_Vsize) {stDispWin.y = 0 ; MSG_DRV_VE("y >> height,please check y range \n");}
1804 if(stDispWin.x + stDispWin.width > u16Out_Hsize) {stDispWin.width = u16Out_Hsize ; MSG_DRV_VE("width >> Hsize,please check width size \n");}
1805 if(stDispWin.y + stDispWin.height > u16Out_Vsize) {stDispWin.height = u16Out_Vsize ; MSG_DRV_VE("height >> Vsize,please check height size \n");}
1806 MSG_DRV_VE("VE Set Display Window: x/y/w/h = %u, %u, %u, %u\n", stDispWin.x, stDispWin.y, stDispWin.width, stDispWin.height);
1807
1808 if(MApi_VE_R2BYTE_MSK(MS_VE_REG_BANK_3B, 0x35, BIT(3)) == 0)
1809 {
1810 stDispWin.y /=2;
1811 }
1812 phyMIUOffsetAddr = 2 * (stDispWin.x + stDispWin.y * u16Out_Hsize);
1813 MDrv_VE_set_scaling_ratio(stDispWin.width,stDispWin.height);
1814 phyMIUOffsetAddr += g_VEInfo.phyMiuBaseAddr;
1815 Hal_VE_Set_winodw_offset(phyMIUOffsetAddr);
1816 }
1817
MDrv_VE_set_display_window(MS_VE_WINDOW_TYPE stDispWin)1818 void MDrv_VE_set_display_window(MS_VE_WINDOW_TYPE stDispWin)
1819 {
1820 #if TVENCODER_UTOPIA2
1821 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1822 PTVE_SETDISPLAYWIN pArgs = NULL;
1823 if(pu32TvencoderInst == NULL)
1824 {
1825 return;
1826 }
1827 pArgs = (PTVE_SETDISPLAYWIN)malloc(sizeof(TVE_SETDISPLAYWIN));
1828
1829 if(NULL == pArgs)
1830 return ;
1831 pArgs->stDispWin = stDispWin;
1832 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_set_display_window, (void*)pArgs);
1833 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1834 {
1835 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
1836 }
1837 free(pArgs);
1838 #else
1839 _MDrv_VE_set_display_window(stDispWin);
1840 #endif
1841 }
1842 //------------------------------------------------------------------------------
1843 /// @brief VE be set display window (backend), after MIU
1844 ///
1845 /// @argument:
1846 // - MS_VE_WINDOW_TYPE - display window
1847 /// @return VE_Result
1848 //------------------------------------------------------------------------------
MDrv_VE_set_be_display_window(MS_VE_WINDOW_TYPE stDispWin)1849 VE_Result MDrv_VE_set_be_display_window(MS_VE_WINDOW_TYPE stDispWin)
1850 {
1851 MS_U16 u16Out_Hsize= (((g_VEInfo.bHDuplicate) && (g_VEInfo.InputSrcType == MS_VE_SRC_DTV)) ? 704 : 720);
1852 MS_U16 u16Out_Vsize = ((g_VEInfo.VideoSystem <= MS_VE_PAL_M) ? 480 : 576);
1853 VE_Result ret = E_VE_OK;
1854
1855 if (!g_VECap.bSupport_CropMode) {
1856 MSG_DRV_VE("[%s] is not supported in this chip\n",
1857 __FUNCTION__);
1858 ret = E_VE_NOT_SUPPORT;
1859 goto fail;
1860 }
1861
1862 //Check display window location and size.
1863 if(stDispWin.x > u16Out_Hsize) {
1864 MSG_DRV_VE("x >> width,please check x range \n");
1865 ret = E_VE_FAIL;
1866 goto fail;
1867 }
1868 if(stDispWin.y > u16Out_Vsize) {
1869 MSG_DRV_VE("y >> height,please check y range \n");
1870 ret = E_VE_FAIL;
1871 goto fail;
1872 }
1873 if(stDispWin.x + stDispWin.width > u16Out_Hsize) {
1874 MSG_DRV_VE("width >> Hsize,please check width size \n");
1875 ret = E_VE_FAIL;
1876 goto fail;
1877 }
1878 if(stDispWin.y + stDispWin.height > u16Out_Vsize) {
1879 MSG_DRV_VE("height >> Vsize,please check height size \n");
1880 ret = E_VE_FAIL;
1881 goto fail;
1882 }
1883
1884 // Width of VE Display window should be even number, otherwise video will be wavy and some strange dotted lines will appear.
1885 if((stDispWin.width & 0x1) == 0x1)
1886 {
1887 stDispWin.width = stDispWin.width + 1;
1888 }
1889
1890 MSG_DRV_VE("VE Set Display Window: x/y/w/h = %u, %u, %u, %u\n", stDispWin.x, stDispWin.y, stDispWin.width, stDispWin.height);
1891
1892 MDrv_VE_set_scaling_ratio(stDispWin.width, stDispWin.height);
1893 Hal_VE_Set_HScale_Output_Line_Number(stDispWin.width);
1894 Hal_VE_Set_VScale_Output_Line_Number((stDispWin.height) / 2); // field size
1895 Hal_VE_Set_Crop_OSD_Offset(stDispWin.x, (stDispWin.y / 2)); // field size
1896
1897 return E_VE_OK;
1898 fail:
1899 printf("Error: [%s] failed, errno: %d\n", __FUNCTION__, ret);
1900 return ret;
1901 }
1902
MDrv_VE_set_frc(MS_U16 u16VInputFreq)1903 void MDrv_VE_set_frc(MS_U16 u16VInputFreq)
1904 {
1905 MS_U32 u32FullNum, u32EmptyNum;
1906 MS_U32 u32FrameSize;
1907 MS_U16 u16Out_FR, u16In_FR;
1908 MS_U16 b3FrameMode = FALSE;
1909 g_VEInfo.u16inputVfreq = u16VInputFreq;
1910 if(g_VEInfo.VideoSystem <= MS_VE_PAL_M)
1911 {
1912 u32FrameSize = VE_NTSC_FRAME_SIZE;
1913 u16Out_FR = 2997;
1914 }
1915 else
1916 {
1917 u32FrameSize = VE_PAL_FRAME_SIZE;
1918 u16Out_FR = 2500;
1919 }
1920 if(g_VEInfo.bVECapture)
1921 {
1922 //FrameSize = 720*Height*2/MIU Length
1923 u32FrameSize = (720*g_VEInfo.u16Outputheight/(BYTE_PER_WORD>>1));//The pitch is always 720pixel for VE
1924 Hal_VE_set_field_size(u32FrameSize/2);
1925 }
1926 u16In_FR = (u16VInputFreq*10/2) ;
1927 MSG_DRV_VE("---VE: InputVFreq=%u, In_FR=%u, Out_FR=%u\n", u16VInputFreq, u16In_FR, u16Out_FR);
1928 if(g_VEInfo.bVECapture)
1929 {
1930 if(g_VEInfo.u32MemSize/3 >= u32FrameSize*BYTE_PER_WORD)
1931 {
1932 b3FrameMode = TRUE;
1933 }
1934 Hal_VE_set_frc(DISABLE, 0xFFFF, 0, g_VEInfo.bSrcInterlace, b3FrameMode);
1935 }
1936 #ifdef VE_NEW_FRC_SETTING
1937 //Suggest to use 4-field buffer mode for normal case (input frame rate is almost same as output frame rate)
1938 //Suggest to use 3-frame buffer mode for special case (input frame rate is lower than output frame rate)
1939 else if((!g_VEInfo.bSrcInterlace)&&(u16In_FR<(u16Out_FR - VE_FRC_TOLERANT))&&(u16In_FR>(u16Out_FR + VE_FRC_TOLERANT)))
1940 {
1941 if(g_VEInfo.u32MemSize/3 >= u32FrameSize*BYTE_PER_WORD)
1942 {
1943 b3FrameMode = TRUE;
1944 }
1945
1946 if(b3FrameMode)
1947 {
1948 u32FullNum = 2*u32FrameSize;
1949 u32EmptyNum = u32FrameSize;
1950 }
1951 else // 2 framemode
1952 {
1953 u32FullNum = u32FrameSize;
1954 u32EmptyNum = u32FrameSize;
1955 }
1956 Hal_VE_set_frc(ENABLE, u32FullNum, u32EmptyNum, g_VEInfo.bSrcInterlace, b3FrameMode);
1957 }
1958 else
1959 {
1960 u32FullNum = u32FrameSize * 3/2;
1961 u32EmptyNum = u32FrameSize / 2;
1962
1963 Hal_VE_set_frc(ENABLE, u32FullNum, u32EmptyNum, 1, b3FrameMode);
1964 }
1965 #else
1966 else if( ( u16In_FR > (u16Out_FR - VE_FRC_TOLERANT) ) && ( u16In_FR<(u16Out_FR + VE_FRC_TOLERANT) ) )
1967 {
1968 // Default always to enable FRC (avoid tearing)
1969 u32FullNum = u32FrameSize * 3/2;
1970 u32EmptyNum = u32FrameSize / 2;
1971 #if defined (__aarch64__)
1972 MSG_DRV_VE("---VE: default ENABLE FRC,u32FullNum=%u, u32EmptyNum=%u\n", u32FullNum, u32EmptyNum);
1973 #else
1974 MSG_DRV_VE("---VE: default ENABLE FRC,u32FullNum=%tu, u32EmptyNum=%tu\n",(ptrdiff_t) u32FullNum,(ptrdiff_t) u32EmptyNum);
1975 #endif
1976 Hal_VE_set_frc(ENABLE, u32FullNum, u32EmptyNum, g_VEInfo.bSrcInterlace, b3FrameMode);
1977 }
1978 //#endif
1979 else if(u16In_FR < u16Out_FR)
1980 {
1981 u32FullNum = u32FrameSize * 19 / 10 ;
1982 u32EmptyNum = (MS_U32)(u16Out_FR - u16In_FR) * u32FrameSize / (MS_U32)u16Out_FR ;
1983 #if defined (__aarch64__)
1984 MSG_DRV_VE("---VE: Enable FRC, u32FullNum=%u, u32EmptyNum=%u\n", u32FullNum, u32EmptyNum);
1985 #else
1986 MSG_DRV_VE("---VE: Enable FRC, u32FullNum=%tu, u32EmptyNum=%tu\n",(ptrdiff_t) u32FullNum,(ptrdiff_t) u32EmptyNum);
1987 #endif
1988 Hal_VE_set_frc(ENABLE, u32FullNum, u32EmptyNum, g_VEInfo.bSrcInterlace, b3FrameMode);
1989 }
1990 else
1991 {
1992 u32FullNum = u32FrameSize +
1993 ((MS_U32)u16Out_FR * u32FrameSize / u16In_FR);
1994 u32EmptyNum = u32FrameSize / 10 ;
1995 #if defined (__aarch64__)
1996 MSG_DRV_VE("---VE: Enable FRC, u32FullNum=%u, u32EmptyNum=%u\n", u32FullNum, u32EmptyNum);
1997 #else
1998 MSG_DRV_VE("---VE: Enable FRC, u32FullNum=%tu, u32EmptyNum=%tu\n",(ptrdiff_t) u32FullNum,(ptrdiff_t) u32EmptyNum);
1999 #endif
2000 Hal_VE_set_frc(ENABLE, u32FullNum, u32EmptyNum, g_VEInfo.bSrcInterlace, b3FrameMode);
2001 }
2002 #endif
2003 #if defined (__aarch64__)
2004 MSG_DRV_VE("---VE: bVECapture=%u, u32FrameSize=%u, b3FrameMode=%u\n", g_VEInfo.bVECapture, u32FrameSize, b3FrameMode);
2005 #else
2006 MSG_DRV_VE("---VE: bVECapture=%u, u32FrameSize=%tu, b3FrameMode=%u\n", g_VEInfo.bVECapture,(ptrdiff_t) u32FrameSize, b3FrameMode);
2007 #endif
2008 }
2009
MDrv_VE_set_capture_window(void)2010 void MDrv_VE_set_capture_window(void)
2011 {
2012 MS_U16 u16Out_Vsize, u16Out_Hsize,u16V_CapSize=0;
2013 MS_U16 u16Tmp, u16Tmp2;
2014 MS_BOOL bVECManualCapWindow = FALSE;
2015
2016 if(((g_VEInfo.InputSrcType == MS_VE_SRC_SUB) || (g_VEInfo.InputSrcType == MS_VE_SRC_MAIN)) &&
2017 (g_VEInfo.InputSrcOfMixedSrc >= MS_VE_SRC_ATV) && (g_VEInfo.InputSrcOfMixedSrc <= MS_VE_SRC_SVIDEO)
2018 )
2019 {
2020 bVECManualCapWindow = TRUE; //For VD sources, need manual tune ve capture window in vec case
2021 }
2022
2023 if(g_VEInfo.bVECapture)
2024 {
2025 u16Out_Hsize = g_VEInfo.u16OutputWidth;
2026 u16Out_Vsize = g_VEInfo.u16Outputheight;
2027 }
2028 else if(!g_VEInfo.bForceCaptureMode)
2029 {
2030 u16Out_Hsize = ((g_VEInfo.InputSrcType == MS_VE_SRC_DTV) && (g_VEInfo.bHDuplicate)) ? 704 : 720;
2031 u16Out_Vsize = (g_VEInfo.VideoSystem <= MS_VE_PAL_M) ? 480 : 576;
2032 }
2033 else
2034 {
2035 u16Out_Hsize = g_VEInfo.u16H_CapSize;
2036 u16Out_Vsize = g_VEInfo.u16V_CapSize;
2037 }
2038
2039 if(g_VEInfo.InputSrcType == MS_VE_SRC_DI)
2040 {
2041 MSG_DRV_VE("VE InputSrcType = MS_VE_SRC_DI \n");
2042 u16Out_Hsize = g_VEInfo.u16H_CapSize;
2043 u16Out_Vsize = g_VEInfo.u16V_CapSize;
2044 }
2045
2046 g_VEInfo.u8VE_DisplayStatus &= ~(EN_VE_INVERSE_HSYNC);
2047
2048
2049 MSG_DRV_VE("Out: Hsize=%d, Vsize=%d \n", u16Out_Hsize, u16Out_Vsize);
2050 MSG_DRV_VE("VE Cap: Hstart=%d, Hsize =%d \n", g_VEInfo.u16H_CapStart, g_VEInfo.u16H_CapSize);
2051 //MSG_DRV_VE("SC Cap: Hstart=%d, Hsize =%d \n", g_SrcInfo.u16H_CapStart, g_SrcInfo.u16H_CapSize));
2052 MSG_DRV_VE("VE Cap: Vstart=%d, Vsize =%d \n", g_VEInfo.u16V_CapStart, g_VEInfo.u16V_CapSize);
2053 //MSG_DRV_VE("SC Cap: Vstart=%d, Vsize =%d \n", g_SrcInfo.u16V_CapStart, g_SrcInfo.u16V_CapSize));
2054 MSG_DRV_VE("[%s][%d]_gbIsCaptureMode = %d, bVECManualCapWindow=%d\n", __FUNCTION__, __LINE__, g_VEInfo.bForceCaptureMode, bVECManualCapWindow);
2055 if(bVECManualCapWindow == FALSE) //For normal AV output case
2056 {
2057 // Horizontal
2058 #if (ENABLE_VE_SUBTITLE)
2059 if((g_VEInfo.VideoSystem <= MS_VE_PAL_M) &&
2060 (g_VEInfo.u16V_CapSize <= 480))
2061 {
2062 u16Tmp2 = 0x17; //fine tune for ntsc 480i case, which is too left
2063 }
2064 else
2065 {
2066 u16Tmp2 = 0;
2067 }
2068
2069 if(g_VEInfo.u16H_CapSize < u16Out_Hsize)
2070 {
2071 #ifndef VE_SOURCE_AFTER_DI
2072 g_VEInfo.u8VE_DisplayStatus &= ~ EN_VE_DEMODE;
2073 #endif
2074 g_VEInfo.u8VE_DisplayStatus |= EN_VE_INVERSE_HSYNC;
2075
2076 u16Tmp = u16Out_Hsize - g_VEInfo.u16H_CapSize;
2077 g_VEInfo.u16H_CapStart = g_VEInfo.u16H_CapStart - u16Tmp/2 + u16Tmp2 + 9 ;
2078 #ifndef VE_SUPPORT_CROP
2079 g_VEInfo.u16H_CapSize = u16Out_Hsize;
2080 #endif
2081 MSG_DRV_VE("--1 temp %d, u16Tmp2 %d, H_start %d\n",u16Tmp,u16Tmp2,g_VEInfo.u16H_CapStart);
2082 }
2083 else if( ( g_VEInfo.u16H_CapSize == u16Out_Hsize ) &&
2084 ( g_VEInfo.u16H_CapSize > g_VEInfo.u16H_SC_CapSize )) //Same condition with Vsize
2085 {
2086 #ifndef VE_SOURCE_AFTER_DI
2087 g_VEInfo.u8VE_DisplayStatus &= ~ EN_VE_DEMODE;
2088 #endif
2089 g_VEInfo.u8VE_DisplayStatus |= EN_VE_INVERSE_HSYNC;
2090
2091 u16Tmp = g_VEInfo.u16H_CapSize - g_VEInfo.u16H_SC_CapSize;
2092 g_VEInfo.u16H_CapStart = g_VEInfo.u16H_SC_CapStart - u16Tmp/2 + u16Tmp2 + 9;
2093 MSG_DRV_VE("--2 temp %d, u16Tmp2 %d, H_start %d\n",u16Tmp, u16Tmp2, g_VEInfo.u16H_CapStart);
2094 }
2095 else
2096 {
2097 //g_VEInfo.u8VE_DisplayStatus &= ~ EN_VE_DEMODE;
2098 g_VEInfo.u8VE_DisplayStatus |= EN_VE_INVERSE_HSYNC;
2099
2100 u16Tmp = g_VEInfo.u16H_CapSize - g_VEInfo.u16H_SC_CapSize;
2101 g_VEInfo.u16H_CapStart = g_VEInfo.u16H_SC_CapStart - u16Tmp/2 + u16Tmp2 + 9;
2102 MSG_DRV_VE("--3 temp %d, u16Tmp2 %d , H_start %d\n",u16Tmp, u16Tmp2,g_VEInfo.u16H_CapStart);
2103 }
2104
2105 #else
2106 if(g_VEInfo.u16H_CapSize < u16Out_Hsize)
2107 {
2108 g_VEInfo.u8VE_DisplayStatus &= ~ EN_VE_DEMODE;
2109 g_VEInfo.u8VE_DisplayStatus |= EN_VE_INVERSE_HSYNC;
2110
2111 u16Tmp = u16Out_Hsize - g_VEInfo.u16H_CapSize;
2112 g_VEInfo.u16H_CapStart -= (u16Tmp/2);
2113 g_VEInfo.u16H_CapSize += u16Tmp;
2114 }
2115 #endif
2116
2117 // Vertical
2118 #if (ENABLE_VE_SUBTITLE)
2119 if((g_VEInfo.VideoSystem <= MS_VE_PAL_M) &&
2120 (g_VEInfo.u16V_CapSize <= 480))
2121 {
2122 if(g_VEInfo.bSrcInterlace)
2123 {
2124 u16Tmp2 = 0x11; //fine tune for ntsc 480i case, which will leave a black band on the bottom
2125 }
2126 else
2127 {
2128 u16Tmp2 = 0x5; //fine tune for ntsc 480p case, which will leave a black band on the bottom
2129 }
2130 }
2131 else if((g_VEInfo.VideoSystem <= MS_VE_PAL_M) &&
2132 (g_VEInfo.u16V_CapSize <= 720))
2133 {
2134 u16Tmp2 = 0x9; //fine tune for ntsc 720p case, which will leave a black band on the bottom
2135 }
2136 else if((g_VEInfo.VideoSystem <= MS_VE_PAL_M) &&
2137 (g_VEInfo.u16V_CapSize <= 1080))
2138 {
2139 u16Tmp2 = 0x9; //fine tune for ntsc 1080i case, which will leave a black band on the bottom
2140 }
2141 else
2142 {
2143 u16Tmp2 = 0;
2144 }
2145
2146 if(g_VEInfo.u16V_CapSize < u16Out_Vsize)
2147 {
2148 g_VEInfo.u8VE_DisplayStatus &= ~ EN_VE_DEMODE;
2149 g_VEInfo.u8VE_DisplayStatus |= EN_VE_INVERSE_HSYNC;
2150
2151 u16Tmp = u16Out_Vsize - g_VEInfo.u16V_CapSize;
2152 if(g_VEInfo.u16V_CapStart > u16Tmp/2 + u16Tmp2)
2153 {
2154 g_VEInfo.u16V_CapStart = g_VEInfo.u16V_CapStart - u16Tmp/2 - u16Tmp2;
2155 }
2156 else
2157 {
2158 g_VEInfo.u16V_CapStart = 0;
2159 }
2160 g_VEInfo.u16V_CapSize = u16Out_Vsize;
2161 MSG_DRV_VE("--1 temp %d, u16Tmp2 %d, V_start %d\n",u16Tmp,u16Tmp2,g_VEInfo.u16V_CapStart);
2162 }
2163 else if( ( g_VEInfo.u16V_CapSize == u16Out_Vsize ) &&
2164 ( g_VEInfo.u16V_CapSize > g_VEInfo.u16V_SC_CapSize ))
2165 {
2166 g_VEInfo.u8VE_DisplayStatus &= ~ EN_VE_DEMODE;
2167 g_VEInfo.u8VE_DisplayStatus |= EN_VE_INVERSE_HSYNC;
2168
2169 u16Tmp = g_VEInfo.u16V_CapSize - g_VEInfo.u16V_SC_CapSize;
2170 if(g_VEInfo.u16V_SC_CapStart > u16Tmp/2 + u16Tmp2)
2171 {
2172 g_VEInfo.u16V_CapStart = g_VEInfo.u16V_SC_CapStart - u16Tmp/2 - u16Tmp2;
2173 }
2174 else
2175 {
2176 g_VEInfo.u16V_CapStart = 0;
2177 }
2178 MSG_DRV_VE("--2 temp %d, u16Tmp2 %d, V_start %d\n",u16Tmp,u16Tmp2,g_VEInfo.u16V_CapStart);
2179 }
2180 else
2181 {
2182 //g_VEInfo.u8VE_DisplayStatus &= ~ EN_VE_DEMODE;
2183 g_VEInfo.u8VE_DisplayStatus |= EN_VE_INVERSE_HSYNC;
2184 u16Tmp = g_VEInfo.u16V_CapSize - g_VEInfo.u16V_SC_CapSize;
2185
2186 MSG_DRV_VE("--g_VEInfo.u16V_CapStart %x\n",g_VEInfo.u16V_CapStart);
2187 MSG_DRV_VE("--u16Tmp %d, u16Tmp2 %d\n",u16Tmp, u16Tmp2);
2188 if(g_VEInfo.u16V_SC_CapStart > (u16Tmp/2 + u16Tmp2))
2189 {
2190 g_VEInfo.u16V_CapStart = g_VEInfo.u16V_SC_CapStart - u16Tmp/2 - u16Tmp2;
2191 }
2192 else
2193 {
2194 g_VEInfo.u16V_CapStart = 0;
2195 }
2196 MSG_DRV_VE("--3 temp %d , u16Tmp2 %d, V_start %d\n",u16Tmp, u16Tmp2 ,g_VEInfo.u16V_CapStart);
2197 }
2198
2199 MSG_DRV_VE("--u16V_CapEnd %d\n",g_VEInfo.u16V_CapStart + g_VEInfo.u16V_CapSize - 1);
2200
2201 if(g_VEInfo.u16V_CapStart> (g_VEInfo.u16V_CapStart + g_VEInfo.u16V_CapSize - 1))
2202 {
2203 Hal_VE_set_cvbs_buffer_out(0x0F,0x00, 0x00, 0x00);//disable
2204 }
2205 #else
2206 if(g_VEInfo.u16V_CapSize < u16Out_Vsize)
2207 {
2208 g_VEInfo.u8VE_DisplayStatus &= ~ EN_VE_DEMODE;
2209 g_VEInfo.u8VE_DisplayStatus |= EN_VE_INVERSE_HSYNC;
2210
2211 u16Tmp = u16Out_Vsize - g_VEInfo.u16V_CapSize;
2212 g_VEInfo.u16V_CapStart -= (u16Tmp/2);
2213 g_VEInfo.u16V_CapSize += u16Tmp;
2214 }
2215 if(g_VEInfo.u16V_CapStart > (g_VEInfo.u16V_CapStart + g_VEInfo.u16V_CapSize - 1))
2216 Hal_VE_set_cvbs_buffer_out(0x0F,0x00, 0x00, 0x00);//disable
2217 #endif
2218 }
2219
2220 MSG_DRV_VE("VE status=%x \n", g_VEInfo.u8VE_DisplayStatus);
2221 MSG_DRV_VE("VE Cap: Hstart=%d, Hsize =%d \n", g_VEInfo.u16H_CapStart, g_VEInfo.u16H_CapSize);
2222 MSG_DRV_VE("VE Cap: Vstart=%d, Vsize =%d \n", g_VEInfo.u16V_CapStart, g_VEInfo.u16V_CapSize);
2223
2224 /*
2225 For input source is component and HDMI all use DE mode.
2226 */
2227 if((g_VEInfo.InputSrcType >= MS_VE_SRC_COMP) && (g_VEInfo.InputSrcType <= MS_VE_SRC_HDMI_C))
2228 {
2229 g_VEInfo.u8VE_DisplayStatus |= EN_VE_DEMODE;
2230 }
2231
2232 #if 1
2233 if(g_VEInfo.bSrcInterlace)
2234 {
2235 u16V_CapSize = g_VEInfo.u16V_CapSize / 2;
2236 MSG_DRV_VE("VE Cap: Interlace mode, Change Vsize =%d \n", u16V_CapSize);
2237 }
2238 else
2239 {
2240 u16V_CapSize = g_VEInfo.u16V_CapSize;
2241 }
2242 #ifdef VE_SUPPORT_CROP
2243 if(!(g_VEInfo.u8VE_DisplayStatus & EN_VE_DEMODE))
2244 {
2245 g_VEInfo.u8VE_DisplayStatus |= EN_VE_DEMODE;
2246 if(g_VEInfo.u16V_CapSize < u16Out_Vsize)
2247 {
2248 u16Tmp = (u16Out_Vsize-g_VEInfo.u16V_CapSize)/2;
2249 }
2250 else
2251 {
2252 u16Tmp = 0;
2253 }
2254
2255 if(g_VEInfo.u16H_CapSize < u16Out_Hsize)
2256 {
2257 u16Tmp2 = (u16Out_Hsize-g_VEInfo.u16H_CapSize)/2;
2258 }
2259 else
2260 {
2261 u16Tmp2 = 0;
2262 }
2263
2264 Hal_VE_set_crop_window(u16Tmp2,
2265 u16Out_Hsize - u16Tmp2 -1,
2266 u16Tmp,
2267 (u16Out_Vsize - u16Tmp+1)/2 -1);
2268 }
2269 else
2270 {
2271 Hal_VE_set_crop_window(0,u16Out_Hsize-1,0,(u16Out_Vsize/2)-1);
2272 }
2273 #endif
2274
2275 if(g_VEInfo.u8VE_DisplayStatus & EN_VE_CCIR656_IN)
2276 Hal_VE_set_capture_window(0x000, VE_DE_HEND_MASK, 0x10, 0xFF);
2277 else if((g_VEInfo.u8VE_DisplayStatus & EN_VE_DEMODE) && (!g_VEInfo.bForceCaptureMode)) // Force DE mode for source coming Scaler OP
2278 Hal_VE_set_capture_window(0x000, VE_DE_HEND_MASK, 0x000, VE_DE_VEND_MASK);
2279 else
2280 {
2281 Hal_VE_set_capture_window(g_VEInfo.u16H_CapStart,
2282 g_VEInfo.u16H_CapStart + g_VEInfo.u16H_CapSize - 1,
2283 g_VEInfo.u16V_CapStart,
2284 g_VEInfo.u16V_CapStart + u16V_CapSize - 1);
2285 }
2286 #else
2287 if(g_VEInfo.u8VE_DisplayStatus & EN_VE_CCIR656_IN)
2288 Hal_VE_set_capture_window(0x000, 0x7FF, 0x10, 0xFF);
2289 else if((g_VEInfo.u8VE_DisplayStatus & EN_VE_DEMODE || g_VEInfo.InputSrcType == MS_VE_SRC_SCALER) && (!_gbIsCaptureMode)) // Force DE mode for source coming Scaler OP if capture mode is disable
2290 Hal_VE_set_capture_window(0x000, 0x7FF, 0x000, 0x7FF);
2291 else
2292 {
2293 Hal_VE_set_capture_window(g_VEInfo.u16H_CapStart,
2294 g_VEInfo.u16H_CapStart + g_VEInfo.u16H_CapSize - 1,
2295 g_VEInfo.u16V_CapStart,
2296 g_VEInfo.u16V_CapStart + g_VEInfo.u16V_CapSize - 1);
2297 }
2298 #endif
2299
2300 if(g_VEInfo.u8VE_DisplayStatus & EN_VE_INVERSE_HSYNC)
2301 Hal_VE_set_hsync_inverse(1); //enable inverse Hsync
2302 else
2303 Hal_VE_set_hsync_inverse(0); //disable inverse Hsync
2304
2305
2306 if(g_VEInfo.bSrcInterlace)
2307 Hal_VE_set_source_interlace(ENABLE);
2308 else
2309 Hal_VE_set_source_interlace(DISABLE);
2310 }
2311
2312 //------------------------------------------------------------------------------
2313 /// @brief MDrv_VE_Get_Ext_Caps: get VE extented capability
2314 ///
2315 /// @argument:
2316 /// @return none
2317 //------------------------------------------------------------------------------
MDrv_VE_Get_Ext_Caps(MS_VE_Ext_Cap * cap)2318 VE_Result MDrv_VE_Get_Ext_Caps(MS_VE_Ext_Cap *cap)
2319 {
2320 cap->bSupport_UpScale = g_VECap.bSupport_UpScale;
2321 cap->bSupport_CropMode = g_VECap.bSupport_CropMode;
2322
2323 return E_VE_OK;
2324 }
2325
2326 //------------------------------------------------------------------------------
2327 /// @brief MDrv_VE_set_crop_window, set up crop window (crop video frame in MIU)
2328 ///
2329 /// @argument:
2330 // - MS_VE_WINDOW_TYPE - crop window
2331 /// @return VE_Result
2332 //------------------------------------------------------------------------------
MDrv_VE_set_crop_window(MS_VE_WINDOW_TYPE stCropWin)2333 VE_Result MDrv_VE_set_crop_window(MS_VE_WINDOW_TYPE stCropWin)
2334 {
2335 MS_U16 u16Out_Hsize= (((g_VEInfo.bHDuplicate) && (g_VEInfo.InputSrcType == MS_VE_SRC_DTV)) ? 704 : 720);
2336 MS_U16 u16Out_Vsize = ((g_VEInfo.VideoSystem <= MS_VE_PAL_M) ? 480 : 576);
2337 MS_PHY phyMIUOffsetAddr = 0;
2338 MS_U8 u8PackPerLine = 0;
2339 MS_U16 u16PixelPerUnit = 0;
2340 MS_U16 u16FieldLineNum = 0;
2341 VE_Result ret = E_VE_OK;
2342
2343 if (!g_VECap.bSupport_CropMode) {
2344 MSG_DRV_VE("[%s] is not supported in this chip\n",
2345 __FUNCTION__);
2346 ret = E_VE_NOT_SUPPORT;
2347 goto fail;
2348 }
2349
2350 //Check crop window location and size.
2351 if(stCropWin.x > u16Out_Hsize) {
2352 MSG_DRV_VE("[%s]x >> width,please check x range\n",
2353 __FUNCTION__);
2354 ret = E_VE_FAIL;
2355 goto fail;
2356 }
2357 if(stCropWin.y > u16Out_Vsize) {
2358 MSG_DRV_VE("[%s]y >> height,please check y range\n",
2359 __FUNCTION__);
2360 ret = E_VE_FAIL;
2361 goto fail;
2362 }
2363
2364 if (Hal_VE_Get_DRAM_Format() == MS_VE_DRAM_FORMAT_Y8C8) {
2365 // Y8C8
2366 u16PixelPerUnit = 4; // 64 / 16 = 4
2367 } else {
2368 // Y8C8M4
2369 u16PixelPerUnit = 3; // 64 / 20 = 3
2370 // NOTE: In Y8C8M4 format, there are at most 3 pixel per access unit
2371 // (64bit). There are 4 unused bits every 64 bits.
2372 }
2373 // step 0: crop left part(stCropWin.x)
2374 // step 1: top part(stCropWin.y * u16Out_HSize)
2375 // NOTE: there are PAL: 288 / NTSC:240 lines in one field.
2376 phyMIUOffsetAddr = (stCropWin.x + (stCropWin.y / 2) * u16Out_Hsize) / u16PixelPerUnit * 8;
2377 phyMIUOffsetAddr += g_VEInfo.phyMiuBaseAddr;
2378 Hal_VE_SetMemAddr(&phyMIUOffsetAddr, NULL);
2379
2380 // seep 2: crop right part (stCropWin.width)
2381 // unit: MIU bus width: 64 bits
2382 u8PackPerLine = (stCropWin.width / u16PixelPerUnit) - 1;
2383 Hal_VE_Set_Pack_Num_Per_Line(u8PackPerLine);
2384
2385 MSG_DRV_VE("step 2: pack number per line: %u\n",
2386 (unsigned int)u8PackPerLine);
2387
2388 // seep 3: crop bottom part (stCropWin.height)
2389 // line per field: PAL: 288, NTSC: 240
2390 u16FieldLineNum = ((stCropWin.height) / 2) - 1;
2391 Hal_VE_Set_Field_Line_Number(u16FieldLineNum);
2392 MSG_DRV_VE("step 3: field line number: %u\n",
2393 (unsigned int)u16FieldLineNum);
2394
2395 // update Cap size for MDrv_VE_set_scaling_ratio
2396 g_VEInfo.u16H_CapSize = stCropWin.width;
2397 g_VEInfo.u16V_CapSize = stCropWin.height;
2398 return E_VE_OK;
2399 fail:
2400 printf("Error: [%s] failed, errno: %d\n", __FUNCTION__, ret);
2401 return ret;
2402 }
2403
_MDrv_VE_SetMode(MS_VE_Set_Mode_Type * pVESetMode)2404 void _MDrv_VE_SetMode(MS_VE_Set_Mode_Type *pVESetMode)
2405 {
2406 g_VEInfo.u16H_CapSize = pVESetMode->u16H_CapSize;
2407 g_VEInfo.u16V_CapSize = pVESetMode->u16V_CapSize;
2408 g_VEInfo.u16H_CapStart = pVESetMode->u16H_CapStart;
2409 g_VEInfo.u16V_CapStart = pVESetMode->u16V_CapStart;
2410
2411 g_VEInfo.u16H_SC_CapSize = pVESetMode->u16H_SC_CapSize;
2412 g_VEInfo.u16V_SC_CapSize = pVESetMode->u16V_SC_CapSize;
2413 g_VEInfo.u16H_SC_CapStart = pVESetMode->u16H_SC_CapStart;
2414 g_VEInfo.u16V_SC_CapStart = pVESetMode->u16V_SC_CapStart;
2415 g_VEInfo.bHDuplicate = pVESetMode->bHDuplicate;
2416 #ifdef VE_SOURCE_AFTER_DI
2417 g_VEInfo.bSrcInterlace = FALSE;
2418 #else
2419 g_VEInfo.bSrcInterlace = pVESetMode->bSrcInterlace;
2420 #endif
2421
2422 MSG_DRV_VE("VE SetMode, VFreq=%d, Hdupliate=%d, Interlace=%d\n",
2423 pVESetMode->u16InputVFreq, g_VEInfo.bHDuplicate, g_VEInfo.bSrcInterlace);
2424
2425 MSG_DRV_VE("VE->H:(%d, %d), V:(%d, %d)\n",
2426 g_VEInfo.u16H_CapStart, g_VEInfo.u16H_CapSize,
2427 g_VEInfo.u16V_CapStart, g_VEInfo.u16V_CapSize);
2428
2429 MSG_DRV_VE("SC->H:(%d, %d), V:(%d, %d)\n",
2430 g_VEInfo.u16H_SC_CapStart, g_VEInfo.u16H_SC_CapSize,
2431 g_VEInfo.u16V_SC_CapStart, g_VEInfo.u16V_SC_CapSize);
2432 if(g_VEInfo.bVECapture == FALSE)
2433 {
2434 g_VEInfo.u16OutputWidth = (( ( g_VEInfo.bHDuplicate ) && ( g_VEInfo.InputSrcType == MS_VE_SRC_DTV ) ) ? 704 : 720);
2435 g_VEInfo.u16Outputheight= ((g_VEInfo.VideoSystem <= MS_VE_PAL_M) ? 480 : 576);
2436 }
2437 MDrv_VE_set_capture_window(); // set capture window
2438 MDrv_VE_set_scaling_ratio(g_VEInfo.u16OutputWidth, g_VEInfo.u16Outputheight); // set scaling ratio
2439 MDrv_VE_set_frc(pVESetMode->u16InputVFreq); // set frc
2440 }
2441
MDrv_VE_SetMode(MS_VE_Set_Mode_Type * pVESetMode)2442 void MDrv_VE_SetMode(MS_VE_Set_Mode_Type *pVESetMode)
2443 {
2444 #if TVENCODER_UTOPIA2
2445 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
2446 PTVE_SETMODE pArgs = NULL;
2447 if(pu32TvencoderInst == NULL)
2448 {
2449 return ;
2450 }
2451 pArgs = (PTVE_SETMODE)malloc(sizeof(TVE_SETMODE));
2452
2453 if(NULL == pArgs)
2454 return ;
2455 pArgs->pVESetMode = pVESetMode;
2456 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SetMode, (void*)pArgs);
2457 if(UTOPIA_STATUS_SUCCESS != u32Ret)
2458 {
2459 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
2460 }
2461
2462 free(pArgs);
2463 #else
2464 _MDrv_VE_SetMode(pVESetMode);
2465 #endif
2466 }
_MDrv_VE_SetBlackScreen(MS_BOOL bEn)2467 void _MDrv_VE_SetBlackScreen(MS_BOOL bEn)
2468 {
2469 MSG_DRV_VE("VE Setblackscreen %x\n", bEn);
2470 Hal_VE_set_blackscreen(bEn);
2471 }
2472
MDrv_VE_SetBlackScreen(MS_BOOL bEn)2473 void MDrv_VE_SetBlackScreen(MS_BOOL bEn)
2474 {
2475 #if TVENCODER_UTOPIA2
2476 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
2477 PTVE_SETBLACKSCREEN pArgs = NULL;
2478 if(pu32TvencoderInst == NULL)
2479 {
2480 return;
2481 }
2482 pArgs = (PTVE_SETBLACKSCREEN)malloc(sizeof(TVE_SETBLACKSCREEN));
2483
2484 if(NULL == pArgs)
2485 return ;
2486 pArgs->bEnable = bEn;
2487
2488 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SetBlackSceen, (void*)pArgs);
2489 if(UTOPIA_STATUS_SUCCESS != u32Ret)
2490 {
2491 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
2492 }
2493 free(pArgs);
2494 #else
2495 _MDrv_VE_SetBlackScreen(bEn);
2496 #endif
2497 }
2498
_MDrv_VE_IsBlackScreenEnabled(void)2499 MS_BOOL _MDrv_VE_IsBlackScreenEnabled(void)
2500 {
2501 return Hal_VE_is_blackscreen_enabled();
2502 }
2503
MDrv_VE_IsBlackScreenEnabled(void)2504 MS_BOOL MDrv_VE_IsBlackScreenEnabled(void)
2505 {
2506 #if TVENCODER_UTOPIA2
2507 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
2508 TVE_ISBLACKSCREENENABLE Args;
2509 if(pu32TvencoderInst == NULL)
2510 {
2511 return FALSE;
2512 }
2513 //pArgs = (PTVE_ISBLACKSCREENENABLE)malloc(sizeof(PTVE_ISBLACKSCREENENABLE));
2514 Args.bEnable = FALSE;
2515 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_IsBlackScreenEnabled, (void*)&Args);
2516 if(UTOPIA_STATUS_SUCCESS != u32Ret)
2517 {
2518 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
2519 }
2520
2521 return Args.bEnable;
2522 #else
2523 return _MDrv_VE_IsBlackScreenEnabled();
2524 #endif
2525 }
2526
MDrv_VE_GetCaps(VE_Caps * pCaps)2527 void MDrv_VE_GetCaps(VE_Caps* pCaps)
2528 {
2529 pCaps->bNTSC = TRUE;
2530 pCaps->bPAL = TRUE;
2531 pCaps->bVESupported = VE_SUPPORTED;
2532 }
2533
2534 //------------------------------------------------------------------------------
2535 /// VE restart TVE to read data from TT buffer
2536 /// @return none
2537 //------------------------------------------------------------------------------
MDrv_VE_EnableTtx(MS_BOOL bEnable)2538 void MDrv_VE_EnableTtx(MS_BOOL bEnable)
2539 {
2540 Hal_VE_EnableTtx(bEnable);
2541 }
2542
2543 #define FILED_PER_FIRE 5
2544 //------------------------------------------------------------------------------
2545 /// VE set TT buffer address
2546 /// @return none
2547 //------------------------------------------------------------------------------
_MDrv_VE_SetTtxBuffer(MS_PHY u32StartAddr,MS_U32 u32Size)2548 void _MDrv_VE_SetTtxBuffer(MS_PHY u32StartAddr, MS_U32 u32Size)
2549 {
2550
2551 //Hal_VE_Set_VbiTtxActiveLines(linePerField);
2552
2553 // MIU size and base adress
2554 Hal_VE_Set_ttx_Buffer(u32StartAddr, u32Size);
2555
2556 // interrupt force & interrupt clear
2557 Hal_VE_Clear_ttxReadDoneStatus();
2558
2559 // start next vbi ttx read
2560 Hal_VE_EnableTtx(ENABLE);
2561 }
2562
MDrv_VE_SetTtxBuffer(MS_PHY u32StartAddr,MS_U32 u32Size)2563 void MDrv_VE_SetTtxBuffer(MS_PHY u32StartAddr, MS_U32 u32Size)
2564 {
2565 #if TVENCODER_UTOPIA2
2566 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
2567 PTVE_SETTTXBUFFER pArgs = NULL;
2568 if(pu32TvencoderInst == NULL)
2569 {
2570 return;
2571 }
2572 pArgs = (PTVE_SETTTXBUFFER)malloc(sizeof(TVE_SETTTXBUFFER));
2573
2574 if(NULL == pArgs)
2575 return ;
2576 pArgs->u32StartAddr = u32StartAddr;
2577 pArgs->u32Size = u32Size;
2578 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SetTtxBuffer, (void*)pArgs);
2579 if(UTOPIA_STATUS_SUCCESS != u32Ret)
2580 {
2581 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
2582 }
2583
2584 free(pArgs);
2585 #else
2586 _MDrv_VE_SetTtxBuffer(u32StartAddr, u32Size);
2587 #endif
2588 }
2589 //------------------------------------------------------------------------------
2590 /// VE clear TT buffer read done status
2591 /// @return none
2592 //------------------------------------------------------------------------------
MDrv_VE_ClearTtxReadDoneStatus(void)2593 void MDrv_VE_ClearTtxReadDoneStatus(void)
2594 {
2595 Hal_VE_Clear_ttxReadDoneStatus();
2596 }
2597
2598 //------------------------------------------------------------------------------
2599 /// VE TT buffer read done status
2600 /// @return TRUE/FALSE
2601 //------------------------------------------------------------------------------
_MDrv_VE_GetTtxReadDoneStatus(void)2602 MS_BOOL _MDrv_VE_GetTtxReadDoneStatus(void)
2603 {
2604 return Hal_VE_Get_ttxReadDoneStatus();
2605 }
2606
MDrv_VE_GetTtxReadDoneStatus(void)2607 MS_BOOL MDrv_VE_GetTtxReadDoneStatus(void)
2608 {
2609 #if TVENCODER_UTOPIA2
2610 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
2611 TVE_GETTTXREADDONE Args ;
2612 if(pu32TvencoderInst == NULL)
2613 {
2614 return FALSE;
2615 }
2616
2617 memset(&Args, 0, sizeof(TVE_GETTTXREADDONE));
2618 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_VE_GetTtxReadDoneStatus, (void*)&Args);
2619 if(UTOPIA_STATUS_SUCCESS != u32Ret)
2620 {
2621 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
2622 }
2623
2624 return Args.bDone;
2625 #else
2626 return _MDrv_VE_GetTtxReadDoneStatus();
2627 #endif
2628 }
2629 //------------------------------------------------------------------------------
2630 /// VE Set VBI TT active Lines
2631 /// @return none
2632 //------------------------------------------------------------------------------
MDrv_VE_SetVbiTtxActiveLines(MS_U8 u8LinePerField)2633 void MDrv_VE_SetVbiTtxActiveLines(MS_U8 u8LinePerField)
2634 {
2635 Hal_VE_Set_VbiTtxActiveLines(u8LinePerField);
2636 }
2637
2638 //------------------------------------------------------------------------------
2639 /// VE Set VBI TT active Lines by the given bitmap
2640 /// @param <IN>\b u32Bitmap: a bitmap that defines whick physical lines the teletext lines are to be inserted.
2641 /// @return none
2642 //------------------------------------------------------------------------------
MDrv_VE_SetVbiTtxActiveLinesBitmap(MS_U32 u32Bitmap)2643 void MDrv_VE_SetVbiTtxActiveLinesBitmap(MS_U32 u32Bitmap)
2644 {
2645 Hal_VE_Set_VbiTtxActiveLinesBitmap(u32Bitmap);
2646 }
2647
2648 //------------------------------------------------------------------------------
2649 /// ve set vbi ttx active line
2650 /// @param <in>\b odd_start: odd page start line
2651 /// @param <in>\b odd_end: odd page end line
2652 /// @param <in>\b even_start: even page start line
2653 /// @param <in>\b even_end: even page end line
2654 /// @return none
2655 //------------------------------------------------------------------------------
MDrv_VE_SetVbiTtxRange(MS_U16 odd_start,MS_U16 odd_end,MS_U16 even_start,MS_U16 enen_end)2656 void MDrv_VE_SetVbiTtxRange(MS_U16 odd_start, MS_U16 odd_end,
2657 MS_U16 even_start, MS_U16 enen_end)
2658
2659 {
2660 Hal_VE_SetVbiTtxRange(odd_start, odd_end, even_start, enen_end);
2661 }
2662
2663
2664
2665 //------------------------------------------------------------------------------
2666 /// VE Set VBI CC
2667 /// @return none
2668 //------------------------------------------------------------------------------
_MDrv_VE_EnableCcSw(MS_BOOL bEnable)2669 void _MDrv_VE_EnableCcSw(MS_BOOL bEnable)
2670 {
2671 Hal_VE_EnableCcSw( bEnable);
2672 }
2673
MDrv_VE_EnableCcSw(MS_BOOL bEnable)2674 void MDrv_VE_EnableCcSw(MS_BOOL bEnable)
2675 {
2676 #if TVENCODER_UTOPIA2
2677 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
2678 PTVE_ENABLECCSW pArgs = NULL;
2679 if(pu32TvencoderInst == NULL)
2680 {
2681 return ;
2682 }
2683 pArgs = (PTVE_ENABLECCSW)malloc(sizeof(TVE_ENABLECCSW));
2684
2685 if(NULL == pArgs)
2686 return;
2687 pArgs->bEnable = bEnable;
2688 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_EnableCcSw, (void*)pArgs);
2689 if(UTOPIA_STATUS_SUCCESS != u32Ret)
2690 {
2691 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
2692 }
2693 free(pArgs);
2694 #else
2695 _MDrv_VE_EnableCcSw(bEnable);
2696 #endif
2697 }
2698 //------------------------------------------------------------------------------
2699 /// VE Set VBI CC active line
2700 /// @return none
2701 //------------------------------------------------------------------------------
_MDrv_VE_SetCcRange(MS_U16 odd_start,MS_U16 odd_end,MS_U16 even_start,MS_U16 enen_end)2702 void _MDrv_VE_SetCcRange(MS_U16 odd_start, MS_U16 odd_end, MS_U16 even_start, MS_U16 enen_end)
2703 {
2704 Hal_VE_SetCcRange( odd_start, odd_end, even_start, enen_end);
2705 }
2706
MDrv_VE_SetCcRange(MS_U16 odd_start,MS_U16 odd_end,MS_U16 even_start,MS_U16 enen_end)2707 void MDrv_VE_SetCcRange(MS_U16 odd_start, MS_U16 odd_end, MS_U16 even_start, MS_U16 enen_end)
2708 {
2709 #if TVENCODER_UTOPIA2
2710 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
2711 PTVE_SETCCRANGE pArgs = NULL;
2712 if(pu32TvencoderInst == NULL)
2713 {
2714 return ;
2715 }
2716
2717 pArgs = (PTVE_SETCCRANGE)malloc(sizeof(TVE_SETCCRANGE));
2718
2719 if(NULL == pArgs)
2720 return ;
2721 pArgs->u16odd_start = odd_start;
2722 pArgs->u16odd_end = odd_end;
2723 pArgs->u16even_start = even_start;
2724 pArgs->u16even_end = enen_end;
2725
2726 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SetCcRange, (void*)pArgs);
2727 if(UTOPIA_STATUS_SUCCESS != u32Ret)
2728 {
2729 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
2730 }
2731 free(pArgs);
2732 #else
2733 _MDrv_VE_SetCcRange(odd_start, odd_end, even_start, enen_end);
2734 #endif
2735 }
2736 //------------------------------------------------------------------------------
2737 /// VE Set VBI CC data
2738 /// @return none
2739 //------------------------------------------------------------------------------
_MDrv_VE_SendCcData(MS_BOOL bIsOdd,MS_U16 data)2740 void _MDrv_VE_SendCcData(MS_BOOL bIsOdd, MS_U16 data) // true: odd, false: even
2741 {
2742 Hal_VE_SendCcData( bIsOdd, data);
2743 }
2744
MDrv_VE_SendCcData(MS_BOOL bIsOdd,MS_U16 data)2745 void MDrv_VE_SendCcData(MS_BOOL bIsOdd, MS_U16 data)
2746 {
2747 #if TVENCODER_UTOPIA2
2748 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
2749 PTVE_SENDCCDATA pArgs = NULL;
2750 if(pu32TvencoderInst == NULL)
2751 {
2752 return ;
2753 }
2754
2755 pArgs = (PTVE_SENDCCDATA)malloc(sizeof(TVE_SENDCCDATA));
2756
2757 if(NULL == pArgs)
2758 return ;
2759 pArgs->bIsOdd = bIsOdd;
2760 pArgs->u16data = data;
2761 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SendCcData, (void*)pArgs);
2762 if(UTOPIA_STATUS_SUCCESS != u32Ret)
2763 {
2764 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
2765 }
2766
2767 free(pArgs);
2768 #else
2769 _MDrv_VE_SendCcData(bIsOdd, data);
2770 #endif
2771 }
2772
2773 //------------------------------------------------------------------------------
2774 /// Set VE Frame Color
2775 /// @return none
2776 //------------------------------------------------------------------------------
_MDrv_VE_SetFrameColor(MS_U32 u32aRGB)2777 VE_Result _MDrv_VE_SetFrameColor(MS_U32 u32aRGB)
2778 {
2779 return Hal_VE_SetFrameColor(u32aRGB);
2780 }
2781
MDrv_VE_SetFrameColor(MS_U32 u32aRGB)2782 VE_Result MDrv_VE_SetFrameColor(MS_U32 u32aRGB)
2783 {
2784 #if TVENCODER_UTOPIA2
2785 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
2786 PTVE_SETFRAMECOLOR pArgs = NULL;
2787 if(pu32TvencoderInst == NULL)
2788 {
2789 return FALSE;
2790 }
2791 pArgs = (PTVE_SETFRAMECOLOR)malloc(sizeof(TVE_SETFRAMECOLOR));
2792
2793 if(NULL == pArgs)
2794 return E_VE_FAIL;
2795 pArgs->u32aRGB = u32aRGB;
2796 pArgs->eRet = E_TVENCODER_FAIL;
2797
2798 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_Set_FrameColor, (void*)pArgs);
2799 if(UTOPIA_STATUS_SUCCESS != u32Ret)
2800 {
2801 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
2802 }
2803
2804 if(E_TVENCODER_OK == pArgs->eRet)
2805 {
2806 free(pArgs);
2807 return E_VE_OK;
2808 }
2809 else
2810 {
2811 free(pArgs);
2812 return E_VE_FAIL;
2813 }
2814 #else
2815 return _MDrv_VE_SetFrameColor(u32aRGB);
2816 #endif
2817
2818 }
2819
2820 //------------------------------------------------------------------------------
2821 /// VE Set output with OSD
2822 /// @return none
2823 //------------------------------------------------------------------------------
_MDrv_VE_SetOSD(MS_BOOL bEnable)2824 void _MDrv_VE_SetOSD(MS_BOOL bEnable)
2825 {
2826 Hal_VE_Set_OSD(bEnable);
2827 }
2828
MDrv_VE_SetOSD(MS_BOOL bEnable)2829 void MDrv_VE_SetOSD(MS_BOOL bEnable)
2830 {
2831 #if TVENCODER_UTOPIA2
2832 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
2833 PTVE_SETOSD pArgs = NULL;
2834
2835 if(pu32TvencoderInst == NULL)
2836 {
2837 return ;
2838 }
2839
2840 pArgs = (PTVE_SETOSD)malloc(sizeof(TVE_SETOSD));
2841
2842 if(NULL == pArgs)
2843 return ;
2844 pArgs->bEnable = bEnable;
2845 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SetOSD, (void*)pArgs);
2846 if(UTOPIA_STATUS_SUCCESS != u32Ret)
2847 {
2848 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
2849 }
2850 free(pArgs);
2851 #else
2852 return _MDrv_VE_SetOSD(bEnable);
2853 #endif
2854 }
2855
2856 //------------------------------------------------------------------------------
2857 /// Set VE OSD Layer
2858 /// @return none
2859 //------------------------------------------------------------------------------
_MDrv_VE_Set_OSDLayer(MS_VE_OSD_LAYER_SEL eVideoOSDLayer)2860 VE_Result _MDrv_VE_Set_OSDLayer(MS_VE_OSD_LAYER_SEL eVideoOSDLayer)
2861 {
2862 return Hal_VE_Set_OSDLayer(eVideoOSDLayer);
2863 }
2864
MDrv_VE_Set_OSDLayer(MS_VE_OSD_LAYER_SEL eVideoOSDLayer)2865 VE_Result MDrv_VE_Set_OSDLayer(MS_VE_OSD_LAYER_SEL eVideoOSDLayer)
2866 {
2867 #if TVENCODER_UTOPIA2
2868 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
2869 PTVE_SETOSDLAYER pArgs = NULL;
2870 if(pu32TvencoderInst == NULL)
2871 {
2872 return FALSE;
2873 }
2874 pArgs = (PTVE_SETOSDLAYER)malloc(sizeof(TVE_SETOSDLAYER));
2875
2876 if(NULL == pArgs)
2877 return E_VE_FAIL;
2878 pArgs->eVideoOSDLayer = eVideoOSDLayer;
2879 pArgs->eRet = E_TVENCODER_FAIL;
2880
2881 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_Set_OSDLayer, (void*)pArgs);
2882 if(UTOPIA_STATUS_SUCCESS != u32Ret)
2883 {
2884 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
2885 }
2886
2887 if(E_TVENCODER_OK == pArgs->eRet)
2888 {
2889 free(pArgs);
2890 return E_VE_OK;
2891 }
2892 else
2893 {
2894 free(pArgs);
2895 return E_VE_FAIL;
2896 }
2897 #else
2898 return _MDrv_VE_Set_OSDLayer(eVideoOSDLayer);
2899 #endif
2900
2901 }
2902
2903 //------------------------------------------------------------------------------
2904 /// Get VE OSD Layer
2905 /// @return none
2906 //------------------------------------------------------------------------------
_MDrv_VE_Get_OSDLayer(void)2907 MS_VE_OSD_LAYER_SEL _MDrv_VE_Get_OSDLayer(void)
2908 {
2909 return Hal_VE_Get_OSDLayer();
2910 }
2911
MDrv_VE_Get_OSDLayer(void)2912 MS_VE_OSD_LAYER_SEL MDrv_VE_Get_OSDLayer(void)
2913 {
2914 #if TVENCODER_UTOPIA2
2915 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
2916 PTVE_GETOSDLAYER pArgs = NULL;
2917 if(pu32TvencoderInst == NULL)
2918 {
2919 return FALSE;
2920 }
2921 pArgs = (PTVE_GETOSDLAYER)malloc(sizeof(TVE_GETOSDLAYER));
2922
2923 if(NULL == pArgs)
2924 return MS_VE_LAYER_NONE;
2925 pArgs->eRet = MS_VE_LAYER_NONE;
2926 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_Get_OSDLayer, (void*)pArgs);
2927 if(UTOPIA_STATUS_SUCCESS != u32Ret)
2928 {
2929 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
2930 }
2931 MS_VE_OSD_LAYER_SEL eReturn = pArgs->eRet;
2932 free(pArgs);
2933 return eReturn;
2934
2935 #else
2936 return _MDrv_VE_Get_OSDLayer();
2937 #endif
2938
2939 }
2940
2941 //------------------------------------------------------------------------------
2942 /// Set VE Video Alpha
2943 /// @return none
2944 //------------------------------------------------------------------------------
_MDrv_VE_Set_VideoAlpha(MS_U8 u8Val)2945 VE_Result _MDrv_VE_Set_VideoAlpha(MS_U8 u8Val)
2946 {
2947 return Hal_VE_Set_VideoAlpha(u8Val);
2948 }
2949
MDrv_VE_Set_VideoAlpha(MS_U8 u8Val)2950 VE_Result MDrv_VE_Set_VideoAlpha(MS_U8 u8Val)
2951 {
2952 #if TVENCODER_UTOPIA2
2953 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
2954 PTVE_SETVIDEOALPHA pArgs = NULL;
2955 if(pu32TvencoderInst == NULL)
2956 {
2957 return FALSE;
2958 }
2959 pArgs = (PTVE_SETVIDEOALPHA)malloc(sizeof(TVE_SETVIDEOALPHA));
2960
2961 if(NULL == pArgs)
2962 return E_VE_FAIL;
2963 pArgs->u8Val = u8Val;
2964 pArgs->eRet = E_TVENCODER_FAIL;
2965
2966 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_Set_VideoAlpha, (void*)pArgs);
2967 if(UTOPIA_STATUS_SUCCESS != u32Ret)
2968 {
2969 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
2970 }
2971
2972 if(E_TVENCODER_OK == pArgs->eRet)
2973 {
2974 free(pArgs);
2975 return E_VE_OK;
2976 }
2977 else
2978 {
2979 free(pArgs);
2980 return E_VE_FAIL;
2981 }
2982 #else
2983 return _MDrv_VE_Set_VideoAlpha(u8Val);
2984 #endif
2985
2986 }
2987
2988 //------------------------------------------------------------------------------
2989 /// Get VE Video Alpha
2990 /// @return none
2991 //------------------------------------------------------------------------------
_MDrv_VE_Get_VideoAlpha(MS_U8 * pu8Val)2992 VE_Result _MDrv_VE_Get_VideoAlpha(MS_U8 *pu8Val)
2993 {
2994 return Hal_VE_Get_VideoAlpha(pu8Val);
2995 }
2996
MDrv_VE_Get_VideoAlpha(MS_U8 * pu8Val)2997 VE_Result MDrv_VE_Get_VideoAlpha(MS_U8 *pu8Val)
2998 {
2999 #if TVENCODER_UTOPIA2
3000 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3001 PTVE_GETVIDEOALPHA pArgs = NULL;
3002 if(pu32TvencoderInst == NULL)
3003 {
3004 return FALSE;
3005 }
3006 pArgs = (PTVE_GETVIDEOALPHA)malloc(sizeof(TVE_GETVIDEOALPHA));
3007
3008 if(NULL == pArgs)
3009 return E_VE_FAIL;
3010 pArgs->pu8Val = pu8Val;
3011 pArgs->eRet = E_TVENCODER_FAIL;
3012
3013 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_Get_VideoAlpha, (void*)pArgs);
3014 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3015 {
3016 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3017 }
3018
3019 if(E_TVENCODER_OK == pArgs->eRet)
3020 {
3021 free(pArgs);
3022 return E_VE_OK;
3023 }
3024 else
3025 {
3026 free(pArgs);
3027 return E_VE_FAIL;
3028 }
3029 #else
3030 return _MDrv_VE_Get_VideoAlpha(pu8Val);
3031 #endif
3032
3033 }
3034
3035
3036 //------------------------------------------------------------------------------
3037 /// VE Set RGB In
3038 /// @return none
3039 //------------------------------------------------------------------------------
_MDrv_VE_SetRGBIn(MS_BOOL bEnable)3040 void _MDrv_VE_SetRGBIn(MS_BOOL bEnable)
3041 {
3042 Hal_VE_set_rgb_in(bEnable);
3043 }
3044
MDrv_VE_SetRGBIn(MS_BOOL bEnable)3045 void MDrv_VE_SetRGBIn(MS_BOOL bEnable)
3046 {
3047 #if TVENCODER_UTOPIA2
3048 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3049 PTVE_SETRGBIN pArgs = NULL;
3050 if(pu32TvencoderInst == NULL)
3051 {
3052 return ;
3053 }
3054 pArgs = (PTVE_SETRGBIN)malloc(sizeof(TVE_SETRGBIN));
3055
3056 if(NULL == pArgs)
3057 return ;
3058 pArgs->bEnable = bEnable;
3059 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SetRGBIn, (void*)pArgs);
3060 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3061 {
3062 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3063 }
3064 free(pArgs);
3065 #else
3066 _MDrv_VE_SetRGBIn(bEnable);
3067 #endif
3068 }
3069 //------------------------------------------------------------------------------
3070 /// VE Get output video standard
3071 /// @param <RET> \b VideoSystem : the video standard: PAL or NTSC
3072 //------------------------------------------------------------------------------
_MDrv_VE_Get_Output_Video_Std(void)3073 MS_VE_VIDEOSYS _MDrv_VE_Get_Output_Video_Std(void)
3074 {
3075 return Hal_VE_Get_Output_Video_Std();
3076 }
3077
MDrv_VE_Get_Output_Video_Std(void)3078 MS_VE_VIDEOSYS MDrv_VE_Get_Output_Video_Std(void)
3079 {
3080 #if TVENCODER_UTOPIA2
3081 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3082 TVE_GETOUTPUTVIDEOSTD Args;
3083
3084 if(pu32TvencoderInst == NULL)
3085 {
3086 return MS_VE_VIDEOSYS_NUM;
3087 }
3088 memset(&Args, 0, sizeof(TVE_GETOUTPUTVIDEOSTD));
3089 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_Get_Output_Video_Std, (void*)&Args);
3090 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3091 {
3092 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3093 }
3094 return Args.stVideoSys;
3095 #else
3096 return _MDrv_VE_Get_Output_Video_Std();
3097 #endif
3098 }
3099 //------------------------------------------------------------------------------
3100 /// Force VE Enable/Disable Capture Mode, used to avoid enter DE mode in some case
3101 /// @param <RET> \b bEnable : TRUE: Force use capture mode, FALSE: use defaut
3102 //------------------------------------------------------------------------------
_MDrv_VE_SetCaptureMode(MS_BOOL bEnable)3103 void _MDrv_VE_SetCaptureMode(MS_BOOL bEnable)
3104 {
3105 g_VEInfo.bForceCaptureMode = bEnable;
3106 }
3107
MDrv_VE_SetCaptureMode(MS_BOOL bEnable)3108 void MDrv_VE_SetCaptureMode(MS_BOOL bEnable)
3109 {
3110 #if TVENCODER_UTOPIA2
3111 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3112 PTVE_SETCAPMODE pArgs = NULL;
3113 if(pu32TvencoderInst == NULL)
3114 {
3115 return ;
3116 }
3117 pArgs = (PTVE_SETCAPMODE)malloc(sizeof(TVE_SETCAPMODE));
3118
3119 if(NULL == pArgs)
3120 return ;
3121 pArgs->bEnable = bEnable;
3122
3123 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SetCaptureMode, (void*)pArgs);
3124 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3125 {
3126 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3127 }
3128 free(pArgs);
3129 #else
3130 _MDrv_VE_SetCaptureMode(bEnable);
3131 #endif
3132 }
3133 //------------------------------------------------------------------------------
3134 /// VE Get Destination Information for GOP mixer
3135 /// @return TRUE/FALSE
3136 //------------------------------------------------------------------------------
_MApi_VE_GetDstInfo(MS_VE_DST_DispInfo * pDstInfo,MS_U32 u32SizeofDstInfo)3137 MS_BOOL _MApi_VE_GetDstInfo(MS_VE_DST_DispInfo *pDstInfo, MS_U32 u32SizeofDstInfo)
3138 {
3139 if(NULL == pDstInfo)
3140 {
3141 MSG_DRV_VE("MApi_VE_GetDstInfo():pDstInfo is NULL\n");
3142 return FALSE;
3143 }
3144
3145 if(u32SizeofDstInfo != sizeof(MS_VE_DST_DispInfo))
3146 {
3147 MSG_DRV_VE("MApi_VE_GetDstInfo():u16SizeofDstInfo is different from the MS_VE_DST_DispInfo defined, check header file!\n");
3148 return FALSE;
3149 }
3150
3151 if(_MDrv_VE_Get_Output_Video_Std() == MS_VE_PAL)
3152 {
3153 //PAL
3154 MSG_DRV_VE("MApi_VE_GetDstInfo(): It's PAL case.\n");
3155 pDstInfo->bInterlaceMode = TRUE;
3156 pDstInfo->HDTOT = 864;
3157 pDstInfo->VDTOT = 624;
3158 pDstInfo->DEHST = 132;
3159 pDstInfo->DEHEND= pDstInfo->DEHST + 720;
3160 pDstInfo->DEVST = 44;
3161 pDstInfo->DEVEND= pDstInfo->DEVST + 576;
3162 return TRUE;
3163 }
3164 else if(_MDrv_VE_Get_Output_Video_Std() == MS_VE_NTSC)
3165 {
3166 //NTSC
3167 MSG_DRV_VE("MApi_VE_GetDstInfo(): It's NTSC case.\n");
3168 pDstInfo->bInterlaceMode = TRUE;
3169 pDstInfo->HDTOT = 858;
3170 pDstInfo->VDTOT = 524;
3171 pDstInfo->DEHST = 119;
3172 pDstInfo->DEHEND= pDstInfo->DEHST +720;
3173 pDstInfo->DEVST = 36;
3174 pDstInfo->DEVEND= pDstInfo->DEVST + 480;
3175 return TRUE;
3176 }
3177 else
3178 {
3179 MSG_DRV_VE("MApi_VE_GetDstInfo(): Unkown standard.\n");
3180 pDstInfo->bInterlaceMode = FALSE;
3181 pDstInfo->HDTOT = 0;
3182 pDstInfo->VDTOT = 0;
3183 pDstInfo->DEHST = 0;
3184 pDstInfo->DEHEND= 0;
3185 pDstInfo->DEVST = 0;
3186 pDstInfo->DEVEND= 0;
3187 return FALSE;
3188 }
3189
3190 }
3191
MApi_VE_GetDstInfo(MS_VE_DST_DispInfo * pDstInfo,MS_U32 u32SizeofDstInfo)3192 MS_BOOL MApi_VE_GetDstInfo(MS_VE_DST_DispInfo *pDstInfo, MS_U32 u32SizeofDstInfo)
3193 {
3194 #if TVENCODER_UTOPIA2
3195 MS_U32 u32Ret = UTOPIA_STATUS_FAIL;
3196 PTVE_GETDSTINFO pArgs ;//= NULL;
3197
3198 if(pu32TvencoderInst == NULL)
3199 {
3200 if(UtopiaOpen(MODULE_TVENCODER, (void**)&pu32TvencoderInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
3201 {
3202 printf("UtopiaOpen TVE failed\n");
3203 return FALSE;
3204 }
3205 }
3206 pArgs = (PTVE_GETDSTINFO)malloc(sizeof(TVE_GETDSTINFO));
3207
3208 if(NULL == pArgs)
3209 return FALSE;
3210 pArgs->pDstInfo = pDstInfo;
3211 pArgs->u32SizeofDstInfo = u32SizeofDstInfo;
3212 pArgs->eRet = E_TVENCODER_FAIL;
3213 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_GetDstInfo, (void*)pArgs);
3214 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3215 {
3216 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3217 }
3218
3219 if(E_TVENCODER_FAIL == pArgs->eRet)
3220 {
3221 free(pArgs);
3222 return FALSE;
3223 }
3224 else
3225 {
3226 free(pArgs);
3227 return TRUE;
3228 }
3229 #else
3230 return _MApi_VE_GetDstInfo(pDstInfo, u32SizeofDstInfo);
3231 #endif
3232 }
3233
_MDrv_VE_Set_TestPattern(MS_BOOL bEn)3234 void _MDrv_VE_Set_TestPattern(MS_BOOL bEn)
3235 {
3236 MSG_DRV_VE("VE Set TestPattern bEn = %x\n", bEn);
3237 Hal_VE_Set_TestPattern(bEn);
3238 }
3239
MDrv_VE_Set_TestPattern(MS_BOOL bEn)3240 void MDrv_VE_Set_TestPattern(MS_BOOL bEn)
3241 {
3242 #if TVENCODER_UTOPIA2
3243 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3244 PTVE_SETTESTPATTERN pArgs =NULL;
3245 if(pu32TvencoderInst == NULL)
3246 {
3247 return ;
3248 }
3249 pArgs = (PTVE_SETTESTPATTERN)malloc(sizeof(TVE_SETTESTPATTERN));
3250
3251 if(NULL == pArgs)
3252 return ;
3253 pArgs->bEnable = bEn;
3254
3255 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_Set_TestPattern, (void*)pArgs);
3256 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3257 {
3258 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3259 }
3260 free(pArgs);
3261 #else
3262 _MDrv_VE_Set_TestPattern(bEn);
3263 #endif
3264 }
MApi_VE_W2BYTE_MSK(MS_VE_REG_BANK VE_BK,MS_U32 u32Reg,MS_U16 u16Val,MS_U16 u16Mask)3265 void MApi_VE_W2BYTE_MSK(MS_VE_REG_BANK VE_BK, MS_U32 u32Reg, MS_U16 u16Val, MS_U16 u16Mask)
3266 {
3267 MS_VIRT _VERIUBaseAddress =0;
3268 MS_PHY phyNonPMBankSize = 0;
3269
3270 if(_VE_RIU_BASE == 0)
3271 {
3272 if(MDrv_MMIO_GetBASE( &_VERIUBaseAddress, &phyNonPMBankSize, MS_MODULE_PM ) != TRUE)
3273 {
3274 MSG_DRV_VE("MDrv_VE_Init GetBASE failure\n");
3275 MS_ASSERT(0);
3276 }
3277 Hal_VE_init_riu_base( _VERIUBaseAddress );
3278 #if defined (__aarch64__)
3279 MSG_DRV_VE("_VE_RIU_BASE = 0x%x \n",_VE_RIU_BASE);
3280 #else
3281 MSG_DRV_VE("_VE_RIU_BASE = 0x%tx \n",(ptrdiff_t)_VE_RIU_BASE);
3282 #endif
3283 }
3284
3285 if(VE_BK == MS_VE_REG_BANK_3B)
3286 {
3287 Hal_VE_W2BYTE_MSK(L_BK_VE_SRC(u32Reg), u16Val, u16Mask);
3288 }
3289 else if(VE_BK == MS_VE_REG_BANK_3E)
3290 {
3291 Hal_VE_W2BYTE_MSK(L_BK_VE_ENC(u32Reg), u16Val, u16Mask);
3292 }
3293 else if(VE_BK == MS_VE_REG_BANK_3F)
3294 {
3295 Hal_VE_W2BYTE_MSK(L_BK_VE_ENC_EX(u32Reg), u16Val, u16Mask);
3296 }
3297 }
3298
MApi_VE_R2BYTE_MSK(MS_VE_REG_BANK VE_BK,MS_U32 u32Reg,MS_U16 u16Mask)3299 MS_U16 MApi_VE_R2BYTE_MSK(MS_VE_REG_BANK VE_BK, MS_U32 u32Reg, MS_U16 u16Mask)
3300 {
3301 MS_VIRT _VERIUBaseAddress =0;
3302 MS_PHY phyNonPMBankSize = 0;
3303
3304 if(_VE_RIU_BASE == 0)
3305 {
3306 if(MDrv_MMIO_GetBASE( &_VERIUBaseAddress, &phyNonPMBankSize, MS_MODULE_PM ) != TRUE)
3307 {
3308 MSG_DRV_VE("VE GetBASE failure\n");
3309 MS_ASSERT(0);
3310 return FALSE;
3311 }
3312 Hal_VE_init_riu_base( _VERIUBaseAddress );
3313 #if defined (__aarch64__)
3314 MSG_DRV_VE("_VE_RIU_BASE = 0x%x \n",_VE_RIU_BASE);
3315 #else
3316 MSG_DRV_VE("_VE_RIU_BASE = 0x%tx \n",(ptrdiff_t)_VE_RIU_BASE);
3317 #endif
3318 }
3319
3320 if(VE_BK == MS_VE_REG_BANK_3B)
3321 {
3322 return Hal_VE_R2BYTE_MSK(L_BK_VE_SRC(u32Reg), u16Mask);
3323 }
3324 else if(VE_BK == MS_VE_REG_BANK_3E)
3325 {
3326 return Hal_VE_R2BYTE_MSK(L_BK_VE_ENC(u32Reg), u16Mask);
3327 }
3328 else if(VE_BK == MS_VE_REG_BANK_3F)
3329 {
3330 return Hal_VE_R2BYTE_MSK(L_BK_VE_ENC_EX(u32Reg), u16Mask);
3331 }
3332 else
3333 {
3334 return 0;
3335 }
3336 }
3337
3338 //------------------------------------------------------------------------------
3339 /// VE Dump Table Interface
3340 /// @return TRUE/FALSE
3341 //------------------------------------------------------------------------------
MDrv_VE_DumpTable(MS_U8 * pVETable,MS_U8 u8TableType)3342 void MDrv_VE_DumpTable(MS_U8 *pVETable, MS_U8 u8TableType)
3343 {
3344 Hal_VE_DumpTable(pVETable, u8TableType);
3345 }
3346
3347 //------------------------------------------------------------------------------
3348 /// VE Set MV
3349 /// @return TRUE/FALSE
3350 //------------------------------------------------------------------------------
MDrv_VE_SetMV(MS_BOOL bEnble,MS_VE_MV_TYPE eMvType)3351 VE_Result MDrv_VE_SetMV(MS_BOOL bEnble, MS_VE_MV_TYPE eMvType)
3352 {
3353 return Hal_VE_SetMV(bEnble, eMvType);
3354 }
3355
3356 //------------------------------------------------------------------------------
3357 /// VE Set MV By Bit Control (CPC/CPS)
3358 /// @return TRUE/FALSE
3359 //------------------------------------------------------------------------------
MDrv_VE_SetMV_BitControl(MS_BOOL bEnable,MS_VE_MV_BitControl MV_BitControl_Data)3360 VE_Result MDrv_VE_SetMV_BitControl(MS_BOOL bEnable, MS_VE_MV_BitControl MV_BitControl_Data)
3361 {
3362 return Hal_VE_SetMV_BitControl(bEnable, MV_BitControl_Data);
3363 }
3364
_MDrv_VE_DCS_SetType(MS_BOOL bEnable,MS_U32 eType)3365 VE_Result _MDrv_VE_DCS_SetType(MS_BOOL bEnable, MS_U32 eType)
3366 {
3367 return Hal_VE_DCS_SetType(bEnable, eType);
3368 }
_MDrv_VE_DCS_SetActivationKey(MS_U8 * pu8ActivationKeyTbl,MS_U8 u8ActivationKeyTblSize)3369 VE_Result _MDrv_VE_DCS_SetActivationKey(MS_U8 *pu8ActivationKeyTbl, MS_U8 u8ActivationKeyTblSize)
3370 {
3371 return Hal_VE_DCS_SetActivationKey(pu8ActivationKeyTbl, u8ActivationKeyTblSize);
3372 }
3373
3374 //------------------------------------------------------------------------------
3375 /// Component Set MV
3376 /// @return TRUE/FALSE
3377 //------------------------------------------------------------------------------
MDrv_VE_DCS_SetType(MS_BOOL bEnable,MS_U32 eType)3378 VE_Result MDrv_VE_DCS_SetType(MS_BOOL bEnable, MS_U32 eType)
3379 {
3380 #if TVENCODER_UTOPIA2
3381 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3382 PTVE_DCSSETTYPE pArgs = NULL;
3383 if(pu32TvencoderInst == NULL)
3384 {
3385 return E_VE_FAIL;
3386 }
3387 pArgs = (PTVE_DCSSETTYPE)malloc(sizeof(TVE_DCSSETTYPE));
3388
3389 if(NULL == pArgs)
3390 return E_VE_FAIL;
3391 pArgs->bEnable = bEnable;
3392 pArgs->eType = eType;
3393 pArgs->eRet = E_TVENCODER_FAIL;
3394
3395 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_DCS_SetType, (void*)pArgs);
3396 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3397 {
3398 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3399 }
3400
3401 if(E_TVENCODER_FAIL == pArgs->eRet)
3402 {
3403 free(pArgs);
3404 return E_VE_FAIL;
3405 }
3406 else
3407 {
3408 free(pArgs);
3409 return E_VE_OK;
3410 }
3411
3412 #else
3413 return _MDrv_VE_DCS_SetType(bEnable, eType);
3414 #endif
3415 }
3416
3417 //------------------------------------------------------------------------------
3418 /// Component Set MV
3419 /// @return TRUE/FALSE
3420 //------------------------------------------------------------------------------
MDrv_VE_DCS_SetActivationKey(MS_U8 * pu8ActivationKeyTbl,MS_U8 u8ActivationKeyTblSize)3421 VE_Result MDrv_VE_DCS_SetActivationKey(MS_U8 *pu8ActivationKeyTbl, MS_U8 u8ActivationKeyTblSize)
3422 {
3423 #if TVENCODER_UTOPIA2
3424 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3425 PTVE_DCSSETACTIVATIONKEY pArgs = NULL;
3426 if(pu32TvencoderInst == NULL)
3427 {
3428 return E_VE_FAIL;
3429 }
3430 pArgs = (PTVE_DCSSETACTIVATIONKEY)malloc(sizeof(TVE_DCSSETACTIVATIONKEY));
3431
3432 if(NULL == pArgs)
3433 {
3434 return E_VE_FAIL;
3435 }
3436 pArgs->pu8ActivationKeyTbl = pu8ActivationKeyTbl;
3437 pArgs->u8ActivationKeyTblSize = u8ActivationKeyTblSize;
3438 pArgs->eRet = E_TVENCODER_FAIL;
3439
3440 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_DCS_SetActivationKey, (void*)pArgs);
3441 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3442 {
3443 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3444 }
3445
3446 if(E_TVENCODER_FAIL == pArgs->eRet)
3447 {
3448 free(pArgs);
3449 return E_VE_FAIL;
3450 }
3451 else
3452 {
3453 free(pArgs);
3454 return E_VE_OK;
3455 }
3456
3457 #else
3458 return _MDrv_VE_DCS_SetActivationKey(pu8ActivationKeyTbl, u8ActivationKeyTblSize);
3459 #endif
3460 }
3461
3462 //------------------------------------------------------------------------------
3463 /// @brief This routine set flag to mask register write for special case \n
3464 /// e.g. MBoot to APP with logo display
3465 /// @argument:
3466 /// - bFlag: TRUE: Mask register write, FALSE: not Mask
3467 /// @return None
3468 //------------------------------------------------------------------------------
_MDrv_VE_DisableRegWrite(MS_BOOL bFlag)3469 VE_Result _MDrv_VE_DisableRegWrite(MS_BOOL bFlag)
3470 {
3471 if(Hal_VE_DisableRegWrite_GetCaps() == TRUE)
3472 {
3473 g_bVeDisableRegWrite = bFlag;
3474 return E_VE_OK;
3475 }
3476 else
3477 {
3478 g_bVeDisableRegWrite = FALSE;
3479 return E_VE_OK;
3480 }
3481 }
3482
MDrv_VE_DisableRegWrite(MS_BOOL bFlag)3483 VE_Result MDrv_VE_DisableRegWrite(MS_BOOL bFlag)
3484 {
3485 #if TVENCODER_UTOPIA2
3486 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3487 PTVE_DISABLEREGWRITE pArgs = NULL;
3488 if(pu32TvencoderInst == NULL)
3489 {
3490 if(UtopiaOpen(MODULE_TVENCODER, (void**)&pu32TvencoderInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
3491 {
3492 printf("UtopiaOpen TVE failed\n");
3493 return FALSE;
3494 }
3495 }
3496 pArgs = (PTVE_DISABLEREGWRITE)malloc(sizeof(TVE_DISABLEREGWRITE));
3497
3498 if(NULL == pArgs)
3499 return E_VE_FAIL;
3500 pArgs->bFlag = bFlag;
3501 pArgs->eRet = E_TVENCODER_FAIL;
3502
3503 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_DisableRegWrite, (void*)pArgs);
3504 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3505 {
3506 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3507 }
3508
3509 if(E_TVENCODER_FAIL == pArgs->eRet)
3510 {
3511 free(pArgs);
3512 return E_VE_FAIL;
3513 }
3514 else
3515 {
3516 free(pArgs);
3517 return E_VE_OK;
3518 }
3519 #else
3520 return _MDrv_VE_DisableRegWrite( bFlag);
3521 #endif
3522 }
3523
3524 //------------------------------------------------------------------------------
3525 /// VE show internal color bar (test pattern)
3526 /// @param - bEnable IN: TRUE to enable color; false to disable color bar
3527 /// @return None
3528 //------------------------------------------------------------------------------
MDrv_VE_ShowColorBar(MS_BOOL bEnable)3529 void MDrv_VE_ShowColorBar(MS_BOOL bEnable)
3530 {
3531 Hal_VE_ShowColorBar(bEnable);
3532 }
3533
3534 //------------------------------------------------------------------------------
3535 /// @brief This routine set read/write addjustment to centralize VE display window.\n
3536 /// Set the adjustment and it works after MDrv_VE_set_display_window() API is invoked. \n
3537 ///
3538 /// @argument:
3539 /// - s32WAddrAdjustment: the pixel units to adjust on write address
3540 /// - s32RAddrAdjustment: the pixel units to adjust on read address
3541 /// @return VE_Result
3542 //------------------------------------------------------------------------------
_MDrv_VE_AdjustPositionBase(MS_S32 s32WAddrAdjustment,MS_S32 s32RAddrAdjustment)3543 VE_Result _MDrv_VE_AdjustPositionBase(MS_S32 s32WAddrAdjustment, MS_S32 s32RAddrAdjustment)
3544 {
3545 return Hal_VE_AdjustPositionBase(s32WAddrAdjustment, s32RAddrAdjustment);
3546 }
3547
MDrv_VE_AdjustPositionBase(MS_S32 s32WAddrAdjustment,MS_S32 s32RAddrAdjustment)3548 VE_Result MDrv_VE_AdjustPositionBase(MS_S32 s32WAddrAdjustment, MS_S32 s32RAddrAdjustment)
3549 {
3550 #if TVENCODER_UTOPIA2
3551 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3552 PTVE_ADJPOSITIONBASE pArgs = NULL;
3553 if(pu32TvencoderInst == NULL)
3554 {
3555 if(UtopiaOpen(MODULE_TVENCODER, (void**)&pu32TvencoderInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
3556 {
3557 printf("UtopiaOpen TVE failed\n");
3558 return FALSE;
3559 }
3560 }
3561 pArgs = (PTVE_ADJPOSITIONBASE)malloc(sizeof(TVE_ADJPOSITIONBASE));
3562
3563 if(NULL == pArgs)
3564 return E_VE_FAIL;
3565 pArgs->s32RAddrAdjustment = s32RAddrAdjustment;
3566 pArgs->s32WAddrAdjustment = s32WAddrAdjustment;
3567 pArgs->eRet = E_TVENCODER_FAIL;
3568
3569 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_AdjustPositionBase, (void*)pArgs);
3570 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3571 {
3572 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3573 }
3574
3575 if(E_TVENCODER_FAIL == pArgs->eRet)
3576 {
3577 free(pArgs);
3578 return E_VE_FAIL;
3579 }
3580 else
3581 {
3582 free(pArgs);
3583 return E_VE_OK;
3584 }
3585 #else
3586 return _MDrv_VE_AdjustPositionBase(s32WAddrAdjustment,s32RAddrAdjustment);
3587 #endif
3588 }
3589 //------------------------------------------------------------------------------
3590 /// @brief In STB Chip, VE needs to set vepll to lock frame rate between HD and SD Path.\n
3591 ///
3592 /// @argument:
3593 /// - MS_VE_PLL_InCfg: Information of HD path
3594 /// - MS_VE_PLL_OutCfg: Information of SD path
3595 /// @return VE_Result
3596 //------------------------------------------------------------------------------
MDrv_VE_SetFrameLock(MS_VE_PLL_InCfg * pInCfg,MS_BOOL bEnable)3597 VE_Result MDrv_VE_SetFrameLock(MS_VE_PLL_InCfg *pInCfg, MS_BOOL bEnable)
3598 {
3599 MS_VE_PLL_OutCfg stOutCfg;
3600
3601 if(g_VEInfo.VideoSystem <= MS_VE_PAL_M)
3602 {
3603 //NTSC, PAL-M System
3604 stOutCfg.u16VttOut = 525;
3605 stOutCfg.u16HttOut = 858;
3606 stOutCfg.u16VdeOut = 480;
3607 stOutCfg.u16HdeOut = 720;
3608 }
3609 else
3610 {
3611 //PAL System
3612 stOutCfg.u16VttOut = 625;
3613 stOutCfg.u16HttOut = 864;
3614 stOutCfg.u16VdeOut = 576;
3615 stOutCfg.u16HdeOut = 720;
3616 }
3617
3618 stOutCfg.bInterlace = TRUE;
3619
3620 if(pInCfg != NULL)
3621 {
3622 memcpy(&_stVE_PllInfo.InCfg, pInCfg, sizeof(MS_VE_PLL_InCfg));
3623 memcpy(&_stVE_PllInfo.OutCfg, &stOutCfg, sizeof(MS_VE_PLL_OutCfg));
3624
3625 //idclk_div & odclk_div
3626 MS_U32 u32FreqIn,u32FreqOut;
3627
3628 if(_stVE_PllInfo.InCfg.u16HdeIn > 720 ) //HD timing
3629 {
3630 _stVE_PllInfo.u32InitPll = 0x19999999;
3631 }
3632 else
3633 {
3634 _stVE_PllInfo.u32InitPll = 0x15555555;
3635 }
3636
3637 u32FreqIn = _stVE_PllInfo.InCfg.u16VttIn * _stVE_PllInfo.InCfg.u16HttIn;
3638 u32FreqOut = ((MS_U32)(_stVE_PllInfo.OutCfg.u16VttOut)* (MS_U32)(_stVE_PllInfo.OutCfg.u16HttOut))*4;
3639 if(!_stVE_PllInfo.OutCfg.bInterlace)
3640 u32FreqOut *= 2;
3641
3642 MSG_DRV_VE("[VE_PLL] MDrv_VE_SetFrameLock\n");
3643 MSG_DRV_VE("[VE_PLL] InCfg.u16HttIn=0x%x \t InCfg.u16VttIn=0x%x \t InCfg.u16HdeIn=0x%x \t InCfg.u16VdeIn=0x%x \t InCfg.u16Hde_St=0x%x \t InCfg.u16Vde_St=0x%x\n", _stVE_PllInfo.InCfg.u16HttIn, _stVE_PllInfo.InCfg.u16VttIn, _stVE_PllInfo.InCfg.u16HdeIn, _stVE_PllInfo.InCfg.u16VdeIn, _stVE_PllInfo.InCfg.u16Hde_St, _stVE_PllInfo.InCfg.u16Vde_St);
3644 #if defined (__aarch64__)
3645 MSG_DRV_VE("[VE_PLL] 32FreqIn=0x%x \t u32FreqOut=0x%x \n",u32FreqIn,u32FreqOut);
3646 MSG_DRV_VE("[VE_PLL] u32InitPll=0x%x \n",_stVE_PllInfo.u32InitPll);
3647 #else
3648 MSG_DRV_VE("[VE_PLL] 32FreqIn=0x%tx \t u32FreqOut=0x%tx \n",(ptrdiff_t)u32FreqIn,(ptrdiff_t)u32FreqOut);
3649 MSG_DRV_VE("[VE_PLL] u32InitPll=0x%tx \n",(ptrdiff_t)_stVE_PllInfo.u32InitPll);
3650 #endif
3651
3652 _ReductionFrac(&u32FreqIn, &u32FreqOut);
3653 _MultiplFrac(&u32FreqIn,&u32FreqOut);
3654
3655 _stVE_PllInfo.u32IDclk = u32FreqIn;
3656 _stVE_PllInfo.u32ODclk = u32FreqOut;
3657
3658 if( ( _stVE_PllInfo.u32IDclk>0xFFFFFF ) || ( _stVE_PllInfo.u32ODclk>0xFFFFFF ) )
3659 {
3660 MSG_DRV_VE("[VE_PLL] ASSERT !!! idclk/odclk overflow\n");
3661 }
3662 #if defined (__aarch64__)
3663 MSG_DRV_VE("[VE_PLL] idclk=%x \t odclk=%x\n",_stVE_PllInfo.u32IDclk,_stVE_PllInfo.u32ODclk);
3664 #else
3665 MSG_DRV_VE("[VE_PLL] idclk=%tx \t odclk=%tx\n",(ptrdiff_t)_stVE_PllInfo.u32IDclk,(ptrdiff_t)_stVE_PllInfo.u32ODclk);
3666 #endif
3667 }
3668 else
3669 {
3670 MSG_DRV_VE("[VE_PLL] input config is NULL, set fixed clk as ve clk!\n");
3671 bEnable = FALSE;
3672 }
3673
3674 return HAL_VE_SetFrameLock((_stVE_PllInfo.u32IDclk&0xFFFFFF),(_stVE_PllInfo.u32ODclk&0xFFFFFF), _stVE_PllInfo.u32InitPll, bEnable);
3675 }
3676
3677 //------------------------------------------------------------------------------
3678 /// @brief MDrv_VE_SetWindow, set crop window and display window in one API.
3679 ///
3680 /// @argument:
3681 /// - a pointer to MS_VE_WINDOW_TYPE - source window, depends on input size
3682 /// - a pointer to MS_VE_WINDOW_TYPE - crop window, depends on source window size
3683 /// - a pointer to MS_VE_WINDOW_TYPE - display window, depends on output size
3684 /// @return VE_Result
3685 //------------------------------------------------------------------------------
MDrv_VE_SetWindow(MS_VE_WINDOW_TYPE * stSrcWin,MS_VE_WINDOW_TYPE * stCropWin,MS_VE_WINDOW_TYPE * stDispWin)3686 VE_Result MDrv_VE_SetWindow(MS_VE_WINDOW_TYPE *stSrcWin, MS_VE_WINDOW_TYPE *stCropWin,
3687 MS_VE_WINDOW_TYPE *stDispWin)
3688 {
3689 MS_VE_WINDOW_TYPE stScaledSrcWin, stScaledCropWin;
3690 const MS_U32 u32BaseWidth = 720; // maximun down-scaled width
3691 const MS_U32 u32BaseHeight = 576; // maximun down-scaled height
3692 MS_U16 u16BakHCapSize = g_VEInfo.u16H_CapSize;
3693 MS_U16 u16BakVCapSize = g_VEInfo.u16V_CapSize;
3694 VE_Result eRet = E_VE_OK;
3695
3696 // check chip capibility
3697 if ((!g_VECap.bSupport_CropMode) || (!g_VECap.bSupport_UpScale))
3698 {
3699 MSG_DRV_VE("[%s] is not supported in this chip\n",
3700 __FUNCTION__);
3701 eRet = E_VE_NOT_SUPPORT;
3702 goto fail;
3703 }
3704 // check input parameters
3705 if (stSrcWin == NULL)
3706 {
3707 MSG_DRV_VE("[%s][%d] failed\n", __FUNCTION__, __LINE__);
3708 eRet = E_VE_FAIL;
3709 goto fail;
3710 }
3711 if (stCropWin == NULL)
3712 {
3713 MSG_DRV_VE("[%s][%d] failed\n", __FUNCTION__, __LINE__);
3714 eRet = E_VE_FAIL;
3715 goto fail;
3716 }
3717 if (stDispWin == NULL)
3718 {
3719 MSG_DRV_VE("[%s][%d] failed\n", __FUNCTION__, __LINE__);
3720 eRet = E_VE_FAIL;
3721 goto fail;
3722 }
3723 memcpy(&stScaledSrcWin, stSrcWin, sizeof(MS_VE_WINDOW_TYPE));
3724 memcpy(&stScaledCropWin, stCropWin, sizeof(MS_VE_WINDOW_TYPE));
3725
3726 // stage0 - setup down scaling factor
3727 if ((stSrcWin->width > u32BaseWidth) || (stSrcWin->height > u32BaseHeight))
3728 {
3729 if ((stSrcWin->width >= ((u32BaseWidth * stSrcWin->height) / u32BaseHeight)))
3730 {
3731 // stSrcWin->width:stSrcwin->height >= base_width:base_height
3732 // base_width-based down scale
3733 MSG_DRV_VE("[%s]stage 0: do width-based down-scale\n", __FUNCTION__);
3734 // setup scaled_srcWin
3735 stScaledSrcWin.x = u32BaseWidth * stSrcWin->x / stSrcWin->width;
3736 stScaledSrcWin.y = u32BaseWidth * stSrcWin->y / stSrcWin->width;
3737 stScaledSrcWin.width = u32BaseWidth;
3738 stScaledSrcWin.height = u32BaseWidth * stSrcWin->height / stSrcWin->width;
3739 // setup scaled_cropWin
3740 stScaledCropWin.x = u32BaseWidth * stCropWin->x / stSrcWin->width;
3741 stScaledCropWin.y = u32BaseWidth * stCropWin->y / stSrcWin->width;
3742 stScaledCropWin.width = u32BaseWidth * stCropWin->width / stSrcWin->width;
3743 stScaledCropWin.height = u32BaseWidth * stCropWin->height / stSrcWin->width;
3744 }
3745 else
3746 {
3747 // stSrcWin->width:stSrcwin->height < base_width:base_height
3748 // base_height-based down scale
3749 MSG_DRV_VE("[%s]stage 0: do height-based down-scale\n", __FUNCTION__);
3750 // setup scaled_srcWin
3751 stScaledSrcWin.x = u32BaseHeight * stSrcWin->x / stSrcWin->height;
3752 stScaledSrcWin.y = u32BaseHeight * stSrcWin->y / stSrcWin->height;
3753 stScaledSrcWin.width = u32BaseHeight * stSrcWin->width / stSrcWin->height;
3754 stScaledSrcWin.height = u32BaseHeight;
3755 // setup scaled_cropWin
3756 stScaledCropWin.x = u32BaseHeight * stCropWin->x / stSrcWin->height;
3757 stScaledCropWin.y = u32BaseHeight * stCropWin->y / stSrcWin->height;
3758 stScaledCropWin.width = u32BaseHeight * stCropWin->width / stSrcWin->height;
3759 stScaledCropWin.height = u32BaseHeight * stCropWin->height / stSrcWin->height;
3760 }
3761 }
3762
3763 // stage1 - Down scale source window width to base_width without lossing information.
3764 // (before MIU)
3765 MSG_DRV_VE("[%s]stage 1: stSrcWin (%d, %d, %d, %d) -> "
3766 "scaled_srcWin (%d, %d, %d, %d)\n",
3767 __FUNCTION__,
3768 stSrcWin->x, stSrcWin->y, stSrcWin->width, stSrcWin->height,
3769 stScaledSrcWin.x, stScaledSrcWin.x, stScaledSrcWin.width, stScaledSrcWin.height);
3770
3771 g_VEInfo.u16H_CapSize = stSrcWin->width;
3772 g_VEInfo.u16V_CapSize = stSrcWin->height;
3773 MDrv_VE_set_scaling_ratio(stScaledSrcWin.width, stScaledSrcWin.height);
3774
3775 // stage2 - Crop video from the down-scaled video. (after MIU)
3776 MSG_DRV_VE("[%s]stage 2: stCropWin (%d, %d, %d, %d) -> "
3777 "scaled_cropWin (%d, %d, %d, %d)\n",
3778 __FUNCTION__,
3779 stCropWin->x, stCropWin->y, stCropWin->width, stCropWin->height,
3780 stScaledCropWin.x, stScaledCropWin.x, stScaledCropWin.width,
3781 stScaledCropWin.height);
3782
3783 if (E_VE_OK != MDrv_VE_set_crop_window(stScaledCropWin))
3784 {
3785 MSG_DRV_VE("[%s][%d] failed\n", __FUNCTION__, __LINE__);
3786 eRet = E_VE_FAIL;
3787 goto fail;
3788 }
3789
3790 // stage3 - Scale cropped video to output video size. (after MIU)
3791 g_VEInfo.u16H_CapSize = stScaledCropWin.width;
3792 g_VEInfo.u16V_CapSize = stScaledCropWin.height;
3793 if (E_VE_OK != MDrv_VE_set_be_display_window(*stDispWin))
3794 {
3795 MSG_DRV_VE("[%s][%d] failed\n", __FUNCTION__, __LINE__);
3796 eRet = E_VE_FAIL;
3797 goto fail;
3798 }
3799 MSG_DRV_VE("[%s]stage 3: scaled_cropWin(%d, %d, %d, %d) -> "
3800 "stDispWin (%d, %d, %d, %d)\n",
3801 __FUNCTION__,
3802 stScaledCropWin.x, stScaledCropWin.x, stScaledCropWin.width,
3803 stScaledCropWin.height,
3804 stDispWin->x, stDispWin->y, stDispWin->width, stDispWin->height);
3805
3806 return E_VE_OK;
3807
3808 fail:
3809 // revert changes
3810 g_VEInfo.u16H_CapSize = u16BakHCapSize;
3811 g_VEInfo.u16V_CapSize = u16BakVCapSize;
3812 printf("Error: [%s] failed, errno: %d\n", __FUNCTION__, eRet);
3813 return eRet;
3814 }
3815
3816 #define MS_VEC_MAX_FRAMENUM_P 3 //These 2 setting should obey with driver setting in "Hal_VE_set_frc"
3817 #define MS_VEC_MAX_FRAMENUM_I 2
3818 /******************************************************************************/
3819 /// Init and config the VE capture
3820 /// @param pVECapture \b IN : @ref PMS_VE_Output_CAPTURE
3821 /// @return TRUE: success
3822 /// @return FALSE: fail
3823 /******************************************************************************/
_MDrv_VE_InitVECapture(PMS_VE_Output_CAPTURE pVECapture)3824 void _MDrv_VE_InitVECapture(PMS_VE_Output_CAPTURE pVECapture)
3825 {
3826 #ifdef MSOS_TYPE_LINUX
3827 g_VEInfo.bVECapture = pVECapture->bVECapture;
3828 if(g_VEInfo.bVECapture)
3829 {
3830 MDrv_VEC_GFLIPInit();
3831 g_VEInfo.u16OutputWidth = pVECapture->u16Width;
3832 g_VEInfo.u16Outputheight= pVECapture->u16height;
3833 g_VEInfo.u32MemSize = pVECapture->u32MemSize;
3834 g_VEInfo.phyMiuBaseAddr = (MS_PHY)pVECapture->u32MiuBaseAddr;
3835 _MDrv_VE_SetMemoryBaseAddr(g_VEInfo.phyMiuBaseAddr, g_VEInfo.u32MemSize);
3836 #if VE_TVS_ISR_SUPPORT
3837 MS_GFLIP_VEC_CONFIG stGflipVECConfig;
3838 Hal_VE_ISRConfig(MS_VE_INT_TVS_VSYNC);
3839 stGflipVECConfig.u16Version = VE_VEC_CONFIG_VERSION;//For compatibility with kernel
3840 stGflipVECConfig.u16Length = sizeof(MS_GFLIP_VEC_CONFIG);
3841 stGflipVECConfig.eConfigType = MS_VEC_CONFIG_INIT;
3842 stGflipVECConfig.bInterlace = g_VEInfo.bSrcInterlace;
3843 stGflipVECConfig.eIsrType = MS_VEC_ISR_VE;
3844 stGflipVECConfig.u8MaxFrameNumber_P = MS_VEC_MAX_FRAMENUM_P;
3845 stGflipVECConfig.u8MaxFrameNumber_I = MS_VEC_MAX_FRAMENUM_I;
3846 stGflipVECConfig.u8Result = FALSE;
3847 if (ioctl(g_VEInfo.s32FdGFlip, MDRV_GFLIP_VEC_IOC_CONFIG, &stGflipVECConfig))
3848 {
3849 MSG_DRV_VE("%s %d: IO(INIT) fail!!!!\n", __FUNCTION__, __LINE__);
3850 return;
3851 }
3852 MSG_DRV_VE("VEC: Config(%u,%u,%u,%u,%u) Return=%u\n", stGflipVECConfig.bInterlace, stGflipVECConfig.u8MaxFrameNumber_P,
3853 stGflipVECConfig.u8MaxFrameNumber_I, (MS_U8)stGflipVECConfig.eIsrType, (MS_U8)stGflipVECConfig.eConfigType, stGflipVECConfig.u8Result);
3854 #endif//VE_TVS_ISR_SUPPORT
3855 }
3856 else
3857 {
3858 g_VEInfo.stVECusScalingInfo.bHCusScalingEnable = FALSE;
3859 g_VEInfo.stVECusScalingInfo.bVCusScalingEnable = FALSE;
3860 }
3861
3862 //workaround to pass parasoft test:
3863 //[2]A pointer parameter in a function prototype should be declared as pointer to const if the pointer is not used to modify the addressed object (JSF-118-4)
3864 pVECapture->u16Width += 0;
3865 #if defined (__aarch64__)
3866 MSG_DRV_VE("VE InitVECapture bEnable=%u, W/H=%u, %u, MemBase=0x%lx, Size=%u\n",
3867 g_VEInfo.bVECapture, pVECapture->u16Width, pVECapture->u16height, pVECapture->u32MiuBaseAddr, g_VEInfo.u32MemSize);
3868 #else
3869 MSG_DRV_VE("VE InitVECapture bEnable=%u, W/H=%u, %u, MemBase=0x%tx, Size=%tu\n",
3870 g_VEInfo.bVECapture, pVECapture->u16Width, pVECapture->u16height,(ptrdiff_t) pVECapture->u32MiuBaseAddr,(ptrdiff_t) g_VEInfo.u32MemSize);
3871 #endif //def __aarch64__
3872 #endif //def MSOS_TYPE_LINUX
3873 }
3874
MDrv_VE_InitVECapture(PMS_VE_Output_CAPTURE pVECapture)3875 void MDrv_VE_InitVECapture(PMS_VE_Output_CAPTURE pVECapture)
3876 {
3877 #if TVENCODER_UTOPIA2
3878 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3879 P_TVE_INITCAPTURE pArgs = NULL;
3880
3881 if(pu32TvencoderInst == NULL)
3882 {
3883 return ;
3884 }
3885
3886 pArgs = (P_TVE_INITCAPTURE)malloc(sizeof(_TVE_INITCAPTURE));
3887
3888 if(NULL == pArgs)
3889 return ;
3890 pArgs->pVECapture = pVECapture;
3891
3892 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_InitVECapture, (void*)pArgs);
3893 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3894 {
3895 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3896 }
3897 free(pArgs);
3898 #else
3899 _MDrv_VE_InitVECapture(pVECapture);
3900 #endif
3901 }
3902 /******************************************************************************/
3903 /// Enable VE capture
3904 /// @param pstVECapState \b IN : @ref PMS_VE_VECAPTURESTATE
3905 /// @return TRUE: success
3906 /// @return FALSE: fail
3907 /******************************************************************************/
_MDrv_VE_EnaVECapture(PMS_VE_VECAPTURESTATE pstVECapState)3908 MS_BOOL _MDrv_VE_EnaVECapture(PMS_VE_VECAPTURESTATE pstVECapState)
3909 {
3910 #ifdef MSOS_TYPE_LINUX
3911 MS_GFLIP_VEC_STATE stGflipVECstate;
3912 stGflipVECstate.bEnable = pstVECapState->bEnable;//Enable or Disable
3913 stGflipVECstate.u8Result = FALSE; //default set to false
3914 stGflipVECstate.u8FrameCount = 0; //default set to 0:Invalid
3915
3916
3917 if(0 > g_VEInfo.s32FdGFlip)
3918 {
3919 MSG_DRV_VE("%s %d: GLIP device not opened!!!!\n", __FUNCTION__, __LINE__);
3920 return FALSE;
3921 }
3922
3923 #if VE_TVS_ISR_SUPPORT
3924 //Below is Progressive/Interlace config for VEC
3925 MS_GFLIP_VEC_CONFIG stGflipVECConfig;
3926 memset(&stGflipVECConfig, 0, sizeof(stGflipVECConfig));
3927 stGflipVECConfig.u16Version = VE_VEC_CONFIG_VERSION;//For compatibility with kernel
3928 stGflipVECConfig.u16Length = sizeof(MS_GFLIP_VEC_CONFIG);
3929 stGflipVECConfig.eConfigType = MS_VEC_CONFIG_ENABLE;
3930 stGflipVECConfig.bInterlace = g_VEInfo.bSrcInterlace;
3931 if (ioctl(g_VEInfo.s32FdGFlip, MDRV_GFLIP_VEC_IOC_CONFIG, &stGflipVECConfig))
3932 {
3933 MSG_DRV_VE("%s %d: IO(INIT) fail!!!!\n", __FUNCTION__, __LINE__);
3934 return FALSE;
3935 }
3936 if(TRUE == stGflipVECConfig.u8Result)
3937 #endif //VE_TVS_ISR_SUPPORT
3938 {
3939 if (ioctl(g_VEInfo.s32FdGFlip, MDRV_GFLIP_VEC_IOC_ENABLEVECAPTURE, &stGflipVECstate))
3940 {
3941 MSG_DRV_VE("%s %d: IO(ENABLE) fail!!!!\n", __FUNCTION__, __LINE__);
3942 return FALSE;
3943 }
3944
3945 pstVECapState->bEnable = stGflipVECstate.bEnable;//return current VEC status info
3946 pstVECapState->u8FrameCount = stGflipVECstate.u8FrameCount;
3947 #if VE_TVS_ISR_SUPPORT
3948 if(stGflipVECstate.u8Result == TRUE)
3949 {
3950 if(stGflipVECstate.bEnable == TRUE)
3951 {
3952 //OS_DELAY_TASK(300);
3953 Hal_VE_sofeware_reset(ENABLE); // software reset
3954 Hal_VE_set_reg_load(ENABLE);// load register,but not affect bit3(VBI output)
3955 //MsOS_DelayTask(5) ; // delay 5 ms
3956 OS_DELAY_TASK(30);
3957 Hal_VE_set_reg_load(DISABLE);// load register,but not affect bit3(VBI output)
3958 OS_DELAY_TASK(5);
3959 Hal_VE_sofeware_reset(DISABLE); // software reset
3960 OS_DELAY_TASK(5);
3961 Hal_VE_set_ve_on_off(ENABLE);
3962 }
3963 else
3964 {
3965 Hal_VE_set_ve_on_off(DISABLE);
3966 }
3967 }
3968 #endif //#if VE_TVS_ISR_SUPPORT
3969 }
3970 pstVECapState->u8Result = stGflipVECstate.u8Result;
3971 MSG_DRV_VE("%s %d: return=%u, Frame=%u\n", __FUNCTION__, __LINE__, stGflipVECstate.u8Result, stGflipVECstate.u8FrameCount);
3972 return stGflipVECstate.u8Result;
3973 #endif
3974 return FALSE; //Unsupport now
3975 }
3976
MDrv_VE_EnaVECapture(PMS_VE_VECAPTURESTATE pstVECapState)3977 MS_BOOL MDrv_VE_EnaVECapture(PMS_VE_VECAPTURESTATE pstVECapState)
3978 {
3979 #if TVENCODER_UTOPIA2
3980 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3981 PTVE_ENACAPTURE pArgs = NULL;
3982
3983 if(pu32TvencoderInst == NULL)
3984 {
3985 return FALSE;
3986 }
3987 pArgs = (PTVE_ENACAPTURE)malloc(sizeof(TVE_ENACAPTURE));
3988
3989 if(NULL == pArgs)
3990 return FALSE;
3991 pArgs->pstVECapState = pstVECapState;
3992 pArgs->eRet = E_TVENCODER_FAIL;
3993
3994 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_EnaVECapture, (void*)pArgs);
3995
3996 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3997 {
3998 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3999 }
4000
4001 if(E_TVENCODER_FAIL == pArgs->eRet)
4002 {
4003 free(pArgs);
4004 return FALSE;
4005 }
4006 else
4007 {
4008 free(pArgs);
4009 return TRUE;
4010 }
4011 #else
4012 return _MDrv_VE_EnaVECapture(pstVECapState);
4013 #endif
4014 }
4015
4016 /******************************************************************************/
4017 /// Get VE capture state
4018 /// @param pstVECapState \b OUT : @ref PMS_VE_VECAPTURESTATE
4019 /// @return TRUE: success
4020 /// @return FALSE: fail
4021 /******************************************************************************/
MDrv_VE_GetVECaptureState(PMS_VE_VECAPTURESTATE pstVECapState)4022 MS_BOOL MDrv_VE_GetVECaptureState(PMS_VE_VECAPTURESTATE pstVECapState)
4023 {
4024 #ifdef MSOS_TYPE_LINUX
4025 MS_GFLIP_VEC_STATE stGflipVECstate;
4026 stGflipVECstate.u8Result = FALSE;
4027 if(0 > g_VEInfo.s32FdGFlip)
4028 {
4029 MSG_DRV_VE("%s %d: GLIP device not opened!!!!\n", __FUNCTION__, __LINE__);
4030 return FALSE;
4031 }
4032
4033 if (ioctl(g_VEInfo.s32FdGFlip, MDRV_GFLIP_VEC_IOC_GETVECAPTURESTATE, &stGflipVECstate))
4034 {
4035 MSG_DRV_VE("%s %d: IO(GET STATE) fail!!!!\n", __FUNCTION__, __LINE__);
4036 return FALSE;
4037 }
4038 //printf("GFLP=%u\n", pstVECapState->u8FrameCount);
4039 pstVECapState->u8Result = stGflipVECstate.u8Result;
4040 if(TRUE == pstVECapState->u8Result)
4041 {
4042 pstVECapState->bEnable = stGflipVECstate.bEnable;
4043 pstVECapState->u8FrameCount = stGflipVECstate.u8FrameCount;
4044 }
4045 return stGflipVECstate.u8Result;
4046 #endif
4047 return FALSE; //Unsupport now
4048 }
4049
4050 //-------------------------------------------------------------------------------------------------
4051 /// Wait on the finish of specified frame: Check if the frame is captured,
4052 /// if Yes, return TRUE, otherwise sleep until the next Vsync ISR
4053 /// @param pstVECapState \b IN : @ref PMS_VE_VECAPTURESTATE
4054 /// @return TRUE: success
4055 /// @return FALSE: fail
4056 //-------------------------------------------------------------------------------------------------
MDrv_VE_VECaptureWaitOnFrame(PMS_VE_VECAPTURESTATE pstVECapState)4057 MS_BOOL MDrv_VE_VECaptureWaitOnFrame(PMS_VE_VECAPTURESTATE pstVECapState)
4058 {
4059 #ifdef MSOS_TYPE_LINUX
4060 MS_GFLIP_VEC_STATE stGflipVECstate;
4061 stGflipVECstate.u8FrameCount = pstVECapState->u8FrameCount;
4062 stGflipVECstate.u8Result = FALSE;
4063 if(0 > g_VEInfo.s32FdGFlip)
4064 {
4065 MSG_DRV_VE("%s %d: GLIP device not opened!!!!\n", __FUNCTION__, __LINE__);
4066 return FALSE;
4067 }
4068
4069 if (ioctl(g_VEInfo.s32FdGFlip, MDRV_GFLIP_VEC_IOC_VECAPTUREWAITONFRAME, &stGflipVECstate))
4070 {
4071 MSG_DRV_VE("%s %d: IO(WAIT) fail!!!!\n", __FUNCTION__, __LINE__);
4072 return FALSE;
4073 }
4074 //printf("GFLP=%u\n", pstVECapState->u8FrameCount);
4075 pstVECapState->bEnable = stGflipVECstate.bEnable;
4076 pstVECapState->u8Result = stGflipVECstate.u8Result;
4077 return pstVECapState->u8Result;
4078 #endif
4079 return FALSE; //Unsupport now
4080 }
4081
4082 ////////////////////////////////////////////////////////////////////////////////
4083 /// @brief \b Function \b Name: MDrv_VE_Adjust_FrameStart
4084 /// @brief \b Function \b Description : the frame start is used to adjust output video
4085 /// (in pixel)
4086 ///
4087 /// @param <IN> \b pixel_offset
4088 /// @return VE_Result
4089 ////////////////////////////////////////////////////////////////////////////////
_MDrv_VE_Adjust_FrameStart(MS_VE_WINDOW_TYPE * stSrcWin,MS_S16 pixel_offset)4090 VE_Result _MDrv_VE_Adjust_FrameStart(MS_VE_WINDOW_TYPE *stSrcWin,MS_S16 pixel_offset)
4091 {
4092 //central alignment
4093 //(720 only show 704. Align formula : Waddr mapping Raddr+8pixel)
4094 //case 1: source is not PAL mode - non-alignment
4095 //case 2: source is 704 & PAL mode and DI mode - non-alignment //DI
4096 //others : alignment //include OP:704 scale to 720 case
4097
4098 Hal_VE_SetMemAddr(&g_VEInfo.phyMiuBaseAddr,&g_VEInfo.phyMiuBaseAddr);
4099
4100 if((stSrcWin) && (g_VEInfo.VideoSystem >= MS_VE_PAL_N )&&(g_VEInfo.VideoSystem <= MS_VE_PAL ) ) //PAL mode
4101 {
4102 if(!(((stSrcWin->width==704) && (stSrcWin->height==576)) &&
4103 (g_VEInfo.InputSrcType == MS_VE_SRC_DI)) )
4104 {
4105 MS_PHY phyAlignAddr = g_VEInfo.phyMiuBaseAddr + 16;
4106 Hal_VE_SetMemAddr(&(phyAlignAddr),&g_VEInfo.phyMiuBaseAddr);
4107 }
4108 }
4109
4110 return Hal_VE_Adjust_FrameStart(pixel_offset);
4111 }
4112
MDrv_VE_Adjust_FrameStart(MS_VE_WINDOW_TYPE * stSrcWin,MS_S16 pixel_offset)4113 VE_Result MDrv_VE_Adjust_FrameStart(MS_VE_WINDOW_TYPE *stSrcWin,MS_S16 pixel_offset)
4114 {
4115 #if TVENCODER_UTOPIA2
4116 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4117 PTVE_ADJFRAMESTART pArgs = NULL;
4118
4119 if(pu32TvencoderInst == NULL)
4120 {
4121 if(UtopiaOpen(MODULE_TVENCODER, (void**)&pu32TvencoderInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
4122 {
4123 printf("UtopiaOpen TVE failed\n");
4124 return FALSE;
4125 }
4126 }
4127
4128 pArgs = (PTVE_ADJFRAMESTART)malloc(sizeof(TVE_ADJFRAMESTART));
4129
4130 if(NULL == pArgs)
4131 return E_VE_FAIL;
4132 pArgs->stSrcWin = stSrcWin;
4133 pArgs->pixel_offset = pixel_offset;
4134 pArgs->eRet = E_TVENCODER_FAIL;
4135
4136 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_Adjust_FrameStart, (void*)pArgs);
4137 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4138 {
4139 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4140 }
4141
4142 if(E_TVENCODER_FAIL == pArgs->eRet)
4143 {
4144 free(pArgs);
4145 return E_VE_FAIL;
4146 }
4147 else
4148 {
4149 free(pArgs);
4150 return E_VE_OK;
4151 }
4152 #else
4153 return _MDrv_VE_Adjust_FrameStart(stSrcWin,pixel_offset);
4154 #endif
4155 }
4156
4157 //-------------------------------------------------------------------------------------------------
4158 /// @brief \b Function \b Name: MDrv_VE_SetWSS525Data
4159 /// @brief \b Function \b Description : Start or Stop to send WSS data on 525i system
4160 /// @param bEn enable/disable wss525
4161 /// @param u32WSSData 20-bit wss data includes 14 bits of data and 6 bits of CRC
4162 ///
4163 /// @return @ref VE_Result
4164 //-------------------------------------------------------------------------------------------------
MDrv_VE_SetWSS525Data(MS_BOOL bEn,MS_U32 u32WSSData)4165 VE_Result MDrv_VE_SetWSS525Data(MS_BOOL bEn, MS_U32 u32WSSData)
4166 {
4167 #if defined (__aarch64__)
4168 MSG_DRV_VE("Enable = %d, wss525data = %u\n", bEn, u32WSSData);
4169 #else
4170 MSG_DRV_VE("Enable = %d, wss525data = %tu\n", bEn,(ptrdiff_t) u32WSSData);
4171 #endif
4172 #if 0
4173 Hal_VE_set_wss_data(bEn, u32WSSData);
4174 #else
4175 return Hal_VE_set_wss525_data(bEn, u32WSSData);
4176 #endif
4177 }
4178
4179 //-------------------------------------------------------------------------------------------------
4180 /// @brief \b Function \b Name: MDrv_VE_GetWSS525Data
4181 /// @brief \b Function \b Description : Get current wss data
4182 /// @param void
4183 ///
4184 /// @return 32-bit wss data, it includes 14 bits of data and 6 bits of CRC in lower 20 bits
4185 //-------------------------------------------------------------------------------------------------
MDrv_VE_GetWSS525Data(void)4186 MS_U32 MDrv_VE_GetWSS525Data(void)
4187 {
4188 #if 0
4189 return Hal_VE_get_wss_data();
4190 #else
4191 return Hal_VE_get_wss525_data();
4192 #endif
4193 }
4194
MDrv_VE_OnOffWSS(MS_BOOL ben)4195 void MDrv_VE_OnOffWSS(MS_BOOL ben)
4196 {
4197 Hal_VE_OnOffWSS(ben);
4198 }
MDrv_VE_GetWSSStatus(void)4199 MS_BOOL MDrv_VE_GetWSSStatus(void)
4200 {
4201 return Hal_VE_GetWSSStatus();
4202 }
MDrv_VE_OnOffMV(MS_BOOL ben)4203 void MDrv_VE_OnOffMV(MS_BOOL ben)
4204 {
4205 Hal_VE_OnOffMV(ben);
4206 }
MDrv_VE_GetMVStatus(void)4207 MS_BOOL MDrv_VE_GetMVStatus(void)
4208 {
4209 return Hal_VE_GetMVStatus();
4210 }
MDrv_VE_OnOffDCS(MS_BOOL ben)4211 void MDrv_VE_OnOffDCS(MS_BOOL ben)
4212 {
4213 Hal_VE_OnOffDCS(ben);
4214 }
MDrv_VE_GetDCSStatus(void)4215 MS_BOOL MDrv_VE_GetDCSStatus(void)
4216 {
4217 return Hal_VE_GetDCSStatus();
4218 }
4219
_MDrv_TVE_SetPowerState(EN_POWER_MODE u16PowerState)4220 MS_U32 _MDrv_TVE_SetPowerState(EN_POWER_MODE u16PowerState)
4221 {
4222 static EN_POWER_MODE _prev_u16PowerState = E_POWER_MECHANICAL;
4223 MS_U32 u32Return = FALSE;
4224
4225 if (u16PowerState == E_POWER_SUSPEND)
4226 {
4227 _prev_u16PowerState = u16PowerState;
4228 //_gbInit = false;
4229 u32Return = TRUE;//SUSPEND_OK;
4230 }
4231 else if (u16PowerState == E_POWER_RESUME)
4232 {
4233 MS_PHY phyMIUAddress = 0;
4234 MS_Switch_VE_Src_Info SwitchInputSrc;
4235 MS_VE_Output_Ctrl OutputCtrl;
4236 SwitchInputSrc.InputSrcType =g_VEInfo.InputSrcType;
4237 OutputCtrl.bEnable = TRUE;
4238 OutputCtrl.OutputType = MS_VE_OUT_TVENCODER;
4239
4240 //Use _phyVEMIUBaseAddr instead of g_VEInfo.phyMiuBaseAddr, otherwise VE memory address will add Dolby buffer address every time.
4241 //It will overlap other module and cause coredump.
4242 //_phyVEMIUBaseAddr is raw value get from VE_INIT,
4243 //this value havs add MIU interval already
4244 phyMIUAddress = _phyVEMIUBaseAddr;
4245
4246 if (_prev_u16PowerState == E_POWER_SUSPEND)
4247 {
4248 // init
4249 //_MDrv_VE_Init(u32MIUAddress);
4250 if (MDrv_VE_SetIOMapBase() != TRUE)
4251 {
4252 MSG_DRV_VE("VE: MDrv_VE_Init MDrv_VE_SetIOMapBase() failure\n");
4253 return FALSE;
4254 }
4255 //u32MIUAddress = 0x0000100000+HAL_MIU1_BASE;
4256 #if defined (__aarch64__)
4257 MSG_DRV_VE("VE input u32MIUAddress=0x%lx \n",phyMIUAddress);
4258 #else
4259 MSG_DRV_VE("VE input u32MIUAddress=0x%tx \n",(ptrdiff_t)phyMIUAddress);
4260 #endif
4261 //get chip capability
4262 Hal_VE_GetCaps(&g_VECap);
4263 _MDrv_VE_SetMemoryBaseAddr(phyMIUAddress, 0);
4264 Hal_VE_init();
4265 // set output std
4266 _MDrv_VE_SetOutputVideoStd(g_VEInfo.VideoSystem);
4267 // set input source
4268 _MDrv_VE_SwitchInputSource(&SwitchInputSrc);
4269 // switch output dest.
4270 Hal_VE_set_out_sel(g_VEInfo.u8DACType);
4271 Hal_VE_set_color_convert(g_VEInfo.VideoSystem, g_VEInfo.u8DACType);
4272 // set mode
4273 MDrv_VE_set_capture_window(); // set capture window
4274 MDrv_VE_set_scaling_ratio(g_VEInfo.u16OutputWidth, g_VEInfo.u16Outputheight); // set scaling ratio
4275 MDrv_VE_set_frc(g_VEInfo.u16inputVfreq); // set frc
4276 // set output ctrl.
4277 _MDrv_VE_SetOutputCtrl(&OutputCtrl);
4278
4279 _prev_u16PowerState = u16PowerState;
4280 u32Return = TRUE;//RESUME_OK;
4281 }
4282 else
4283 {
4284 //printf("[%s,%5d]It is not suspended yet. We shouldn't resume\n",__FUNCTION__,__LINE__);
4285 u32Return = TRUE;//SUSPEND_FAILED;
4286 }
4287 }
4288 else
4289 {
4290 //printf("[%s,%5d]Do Nothing: %d\n",__FUNCTION__,__LINE__,u16PowerState);
4291 u32Return = FALSE;
4292 }
4293
4294 return u32Return;// for success
4295 }
4296
MDrv_TVE_SetPowerState(EN_POWER_MODE u16PowerState)4297 MS_U32 MDrv_TVE_SetPowerState(EN_POWER_MODE u16PowerState)
4298 {
4299 #if TVENCODER_UTOPIA2
4300 MS_U32 u32Ret = UTOPIA_STATUS_FAIL;
4301 PTVE_SETPOWERSTATE pArgs;
4302 if(pu32TvencoderInst == NULL)
4303 {
4304 return FALSE;
4305 }
4306 pArgs = (PTVE_SETPOWERSTATE)malloc(sizeof(TVE_SETPOWERSTATE));
4307
4308 if(NULL == pArgs)
4309 return FALSE;
4310 pArgs->ePowerState = u16PowerState;
4311 pArgs->eRet = E_TVENCODER_FAIL;
4312
4313 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_SetPowerState, (void*)pArgs);
4314
4315 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4316 {
4317 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4318 }
4319
4320 if(E_TVENCODER_FAIL == pArgs->eRet)
4321 {
4322 free(pArgs);
4323 return FALSE;
4324 }
4325 else
4326 {
4327 free(pArgs);
4328 return TRUE;
4329 }
4330 #else
4331 return _MDrv_TVE_SetPowerState(u16PowerState);
4332 #endif
4333 }
4334
4335 //-------------------------------------------------------------------------------------------------
4336 /// @brief \b Function \b Name: MDrv_VE_ReloadSetting()
4337 /// @brief \b Function \b Description : Do SW resetting do confirm all change are applied
4338 /// @param void
4339 ///
4340 /// @return @ref VE_Result
4341 //-------------------------------------------------------------------------------------------------
_MDrv_VE_ReloadSetting(void)4342 VE_Result _MDrv_VE_ReloadSetting(void)
4343 {
4344 return Hal_VE_ReloadSetting();
4345 }
4346
4347 //------------------------------------------------------------------------------
4348 /// @brief \b Function \b Name: MDrv_VE_ReloadSetting()
4349 /// @brief \b Function \b Description : Do SW resetting do confirm all change are applied
4350 /// @param void
4351 ///
4352 /// @return @ref VE_Result
4353 //------------------------------------------------------------------------------
MDrv_VE_ReloadSetting(void)4354 VE_Result MDrv_VE_ReloadSetting(void)
4355 {
4356 #if TVENCODER_UTOPIA2
4357 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4358 PTVE_RELOADSETTING pArgs = NULL;
4359 if(pu32TvencoderInst == NULL)
4360 {
4361 return FALSE;
4362 }
4363 pArgs = (PTVE_RELOADSETTING)malloc(sizeof(PTVE_RELOADSETTING));
4364
4365 if(NULL == pArgs)
4366 {
4367 return E_TVENCODER_FAIL;
4368 }
4369 pArgs->eRet = E_TVENCODER_FAIL;
4370
4371 u32Ret = UtopiaIoctl(pu32TvencoderInst, E_MDRV_CMD_TVE_ReloadSetting, (void*)pArgs);
4372 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4373 {
4374 printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4375 }
4376
4377 if(E_TVENCODER_OK == pArgs->eRet)
4378 {
4379 free(pArgs);
4380 return TRUE;
4381 }
4382 else
4383 {
4384 free(pArgs);
4385 return FALSE;
4386 }
4387 #else
4388 return _MDrv_VE_ReloadSetting();
4389 #endif
4390
4391 }
4392 #endif
4393
4394