/**
 * @file hv_mw_DisplayPort.h
 * @brief Header file of DpRx MiddleWare module.
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2022-08-10
 */

#ifndef __SDK_MIDDLEWARE_DISPLAY_PORT_INC_DISPLAY_PORT_H__
#define __SDK_MIDDLEWARE_DISPLAY_PORT_INC_DISPLAY_PORT_H__

#include "hv_mw_InputPortManager.h"
#include "hv_comm_Event.h"
#include "hv_comm_Timer.h"
#include "hv_vos_Comm.h"
#include "hv_comm_Define.h"
#include "hv_drv_DisplayPort.h"
#include "hv_comm_SafeQueue.h"

typedef struct _DpRxIntStatus
{
    UINT32 uiIntrruptStatus1;
    UINT32 uiIntrruptStatus2;
    UINT32 uiIntrruptStatus3;
}DpRxIntStatus;

DECLARE_HS_SAFE_QUEUE(DpQueue, 20, sizeof(DpRxIntStatus));

/**
 * @brief dump current video timing info.
 * @param[in] pstVideoTiming point to timing info.
 * @return VOID.
 */
VOID Hv_Mw_DpRx_PrintTimingInfo(VideoTimingParam *pstVideoTiming);

/**
 * @brief dump current video color info.
 * @param[in] pstVideoColor point to color info.
 * @return VOID.
 */
VOID Hv_Mw_DpRx_PrintColorInfo(VideoColorParam *pstVideoColor);

/**
 * @brief dump current hdr info.
 * @param[in] pstHDRPara point to hdr info.
 * @return VOID.
 */
VOID Hv_Mw_DpRx_PrintHdrInfo(HDRParam *pstHDRPara);

/**
 * @brief dump current AMD SPD info.
 * @param[in] pstVrrInfo point to VRR info.
 * @return VOID.
 */
VOID Hv_Mw_DpRx_PrintAMDInfo(VRRInfoParam *pstVrrInfo);

/**
 * @brief dump current NVIDIA SPD info.
 * @param[in] pstVrrInfo point to VRR info.
 * @return VOID.
 */
VOID Hv_Mw_DpRx_PrintNvidiaInfo(VRRInfoParam *pstVrrInfo);

/**
 * @brief Set DP HPD level.
 * @param[in] enPortIndex, port index of DP.
 * @param[in] BOOL, DP_HPD_LOW or DP_HPD_HIGH.
 * @return VOID.
 */
Status Hv_Mw_DpRx_HpdLevel(LinkPortIndex enPortIndex, BOOL bHpdLevel);

/**
 * @brief generate IRQ_HPD.
 * @param[in] enPortIndex, port index of DP.
 * @return VOID.
 */
VOID Hv_Mw_DpRx_IrqHpd(LinkPortIndex enPortIndex);

/**
 * @brief Dp Rx SDP interupt mask.
 * @param[in] enPortIndex: port index
 * @return VOID.
 */
VOID Hv_Mw_DpRx_MaskSdpInt(LinkPortIndex enPortIndex, BOOL bSwitch);

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

/**
 * @brief Dp Rx Htotal interupt mask.
 * @param[in] enPortIndex: port index
 * @return VOID.
 */
VOID Hv_Mw_DpRx_MaskRxHtotalInt(LinkPortIndex enPortIndex, BOOL bSwitch);

/**
 * @brief Set DP EDID.
 * @param[in] ucPortId: port index 0 or 1
 * @param[pucEdidData] EDID
 * @param[usLen] EDID len
 * @return Status.
 */
Status Hv_Mw_DpRx_SetEdid(LinkPortIndex enPortIndex, const UCHAR8 *pucEdidData, USHORT16 usLen);

/**
 * @brief Get DP EDID.
 * @param[in] ucPortId: port index 0 or 1
 * @param[pucEdidData] EDID
 * @return EDID len.
 */
UINT32 Hv_Mw_DpRx_GetEdid(LinkPortIndex enPortIndex, UCHAR8 *pucEdidData);

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

/**
 * @brief Set DP version.
 * @param[ucDpVer] DP Version 1.1 or 1.2 or 1.4
 * @return Status.
 */
Status Hv_Mw_DpRx_SetAllDpVer(UCHAR8 ucDpVer);

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

/**
 * @brief Get DP version.
 * @return DP version.
 */
UCHAR8 Hv_Mw_DpRx_GetAllDpVer();

/**
 * @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_Mw_DpRx_SetMaxLaneCount(LinkPortIndex enPortIndex, UCHAR8 ucDpLaneCount);

/**
 * @brief Get InputPort Event for Interrupt Flags and send to System Event List.
 * @param[in] pstEvent point to InputPort Event.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_ProcSystemMsg(InputPortEvent* pstEvent);
Status Hv_Mw_DpRx_ProcCableMsg(InputPortEvent* pstEvent);

/**
 * @brief Get InputPort Event for Interrupt Flags and send to System Event List.
 * @param[in] LinkPortIndex, portIndex.
 * @return BOOL, 0-NotConnected, 1-Connected.
 */
BOOL Hv_Mw_DpRx_GetPortStatus(LinkPortIndex enLinkPortIndex);

/**
 * @brief Provide HDR data.
 * @param[in] enLinkPortIndex, port index.
 * @param[in] pstHdrPara point to HDR data struct.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_GetHdrPara(LinkPortIndex enLinkPortIndex, HDRParam  *pstHdrPara);

/**
 * @brief aux state.
 * @param[in] enLinkPortIndex, port index.
 * @return Status, 0-not connect, 1-connect.
 */
BOOL Hv_Mw_DpRx_GetAuxState(LinkPortIndex enPortIndex);

/**
 * @brief Initialize DpRx software module.
 * @param[in] pstDisplayPortManager point to Manager Info.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Init(DisplayPortManager* pstDisplayPortManager);

/**
 * @brief Initialize DpRx Interrupt.
 * @param[in] enPortIndex, DP Port Index.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_InterruptInit(LinkPortIndex enPortIndex);

/**
 * @brief Process in DpRx State Machine to state for the first time.
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_FirstEnter(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process of starting from state IDLE.
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_IdleStart(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process Cable Detect in DpRx State Machine.
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_CableDet(const InputPortEvent* pstEvent, VOID* pstPortData);

/**
 * @brief Process Link Training Done in DpRx State Machine.
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_TrainingDone(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process Link Training Fail in DpRx State Machine.
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_TrainingFail(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process Timing Check in DpRx State Machine .
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_CheckTiming(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process Training NG in DpRx State Machine .
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_TrainingNG(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process Hpd Pull-Up in DpRx State Machine .
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_HpdTimeOut(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process Timing Change in DpRx State Machine .
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_TimingChange(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process Audio Reshape in DpRx State Machine .
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_AudioReshape(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process Color Change in DpRx State Machine .
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_ColorChange(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process HDR Change in DpRx State Machine .
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_HdrChange(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process VRR Change in DpRx State Machine .
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_VrrChange(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Get OUI and timing ignore for NVIDIA GSYNC .
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_TimingIgnoreChange(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process Adaptive Sync Start in DpRx State Machine .
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_AdaptSyncStart(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process Adaptive Sync Stop in DpRx State Machine .
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_AdaptSyncEnd(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process Mccs Msg Recv in DpRx State Machine .
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_MccsProc(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @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_Mw_DpRx_SetTypecOrientation(LinkPortIndex enPortIndex, UCHAR8 ucOrientation, UCHAR8 ucPinAssignment);

/**
 * @brief Config DPRX Audio Stop.
 * @param[in] enPortIndex: DP port index
 * @return VOID.
 */
Status Hv_Mw_DpRx_AudioStop(LinkPortIndex enPortIndex);

/**
 * @brief Config DPRX Audio Start.
 * @param[in] enPortIndex: DP port index
 * @return VOID.
 */
Status Hv_Mw_DpRx_AudioStart(LinkPortIndex enPortIndex);

/**
 * @brief Check DPRX Audio ready.
 * @param[in] enPortIndex: DP port index
 * @return VOID.
 */
Status Hv_Mw_DpRx_AudioCheck(LinkPortIndex enPortIndex);

/**
 * @brief Config DPRX Wake Process.
 * @param[in] enPortIndex: DP port index
 * @return VOID.
 */
Status Hv_Mw_DpRx_Sm_WakeUp(const InputPortEvent *pstEvent, VOID *pstPortData);

/**
 * @brief Process audio MUTE change in DpRx State Machine.
 * @param[in] pstEvent point to Inputport Event.
 * @param[in] pstPortData point to Inputport Data.
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_Sm_AudioMuteChgHandler(const InputPortEvent *pstEvent, VOID *pstPortData);

/* Used for Update EDID withou check Type and HPD, Used for Factory ParaUpdte */
/**
 * @brief Update EDID Content Robust.
 * @param[in] enPortIndex: DP port index
 * @return Status, 0-HV_SUCCESS, 1-HV_FAILURE.
 */
Status Hv_Mw_DpRx_UpdtEdidRobust(LinkPortIndex enPortIndex);

#endif
