/* 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$
 * $Date  $
 * $RCSfile: drv_hdmi.h,v $
 * $Revision$
 *
 *---------------------------------------------------------------------------*/
#ifndef _DRV_HDMI2_H_
#define _DRV_HDMI2_H_

#include "typedef.h"
#include "x_timer.h"

#define HDMI_RX_NEW_DOLBY_EDR_MD    (1<<1)
#define HDMI_RX_DOLBY_EDR_CRC_ERROR (1<<2)

#define HDMI_RX_HDCP2X_INT_AUTH_DONE      (1)
#define HDMI_RX_HDCP2X_INT_AKE_SENT_RCVD  (1<<18)

#define HDMI_RST_ALL    1
#define HDMI_RST_EQ        2
#define HDMI_RST_DEEPCOLOR    3
#define HDMI_RST_FIXEQ        4
#define HDMI_RST_RTCK        5
#define HDMI_RST_DIGITALPHY 6

#define HDMI_AUD_Length_Unknown      0
#define HDMI_AUD_Length_16bits      1
#define HDMI_AUD_Length_17bits      2
#define HDMI_AUD_Length_18bits      3
#define HDMI_AUD_Length_19bits      4
#define HDMI_AUD_Length_20bits      5
#define HDMI_AUD_Length_21bits      6
#define HDMI_AUD_Length_22bits      7
#define HDMI_AUD_Length_23bits      8
#define HDMI_AUD_Length_24bits      9

//Audio error handler related
#define AUDPACKET_INVALID 0
#define AUDPACKET_1 1
#define AUDPACKET_MAX 200
#define AUDPACKET_GOOD 201

#define HDMI_ENABLE_EQ_TRACKING_6G 1

#define HDMI_HDR_METADATA_LENGTH 24
#define HDMI_INVALID_HDR_EOTF_VALUE 0xff

#define HDMI_DOLBY_EDR_MAX_BODY_LENGTH 482 //Support total 482byte metadata body = (119 + 121*3)
#define HDMI_DOLBY_EMP_EDR_MAX_BODY_LENGTH 512 //Dolby EMP Max playload
#define HDMI_DOLBY_EDR_MAX_METADATA_BUFFER 1000 //define max metadat buffer for debug purpose

#define HDMI_HDR10P_MAX_METADATA_BUFFER 10 //define max metadat buffer for debug purpose
#define HDMI_DYNAMIC_METADATA_PACKET_LEN 28
#define HDMI_VSI_METADATA_LENGTH 28

#define HDMI_DYNAMIC_METADATA_LENGTH 1120 //for 10+ and Dolby EMP array length

#define HDMI_SUPPORT_DOLBY_VISION_NEW
#define HDMI_INTERRUPT_FLAG_NONE                        0x0
#define HDMI_INTERRUPT_FLAG_DVVSI                      (1<<0)
#define HDMI_INTERRUPT_FLAG_H14B                       (1<<1)
#define HDMI_INTERRUPT_FLAG_0x87                       (1<<2)
//#define HDMI_SUPPORT_CCIR_BYPASS

typedef void (* PFN_NOTIFY_CABLE_5V)(UINT8);

enum
{
    HDMI_3D_Structure_FramePacking=0,
    HDMI_3D_Structure_FieldAlternative,
    HDMI_3D_Structure_LineAlternative,
    HDMI_3D_Structure_SideBySideFull,
    HDMI_3D_Structure_LDepth,
    HDMI_3D_Structure_LDepthGraph,
    HDMI_3D_Structure_TopBottom,
    HDMI_3D_Structure_SideBySideHalf=8,
    HDMI_3D_Structure_Unknow
};

enum
{
    HDMI_NOSIGNAL_STATE=0,
    HDMI_WAIT_CONNECT_STATE,
    HDMI_WAIT_STABLE_STATE,
    HDMI_STABLE_STATE
};
typedef enum
{
    HDMI_RX_MODE_DVI,
    HDMI_RX_MODE_HDMI1X,
    HDMI_RX_MODE_HDMI2X,
    HDMI_RX_MODE_MHL
}HdmiRxMode_t;

typedef enum eHDMI_SWITCH_NO {
    HDMI_SWITCH_INIT = 0,
    HDMI_SWITCH_1,
    HDMI_SWITCH_2,
    HDMI_SWITCH_3,
    HDMI_SWITCH_4,
    HDMI_SWITCH_MAX
}E_HDMI_SWITCH_NUM;

#define HDMI_MAX_PHYCIAL_PORT_NUM HDMI_SWITCH_4 //define it for each SOC

typedef enum
{
    HDMI_RX_INPUT_TYPE_NONE,
    HDMI_RX_INPUT_TYPE_HDMI,
    HDMI_RX_INPUT_TYPE_MHL,
}HdmiRxInputType_t;


typedef enum
{
    HDMI_RX_CLRSPC_UNKNOW,
    HDMI_RX_CLRSPC_YC444_601,
    HDMI_RX_CLRSPC_YC422_601,
    HDMI_RX_CLRSPC_YC420_601,

    HDMI_RX_CLRSPC_YC444_709,
    HDMI_RX_CLRSPC_YC422_709,
    HDMI_RX_CLRSPC_YC420_709,

    HDMI_RX_CLRSPC_XVYC444_601,
    HDMI_RX_CLRSPC_XVYC422_601,
    HDMI_RX_CLRSPC_XVYC420_601,

    HDMI_RX_CLRSPC_XVYC444_709,
    HDMI_RX_CLRSPC_XVYC422_709,
    HDMI_RX_CLRSPC_XVYC420_709,

    HDMI_RX_CLRSPC_sYCC444_601,
    HDMI_RX_CLRSPC_sYCC422_601,
    HDMI_RX_CLRSPC_sYCC420_601,

    HDMI_RX_CLRSPC_Adobe_YCC444_601,
    HDMI_RX_CLRSPC_Adobe_YCC422_601,
    HDMI_RX_CLRSPC_Adobe_YCC420_601,

    HDMI_RX_CLRSPC_RGB,
    HDMI_RX_CLRSPC_Adobe_RGB,

    HDMI_RX_CLRSPC_BT_2020_RGB_non_const_luminous,
    HDMI_RX_CLRSPC_BT_2020_RGB_const_luminous,

    HDMI_RX_CLRSPC_BT_2020_YCC444_non_const_luminous,
    HDMI_RX_CLRSPC_BT_2020_YCC422_non_const_luminous,
    HDMI_RX_CLRSPC_BT_2020_YCC420_non_const_luminous,

    HDMI_RX_CLRSPC_BT_2020_YCC444_const_luminous,
    HDMI_RX_CLRSPC_BT_2020_YCC422_const_luminous,
    HDMI_RX_CLRSPC_BT_2020_YCC420_const_luminous

}HdmiRxClrSpc_t;

typedef enum
{
    HDMI_RX_BIT_DEPTH_8_BIT,
    HDMI_RX_BIT_DEPTH_10_BIT,
    HDMI_RX_BIT_DEPTH_12_BIT,
    HDMI_RX_BIT_DEPTH_16_BIT
}HdmiRxBitDepth_t;

typedef enum
{
    HDMI_RX_CLRFMT_RGB,
    HDMI_RX_CLRFMT_YCC422,
    HDMI_RX_CLRFMT_YCC444,
    HDMI_RX_CLRFMT_YCC420,
}HdmiRxClrFmt_t;

typedef enum
{
    HDMI_RX_RGB_FULL,
    HDMI_RX_RGB_LIMT,
    HDMI_RX_YCC_FULL,
    HDMI_RX_YCC_LIMT
}HdmiRxRange_t;
typedef enum
{
    HDMI_RX_OVERSCAN=1,
    HDMI_RX_UNDERSCAN
}HdmiRxScanInfo_t;

typedef enum
{
    HDMI_RX_ASPECT_RATIO_4_3=1,
    HDMI_RX_ASPECT_RATIO_16_9
}HdmiRxAspectRatio_t;

typedef enum
{
    HDMI_RX_AFD_SAME=8,
    HDMI_RX_AFD_4_3,
    HDMI_RX_AFD_16_9,
    HDMI_RX_AFD_14_9
}HdmiRxAFDInfo_t;

typedef enum
{
    HDMI_RX_ITC_GRAPHICS=0,
    HDMI_RX_ITC_PHOTO,
    HDMI_RX_ITC_CINEMA,
    HDMI_RX_ITC_GAME
}HdmiRxITCInfo_t;

typedef enum
{
    HDMI_RX_HDCP_LINK_VER_NONE,
    HDMI_RX_HDCP_LINK_VER_HDCP1X,
    HDMI_RX_HDCP_LINK_VER_HDCP22,
}HdmiRxHdcpLinkVer_t;

typedef enum
{
    HDMI_RX_HDCP2X_AUTH_OFF=0,
    HDMI_RX_HDCP2X_AUTH_AKE_SENT_RCVD,
    HDMI_RX_HDCP2X_AUTH_AUTH_DONE
}HDMI_RX_HDCP2X_AUTH_STATUS_T;

typedef enum
{
    HDMI_RX_HDCP1_STATUS_OFF =0x0,
    HDMI_RX_HDCP1_STATUS_AUTH_DONE =0x1,
    HDMI_RX_HDCP1_STATUS_AUTH_FAIL =0x2,
    HDMI_RX_HDCP1_STATUS_DECRYPT_SUCCESS=0x4,
    HDMI_RX_HDCP1_STATUS_DECRYPT_FAIL=0x8
}HdmiRxHdcp1Status_t;

typedef enum
{
    HDMI_RX_AUDIO_FS_24KHZ,
    HDMI_RX_AUDIO_FS_32KHZ,
    HDMI_RX_AUDIO_FS_44_1KHZ,
    HDMI_RX_AUDIO_FS_48KHZ,
    HDMI_RX_AUDIO_FS_88_2KHZ,
    HDMI_RX_AUDIO_FS_96KHZ,
    HDMI_RX_AUDIO_FS_176_4KHZ,
    HDMI_RX_AUDIO_FS_192KHZ,
    HDMI_RX_AUDIO_FS_768KHZ
}HdmiRxAudioFs_t;

typedef enum
{
    HDMI_TMDS_CLOCK_UNKNOW,
    HDMI_TMDS_CLOCK_27,             //           freq <=  27.000
    HDMI_TMDS_CLOCK_27_33P75,       //  27.000 < freq <=  33.750
    HDMI_TMDS_CLOCK_33P75_40P5,     //  33.750 < freq <=  40.500
    HDMI_TMDS_CLOCK_40P5_54,        //  40.500 < freq <=  54.000
    HDMI_TMDS_CLOCK_54_75,    	    //  54.000 < freq <=  75.000
    HDMI_TMDS_CLOCK_75_93P75,       //  75.000 < freq <=  97.750
    HDMI_TMDS_CLOCK_93P75_112P5,    //  93.750 < freq <= 112.500
    HDMI_TMDS_CLOCK_112P5_148P5,    // 112.500 < freq <= 148.500
    HDMI_TMDS_CLOCK_148P5_150,      // 148.500 < freq <= 150.000
    HDMI_TMDS_CLOCK_150_185P625,    // 150.000 < freq <= 185.625
    HDMI_TMDS_CLOCK_185P625_227P75, // 185.625 < freq <= 227.750
    HDMI_TMDS_CLOCK_227P75_290,     // 227.750 < freq <= 290.000
    HDMI_TMDS_CLOCK_297_594,        // 290.000 < freq <= 594.000
    HDMI20_TMDS_CLOCK_290_340,      // 290.000 < freq <= 340.000 // 20190816
	HDMI20_TMDS_CLOCK_340_425P5,	// 340.000 < freq <= 425.500 // 20190816
	HDMI20_TMDS_CLOCK_425P5_510,	// 425.500 < freq <= 510.000 // 20190816
	HDMI20_TMDS_CLOCK_510_594,		// 510.000 < freq <= 594.000 // 20190816
    HDMI_FRL_DATA_RATE_3G,	        // 3GB/s
    HDMI_FRL_DATA_RATE_6G,			// 6GB/s
    HDMI_FRL_DATA_RATE_8G,			// 8GB/s
    HDMI_FRL_DATA_RATE_10G,			// 10GB/s
    HDMI_FRL_DATA_RATE_12G,    		// 12GB/s
}HdmiTmdsClkRate_t;

typedef enum
{
    MHL_TMDS_CLOCK_UNKNOW,
//    MHL_TMDS_CLOCK_25_37,
    MHL_TMDS_CLOCK_25_35,
    MHL_TMDS_CLOCK_35_37,
//    MHL_TMDS_CLOCK_37_50,
    MHL_TMDS_CLOCK_37_40,
    MHL_TMDS_CLOCK_40_50,
    MHL_TMDS_CLOCK_50_60,
    MHL_TMDS_CLOCK_60_67,
    MHL_TMDS_CLOCK_67_75
}MhlTmdsClkRate_t;


typedef enum
{
    HDMI_AUDIO_FIFO_NORMAL= 0x1,
    HDMI_AUDIO_FIFO_UNDERRUN= 0x2,
    HDMI_AUDIO_FIFO_OVERRUN= 0x4
}HdmiAudFifoStatus_t;

typedef enum
{
    HDMI_TMDS_DATA_CHANNEL_0,
    HDMI_TMDS_DATA_CHANNEL_1,
    HDMI_TMDS_DATA_CHANNEL_2,
    HDMI_TMDS_DATA_CHANNEL_3_CLK
}HdmiTmdsDataChannel_t;

typedef enum
{
    HDMI_INFO_FRAME_UNKNOWN,
    HDMI_INFO_FRAME_ID_AVI,
    HDMI_INFO_FRAME_ID_SPD,
    HDMI_INFO_FRAME_ID_AUD,
    HDMI_INFO_FRAME_ID_MPEG,
    HDMI_INFO_FRAME_ID_UNREC,
    HDMI_INFO_FRAME_ID_ACP,
    HDMI_INFO_FRAME_ID_VSI,
    HDMI_INFO_FRAME_ID_ISRC0,
    HDMI_INFO_FRAME_ID_ISRC1,
    HDMI_INFO_FRAME_ID_GCP,
    HDMI_INFO_FRAME_ID_HFVSI,
    HDMI_INFO_FRAME_ID_HDR_0x86,
    HDMI_INFO_FRAME_ID_HDR_0x87,
    HDMI_INFO_FRAME_ID_EMPPKT1,
    HDMI_INFO_FRAME_ID_DVVSI,
    HDMI_INFO_FRAME_ID_VRR,
}HdmiInfoFrameID_t;


enum
{
    HDMI_SPD_NONE_CHG,
    HDMI_SPD_CLEAR,//no SPD
    HDMI_SPD_CHG_TOUP,
    HDMI_SPD_CHG_TONONUP,
    HDMI_SPD_CHG_TOSV,
    HDMI_SPD_CHG_TONONSV,
};

enum
{
    HDMI_SPD_NONE_STATUS,
    HDMI_SPD_UP_UNDET,//Without specific pattern
    HDMI_SPD_UP_DETED,//With specific pattern
    HDMI_SPD_SV_UNDET,
    HDMI_SPD_SV_DETED,
};

typedef enum {
    HDMI_HDCP1X,
    HDMI_HDCP2X
}HDMI_HDCP_KEY_CHECK_MODE_T;

typedef enum
{
    HDMI_DOLBY_HDR_NONE,
    HDMI_DOLBY_HDR_LOW_LATENCY,
    HDMI_DOLBY_HDR_DETECT_STANDARD
}E_HDMI_DOLBY_HDR_STATE;

typedef enum
{
    HDMI_FRL_MODE_LEGACY = 0,
    HDMI_FRL_MODE_FRL_3G_3CH,
    HDMI_FRL_MODE_FRL_6G_3CH,
    HDMI_FRL_MODE_FRL_6G_4CH,
    HDMI_FRL_MODE_FRL_8G,
    HDMI_FRL_MODE_FRL_10G,
    HDMI_FRL_MODE_FRL_12G,
    HDMI_FRL_MODE_NONE
}E_HDMI_FRL_MODE_TYPE;

typedef enum
{
    HDMI_VRR_TYPE_NONE = 0,
    HDMI_VRR_TYPE_EMP,
    HDMI_VRR_TYPE_FreeSync,
    HDMI_VRR_TYPE_GSync,
    HDMI_VRR_TYPE_Max
}E_HDMI_VRR_TYPE;

typedef struct
{
    UINT16  _u2VTotal;
    UINT16  _u2VSYNCWidth;
    UINT16  _u2VFrontPorch;
    UINT16  _u2VBackPorch;
    UINT16  _u2VTotalMin;
    UINT16  _u2VFrontPorchMin;
    UINT16  _u2VDEWidth;
    UINT16  _u2HTotal;
    UINT16  _u2HSYNCWidth;
    UINT16  _u2HFrontPorch;
    UINT16  _u2HBackPorch;
    UINT16  _u2HDEWidth;
} HdmiRxTimingInfo_t;

typedef struct
{
    BOOL bConvertRGB;
    BOOL bSimple422;
    BOOL bNative420;
    BOOL bNative422;
    UINT8 _u1BitPerComponent;
    UINT8 _u1BitPerPixel;
    UINT8 _u1BitPerPixelFrac;
    UINT16  _u2HFrontPorch_DSC;
    UINT16  _u2HSYNCWidth_DSC;
    UINT16  _u2HBackPorch_DSC;
    UINT16  _u2HDEWidth_DSC;
    UINT16  _u2HTotal_DSC;
    UINT16  _u2PicHigh;
    UINT16  _u2PicWidth;
    UINT16  _u2SliceHigh;
    UINT16  _u2SliceWidth;
    UINT16  _u2ChunkSize;
    UINT16  _u2SliceNum;
    UINT16  _u2Eng0ReuseTimePerLine;
    UINT16  _u2PerSliceProcCyc;
    UINT16  _u2InitDecDelay;
    UINT32  _u4DSCSFTSlice;
    UINT32  _u4DSCSFTBlank;
    UINT32  _u4HTTCycCkDSC;
} HdmiRxDSCTimingInfo_t;

typedef struct
{
    HdmiRxClrSpc_t clrSpc;
    HdmiRxRange_t range;
}HdmiVideoInfo_t;

typedef struct
{
    BOOL fgItc;
    HdmiRxITCInfo_t ItcContent;
}HdmiItcInfo_t;

typedef struct
{
    UINT8 HDMI_3D_Enable;
    UINT8 HDMI_3D_Video_Format;
    UINT8 HDMI_3D_Structure;
    UINT8 HDMI_3D_EXTDATA;
}HdmiVideo3DInfo_t;

typedef struct
{
    UINT8 layout;
    UINT8 dsd;
    UINT8 hbrA;
    HdmiRxAudioFs_t audioFs;
}HdmiRxAudioFormat_t;

typedef struct
{
    UINT8 u1CategoryCode;
    UINT8 u1WordLength;
    UINT8 u1b1;
    UINT8 u1b2;
    UINT8 u1b3;
    BOOL fgCopyRight;
    BOOL fgIsPCM;
}HdmiRxAudioChannelStatus_t;

typedef struct
{
    BOOL fgIsAudMute;
    HdmiRxAudioFormat_t audFormat;
    HdmiRxAudioChannelStatus_t chlStatus;
}HdmiRxAudioInfomation_t;

typedef struct
{
    HdmiInfoFrameID_t u1InfoID;
    UINT8 u1InfoData[32];
}HdmiRxInfo_t;

typedef struct
{
    UINT32 u4Header;
    UINT32 au4VdrName[2];//Vendor Name Chacter VN1 TO VN8, 8 bytes.
    UINT32 au4PrdDspt[4];//Product Description Chacter PD1 TO PD16,16 bytes.
    UINT8 u1SrcInfo;
}HdmiSpdParse_t;

typedef struct
{
    UINT8 u1ScramblingOn;
    UINT8 u1ClkRatio;
}HdmiScdcStatus_t;

typedef struct
{
    UINT8 au1HdrMetadata[HDMI_HDR_METADATA_LENGTH];
}HDMI_HDR_METADATA;

typedef struct
{
    UINT8 u1InterFlag;
    HdmiRxClrSpc_t clrSpc;
    HdmiRxRange_t range;
    HdmiRxBitDepth_t depth;
    UINT8 u1VSIInfoData[32];
    UINT8 u1DVVSIInfoData[32];
    UINT8 u187InfoData[32];
}HDMI_DOLBYVISION_INFO_T;

typedef struct
{
    UINT8 u1HandleType;
    HdmiRxClrSpc_t clrSpc;
    HdmiRxRange_t range;
    HdmiRxBitDepth_t depth;
}HDMI_DOLBYVISION_EMP_INFO_T;

typedef struct
{
    UINT8  u1VRR_EN;
    UINT8  u1Fs_Support;
    UINT8  u1Fs_Enable;
    UINT8  u1Fs_Active;
    UINT8  u1Fs_NCS_Active;
    UINT8  u1Fs_BCtl_Active;
    UINT8  u1Fs_SLD_Dis_ctl;
    UINT8  u1Fs_Native_Color;
    UINT8  u1Fs_Min_FR;
    UINT8  u1Fs_Max_FR;
    UINT8  u1Fs_sRGB_EOTF_Active;
    UINT8  u1Fs_BT709_EOTF_Active;
    UINT8  u1Fs_Gamma22_EOTF_Active;
    UINT8  u1Fs_Gamma26_EOTF_Active;
    UINT8  u1Fs_PQ_EOTF_Active;
    UINT8  u1Fs_BCtl;
}HDMI_DRR_Fs_Info;

typedef struct
{
    UINT8  u1VRR_EN;
    UINT8  u1M_CONST;
    UINT8  u1FVA_Factor;
    UINT8  u1Base_Vfront;
    UINT8  u1RB;
    UINT16 u2Base_Refesh_Rate;
}HDMI_VRR_Info;

typedef struct
{
   UINT8 u1Index;
   UINT8 u1VIC1;
   UINT8 u1VIC2;
   UINT16 u2Width;
   UINT16 u2Height;
   UINT8 u1BaseFR;
   UINT16 u2Htotal;
   UINT16 u1BaseVT;
   UINT16 u2PixClock;
}HDMI20_VIC_MAP_BASE_VRR_T;

#ifdef CC_HDMI_POH_SUPPORT
typedef enum
{
    HDMI_POH_STATE_IDLE,
    HDMI_POH_STATE_WAIT_CONNECT,
    HDMI_POH_STATE_CONNECTED
}E_HDMI_POH_STATE;

typedef struct _HDMI_POH_CONFIG_T
{
    UINT8 u1PortId; //Driver port ID
    UINT8 fgEnable; //POH enable
    INT32 i4GpioPwrEn; //POH power enable gpio
    INT32 i4GpioPohDet; //POH device detect gpio
    INT32 i4GpioOcpDet; //POH over current detect gpio
}HDMI_POH_CONFIG_T;
#endif //CC_HDMI_POH_SUPPORT

#define DEF_HDMI_MAX_DATA_LANE_NUM 4
#define DEF_HDMI_MULTI_VSIF_NUM     4

typedef struct
{
    UINT8 _phy_count;
    UINT8 _band_change;
    UINT8 _bHdmiCmd;
    UINT8 _bHDMIState;
    UINT8 _bHDMIStateOld;
    UINT8 _bH21MaxFRLRate;
    UINT8 _bH21MaxDSCFRLRate;
    UINT8 _bHDMITxFFE[DEF_HDMI_MAX_DATA_LANE_NUM];
    UINT8 _bPreHDMITxFFE[DEF_HDMI_MAX_DATA_LANE_NUM];
    BOOL _fgFRLTraingDone;
    UINT8 _bHDMIPower5vStatus;
    BOOL  _fgForce5vOn;
    UINT8 _bHdmiPlug;
    UINT8 _bUnplugFlag;
    UINT8 _bHDMIAvMute;
    UINT8 _bHDMICkdt;
    UINT8 _bHDMIScdt;
    UINT8 _bHDMIScdtLose;
    UINT8 _bHDMIHpdTimerCnt;
    UINT8 _bHDMIHdcp1xGood;
    UINT8 _bHDMIHdcp2xNoExistCnt;
    BOOL _fgIsHDMIHdcp2xExist;
    UINT8 _bHdmi2HdcpHandlerCnt;
    UINT8 _bHdmi2HdcpErrCnt;
    BOOL _fgFirstEnterAuthDone;
    UINT8 _bSCDTdelay;
    UINT8 _bHDMIResStableCnt;
    UINT8 _bHDMIResUnStableCnt;
    UINT8 _bHDMIResDetectCnt;
    UINT8 _bIs422;
    UINT8 _bIs420;
    BOOL _fgIsFRL;
    BOOL _fgIsDSCEnabled;
    UINT8 _bHDMIFastSW;
    UINT8 _bResv1;
    UINT8 _bNoSpdCount;
    UINT8 _bNo4KPsCount;
    UINT8 _bHDMIEqTracking;
    UINT8 _bHDMIEqCh0;
    UINT8 _bHDMIEqCh1;
    UINT8 _bHDMIEqCh2;
    UINT8 _bHDMIFrameRate;
    UINT16 _u2FreqFrac;
    UINT16 _u2SDMPostDIV;
    UINT16 _u2DigitalDIV;
    UINT16 _u2PixelClk1PMhz;
    UINT16 _u2HD21Pixl;
    UINT16 _u2VPInter;
    UINT16 _u28KInter;
    UINT16 _bHDMIEqTrackingWaitCnt;
    UINT16 _bHDMIEqTrackingStableCnt;
    UINT32 _u4SDMPLLSet;
    UINT32 _dwHDMIClkKhz;
    BOOL _fgHDMI40xMode;
    UINT8 _bPLLBandSel;
    UINT8 _bCDRMode;
    UINT8 _bSpdStatus;
    UINT8 _bSpdUpStaChg;
    UINT8 _b4KPsStatus;
    UINT8 _bNoAcpCount;
    UINT8 _bHdrEOTF;
    UINT8 _bHDR0x87ValidPackets;

    UINT8 _bHdmiDvVsif_L11;
    UINT8 _bHdmiDvVsif_Content;
    UINT8 _bHdmiDvEmp_L11;
    UINT8 _bHdmiDvEmp_Content;
    BOOL _fgHdmiVsifDVGMState;
    BOOL _fgHdmiEmpDVGMState;
    BOOL _fgHdmiNewDVGMState;
    BOOL _fgHdmiDVGMState;

    BOOL _fgFirstAnaSetting;
    HAL_TIME_T _rHdrReceiveTime;
    HAL_TIME_T _rHDMIEqTrackingStart;
    UINT8 _bHDMIAllmConfig;
    HAL_TIME_T _rVrrReceiveTime;
    HAL_TIME_T _rVsiReceiveTime;
    HAL_TIME_T _rDolbyVsiReceiveTime;
    HAL_TIME_T _rDolbyEMPReceiveTime;
    HAL_TIME_T _rHdr10PVsiReceiveTime;
    HAL_TIME_T _rHdr10PEMPReceiveTime;
    HAL_TIME_T _rHFVsiReceiveTime;
#ifdef CC_HDMI_POH_SUPPORT
    E_HDMI_POH_STATE _ePohState;
#endif
    HdmiRxTimingInfo_t _HdmiTimingInfo;
    HdmiRxTimingInfo_t _PreHdmiTimingInfo;
    HdmiRxDSCTimingInfo_t _HdmiDSCTimingInfo;
    HdmiRxMode_t _HdmiMode;
    HdmiRxInputType_t _ConnectType;
    HdmiRxClrFmt_t _HdmiClrFmt;
    HdmiRxClrSpc_t _HdmiClrSpc;
    HdmiRxBitDepth_t _HdmiDepth;
    HdmiRxRange_t _HdmiRange;
    HdmiRxScanInfo_t _HdmiScan;
    HdmiRxAspectRatio_t _HdmiAspect;
    HdmiRxAFDInfo_t    _HdmiAFD;
    HdmiItcInfo_t     _HdmiITC;
    HdmiVideo3DInfo_t _Hdmi3DInfo;
    HdmiRxHdcpLinkVer_t _HdcpLinkVer;
    HdmiRxHdcp1Status_t _Hdcp1xState;
    HDMI_RX_HDCP2X_AUTH_STATUS_T _eHdcp2xAuthStatus;

    HdmiScdcStatus_t _ScdcInfo;
    HdmiRxInfo_t _AviInfo;
    HdmiRxInfo_t _SpdInfo;
    HdmiRxInfo_t _AudInfo;
    HdmiRxInfo_t _MpegInfo;
    HdmiRxInfo_t _UnrecInfo;
    HdmiRxInfo_t _Hdr87Info;
    HdmiRxInfo_t _Hdr86Info;
    HdmiRxInfo_t _AcpInfo;
    HdmiRxInfo_t _VsiInfo[DEF_HDMI_MULTI_VSIF_NUM];
    HdmiRxInfo_t _Isrc0Info;
    HdmiRxInfo_t _Isrc1Info;
    HdmiRxInfo_t _GcpInfo;
    HdmiRxInfo_t _HfVsiInfo[DEF_HDMI_MULTI_VSIF_NUM];
    HdmiRxInfo_t _EmpPkt1;
    HDMI_VRR_Info _VrrInfo;
    HDMI_DRR_Fs_Info _DrrFsInfo;
    HdmiRxAudioInfomation_t _AudStatus;
    HDMI_HDR_METADATA _rHdrMetadata;
    E_HDMI_DOLBY_HDR_STATE _rDolbyHdrState;
    HDMI_DOLBYVISION_INFO_T Hdmi_Dv_Info;
    E_HDMI_FRL_MODE_TYPE _rHdmiFRLMode;
    UINT8  _u1VPTimingIdx;
    UINT8  _u1VIC;
    UINT8  _u1NewCCIRMode;
    UINT32 _u4VActive;
    BOOL _fgIsHDCP1x;
    BOOL _fgIsHDCP2x;
    UINT8 _bHdmi2BchErrCnt;
    UINT8 _bHdmi2CheckBchCnt;
    UINT8  _u1VPOutMode;
    UINT8 _bHDMISCDCTimerCnt;
} HdmiRxObject_t;

typedef struct HDMI_PORT_INFO_T
{
    UINT8 u1UIPortId;           ///< HDMI UI Port ID, Port ID should start from 1 which corresponds to HDMI "port 1".
    UINT8 u1DriverPortId;       ///< HDMI  Driver Port ID
    BOOL bEnable;               ///<HDMI Driver Port Enable
    BOOL bCECSupport;           ///<CEC Support
    BOOL bARCSupport;           ///<ARC Support
} HDMI_PORT_INFO_T;

typedef struct HDMI_PORTS_INFO_T
{
    UINT8 u1PortNum;           ///< the number of HDMI ports in the system
    HDMI_PORT_INFO_T rHdmiPortInfo[HDMI_SWITCH_MAX-1];
} HDMI_PORTS_INFO_T;

typedef struct _HDMI_AUD_HANDLER_CTX_T
{
    BOOL fgHdmiAudInit;
    E_HDMI_SWITCH_NUM eActivePort;
    UINT8 u1ACR_DPLL_LOCK;
    UINT8 u1AudFifoFault;
    UINT8 u1AudPacket;
    UINT8 bHDMIAudFIFOflag;
    UINT8 bHDMIAudFreq;
    BOOL fgMuteAudModule;
    BOOL fgAudToggleFs;
    UINT8 u1AudToggleFsCounter;
    BOOL fgDsdOn;
    BOOL fgHbrOn;
}HDMI_AUD_HANDLER_CTX_T;

typedef struct _HDMI_DOLBY_EDR_METADATA_T
{
    UINT8 u1DmMetadataId;
    UINT8 au1MdBodyPKT[HDMI_DOLBY_EMP_EDR_MAX_BODY_LENGTH];
    UINT16 u2Length;
}HDMI_DOLBY_EDR_METADATA_T;

#ifdef CC_SUPPORT_DOLBY_VISION
typedef struct _HDMI_DOLBY_EDR_CTX_T
{
    HDMI_DOLBY_EDR_METADATA_T rHdmiDolbyEdrMetadata;
    HDMI_DOLBY_EDR_METADATA_T *prDolbyEdrMetadataBuffer;
    UINT16 u2CurrDolbyEdrMetadataIndex;
    UINT32 u4NoMetadataCount;
    BOOL fgDolbyHdrExist;
    BOOL fgDolbyHdr20EMPExist;
    UINT8 fgDolbyHdr20EMPHandle; // 0: CRC Fail 1:CRC Pass 2: do not have CRC(NO EMP case)
    BOOL fgFreezeVideo;
    UINT8 u1NoFreezeCounter;
    UINT8 u1UnfreezeCount;
}HDMI_DOLBY_EDR_CTX_T;
#endif //CC_SUPPORT_DOLBY_VISION

#ifdef CC_SUPPORT_HDR10Plus

typedef struct _HDMI_HDR10PLUS_EMP_MATADATA_PACKETS_T
{
    UINT8 au1DyMdPKT[HDMI_DYNAMIC_METADATA_LENGTH];
}HDMI_HDR10PLUS_EMP_MATADATA_PACKETS_T;

typedef struct _HDMI_HDR10PLUS_EMP_METADATA_T
{
    UINT8   uCountryCode;
    UINT16  u2ProviderCode;
    UINT16  u2OrientedCode;
    UINT8   uIdentifier;
    UINT8   uVersion;
    UINT8   uNumWindows;
    UINT16  u2WindowUpperLeftCornerX[3];
    UINT16  u2WindowUpperLeftCornerY[3];
    UINT16  u2WindowLowerRightCornerX[3];
    UINT16  u2WindowLowerRightCornerY[3];
    UINT16  u2CenterOfEllipseX[3];
    UINT16  u2CenterOfEllipseY[3];
    UINT8   uRotationAngle[3];
    UINT16  u2SemiMajorAxisInternalEllipse[3];
    UINT16  u2SemiMajorAxisExternalEllipse[3];
    UINT16  u2SemiMinorAxisExternalEllipse[3];
    UINT8   uOverlapProcessOption[3];

    UINT32  u4TargetSystemDisplayMaximumLuminance;
    BOOL    bTargetSystemDisplayActualPeakLuminanceFlag;
#if 1
    UINT8   uNumRowsTargetedSystemDisplayActualPeakLuminance;
    UINT8   uNumColsTargetedSystemDisplayActualPeakLuminance;
    UINT8   uTargetedSystemDisplayActualPeakLuminance[25][25];
#endif
    UINT32  u4Maxscl[3][3];
    UINT32  u4AverageMaxrgb[3];
    UINT8   uNumDistributionMaxrgbPercentiles[3];
    UINT8   uDistributionMaxrgbPercentages[3][15];
    UINT32  u4DistributionMaxrgbPercentiles[3][15];
    UINT16  u2FractionBrightPixels[3];

    BOOL    bMasteringDisplayActualPeakLuminanceFlag;
#if 1
    UINT8   uNumRowsMasteringDisplayActualPeakLuminance;
    UINT8   uNumColsMasteringDisplayActualPeakLuminance;
    UINT8   uMasteringDisplayActualPeakLuminance[25][25];
#endif
    BOOL    bToneMappingFlag[3];
    UINT16  u2KneePointX[3];
    UINT16  u2KneePointY[3];
    UINT8   uNumBezierCurveAnchors[3];
    UINT16  u2BezierCurveAnchors[3][15];
    BOOL    bColorSaturationMappingFlag[3];
    UINT8   uColorSaturationWeight[3];
}HDMI_HDR10PLUS_EMP_METADATA_T;

typedef struct _HDMI_HDR10Plus_EMP_T
{
    BOOL fgHdr10PlusEMPExist;
    UINT16 u2CurrEMPMetadataIndex;
    UINT16 u2Length;
    HDMI_HDR10PLUS_EMP_METADATA_T rHdmiHdr10PlusEmpMetadata;
}HDMI_HDR10Plus_EMP_T;

typedef struct _HDMI_HDR10Plus_VSI_METADATA_T
{
    UINT8 u1ApplicationVersion;
    UINT8 u1TargetSystemDisplayMaximumLuminance;
    UINT8 u1AverageMaxrgb;
    UINT8 au1DistributionValue[9];
    UINT8 u1NumBezierCurveAnchrs;
    UINT16 u2KneePointX;
    UINT16 u2KneePointY;
    UINT8 u1BezierCurveAnchors[9];
    UINT8 u1GraphicsOverlayFlag;
    UINT8 u1NoDelayFlag;
}HDMI_HDR10Plus_VSI_METADATA_T;

typedef struct _HDMI_HDR10Plus_VSI_T
{
    BOOL fgHdr10PlusVsiExist;
    UINT16 u2CurrVSIMetadataIndex;
    UINT16 u2Length;
    HDMI_HDR10Plus_VSI_METADATA_T rHdmiHdr10PlusVsiMetadata;
}HDMI_HDR10Plus_VSI_T;

#endif

typedef struct _HDMI_HDR_EMP_MD_T
{
    UINT8 u1EMPHead;                                //hdmi spec,CTA-861-G-Final-HDMI forum.pdf, The HDR Dynamic Metadata Extended inforFrame HEAD
    UINT8 u1ByteIndex;                              //value is 0~HDMI_DYNAMIC_METADATA_LENGTH-1,
    UINT8 u1BitIndex;                               //value is 1~8
    UINT16 u2Length;                                //value is 0~HDMI_DYNAMIC_METADATA_LENGTH-1,
    UINT8 au1DyMdPKT[HDMI_DYNAMIC_METADATA_LENGTH];
}HDMI_HDR_EMP_MD_T;

typedef void (*DRIVER_HDMI_ACP_CHG_CB)(UINT8 u1HdmiAcp,void* pvTag);
typedef struct _HDMI_ACP_HANDLER_CTX_T
{
    DRIVER_HDMI_ACP_CHG_CB pfAcpChgCb;
    void* pvAcpChgTag;
    UINT8 u1LastAcpType;
}HDMI_ACP_HANDLER_CTX_T;

extern E_HDMI_SWITCH_NUM eHDMICurrSwitch;
extern void vHDMI2ParseAviInfo(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Check HDMI port support 6G or not
 * @param        ePort---- HDMI port number
 * @retval       TRUE for support 6G, FALSE for not support
*/
extern BOOL bHDMI2IsSupport6G(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Check HDMI port is valid or not
 * @param        ePort---- HDMI port number
 * @retval       TRUE for valid port, FALSE for invalid
*/
extern BOOL fgHDMI2IsValidPort(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Get MHL port id
 * @retval       MHL port id
*/
extern UINT8 u1HDMI2GetMhlPortId(void);
/**
 * @brief        Get HDMI2.0 digital base address
 * @param        ePort---- HDMI port number
 * @retval       Base address
*/
extern UINT16 u2HDMI2GetDigBaseAddr(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Get HDMI analog base address
 * @param        ePort---- HDMI port number
 * @retval       Base address
*/
extern UINT16 u2HDMI2GetAnaBaseAddr(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Get 5V status
 * @param        ePort---- HDMI port number
 * @retval       1 for 5V exist, 0 for not exist
*/
extern UINT8 u1HDMI2_Get5VStatus(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Force 5V on for test which cannot have 5V input
 * @param        ePort---- HDMI port number
 * @param        fgEnable---- TRUE for force 5V on, FALSE for auto detect 5V
*/
extern void vHDMI2Force5vOn(E_HDMI_SWITCH_NUM ePort,BOOL fgEnable);
/**
 * @brief        Check 5v force on or not
 * @param        ePort---- HDMI port number
 * @retval       True for 5V force on, FALSE for not 5V force on
*/
extern BOOL fgHDMI2Force5vOn(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Select port to be active
 * @param        ePort---- Active HDMI port number
 * @param        u1Type---- Video path number
*/
extern void vHDMI2PortSel(E_HDMI_SWITCH_NUM ePort,UINT8 u1Type);
/**
* @brief       Reset all hdmi port
 * @param        void
*/
extern UINT8 vHDMI2AllPortReset(void);
/**
 * @brief        Select pll to active port
 * @param        ePort---- Active HDMI port number
 * @param        u1Type---- Video path number
*/
extern void vHDMI2PllSel(E_HDMI_SWITCH_NUM ePort,UINT8 u1Type);
/**
 * @brief        Set HDMI state machine
 * @param        ePort---- HDMI port number
 * @param        u1HdmiSta---- HDMI state
*/
extern void vHDMI2SetStateMachine(E_HDMI_SWITCH_NUM ePort,UINT8 u1HdmiSta);
/**
 * @brief        Set HDMI state machine for all HDMI ports
 * @param        u1HdmiSta---- HDMI state
*/
extern void vHDMI2SetStateMachineAll(UINT8 u1HdmiSta);
/**
 * @brief        Set HDMI state machine
 * @param        ePort---- HDMI port number
*/
extern void vHDMI2SetNoSignalState(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Get HDMI state machine
 * @param        ePort---- HDMI port number
 * @retval       HDMI state
*/
extern UINT8 bHDMI2GetStateMachine(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Stop HDMI loop
 * @param        ePort---- HDMI port number
*/
extern void vHDMI2StopFw(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Resume HDMI loop
 * @param        ePort---- HDMI port number
*/
extern void vHDMI2ResumeFw(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Check HDMI is unplug or not
 * @param        ePort---- HDMI port number
 * @retval       1 for HDMI is unplug, 0 for not
*/
extern UINT8 u1HDMI2IsUnplug(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Clear HDMI unplug flag
 * @param        ePort---- HDMI port number
*/
extern void vHDMI2ClrUnplug(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Set HDMI unplug flag
 * @param        ePort---- HDMI port number
*/
extern void vHDMI2SetUnplug(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Check if now is HPD low period
 * @param        ePort---- HDMI port number
 * @retval       1 for now is HPD low period, 0 for not
*/
extern UINT8 u1HDMI2IsHpdPulse(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Set HPD high period flag
 * @param        ePort---- HDMI port number
 * @param        u1Val---- 1 for HPD high, 0 for HPD low
*/
extern UINT8 vHDMI2GetHpdPulse(E_HDMI_SWITCH_NUM ePort);
/**
* @brief        Get HPD high period flag
* @param        ePort---- HDMI port number
* @retval       1 for HPD high, 0 for HPD low
*/
extern void vHDMI2SetHpdPulse(E_HDMI_SWITCH_NUM ePort,UINT8 u1Val);
/**
 * @brief        Check if SCDT lose or not
 * @param        ePort---- HDMI port number
 * @retval       1 for SCDT lose, 0 for SCDT exist
*/
extern UINT8 u1HDMI2IsSyncLose(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Set SCDT lose flag
 * @param        ePort---- HDMI port number
 * @param        u1Val---- 1 for SCDT lose, 0 for SCDT exist
*/
extern void vHDMI2SetSyncLose(E_HDMI_SWITCH_NUM ePort,UINT8 u1Val);
/**
 * @brief        Get real time signal exist(CKDT and SCDT both exist) or not
 * @param        ePort---- HDMI port number
 * @retval       TRUE for signal exist, FALSE for not
*/
extern BOOL fgHDMI2SignalPresent(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Get 420 mode
 * @param        ePort---- HDMI port number
 * @retval       TRUE for 420 mode, FALSE for not
*/
extern BOOL fgHDMI20Get420Mode(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Check pixel repeat or not
 * @param        ePort---- HDMI port number
 * @retval       TRUE for pixel repeat, FALSE for not
*/
extern BOOL fgHDMI2IsPixelRepeate(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Check RGB or YCbCr
 * @param        ePort---- HDMI port number
 * @retval       1 for RGB, 0 for YCbCr
*/
extern UINT8 bHDMI20RgbInput(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Check ITU601 or ITU709
 * @param        ePort---- HDMI port number
 * @retval       1 for ITU601, 0 for ITU709
*/
extern UINT8 bHDMI2Clocrimetry(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Get HDMI range mode
 * @retval       00: Default, depend on video format.
                           PC timing: full range.
                           Video timing: limited range.
                     01: limited range.
                     10: full range.
                     11: Reserved.
*/
extern UINT8 bGetHDMIRangeMode(void);
/**
 * @brief        Set HDMI range mode
 * @param        bMode---- 00: Default, depend on video format.
                                           PC timing: full range.
                                           Video timing: limited range.
                                      01: limited range.
                                      10: full range.
                                      11: Reserved.
*/
extern void vSetHDMIRangeMode(UINT8 bMode);
/**
 * @brief        Get HDMI RGB range
 * @param        ePort---- HDMI port number
 * @retval       HDMI RGB range
*/
extern UINT8 bHDMI20RgbRange(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Get HDMI dule mode
 * @param        ePort---- HDMI port number
 * @retval       TRUE for HDMI dule mode, FALSE for not
*/
extern BOOL fgHDMI2GetDuleMode(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Set HDMI analog circuit control
 * @param        ePort---- HDMI port number
 * @param        bOnOff---- TRUE for HDMI analog circuit on, FALSE for off
*/
extern void vHDMI2EQCIRCUITCTRL(E_HDMI_SWITCH_NUM ePort,BOOL bOnOff);
/**
 * @brief        Turn HDMI termination on or off. The HDMI analog circuit will also be turned off when turn off termination here.
 * @param        ePort---- HDMI port number
 * @param        bOnOff---- TRUE for turn on termination, FALSE for turn off
*/
extern void vHDMI2TMDSCTRL(E_HDMI_SWITCH_NUM ePort,BOOL bOnOff);
/**
 * @brief        Set HDCP ddc bus control
 * @param        ePort---- HDMI port number
 * @param        bOnOff---- TRUE for turn on, FALSE for turn off
*/
extern void vHDMI2DDCBusCTRL(E_HDMI_SWITCH_NUM ePort,BOOL bOnOff);
/**
 * @brief        Get HDMI deep color status
 * @param        ePort---- HDMI port number
 * @retval       Color depth, see Enum HdmiRxBitDepth_t
*/
extern HdmiRxBitDepth_t bHDMI20DeepColorStatus(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Set HDMI video mute.
 * @param        ePort---- HDMI port number
 * @param        u1En---- TRUE for mute, FALSE for unmute
*/
extern void vHDMI2VideoMute(E_HDMI_SWITCH_NUM ePort,UINT8 u1En);
/**
 * @brief        Get audio channel number
 * @param        ePort---- HDMI port number
 * @retval       Audio channel number
*/
extern UINT8 bHDMI20GetAudChannelNum(E_HDMI_SWITCH_NUM ePort);
extern UINT8 u1HDMI2GetPLLBand(E_HDMI_SWITCH_NUM ePort);
extern BOOL fgHDMI2Get40xMode(E_HDMI_SWITCH_NUM ePort);
extern UINT8 bGetHDMIRangeMode(void);
extern UINT8 u1HDMI2GetCDRMode(E_HDMI_SWITCH_NUM ePort);

/**
 * @brief        Not implemented
 * @param        fgEnable----
 * @retval
*/
extern void vHDMISpdifOutEnable(BOOL fgEnable);
/**
 * @brief        Get audio bit width
 * @param        ePort---- HDMI port number
 * @retval       Audio bit width
*/
extern UINT8 bHDMI20AudBitWidth(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Get audio sample frequency
 * @retval       Audio sample frequency
*/
extern UINT8 u1HDMI20GetAudioSamplingFreq(void);
/**
 * @brief        Get audio status for hdmi2.0
 * @retval       1 for audio NG, 0 for audio OK
*/
extern UINT8 bHDMI20AudStatus(void);
/**
 * @brief        Check dsd audio exist for hdmi2.0
 * @retval       TRUE for dsd audio exist, FALSE for dsd audio not exist
*/
extern BOOL fgHDMI20AudDsdOn(void);
/**
 * @brief        Check hbr audio exist for hdmi2.0
 * @retval       TRUE for hbr audio exist, FALSE for hbr audio not exist
*/
extern BOOL fgHDMI20AudHbrOn(void);
/**
 * @brief        Check linear PCM audio
 * @param        ePort---- HDMI port number
 * @retval       TRUE for linear PCM audio, FALSE for not
*/
extern BOOL fgHDMI20IsPCM(E_HDMI_SWITCH_NUM ePort);
#ifdef CC_SUPPORT_DOLBY_VISION
/**
 * @brief        Get Dolby hdr type from info frames
 * @param        const pointer to dolby hdr infoframes
 * @retval       E_HDMI_DOLBY_HDR_STATE(HDMI_DOLBY_HDR_NONE/HDMI_DOLBY_HDR_LOW_LATENCY/HDMI_DOLBY_HDR_DETECT_STANDARD)
*/
extern E_HDMI_DOLBY_HDR_STATE eHDMI2ParseDolbyInfo(const HdmiRxInfo_t* pHdmiRxInfo);
/**
 * @brief        Get Dolby hdr no infoframe setting
 * @retval       TRUE - Dolby hdr no inforame to check, FALSE - Need to check infoframe for Dolby HDR
*/
extern BOOL fgHDMI2GetDolbyHdrNoInfo(void);
/**
 * @brief        Check dolby HDR exist
 * @param        fgNoInfo---- TRUE - Dolby hdr no inforame to check, FALSE - Need to check infoframe for Dolby HDR
*/
extern void vHDMI2SetDolbyHdrNoInfo(BOOL fgNoInfo);
/**
 * @brief        Get current dolby HDR state
 * @param        eHdmiPort---- HDMI port number
 * @retval       Refer to enum E_HDMI_DOLBY_HDR_STATE
*/
extern E_HDMI_DOLBY_HDR_STATE eHDMI2DolbyHdrState(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Init dolby EDR metadata buffer
*/
extern void vHDMI2InitDolbyEdrMetadataBuffer(void);
/**
 * @brief        Get dolby EDR metadata buffer
 * @param        u2Index---- Metadata index
 * @param        *prEdrMetadata---- Pointer to metadata structure HDMI_DOLBY_EDR_METADATA_T
 * @retval       TRUE for valid metadata, FALSE no valid metadata
*/
extern BOOL fgHDMI2GetDolbyEdrMetadataBuff(UINT16 u2Index, HDMI_DOLBY_EDR_METADATA_T *prEdrMetadata);
/**
 * @brief        Freeze/Unfreeze video for Dolby video error handling.
 * @param        u1Path---- Video path number
 * @param        fgFreeze---- TRUE for freeze, FALSE for unfreeze
 * @param        fgForce---- TRUE for ignore signal status, FALSE require stable signal status in DVI.
*/
extern void vHDMI2DolbyEdrFreezeVideo(UINT8 u1Path,BOOL fgFreeze, BOOL fgForce);
/**
 * @brief        Freeze/Unfreeze video for Dolby video error handling.
 * @param        u1Path---- Video path number
*/
extern void vHDMI2DolbyHandleUnfreeze(UINT8 u1Path);
extern void vHDMI2DolbyEmpHandler(const HDMI_HDR_EMP_MD_T* prDynamicHdrEMPktInfo);
#endif //CC_SUPPORT_DOLBY_VISION

#ifdef CC_SUPPORT_W2DR2R
/**
 * @brief        Set w2d r2r frame delay numbers
 * @param        u1FrameDelay---- w2d r2r frame delay numbers
*/
extern void vHDMI2SetW2DR2RFrameDelay(UINT8 u1FrameDelay);
/**
 * @brief        Get w2d r2r frame delay numbers
 * @retval       frame delay numbers
*/
extern UINT8 vHDMI2GetW2DR2RFrameDelay(void);
#endif

#ifdef CC_SUPPORT_HDR10Plus
/**
 * @retval       Refer to HDR10Plus EMP Exist or not
*/
extern BOOL vHDMI2GetHdr10PlusEMPExist(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @retval       Refer to HDR10Plus VSI Exist or not
*/
extern BOOL vHDMI2GetHdr10PlusVSIExist(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Init HDR10Plus metadata buffer
*/
extern void vHDMI2InitHdr10plusMetadataBuffer(void);
/**
 * @brief        Get HDR10Plus Emp metadata buffer
 * @param        u2Index---- Metadata index
 * @param        *prEmpMetadata---- Pointer to metadata structure
HDMI_HDR10Plus_EMP_T
 * @retval       TRUE for valid metadata, FALSE no valid metadata
*/
extern BOOL fgHDMI2GetHdr10PlusEmpMetadataBuff(UINT16 u2Index, HDMI_HDR10Plus_EMP_T *prEmpMetadata);
/**
 * @brief        Get HDR10Plus Vsi metadata buffer
 * @param        u2Index---- Metadata index
 * @param        *prVsiMetadata---- Pointer to metadata structure
HDMI_HDR10Plus_VSI_T
 * @retval       TRUE for valid metadata, FALSE no valid metadata
*/
extern BOOL fgHDMI2GetHdr10PlusVsiMetadataBuff(UINT16 u2Index, HDMI_HDR10Plus_VSI_T *prVsiMetadata);
/**
 * @retval       set to HDR10Plus EMP Exist or not
*/
extern void vHDMI2SetHdr10PlusEmpExist(E_HDMI_SWITCH_NUM eHdmiPort,BOOL fgEmpExist);
/**
 * @retval       HDR10+ set VSI Exist
*/
extern void vHDMI2SetHdr10PlusVsiExist(E_HDMI_SWITCH_NUM eHdmiPort,BOOL fgEmpExist);
/**
 * @retval       HDR10+ parse VSI Metadata
*/
extern void _vHDMI2Hdr10PlusVsifParseMd(E_HDMI_SWITCH_NUM eHdmiPort,HdmiRxInfo_t Hdr10PVsiInfo);
/**
 * @retval       HDR10+ VSI Notify to VDP
*/
extern void _vHDMI2Hdr10PlusVsifNotifyToVDP(E_HDMI_SWITCH_NUM eHdmiPort);
extern void vHDMI2HDR10PlusEmpHandler(E_HDMI_SWITCH_NUM eHdmiPort, HDMI_HDR_EMP_MD_T* prDynamicHdrEMPktInfo);
#endif


/**
 * @brief        Init HDMI module
*/
extern void vHDMI2Init(void);
/**
 * @brief        Get last recorded input TMDS clock
 * @param        ePort---- HDMI port number
 * @retval       TMDS clock in Khz
*/
extern UINT32 u4HDMI2GetTmdsClkKhz(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Get current input TMDS clock
 * @param        ePort---- HDMI port number
 * @retval       TMDS clock in Khz
*/
extern UINT32 u4HDMI2GetCurrentTmdsClkKhz(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Get clock rate enum
 * @param        u4ClkKhz---- Clock rate in Khz
 * @retval       Clock rate enum
*/
extern HdmiTmdsClkRate_t bHDMI2GetRefClkRate(UINT32 u4ClkKhz,BOOL b40xMode);
/**
 * @brief        Get clock rate enum
 * @param        u4ClkKhz---- Clock rate in Khz
 * @retval       Clock rate enum
*/
extern MhlTmdsClkRate_t bMHL2GetRefClkRate(UINT32 u4ClkKhz);
/**
 * @brief        Check hdcp stable
 * @param        ePort---- HDMI port number
 * @retval       1 for HDCP stable, 0 for unstable
*/
extern UINT8 u1IsHDMI2HdcpStable(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Check hdcp authentication done
 * @param        ePort---- HDMI port number
 * @retval       TRUE for authentication done, FALSE for not
*/
extern BOOL fgIsHDMI2HdcpAuthDone(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Check hdcp2x decrypting on
 * @param        ePort---- HDMI port number
 * @retval       TRUE for hdcp2x decrypting on, FALSE for hdcp2x decrypting off
*/
extern BOOL fgIsHDMI2HDCP2xExist(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Set HDMI fast switch flag
 * @param        ePort---- HDMI port number
 * @param        u1Val---- 1 for fast switch on, 0 for fast switch off
*/
extern void vSetHdmi2FastSw(E_HDMI_SWITCH_NUM ePort, UINT8 u1Val);
/**
 * @brief        Check HDMI fast switch flag
 * @param        ePort---- HDMI port number
 * @retval       1 for fast switch on, 0 for fast switch off
*/
extern UINT8 u1IsHdmi2FastSw(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Get bit rate
 * @param        ePort---- HDMI port number
 * @retval       Bit rate
*/
extern UINT32 u4HDMI2GetBitRate(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Check HDMI resolution stable
 * @param        ePort---- HDMI port number
 * @retval       1 for HDMI resolution stable, 0 for unstable
*/
extern UINT8 u1IsHDMI20Stable(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Check HDMI/DVI mode
 * @param        eHdmiPort---- HDMI port number
 * @retval       See Enum HdmiRxMode_t
*/
extern UINT8 bHDMI20GetHdmiMode(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Get HDMI scan info
 * @param        eHdmiPort---- HDMI port number
 * @retval       HDMI scan info
*/
extern UINT8 bHDMI20ScanInfo(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Get HDMI aspect ratio
 * @param        eHdmiPort---- HDMI port number
 * @retval       HDMI aspect ratio
*/
extern UINT8 bHDMI20AspectRatio(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Get HDMI AFD
 * @param        eHdmiPort---- HDMI port number
 * @retval       HDMI AFD
*/
extern UINT8 bHDMI20AFD(E_HDMI_SWITCH_NUM eHdmiPort);

/**
 * @brief        Get HDMI ITC flag
 * @param        eHdmiPort---- HDMI port number
 * @retval       HDMI ITC flag
*/
extern UINT8 bHDMI20ITCFlag(E_HDMI_SWITCH_NUM eHdmiPort);

/**
 * @brief        Get HDMI ITC content
 * @param        eHdmiPort---- HDMI port number
 * @retval       HDMI ITC content
*/
extern UINT8 bHDMI20ITCContent(E_HDMI_SWITCH_NUM eHdmiPort);

/**
 * @brief        Check 422 input
 * @param        eHdmiPort---- HDMI port number
 * @retval       1 for 422 input, 0 for not
*/
extern UINT8 bHDMI20422Input(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Transfer color space to YC422
 * @param        eHdmiPort---- HDMI port number
 * @param        fgEnable---- TRUE for enable, FALSE for disable
*/
extern void vHDMI2TransferToVDP422(E_HDMI_SWITCH_NUM eHdmiPort,BOOL fgEnable);
/**
 * @brief        Get HDMI ITC flag
 * @param        eHdmiPort---- HDMI port number
 * @retval       HDMI ITC flag
*/
extern UINT8 bHDMI2ITCFlag(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Get HDMI ITC content
 * @param        eHdmiPort---- HDMI port number
 * @retval       HDMI ITC content
*/
extern UINT8 bHDMI2ITCContent(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Get hdcp1x status
 * @param        eHdmiPort---- HDMI port number
 * @retval       See HdmiRxHdcp1Status_t for bit map
*/
extern UINT8 bHDMIHDCP1StatusGet(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Get hdcp2x auth status
 * @param        eHdmiPort---- HDMI port number
 * @retval       Enum for auth status, see HDMI_RX_HDCP2X_AUTH_STATUS_T
*/
extern HDMI_RX_HDCP2X_AUTH_STATUS_T eHDMI2GetHdcp2xAuthStatus(E_HDMI_SWITCH_NUM ePort);
/**
 * @brief        Get HDMI infoframe for hdmi_if interface
 * @param        eHdmiPort---- HDMI port number
 * @param        *ptInfo---- Pointer to HdmiRxInfo_t
 * @param        u1Type---- Infoframe type, see HdmiInfoFrameID_t
 * @retval
*/
extern UINT8 bHDMI20GetInfoFrameToIF(E_HDMI_SWITCH_NUM eHdmiPort,HdmiRxInfo_t *ptInfo,UINT8 u1Type);
/**
 * @brief        Get HDMI SPD UP status
 * @param        eHdmiPort---- HDMI port number
 * @retval       HDMI SPD UP status
*/
extern UINT8 u1HDMI2GetUPStatus(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Check HDMI SPD UP status change
 * @param        eHdmiPort---- HDMI port number
 * @retval       HDMI SPD UP status change type
*/
extern UINT8 u1HDMI2GetUPStaChg(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Get HDMI SPD 4K ps status
 * @param        eHdmiPort---- HDMI port number
 * @retval       HDMI SPD 4K ps status
*/
extern UINT8 u1HDMI2Get4KPStatus(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Set ACP change callback function
 * @param        pfAcpChgCb---- Pointer to DRIVER_HDMI_ACP_CHG_CB
 * @param        *tag---- Externed tag
*/
extern void vHDMI2SetAcpChgCallback(DRIVER_HDMI_ACP_CHG_CB pfAcpChgCb,void *tag);
/**
 * @brief        Check HDCP key valid
 * @param        eHdcpKeyCheckMode---- Check key type, see HDMI_HDCP_KEY_CHECK_MODE_T
 * @retval       1 for key valid, 0 for key invalid
*/
extern UINT8 u1HDMIHDCPKeyCheckValid(HDMI_HDCP_KEY_CHECK_MODE_T eHdcpKeyCheckMode);
#ifdef __MODEL_slt__
/**
 * @brief        Sample slt golden CRC
 * @param        eHdmiPort---- HDMI port number
 * @retval       TRUE for sucess, FALSE for fail
*/
extern BOOL bHDMI2SltCRCSample(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Check slt CRC same as golden CRC
 * @param        eHdmiPort---- HDMI port number
 * @retval       TRUE for same as golden CRC, FALSE for not
*/
extern BOOL bHDMI2SltCRCCheck(E_HDMI_SWITCH_NUM eHdmiPort);
#endif //__MODEL_slt__
/**
 * @brief        Print HDCP1.4 status
 * @param        eHdmiPort---- HDMI port number
*/
extern void vHDMI2PrintHdcp14Status(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Print HDCP2.2 status
 * @param        eHdmiPort---- HDMI port number
*/
extern void vHDMI2PrintHdcp22Status(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Print HDMI general status
 * @param        eHdmiPort---- HDMI port number
*/
extern void vHDMI2PrintHdmiGeneralStatus(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Print HDMI video status
 * @param        eHdmiPort---- HDMI port number
*/
extern void vHDMI2PrintHdmiVideoStatus(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Print HDMI audio status
 * @param        eHdmiPort---- HDMI port number
*/
extern void vHDMI2PrintHdmiAudioStatus(E_HDMI_SWITCH_NUM eHdmiPort);
/**
 * @brief        Print HDMI status
 * @param        eHdmiPort---- HDMI port number
 * @retval
*/
extern void vHDMI2PrintHdmiStatus(E_HDMI_SWITCH_NUM eHdmiPort);
#ifdef CC_SUPPORT_STR
/**
 * @brief        HDMI fastboot suspend function
*/
extern void HDMI2_pm_suspend(void);
/**
 * @brief        HDMI fastboot resume function
*/
extern void HDMI2_pm_resume(void);
#endif //CC_SUPPORT_STR
/**
 * @brief        HDMI main loop handler
*/
extern void vHDMI2MainLoop(void);
extern UINT8 bHDMI20RgbInput(E_HDMI_SWITCH_NUM ePort);

//Customized functions defined in hdmi_conf.c >>> BEGIN
extern void vHDMIHPDHigh(E_HDMI_SWITCH_NUM eSwitch);
extern void vHDMIHPDLow(E_HDMI_SWITCH_NUM eSwitch);
extern UINT8 bHDMIPort5VStatus(E_HDMI_SWITCH_NUM ePort);
extern void vHDMISetSwitch(E_HDMI_SWITCH_NUM eSwitch,UINT8 u1Type);
extern void vHDMIMonitorConnectedDevices(void);
extern UINT8 u1HDMIGetPhysicalPortConnected(E_HDMI_SWITCH_NUM ePort);
//Customized functions defined in hdmi_conf.c >>> END
//Customized functions defined in mtk_hdmi.h >>> BEGIN
extern void vHDMIPortInfoInit(void);
extern void vHDMIGetPortsInfo(HDMI_PORTS_INFO_T* prPortsInfo);
extern E_HDMI_SWITCH_NUM eHDMIGetPhysicalPortId(E_HDMI_SWITCH_NUM eVirPort);
extern E_HDMI_SWITCH_NUM eHDMIGetVirtualPortId(E_HDMI_SWITCH_NUM ePhyPort);
#ifdef CC_HDMI_POH_SUPPORT
extern void vHDMIPohConfigInit(void);
extern BOOL fgHDMIPohEnabled(E_HDMI_SWITCH_NUM ePort);
extern void vHDMIGetPohConfig(E_HDMI_SWITCH_NUM ePort,HDMI_POH_CONFIG_T *prPohConfig);
#endif
//Customized functions defined in mtk_hdmi.h >>> END
extern void vHDMI2SetLateResumeFlag(BOOL fgLateResume);
extern HdmiRxObject_t* pHDMI2GetHdmiRxObject(void);
//vrr function for tmds
extern void _vHDMIRestEMPPkt1VrrInfo(E_HDMI_SWITCH_NUM eHdmiPort);
extern void _vHDMI2SetVrrEMPPkt1Info(E_HDMI_SWITCH_NUM eHdmiPort, HdmiRxInfo_t eEmpInfo);
extern void _vHDMI2GetEMPPkt1VrrInfo(E_HDMI_SWITCH_NUM eHdmiPort, HDMI_VRR_Info *prVrrInfo);
extern UINT8 u1HDMI2GetVrrEnInfo(E_HDMI_SWITCH_NUM eHdmiPort);
extern void _vHDMI2GetFreeSyncInfo(E_HDMI_SWITCH_NUM eHdmiPort, HDMI_DRR_Fs_Info *prFsInfo);
extern void _vHDMI2UpdateVrrCCIRTgen(E_HDMI_SWITCH_NUM eHdmiPort);
extern void _vHDMIRestSPDDrrInfo(E_HDMI_SWITCH_NUM eHdmiPort);
extern void _vHDMI2InputVsyncISR(UINT8 u1Type);
extern void _vHDMI2DolbyEMPNotifyToVDP(void);
extern E_HDMI_SWITCH_NUM u2HDMI2GetDigBaseAddrToPort(UINT16 u2HdmiRegBase);
extern UINT8 u1HDMI20SearchVRRBaseTimig(E_HDMI_SWITCH_NUM eHdmiPort);
extern void _vHDMI2ParserSPDInfo(E_HDMI_SWITCH_NUM eHdmiPort);
extern void _vHDMI2ClkPathSel(E_HDMI_SWITCH_NUM eHdmiPort);
extern void vHDMI2PhyCntSet(E_HDMI_SWITCH_NUM ePort, UINT8 val);
/**
 * @brief        HDMI TMDS get 2PLR Mode function
*/
extern BOOL bHDMI2Get2PLRMode(E_HDMI_SWITCH_NUM eHdmiPort);
extern void _vHDMI2MuteAudio(E_HDMI_SWITCH_NUM ePort,BOOL bEn);
extern void vHDMI2GetCable5VStatus(PFN_NOTIFY_CABLE_5V pCBFun);

#endif

