/**
 * @file hv_cal_vbo_tx.c
 * @brief VboTx CAL module driver
 * @details This module provide interfaces for DRV level.
 * @author HiView SoC Software Team
 * @version 0.0.1
 * @date 20220903
 * @copyright Copyright(c),2022-9, Hiview Software. All rights reserved.
 * @par History:
 * <table>
 * <tr><th>Author                         <th>Date             <th>Details
 * <tr><td>HiView SoC Software Team   <td>20220903       <td>Create and first Version.
 * </table>
 **/

#include "hv_cal_VboTx.h"
#include "hv_vos_Comm.h"
#include "HV_REGS_HT7315.h"

VOID Hv_Cal_VboTx_Init(HvVboTopParam stVboTopParam)
{
    /* fix settings */
    HV_W32_FIELD(TX_VBY1_TOP_VBY1TX_SET_1, reg_byte_mode, stVboTopParam.usByteMode);
    HV_W32_FIELD(TX_VBY1_TOP_VBY1TX_SET_4, reg_pll_stable, stVboTopParam.usPllStable);
    HV_W32_FIELD(TX_VBY1_TOP_VBY1TX_SET_12, reg_fw_htpdn_set, stVboTopParam.usFwHtpdnSet);
    HV_W32_FIELD(TX_VBY1_TOP_VBY1TX_SET_4, reg_reg_delay, stVboTopParam.usRegDelay);
    HV_W32_FIELD(TX_VBY1_TOP_VBY1TX_PHY_SET_1, reg_lane_enable, stVboTopParam.usLaneEnable);
    HV_W32_FIELD(TX_VBY1_TOP_VBY1TX_SET_4, reg_debounce_cnt, stVboTopParam.usDebounceCnt);
    HV_W32_FIELD(TX_VBY1_TOP_VBY1TX_SET_0, reg_color_format, stVboTopParam.usColorFormat);
    HV_W32_FIELD(TX_VBY1_TOP_VBY1TX_SET_12, reg_htpdn_mode_ctrl, stVboTopParam.usHtpdnModeCtrl);
    HV_W32_FIELD(TX_VBY1_TOP_VBY1TX_SET_1, reg_lane_count, (stVboTopParam.usLaneNum * stVboTopParam.usSection));
    HV_W32_FIELD(TX_VBY1_TOP_VBY1TX_SET_1, reg_pixel_mode, stVboTopParam.usPixelMode);
    HV_W32_FIELD(TX_VBY1_TOP_VBY1TX_SET_1, reg_section, stVboTopParam.usSection);
    
    HV_W32_FIELD(TX_PIF_TX_TOP_18, reg_txgrp_00_dclk_sel, 0);  //从1改成0，解决部分VBO屏兼容性问题
    return;
}

VOID Hv_Cal_VboTx_SetMacEn(BOOL bEn)
{
    HV_W32_FIELD(TX_VBY1_TOP_VBY1TX_SET_4, reg_reg_en, bEn);
    return;
}

VOID Hv_Cal_VboTx_SetPifVboClkEn(BOOL bEn)
{
    HV_W32_FIELD(TX_PIF_TX_TOP_PIF_TX_CLKGEN0, reg_pif_vby1_clk_en, bEn);
    return;
}

Status Hv_Cal_VboTx_GetVboLocknStatus(VOID)
{
    HV_R32_DECL_VAR();
    if ((HV_R32_FIELD(TX_VBY1_TOP_VBY1TX_READBACK_0, lockn_ro) ==0) || (HV_R32_FIELD(TX_VBY1_TOP_VBY1TX_READBACK_0, hw_lockn_ro) == 0))
    {
        return HV_SUCCESS;
    }
    else
    {
        return HV_FAILURE;
    }
}

BOOL Hv_Cal_VboTx_CheckPanelExist(VOID)
{
    HV_R32_DECL_VAR();
    if ((HV_R32_FIELD(TX_VBY1_TOP_VBY1TX_READBACK_0, hw_htpdn_ro) == 0) || (HV_R32_FIELD(TX_VBY1_TOP_VBY1TX_READBACK_0, htpdn_ro) == 0))
    {
        return HV_TRUE;
    }
    else
    {
        return HV_FALSE;
    }
}

