/* 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.
 *
 *****************************************************************************/

/*
 * $Author: dtvbm11 $
 * $Date: 2015/11/10 $
 * $RCSfile: drv_dvi.h,v $
 * $Revision: #1 $
 *
 *---------------------------------------------------------------------------*/
/**
 * @file DVI/HDMI/CCIR decoder driver interface
 *
 * @author daniel_hsiao@mtk.com.tw
 */

#ifndef _DRV_DVI_H_
#define _DRV_DVI_H_

#include "typedef.h"

#define CCIR_decode_444	 1

extern BOOL   _IsDviDetectDone;
extern UINT8   _bDviExtSrc;
extern UINT8   _bSync1Vsyn2;
extern UINT8   _bDviTiming;
extern UINT16   _wDviWidth;
extern UINT16   _wDviHeight;
extern UINT8   _bDviVclk;
extern UINT8   _bDviModeDetState;
extern UINT8 _bDviChkState;
extern UINT32 _bQueryMode;

#define fgIsExtSrcDVI() (_bDviExtSrc&SV_DV_DVI)
#define fgIsExtSrcHDMI() (_bDviExtSrc&SV_DV_HDMI)
#define fgIsExtSrcAdYPbPr() (_bDviExtSrc&SV_DV_AD_YPbPr)
#define fgIsExtSrcAdRGB() (_bDviExtSrc&SV_DV_AD_RGB)
#define fgIsExtSrcCCIR() (_bDviExtSrc&SV_DV_CCIR)
#define fgIsExtSrcFromCCIR() (_bDviExtSrc&SV_DV_FROM_CCIR)
#define fgIsExtSrcDTV() (_bDviExtSrc&SV_DV_DTV)

#define RANGE_CHECKING(a, b, offset)  ((UINT32)((a)+(offset)-(b)) <= ((offset)*2))

/*BEGIN: 2014-5-9 George.Yang For modifying the CCIR-AVStart\AVWidth\VSStart\VDEWidth*/
typedef struct{
	UINT16  Cur_AVStart_Value;
	UINT16  Old_AVStart_Value;
	UINT16  Cur_AVWidth_Value;
	UINT16  Old_AVWidth_Value;

	UINT16  Cur_VSStart_Value;
	UINT16  Old_VSStart_Value;
	UINT16  Cur_VDEWidth_Value;
	UINT16  Old_VDEWidth_Value;

	UINT8   New_Pattern_Num;
	UINT8   Old_Pattern_Num;
	
}CCIR_Blank_Value_T;
extern CCIR_Blank_Value_T CCIRBlankValue;
/*END: 2014-5-9 George.Yang For modifying the CCIR-AVStart\AVWidth\VSStart\VDEWidth*/


extern void vCCIROSDOnOff(UINT8 fgIsOn);
extern void vCCIROSDInitial(void);
extern void vCCIROSDConnect(UINT8 bchannel, UINT8 fgIsOn) ;
extern void vCCIROSDConnect(UINT8 bchannel, UINT8 fgIsOn);
extern UINT16 wCCIROSDInputHTotal(void);
extern UINT16 wCCIROSDInputVTotal(void);
extern UINT16 wCCIROSDInputWidth(void);
extern UINT16 wCCIROSDInputHeight(void);
extern UINT8 bCCIROSDRefreshRate(void);
extern UINT8 bCCIROSDInterlace(void);
extern void vCCIROSDSETVSTART(void);
extern UINT8 bCCIROSDSigStatus(void);
extern void vCCIROSDDebugMsg(void);

extern void vDviConnect(UINT8 bchannel, UINT8 fgIsOn) ;
extern UINT16 wDviInputWidth(void) ;
extern UINT16 wDviInputHeight(void) ;
extern UINT8 bDviRefreshRate(void) ;
extern UINT8 bDviInterlace(void) ;
extern UINT8 bDviSigStatus(void) ;
extern UINT8 bDviIsVideoTiming(void);
extern UINT8 bDviIsNativeVideoTiming(void);

extern void vDviISR(void) ;
extern UINT8 bGetSupportHdmiModeVideoTiming(void);
extern void vDviModeDetect(void) ;
extern void vDviChkModeChange(void) ;

extern void vDviSetAvStart(UINT16 wStart) ;
extern void vDviSetAvWidth(UINT16 wWidth);
extern void vDviSetVsStart(UINT16 wStart);
extern void vDviSetVsWidth(UINT16 wWidth);
extern void vHdmiInformModeChg(void);
extern UINT16 wDviGetAvWidth(void) ;

extern UINT16 wCCIRGetAvWidth(void);

UINT8 bDviStdTimingSearch(UINT8 ) ;
void vDviInitial(void);
void vDVIDebugMsg(void);
extern UINT8 bDVICENStatus(void);
extern UINT8 bCCIRCENStatus(void);
extern UINT16 wDviInputHTotal(void);
extern UINT16 wDviInputVTotal(void);
extern void vDviTDTVCB(void *pvArgv);
extern void bHDMI3DLRFreeRunControl(UINT8 bvalue);
#ifdef CC_SUPPORT_W2DR2R
UINT8 bDviStdTimingSearchByPort(UINT8 bMode,UINT8 u1HdmiPort);
#endif
#ifdef CC_AUD_HDMI_SPDIF_CFG
extern UINT8 API_Get_Audio_SPDIF_STATUS(void);
#endif
//extern void vHDMISwitchInit(void);
#endif
