/**
 * @file hv_drv_DpuPQ.c
 * @brief dpu PQ 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 "hv_drv_PQ.h"
#include "hv_drv_Mprt.h"
#include "hv_cal_PQ.h"
#include "hv_comm_Utilities.h"
#include "hv_chip_Debug.h"
#include "hv_drv_DpuCommon.h"
#include "HV_PAGE_HT7315_GAMMA.h"

static UCHAR8 ucHdrEn[2] = {1,1};
static USHORT16 usContrastValue[2] = {1,1};
static USHORT16 usBlackLevelValue[2] = {1,1};
static BrightnessOsdSet s_BrightnessOsdConfig;

static UCHAR8 s_ucDrvFullLdcMacro = 0;

VOID Hv_Drv_PQSetMacroConfig(UCHAR8 ucFullLdc, UCHAR8 uc2DPixelGain)
{
    s_ucDrvFullLdcMacro = ucFullLdc;
    Hv_Cal_PQ_LDC_SetMacroConfig(ucFullLdc, uc2DPixelGain);
    return;
}

VOID Hv_Drv_SetBrightnessConfigValue(const BrightnessOsdSet *pstBrightnessConfigValue)
{
    HV_MEMCPY(&s_BrightnessOsdConfig, pstBrightnessConfigValue, sizeof(s_BrightnessOsdConfig));

    return;
}

VOID Hv_Drv_PQPathBypass(BOOL bEn)
{
    Hv_Cal_PQPathBypass(bEn);
    return;
}
    
VOID Hv_Drv_DpuPQ_CommonRegInit(const UINT32 *puiBaseRegAddr, UINT32 uiLen)
{
    Hv_Common_BinConfigInit(puiBaseRegAddr, uiLen);
    /* osd pq init */
    HV_W32_FIELD(DISP_TOP_SUB_OSD_TOP_BC, reg_en_no_latch, 0);
    HV_W32_FIELD(DISP_TOP_SUB_OSD_TOP_BC, reg_en, 1);
    HV_W32_FIELD(DISP_TOP_SUB_OSD_TOP_A8, reg_en_osd_mtx_through, 1);

    return;
}

VOID SaveAddrToDummy(UINT32 uiAddr, UINT32 uiValue)
{
    HV_W32(uiAddr, uiValue & 0x7fffffff);
    return;
}

VOID Hv_Drv_DpuPQ_ConfigInit(VOID)
{
    Hv_Cal_DpuPQ_ConfigInit();
    return;
}

//////////////////////////////////////////////////////////////////////////////
VOID Hv_Drv_PQ_CMEnable(UCHAR8 ucCMEn)
{
    Hv_Cal_PQ_CMEnable(ucCMEn);
    return;
}

VOID Hv_Drv_PQ_CscInit(const UINT32 *puiCscAddr, UINT32 uiLen)
{
    SaveAddrToDummy(SW_DUMMY_PQTOOL_CSC_BIN, (UINT32)puiCscAddr);
    Hv_Common_BinConfigInit(puiCscAddr, uiLen);

    return;
}

VOID Hv_Drv_PQ_CMInit(const UINT32 *puiCmAddr, UINT32 uiLen)
{
    Hv_Common_BinConfigInit(puiCmAddr, uiLen);

    return;
}

VOID Hv_Drv_PQ_CMLutInit(const UINT32 *puiCmLutAddr, UINT32 *puiCmLutAddr2)
{
    Hv_Cal_PQ_CMLutInit((UCHAR8*)puiCmLutAddr, (UCHAR8*)puiCmLutAddr2);
    return;
}

VOID Hv_Drv_PQ_CMSetHue(UCHAR8 ucColor, UCHAR8 ucHue)
{
    Hv_Cal_PQ_CMSetHue(ucColor, ucHue);
    return;
}

VOID Hv_Drv_PQ_CMSetSat(UCHAR8 ucColor, UCHAR8 ucSat)
{
    Hv_Cal_PQ_CMSetSat(ucColor, ucSat);
    return;
}

VOID Hv_Drv_PQ_CMSetLum(UCHAR8 ucColor, UCHAR8 ucLum)
{
    Hv_Cal_PQ_CMSetLum(ucColor, ucLum);
    return;
}
///////////////////////////////////////////////////////////////////////////////////

VOID Hv_Drv_PQ_GammaLutInit(const UINT32 *puiGammalut)
{
    Hv_Cal_PQ_GammaLutInit((UINT32*)puiGammalut);
    return;
}

VOID Hv_Drv_PQ_OsdGammaLutInit(const UINT32 *puiOsdGmiAddr, const UINT32 *puiOsdGmdAddr)
{
    Hv_Cal_PQ_OsdGammaLutInit((UINT32*)puiOsdGmiAddr, (UINT32*)puiOsdGmdAddr);
    return;
}

VOID Hv_Drv_PQ_GammaInit(const UINT32 *puiGammabin, UINT32 uiLen)
{
    Hv_Common_BinConfigInit((UINT32*)puiGammabin, uiLen);

    Hv_Cal_PQ_GammaEnable(HV_ENABLE);

    return;
}

VOID Hv_Drv_PQ_SetGammaIndex(UCHAR8 uiIndex)
{
    Hv_Cal_PQ_SetGammaIndex(uiIndex);
    return;
}

VOID Hv_Drv_PQ_SetOsdGammaIndex(UCHAR8 ucIndex)
{
    Hv_Cal_PQ_SetOsdGammaIndex(ucIndex);
    return;
}

VOID Hv_Drv_PQ_SharpnessInit(const UINT32 *puiSharpnessbin, UINT32 uiLen, const UINT32 *puiSharpnessParam)
{
    Hv_Common_BinConfigInit(puiSharpnessbin, uiLen);

    return Hv_Cal_PQ_SharpnessInit((UCHAR8*)puiSharpnessParam);
}

VOID Hv_Drv_PQ_SetSharpness(UCHAR8 ucSharpness)
{
    return Hv_Cal_PQ_SetSharpness(ucSharpness);
}

VOID Hv_Drv_PQ_SharpnessEnable(UCHAR8 ucSharpnessEn)
{
    Hv_Cal_PQ_SharpnessEnable(ucSharpnessEn);
    return;
}


VOID Hv_Drv_PQ_GcInit(const UINT32 *puiGcAddr, UINT32 uiLen)
{
    Hv_Common_BinConfigInit(puiGcAddr, uiLen);
    Hv_Cal_PQ_GCEnable(HV_ENABLE);

    return;
}

VOID Hv_Drv_PQ_GcLutInit(const UINT32 *puiGcLutAddr, UINT32 *puiGcLutAddr1)
{
    SaveAddrToDummy(SW_DUMMY_PQTOOL_GC_LUT, (UINT32)puiGcLutAddr1);

    Hv_Cal_PQ_GCLutInit((UCHAR8*)puiGcLutAddr, (UCHAR8*)puiGcLutAddr1);
    return;
}
VOID Hv_Drv_PQ_GcModeSwitch(UCHAR8 ucGcMode, UCHAR8 ucCurBlkSta)
{
    Hv_Cal_PQ_GCModeSwitch(ucGcMode,ucCurBlkSta);
    return;
}


VOID Hv_Drv_PQ_GCEnable(UCHAR8 ucGCEn)
{
    Hv_Cal_PQ_GCEnable(ucGCEn);
    return;
}

VOID Hv_Drv_PQ_GCSetDarkStaDir(UCHAR8 ucDir)
{
    Hv_Cal_PQ_GCSetDarkStaDir(ucDir);
    return;
}

VOID Hv_Drv_PQ_LdcLutInit(const UINT32 *puiLdcLutAddr, UINT32 *puiBlAddr)
{
    Hv_Cal_PQ_LDC_Init((UCHAR8*)puiLdcLutAddr, (UCHAR8*)puiBlAddr);
    SaveAddrToDummy(SW_DUMMY_PQTOOL_LDC_LUT, (UINT32)puiLdcLutAddr);

    return;
}

VOID Hv_Drv_PQ_LdcInit(const UINT32 *puiLdcAddr, UINT32 uiLen)
{
    Hv_Common_BinConfigInit(puiLdcAddr, uiLen);

    return;
}

VOID Hv_Drv_PQ_LdcPwmBlend(UINT32 uiPwmValue)
{
    Hv_Cal_PQ_LDC_Spi_PWM_Blending(uiPwmValue);

    return;
}

VOID Hv_Drv_PQ_LdcSetModeLutAddr(const USHORT16 *pusLdcModeLutBaseAddr)
{
    Hv_Cal_PQ_LDC_SetModeLutAddr((UCHAR8*)pusLdcModeLutBaseAddr);
    return;
}

VOID Hv_Drv_PQ_LdcSetMode(UCHAR8 ucLdcModeIndex, USHORT16 usMaxWeightVal)
{
    Hv_Cal_PQ_LDC_SetMode(ucLdcModeIndex, usMaxWeightVal);

    return;
}

USHORT16 Hv_Drv_PQ_LdcCalcPWM()
{
    UCHAR8 ucPwm = Hv_Cal_PQ_LDC_CalcPWM();
    ucPwm = (ucPwm * 100) / 255;
    USHORT16 usBrightness  = 0;

    if(ucPwm <= s_BrightnessOsdConfig.BrightOsdMidl)
    {
        usBrightness = LINEAR_MAPPING_VALUE(ucPwm, s_BrightnessOsdConfig.BrightOsdStart, s_BrightnessOsdConfig.BrightOsdMidl, s_BrightnessOsdConfig.BrightDrvforOsdStart, s_BrightnessOsdConfig.BrightDrvforOsdMidl);
    }
    else
    {
        usBrightness = LINEAR_MAPPING_VALUE(ucPwm, s_BrightnessOsdConfig.BrightOsdMidl, s_BrightnessOsdConfig.BrightOsdEnd, s_BrightnessOsdConfig.BrightDrvforOsdMidl, s_BrightnessOsdConfig.BrightDrvforOsdEnd);
    }

    return usBrightness;
}

UINT32 Hv_Drv_PQ_LDCGetGlobalAvgBright(VOID)
{
    return Hv_Cal_PQ_LDC_GetGlobalAvgBright();
}

UINT32 Hv_Drv_PQ_LDCGetGlobalMaxBright(VOID)
{
    return Hv_Cal_PQ_LDC_GetGlobalMaxBright();
}

VOID Hv_Drv_PQ_SetLdBypass(UCHAR8 ucLdBypass)
{
    return;
}

VOID Hv_Drv_PQ_SetMaxBl(UCHAR8 ucMaxBl)
{
    return;
}

UINT32 Hv_Drv_PQ_GetLdimBlBufAddr(UCHAR8 ucBlBufId)
{
    return Hv_Cal_PQ_GetLdimBlBufAddr(ucBlBufId);
}

UINT32 Hv_Drv_PQ_GetKspiRdmaAddr(VOID)
{
    UINT32 uiKspiRdmaAddr = 0;
    uiKspiRdmaAddr = Hv_Cal_PQ_GetKspiRdmaAddr();

    return uiKspiRdmaAddr;
}

VOID Hv_Drv_PQ_SetKspiDemoMode(UCHAR8 ucDemoMode)
{
    Hv_Cal_PQ_SetKspiDemoMode(ucDemoMode);
    return;
}

VOID Hv_Drv_PQ_SetKspiDemoData(USHORT16 usDemoData)
{
    Hv_Cal_PQ_SetKspiDemoData(usDemoData);
    return;
}

VOID Hv_Drv_PQ_SetKspiDataLen(USHORT16 usDataLen)
{
    Hv_Cal_PQ_SetKspiDataLen(usDataLen);
    return;
}

VOID Hv_Drv_PQ_SetKspiHeader(UCHAR8 ucCh, UCHAR8 ucHeaderNum, USHORT16 *pusHeadrData)
{
    Hv_Cal_PQ_SetKspiHeader(ucCh, ucHeaderNum, pusHeadrData);
    return;
}

VOID Hv_Drv_PQ_SetKspiTail(UCHAR8 ucCh, UCHAR8 ucTailNum, USHORT16 *pusTailData)
{
    Hv_Cal_PQ_SetKspiTail(ucCh, ucTailNum, pusTailData);
    return;
}

VOID Hv_Drv_PQ_KspiHardCrcEn(UCHAR8 ucHardCrcEn)
{
    Hv_Cal_PQ_KspiHardCrcEn(ucHardCrcEn);
    return;
}

VOID Hv_Drv_PQ_KspiEn(UCHAR8 ucKspiEn)
{
    Hv_Cal_PQ_KspiEn(ucKspiEn);
    return;
}

VOID Hv_Drv_PQ_KspiSwModeEn(UCHAR8 ucSwModeEn)
{
    Hv_Cal_PQ_KspiSwModeEn(ucSwModeEn);
    return;
}

VOID Hv_Drv_PQ_HdrInit(const UINT32 *puiHdrAddr1, UCHAR8 ucHdrIdx)
{
    Hv_Cal_PQ_HDRLutInit((CHAR8*)puiHdrAddr1, ucHdrIdx);

    return;
}

VOID Hv_Drv_PQ_HDREnableFlag(UCHAR8 ucCh, UCHAR8 ucHDREn)
{
    if(ucCh < 2)
    {
        ucHdrEn[ucCh] = ucHDREn;
    }
    return;

}


UCHAR8 Hv_Drv_PQ_GetHDREnable(UCHAR8 ucCh)
{
    if(ucCh < 2)
    {
        return ucHdrEn[ucCh];
    }
    else
    {
        return 0;
    }
    
}

VOID Hv_Drv_PQ_HDREnable(UCHAR8 ucCh, UCHAR8 ucHDREn)
{
    if(ucCh < 2)
    {
        ucHdrEn[ucCh] = ucHDREn;
        Hv_Cal_PQ_HDREnable(ucHDREn, ucCh);
    }
    return;
}

VOID Hv_Drv_PQ_SetHdrMode(UCHAR8 ucCh, UCHAR8 ucHdrModel, HDRParam* pstHdrParam) 
{
    Hv_Cal_PQ_HdrSetType(ucHdrModel, pstHdrParam, ucCh);
    
    return;
}


VOID Hv_Drv_PQ_GetBlkAvg(USHORT16 usPstX, USHORT16 usPstY, UCHAR8 *puiRed, UCHAR8 *puiGreen, UCHAR8 *puiBlue)
{
    return;
}

//========================WCG==============================//

VOID Hv_Drv_PQ_WcgInit(const UINT32 *puiWcgAddr, UINT32 uiLen)
{
    Hv_Common_BinConfigInit(puiWcgAddr, uiLen);

    return;
}


VOID Hv_Drv_PQ_WcgLutInit(const UINT32 *puiGmiAddr, const UINT32 *puiRgbAddr, const UINT32 *puiGmdAddr)
{
    SaveAddrToDummy(SW_DUMMY_PQTOOL_WCG_LUT, (UINT32)puiRgbAddr);

    return Hv_Cal_PQ_WCGLUTInit((UINT32*)puiGmiAddr, (UINT32*)puiRgbAddr, (UINT32*)puiGmdAddr);
}


VOID Hv_Drv_PQ_SetGamutFac(GamutSet *stGamut)
{
    Hv_Cal_PQ_SetGamutFac(stGamut);
    Hv_Cal_PQ_SetOsdGamutFac(stGamut);

    return;
}

VOID Hv_Drv_PQ_SetGamutNative()
{
    Hv_Cal_PQ_SetGamutNative();
    Hv_Cal_PQ_SetOsdGamutNative();

    return;
}

VOID Hv_Drv_PQ_SetOsdGamutNative()
{
    Hv_Cal_PQ_SetOsdGamutNative();

    return;
}

VOID Hv_Drv_PQ_SetGamut(const UINT32 *puiGamutAddr, UCHAR8 ucGamut)
{
    HV_LOG_DEBUG(VIDEO,"Hv_Drv_PQ_SetGamut %x %u", puiGamutAddr, ucGamut);
    if(ucGamut == 3)
    {
        HV_LOG_DEBUG(VIDEO,"NATIVE");
        Hv_Cal_PQ_SetGamutNative();
        Hv_Cal_PQ_SetOsdGamutNative();
    }
    else
    {
        Hv_Cal_PQ_SetGamut((UINT32*)puiGamutAddr, ucGamut);
    }

    return;
}

VOID Hv_Drv_PQ_WcgEnable(UCHAR8 ucWcgEn)
{
    return Hv_Cal_PQ_WCGEnable(ucWcgEn);
}


VOID Hv_Drv_PQ_WCGUpdateRgbLut(VOID)
{
    Hv_Cal_PQ_WCGUpdateRgbLut();

    return;
}

VOID Hv_Drv_SetGamutEnable(VOID)
{
    Hv_Cal_PQ_SetGamutEnable();
    return;
}

VOID Hv_Drv_SetWCGLutEnable(VOID)
{
    Hv_Cal_PQ_SetWCGLutEnable();
    return;
}

VOID Hv_Drv_SetGamutParam(const GamutSet *psGamut)
{
    Hv_Cal_PQ_SetGamutParam(psGamut);
    return;
}

VOID Hv_Drv_PQ_SetGamutOffset(const GamutOffset *pstOffset)
{
    Hv_Cal_PQ_SetGamutOffset(pstOffset);
    return;
}

VOID Hv_Drv_LoadWCGLUT(const UINT32 *puiRgbAddr)
{
    UINT32 uiWcgRgbLutAddr = 0;

    uiWcgRgbLutAddr = ((UINT32)puiRgbAddr & 0x7FFFFFFF);
    HV_W32_FIELD(DISP_TOP_DPU_VDM_TBL_RD_03_60, reg_03_dm_tbl_start_adr3, uiWcgRgbLutAddr);
    /* enable dma of WCG when load lut */
    Hv_Drv_PQ_WCGUpdateRgbLut();

    return;
} 

//========================CSC MTX==============================//
static UINT32 *s_puiMainCscConfig = NULL;
static UINT32 *s_puiSubCscConfig = NULL;

VOID Hv_Drv_PQ_CscConfigAddr(const UINT32 *puiMainCscHdb, const UINT32 *puiSubCscHdb)
{
    s_puiMainCscConfig = (UINT32*)puiMainCscHdb;
    s_puiSubCscConfig = (UINT32*)puiSubCscHdb;
    SaveAddrToDummy(SW_DUMMY_PQTOOL_CSC_MAINHDB, (UINT32)puiMainCscHdb);
    if (puiSubCscHdb != NULL)
    {
        SaveAddrToDummy(SW_DUMMY_PQTOOL_CSC_SUBHDB, (UINT32)puiSubCscHdb);
    }
    return;
}

VOID Hv_Drv_PQ_SetBrightRange(UCHAR8 ucCh, UCHAR8 ucRange)
{
    Hv_Cal_PQ_SetBrightRange((UCHAR8*)s_puiMainCscConfig, (UCHAR8*)s_puiSubCscConfig, ucCh, ucRange);
    return;
}

VOID Hv_Drv_PQ_SetColorSpace(UCHAR8 ucCh, UCHAR8 ucColorSpace)
{
    Hv_Cal_PQ_SetColorSpace((UCHAR8*)s_puiMainCscConfig, (UCHAR8*)s_puiSubCscConfig, ucCh, ucColorSpace);
    return;
}

VOID Hv_Drv_PQ_SetContrast(UCHAR8 ucCh, UINT32 uiContrast)
{
    usContrastValue[ucCh] = uiContrast;
    Hv_Cal_PQ_SetContrast(ucCh, uiContrast);
    return;
}

VOID Hv_Drv_PQ_SetHue(UCHAR8 ucCh, UCHAR8 ucHue)
{
    Hv_Cal_PQ_SetHue(ucCh, ucHue);
    return;
}

VOID Hv_Drv_PQ_SetRGBGain(UCHAR8 ucCh, USHORT16 usRed, USHORT16 usGreen, USHORT16 usBlue)
{
    Hv_Cal_PQ_SetRGBGain(ucCh, usRed, usGreen, usBlue);
    return;
}

VOID Hv_Drv_PQ_SetRGBOffset(UCHAR8 ucCh, USHORT16 usRed, USHORT16 usGreen, USHORT16 usBlue)
{
    Hv_Cal_PQ_SetRGBOffset(ucCh, usRed, usGreen, usBlue);
    return;
}

VOID Hv_Drv_PQ_SetBlackLevel(UCHAR8 ucCh, USHORT16 usBlackLevel)
{
    usBlackLevelValue[ucCh] = usBlackLevel;
    Hv_Cal_PQ_SetBlackLevel(ucCh, usBlackLevel);
    return;
}

VOID Hv_Drv_PQ_SetSaturation(UCHAR8 ucCh, UCHAR8 ucSaturation)
{
    Hv_Cal_PQ_SetSatVal(ucCh, ucSaturation);
    Hv_Cal_PQ_SetSaturation(ucCh, ucSaturation);
    return;
}

//===============================end of CSC MTX=======================
VOID Hv_Drv_PQ_DitherInit(const UINT32 *puiDitherAddr, UINT32 uiLen)
{
    Hv_Common_BinConfigInit(puiDitherAddr, uiLen);
    return;
}

VOID Hv_Drv_PQ_ScalerUpLutInit(const UINT32 *puiScalerAddr)
{
    Hv_Cal_PQ_ScalerLutInit((UINT32*)puiScalerAddr);
    return; 
}

static UCHAR8 s_ucDyBlEn = 0;
VOID Hv_Drv_PQ_DynamicBLEn(UCHAR8 ucEn)
{
    s_ucDyBlEn = ucEn;

    return;
}
UCHAR8 Hv_Drv_PQ_GetDynamicBLEn()
{
    return s_ucDyBlEn;
}

VOID Hv_Drv_DpuPQ_DmaTableEnable(BOOL bEn)
{
    Hv_Drv_DpuPQ_DmaEnable(bEn);

    return;
}

UCHAR8 Hv_Drv_DpuPQ_GetPattern()
{
    return Hv_Cal_Detect_Pattern_Main();
}

VOID Hv_Drv_DpuPQ_DmaEnable(UCHAR8 ucEn)
{
    Hv_Cal_PQ_GammaVDMEnable(ucEn);
    Hv_Cal_PQ_OsdGammaVDMEnable(ucEn);
    Hv_Cal_PQ_GCVDMEnable(ucEn);
    Hv_Cal_PQ_HDRVDMEnable(CHANNEL_TYPE_MAIN, ucEn);
    Hv_Cal_PQ_HDRVDMEnable(CHANNEL_TYPE_SUB, ucEn);
    if(HV_CONFIG_OFF == s_ucDrvFullLdcMacro)
    {
        Hv_Cal_PQ_LDCVDMEnable(ucEn);
    }
    Hv_Cal_PQ_WCGVDMEnable(ucEn);
    Hv_Cal_PQ_CMVDMEnable(ucEn);
    Hv_Cal_PQ_ScalerVDMEnable(ucEn);

    return;
}

VOID Hv_Drv_DpuPQ_DmaSetlatch(VOID)
{   
    Hv_Cal_DpuPQ_DmaSetlatch();
    return;
}

VOID Hv_Drv_DpuPQ_DmaWorkaround(VOID)
{  
    Hv_Cal_DpuPQ_DmaWorkaround();
    return;
}

VOID Hv_Drv_DpuPQ_PatternDetEn(UCHAR8 ucEn)
{
    Hv_Cal_Detect_PatternEn(ucEn);
    return;
}

VOID Hv_Drv_DpuPQ_PatternDetProc()
{
    static UINT32 uiEnterCnt1 = 0;
    static UINT32 uiEnterCnt2 = 0;
    static UINT32 uiEnterCnt3 = 0;


    UCHAR8 ucPat = 0;
    static UCHAR8 ucLast = 0;
    HV_W32_FIELD(RX_SH08_TOP_RX_CTRL_0, reg_gpio22_func_sel, 3);
    ucPat = Hv_Drv_DpuPQ_GetPattern();
    HV_W32_FIELD(RX_SH08_TOP_RX_CTRL_0, reg_gpio22_func_sel, 0);
    static USHORT16 usBrightness  = 0;

    if(ucPat == 1)
    {
        uiEnterCnt1 ++;
        if((uiEnterCnt1 == 3))
        {
            usBrightness = s_BrightnessOsdConfig.BrightforPart1;
            Hv_Drv_PQ_SetGammaIndex(4);
            uiEnterCnt2 = 0;
            uiEnterCnt3 = 0;
        }
    }
    else if(ucPat == 2)
    {
        uiEnterCnt2++;
        if(uiEnterCnt2 == 3)
        {
            Hv_Drv_PQ_SetGammaIndex(4);
            usBrightness = s_BrightnessOsdConfig.BrightforPart2;
            uiEnterCnt1 = 0;
            uiEnterCnt3 = 0;
        }
    }
    else if(ucPat == 3)
    {
        uiEnterCnt3++;
        if(uiEnterCnt3 == 3)
        {
            Hv_Drv_PQ_SetGammaIndex(4);
            usBrightness = s_BrightnessOsdConfig.BrightforPart3;
            uiEnterCnt1 = 0;
            uiEnterCnt2 = 0;
        }
    }
    else//other
    {
        if((ucLast == 2)||(ucLast == 3)||(ucLast == 1))
        {
            Hv_Drv_PQ_SetGammaIndex(1);
            usBrightness = s_BrightnessOsdConfig.BrightforHdrMax;
        }
        else
        {
        }
        uiEnterCnt1 = 0;
        uiEnterCnt2 = 0;
        uiEnterCnt3 = 0;
    }
    ucLast = ucPat;

    if (usBrightness == 0)
    {
        usBrightness = s_BrightnessOsdConfig.BrightforHdrMax;
    }
    Hv_Drv_MPRT_SetOutHighFreqPwmDuty(HV_PROJECT_CONFIG_MPRT_HIGHT_PORT, (HV_PROJECT_CONFIG_MPRT_HIGHT_FREQ_PWM_TOTAL - usBrightness), usBrightness);

    return;
}


VOID Hv_Drv_PQ_AmBilight_Init(VOID)
{
    Hv_Cal_PQ_AmBilight_Init();
    return;
}
VOID Hv_Drv_PQ_AmBilight_Enable(BOOL bEnable)
{
    Hv_Cal_PQ_AmBilight_Enable(bEnable);
    return;
}
VOID Hv_Drv_PQ_AmBilight_SetCells(UCHAR8 ucHNum, UCHAR8 ucVNum, USHORT16 *pusHSizeTbl, USHORT16 *pusVSizeTbl)
{
    Hv_Cal_PQ_AmBilight_SetCells(ucHNum, ucVNum, pusHSizeTbl, pusVSizeTbl);
    return;
}
VOID Hv_Drv_PQ_AmBilight_DMAEnable(BOOL bEnable)
{
    Hv_Cal_PQ_AmBilight_DMAEnable(bEnable);
    return;
}
VOID Hv_Drv_PQ_AmBilight_DMAWriterAddr(UINT32 *pucAddr)
{
    Hv_Cal_PQ_AmBilight_DMAWriterAddr(pucAddr);
    return;
}
VOID Hv_Drv_PQ_AmBilight_DMAWriteSetting(UCHAR8 ucHNum, UCHAR8 ucVNum, UCHAR8 ucBurstLen)
{
    Hv_Cal_PQ_AmBilight_DMAWriteSetting(ucHNum, ucVNum, ucBurstLen);
    return;
}

VOID Hv_Drv_PQ_CMFineTune_Sat(UCHAR8 ucIndex, UCHAR8 ucOffset)
{
    Hv_Cal_PQ_FineTune_Sat(ucIndex, ucOffset);
    return;
}

VOID Hv_Drv_PQ_CMFineTune_Hue(UCHAR8 ucIndex, UCHAR8 ucOffset)
{
    Hv_Cal_PQ_FineTune_Hue(ucIndex, ucOffset);
    return;
}

VOID Hv_Drv_PQ_CMFineTune_Lum(UCHAR8 ucIndex, UCHAR8 ucOffset)
{
    Hv_Cal_PQ_FineTune_Lum(ucIndex, ucOffset);
    return;
}

VOID Hv_Drv_PQ_Cm64Axis(UCHAR8 ucType, UCHAR8 ucIndex, UCHAR8 ucOffset)
{
    if(ucType == CM_SET_HUE)
    {
        Hv_Drv_PQ_CMFineTune_Hue(ucIndex, ucOffset);
    }
    else if(ucType == CM_SET_SAT)
    {
        Hv_Drv_PQ_CMFineTune_Sat(ucIndex, ucOffset);
    }
    else
    {
        Hv_Drv_PQ_CMFineTune_Lum(ucIndex, ucOffset);
    }

    return;
}


VOID Hv_Drv_PQ_CMChangeLut(UINT32 uiLutAddr)
{
    Hv_Cal_PQ_CMChangedLut(uiLutAddr);
    return;
}


VOID Hv_Drv_PQ_SetInpPattEn(UCHAR8 ucEn)
{
    Hv_Cal_DpuPQ_SetInpPattEn(ucEn);
    return;
}

VOID Hv_Drv_PQ_SetInpPatColor(USHORT16 usRed, USHORT16 usGreen, USHORT16 usBlue)
{
    Hv_Cal_DpuPQ_SetInpColor(usRed, usGreen, usBlue);
    return;
}


VOID Hv_Drv_PQ_HdrAuthProcess(const HDRParam* pstHdrParam)
{
    HV_LOG_INFO(PQ, "Maxlum  0x%x %x %x %x", pstHdrParam->usMaxLum,pstHdrParam->usMinLum, pstHdrParam->usMaxCntn, pstHdrParam->usMaxFrmAvg);
    HV_LOG_INFO(PQ, "Maxlum  %d %d %d %d", pstHdrParam->usMaxLum,pstHdrParam->usMinLum, pstHdrParam->usMaxCntn, pstHdrParam->usMaxFrmAvg);

    return;
}

VOID Hv_Drv_PQ_HdrToneMappingInit(UCHAR8 ucMapType, UINT32 uiMapLutAddr)
{
    Hv_Cal_PQ_HdrToneMappingLutInit(ucMapType, uiMapLutAddr);
    return;
}


VOID Hv_Drv_PQ_KspiSwSendData(UCHAR8 ucCh, UINT32* puiData, UINT32 uiLength, UCHAR8 ucLastChFlag)
{
    Hv_Cal_PQ_KspiSwSendData(ucCh, puiData, uiLength, ucLastChFlag);
    return;
}

VOID Hv_Drv_PQ_KspiSwSendDataInit(VOID)
{
    Hv_Cal_PQ_KspiSwSendDataInit();
}

VOID Hv_Drv_PQ_KspiSwSendDataStart(VOID)
{
    Hv_Cal_PQ_KspiSwSendDataStart();
}

VOID Hv_Drv_PQ_LDC_SetCurveY(UCHAR8 ucY0, UCHAR8 ucY1)
{
    Hv_Cal_PQ_LDC_SetCurveY(ucY0, ucY1);
}

VOID Hv_Drv_PQ_LDC_LdcEn(UCHAR8 ucEn)
{
    Hv_Cal_PQ_LDC_LdcEn(ucEn);
    return;
}

VOID Hv_Drv_PQ_LDC_SpaceFilterEn(UCHAR8 ucEn)
{
    Hv_Cal_PQ_LDC_SpaceFilterEn(ucEn);
    return;
}

VOID Hv_Drv_PQ_LDC_TimeFilterEn(UCHAR8 ucEn)
{
    Hv_Cal_PQ_LDC_TimeFilterEn(ucEn);
    return;
}

VOID Hv_Drv_PQ_LDC_BlgammaEn(UCHAR8 ucEn)
{
    Hv_Cal_PQ_LDC_BlgammaEn(ucEn);
    return;
}

VOID Hv_Drv_PQ_LDC_PixelgainEn(UCHAR8 ucEn)
{
    Hv_Cal_PQ_LDC_PixelgainEn(ucEn);
    return;
}

VOID Hv_Drv_PQ_LDC_Blgamma1En(UCHAR8 ucEn)
{
    Hv_Cal_PQ_LDC_Blgamma1En(ucEn);
    return;
}

VOID Hv_Drv_PQ_PatDetInit(USHORT16 ** puiData, UCHAR8 ucPatNum, UCHAR8 ucPatW, UCHAR8 ucPatH)
{
    Hv_Cal_PQ_SetPattern(puiData, ucPatNum, ucPatW, ucPatH);
    return;
}

VOID Hv_Drv_PQ_GammaBypass(BOOL bEn)
{
    Hv_Cal_PQGammaBypass(bEn);
    return;
}

VOID Hv_Drv_PQ_ColorBypass(BOOL bEn)
{
    Hv_Cal_PQColorBypass(bEn);
    return;
}
VOID Hv_Drv_PQ_LDCPrintPattern()
{
    Hv_Cal_PQ_LDCPrintPattern();
    return;
}

/* HSRX Cursor */
VOID Hv_Drv_PQ_SetHSRXCursorEnable(BOOL bEn)
{
    Hv_Cal_PQ_SetHSRXCursorEnable(bEn);
}

VOID Hv_Drv_PQ_SetHSRXCursorWidth(UCHAR8 ucHwidth, UCHAR8 ucVwidth)
{
    Hv_Cal_PQ_SetHSRXCursorWidth(ucHwidth, ucVwidth);
}

VOID Hv_Drv_PQ_SetHSRXCursorPos(USHORT16 usHcnt, USHORT16 usVcnt)
{
    Hv_Cal_PQ_SetHSRXCursorPos(usHcnt, usVcnt);
}

VOID Hv_Drv_PQ_GetHSRXCursorBdColor(UCHAR8 *pucR, UCHAR8 *pucG, UCHAR8 *pucB)
{
    *pucR = (Hv_Cal_PQ_GetHSRXCursorBdR() >> 4) & 0xFF;
    *pucG = (Hv_Cal_PQ_GetHSRXCursorBdG() >> 4) & 0xFF;
    *pucB = (Hv_Cal_PQ_GetHSRXCursorBdB() >> 4) & 0xFF;
}

/* SRP Cursor */
VOID Hv_Drv_PQ_SetSrpCursorEnable(BOOL bEn)
{
    Hv_Cal_PQ_SetSrpCursorEnable(bEn);
}

VOID Hv_Drv_PQ_SetSrpCursorWidth(UCHAR8 ucHwidth, UCHAR8 ucVwidth)
{
    Hv_Cal_PQ_SetSrpCursorWidth(ucHwidth, ucVwidth);
}

VOID Hv_Drv_PQ_SetSrpCursorPos(USHORT16 usHcnt, USHORT16 usVcnt)
{
    Hv_Cal_PQ_SetSrpCursorPos(usHcnt, usVcnt);
}

VOID Hv_Drv_PQ_GetSrpCursorColor(UCHAR8 *pucR, UCHAR8 *pucG, UCHAR8 *pucB)
{
    *pucR = (Hv_Cal_PQ_GetSrpCursorColorR() >> 4) & 0xFF;
    *pucG = (Hv_Cal_PQ_GetSrpCursorColorG() >> 4) & 0xFF;
    *pucB = (Hv_Cal_PQ_GetSrpCursorColorB() >> 4) & 0xFF;
}

/* LDG Cursor */
VOID Hv_Drv_PQ_SetLdgCursorEnable(BOOL bEn)
{
    Hv_Cal_PQ_SetLdgCursorEnable(bEn);
}

VOID Hv_Drv_PQ_SetLdgCursorWidth(UCHAR8 ucHwidth, UCHAR8 ucVwidth)
{
    Hv_Cal_PQ_SetLdgCursorWidth(ucHwidth, ucVwidth);
}

VOID Hv_Drv_PQ_SetLdgCursorPos(USHORT16 usHcnt, USHORT16 usVcnt)
{
    Hv_Cal_PQ_SetLdgCursorPos(usHcnt, usVcnt);
}

VOID Hv_Drv_PQ_GetLdgCursorColor(UCHAR8 *pucR, UCHAR8 *pucG, UCHAR8 *pucB)
{
    *pucR = (Hv_Cal_PQ_GetLdgCursorColorR() >> 4) & 0xFF;
    *pucG = (Hv_Cal_PQ_GetLdgCursorColorG() >> 4) & 0xFF;
    *pucB = (Hv_Cal_PQ_GetLdgCursorColorB() >> 4) & 0xFF;
}

/* Display Control Pre Cursor */
VOID Hv_Drv_PQ_SetDispCtrlPreCursorEnable(BOOL bEn)
{
    Hv_Cal_PQ_SetDispCtrlPreCursorEnable(bEn);
}

VOID Hv_Drv_PQ_SetDispCtrlPreCursorWidth(UCHAR8 ucHwidth, UCHAR8 ucVwidth)
{
    Hv_Cal_PQ_SetDispCtrlPreCursorWidth(ucHwidth, ucVwidth);
}

VOID Hv_Drv_PQ_SetDispCtrlPreCursorPos(USHORT16 usHcnt, USHORT16 usVcnt)
{
    Hv_Cal_PQ_SetDispCtrlPreCursorPos(usHcnt, usVcnt);
}

VOID Hv_Drv_PQ_GetDispCtrlPreCursorBdColor(UCHAR8 *pucR, UCHAR8 *pucG, UCHAR8 *pucB)
{
    UINT32 uiColorL = Hv_Cal_PQ_GetDispCtrlPreCursorBdColor0();
    UINT32 uiColorH = Hv_Cal_PQ_GetDispCtrlPreCursorBdColor1();
    UINT64 uiColor = ((UINT64)uiColorH << 32) | (UINT64)uiColorL;

    *pucR = (uiColor >> 28) & 0xFF;
    *pucG = (uiColor >> 16) & 0xFF;
    *pucB = (uiColor >> 4) & 0xFF;
}

/* Display Control Post Cursor */
VOID Hv_Drv_PQ_SetTXPostCursorEnable(BOOL bEn)
{
    Hv_Cal_PQ_SetTXPostCursorEnable(bEn);
}

VOID Hv_Drv_PQ_SetTXPostCursorWidth(UCHAR8 ucHwidth, UCHAR8 ucVwidth)
{
    Hv_Cal_PQ_SetTXPostCursorWidth(ucHwidth, ucVwidth);
}

VOID Hv_Drv_PQ_SetTXPostCursorPos(USHORT16 usHcnt, USHORT16 usVcnt)
{
    Hv_Cal_PQ_SetTXPostCursorPos(usHcnt, usVcnt);
}

VOID Hv_Drv_PQ_GetTXPostCursorFdColor(UCHAR8 *pucR, UCHAR8 *pucG, UCHAR8 *pucB)
{
    UINT32 uiColor = Hv_Cal_PQ_GetTXPostCursorFdColor();

    *pucR = (uiColor >> 22) & 0xFF;
    *pucG = (uiColor >> 12) & 0xFF;
    *pucB = (uiColor >> 2) & 0xFF;
}

VOID Hv_Drv_PQ_GetTXPostCursorBdColor(UCHAR8 *pucR, UCHAR8 *pucG, UCHAR8 *pucB)
{
    UINT32 uiColor = Hv_Cal_PQ_GetTXPostCursorBdColor();

    *pucR = (uiColor >> 22) & 0xFF;
    *pucG = (uiColor >> 12) & 0xFF;
    *pucB = (uiColor >> 2) & 0xFF;
}

USHORT16 Hv_Drv_PQ_GetContrast(UCHAR8 ucCh)
{
    return usContrastValue[ucCh];
}

USHORT16 Hv_Drv_PQ_GetBlackLevel(UCHAR8 ucCh)
{
    return usBlackLevelValue[ucCh];
}

VOID Hv_Drv_PQ_SetSharpnessReverse(UCHAR8 ucSharpness)
{
    Hv_Cal_PQ_SetSharpnessReverse(ucSharpness);
}

VOID Hv_Drv_PQ_SetHdrGmiLut(UCHAR8 ucHdrIdx, UINT32 uiHdrGmiLutAddr)
{
    Hv_Cal_PQ_SetHdrGmiLut(ucHdrIdx, uiHdrGmiLutAddr);
}
VOID Hv_Drv_PQ_LDCPrintSumDiff()
{
    Hv_Cal_PQ_LDCPrintSumDiff();
    return;
}
VOID Hv_Drv_PQ_LDCSetPatThr(UINT32 uiThr)
{
    Hv_Cal_PQ_LDCSetPatThr(uiThr);
    return;
}

VOID Hv_Drv_PQ_ReconfigPQSize(const VideoConfigParams* pstVideoConfigParams)
{
    Hv_Cal_DpuPQ_ReconfigDpuMainPqSize(pstVideoConfigParams);
}
VOID Hv_Drv_PQ_DdcciGammaPrepare()
{
    HV_W32_FIELD(TX_GAMMA_00, reg_gamma_en, 0);//读值保存
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_1_1C, wcg_bypass, 1);//读值保存
    HV_W32_FIELD(DISP_TOP_SUB_LDG_04, reg_main_csc_en, 0);
    HV_W32_FIELD(DISP_TOP_DPU_CA_VGSF_00_50, reg_00_ca_vg_cs2_convert_on, 0);
    HV_W32_FIELD(DISP_TOP_SRP_TOP_04, reg_sr_cb_cps_on, 0);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_00, reg_ldg_top_bypass, 1);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_E8, ct_pq_gmd_enable, 0);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_00, ct_pq_gmi_enable, 0);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_04, ct_pq_mtx_enable, 0);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_38, ct_pq_cm_enable, 0);
    HV_W32_FIELD(DISP_TOP_SRP_CPS_04, reg_sr_cb_dm_on, 0);
    HV_W32_FIELD(DISP_TOP_DPU_CA_VGSF_00_30, reg_00_ca_vg_cs1_convert_func_clk_en, 0);
    HV_W32_FIELD(RX_HSRX_CH_00_00, reg_00_hsrx_patt_apb_clk_en, 1);
    HV_W32_FIELD(RX_HSRX_CH_01_00, reg_01_hsrx_patt_apb_clk_en, 1);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_98, reg_gamma_en, 0);
    return;
}
VOID Hv_Drv_PQ_DdcciGammaFinish()
{
    HV_W32_FIELD(DISP_TOP_SUB_LDG_04, reg_main_csc_en, 1);
}

VOID Hv_Drv_PQ_DdcciColorSpacePrepare()
{
    HV_R32_DECL_VAR();
    // s_uiGammaEnableOri = HV_R32_FIELD(TX_GAMMA_00, reg_gamma_en);
    // s_uiWCGBypassOri = HV_R32_FIELD(DISP_TOP_LD_WCG_REG_1_1C, wcg_bypass);

    HV_W32_FIELD(TX_GAMMA_00, reg_gamma_en, 1);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_1_1C, wcg_bypass, 1);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_04, reg_main_csc_en, 0);
    HV_W32_FIELD(DISP_TOP_DPU_CA_VGSF_00_50, reg_00_ca_vg_cs2_convert_on, 0);
    HV_W32_FIELD(DISP_TOP_SRP_TOP_04, reg_sr_cb_cps_on, 0);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_00, reg_ldg_top_bypass, 1);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_E8, ct_pq_gmd_enable, 0);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_00, ct_pq_gmi_enable, 0);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_04, ct_pq_mtx_enable, 0);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_38, ct_pq_cm_enable, 0);
    HV_W32_FIELD(DISP_TOP_SRP_CPS_04, reg_sr_cb_dm_on, 0);
    HV_W32_FIELD(DISP_TOP_DPU_CA_VGSF_00_30, reg_00_ca_vg_cs1_convert_func_clk_en, 0);
    HV_W32_FIELD(RX_HSRX_CH_00_00, reg_00_hsrx_patt_apb_clk_en, 1);
    HV_W32_FIELD(RX_HSRX_CH_01_00, reg_01_hsrx_patt_apb_clk_en, 1);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_98, reg_gamma_en, 0);
    HV_W32_FIELD(TX_GAMMA_00, reg_gamma_cpu_en, 0);
}

VOID Hv_Drv_PQ_DdcciWcgEnable(BOOL bEn)
{
    if(bEn)
    {
        HV_W32_FIELD(DISP_TOP_LD_WCG_REG_1_1C, wcg_bypass, 0);
        HV_W32_FIELD(DISP_TOP_LD_WCG_REG_E8, ct_pq_gmd_enable, 1);
        HV_W32_FIELD(DISP_TOP_LD_WCG_REG_00, ct_pq_gmi_enable, 1);
        HV_W32_FIELD(DISP_TOP_LD_WCG_REG_04, ct_pq_mtx_enable, 1);
        HV_W32_FIELD(DISP_TOP_LD_WCG_REG_38, ct_pq_cm_enable, 1);
    }
    else
    {
        HV_W32_FIELD(DISP_TOP_LD_WCG_REG_1_1C, wcg_bypass, 1);
        HV_W32_FIELD(DISP_TOP_LD_WCG_REG_E8, ct_pq_gmd_enable, 0);
        HV_W32_FIELD(DISP_TOP_LD_WCG_REG_00, ct_pq_gmi_enable, 0);
        HV_W32_FIELD(DISP_TOP_LD_WCG_REG_04, ct_pq_mtx_enable, 0);
        HV_W32_FIELD(DISP_TOP_LD_WCG_REG_38, ct_pq_cm_enable, 0);
    }
    
    return;
}

VOID Hv_Drv_PQ_DdcciWriteColorSpaceData(USHORT16* pusData)
{
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_14, ct_pq_r_r_coef, pusData[0]);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_18, ct_pq_g_r_coef, pusData[1]);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_20, ct_pq_b_r_coef, pusData[2]);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_14, ct_pq_r_g_coef, pusData[3]);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_1C, ct_pq_g_g_coef, pusData[4]);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_20, ct_pq_b_g_coef, pusData[5]);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_18, ct_pq_r_b_coef, pusData[6]);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_1C, ct_pq_g_b_coef, pusData[7]);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_24, ct_pq_b_b_coef, pusData[8]);

    HV_W32_FIELD(DISP_TOP_SUB_OSD_TOP_14, ct_pq_r_r_coef, pusData[9]);
    HV_W32_FIELD(DISP_TOP_SUB_OSD_TOP_18, ct_pq_g_r_coef, pusData[10]);
    HV_W32_FIELD(DISP_TOP_SUB_OSD_TOP_20, ct_pq_b_r_coef, pusData[11]);
    HV_W32_FIELD(DISP_TOP_SUB_OSD_TOP_14, ct_pq_r_g_coef, pusData[12]);
    HV_W32_FIELD(DISP_TOP_SUB_OSD_TOP_1C, ct_pq_g_g_coef, pusData[13]);
    HV_W32_FIELD(DISP_TOP_SUB_OSD_TOP_20, ct_pq_b_g_coef, pusData[14]);
    HV_W32_FIELD(DISP_TOP_SUB_OSD_TOP_18, ct_pq_r_b_coef, pusData[15]);
    HV_W32_FIELD(DISP_TOP_SUB_OSD_TOP_1C, ct_pq_g_b_coef, pusData[16]);
    HV_W32_FIELD(DISP_TOP_SUB_OSD_TOP_24, ct_pq_b_b_coef, pusData[17]);
    

}

VOID Hv_Drv_PQ_DdcciColorSpaceFinish()
{
    HV_W32_FIELD(DISP_TOP_SUB_LDG_04, reg_main_csc_en, 1);
}

VOID Hv_Drv_PQ_DdcciColorTempPrepare()
{
     HV_R32_DECL_VAR();
    // s_uiGammaEnableOri = HV_R32_FIELD(TX_GAMMA_00, reg_gamma_en);
    // s_uiWCGBypassOri = HV_R32_FIELD(DISP_TOP_LD_WCG_REG_1_1C, wcg_bypass);

    HV_W32_FIELD(TX_GAMMA_00, reg_gamma_en, 1);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_1_1C, wcg_bypass, 1);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_04, reg_main_csc_en, 1);
    HV_W32_FIELD(DISP_TOP_DPU_CA_VGSF_00_50, reg_00_ca_vg_cs2_convert_on, 0);
    HV_W32_FIELD(DISP_TOP_SRP_TOP_04, reg_sr_cb_cps_on, 0);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_00, reg_ldg_top_bypass, 1);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_E8, ct_pq_gmd_enable, 0);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_00, ct_pq_gmi_enable, 0);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_04, ct_pq_mtx_enable, 0);
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_38, ct_pq_cm_enable, 0);
    HV_W32_FIELD(DISP_TOP_SRP_CPS_04, reg_sr_cb_dm_on, 0);
    HV_W32_FIELD(DISP_TOP_DPU_CA_VGSF_00_30, reg_00_ca_vg_cs1_convert_func_clk_en, 0);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_98, reg_gamma_en, 0);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_00, reg_ldg_top_bypass, 0);

    HV_W32_FIELD(RX_HSRX_CH_00_00, reg_00_hsrx_patt_apb_clk_en, 1);
    HV_W32_FIELD(RX_HSRX_CH_01_00, reg_01_hsrx_patt_apb_clk_en, 1);

    return;
}

VOID Hv_Drv_PQ_DdcciColorTempFinish()
{
    HV_W32_FIELD(DISP_TOP_SUB_LDG_04, reg_main_csc_en, 1);
    return;
}

VOID Hv_Drv_PQ_DdcciPatternPrepare(VOID)
{
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_38, reg_00_ptc_inp_patt_type0_clk_en, 1);
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_38, reg_00_ptc_inp_patt_type1_clk_en, 1);
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_38, reg_00_ptc_inp_patt_type_new_clk_en, 1);
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_38, reg_00_ptc_inp_patt_loop_clk_en, 1);

    HV_W32_FIELD(DISP_TOP_SUB_LDG_F0, reg_fw_black_insert_enable, 0);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_F0, reg_black_insert_fw_mode, 0);
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_04, reg_00_ptc_inp_patt_mode, 0);
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_00, reg_00_ptc_inp_patt_enable, 0);
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_38, reg_00_ptc_inp_patt_type0_clk_en, 1);
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_00, reg_00_ptc_inp_patt_enable, 0);
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_00, reg_00_ptc_inp_patt_enable, 1);
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_04, reg_00_ptc_inp_patt_mode, 0);
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_38, reg_00_ptc_inp_patt_loop_stop, 1);
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_04, reg_00_ptc_inp_patt_type_0, 0);
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_08, reg_00_ptc_inp_patt_para_0, 0);

    return;
}

VOID Hv_Drv_PQ_DdcciPatternFinish(VOID)
{
    HV_W32_FIELD(RX_PTC_INP_PATT_TOP_00_00, reg_00_ptc_inp_patt_enable, 0);
    return;
}

VOID Hv_Drv_PQ_DdcciTrainingStart(VOID)
{
    HV_W32_FIELD(TX_GAMMA_00, reg_gamma_clk_gating_off, 1);
}

VOID Hv_Drv_PQ_DdcciSetGamma(BOOL bEn)
{
    HV_W32_FIELD(TX_GAMMA_00, reg_gamma_en, bEn);
}

UCHAR8 Hv_Drv_PQ_DdcciGetGamma()
{
    HV_R32_DECL_VAR();
    return HV_R32_FIELD(TX_GAMMA_00, reg_gamma_en);
}

VOID Hv_Drv_PQ_DdcciSetWcg(UCHAR8 ucData)
{
    HV_W32_FIELD(DISP_TOP_LD_WCG_REG_1_1C, wcg_bypass, ucData);
}

UCHAR8 Hv_Drv_PQ_DdcciGetWcg()
{
    HV_R32_DECL_VAR();
    return HV_R32_FIELD(DISP_TOP_LD_WCG_REG_1_1C, wcg_bypass);
}

VOID Hv_Drv_PQ_DdcciSetLdg(UCHAR8 ucData)
{
    HV_W32_FIELD(DISP_TOP_SUB_LDG_00, reg_ldg_top_bypass, ucData);
}

UCHAR8 Hv_Drv_PQ_DdcciGetLdg()
{
    HV_R32_DECL_VAR();
    return HV_R32_FIELD(DISP_TOP_SUB_LDG_00, reg_ldg_top_bypass);
}
UCHAR8 Hv_Drv_PQ_DdcciGetHdr()
{
    HV_R32_DECL_VAR();
    return HV_R32_FIELD(DISP_TOP_LDG_HDR_REG_00_00, reg_00_ct_ldg_hdr_passthrough);
}

VOID Hv_Drv_PQ_DdcciSetHdr(UCHAR8 ucData)
{
    HV_W32_FIELD(DISP_TOP_LDG_HDR_REG_00_00, reg_00_ct_ldg_hdr_passthrough, ucData);
}
VOID Hv_Drv_PQ_MhiInit()
{
    Hv_Cal_PQ_MhiInit();
}
VOID Hv_Drv_MhiSetPos(USHORT16 usStartX, USHORT16 usStartY, USHORT16 usWidth, USHORT16 usHeight)
{
    Hv_Cal_MhiSetPos(usStartX, usStartY, usWidth, usHeight);
}


UINT32* Hv_Drv_PQ_GetMhi16()
{
    return Hv_Cal_PQ_GetMhi16();
}


VOID Hv_Drv_PQ_PWM(VOID)
{

#if 0
    /*pwm init*/
    Hv_Drv_MPRT_SetOutHighFreqPwmDuty(HV_BOARD_CONFIG_GPIO_FB0_PWM1,2153,2150);
    Hv_Drv_MPRT_SetOutHighFreqPwmDuty(HV_BOARD_CONFIG_GPIO_FB1_PWM5,2153,2150);
    
    Hv_Drv_MPRT_PwmMode(HV_BOARD_CONFIG_GPIO_FB0_PWM1, 3);
    Hv_Drv_MPRT_PwmMode(HV_BOARD_CONFIG_GPIO_FB1_PWM5, 3);

    Hv_Drv_MPRT_PwmEnable(HV_BOARD_CONFIG_GPIO_FB0_PWM1, 1);
    Hv_Drv_MPRT_PwmEnable(HV_BOARD_CONFIG_GPIO_FB1_PWM5, 1);
#endif
}

VOID Hv_Drv_PQ_GCLutExpand(USHORT16 *pusInput, UCHAR8 ucCnt)
{
    Hv_Cal_PQ_GCLutExpand(pusInput, ucCnt);
}

VOID Hv_Drv_PQ_SetBrightRangeY(UCHAR8 ucCh, UCHAR8 ucRange)
{
    Hv_Cal_PQ_SetBrightRangeY(NULL, NULL, ucCh, ucRange);
}
