#include "x_timer.h"
#ifndef _DRV_W2DR2R_H_
#define _DRV_W2DR2R_H_
typedef struct R2R_T
{
	UINT32 u4Htotal;
	UINT32 u4Vtotal;
	UINT32 u4HsyncWidth;
	UINT32 u4Width;
	UINT32 u4Height;
	UINT32 u4VsyncStart;
	UINT32 u4VsyncEnd;
	UINT32 u4VsyncEvenStart;
	UINT32 u4VsyncEvenEnd;
	UINT32 u4HdeStart;
	UINT32 u4HdeEnd;
	UINT32 u4VdeStart;
	UINT32 u4VdeEnd;
	UINT32 u4VdeEvenStart;
	UINT32 u4VdeEvenEnd;
	UINT32 u43DFpVsyncStart;
	UINT32 u43DFpVsyncEnd;
	UINT32 u43DFpVdeStart;
	UINT32 u43DFpVdeEnd;
	UINT8  u1BitNum;
	UINT8  u1VB1Enable;
	UINT8  u1CaptureEnable;
	UINT8  u1R2r4096to3840;
	UINT8  fgR2r3DFp;
	UINT32 u4R2rMuteCnt;
	UINT8  fgR2rInterlaced;
}R2R_CONFI;
typedef struct 
{
	UINT32 u4HTotal;
	UINT32 u4HFrontPorch;
	UINT32 u4HSyncWidth;
	UINT32 u4HBackPorch;
	UINT32 u4HActive;

	
	UINT32 u4VTotal;
	UINT32 u4VFrontPorch;
	UINT32 u4VSyncWidth;
	UINT32 u4VBackPorch;
	UINT32 u4VActive;

}R2R_DISPLAY_T;

typedef struct W2D_T
{
	UINT32 u4Width;
	UINT32 u4Height;
	UINT8 u1BitNum;
	UINT8 u1IsHdmi422;
	UINT8 u4W2DLeftAndRight;
	UINT8 u1W2DStatusGoodFlg;
	UINT8 u1W2DIntMonitorCnt;   // for w2d enable ,but no int issue
	UINT8 u1W2DIntGoodCnt;
	UINT8 u1CutEnable;
}W2D_CONFI;
typedef struct 
{
	UINT32 u4Htotal;
	UINT32 u4Vtotal;
	UINT32 u4Hde;
	UINT32 u4HsyncFrontPorch;
	UINT32 u4HsyncWidth;
	UINT32 u4HsyncbackPorch;
	UINT32 u4Vde;
	UINT32 u4VsyncFrontPorch;
	UINT32 u4VsyncWidth;
	UINT32 u4VsyncbackPorch;
	UINT8 u1FrameRate;
	UINT8 vicCode;
	UINT8  u1IsInterlaceTiming;
}HDMI_TIMING_T;

typedef struct W2D_TXT
{
	W2D_CONFI eW2dConfi;
	UINT32 u4VideoTxtAddr;
	UINT8 WritingTxtStatus;  //0: no request  1: request start  2:writing...  3 write done;
	UINT8 txtureModeEnable;
	UINT8 timingStableCnt;
	UINT8 timingStable;
	UINT8 hdmiPortId;
	UINT8 dvitiming;
}W2D_VIDEO_TXT_CONFI;
typedef struct R2R_TXT
{
	R2R_CONFI eR2rconfi;
	UINT32 u4VideoTxtAddr;
	UINT8 ReadingTxtCnt;  //0: no request  1: request start  2:writing...  3 write done;
	UINT8 fgR2rsettingdone;
}R2R_VIDEO_TXT_CONFI;

typedef struct 
{
	UINT32 u4FrameYaddr;
	UINT32 u4FrameUaddr;
	UINT32 u4FrameVaddr;
}R2R_FRAME_ADDR;
typedef struct 
{
//left
	UINT32 u4FrameLYaddr;
	UINT32 u4FrameLUaddr;
	UINT32 u4FrameLVaddr;
//right	
	UINT32 u4FrameRYaddr;
	UINT32 u4FrameRUaddr;
	UINT32 u4FrameRVaddr;
}W2D_FRAME_ADDR;
typedef struct 
{
	UINT32 u4OldW2dStatus;
	UINT32 u4NewW2dStatus;
	UINT32 u4StatusWrongCnt;
	UINT32 u4StatusGoodCnt;
}W2D_STA_MONITOR_T;
typedef struct
{
	UINT32 port;
	UINT32 Yaddr;
	UINT32 Uaddr;
	UINT32 Vaddr;
	UINT32 width;
	UINT32 height;
	UINT32 pitch; 
	UINT32 isRgb;  //  1 : RGB, 0: YUV
}W2D_VDO_TXTURE_TYPE;
extern UINT32 u4W2DGetBase(BOOL fgLeft);
extern BOOL bGetR2RVb1Enable(void);
extern void vSetR2RVb1Enable(BOOL fgEnable);
extern UINT32 dwGetR2RConfigWidth(void);
extern UINT32 dwGetR2RConfigHTotal(void);
extern E_HDMI_SWITCH_NUM bGetW2dActivePort(void);
extern void vW2DEnable(BOOL fgLeft);
extern	void vW2DDisable(BOOL fgLeft);
extern BOOL bW2DIsEnable(BOOL fgLeft);
extern BOOL bIsW2DR2RPort(E_HDMI_SWITCH_NUM u1Port);
extern void vW2DSetPackMode(UINT8 u1PackMode);
extern void vW2DSetLAddr(UINT32 u4ChAaddr,UINT32 u4ChBAddr, UINT32 u4ChCAddr);
extern	void vW2DSetRAddr(UINT32 u4ChAaddr,UINT32 u4ChBAddr, UINT32 u4ChCAddr);
extern void vW2DCutEnalbe(BOOL fgCutEn,BOOL fgCutLeftAndRight);
extern void vW2DSetPitch(UINT32 u4HdeWidth,UINT8 u1BitNum,UINT8 u1W2DLAndR);
extern	void vW2DSetVeticalLine(UINT32 u4VerticalLine);
extern void vW2DSetVsyncStart(UINT32 u4VsyncStart);
extern void vW2DInit(void);
extern void vConfiW2D(W2D_CONFI w2dConfigure);
extern void vW2DClrLeftInt(void);
extern void vW2DClrRightInt(void);
extern void vR2RSetHtoalAndVtotal(UINT32 u4Htotal,UINT32 u4Vtotal);
extern void vR2RSetHsyncWidth(UINT32 u4HsyncWidth);
extern void vR2RSetHdewAndVdew(UINT32 u4HdeWidth,UINT32 u4VdeWidth);
extern void vR2RSetVsync(UINT32 u4VsyncStart,UINT32 u4VsyncEnd,UINT32 u4VsyncEvenStart,UINT32 u4VsyncEvenEnd);
extern void vR2RSetHde(UINT32 u4HdeStart,UINT32 u4HdeEnd);
extern void vR2RSetVde(UINT32 u4VdeStart,UINT32 u4VdeEnd,UINT32 u4VdeEvenStart,UINT32 u4VdeEvenEnd);
extern void vR2RSetPitch(UINT32 u4HdeWidth,UINT8 u1BitNum);
extern void vR2RSetWordMax(UINT32 u4HdeWidth,UINT8 u1BitNum);
extern void vR2RSetADDR(UINT32 u4ChA,UINT32 u4ChB,UINT32 u4ChC);
extern void vR2REnableWriteBack(BOOL fgEnable);
extern void vR2RSetPacketMode(UINT8 u1BitNum);
extern void vR2RSetBypassMode(BOOL fgEnable);
extern BOOL vR2RIsR2RInt(void);
extern void vR2RClrR2RInt(void);
extern void vR2RIntEnable(BOOL fgEnable);
extern void vR2REnableDram(BOOL fgEnable);
extern void vR2REnableTiming(BOOL fgEnable);
extern BOOL fgIsR2REnableBypass(void);
extern void vR2RRoundMidEn(BOOL fgEnable);
extern void vR2RInit(void);
extern void vConfiR2R(R2R_CONFI r2rConfigure);
extern void vW2DFPGAemulation(void);
extern void vSetW2DControl(W2D_CONFI *w2dConfigure,UINT8 DviTiming);
extern void vSetR2RControl(R2R_CONFI *r2rConfigure,UINT8 DviTiming);
extern void vHDMIW2DR2RSetting(UINT8 u1PortL,UINT8 u1PortR);
extern void _vHdmiR2rISR(UINT16 u2Vector);
extern void vHdmiR2rIntHandle(void);

extern void vHdmiW2dIntHandle(void);
extern void vW2DSetFrameAddr(W2D_FRAME_ADDR arW2dWriteFrameAddr);
extern void vR2RSetFrameAddr(R2R_FRAME_ADDR arFrameAddr);
extern void vR2RRegisterIsr(void);
extern void vHDMICreateR2rThread(void);
extern void vHDMICreateW2dThread(void);
extern void vSetW2dControlCmd(UINT32 u4Height,UINT32 u4Width,UINT8 u1BitNum, UINT8 u1Is422,UINT8 u1LeftAndRight);
extern void vSetR2RControlCmd(UINT8 u1timingVic,UINT8 u1BitNum,UINT8 u1vb1Enable);
extern void vR2RSetPatternEn(BOOL fgPatternEn, UINT32 u4YPadding, UINT32 u4UPadding, UINT32 u4VPadding);
extern void vW2dR2rInit(void);
extern void vW2dR2rFbmInit(void);
extern void vConfigW2DR2RAddr(UINT32 u4BaseAddr,UINT32 u4BaseAddr2,UINT32 u4BaseAddr3,UINT32 u4Width,UINT8 u1BitNum);
void vDisableW2dR2r(void);
void vEnableW2dR2r(void);
void vW2DLeftSetInputDataAndClk(UINT8 u1HdmiPortL);
void vW2DRightSetInputDataAndClk(UINT8 u1HdmiPortR);
void vW2dR2rPrintStatus(void);
void vR2RSelVB1Oclk(void);
void vR2RSelMainCLK(void);
void vR2RSelSubCLK(void);
void vR2RCCIRSelCLK(UINT8 u1R2R);
void vCCIRSelMainCLK(void);
void vCCIRSelSubCLK(void);
void u4R2rReadNextFrame(void);
void u4W2dWriteNextFrame(void);
UINT32 u4W2dFrameSize(UINT32 height, UINT32 width, UINT8 bitNum);
void vW2dR2rUseSameFrame(UINT8 fgSame);
extern UINT8 fgHDMIW2DR2REnable;
extern UINT8 fgW2dForceLeftAndRight;
void vW2dForceLR(UINT8 fgLR);
void vR2RtoVB1Path(void);
void vR2RSetOmuxOutput(UINT8 u1MainSub,UINT8 u1OutputEn);
void vR2RSelPortTiming(UINT8 u1Port);
void vUhdInitR2rSlaveMode(UINT8 bOnOff);
typedef enum W2D_CONFI_T {
	W2D_NO_NEED = 0,
	W2D_USE_LEFT_ONLY,
	W2D_USE_LEFT_AND_RIGHT
}W2D_CONFI_TYPE;

W2D_CONFI_TYPE vDviTimingNeedW2d(UINT8 u1Dvitiming);
#ifdef CC_HDMI_2_0_SUPPORT
extern W2D_CONFI_TYPE vDviTimingNeedW2d_V2(void);
#endif
extern UINT8 fgForceUseW2D;
extern UINT8 fg2k2ktoOmux;

void vW2dR2rReadWriteSyncInit(void);
void vR2RSetCapureMode(UINT8 fgEnable);
void vW2d2K2KtoOmux(UINT8 fgEnable);
void vW2dStatusReset(void);
void vW2dChangeFifoTh(UINT8 threshold,UINT8 thresholdY);
void vW2dSetFifoThreshold(UINT8 threshold,UINT8 thresholdY);
void vW2dUseChannelC(UINT8 u1Use);
void vW2dSetVideoTextureControl(UINT8 port,UINT8 enable);
void vR2rSetVideoTextureControl(UINT32 u4Addr,UINT8 u1BitNum,UINT32 u4ReadCnt);
void vW2dConfiVideoTexture(W2D_VIDEO_TXT_CONFI ew2dVideoTxt);
void vR2rConfiVideoTexture(R2R_VIDEO_TXT_CONFI er2rVideoTxt);
BOOL bR2rSelVB1Path(void);
void vR2rConfigFptoFs(UINT8 fgFpInput,UINT32 u4VsyncStart,UINT32 u4VsyncEnd,UINT32 u4VdeStart,UINT32 v4VdeEnd);
void vForR2r3D(UINT8 u1R2r3dInput);
void vW2dWriteVdoTxture(UINT8 u1HdmiPort,UINT32 u4StartAddr,UINT8 u1BitNum);
BOOL IsW2dWritingTxture(void);
void vR2rEnable(UINT8 enable);
void vR2rSetMuteCnt(UINT32 muteCnt);
void vW2dTxtureModeLoop(void);
void vR2rconfigVb1Display(R2R_CONFI eR2rconfi);
void vW2dR2rConfiColorFormatTrans(void);
void vW2dR2rErrorHandle(void);
void vW2dReset(void);
void vR2rRegisterDisplayCB(void);
UINT32 u4GetVdoTxtureHdmiPort(UINT32 u4RzId);
UINT8 u1R2rGetDumpFrameAddr(W2D_VDO_TXTURE_TYPE *pW2dVdoTxture);
#ifdef CC_INPUTSOURCE_VIDEO_ON_TEXTURE
UINT8 u1ApiW2dTxtureModeSet(BOOL enable);
UINT8 u1ApiW2dTxtureModeGet(void);
#endif
UINT32 vR2rGetVTotal(void);
UINT32 vR2rGetHTotal(void);
UINT32 vR2rGetHActive(void);
UINT32 vR2rGetVActive(void);
UINT8 u1TimingNeedCutByR2R(UINT8 u1DviTiming);
void vW2dR2rErrorHandle(void);
extern UINT32 u4GetHdmiRegBase(E_HDMI_SWITCH_NUM ePort);
extern UINT32 u4GetAnalogRegBase(E_HDMI_SWITCH_NUM ePort);
UINT8 getOmuxOutputField(void);
#endif
