/**
 * @file hv_cal_EdpTx_training.h
 * @brief Header file of CAL EdpTx sturct.
 * 
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 * 
 * 
 * @endverbatim
 *
 * @author HiView SoC Software Team
 * @version 0.0.1
 * @date 2022-11-11
 */

#ifndef __HV_CAL_EDP_TX_TRAINING_H__
#define __HV_CAL_EDP_TX_TRAINING_H__
#include "hv_comm_DataType.h"
#include "hv_cal_EdpTxCommon.h"
#include "hv_vos_Comm.h"
#include "hv_comm_Define.h"
/* AUX Command define */
#define EDPTX_NATIVE_AUX_W                     8
#define EDPTX_NATIVE_AUX_R                     9

typedef enum _EdpTxTpsPatTyp
{
    EDPTX_SEND_TPS1 = 1,
    EDPTX_SEND_TPS2 = 2,
    EDPTX_SEND_TPS3 = 3,
    EDPTX_SEND_TPS4 = 4,
}EdpTxTpsPattTyp;

typedef struct _HvEdpTxPhyAnaLevel
{
    UCHAR8 ucSwingMainVale;    //swing=(ib_source*5+10)*swing_main (mV)
    UCHAR8 ucPreEmphVale;      //swing_tapi
    UCHAR8 ucIbSourceAdj;
}HvEdpTxSourcePhyAnaValue;

/**
 * @brief Return aux delay.
 */
UINT32 Hv_Cal_EdpTX_GetAuxDelay(VOID);

/**
 * @brief AUX Write.
 * @param[in] pstEdpTxAuxTransInfo aux trans param.
 * @return 0: Success or 1: Fail.
 */
UCHAR8 Hv_Cal_EdpTx_AuxNativeMasterWrite(HvEdpTxAuxTransInfo *pstEdpTxAuxTransInfo);

/**
 * @brief AUX Read.
 * @param[in] pstEdpTxAuxTransInfo aux trans param.
 * @return 0: Success or 1: Fail.
 */
UCHAR8 Hv_Cal_EdpTx_AuxNativeMasterRead(HvEdpTxAuxTransInfo *pstEdpTxAuxTransInfo);

/**
 * @brief edp hpd mode settings.
 * @param[in] enEdpHpdPort hpd port num.
 * @param[in] ucSoftMode soft mode, 2表示软件模式开并拉低，3表示软件模式开并拉高，0表示硬件模式.
 */
VOID Hv_Cal_EdpTx_SetHpdSoftMode(EdpHpdPortIndex enEdpHpdPort, UCHAR8 ucSoftMode);

/**
 * @brief Get hpd status.
 * @param[in] enEdpHpdPort edp_hpd port.
 * @return 0: disconncet 1: connect.
 */
UCHAR8 Hv_Cal_EdpTx_GetHpdStatus(EdpHpdPortIndex enEdpHpdPort);

/**
 * @brief Get hpd evt.
 * @param[in] enEdpHpdPort edp_hpd port.
 * @return 0: no evt 1: hdp evt.
 */
UCHAR8 Hv_Cal_EdpTx_GetHpdEvt(EdpHpdPortIndex enEdpHpdPort);

/**
 * @brief Set source send TPS.
 * @param[in] enPortIndex edp_tx port.
 * @param[in] ucTpsType TPS type.
 */
VOID Hv_Cal_EdpTx_SendTpsPattern(EdpTxPortIndex enPortIndex, EdpTxTpsPattTyp enTpsType);

/**
 * @brief Set source scramb_disable
 * @param[in] enPortIndex edp_tx port.
 * @param[in] bEn 0: enalbe sr, 1: disable sr
 */
VOID Hv_Cal_EdpTx_SetEdptxScrambDis(EdpTxPortIndex enPortIndex, BOOL bEn);

/**
 * @brief Set source phy analog param(SwingMainVale, PreEmphVale, IbSourceAdj).
 * @param[in] ucSwingLevel sink report Swing Level.
 * @param[in] ucPreEmpLevel sink report PreEmp Level.
 */
VOID Hv_Cal_EdpTx_SetSourcePhyAnaValue(UCHAR8 ucSwingLevel, UCHAR8 ucPreEmpLevel);

/**
 * @brief Get source Aux trans response.
 * @param[in] enPortIndex edp_tx port.
 * @param[in] bCmd aux command.
 * @return 0: ack, 1: nack, 2: deffer, 3: reserved
 */
UCHAR8 Hv_Cal_EdpTx_GetAuxTransRsp(EdpTxPortIndex enPortIndex, UCHAR8 ucCmd);

/**
 * @brief Set source EQ done, send video data.
 * @param[in] enPortIndex edp_tx port.
 * @param[in] bDone EQ done.
 */
VOID Hv_Cal_EdpTX_SetEdptxEqDone(EdpTxPortIndex enPortIndex, BOOL bDone);

/**
 * @brief Aux operation start, write 0 then write 1 to start a aux operation.
 * @param[in] enPortIndex edp_tx port.
 * @param[in] bTrigger start value.
 */
VOID Hv_Cal_EdpTx_AuxTransStart(EdpTxPortIndex enPortIndex, BOOL bTrigger);

/**
 * @brief Clear aux_trans_done and aux_rsp_timeout status
 * @param[in] enPortIndex edp_tx port.
 */
VOID Hv_Cal_EdpTx_ClearAuxTransStaus(EdpTxPortIndex enPortIndex);

/**
 * @brief Get aux_trans_done status
 * @param[in] enPortIndex edp_tx port.
 * @return 0: aux operation ongoing; 1:aux operation complete
 */
UCHAR8 Hv_Cal_EdpTx_GetAuxTransDone(EdpTxPortIndex enPortIndex);

/**
 * @brief Get aux_rsp_timeout status
 * @param[in] enPortIndex edp_tx port.
 * @return 0: aux transaction ok; 1: aux transaction timeout
 */
UCHAR8 Hv_Cal_EdpTx_GetAuxTransTimeOut(EdpTxPortIndex enPortIndex);


VOID Hv_Cal_EdpTx_AuxNativeMasterProc(HvEdpTxAuxTransInfo *pstEdpTxAuxTransInfo);

VOID Hv_Cal_EdpTx_SetTxPhy00SwingMain(UCHAR8 ucSwing0, UCHAR8 ucSwing1, UCHAR8 ucSwing2, UCHAR8 ucSwing3);

VOID Hv_Cal_EdpTx_SetTxPhy01SwingMain(UCHAR8 ucSwing0, UCHAR8 ucSwing1, UCHAR8 ucSwing2, UCHAR8 ucSwing3);

VOID Hv_Cal_EdpTx_SetTxPhy00SwingTapi(UCHAR8 ucPreEmph0, UCHAR8 ucPreEmph1, UCHAR8 ucPreEmph2, UCHAR8 ucPreEmph3);

VOID Hv_Cal_EdpTx_SetTxPhy01SwingTapi(UCHAR8 ucPreEmph0, UCHAR8 ucPreEmph1, UCHAR8 ucPreEmph2, UCHAR8 ucPreEmph3);

/**
 * @brief Init edptx link training
 * @param[in] enPortIndex edp_tx port.
 * @param[in] ucLaneNum edp_tx lane num.
 */
VOID Hv_Cal_EdpTx_InitLink(EdpTxPortIndex enPortIndex, UCHAR8 ucLaneNum);

/**
 * @brief Rest edptx enable for link training
 * @param[in] enPortIndex edp_tx port.
 * @param[in] bEn 0:off edp, 1: on edp
 */
VOID Hv_Cal_EdpTX_RetEdptxEnable(EdpTxPortIndex enPortIndex, BOOL bEn);

/**
 * @brief set idle pattern enable
 * @param[in] enPortIndex edp_tx port.
 * @param[in] bEn 0:off edp, 1: on edp
 */
VOID Hv_Cal_EdpTx_SendIdlePatternEn(EdpTxPortIndex enEdpTxPort, BOOL bEn);

/**
 * @brief get edptx total lane num
 */
USHORT16 Hv_Cal_EdpTX_GetKtxPairNum(VOID);

/**
 * @brief is enable assr
 */
VOID Hv_Cal_EdpTx_SetAssrEn(EdpTxPortIndex enPort, BOOL bEn);
#endif
