/**
 * @file hv_drv_DpuMainScaler.c
 * @brief dpu driver source code.
 * @details This file provides the following functions: \n
 *          (1) Initialization and reset functions \n
 *
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2022-08-23
 * @copyright Copyright(c),2022-8, Hiview Software. All rights reserved.
 * @par History:
 * <table>
 * <tr><th>Author                        <th>Date         <th>Change Description
 * <tr><td>HiView SoC Software Team      <td>2022-08-23   <td>init
 * </table>
*/
#include <math.h>
#include "hv_comm_MemoryConfig.h"
#include "PanelConfig.h"
#include "hv_vos_Comm.h"

#include "hv_comm_Assert.h"
#include "hv_comm_Utilities.h"
#include "hv_comm_DataBase.h"
#include "hv_comm_MemParser.h"

#include "hv_drv_DpuCommon.h"
#include "hv_drv_DpuMainScaler.h"
#include "hv_drv_DpuMainMute.h"
#include "hv_cal_DpuMainScaler.h"
#include "hv_drv_PQ.h"
#include "hv_cal_DpuCprConfig.h"
#include "hv_drv_DpuSubScaler.h"

static VOID CalcMianWindowSize(VideoConfigParams* pstVideoConfigParams, USHORT16 *pusHstart, USHORT16 *pusHend, USHORT16 *pusVstart, USHORT16 *pusVend)
{
    USHORT16 usHpos = HV_COMMON_DATABASE_GET(UserData, usProEsportHPos);
    USHORT16 usVpos = HV_COMMON_DATABASE_GET(UserData, usProEsportVPos);
    USHORT16 usHsize = HV_COMMON_DATABASE_GET(UserData, usProEsportHSize);
    USHORT16 usVsize = HV_COMMON_DATABASE_GET(UserData, usProEsportVSize);
    if (usHpos < (usHsize / 2))
    {
        *pusHstart = 0;
        *pusHend = usHsize;
    }
    else if ((usHpos + (usHsize / 2))  > pstVideoConfigParams->usVideoPanelHactive)
    {
        *pusHstart = pstVideoConfigParams->usVideoPanelHactive - usHsize;
        *pusHend = pstVideoConfigParams->usVideoPanelHactive;
    }
    else
    {
        *pusHstart = usHpos - (usHsize / 2);
        *pusHend = usHpos + ceil((FLOAT32)usHsize / 2);
    }

    if (usVpos < (usVsize / 2))
    {
        
        *pusVstart = 0;
        *pusVend = usVsize;
    }
    else if ((usVpos + (usVsize / 2))  > pstVideoConfigParams->usVideoPanelVactive)
    {
        *pusVstart = pstVideoConfigParams->usVideoPanelVactive - usVsize;
        *pusVend = pstVideoConfigParams->usVideoPanelVactive;
    }
    else
    {
        *pusVstart = usVpos - (usVsize / 2);
        *pusVend = usVpos + ceil((FLOAT32)usVsize / 2);
    }
    return;
}

VOID Hv_Drv_DpuScaler_MainWindowConfig(VideoConfigParams* pstVideoConfigParams)
{
    if (HV_FALSE == HV_COMMON_DATABASE_GET(UserData, ucProEsportSwitch))
    {
        Hv_Cal_DpuScaler_DtcMainWindowHstart(0);
        Hv_Cal_DpuScaler_DtcMainWindowHend(pstVideoConfigParams->uiOutputVideoWidth - 1);
        Hv_Cal_DpuScaler_DtcMainWindowVstart(0);
        Hv_Cal_DpuScaler_DtcMainWindowVend(pstVideoConfigParams->uiOutputVideoHight - 1);
    }
    else
    {
        USHORT16 usHstart = 0;
        USHORT16 usHend = pstVideoConfigParams->uiOutputVideoWidth;
        USHORT16 usVstart = 0;
        USHORT16 usVend = pstVideoConfigParams->uiOutputVideoHight;
        CalcMianWindowSize(pstVideoConfigParams, &usHstart, &usHend, &usVstart, &usVend);
        Hv_Cal_DpuScaler_DtcMainWindowHstart(usHstart);
        Hv_Cal_DpuScaler_DtcMainWindowHend(usHend - 1);
        Hv_Cal_DpuScaler_DtcMainWindowVstart(usVstart);
        Hv_Cal_DpuScaler_DtcMainWindowVend(usVend - 1);
    }
    return;
}

static VOID CapVgsfMainC02ConfigEnable(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR_VOID(pstVideoConfigParams);
    if (ColorFormatType_YCbCr420 == pstVideoConfigParams->stColor.eClrFormat)
    {
        Hv_Cal_DpuScaler_CapVgsfMainC02ClkEn(1);
        Hv_Cal_DpuScaler_CapVgsfMainC02Enable(1);
#if (CONFIG_USER_PANEL_RESOLUTION_TYPE == PANEL_RESOLUTION_TYPE_UHD)
        Hv_Cal_DpuScaler_CapVgsfMainC02DeEnable(0);
#else
        Hv_Cal_DpuScaler_CapVgsfMainC02DeEnable(1);
#endif
    }
    else
    {
        Hv_Cal_DpuScaler_CapVgsfMainC02ClkEn(0);
        Hv_Cal_DpuScaler_CapVgsfMainC02Enable(0);
#if (CONFIG_USER_PANEL_RESOLUTION_TYPE == PANEL_RESOLUTION_TYPE_UHD)
#else
        Hv_Cal_DpuScaler_CapVgsfMainC02DeEnable(0);
#endif
    }
    return;
}

static VOID CapVgsfMainC24ConfigEnable(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR_VOID(pstVideoConfigParams);
    if (ColorFormatType_YCbCr420 == pstVideoConfigParams->stColor.eClrFormat
        || ColorFormatType_YCbCr422 == pstVideoConfigParams->stColor.eClrFormat)
    {
        Hv_Cal_DpuScaler_CapVgsfMainC24ClkEn(1);
    }
    else
    {
        Hv_Cal_DpuScaler_CapVgsfMainC24ClkEn(0);
    }
    return;
}


static VOID CapVgsfMainC42ConfigEnable(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR_VOID(pstVideoConfigParams);
    /*hdr 打开时会转化到RGB在CSC2转化为YUV444,此时只需要判决DDR中的颜色格式不是YUV444就需要开启C42*/
    if ((ColorFormatType_YCbCr422 == pstVideoConfigParams->stFrameBufferCfg.enFBColorFormat)
        || (ColorFormatType_YCbCr420 == pstVideoConfigParams->stFrameBufferCfg.enFBColorFormat))
    {
        Hv_Cal_DpuScaler_CapVgsfMainC42FuncClkEn(1);
        Hv_Cal_DpuScaler_CapVgsfMainC42On(1);
    }
    else
    {
        Hv_Cal_DpuScaler_CapVgsfMainC42FuncClkEn(0);
        Hv_Cal_DpuScaler_CapVgsfMainC42On(0);
    }
    return;
}

static VOID CapVgsfMainC20ConfigEnable(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR_VOID(pstVideoConfigParams);
    /*hdr 打开时会转化到RGB在CSC2转化为YUV444,此时只需要判决DDR中的颜色格式,是YUV420就需要开启C20*/
    if (ColorFormatType_YCbCr420 == pstVideoConfigParams->stFrameBufferCfg.enFBColorFormat)
    {
        Hv_Cal_DpuScaler_CapVgsfMainC20FuncClkEn(1);
        Hv_Cal_DpuScaler_CapVgsfMainC20Enable(1);
        /* 输入为YUV420，且进行Vflip时，需要更换CbCr顺序，否则会出现红色蓝色反转现象 */
        if ((ColorFormatType_YCbCr420 ==pstVideoConfigParams->stColor.eClrFormat)
            &&(HV_ENABLE == pstVideoConfigParams->bVflipEnable))
        {
            Hv_Cal_DpuScaler_CapVgsfMainC20CbCrPosAdjEnable(1);
        }
        else
        {
            Hv_Cal_DpuScaler_CapVgsfMainC20CbCrPosAdjEnable(0);
        }
    }
    else
    {
        Hv_Cal_DpuScaler_CapVgsfMainC20FuncClkEn(0);
        Hv_Cal_DpuScaler_CapVgsfMainC20Enable(0);
    }

    return;
}

static VOID CapVgsfMainCSC2ConfigEnable(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR_VOID(pstVideoConfigParams);
    /*6是RGB转YUV 7是YUV转RGB,过DDR使用YUV数据所以开CSC2*/
    if (Hv_Cal_DpuScaler_GetCapVgsfMainCsc1FunctionOn()
        || (ColorFormatType_RGB == pstVideoConfigParams->stColor.eClrFormat))
    {
        /*cap vgsf csc2 setting start*/
        Hv_Cal_DpuScaler_CapVgsfMainCsc2ClkEn(1);
        Hv_Cal_DpuScaler_CapVgsfMainCsc2ConvertOn(1);
        Hv_Cal_DpuScaler_CapVgsfMainCsc2ConvertMode(6);
        /*cap vgsf csc2 setting end*/
    }
    else
    {
        Hv_Cal_DpuScaler_CapVgsfMainCsc2ClkEn(0);
        Hv_Cal_DpuScaler_CapVgsfMainCsc2ConvertOn(0);
        Hv_Cal_DpuScaler_CapVgsfMainCsc2ConvertMode(0);
    }
    return;
}

Status Hv_Drv_DpuScaler_CapVgsfSettingsMain(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR(pstVideoConfigParams);

    CapVgsfMainC02ConfigEnable(pstVideoConfigParams);
    CapVgsfMainC24ConfigEnable(pstVideoConfigParams);
    Hv_Cal_DpuScaler_CapVgsfMainCsc1Config(pstVideoConfigParams);
    CapVgsfMainC42ConfigEnable(pstVideoConfigParams);
    CapVgsfMainC20ConfigEnable(pstVideoConfigParams);
    CapVgsfMainCSC2ConfigEnable(pstVideoConfigParams);

    /*1是开启scaler down，3是scaler down bypass*/
    if (HV_TRUE == pstVideoConfigParams->bHorizontalNeedScaler)
    {
        Hv_Cal_DpuScaler_CapVgsfMainCaVgMsfYhMode(1);
    }
    else
    {
        Hv_Cal_DpuScaler_CapVgsfMainCaVgMsfYhMode(3);
    }

    if (HV_TRUE == pstVideoConfigParams->bVerticalNeedScaler)
    {
        Hv_Cal_DpuScaler_CapVgsfMainCaVgMsfYvMode(1);
    }
    else
    {
        Hv_Cal_DpuScaler_CapVgsfMainCaVgMsfYvMode(3);
    }

    /*整个CPA的outsize，包含C42 C02 C20等*/
    Hv_Cal_DpuScaler_CapVgsfMainInOutSize(pstVideoConfigParams);

    FLOAT32 fTmp = 0.0f;
    /*cap vgsf main scf down setting*/
    DpucScalerParam stDpucScalerParam = {0};
    stDpucScalerParam.usHsfInize = pstVideoConfigParams->uiInputVideoWidth;
    stDpucScalerParam.usHsfOutsize = pstVideoConfigParams->uiDdrOrWtrVideoWidth;
    HV_ASSERT_TRUE(stDpucScalerParam.usHsfOutsize > 0);
    /*8192* in_size/out_size*/
    stDpucScalerParam.uiHfilbase = 8192 * stDpucScalerParam.usHsfInize / stDpucScalerParam.usHsfOutsize;
    fTmp = (8192 * (FLOAT32)stDpucScalerParam.usHsfInize / (FLOAT32)stDpucScalerParam.usHsfOutsize) + 0.5;
    stDpucScalerParam.uiHfilbase = (UINT32)fTmp;
    stDpucScalerParam.usVsfInize = pstVideoConfigParams->uiInputVideoHight;
    stDpucScalerParam.usVsfOutsize = pstVideoConfigParams->uiDdrOrWtrVideoHight;
    HV_ASSERT_TRUE(stDpucScalerParam.usVsfOutsize  > 0);
    /*8192* in_size/out_size*/
    stDpucScalerParam.uiVfilbase = (UINT32)8192 * pstVideoConfigParams->uiInputVideoHight / pstVideoConfigParams->uiDdrOrWtrVideoHight;
    fTmp = (FLOAT32)((FLOAT32)(8192 * (FLOAT32)pstVideoConfigParams->uiInputVideoHight / (FLOAT32)pstVideoConfigParams->uiDdrOrWtrVideoHight) + 0.5);
    stDpucScalerParam.uiVfilbase = (UINT32)fTmp;
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_MAIN_MONTAGE)
    if(HV_COMMON_DATABASE_GET(UserData, bMainMontageSw))
    {
        stDpucScalerParam.usHsfInize = pstVideoConfigParams->uiInputVideoWidth;
        stDpucScalerParam.usHsfOutsize = pstVideoConfigParams->uiInputVideoWidth;
        stDpucScalerParam.uiHfilbase = 8192;
        stDpucScalerParam.usVsfInize = pstVideoConfigParams->uiInputVideoHight;
        stDpucScalerParam.usVsfOutsize = pstVideoConfigParams->uiInputVideoHight;
        stDpucScalerParam.uiVfilbase = 8192;
    }
#endif
    BOOL bCprMode = HV_FALSE;
    if ((DATA_PATH_MODE_COMPRESS_COLORFORMAT_RX == pstVideoConfigParams->enDataPathMode) || (pstVideoConfigParams->enDataPathMode >= DATA_PATH_MODE_COMPRESS_COLORFORMAT_YUV444))
    {
        bCprMode = HV_TRUE;
    }
    Hv_Cal_DpuScaler_CapVgsfMainScfDown(bCprMode, &stDpucScalerParam);
    return HV_SUCCESS;
}

Status Hv_Drv_DpuScaler_DpcCapSrpMainSettings(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR(pstVideoConfigParams);
    DpuDpcCapSrpParam stDpuDpcCapSrpParam = {0};
    /*data mode 0:444 1:422 2:420*/
    if (ColorFormatType_YCbCr422 == pstVideoConfigParams->stFrameBufferCfg.enFBColorFormat)
    {
        stDpuDpcCapSrpParam.ucCaDataMode = 1;
    }
    else if (ColorFormatType_YCbCr420 == pstVideoConfigParams->stFrameBufferCfg.enFBColorFormat)
    {
        stDpuDpcCapSrpParam.ucCaDataMode = 2;
    }
    else/*YUV444 and RGB444*/
    {
        stDpuDpcCapSrpParam.ucCaDataMode = 0;
    }
    
    if (ColorDepthType_12Bit == pstVideoConfigParams->stFrameBufferCfg.enFBColorDepth)
    {
        stDpuDpcCapSrpParam.ucCaDataBitwidth = 12;
    }
    else if (ColorDepthType_10Bit == pstVideoConfigParams->stFrameBufferCfg.enFBColorDepth)
    {
        stDpuDpcCapSrpParam.ucCaDataBitwidth = 10;
    }
    else/*ColorDepthType_8Bit and ColorDepthType_6Bit*/
    {
        stDpuDpcCapSrpParam.ucCaDataBitwidth = 8;
    }

    if ((pstVideoConfigParams->stFrameBufferCfg.bUseFrameBuffer) && (HV_TRUE == pstVideoConfigParams->stFrameBufferCfg.bUseCompress))
    {
        stDpuDpcCapSrpParam.ucCaEncPackWork = 1;
    }
    else
    {
        stDpuDpcCapSrpParam.ucCaEncPackWork = 2;
    }

    if (HV_FALSE == pstVideoConfigParams->stFrameBufferCfg.bUseCompress)
    {
        stDpuDpcCapSrpParam.ucDecUnpackSel = 1;
    }
    else
    {
        stDpuDpcCapSrpParam.ucDecUnpackSel = 0;
    }

    if (ColorFormatType_YCbCr422 == pstVideoConfigParams->stFrameBufferCfg.enFBColorFormat)
    {
        stDpuDpcCapSrpParam.ucDataMode = 1;
    }
    else if (ColorFormatType_YCbCr420 == pstVideoConfigParams->stFrameBufferCfg.enFBColorFormat)
    {
        stDpuDpcCapSrpParam.ucDataMode = 2;
    }
    else/*YUV444 and RGB444*/
    {
        stDpuDpcCapSrpParam.ucDataMode = 0;
    }

    if (ColorDepthType_12Bit == pstVideoConfigParams->stFrameBufferCfg.enFBColorDepth)
    {
        stDpuDpcCapSrpParam.ucDataWidth = 3;
    }
    else if (ColorDepthType_10Bit == pstVideoConfigParams->stFrameBufferCfg.enFBColorDepth)
    {
        stDpuDpcCapSrpParam.ucDataWidth = 2;
    }
    else/*other 都按照8bit处理*/
    {
        stDpuDpcCapSrpParam.ucDataWidth = 1;
    }

    Hv_Cal_DpuScaler_DpcSrpMainSettings(&stDpuDpcCapSrpParam);
    /*Mainpath 0:ddr data; 1:framesync data*/
    if (HV_TRUE == pstVideoConfigParams->stFrameBufferCfg.bUseFrameBuffer)
    {
        Hv_Cal_DpuScaler_DpcSrpMainFrcFrameSyncSel(0);
    }
    else
    {
        Hv_Cal_DpuScaler_DpcSrpMainFrcFrameSyncSel(1);
    }
    return HV_SUCCESS;
}

Status Hv_Drv_DpuScaler_DpuVdmMainSettings(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR(pstVideoConfigParams);
    DpuVdmConfigSettings stDpuVdmConfigSettings = {0};
    /*用FRC passthrough mode才配置，否则关闭读写使能;*/
    if ((HV_TRUE == pstVideoConfigParams->stFrameBufferCfg.bUseFrameBuffer) 
        && (HV_FALSE == pstVideoConfigParams->stFrameBufferCfg.bUseCompress))
    {
        UINT32 uiWidthScf = pstVideoConfigParams->uiDdrOrWtrVideoWidth;
        UINT32 uiHeightScf = pstVideoConfigParams->uiDdrOrWtrVideoHight;
        UINT32 uiheight = uiHeightScf;
        UINT32 uiPxlBits = 0;
        UINT32 uiBusBits = 128;/*固定值*/
        UINT32 uiWdmaStartAdr  = 0; 
        UINT32 uiWdmaStartAdr1 = 0;
        UINT32 uiWdmaStartAdr2 = 0; 
        UINT32 uiWdmaStartAdr3 = 0;
        UINT32 uiRdmaStartAdr = 0; 
        UINT32 uiRdmaStartAdr1 = 0;
        UINT32 uiRdmaStartAdr2 = 0;
        /*配置VDM首先需要关闭开关，硬件要求规范*/
        Hv_Cal_DpuScaler_DpuRvdm00RdEnable(0);
        Hv_Cal_DpuScaler_DpuWvdm00WrEnable(0);  
        uiPxlBits = Hv_Drv_DpuScaler_GetPxlBits(pstVideoConfigParams->stFrameBufferCfg.enFBColorFormat, pstVideoConfigParams->stFrameBufferCfg.enFBColorDepth);
        UINT32 uiColDatNum = ROUND_DIV(uiWidthScf * uiPxlBits, uiBusBits);
        /*reg_dm_rd_col_step = reg_dm_rd_col_dat_num * iBusBits / 8*/
        UINT32 uiColStep = uiColDatNum * uiBusBits >> 3;
        HV_LOG_DEBUG(VIDEO,"Main channel uiWidthScf=%u,uiHeightScf=%u,uiPxlBits=%u,uiColDatNum=%u,uiColStep=%u",uiWidthScf,uiHeightScf,uiPxlBits,uiColDatNum,uiColStep);

        /*不开启PXP则总frc start开始分配，如果开启了PIP/PBP时分配主通道FRC内存从 FRC start + sub通道已占用的最大内存处分配，
        这样配置辅通道的时候不必考虑主通道是否配置了，配置主通道时又固定按照辅通道最大计算，解耦处理*/
#ifdef CONFIG_USER_DOUBLE_CHANNEL_ON
        //TODO:优化预留sub ddr size
        UINT32 uiFrcStartAddress = Hv_Board_Memory_FRCStart() + pstVideoConfigParams->uiSubChannelUsedMemory;
#else
        UINT32 uiFrcStartAddress = Hv_Board_Memory_FRCStart();
#endif

        if(pstVideoConfigParams->bInterlacedMode)
        {
            uiWdmaStartAdr  = 0 * uiColStep * uiheight + uiFrcStartAddress;
            uiWdmaStartAdr1 = 1 * uiColStep * uiheight + uiFrcStartAddress;
            uiWdmaStartAdr2 = 2 * uiColStep * uiheight + uiFrcStartAddress;
            uiWdmaStartAdr3 = 3 * uiColStep * uiheight + uiFrcStartAddress;
            HV_LOG_DEBUG(VIDEO,"uiWdmaStartAdr=0x%x,uiWdmaStartAdr1=0x%x,uiWdmaStartAdr2=0x%x,uiWdmaStartAdr3=0x%x",uiWdmaStartAdr,uiWdmaStartAdr1,uiWdmaStartAdr2,uiWdmaStartAdr3);
            if((uiWdmaStartAdr2 >= (0x80000000 + HV_MEMORY_CONFIG_DDR_SIZE)) || (uiWdmaStartAdr3 >= (0x80000000 + HV_MEMORY_CONFIG_DDR_SIZE)))
            {
                return HV_FAILURE;
            }
            if (pstVideoConfigParams->bVflipEnable)
            {
                uiRdmaStartAdr = uiWdmaStartAdr1 - uiColStep;
                uiRdmaStartAdr1 = uiWdmaStartAdr2 - uiColStep;
                uiRdmaStartAdr2 =  uiWdmaStartAdr3 - uiColStep;
                stDpuVdmConfigSettings.ucDmRdColStepDir = 1;
                stDpuVdmConfigSettings.ucDmRdLineStepDir = 1;
            }
            else
            {
                uiRdmaStartAdr = uiWdmaStartAdr; 
                uiRdmaStartAdr1 = uiWdmaStartAdr1;
                uiRdmaStartAdr2 = uiWdmaStartAdr2;
                stDpuVdmConfigSettings.ucDmRdColStepDir = 0;
                stDpuVdmConfigSettings.ucDmRdLineStepDir = 0;
            }
            stDpuVdmConfigSettings.uiDmRdStartAdr2 = uiRdmaStartAdr2;
            stDpuVdmConfigSettings.uiDmWrStartAdr2 = uiWdmaStartAdr2;
        }
        else
        {
            uiWdmaStartAdr  = 0 * uiColStep * uiheight + uiFrcStartAddress;
            uiWdmaStartAdr1 = 1 * uiColStep * uiheight + uiFrcStartAddress;
            uiWdmaStartAdr2 = 2 * uiColStep * uiheight + uiFrcStartAddress;
            HV_LOG_DEBUG(VIDEO,"uiWdmaStartAdr=0x%x,uiWdmaStartAdr1=0x%x,uiWdmaStartAdr2=0x%x",uiWdmaStartAdr,uiWdmaStartAdr1,uiWdmaStartAdr2);
            if((uiWdmaStartAdr1 >= (0x80000000 + HV_MEMORY_CONFIG_DDR_SIZE)) || (uiWdmaStartAdr2 >= (0x80000000 + HV_MEMORY_CONFIG_DDR_SIZE)))
            {
                return HV_FAILURE;
            }
            if (pstVideoConfigParams->bVflipEnable)
            {
                uiRdmaStartAdr = uiWdmaStartAdr1 - uiColStep;
                uiRdmaStartAdr1 = uiWdmaStartAdr2 - uiColStep;
                stDpuVdmConfigSettings.ucDmRdColStepDir = 1;
                stDpuVdmConfigSettings.ucDmRdLineStepDir = 1;
            }
            else
            {
                uiRdmaStartAdr = uiWdmaStartAdr; 
                uiRdmaStartAdr1 = uiWdmaStartAdr1;
                stDpuVdmConfigSettings.ucDmRdColStepDir = 0;
                stDpuVdmConfigSettings.ucDmRdLineStepDir = 0;
            }
        }
        
        /*RDMA Line Mode Setting*/
        stDpuVdmConfigSettings.uiDmColStep = uiColStep;
        stDpuVdmConfigSettings.usDmRdColDatNum = uiColDatNum;
        stDpuVdmConfigSettings.usDmTotalColNum = uiheight;
        /*burstLen - 1(建议值31，15，7)*/
        UINT32 uiBurstLen = 31;
        stDpuVdmConfigSettings.ucDmBurstLen = uiBurstLen;

        /*=int(reg_dm_rd_col_dat_num/(reg_dm_rd_burst_len+1)*/
        UINT32 uiBurstNum = uiColDatNum / (uiBurstLen + 1);
        stDpuVdmConfigSettings.uiDmBurstNum = uiBurstNum;

        /*=reg_dm_rd_col_dat_num-reg_dm_rd_burst_num*(reg_dm_rd_burst_len+1)*/
        UINT32 uiBurstRmd = uiColDatNum - uiBurstNum * (uiBurstLen + 1);
        stDpuVdmConfigSettings.ucDmBurstRmd = uiBurstRmd;

        UINT32 uiLineStep = uiColStep;
        stDpuVdmConfigSettings.uiDmLineStep = uiLineStep;
        stDpuVdmConfigSettings.usDmTotalLineNum = 1;
        stDpuVdmConfigSettings.ucDmOutstanding = 2;
        stDpuVdmConfigSettings.uiDmRdStartAdr = uiRdmaStartAdr;
        stDpuVdmConfigSettings.uiDmRdStartAdr0 = uiRdmaStartAdr;
        stDpuVdmConfigSettings.uiDmRdStartAdr1 = uiRdmaStartAdr1;

        /*WDMA Line Mode Setting 3840*1080 case设置31不行*/
        stDpuVdmConfigSettings.uiDmWrStartAdr = uiWdmaStartAdr;
        stDpuVdmConfigSettings.uiDmWrStartAdr0 = uiWdmaStartAdr;
        stDpuVdmConfigSettings.uiDmWrStartAdr1 = uiWdmaStartAdr1;
        Hv_Cal_DpuScaler_DpuVdmMainConfig(&stDpuVdmConfigSettings);
        /*配置VDM完成打开开关，硬件要求规范*/
        Hv_Cal_DpuScaler_DpuRvdm00RdEnable(1);
        Hv_Cal_DpuScaler_DpuWvdm00WrEnable(1);
    }
    else /*framesync时要关闭DM的读写*/
    {
        Hv_Cal_DpuScaler_DpuRvdm00RdEnable(0);
        Hv_Cal_DpuScaler_DpuWvdm00WrEnable(0);
    }
    return HV_SUCCESS;
}

Status Hv_Drv_DpuScaler_SrpTopMainSettings(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR(pstVideoConfigParams);
    /*hlifp*/
    Hv_Cal_DpuScaler_SrpTopMainScHflip(pstVideoConfigParams->bHflipEnable);

    /*main*/
    HV_ASSERT_VALID_PTR(pstVideoConfigParams);
    UINT32 uiWidthScf  = pstVideoConfigParams->uiDdrOrWtrVideoWidth;
    UINT32 uiHeightScf = pstVideoConfigParams->uiDdrOrWtrVideoHight;
    UINT32 uiwidthOut  = pstVideoConfigParams->uiOutputVideoWidth;
    UINT32 uiHeightOut = pstVideoConfigParams->uiOutputVideoHight;
    
    Hv_Cal_DpuScaler_SrpTopMainSrPassthrough(0);
    Hv_Cal_DpuScaler_SrpTopMainSrSpatWith(uiWidthScf);

    Hv_Cal_DpuScaler_SrpTopMainC02Config(pstVideoConfigParams);
    Hv_Cal_DpuScaler_SrpTopMainSrC24Config(pstVideoConfigParams);
    Hv_Cal_DpuScaler_SrpTopMainConfig(pstVideoConfigParams);



    return HV_SUCCESS;
}

Status Hv_Drv_DpuScaler_SubLdgTopMainSettings(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR(pstVideoConfigParams);
    /*main*/
    Hv_Cal_DpuScaler_SubLdgTopMainCscEn(1);
    Hv_Cal_DpuScaler_SubLdgTopMainBlendEn(1);
    Hv_Cal_DpuScaler_SubLdgTopMainBorderEn(0);
    return HV_SUCCESS;
}

Status Hv_Drv_DpuScaler_SetMainPathInterlaceMode(const VideoConfigParams* pstVideoConfigParams, UCHAR8 ucFieldPolar)
{
    HV_ASSERT_VALID_PTR(pstVideoConfigParams);
    UINT32 uiHeightScf = pstVideoConfigParams->uiDdrOrWtrVideoHight;
    UINT32 uiHeightOut = pstVideoConfigParams->uiOutputVideoHight;
    UINT32 uiVfilbase = 8192 *  uiHeightScf / uiHeightOut;
    if (HV_TRUE == pstVideoConfigParams->bInterlacedMode)
    {
        Hv_Cal_DpuScaler_ScMainPvosPs0(0x1000000-uiVfilbase);
        Hv_Cal_DpuScaler_ScMainPvosPs1(uiVfilbase);

        Hv_Cal_DpuScaler_ScMainFeildSel(0);//keep this always '0' in Interlace mode
        Hv_Cal_DpuScaler_ScMainFeildPolar(0);
    }
    else
    {
        Hv_Cal_DpuScaler_ScMainPvosPs0(0);//will config this later 
        Hv_Cal_DpuScaler_ScMainPvosPs1(0);//will config this later

        Hv_Cal_DpuScaler_ScMainFeildSel(0);
        Hv_Cal_DpuScaler_ScMainFeildPolar(0);
    }
    return HV_SUCCESS;
}


Status Hv_Drv_DpuScaler_MainHdrSetPatternEn(UINT32 uiEn)
{
    if(uiEn)
    {
        Hv_Cal_DpuScaler_CapVgsfMainHdrGmiPatternEn(1);
        Hv_Cal_DpuScaler_CapVgsfMainHdrPattern(0x2000, 0, 0x2000);
    }
    else
    {
        Hv_Cal_DpuScaler_CapVgsfMainHdrGmiPatternEn(0);
    }
    return HV_SUCCESS;
}

Status Hv_Drv_DpuScaler_MainHdrEnable(UINT32 uiValue)
{
    if(uiValue == 0)
    {
        Hv_Cal_DpuScaler_CapVgsfMainHdrPassthrough(1);
    }
    else
    {
        Hv_Cal_DpuScaler_CapVgsfMainHdrPassthrough(0);
    }
    return HV_SUCCESS;
}

Status Hv_Drv_DpuScaler_MainHdrDmEnable(UINT32 uiValue)
{
    if(uiValue == 0)
    {
        Hv_Cal_DpuScaler_CapVgsfMainHdrLutGmiEn(0);
    }
    else
    {
        Hv_Cal_DpuScaler_CapVgsfMainHdrLutGmiEn(1);
    }
    return HV_SUCCESS;
}



Status Hv_Drv_DpuScaler_MainHdrProcessSOP(const HDRParam* pstHdrParam)
{
    HV_ASSERT_VALID_PTR(pstHdrParam);

     //check if source HDR is On
    if((HDR10_TYPE == pstHdrParam->xType)||(HLG_TYPE == pstHdrParam->xType))
    {
        UINT32 uiAllZero = 1;
        Hv_Drv_PQ_SetHdrMode(CHANNEL_TYPE_MAIN, pstHdrParam->xType, (HDRParam*)pstHdrParam);
        HV_LOG_INFO(PQ, "MaxLum %d MinLum %d usMaxCntn %d usMaxFrmAvg %d", pstHdrParam->usMaxLum, pstHdrParam->usMinLum, pstHdrParam->usMaxCntn, pstHdrParam->usMaxFrmAvg);
        //Hv_Drv_PQ_HdrEotfProc(pstHdrParam->usMaxLum, pstHdrParam->usMinLum);
        if(HDR10_TYPE == pstHdrParam->xType)
        {
            Hv_Drv_PQ_HdrAuthProcess(pstHdrParam);
        }
    }
    else//HDR to SDR
    {
        Hv_Drv_PQ_SetHdrMode(CHANNEL_TYPE_MAIN, SDR_TYPE, (HDRParam*)pstHdrParam);
    }

    return HV_SUCCESS;
}

Status Hv_Drv_DpuScaler_CapVgsfMainHdrSetting(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR(pstVideoConfigParams);
    /* main cap sync setting before HDR dma enable */
    HV_W32_FIELD(DISP_TOP_DPU_CA_SYNC_00_04, reg_00_ca_htotal, pstVideoConfigParams->uiInputVideoHtotal);
    HV_W32_FIELD(DISP_TOP_DPU_CA_SYNC_00_04, reg_00_ca_vact, pstVideoConfigParams->uiInputVideoHight);

    
    if(0 != pstVideoConfigParams->bHdrSwitch)
    {
        Hv_Drv_DpuScaler_MainHdrProcessSOP(&pstVideoConfigParams->stHdrParam);
    }
    else
    {
        Hv_Drv_DpuScaler_MainHdrEnable(0);
    }

    return HV_SUCCESS;
}


VOID Hv_Drv_DpuScaler_MainSetPicPos(const VideoConfigParams* pstVideoConfigParams, USHORT16 usHoffset, USHORT16 usVoffset)
{
    UINT32 uiHfill = 0;
    UINT32 uiVfill = 0;
    uiHfill = HV_R32(DISP_TOP_REG_VIDEO_CUBIC_SCALER_V2_00_2C);
    uiVfill = HV_R32(DISP_TOP_REG_VIDEO_CUBIC_SCALER_V2_00_30);
    INT32 iTmp = 0;
    iTmp = pstVideoConfigParams->uiDdrOrWtrVideoHight * 8192  - (uiVfill*pstVideoConfigParams->uiOutputVideoHight);
    iTmp = iTmp/2 - (usHoffset * 8192);
    if(iTmp < 0)
    {
        Hv_Cal_DpuScaler_ScMainPvosPs0(iTmp + (1<<24)  + (uiVfill/2));
    }
    else
    {
        Hv_Cal_DpuScaler_ScMainPvosPs0(iTmp + (uiVfill/2));
    }
    
    iTmp = (uiHfill *(pstVideoConfigParams->uiDdrOrWtrVideoWidth - pstVideoConfigParams->uiOutputVideoWidth)/2 - usVoffset*8192);
    if(iTmp < 0)
    {
        Hv_Cal_DpuScaler_ScMainPhosPsA0(iTmp + (1<<25) + uiHfill/2);
    }
    else
    {
        Hv_Cal_DpuScaler_ScMainPhosPsA0(iTmp + uiHfill/2);

    }
    return;
}

//all the "<<13" in the following mean *8192
static UINT32 s_uiValidHeight = 0;
Status Hv_Drv_DpuScaler_MainRatio(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR(pstVideoConfigParams);
    INT32 uiPosa = 0;
    INT32 uiPosc = 0;

    UINT32 uiVtmp = 0;
    UINT32 uiHtmp = 0;

    UINT32 uiOutW = pstVideoConfigParams->uiOutputVideoWidth;
    UINT32 uiOutH = pstVideoConfigParams->uiOutputVideoHight;

    UCHAR8 ucVfill = 0;
    UINT32 uiRealHeight = 0;

    UINT32 uiValid = 0;
    RatioParam atRatioArr[OUTPUTRATIO_MAX] = 
    {
        {pstVideoConfigParams->usVideoPanelHactive, pstVideoConfigParams->usVideoPanelVactive}, {16,9}, {4,3}, {21,9}, {5,3}, {1,1}, {16,10}, {5,4},{pstVideoConfigParams->usVideoPanelHactive, pstVideoConfigParams->usVideoPanelVactive},
        /* OUTPUTRATIO_17INCH_4TO3 */
        {4,3}, {4,3}, {5,4}, {16,10}, {16,9}, {16,10}, {16,9}, {16,9}, {16,9},  
    };

    VideoRatio enRatio = pstVideoConfigParams->enAspectRatio;
    USHORT16 usPanelInchWidth  = HV_COMMON_DATABASE_GET_STARRAY(UserData, astPanelInch, enRatio, usPanelInchW);
    USHORT16 usPanelInchHeight = HV_COMMON_DATABASE_GET_STARRAY(UserData, astPanelInch, enRatio, usPanelInchH);
    USHORT16 usPanelRealOutWidth  = 0;
    USHORT16 usPanelRealOutHeight = 0;
    /* 如果需要显示其他尺寸的图像大小，需要计算对应尺寸的范围 */
    if ((enRatio >= OUTPUTRATIO_17INCH_4TO3) && (usPanelInchWidth!= 0) && (usPanelInchHeight != 0)
        && (pstVideoConfigParams->usPanelInchWidth != 0) && (pstVideoConfigParams->usPanelInchHeight != 0))
    {
        //use float to keep accuracy
        usPanelRealOutWidth = (USHORT16)((FLOAT32)pstVideoConfigParams->uiOutputVideoWidth * (FLOAT32)usPanelInchWidth / (FLOAT32)pstVideoConfigParams->usPanelInchWidth  + 0.5);
        usPanelRealOutHeight = (USHORT16)((FLOAT32)pstVideoConfigParams->uiOutputVideoHight * (FLOAT32)usPanelInchHeight / (FLOAT32)pstVideoConfigParams->usPanelInchHeight + 0.5);
        usPanelRealOutWidth = usPanelRealOutWidth + usPanelRealOutWidth%2;//must be even
        usPanelRealOutHeight = usPanelRealOutHeight + usPanelRealOutHeight%2;//must be even
        /* 根据输出图像尺寸更新比例值，保证输出尺寸图像满屏 */
        atRatioArr[enRatio].usRatioW = usPanelRealOutWidth;
        atRatioArr[enRatio].usRatioH = usPanelRealOutHeight;
    }
    else
    {
        usPanelRealOutWidth = pstVideoConfigParams->uiOutputVideoWidth;
        usPanelRealOutHeight = pstVideoConfigParams->uiOutputVideoHight;
    }

    HV_LOG_DEBUG(VIDEO, "==Hv_Drv_DpuScalerSclRatio %u %u %u %u %u %u %u    %d %d===", pstVideoConfigParams->enAspectRatio, pstVideoConfigParams->uiInputVideoWidth, pstVideoConfigParams->uiInputVideoHight,pstVideoConfigParams->uiDdrOrWtrVideoWidth, pstVideoConfigParams->uiDdrOrWtrVideoHight, uiOutW, uiOutH, usPanelRealOutWidth, usPanelRealOutHeight);
    if(pstVideoConfigParams->enAspectRatio == OUTPUTRATIO_AUTO)
    {

        /*in case w h ratio changed when scale down*/
        if(pstVideoConfigParams->enPxpMode == PXP_MODE_PBP_ENABLE)
        {
            atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioW = pstVideoConfigParams->uiDdrOrWtrVideoWidth;
            atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioH = pstVideoConfigParams->uiDdrOrWtrVideoHight;
        }
        else
        {
            atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioW = pstVideoConfigParams->uiInputVideoWidth;
            atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioH = pstVideoConfigParams->uiInputVideoHight;
        }
    }

    USHORT16 usMainPipH = 0;
    #ifdef CONFIG_USER_DOUBLE_CHANNEL_ON
    usMainPipH = Hv_Drv_DpuScaler_GetPbpMainWindowHSize(pstVideoConfigParams->usVideoPanelHactive);
    #else
    usMainPipH = pstVideoConfigParams->usVideoPanelHactive >> 1;
    #endif
    if((pstVideoConfigParams->enAspectRatio != OUTPUTRATIO_1TO1))
    {
        if(pstVideoConfigParams->enPxpMode == PXP_MODE_CLOSE)
        {
            if(usPanelRealOutHeight * atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioW > atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioH * usPanelRealOutWidth)
            {
                uiOutW = usPanelRealOutWidth;
            }
            else
            {
                uiOutW = (UINT32)((FLOAT32)usPanelRealOutHeight * (FLOAT32)atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioW / (FLOAT32)atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioH + 0.5);
            }
        }
        else if(pstVideoConfigParams->enPxpMode == PXP_MODE_PBP_ENABLE)
        {
            //FILL H 
            if(pstVideoConfigParams->uiInputVideoWidth* pstVideoConfigParams->usVideoPanelVactive > pstVideoConfigParams->uiInputVideoHight* usMainPipH)
            {
                uiOutW =  usMainPipH;
                HV_LOG_DEBUG(PQ, "fill h %d", uiOutW);
            }
            else//fill v
            {
                uiOutW = pstVideoConfigParams->uiInputVideoWidth*(pstVideoConfigParams->usVideoPanelVactive)/pstVideoConfigParams->uiInputVideoHight;
                HV_LOG_DEBUG(PQ, "fill v %d", uiOutW);
            };
            ///*make sure we reach maxmun H size*/
            //if(uiOutW < (pstVideoConfigParams->usVideoPanelHactive >> 1))
            //{
            //    uiOutW = pstVideoConfigParams->usVideoPanelHactive >> 1;
            //}
        }
        else//PIP
        {

            Hv_Cal_DpuScaler_ScMainPvosPs0(0);
            Hv_Cal_DpuScaler_ScMainPvosPs1(0);
            Hv_Cal_DpuScaler_ScMainPhosPsA0(0);
            Hv_Cal_DpuScaler_ScMainPhosPsB0(0);
            return HV_SUCCESS;
        }
        //get real Height if interlace
        if(pstVideoConfigParams->bInterlacedMode)
        {
            uiRealHeight  = pstVideoConfigParams->uiDdrOrWtrVideoHight << 1;
        }
        else
        {
            uiRealHeight  = pstVideoConfigParams->uiDdrOrWtrVideoHight;
        }

        if(pstVideoConfigParams->enAspectRatio != OUTPUTRATIO_AUTO)
        {
            if(pstVideoConfigParams->enPxpMode == PXP_MODE_PBP_ENABLE)
            {
                atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioW = atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioW/2;
            }
            if(usPanelRealOutHeight * atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioW > atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioH * usPanelRealOutWidth)
            {
                uiOutH = usPanelRealOutWidth * atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioH / atRatioArr[pstVideoConfigParams->enAspectRatio].usRatioW;
            }
            else
            {
                uiOutH = usPanelRealOutHeight;
            }
            HV_LOG_DEBUG(PQ, "1uiOut WH %d %d", uiOutH, uiOutW);
        }
        else/*Auto mode, calculate out H*/
        {
            HV_LOG_DEBUG(PQ, "ELSE %d %d %d %d", pstVideoConfigParams->uiInputVideoWidth, pstVideoConfigParams->uiOutputVideoHight, uiRealHeight, pstVideoConfigParams->uiOutputVideoWidth);
            if(pstVideoConfigParams->uiInputVideoWidth * pstVideoConfigParams->uiOutputVideoHight >= uiRealHeight *pstVideoConfigParams->uiOutputVideoWidth)
            {
                if(pstVideoConfigParams->bInterlacedMode)
                {
                    uiOutH = (FLOAT32)((FLOAT32)uiOutW * uiRealHeight / pstVideoConfigParams->uiDdrOrWtrVideoWidth + 0.5);
                }
                else
                {
                    uiOutH = uiOutW * pstVideoConfigParams->uiInputVideoHight/pstVideoConfigParams->uiInputVideoWidth;
                }
                if((pstVideoConfigParams->enPxpMode == PXP_MODE_PBP_ENABLE)&& (uiOutH > pstVideoConfigParams->usVideoPanelVactive))
                {
                    uiOutH = (pstVideoConfigParams->usVideoPanelVactive*pstVideoConfigParams->usVideoPanelHactive/2)/uiOutW;
                }
                HV_LOG_DEBUG(PQ, "uiH %d", uiOutH);
            }
            else
            {
                uiOutH = pstVideoConfigParams->uiOutputVideoHight;
                uiOutW = (UINT32)((FLOAT32)pstVideoConfigParams->uiOutputVideoHight * (FLOAT32)pstVideoConfigParams->uiDdrOrWtrVideoWidth / (FLOAT32)uiRealHeight + 0.5);
                HV_LOG_DEBUG(PQ, "uiwH %d %d", uiOutW, uiOutH);
            }
            HV_LOG_DEBUG(PQ, "2uiOut WH %d %d", uiOutH, uiOutW);
        }

        HV_LOG_DEBUG(PQ, "====uiOut WH %d %d", uiOutH, uiOutW);
        //changed output Timing
        FLOAT32 fHtmp = ((FLOAT32)pstVideoConfigParams->uiDdrOrWtrVideoWidth *8192) / (FLOAT32)uiOutW;
        //uiHtmp = (pstVideoConfigParams->uiDdrOrWtrVideoWidth << 13) / uiOutW;
        //uiPosa = (uiHtmp * (pstVideoConfigParams->uiOutputVideoWidth - uiOutW)) >> 1;
        fHtmp = (fHtmp * (pstVideoConfigParams->uiOutputVideoWidth - uiOutW))/2;
        uiPosa = (UINT32)(fHtmp+0.5);
        uiPosa = (1 << 25) - uiPosa;

        Hv_Cal_DpuScaler_ScMainPhosPsB0(0);
        uiHtmp = (UINT32)((FLOAT32)(((FLOAT32)pstVideoConfigParams->uiDdrOrWtrVideoWidth *8192) / (FLOAT32)uiOutW) + 0.5);
        Hv_Cal_DpuScaler_SrpTopMainScHfilbase(uiHtmp);
        Hv_Cal_DpuScaler_ScMainPhosPsA0(uiPosa + uiHtmp/2);//plus hfill/2
        if(pstVideoConfigParams->bInterlacedMode)
        {
            fHtmp = (FLOAT32)((FLOAT32)uiRealHeight *8192 / (FLOAT32)uiOutH)/2 + 0.5;
            Hv_Cal_DpuScaler_SrpTopMainScVfilbase((UINT32)fHtmp);
            uiVtmp = ((uiRealHeight *8192) / uiOutH)/2; 
        }
        else
        {
            fHtmp = (FLOAT32)(uiRealHeight*8192 / uiOutH);
            Hv_Cal_DpuScaler_SrpTopMainScVfilbase((UINT32)fHtmp);
            uiVtmp = ((uiRealHeight *8192) / uiOutH); 
        }
        if(ucVfill == 1)
        {
            s_uiValidHeight = pstVideoConfigParams->usVideoPanelVactive;
            //HV_LOG_ERROR(PQ, "1VFILL 1  -- %d %d", pstVideoConfigParams->usVideoPanelVactive,  pstVideoConfigParams->uiOutputVideoHight);
        }
        else
        {
            s_uiValidHeight = uiOutH;
            //s_uiValidHeight = pstVideoConfigParams->usVideoPanelVactive*uiHtmp/(UINT32)fHtmp;
            //HV_LOG_ERROR(PQ, "1VFILL 0  -- %d %d %d", uiHtmp, (UINT32)fHtmp, 10*pstVideoConfigParams->usVideoPanelVactive*uiHtmp/(UINT32)fHtmp);

        }
       
        //              do not use realheight here
        INT32 iPosc = ((INT32)(pstVideoConfigParams->uiDdrOrWtrVideoHight<< 13) - (INT32)(uiVtmp * pstVideoConfigParams->uiOutputVideoHight))/2;
        if(iPosc < 0)
        {
            iPosc += 1 << 24;
        }
        Hv_Cal_DpuScaler_ScMainPvosPs0(iPosc + (UINT32)(fHtmp/2));//plus vfill/2
        Hv_Cal_DpuScaler_ScMainPvosPs1(0);
        if(pstVideoConfigParams->bInterlacedMode)
        {
            Hv_Cal_DpuScaler_ScMainPvosPs1(iPosc+(UINT32)(fHtmp/2)- 4096);//ps1 = ps0 - 4096
        }

    }
    else//1to1 mode
    {
        if(pstVideoConfigParams->bInterlacedMode)
        {
            uiRealHeight  = pstVideoConfigParams->uiInputVideoHight << 1;
        }
        else
        {
            uiRealHeight  = pstVideoConfigParams->uiInputVideoHight;
        }

        s_uiValidHeight = pstVideoConfigParams->uiInputVideoHight;
        {
            if(pstVideoConfigParams->bInterlacedMode)
            {
                uiValid = uiOutH * pstVideoConfigParams->uiDdrOrWtrVideoWidth / (pstVideoConfigParams->uiDdrOrWtrVideoHight << 1);
                uiHtmp =  pstVideoConfigParams->uiDdrOrWtrVideoWidth << 13 / uiValid;
                uiVtmp =  pstVideoConfigParams->uiDdrOrWtrVideoHight << 14 / uiOutH;

                uiHtmp = 8192;//keep h the same
                uiVtmp = 4096;//v scale up 2times
            }
            else
            {
                uiValid = uiOutH * pstVideoConfigParams->uiDdrOrWtrVideoWidth / pstVideoConfigParams->uiDdrOrWtrVideoHight;
                uiHtmp = pstVideoConfigParams->uiDdrOrWtrVideoWidth << 13 / uiValid;
                uiVtmp = pstVideoConfigParams->uiDdrOrWtrVideoHight << 13 / uiOutH;

                uiHtmp = 8192;
                uiVtmp = 8192;
            }

            uiOutW = pstVideoConfigParams->uiOutputVideoWidth;
            uiOutH = pstVideoConfigParams->uiOutputVideoHight;
            uiValid = pstVideoConfigParams->uiDdrOrWtrVideoWidth;////uiOutH*rs.w/rs.h;


            uiPosa = (uiHtmp * (uiValid-uiOutW)) >> 1;
            if(uiPosa < 0)
                uiPosa = (1 << 25) + uiPosa;


            INT32 iTmp = 0;
            //use uiDdrOrWtrVideoHight for Interlace, beacuse this is the real input timing
            iTmp = (pstVideoConfigParams->uiDdrOrWtrVideoHight <<13) - (uiVtmp * uiOutH);
            INT32 iPosc = iTmp/2;
            if(iPosc < 0)
                iPosc += 1<<24;

            Hv_Cal_DpuScaler_ScMainPvosPs0(iPosc + uiVtmp/2);
            if(pstVideoConfigParams->bInterlacedMode)
            {
                Hv_Cal_DpuScaler_SrpTopMainScVfilbase(uiVtmp);
                Hv_Cal_DpuScaler_ScMainPvosPs1(iPosc + uiVtmp/2 - 4096);//ps1 = ps0 - 4096
            }
            else
            {
                Hv_Cal_DpuScaler_SrpTopMainScVfilbase(uiVtmp);
            }

            Hv_Cal_DpuScaler_ScMainPhosPsA0(uiPosa + 4096);
            Hv_Cal_DpuScaler_SrpTopMainScHfilbase(8192);
        }

        Hv_Cal_DpuScaler_ScMainOrfCrlev(0x80);
        Hv_Cal_DpuScaler_ScMainOrfCblev(0x80);
        Hv_Cal_DpuScaler_ScMainOrfYlev(0);

    }
    
    HV_R32_DECL_VAR();
    if(HV_R32_FIELD(DISP_TOP_REG_VIDEO_CUBIC_SCALER_V2_00_00, reg_00_sc_chmode) == 0)
    {
        HV_W32_FIELD(DISP_TOP_REG_VIDEO_CUBIC_SCALER_V2_00_1C, reg_00_sc_phos_in, 8);
        if(HV_R32_FIELD(DISP_TOP_REG_VIDEO_CUBIC_SCALER_V2_00_24, reg_00_sc_phos_ps_A) == 0)
        {
            HV_W32_FIELD(DISP_TOP_REG_VIDEO_CUBIC_SCALER_V2_00_24, reg_00_sc_phos_ps_A, HV_R32_FIELD(DISP_TOP_REG_VIDEO_CUBIC_SCALER_V2_00_2C, reg_00_sc_hfilbase)/2);
        }
    }

    
    if(HV_R32_FIELD(DISP_TOP_REG_VIDEO_CUBIC_SCALER_V2_00_00, reg_00_sc_cvmode) == 0)
    {
        HV_W32_FIELD(DISP_TOP_REG_VIDEO_CUBIC_SCALER_V2_00_1C, reg_00_sc_pvos_in, 8);
        if(HV_R32_FIELD(DISP_TOP_REG_VIDEO_CUBIC_SCALER_V2_00_20, reg_00_sc_pvos_ps0) == 0)
        {
            HV_W32_FIELD(DISP_TOP_REG_VIDEO_CUBIC_SCALER_V2_00_20, reg_00_sc_pvos_ps0, HV_R32_FIELD(DISP_TOP_REG_VIDEO_CUBIC_SCALER_V2_00_30, reg_00_sc_vfilbase)/2);
        }
    }

    USHORT16 usFillBase = 0;
    //for Edge of Scaling down
    //if(HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_6C, reg_00_ca_vg_msf_yhmode) == 1)
    {
        usFillBase = HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_80, reg_00_ca_vg_hfilbase);
        HV_W32_FIELD(DISP_TOP_DPU_CA_VGSF_00_70, reg_00_ca_vg_phos_ps, usFillBase/2 - 4096);
    }
    //if(HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_6C, reg_00_ca_vg_msf_yvmode) == 1)
    {
        usFillBase = HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_84, reg_00_ca_vg_vfilbase);
        HV_W32_FIELD(DISP_TOP_DPU_CA_VGSF_00_74, reg_00_ca_vg_pvos_ps, usFillBase/2 - 4096);
    }

 
    return HV_SUCCESS;
}

VOID Hv_Drv_DpuScaler_DpuDataPath_Reset(BOOL bEn)
{
    Hv_Cal_DpuScaler_DpuRvdm00RdEnable(bEn);
    Hv_Cal_DpuScaler_DpuWvdm00WrEnable(bEn);
    if(Hv_Cal_DpuScaler_GetCapVgsfMainCsc1FunctionOn())
    {
        Hv_Cal_DpuScaler_CapVgsfMainCs1FuncClkEn(0);
        Hv_Cal_DpuScaler_CapVgsfMainCs1En(0);
    }
    return;
}

Status Hv_Drv_DpuScaler_LDGMainInsertBlackCableDetect()
{
    return Hv_Cal_DpuScaler_LDGMainInsertBlackCableDetect();
}

static VOID DtcFreeRunTimingConfig(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR_VOID(pstVideoConfigParams);
    Hv_Cal_DpuScaler_DtcTxVdeDummyNum(0);

    return;
}

static Status SubLdgTopCommonSettings(const VideoConfigParams* pstVideoConfigParams)
{
    Hv_Cal_DpuScaler_SubLdgTopByPass(0);
    Hv_Cal_DpuScaler_SubLdgTopBorderMode(0);
    return HV_SUCCESS;
}

VOID Hv_Drv_DpuMainScaler_CapVgsfMainCapInSize(UINT32 uiRxInHact, UINT32 uiRxInVact)
{
    Hv_Cal_DpuScaler_CapVgsfMainCapInSize(uiRxInHact, uiRxInVact);
    return;
}

typedef enum _FrcDdrReadRatio
{
    FRC_DDR_READ_FAST =0,
    FRC_DDR_WRITE_FAST,
    FRC_DDR_SAME_SPEED,
} FrcDdrReadRatio;

static FrcDdrReadRatio GetWriteReadRatio(const VideoConfigParams* pstVideoConfigParams, FLOAT32* pfRatio)
{
    FLOAT32 fRatio = ((FLOAT32)pstVideoConfigParams->uiInputFrameRate / pstVideoConfigParams->uiOutputFrameRate) * 
    ((FLOAT32) s_uiValidHeight * pstVideoConfigParams->uiInputVideoHight / (pstVideoConfigParams->uiOutputVideoHight * pstVideoConfigParams->uiDdrOrWtrVideoHight));

    *pfRatio = fRatio;

    if (fRatio < 1)         //读快写慢
    {
        return FRC_DDR_READ_FAST;
    }
    else if (fRatio > 1)    //写快读慢
    {
        return FRC_DDR_WRITE_FAST;
    }
    else                    //读写同速
    {
        return FRC_DDR_SAME_SPEED;
    }
}

static FLOAT32 GetYRatio (FLOAT32 fXratio)
{
    FLOAT32 fYratio = fXratio;
    if (fYratio > 0.5f)
    {
        fYratio = 0.5f;
    }
    return fYratio;
}

static VOID CalcFrcReadWriteDoneTh(const VideoConfigParams* pstVideoConfigParams, USHORT16* pusFrcRdDoneTh, USHORT16* pusFrcWrDoneTh)
{
    FLOAT32 fXRatio = 0.5f;
    FLOAT32 fYRatio = 0.5f;
    FrcDdrReadRatio enFrcDdrReadRatio = GetWriteReadRatio(pstVideoConfigParams, &fXRatio);
    HV_R32_DECL_VAR();
    USHORT16 usRxVTopCutLine = 0;
    USHORT16 usTxVactValid = s_uiValidHeight;                                                           //valid指屏上不带擦黑部分的有效图像部分
    USHORT16 usRxVactValid = pstVideoConfigParams->uiInputVideoHight;                                   //cut之后进入scaler down的真实图像大小
    USHORT16 usTxTopBlackInertLine = (pstVideoConfigParams->uiOutputVideoHight - usTxVactValid) >> 1;   //屏幕上部插黑行数

    if (HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_08, reg_00_ca_in_mask_on))
    {
        usRxVTopCutLine = HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_8C, reg_00_ca_out_cut_vstart);
        usRxVactValid = HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_10, reg_00_ca_in_cut_vend) -  HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_0C, reg_00_ca_in_cut_vstart);
    }
    switch (enFrcDdrReadRatio)
    {
        case FRC_DDR_READ_FAST:     //读快写慢
        {
            fYRatio = GetYRatio(fXRatio);
            *pusFrcRdDoneTh = fYRatio * usTxVactValid + usTxTopBlackInertLine;
            *pusFrcWrDoneTh = (1 - fYRatio) * usRxVactValid + usRxVTopCutLine;
            break;
        }
        case FRC_DDR_WRITE_FAST:   //写快读慢
        {
            fXRatio = 1.0f / fXRatio;
            fYRatio = GetYRatio(fXRatio);
            *pusFrcRdDoneTh = (1 - fYRatio) * usTxVactValid + usTxTopBlackInertLine;
            *pusFrcWrDoneTh = fYRatio * usRxVactValid + usRxVTopCutLine;
            break;
        }
        case FRC_DDR_SAME_SPEED:    //读写同速
        {
            *pusFrcRdDoneTh = usTxVactValid / 2 + usTxTopBlackInertLine;
            *pusFrcWrDoneTh = usRxVactValid / 2 + usRxVTopCutLine;
            break;
        }
        default:                    //保守用法
        {
            *pusFrcRdDoneTh = pstVideoConfigParams->uiOutputVideoHight - 1;
            *pusFrcWrDoneTh = pstVideoConfigParams->uiInputVideoHight - 1;
            break;
        }
    }
}

static VOID DtcBufReadFast(const VideoConfigParams* pstVideoConfigParams, USHORT16* pusFrcRdDoneTh, USHORT16* pusFrcWrDoneTh)
{
    USHORT16 usTxVactValid = pstVideoConfigParams->uiDdrOrWtrVideoHight;                                //valid指不带擦黑部分的有效图像部分
    USHORT16 usTxTopBlackInertLine = (pstVideoConfigParams->uiOutputVideoHight - usTxVactValid) >> 1;   //屏幕上部插黑行数
    FLOAT32 fRateRatio = (FLOAT32)pstVideoConfigParams->uiInputFrameRate / pstVideoConfigParams->uiOutputFrameRate;
    if (fRateRatio > 0.5f)
    {
        fRateRatio = 0.5f;
    }

    *pusFrcRdDoneTh = (USHORT16)(fRateRatio * usTxVactValid + usTxTopBlackInertLine);
    *pusFrcWrDoneTh = (USHORT16)((1 - (fRateRatio * (1 - (usTxTopBlackInertLine / pstVideoConfigParams->uiOutputVideoHight)))) * pstVideoConfigParams->uiInputVideoHight);
    return;
}

Status Hv_Drv_DpuMainScaler_Config(const VideoConfigParams* pstVideoConfigParams)
{
    HV_ASSERT_VALID_PTR(pstVideoConfigParams);
    DpuDtcTopTimingParam stDpuDtcTopTimingParam = {0};
    if (DIS_TIMING_MODE_FRAMESYNC == pstVideoConfigParams->enTimingMode)
    {
        HV_LOG_DEBUG(VIDEO, "ip Clock=%d,d_clock=%d, dest d_clk=%d\n", pstVideoConfigParams->uiRxDpllFreq,pstVideoConfigParams->uiDisplayPllFreq, pstVideoConfigParams->uiDestDisplayPllFreq);
        if (pstVideoConfigParams->uiRxDpllFreq < pstVideoConfigParams->uiDestDisplayPllFreq)
        {
            /*当两个clk非常接近，且理论计算值与实际值偏差稍大一点时会有误判的情况。因为动态调时钟，所以拿理论值uiDestDisplayPllFreq来判断，更接近实际值。*/
            stDpuDtcTopTimingParam.ucDtcRbufClkSel = 1;

        }
        else
        {
            stDpuDtcTopTimingParam.ucDtcRbufClkSel = 0;
        }
    }
    Hv_Cal_DpuScaler_DtcClkDelayConfig(pstVideoConfigParams, &stDpuDtcTopTimingParam);
    stDpuDtcTopTimingParam.usRxVact = pstVideoConfigParams->uiInputVideoHight;
    stDpuDtcTopTimingParam.ucFrcMainBufNum = pstVideoConfigParams->bInterlacedMode ? 3 : 2;

    CalcFrcReadWriteDoneTh(pstVideoConfigParams, &stDpuDtcTopTimingParam.usFrcMainRdDoneTh, &stDpuDtcTopTimingParam.usFrcMainWrDoneTh);

    #if 0
    if (pstVideoConfigParams->uiInputFrameRate == pstVideoConfigParams->uiOutputFrameRate)
    {
        stDpuDtcTopTimingParam.usFrcMainWrDoneTh = pstVideoConfigParams->uiInputVideoHight >> 1;
        stDpuDtcTopTimingParam.usFrcMainRdDoneTh = pstVideoConfigParams->uiOutputVideoHight >> 1;
    }
    else if (pstVideoConfigParams->uiInputFrameRate > pstVideoConfigParams->uiOutputFrameRate)
    {
        stDpuDtcTopTimingParam.usFrcMainWrDoneTh = pstVideoConfigParams->uiInputVideoHight / 3;
        stDpuDtcTopTimingParam.usFrcMainRdDoneTh = (pstVideoConfigParams->uiOutputVideoHight << 1) / 3;
    }
    else
    {
        // stDpuDtcTopTimingParam.usFrcMainWrDoneTh = (pstVideoConfigParams->uiInputVideoHight << 1) / 3;
        // stDpuDtcTopTimingParam.usFrcMainRdDoneTh = pstVideoConfigParams->uiOutputVideoHight / 3;
        DtcBufReadFast(pstVideoConfigParams, &stDpuDtcTopTimingParam.usFrcMainRdDoneTh, &stDpuDtcTopTimingParam.usFrcMainWrDoneTh);
    }
    if ((PXP_MODE_PBP_ENABLE == pstVideoConfigParams->enPxpMode) && (pstVideoConfigParams->uiInputFrameRate < pstVideoConfigParams->uiOutputFrameRate))
    {
        UINT32 uiVbottomLine = (pstVideoConfigParams->uiOutputVideoHight - pstVideoConfigParams->uiDdrOrWtrVideoHight) / 2;
        stDpuDtcTopTimingParam.usFrcMainWrDoneTh = (USHORT16)((1.0f - (FLOAT32)pstVideoConfigParams->uiInputFrameRate / pstVideoConfigParams->uiOutputFrameRate * \
        (1.0f - (FLOAT32)uiVbottomLine / pstVideoConfigParams->uiOutputVideoHight)) * (FLOAT32)pstVideoConfigParams->uiInputVideoHight);
    }
    #endif
    /*V flip时，写的终点是读的起点*/
    if (HV_TRUE == pstVideoConfigParams->bVflipEnable)
    {
        stDpuDtcTopTimingParam.usFrcMainWrDoneTh = pstVideoConfigParams->uiInputVideoHight - 1;
        stDpuDtcTopTimingParam.usFrcMainRdDoneTh = pstVideoConfigParams->uiOutputVideoHight - 1;
    }

    Hv_Cal_DpuScaler_DtcTopTimingParam(&stDpuDtcTopTimingParam);

    Hv_Drv_DpuScaler_CapVgsfMainHdrSetting(pstVideoConfigParams);
#ifdef HV_SCALER_DEBUG_VERSION
    Hv_Cal_DpuScaler_CapVgsfPattSettingsMain(pstVideoConfigParams);
#endif
    HV_ASSERT_SUCCESS(Hv_Drv_DpuScaler_CapVgsfSettingsMain(pstVideoConfigParams));
    HV_ASSERT_SUCCESS(Hv_Drv_DpuScaler_DpcCapSrpMainSettings(pstVideoConfigParams));
    if (HV_TRUE == pstVideoConfigParams->stFrameBufferCfg.bUseCompress)/*FRC&CPR*/
    {
        Hv_Cal_DpuScaler_DpuRvdm00RdEnable(0);
        Hv_Cal_DpuScaler_DpuWvdm00WrEnable(0);
        Hv_Cal_DpuScaler_MainCprEncodeConfig(pstVideoConfigParams);
        Hv_Cal_DpuScaler_MainCprDecodeConfig(pstVideoConfigParams);
        HV_ASSERT_SUCCESS(Hv_Cal_DpuScaler_MainCprEncodeVdmConfig(pstVideoConfigParams));
        HV_ASSERT_SUCCESS(Hv_Cal_DpuScaler_MainCprDecodeVdmConfig(pstVideoConfigParams));
    }
    else/*framesync & frc passthrough*/
    {
        Hv_Cal_DpuScaler_DpuEncVdmWriteEnable(0);
#if (HV_CONFIG_OFF == HV_PROJECT_CONFIG_CHANNEL_SEAMLESS_SWITCH)
        Hv_Cal_DpuScaler_DpuDecVdmReadEnable(0);
#endif
        HV_ASSERT_SUCCESS(Hv_Drv_DpuScaler_DpuVdmMainSettings(pstVideoConfigParams));
    }

    HV_ASSERT_SUCCESS(Hv_Drv_DpuScaler_SrpTopMainSettings(pstVideoConfigParams));
    HV_ASSERT_SUCCESS(Hv_Drv_DpuScaler_SubLdgTopMainSettings(pstVideoConfigParams));
    HV_ASSERT_SUCCESS(Hv_Drv_DpuScaler_SetMainPathInterlaceMode(pstVideoConfigParams, 0));
    Hv_Drv_DpuScaler_MainRatio(pstVideoConfigParams);
    HV_ASSERT_SUCCESS(SubLdgTopCommonSettings(pstVideoConfigParams));
    Hv_Drv_DpuScaler_SetMainCapInCutParam(pstVideoConfigParams);
#if (0 != HV_PROJECT_CONFIG_DPU_OVER_SCAN_SIDE_SIZE)
    if (1 == HV_COMMON_DATABASE_GET(UserData, bOverScan))
    {
        Hv_Cal_DpuScaler_CapVgsfMainInCutEn(HV_TRUE);
        Hv_Cal_DpuScaler_DtcDelayMode(1);
    }
    else
    {
        Hv_Cal_DpuScaler_CapVgsfMainInCutEn(HV_FALSE);
        Hv_Cal_DpuScaler_DtcDelayMode(0);
    }
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_MAIN_MONTAGE)
    Hv_Drv_DpuScaler_SetMainCapOutCutParam();
#endif 
    Hv_Drv_PQ_ReconfigPQSize(pstVideoConfigParams);
    return HV_SUCCESS;
}

VOID Hv_Drv_DpuScaler_InitFrcModeMain(BOOL bStart)
{
    Hv_Cal_DpuScaler_SetMainFrcIndexStart(bStart);
    return;
}

VOID Hv_Drv_DpuScaler_SetMainCapInCutParam(const VideoConfigParams* pstVideoConfigParams)
{
    if (0 != HV_PROJECT_CONFIG_DPU_OVER_SCAN_SIDE_SIZE)
    {
        DpuCapCutParam stDpuCapCutParam = {0};
        stDpuCapCutParam.usCutHstart = (pstVideoConfigParams->usInputCutHsize >> 1) + 1;
        stDpuCapCutParam.usCutHend = pstVideoConfigParams->uiInputVideoWidth + (pstVideoConfigParams->usInputCutHsize >> 1);
        stDpuCapCutParam.usCutVstart = (pstVideoConfigParams->usInputCutVsize >> 1) + 1;
        stDpuCapCutParam.usCutVend = pstVideoConfigParams->uiInputVideoHight + (pstVideoConfigParams->usInputCutVsize >> 1);
        Hv_Cal_DpuScaler_SetCapVgsfMainInCutParam(&stDpuCapCutParam);
        //Hv_Cal_DpuScaler_CapVgsfMainInCutEn(1);
    }
    return;
}

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_MAIN_MONTAGE)
Status Hv_Drv_DpuScaler_SetMainCapOutCutParam(VOID)
{
    BOOL     bSw       = HV_COMMON_DATABASE_GET(UserData, bMainMontageSw);
    USHORT16 usCutHsta = HV_COMMON_DATABASE_GET(UserData, usMontageInHsta);
    USHORT16 usCutHend = HV_COMMON_DATABASE_GET(UserData, usMontageInHend);
    USHORT16 usCutVsta = HV_COMMON_DATABASE_GET(UserData, usMontageInVsta);
    USHORT16 usCutVend = HV_COMMON_DATABASE_GET(UserData, usMontageInVend);
    DpuCapCutParam stDpuCapCutParam = {0};
    HV_ASSERT_TRUE(usCutHend - usCutHsta > 0);
    HV_ASSERT_TRUE(usCutVend - usCutVsta > 0);
    stDpuCapCutParam.usCutHstart = usCutHsta + 1;
    stDpuCapCutParam.usCutHend = usCutHend;
    stDpuCapCutParam.usCutVstart = usCutVsta + 1;
    stDpuCapCutParam.usCutVend = usCutVend;
    Hv_Cal_DpuScaler_SetCapVgsfMainOutCutParam(&stDpuCapCutParam);
    Hv_Cal_DpuScaler_CapVgsfMainOutCutEn(bSw);
    return HV_SUCCESS;
}
#endif

VOID Hv_Drv_DpuScaler_PQ_Debug(VOID)
{
    HV_R32_DECL_VAR();
    UCHAR8 ucC02ClkEn = 0;
    UCHAR8 ucC02En = 0;
    UCHAR8 ucC24Clk = 0;
    UCHAR8 ucCs1Clk = 0;
    UCHAR8 ucCs1En = 0;
    UCHAR8 ucHdrEn = 0;
    UCHAR8 ucCs2Clk = 0;
    UCHAR8 ucCs2En = 0;

    ucC02ClkEn = HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_24, reg_00_ca_vg_c02_func_clk_en);
    ucC02En = HV_R32_FIELD(DISP_TOP_C420_422_00_00, reg_00_420_422_en);
    ucC24Clk = HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_28, reg_00_ca_vg_yuv422to444_func_clk_en); 
    ucCs1Clk = HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_30, reg_00_ca_vg_cs1_convert_func_clk_en);
    ucCs1En = HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_30, reg_00_ca_vg_csc1_en);
    ucHdrEn = HV_R32_FIELD(DISP_TOP_LDG_HDR_REG_00_00, reg_00_ct_ldg_hdr_passthrough);
    ucCs2Clk = HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_50, reg_00_ca_vg_cs2_convert_func_clk_en); 
    ucCs2En = HV_R32_FIELD(DISP_TOP_DPU_CA_VGSF_00_50, reg_00_ca_vg_cs2_convert_on);



    HV_LOG_INFO(PQ, "c02(%u - %u) - c24(%u ) - cs1(%u - %u) hdr(%u) cs2(%u- %u)", ucC02ClkEn, ucC02En, ucC24Clk, ucCs1Clk, ucCs1En, ucHdrEn, ucCs2Clk, ucCs2En);

    return;
}

VOID Hv_Drv_DpuScaler_SetLineInt(UCHAR8 ucIndex, USHORT16 usLine)
{
    Hv_Cal_DpuScaler_SetLineInt(ucIndex, usLine);
    return;
}

VOID Hv_Drv_DpuScaler_SetLineIntEn(UINT32 uiEn)
{
    Hv_Cal_DpuScaler_SetLineIntEn(uiEn);
    return;
}

VOID Hv_Drv_DpuScaler_SetDpuIntEn(UCHAR8 ucEn)
{
    Hv_Cal_DpuScaler_SetDpuInt(ucEn);
    return;
}

BOOL Hv_Drv_DpuScaler_IsDtcVtotalInPanlSpec(USHORT16 usVtotalMax, USHORT16 usVtotalMin)
{
    USHORT16 usDtcVtotal = Hv_Cal_DpuScaler_GetDtcVtotal();
    if (usDtcVtotal >= usVtotalMin && usDtcVtotal <= usVtotalMax)
    {
        return HV_TRUE;
    }
    else
    {
        return HV_FALSE;
    }
}
