/* 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: wenming.wu $
 * $Date: 2016/02/29 $
 * $RCSfile: drv_dvi.h,v $
 * $Revision: #7 $
 *
 *---------------------------------------------------------------------------*/
/**
 * @file DVI/HDMI/CCIR decoder driver interface
 *
 * @author daniel_hsiao@mtk.com.tw
 */

#ifndef _DRV_DVI2_H_
#define _DRV_DVI2_H_

#include "typedef.h"
#include "drv_hdmi2.h"

enum
{
    DVI_NO_SIGNAL,
    DVI_CHK_MODECHG,
    DVI_WAIT_STABLE
};

enum
{
	DVI_3D_NONE,
	DVI_FP_progressive,
	DVI_FP_interlace,
	DVI_SBS_full_progressive,
	DVI_SBS_full_interlace,
	DVI_Field_Alternative
};

typedef struct
{
	
	UINT8   _bDviChkState;
	UINT8   _bDviModeChgFlg;
	UINT8	_bDviVclk;
	UINT32	_wDviHclk; // timing table: table value; otherwise, the value used by timing search
	UINT32	_wDviPixclk;
	UINT32	_wDviWidth;
	UINT32	_wDviHeight;
	UINT32	_wDviHtotal;
	UINT32	_wDviVtotal;
	UINT8   _bInterlace;
	UINT8	_bDviTiming;
	UINT8   _bWidthStableCnt;
	UINT8   _bHeightStableCnt;
	UINT8   _bVclkStableCnt;
	UINT8   _bWidthStableFlg;
	UINT8   _bHeightStableFlg;

	UINT8  _bModeChgCnt;
	UINT8  _bDeChgCnt;
	UINT8  _bPixelClkChgCnt;
	UINT8  _bColorChgCnt;
	UINT8  _bNoSigalCnt;
	UINT8  _bNoConnectCnt;
	UINT8  _bInfoChgCnt;

	UINT8	_bDviVclkTmp;
	UINT32	_wDviWidthTmp;
	UINT32	_wDviHeightTmp;
	UINT32	_wDviHtotalTmp;
	UINT32	_wDviVtotalTmp;
//Monitor mode change status start
	UINT8   _bHdmiMD;
	UINT8   _bHdmi4KPsStaChg;
	UINT8   _bHdmiRange;
	UINT8   _bHdmi422Input;
	UINT8   _bHdmiColorMetry;
        UINT8   _bHdmi3DEnable;
        UINT8   _bHdmi3DStructure;
        UINT8   _bHDMIColorSpace;
        UINT32 _bQueryMode;
    //Monitor mode change status end
}DviStatus_t;

extern UINT8   _bDviExtSrc;


#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)

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 vDvi2Initial(UINT8 bchannel);
extern void vDvi2Connect(UINT8 bchannel, UINT8 fgIsOn);
extern UINT8 bDvi2GetPath(HdmiRxPort ePort);
extern UINT8 bDvi2GetActivePort(UINT8 u1Type);
extern void vCCIRSelW2D(UINT8 u1Type, BOOL bSelW2d);
#if defined(CC_SUPPORT_W2DR2R)
extern void vCCIR2SetR2RPath(UINT8 u1Type);
#endif
extern UINT16 wDvi2InputHTotal(UINT8 u1Type);
extern UINT16 wDvi2InputVTotal(UINT8 u1Type);
extern UINT16 wDvi2InputWidth(UINT8 u1Type);
extern UINT16 wDvi2InputHeight(UINT8 u1Type);
extern void vDvi2SetModeDone(UINT8 u1Type);
extern void vDvi2SetModeChange(UINT8 u1Type);
extern UINT32 dwDVI2GetVtotal(UINT16 u2HdmiBase);	
extern UINT32 dwDVI2GetHtotal(UINT16 u2HdmiBase);
extern BOOL fgDVI2GetHAct(UINT16 u2HdmiBase);
extern UINT32 dwDVI2GetWidth(UINT16 u2HdmiBase);
extern UINT32 dwDVI2GetHeight(UINT16 u2HdmiBase);
extern UINT32 dwDvi2PIXClock(UINT16 u2HdmiBase);
extern UINT32 dwDvi2HSClock(UINT16 u2HdmiBase);
extern UINT32 dwDvi2VSClock(UINT16 u2HdmiBase);
extern UINT8 bDvi2GetColorSpace(UINT8 u1Type);
extern void vDvi2SetColorSpace(UINT8 u1Type,UINT8 u1ClrSpc);
extern UINT8 bDvi2RefreshRate(UINT8 u1Type);
extern UINT8 bDvi2SigStatus(UINT8 u1Type);
extern UINT8 bDvi2Interlace(UINT8 u1Type);
extern BOOL fgIsDvi2VideoTiming(UINT8 u1Type);
extern void vDvi2ModeDetect(UINT8 u1Type);
extern void vDvi2ChkModeChange(UINT8 u1Type);
extern BOOL fgDvi2IsModeChg(UINT8 bchannel);
extern UINT8 bDvi23DPacketVaild(UINT8 u1Type);
extern UINT32 dwDvi2Get3DVtotal(UINT8 u1Type);
extern UINT32 dwDvi2Get3DVactive(UINT8 u1Type);
extern UINT32 dwDvi2Get3DHtotal(UINT8 u1Type);
extern UINT32 dwDvi2Get3DHactive(UINT8 u1Type);
extern UINT8 bDvi2Get3DRefreshRate(UINT8 u1Type);
extern void vDvi2GetDebugMessage(UINT8 u1Type);
extern UINT32 wDvi2QueryAP3DSetting(UINT8 u1Type);
extern UINT8 bDvi2GetInterlaced(UINT8 u1Type);
extern UINT16 wDvi2GetPorch(UINT8 bPath, UINT8 bPorchType);
extern void vDvi2SetPorch(UINT8 bPath, UINT8 bPorchType, UINT16 wValue);
extern UINT8 bDvi2IsVideoTiming(UINT8 bPath);
extern UINT8 bGetSupportHdmi2ModeVideoTiming(UINT8 bPath);
extern void vDVI2FixColor(UINT8 bPath);
#endif
