/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/


#ifndef _DRV_TVE_H_
#define _DRV_TVE_H_

#include "x_typedef.h"
#if 0	// johnny mark  20080320
#include "drv_pmx.h"
#endif	// johnny mark  20080320
#include "x_os.h"       /* using x_memset() */

/* Maximum number of plane mixer */
#define TVE_1				0	/* Main display */
#define TVE_2				1	/* Aux display */
#define TVE_MAX_NS			2

/* TVE configuration return value */
#define TVE_SET_ERROR		0
#define TVE_SET_OK			1
#define TVE_SET_VBI_OVERFLOW	2

/* TVE output */
#define TVE_OUT_CVBS		0
#define TVE_OUT_S_VIDEO	    1
#define TVE_OUT_YBR			2
#define TVE_OUT_RGB			3
#define TVE_MAX_OUT			4

/* TVE mode */
#define TVE_MOD_COMPOSITE		0
#define TVE_MOD_COMPONENT		1
#define TVE_MOD_RGB			    2
#define TVE_MOD_VGA             TVE_MOD_RGB
#define TVE_MAX_MOD			    3

/* TVE format */

#if 1	// johnny add  20080320
// Plane mixer mode
#define PMX_MODE_480I			0
#define PMX_MODE_576I			1
#define PMX_MODE_480P			2
#define PMX_MODE_576P			3
#define PMX_MODE_720P			4
#define PMX_MODE_1080I			5

#define PMX_MODE_768P			6
#define PMX_MODE_540P			7
#define PMX_MODE_768I			8
#define PMX_MODE_1536I			9
#define PMX_MODE_720I			10
#define PMX_MODE_1440I			11
#define PMX_MODE_UNKNOWN		12
#endif 

#define TVE_FMT_480I                    PMX_MODE_480I
#define TVE_FMT_576I                    PMX_MODE_576I
#define TVE_FMT_480P                    PMX_MODE_480P
#define TVE_FMT_576P                    PMX_MODE_576P
#define TVE_FMT_720P                    PMX_MODE_720P
#define TVE_FMT_1080I                   PMX_MODE_1080I
#define TVE_FMT_768P                    PMX_MODE_768P
#define TVE_MAX_FMT                     2

/* TVE field */
#define TVE_FIELD_ODD			0
#define TVE_FIELD_EVEN			1
#define TVE_FIELD_BOTH			2

/* TVE Macrovision APS types */
#define TVE_MV_APS_Type0		0
#define TVE_MV_APS_Type1		1
#define TVE_MV_APS_Type2		2
#define TVE_MV_APS_Type3		3
#define TVE_MAX_MV_APS			4

#define TVE_MAX_MV_TEST_CASES   6

/* TVE Low/High Impedence */
#define TVE_LOW_IMPEDENCE       0   /* for MT5351_DEMO_BOARD */
#define TVE_HIGH_IMPEDENCE      1   /* for MT5351_M1_BOARD */

/* TVE WSS/CGMS Aspect Ratio
   NOR: Normal, LB: LetterBox, C: Center, T: Top, LG: Larger than
   525-Line (CGMS) */
#define CGMS_NOR_4_3			0
#define CGMS_NOR_16_9			1
#define CGMS_LB_4_3             2
#define CGMS_LB_16_9			3
/* 625-Line (WSS)  */
#define WSS_LB_14_9_C			1
#define WSS_LB_14_9_T			2
#define WSS_LB_16_9_T			4
#define WSS_ANA_16_9			7
#define WSS_FULL_4_3			8
#define WSS_LB_16_9_C			11
#define WSS_LB_LG_16_9_C		13
#define WSS_FULL_14_9_C			14

/* TVE Mixer select */
#define TVE_VDOIN_MIXER	0
#define TVE_DEMOD_MIXER	1
#ifdef CC_MT5363
#define TVE_SIF_MIXER		2
#endif

//TVE field invert WA
//#ifndef CC_MT5363
#define TVE_WA //mt5387
//#else
//#endif

/******************************************************************************
* TVE API
******************************************************************************/
extern UINT32 TVE_Init(void);
extern UINT32 TVE_UnInit(void);
extern UINT32 TVE_Reset(UCHAR ucTveId);
extern UINT32 TVE_QueryStatus(void);

extern UINT32 TVE_SetEnable(UCHAR ucTveId, UCHAR ucEnable);
extern UINT32 TVE_GetEnable(UCHAR ucTveId, UCHAR* pucEnable);

extern UINT32 TVE_SetMode(UCHAR ucTveId, UCHAR ucMode);
extern UINT32 TVE_GetMode(UCHAR ucTveId, UCHAR* pucMode);

extern UINT32 TVE_SetFmt(UCHAR ucTveId, UCHAR ucFmt);
extern UINT32 TVE_GetFmt(UCHAR ucTveId, UCHAR* pucFmt);

extern UINT32 TVE_SetImpedence(UCHAR ucTveId, UCHAR ucImpedence);
extern UINT32 TVE_GetImpedence(UCHAR ucTveId, UCHAR* pucImpedence);

extern UINT32 TVE_SetColorBar(UCHAR ucTveId, UCHAR ucOn);
extern UINT32 TVE_SetCcEnable(UCHAR ucTveId, UCHAR ucEnable);
extern UINT32 TVE_GetCcEnable(UCHAR ucTveId, UCHAR* pucCcEnable);
extern UINT32 TVE_SendCc(UCHAR ucTveId, UCHAR ucField, const UCHAR *pucData, PTS_T u8Pts);
extern UINT32 TVE_SendCcIsr(UCHAR ucTveId, UCHAR ucIsOddField, UINT32 u4PmxPts);
/*
extern UINT32 TVE_SetMvEnable(UCHAR ucTveId, UCHAR ucEnable);
extern UINT32 TVE_GetMvEnable(UCHAR ucTveId, UCHAR* pucMvEnable);
extern UINT32 TVE_WriteMvValue(UCHAR ucTveId, UINT32 u4MvReg, UINT32 u4Value);
extern UINT32 TVE_ReadMvValues(UCHAR ucTveId);
extern UINT32 TVE_MvTest(UCHAR ucTveId, UCHAR ucCaseNum);
extern UINT32 TVE_GetMvTest(UCHAR ucTveId, UCHAR* pucValue);
*/
extern UINT32 TVE_SetWssEnable(UCHAR ucTveId, UCHAR ucEnable);
extern UINT32 TVE_GetWssEnable(UCHAR ucTveId, UCHAR* pucWssEnable);
extern UINT32 TVE_SendWss(UCHAR ucTveId,const UCHAR *pu1Buf, UINT32 length);
extern UINT32 TVE_SetAspectRatio(UCHAR ucTveId, UCHAR ucAspectRatio);
extern UINT32 TVE_GetAspectRatio(UCHAR ucTveId, UCHAR* pucAspectRatio);
extern UINT32 TVE_SetCgmsaValue(UCHAR ucTveId, UCHAR ucValue);
extern UINT32 TVE_GetCgmsaValue(UCHAR ucTveId, UCHAR* pucValue);

extern UINT32 TVE_PlayCc(UCHAR ucTveId, UCHAR ucEsId);
extern UINT32 TVE_StopCc(UCHAR ucTveId, UCHAR ucEsId);
extern UINT32 TVE_SetTTXEnable(UCHAR ucTveId, UCHAR ucEnable);
extern UINT32 TVE_GetTTXEnable(UCHAR ucTveId, UCHAR* pucTTXEnable);
extern UINT32 TVE_SendTTX(UCHAR ucTveId,const UCHAR *pu1Buf, UINT32 length);

extern UINT32 TVE_DACPower(UCHAR ucTveId, UCHAR DAC, UCHAR ucEnable);
extern UINT32 TVE_OnInputVSync(void);

extern void Bypass_Init(void);
extern UINT32 TVE_GetFieldInfo(UCHAR ucTveId);
extern void  _TVE_Mainloop(void);
#if 0
extern UINT32 AuxOutConnect(UCHAR ucDACid, UCHAR ucDACSrc);
extern UINT32 AuxOutDisconnect(UCHAR ucDACid, UCHAR ucDACSrc);
extern UINT32 AuxOut_VideoStart(UCHAR ucDACid);
extern UINT32 AuxOut_VideoStop(UCHAR ucDACid);
extern UINT32 AuxOut_VideoMute(UCHAR ucDACid, UCHAR ucOn);
extern UINT32 AuxOut_SendVbiData(UCHAR ucDACid, UCHAR eType, UCHAR *pu1Buf, UINT32 length);
extern UINT32 AuxOut_VbiEnable(UCHAR ucDACid, UCHAR eType, UCHAR ucOn);
#endif
extern UINT32 TVE_SelectInput(UCHAR ucTveSrc);
extern UINT32 TVE_OSDpath(UCHAR ucTveId, UCHAR ucOn);
#ifdef CC_MT5363
extern UINT32 TVE_PIPMixer(UCHAR ucTveId, UCHAR ucEnable);
#endif
#endif /* _DRV_TVE_H_ */

