/**
 * @file hv_drv_DisplayPort.h
 * @brief Header file of DpRx Driver module.
 * 
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 * (+)  
 * 
 * @endverbatim
 *
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2022-08-10
 */
#ifndef _HV_DRV_DP_H_
#define _HV_DRV_DP_H_

#include "hv_comm_DataType.h"
#include "hv_comm_Define.h"
#include "hv_cal_Dprx.h"

#define DP_HPD_HIGH                            1
#define DP_HPD_LOW                             0

#define DP_MCCS_CMD_LENGTH                     16

#define DP_EDID_MAX_LENGTH                     512

/**
 * @brief The IP of DpRx Initialize.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_Init(UCHAR8 ucPortId);

/**
 * @brief Update Edid
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_UpdtEdid(UCHAR8 ucPortId, const UCHAR8 *pucEdid, USHORT16 usLen);

/**
 * @brief Set DP version.
 * @param[in] ucPortId: port index 0 or 1
 * @param[ucDpVer] DP Version 1.2 or 1.4
 * @return Status.
 */
Status Hv_Drv_DpRx_SetDpVer(UCHAR8 ucPortId, UCHAR8 ucDpVer);

/**
 * @brief Get DP version.
 * @param[in] ucPortId: port index 0 or 1
 * @return DP version.
 */
UCHAR8 Hv_Drv_DpRx_GetDpVer(UCHAR8 ucPortId);

/**
 * @brief Detect Cable Connected or not
 * @param[in] ucPortId: port index 0 or 1
 * @param[out] puwCnctSt point to Connected Status
 * @return HV_TRUE or HV_FALSE.
 */
BOOL Hv_Drv_DpRx_DetectCable(UCHAR8 ucPortId);

/**
 * @brief Get Dp AuxN State.
 * @param[in] ucPortId: port index 0 or 1
 * @return BOOL, HV_TRUE for level high
 */
 BOOL Hv_Drv_DpRx_GetAuxState(UCHAR8 ucPortId);

/**
 * @brief Set cable connect status, used for debug tool.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_SetCableStatus(UCHAR8 ucPortId, BOOL bPlugIn);

/**
 * @brief Set hpd status, used for debug tool.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_SetHPDStatus(UCHAR8 ucPortId, BOOL bHigh);

/**
 * @brief Send IRQ_HPD to DPTX
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_IrqHpd(UCHAR8 ucPortId);

/**
 * @brief Pull HPD Line to high voltage or low voltage
 * @param[in] ucPortId: port index 0 or 1
 * @param[in] bSwitch: HV_TRUE for high or HV_FALSE for low
 * @return VOID.
 */
VOID Hv_Drv_DpRx_EvtHpd(UCHAR8 ucPortId, BOOL bSwitch);

/**
 * @brief Detect the Link status of DP
 * @param[in] ucPortId: port index 0 or 1
 * @return HV_TRUE: link sync, HV_FALSE: link not sync.
 */
BOOL Hv_Drv_DpRx_DetectLink(UCHAR8 ucPortId);

/**
 * @brief Dump Training NG reason.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_DumpFailStatus(UCHAR8 ucPortId);

/**
 * @brief Detect the Link has video or not
 * @param[in] ucPortId: port index 0 or 1
 * @return HV_TRUE: has video, HV_FALSE: no video.
 */
BOOL Hv_Drv_DpRx_DetectVideo(UCHAR8 ucPortId);

/**
 * @brief Detect the Video Timing
 * @param[in] ucPortId: port index 0 or 1
 * @param[out] pstTiming point to Video Timing.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Drv_DpRx_GetTiming(UCHAR8 ucPortId, VideoTimingParam *pstTiming,AudioTimingParam *pstAudioTiming);

/**
 * @brief Get SDP status.
 * @param[in] ucPortId: port index 0 or 1
 * @return BOOL: HV_TRUE good, HV_FALSE error.
 */
BOOL Hv_Drv_DpRx_GetSdpStatus(UCHAR8 ucPortId);

/**
 * @brief Get Audio Status
 * @param[in] ucPortId: port index 0 or 1
 * @return BOOL, 0-HV_FALSE, 1-HV_TRUE.
 */
BOOL Hv_Drv_DpRx_GetAudioSta(UCHAR8 ucPortId);

/**
 * @brief Get VRR parameter.
 * @param[in] ucPortId: port index 0 or 1
 * @param[out] pstVrrParam point to the parameter of VRR.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Drv_DpRx_GetVrr(UCHAR8 ucPortId, VRRInfoParam *pstVrrParam);

/**
 * @brief Set Timing Ignore.
 * @param[in] ucPortId: port index 0 or 1
 * @param[in] bIgnore: ignore msa timing or not
 * @return VOID.
 */
VOID Hv_Drv_DpRx_SetTimingIgnore(UCHAR8 ucPortId, BOOL bIgnore);

/**
 * @brief DP max lane count.
 * @param[in] ucPortId: port index 0 or 1
 * @param[in] ucDpLaneCount: 1 or 2 or 4
 * @return Status.
 */
Status Hv_Drv_DpRx_SetMaxLaneCount(UCHAR8 ucPortId, UCHAR8 ucDpLaneCount);

/**
 * @brief Detect Color
 * @param[in] ucPortId: port index 0 or 1
 * @param[out] pstColor point to the parameter of Color.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Drv_DpRx_GetColor(UCHAR8 ucPortId, VideoColorParam *pstColor);

/**
 * @brief Dp Rx reshape audio data.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_AudioReshape(UCHAR8 ucPortId);

/**
 * @brief Detect HDR
 * @param[in] ucPortId: port index 0 or 1
 * @param[out] pstColor point to the parameter of Color.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Drv_DpRx_GetHdr(UCHAR8 ucPortId, HDRParam *pstHdr);

/**
 * @brief Save HDR to buffer
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_SaveHdr(UCHAR8 ucPortId);

/**
 * @brief Clear HDR buffer
 * @param[in] ucPortId: port index 0 or 1
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Drv_DpRx_ClrHdr(UCHAR8 ucPortId);

/**
 * @brief Save VRR to buffer
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_SaveVrr(UCHAR8 ucPortId);

/**
 * @brief Clear VRR buffer
 * @param[in] ucPortId: port index 0 or 1
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Drv_DpRx_ClrVrr(UCHAR8 ucPortId);

/**
 * @brief Save new SDP packets
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_UpdateSdp(UCHAR8 ucPortId);

/**
 * @brief Check OUI and TimingIgnore for NVIDIA
 * @param[in] ucPortId: port index 0 or 1
 * @param[out] pstVrrParam: output VRR info
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Drv_DpRx_CheckOui(UCHAR8 ucPortId, VRRInfoParam *pstVrrParam);

/**
 * @brief Get Power state.
 * @param[in] ucPortId: port index 0 or 1
 * @return 1:power on; 2:power off.
 */
UCHAR8 Hv_Drv_DpRx_GetPowerState(UCHAR8 ucPortId);

/**
 * @brief Get mccs command.
 * @param[in] ucPortId: port index 0 or 1
 * @param[out] pucMccsContent point to the mccs command;
 * @param[in] ucLength command len.
 * @return VOID.
 */
VOID Hv_Drv_DpRx_GetMccsCmd(UCHAR8 ucPortId, UCHAR8 *pucMccsCmd, UCHAR8 ucLength);

/**
 * @brief Get Interrupt Irq Index
 * @param[in] ucPortId: port index 0 or 1
 * @param[out] pucIrqId point to the array that store irq index.
 * @return UCHAR8, IRQ ID.
 */
UCHAR8 Hv_Drv_DpRx_GetIrqId(UCHAR8 ucPortId);

UCHAR8 Hv_Drv_DpRx_GetCableIrqId(UCHAR8 ucPortId);

/**
 * @brief Mask SDP change interrupt
 * @param[in] ucPortId: port index 0 or 1
 * @param[in] bSwitch: 0-off, 1-on
 * @return VOID.
 */
VOID Hv_Drv_DpRx_MaskSdpInt(UCHAR8 ucPortId, BOOL bSwitch);

/**
 * @brief Mask Color change interrupt
 * @param[in] ucPortId: port index 0 or 1
 * @param[in] bSwitch: 0-off, 1-on
 * @return VOID.
 */
VOID Hv_Drv_DpRx_MaskColorInt(UCHAR8 ucPortId, BOOL bSwitch);

/**
 * @brief Mask Timing interrupt
 * @param[in] ucPortId: port index 0 or 1
 * @param[in] bSwitch: 0-off, 1-on
 * @return VOID.
 */
VOID Hv_Drv_DpRx_MaskTimingInt(UCHAR8 ucPortId, BOOL bSwitch);

/**
 * @brief Dp Rx Htotal interupt mask.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_MaskRxHtotalInt(UCHAR8 ucPortId, BOOL bSwitch);

/**
 * @brief Mask Timing interrupt
 * @param[in] ucPortId: port index 0 or 1
 * @param[in] bSwitch: 0-off, 1-on
 * @return VOID.
 */
VOID Hv_Drv_DpRx_MaskAudioDepthInt(UCHAR8 ucPortId, BOOL bSwitch);
/**
 * @brief Set Interrupt Enable
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_SetIntEnable(UCHAR8 ucPortId);

/**
 * @brief Get Interrupt Flags
 * @param[in] ucPortId: port index 0 or 1
 * @param[out] puiDpIntFlag point to the Interrupt Flags that don't belong to hdcp.
 * @param[out] puiHdcpIntFlag point to the Interrupt Flags that belong to hdcp.
 * @return VOID.
 */
VOID Hv_Drv_DpRx_GetIntFlag(UCHAR8 ucPortId, UINT32 *puiDpIntFlag, UINT32 *puiHdcpIntFlag);

/**
 * @brief Clear Interrupt Flags
 * @param[in] ucPortId: port index 0 or 1
 * @param[out] puiDpIntFlag point to the Interrupt Flags that don't belong to hdcp.
 * @param[out] puiHdcpIntFlag point to the Interrupt Flags that belong to hdcp.
 * @return VOID.
 */
VOID Hv_Drv_DpRx_ClrIntFlag(UCHAR8 ucPortId, UINT32 *puiDpIntFlag, UINT32 *puiHdcpIntFlag);

/**
 * @brief Dp Rx Link Bandwidth changed.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_LinkBwChanged(UCHAR8 ucPortId);

/**
 * @brief Dp Rx Link Count changed.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_LinkCountChanged(UCHAR8 ucPortId);

/**
 * @brief Dp Rx Generate EQ Permit.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID  Hv_Drv_DpRx_EqPermit(UCHAR8 ucPortId);

/**
 * @brief Dp Rx Training Done.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_TrainingDone(UCHAR8 ucPortId);

/**
 * @brief Dp Rx Training Failed.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_TrainingFail(UCHAR8 ucPortId);

/**
 * @brief Dp Rx select training mode.
 * @param[in] ucPortId: port index 0 or 1
 * @param[in] ucTrainMode: auto/no-link/full-link
 * @return VOID.
 */
VOID Hv_Drv_DpRx_SetTrainMode(UCHAR8 ucPortId, UCHAR8 ucTrainMode);

/**
 * @brief Dp Rx audio fifo OnOff.
 * @param[in] ucPortId: port index 0 or 1
 * @return Status.
 */
Status Hv_Drv_DpRx_AudioFifoOnOff(UCHAR8 ucPortId, BOOL bEn);

/**
 * @brief Detect the Link has audio or not
 * @param[in] ucPortId: port index 0 or 1
 * @return HV_TRUE: has audio, HV_FALSE: no audio.
 */
BOOL Hv_Drv_DpRx_DetectAudio(UCHAR8 ucPortId);

/**
 * @brief Dp Rx re-do deskew.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_ToggleDeskew(UCHAR8 ucPortId);

/**
 * @brief Dp Rx recieve sw irq.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_SwIrq(UCHAR8 ucPortId);

/**
 * @brief Clear cable Interrupt Flags
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_ClrCableIntFlag(UCHAR8 ucPortId);

/**
 * @brief Analysize Interrupt Flags to get Cal Event.
 * @param[in] ucPortId: port index 0 or 1
 * @param[in] puiNoHdcpIntFlag point to the Interrupt Flags that don't belong to hdcp.
 * @param[out] pstDpRxEventList point to the Cal Event.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Drv_DpRx_AlysIntEvent(UCHAR8 ucPortId, UINT32 *puiNoHdcpIntFlag, DpRxIntEventList *pstDpRxEventList);

/**
 * @brief mccs command reply.
 * @param[in] ucPortId: port index 0 or 1
 * @param[in] data point to reply data
 * @param[in] len reply data length
 * @return VOID.
 */
VOID Hv_Drv_DpRx_MccsReply(UCHAR8 ucPortId, UCHAR8 *data, UCHAR8 len);

/**
 * @brief Get sdp fifo data.
 * @param[in] ucPortId: port index 0 or 1
 * @param[in] pstHdr: point to hdr data struct
 * @param[in] pstVrrParam point to the vrr data struct;
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Drv_DpRx_GetSdpFifo(UCHAR8 ucPortId, HDRParam *pstHdr, VRRInfoParam *pstVrrParam);

/**
 * @brief Get port mux.
 * @param[in] ucPortId: port index 0 or 1
 * @param[out] puiPortMux point to the port mux;
 * @return MuxMatrix.
 */
UCHAR8 Hv_Drv_DpRx_GetPortMux(VOID);

/**
 * @brief Reset DPCD config & ctrl settings
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_ResetDpcd(UCHAR8 ucPortId);

/**
 * @brief Set audio valid thro.
 * @param[in] ucPortId: port index 0 or 1
 * @param[in] uiAudVld: audio vld value
 * @return VOID.
 */
VOID Hv_Drv_DpRx_SetAudVldThro(UCHAR8 ucPortId, UINT32 uiAudVld);

/**
 * @brief Get current frame rate.
 * @param[in] ucPortId: port index 0 or 1
 * @return current frame rate.
 */
UINT32 Hv_Drv_DpRx_GetFrameRate(UCHAR8 ucPortId);

/**
 * @brief Config DPRX Aux polarity and Lane polarity.
 * @param[in] ucPortId: port index 0 or 1
 * @param[in] ucOrientation: Norm or Reverse
 * @param[in] ucPinAssignment: 0 for C, 1 for D, 2 for E
 * @return VOID.
 */
VOID Hv_Drv_DpRx_SetTypecOrientation(UCHAR8 ucPortId, UCHAR8 ucOrientation, UCHAR8 ucPinAssignment);

/**
 * @brief Config DPRX Audio Stop.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_AudioStop(UCHAR8 ucPortId);

/**
 * @brief Config DPRX Audio Stop.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_AudioStart(UCHAR8 ucPortId);

/**
 * @brief Check DPRX Audio ready.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_AudioCheck(UCHAR8 ucPortId);

/**
 * @brief Reset DP.
 * @param[in] ucPortId: port index 0 or 1
 * @return VOID.
 */
VOID Hv_Drv_DpRx_Reset(UCHAR8 ucPortId, BOOL bEn);

/**
 * @brief Enable DP Aux write.
 * @param[in] bEn
 * @return VOID.
 */
VOID Hv_Drv_DpRx_EnableApbWr(BOOL bEn);

#endif
