/**
 * @file hv_comm_DataBase.c
 * @brief common database file.
 * @details This file provides the following functions: \n
 *          (1) data type define \n
 * @bug 1.bug1 \n
 * @todo 1.todo1 \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 <string.h>
#include "hv_comm_DataBase.h"
#include "hv_comm_Event.h"
#include "hv_comm_Timer.h"
#include "hv_comm_Log.h"
#include "hv_comm_Assert.h"
#include "hv_mw_Video.h"
#include "hv_mw_PQ.h"
#include "hv_mw_Hdcp.h"
#include "hv_drv_Flash.h"
#include "hv_drv_Mailbox.h"
#include "hv_app_Function.h"
#include "hv_chip_Debug.h"
#include "hv_drv_Gpio.h"
#include "PanelConfig.h"
#include "HV_REGS_HT7315.h"
#include "hv_panel_Param.h"
#include "hv_comm_FlashConfig.h"
#include "hv_mw_Hdmi.h"
#include "hv_mw_DisplayPort.h"

/* allgine size to 16 uppper. */
#define ALLIGNUP16(value) ((value + 15) >> 4 << 4)
/* sector size for erase */
#define SECTOR_SIZE                  (4*1024)

USHORT16 s_usUserRWVersion      = 0;
#ifdef CONFIG_DB_USERDATA
USHORT16 s_usUserRWVersionBack  = 0;
#endif

/*User data defualt for data resume*/
#define USER_DATA_VERSION 2
const static UserDataDBRegion s_stDefaultUserDataDBRegion =
{
    .uiMagicNumber      = DATABASE_VALID_MAGIC_NUMBER,
    .usVersion          = USER_DATA_VERSION,
    .usRWVersion        = 0,
    .stMode =
    {
        /* STANDARD */
        {.ucBrightness = 80, .ucContrast = 50},
        /* GAME */
        {.ucBrightness = 100, .ucContrast = 60},
        /* MOVIE */
        {.ucBrightness = 60, .ucContrast = 55},
        /* OFFICE */
        {.ucBrightness = 80, .ucContrast = 40},
        /* CUSTOM */
        {.ucBrightness = 70, .ucContrast = 50},
    },
    .ucDisplayMode = 0,

    .ucBrightness = 80,
    .ucContrast = 50,
    .ucDDCCI = 1,
    .ucHue = 50,
    .ucSaturation = 50,
    .ucSharpness = 10,
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_DARK_STABILIZER)
    .ucDarkStabilizer = 0,
#endif
    .ucGameMode = 0,
    .ucColorMode = 0,
    .ucColorTemperature = PQ_COLOR_TEMP_STANDARD,
    .ucColorSpace = PQ_GAMUT_NATIVE,
    .ucRed = 100,
    .ucGreen = 94,
    .ucBlue = 97,
    .ucGamma = PQ_GAMMA2_2,
    .ucLowBlueLight = 0,
#if (HV_PROJECT_CONFIG_COLOR_FILTER == HV_CONFIG_ON)
    .ucColorFilter = 0,
#endif

    .ucVideoSource = 0,
    .bAutoVideoSrcSelSw = 1,
    .bAutoVideoBackup = 1,
    .ucHdmi0Format = 0,
    .ucHdmi1Format = 0,

	.bHdmiAllmEn = 1,
	.bQms = 0,

    .ucProportion = OUTPUTRATIO_AUTO,
    .ucResponseTime = PQ_OD_OFF,

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_MPRT)
    .ucMprt = 0,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_FREESYNC)
    .ucFreeSync = 0,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_ADAPTIVESYNC)
    .ucAdaptiveSync = 0,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_GSYNC)
    .ucGSync = 0,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_LDR)
    .ucLdr = 0,
    .ucLdrRgb = 0,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_DCR)
    .ucDcr = 0,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_EYESHIELD)
    .ucEyeshield = 0,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_CROSSHAIR)
    .ucOsdCrosshair = 0,
    .ucDynCrosshair = 0,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_REFRESH_RATE)
    .ucOsdFrameCounter = 0,
#endif
    .ucOsdTimerCounter = 0,

    .ucOsdLanguage = 0,
    .ucOsdMenuHPos = 99,
    .ucOsdMenuVPos = 1,
    .ucOsdTime = 10,
    .ucOsdTrans = 255,
    .ucOsdLock = 0,
    .ucDPVersion = HV_DP_VER14,
    .ucDP1Version = HV_DP_VER14,

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_HDR)
    .enHdrSwitch = 1,
    .enHdrSwitchBackup = 1,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_CUSTOM_KEY)
    .ucOsdCustomKey1 = 0,
    .ucOsdCustomKey2 = 3,
    .ucOsdCustomKey3 = 1,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_LIGHT_EFFECT)
    .ucLightEffect = 1,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_AMBIENT_LIGHT)
    .ucAmbientLight = 0,
    .ucMonoLight = 0,
#endif

#if ((HV_CONFIG_ON == HV_PROJECT_CONFIG_VARIABLEBACKLIGHT) || (HV_CONFIG_ON == HV_PROJECT_CONFIG_FULL_LOCALDIMMING))
    .bVariableBackLight = 0,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_OSD_ROTATION)
    .ucOsdRotation = 0,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_CM)
    .ucHueByR = 0,
    .ucHueByG = 0,
    .ucHueByB = 0,
    .ucHueByC = 0,
    .ucHueByM = 0,
    .ucHueByY = 0,

    .ucSatByR = 0,
    .ucSatByG = 0,
    .ucSatByB = 0,
    .ucSatByC = 0,
    .ucSatByM = 0,
    .ucSatByY = 0,

    .ucLumByR = 0,
    .ucLumByG = 0,
    .ucLumByB = 0,
    .ucLumByC = 0,
    .ucLumByM = 0,
    .ucLumByY = 0,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_MAGNIFY)
    .bMagnifyGlassSw = 0,
    .fMagnifyGlassScalerUpRatio = 3,
    .usMagnifyGlassHsize = 300,
    .usMagnifyGlassVsize = 300,
    /*放大镜默认位置在屏幕中间 TODO:实际需要根据RX输入的timing来进行放大*/
    .usMagnifyGlassPositionH = PANEL_H_ACTIVE / 2,
    .usMagnifyGlassPositionV = PANEL_V_ACTIVE / 2,
    /*放大镜要放大画面的位置*/
    .usMagnifyGlassSamplingLocH = PANEL_H_ACTIVE / 2,
    .usMagnifyGlassSamplingLocV = PANEL_V_ACTIVE / 2,
#endif

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_MAIN_MONTAGE)
    .bMainMontageSw = 1,
    .ucMontageMode = 0,
    .usMontageInHsta = 0,
    .usMontageInHend = 1280,
    .usMontageInVsta = 0,
    .usMontageInVend= 720,
#endif

    .ucVolume = 50,
    .bMute = 0,
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_AUDIO_SETTING)
    .ucAudioSource = 0,
    .uiHeadsetVolume = 0,
    .uiSpeakerVolume = 0,
    .uiSoundDelayTime = 0,
    .uiEQMode = 0,
#endif

#ifdef CONFIG_USER_DOUBLE_CHANNEL_ON
    .ucPxPMode = 0,
    .ucPxPColor = 0,
    .ucPxPVideoSource = 0,
    .bPxPSwitch = 0,
    .ucPipPosition = 2,
    .ucPipSize = 0,
    .usPipSmallWindowHSize = PANEL_H_ACTIVE * 2 / 5,
    .usPipSmallWindowVSize = PANEL_V_ACTIVE * 2 / 5,
    .usPipMiddleWindowHSize = PANEL_H_ACTIVE / 2,
    .usPipMiddleWindowVSize = PANEL_V_ACTIVE / 2,
    .usPipBigWindowHSize = PANEL_H_ACTIVE / 2,
    .usPipBigWindowVSize = PANEL_V_ACTIVE / 2,
    .usPipWindowHSize = PANEL_H_ACTIVE / 2,         /*当前使用的pip h大小*/
    .usPipWindowVSize = PANEL_V_ACTIVE / 2,         /*当前使用的pip v大小*/
    .ucPbpSize = 1,
    .usPbpSmallWindowHSize = PANEL_H_ACTIVE / 3,
    .usPbpMiddleWindowHSize = PANEL_H_ACTIVE / 2,
    .usPbpBigWindowHSize = PANEL_H_ACTIVE * 2 / 3,
    .usPbpWindowHSize = PANEL_H_ACTIVE / 2,         /*当前使用的pbp h大小*/
    .usOsdPipHPosLevel = 0,
    .usOsdPipVPosLevel = 0,
#endif
#if (HV_BOARD_CONFIG_HDMI_0 == PORT_VALID)
    .ucHdmi0EdidCfg = 0xFF,
#endif
#if (HV_BOARD_CONFIG_HDMI_1 == PORT_VALID)
    .ucHdmi1EdidCfg = 0xFF,
#endif
#if (0 != HV_PROJECT_CONFIG_DPU_OVER_SCAN_SIDE_SIZE)
    .bOverScan = 0,
#endif
    .ucProEsportSwitch = 0,
    .usProEsportHSize = 2320,
    .usProEsportVSize = 1305,
    .usProEsportHPos = PANEL_H_ACTIVE / 2,
    .usProEsportVPos = PANEL_V_ACTIVE / 2,
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_DPU_BRIGHT_FRAME)
    .bBrightFrameEn = 0,
    .usBrightFrameRatio = 1,
    .usBrightFrameHsize = 300,
    .usBrightFrameVsize = 300,
    .usBrightFramePosH = PANEL_H_ACTIVE / 2,
    .usBrightFramePosV = PANEL_V_ACTIVE / 2,
    .ucOsdBfSizeLevel = 0,
    .ucOsdBfHPosLevel = 0,
    .ucOsdBfVPosLevel = 0,
#endif
    /*注意EEPROM存储使用witre-thru模式，不使用bModifyFlag机制*/
    .bModifyFlag = HV_FALSE,
};

/*Factory data defualt for data resume*/
#define FACTORY_DATA_VERSION 2
static volatile FactoryDataDBRegion s_stDefaultFactoryDataDBRegion = 
{
    .uiMagicNumber          = DATABASE_VALID_MAGIC_NUMBER,
    .usVersion              = FACTORY_DATA_VERSION,
    .bUartEnable            = HV_TRUE,
    .ucFactoryPanelSscFreq  = 0,
    .ucFactoryPanelSsSetp   = 0,
    .ucFactoryDdrSscFreq    = 0,
    .ucFactoryDdrSsSetp     = 0,
    .ucFactWeek             = 0x15,
    .ucFactYear             = 0x21,
    .uiProductSN            = 0x00061899,
    .acDescSn               = {[0 ... 12] = 0x00},
    .ucFactoryBrightness    = 75,
    .ucFactoryContrast      = 75,
    .ucFactorySharpness     = 10,
    .ucFactoryEnergy        = 45,
    .ucDefaultLanguage      = UD_LANGUAGE_V_CN,
    .stColTempStandard      = {128, 128, 128},
    .stColTempWarm          = {128, 128, 120},
    .stColTempCool          = {108, 113, 128},
    .stColTempSrgb          = {107, 102, 96},
    .stColTempEyeCare       = {128, 122, 106},//4500 
    .stColTempP3            = {118, 128, 116}, //P3 4300K
    .stColTempLowBlueLvl1   = {128, 115, 90},
    .stColTempLowBlueLvl2   = {128, 110, 80},
    .stColTempLowBlueLvl3   = {128, 105, 70}, 
    .stColTempLowBlueLvl4   = {128, 99, 58}, //4500 
    .stColTempCustom        = {255, 255, 255},
    .stGamutNative = { 
        0x1000, 0, 0,
        0, 0x1000, 0,
        0, 0, 0x1000,
        0x1000, 0, 0,
        0, 0x1000, 0,
        0, 0, 0x1000
    },

    .stGamutSrgb            = { 
        0xd28, 0x2d7, 0x0,
        0xa3, 0xfec, 0xff71,
        0x2d, 0xea, 0xee9,
        0x1000, 0, 0,
        0, 0x1000, 0,
        0, 0, 0x1000
    },
    .stGamut709             = {
        0xd28, 0x2d7, 0x0,
        0xa3, 0xfec, 0xff71,
        0x2d, 0xea, 0xee9,
        0x1000, 0, 0,
        0, 0x1000, 0,
        0, 0, 0x1000
    },
    .stGamutP3              = {
        0x1011, 0xfefd, 0xf2,
        0x1e, 0x107e, 0xff63,
        0xffe1, 0xffbe, 0x1060,
        0x1000, 0, 0,
        0, 0x1000, 0,
        0, 0, 0x1000
    },
    .stGamutHdr = {
        0x1011, 0xfefd, 0xf2,
        0x1e, 0x107e, 0xff63,
        0xffe1, 0xffbe, 0x1060,
        0x1000, 0, 0,
        0, 0x1000, 0,
        0, 0, 0x1000
    },
    .stGamutAdobe = {
        0x1000, 0x0, 0x0,
        0x0, 0x1000, 0x0,
        0x0, 0x0, 0x1000,
        0x1000, 0, 0,
        0, 0x1000, 0,
        0, 0, 0x1000
    },


#if (0 == HV_PROJECT_CONFIG_HDCP_KEY_ONROM)
    .ucUseSeperatorHDCPKey = HV_FALSE,
#else
    .ucUseSeperatorHDCPKey = HV_TRUE,
#endif
    .ucUseExtEdid           = 0x0,
    .bModifyFlag            = HV_FALSE,
};

/*System data defualt for data resume*/
#define SYSTEM_DATA_VERSION 2
const static SystemDataDBRegion s_stDefaultSystemDataDBRegion =
{
    .uiMagicNumber      = DATABASE_VALID_MAGIC_NUMBER,
    .usVersion          = SYSTEM_DATA_VERSION,
    /*System data defualt init*/
    .stAudioEqDataBase[ROCK_MODE] =
    {
        .stAudioEqLpf0 = {0},
        .stAudioEqHpf0 = {0},
        .stAudioEqBpf0 = {0},
        .stAudioEqBpf1 = {0},
        .stAudioEqBpf2 = {0},
        .stAudioEqBpf3 = {0},
        .stAudioEqBpf4 = {0},
    },
    .stAudioEqDataBase[POP_MODE] =
    {
        .stAudioEqLpf0 = {0},
        .stAudioEqHpf0 = {0},
        .stAudioEqBpf0 = {0},
        .stAudioEqBpf1 = {0},
        .stAudioEqBpf2 = {0},
        .stAudioEqBpf3 = {0},
        .stAudioEqBpf4 = {0},
    },
    .stAudioEqDataBase[LIVE_MODE] =
    {
        .stAudioEqLpf0 = {0},
        .stAudioEqHpf0 = {0},
        .stAudioEqBpf0 = {0},
        .stAudioEqBpf1 = {0},
        .stAudioEqBpf2 = {0},
        .stAudioEqBpf3 = {0},
        .stAudioEqBpf4 = {0},
    },
    .stAudioEqDataBase[DANCE_MODE] =
    {
        .stAudioEqLpf0 = {0},
        .stAudioEqHpf0 = {0},
        .stAudioEqBpf0 = {0},
        .stAudioEqBpf1 = {0},
        .stAudioEqBpf2 = {0},
        .stAudioEqBpf3 = {0},
        .stAudioEqBpf4 = {0},
    },
    .stAudioEqDataBase[CLUB_MODE] =
    {
        .stAudioEqLpf0 = {0},
        .stAudioEqHpf0 = {0},
        .stAudioEqBpf0 = {0},
        .stAudioEqBpf1 = {0},
        .stAudioEqBpf2 = {0},
        .stAudioEqBpf3 = {0},
        .stAudioEqBpf4 = {0},
    },
    .stAudioEqDataBase[POWER_MODE] =
    {
        .stAudioEqLpf0 = {0},
        .stAudioEqHpf0 = {0},
        .stAudioEqBpf0 = {0},
        .stAudioEqBpf1 = {0},
        .stAudioEqBpf2 = {0},
        .stAudioEqBpf3 = {0},
        .stAudioEqBpf4 = {0},
    },
    /*TODU init*/

    .bFactoryMode           = HV_TRUE,
#if (HV_PROJECT_CONFIG_CTS == HV_CONFIG_ON)
    .ucAutoUpdataEdidEnable = HV_FALSE,
#else
    .ucAutoUpdataEdidEnable = HV_TRUE,
#endif
    .stSubWindowBorderCfg =
    {
        .ucPxpBorderEnable = HV_TRUE,
        .ucSubWindowBorderWidth = 2,
        .ucSubWindowBorderColorR = 0,
        .ucSubWindowBorderColorG = 0,
        .ucSubWindowBorderColorB = 0xFF,
    },

    .bBurnInEnable      = HV_TRUE,
    .bShowLogoFlag      = HV_TRUE,
    .bEdidWp            = HV_FALSE,
    .bDeveloperMode     = HV_FALSE,
    .ucPowerLedMode     = 2,/* 0:off 1:on 2:breath */

    .bModifyFlag        = HV_FALSE,
};

/*hdcp default key, 为了节约RAM内存，不在额外开辟,如果使用flash单独的key会直接覆盖当前default KEY*/

#if (HV_CONFIG_OFF == HV_PROJECT_CONFIG_HDCP_KEY_CLEAR_TEXT)
static HDCPDataDBRegion s_stDefaultHDCPDataDBRegion =
{
    .usCheckCrc = 0x0,
    .usVersion = 0x0,
    .uiMagicNumber = DATABASE_VALID_MAGIC_NUMBER,
    .stKey =
    {
        .stHdcp1xRxKey =
        {
            /*Bksv key input hear*/
            .aucBksv =
            {
                0x01, 0x05, 0x02, 0x60, 0x9d
            },
            /*Dks key input hear*/
            .aucDks =
            {
                0xed, 0x46, 0x53, 0x69, 0x33, 0x28, 0x76, 0x0f, 0x54, 0xa1, 0xba, 0x06, 0x95, 0x1f, 0x4d, 0x4d, 
                0x4f, 0x28, 0x2d, 0x8b, 0xcb, 0x2e, 0x54, 0x88, 0xa4, 0x6f, 0x10, 0x42, 0x09, 0x62, 0xa6, 0x32, 
                0x1c, 0x6e, 0x74, 0x4d, 0x55, 0xd1, 0x63, 0x2c, 0x18, 0xb4, 0x66, 0x8a, 0x30, 0xf2, 0x4d, 0x09, 
                0xe0, 0x5e, 0x91, 0xb7, 0x81, 0xa0, 0x99, 0x6b, 0x9f, 0x0f, 0x8e, 0x2c, 0x09, 0x60, 0x4e, 0x4f, 
                0x05, 0xe7, 0x36, 0xee, 0x4a, 0x18, 0x4d, 0x3b, 0x6e, 0x76, 0x95, 0xa2, 0xa7, 0xc6, 0xe5, 0x7c, 
                0xfb, 0x6d, 0x6c, 0xf9, 0x61, 0x23, 0x6a, 0x0b, 0xca, 0x05, 0xab, 0x47, 0x09, 0xbe, 0x4b, 0xcd, 
                0x6e, 0x6d, 0xc0, 0xf6, 0x39, 0x28, 0x31, 0x30, 0x36, 0xd7, 0x94, 0x90, 0x76, 0x6d, 0x79, 0x50, 
                0x1e, 0x2a, 0xf1, 0x56, 0xeb, 0xe9, 0x3b, 0xf2, 0xd6, 0x04, 0x41, 0x08, 0xb8, 0xcf, 0x3b, 0xa7, 
                0x73, 0xf4, 0xa5, 0xa1, 0x96, 0xc4, 0x57, 0x61, 0x91, 0x7a, 0x15, 0x88, 0x72, 0xc2, 0xbc, 0x10, 
                0x85, 0x1b, 0xeb, 0x84, 0xc2, 0x67, 0x32, 0x20, 0x1a, 0x4a, 0x65, 0x0e, 0x75, 0xde, 0x40, 0x15, 
                0x1b, 0x79, 0xbb, 0x67, 0x06, 0x44, 0xb2, 0x10, 0x6c, 0xa1, 0x5c, 0x59, 0x1a, 0xc7, 0x66, 0x95, 
                0x50, 0x85, 0x0e, 0x99, 0x5d, 0x8a, 0xd7, 0xc3, 0xef, 0x62, 0xdf, 0x37, 0x8c, 0x95, 0x58, 0xc0, 
                0x33, 0x58, 0x46, 0x57, 0x39, 0x9a, 0x84, 0x24, 0x5f, 0xa6, 0x60, 0x6c, 0x41, 0xf6, 0x5e, 0x23, 
                0x16, 0x1f, 0x6a, 0x8f, 0xdf, 0xed, 0x7e, 0x6d, 0x4e, 0x83, 0x5b, 0xaf, 0x74, 0x26, 0xe4, 0x7c, 
                0xb3, 0x66, 0xde, 0xfc, 0x16, 0xef, 0x61, 0xd1, 0x4b, 0x0b, 0x58, 0x8f, 0x6a, 0xe3, 0x95, 0x7a, 
                0x5e, 0xf5, 0xf7, 0xe8, 0x9b, 0x80, 0x9d, 0x4d, 0xd7, 0x14, 0x85, 0xa4, 0x0e, 0xdc, 0x77, 0xa8, 
                0x40, 0x78, 0x3f, 0xbe, 0x2d, 0x6a, 0x4c, 0xe5, 0x8f, 0xd6, 0x6f, 0xfa, 0xf0, 0x6d, 0x39, 0xeb, 
                0x59, 0xaf, 0x3d, 0x50, 0xd5, 0xd2, 0x5b, 0x5a
            }
        },
        .stHdcp2xRxKey =
        {
            .aucHdcp2xRxLc128 =
            {
                0xc3, 0x4e, 0x6b, 0xa6, 0x46, 0x84, 0xa4, 0x77, 0x78, 0x60, 0xbe, 0xb3, 0x32, 0x25, 0x1c, 0x64
            },
            .aucHdcp2xRxCert =
            {
                0x98, 0xe3, 0x34, 0xa8, 0x4f, 0xe9, 0xbe, 0xbf, 0x7a, 0x3e, 0xf7, 0x68, 0xdf, 0x87, 0x99, 0x7f, 
                0x7d, 0xe3, 0x2f, 0x3e, 0xe8, 0x0a, 0xb5, 0x05, 0xe1, 0x22, 0x22, 0xb5, 0xc6, 0x44, 0xe1, 0x0c, 
                0x4e, 0x32, 0x66, 0xcb, 0xa4, 0xbb, 0x65, 0x04, 0x74, 0xf4, 0x4f, 0xc2, 0x91, 0xec, 0x74, 0x52, 
                0xbd, 0x9c, 0x47, 0x2f, 0x59, 0x10, 0xcd, 0x14, 0xef, 0x31, 0x89, 0xa9, 0x8c, 0x5e, 0x2f, 0xed, 
                0x2f, 0xa7, 0x19, 0x28, 0xa2, 0x73, 0x15, 0x7e, 0x60, 0x03, 0x4a, 0x6c, 0x19, 0x48, 0xf2, 0x7e, 
                0xd0, 0x51, 0x9d, 0x84, 0x71, 0x66, 0xd0, 0x53, 0x46, 0x10, 0xef, 0xd9, 0x5b, 0x80, 0x94, 0x95, 
                0x36, 0xb3, 0xf6, 0x39, 0x81, 0x2f, 0xff, 0xb6, 0x12, 0xad, 0x7b, 0x44, 0x14, 0xc3, 0x43, 0x3d, 
                0xa1, 0xf2, 0x13, 0x5a, 0xc6, 0x9c, 0x10, 0xed, 0x95, 0x40, 0xa2, 0xb1, 0x13, 0x1c, 0xf4, 0xa3, 
                0xe5, 0x70, 0x96, 0x27, 0x72, 0x08, 0xb4, 0xfc, 0x77, 0x57, 0x67, 0xd0, 0xe9, 0x9b, 0xa5, 0x92, 
                0x03, 0x5c, 0x25, 0xde, 0xbf, 0x9c, 0xd4, 0xb4, 0xca, 0xc9, 0xfd, 0x67, 0x92, 0x21, 0xa8, 0x07, 
                0x82, 0xe3, 0x83, 0xd6, 0x14, 0x7d, 0x4d, 0x62, 0x0f, 0x76, 0xf8, 0xcb, 0x92, 0x5e, 0x6c, 0xce, 
                0xc5, 0xa5, 0x1e, 0x58, 0x9a, 0x7c, 0x44, 0x86, 0x71, 0xc3, 0xd7, 0x8d, 0xed, 0xb5, 0x79, 0x06, 
                0xd7, 0xe7, 0x54, 0x28, 0x93, 0x59, 0xfb, 0xda, 0x62, 0xf8, 0x56, 0x54, 0x88, 0x1a, 0x50, 0xc8, 
                0x58, 0xcb, 0x11, 0x5a, 0x61, 0x40, 0xfe, 0x6a, 0x5c, 0xef, 0x25, 0xc3, 0x92, 0x48, 0xc7, 0x97, 
                0x2b, 0xd9, 0x96, 0xf7, 0xb9, 0xd0, 0xed, 0x43, 0x8e, 0xa7, 0xb5, 0x10, 0x73, 0x67, 0xf8, 0x8d, 
                0x03, 0x12, 0xfa, 0xf3, 0xb8, 0x1a, 0x89, 0x03, 0xe0, 0xf0, 0x0a, 0xdf, 0x13, 0x6c, 0x4c, 0xeb, 
                0x41, 0xae, 0x34, 0xa3, 0x62, 0xa8, 0x93, 0xa2, 0xdc, 0x32, 0xf2, 0x9b, 0xe3, 0x18, 0x50, 0xec, 
                0x86, 0xb7, 0xcb, 0xc0, 0x18, 0x35, 0xbb, 0x6c, 0x01, 0x8f, 0x2e, 0x09, 0xc8, 0x98, 0xd4, 0x90, 
                0xee, 0xf8, 0xc0, 0x72, 0x16, 0x62, 0xba, 0x4d, 0xb0, 0xe2, 0x40, 0x44, 0x05, 0xb7, 0x6e, 0xf9, 
                0xff, 0x22, 0x2b, 0xbf, 0x2c, 0x66, 0xcf, 0x0d, 0x2c, 0x5d, 0xc6, 0x80, 0xe0, 0xa3, 0x1b, 0xd3, 
                0x37, 0x49, 0x75, 0xa8, 0xb1, 0xc2, 0x97, 0x1c, 0x9c, 0x92, 0xcd, 0xb9, 0xee, 0x1b, 0xf2, 0xb8, 
                0x48, 0x5b, 0xc7, 0x0f, 0x96, 0xee, 0x6c, 0x1b, 0xaa, 0x3d, 0xbb, 0x21, 0x4f, 0xe8, 0xe6, 0x2a, 
                0x71, 0xae, 0xe2, 0x39, 0xb7, 0xfb, 0x2e, 0xdc, 0x7d, 0x33, 0x34, 0x80, 0xab, 0xb7, 0xb1, 0xef, 
                0x8c, 0x1d, 0xb4, 0x07, 0xfc, 0x9b, 0xdf, 0x15, 0xaf, 0x7e, 0xdf, 0xb1, 0xfa, 0xa9, 0x0d, 0x1b, 
                0x05, 0xca, 0xcf, 0xa2, 0x42, 0xb1, 0xb7, 0xb8, 0xc8, 0xe9, 0xd7, 0x6d, 0x79, 0xe1, 0x17, 0xd3, 
                0xb1, 0x3c, 0x23, 0x06, 0x46, 0xd1, 0x0b, 0xcb, 0xbc, 0x58, 0x05, 0x0c, 0x1d, 0xa1, 0x12, 0x89, 
                0x2a, 0x76, 0x29, 0xb0, 0x21, 0x88, 0x3d, 0xfd, 0x36, 0xaf, 0x66, 0xa7, 0xa8, 0xb2, 0x68, 0x8b, 
                0x02, 0x5f, 0x55, 0xfa, 0x06, 0x9e, 0x99, 0x75, 0x38, 0x37, 0x8b, 0xdd, 0xb3, 0x09, 0x65, 0x58, 
                0x53, 0xb1, 0xab, 0x87, 0xbf, 0x1b, 0xa9, 0x05, 0xda, 0x4b, 0x77, 0x21, 0x72, 0xd6, 0x77, 0xac, 
                0x4e, 0xb7, 0x8b, 0xe4, 0xeb, 0xd1, 0x8c, 0xc5, 0x4f, 0x1a, 0xb7, 0x94, 0xfe, 0x05, 0xf8, 0xc9, 
                0x36, 0x5b, 0x1a, 0x76, 0x4c, 0xb2, 0x10, 0x95, 0xe0, 0xc4, 0xb6, 0x7d, 0xb7, 0xd5, 0x40, 0x10, 
                0xf7, 0xe9, 0xeb, 0x27, 0x64, 0x17, 0x43, 0x56, 0x45, 0x83, 0xbc, 0x4d, 0x8a, 0x68, 0x86, 0x06, 
                0xe9, 0x23, 0x41, 0x07, 0xe4, 0xee, 0x2b, 0x8d, 0x56, 0x08
            },
            .aucHdcp2xRxPrivKey =
            {
                0x55, 0xd8, 0x61, 0x87, 0x47, 0x32, 0xdc, 0xaa, 0xe6, 0xb3, 0x19, 0x2a, 0x13, 0x0e, 0xcb, 0x5e, 
                0x2d, 0xef, 0xa6, 0x58, 0xb3, 0x5a, 0x89, 0xf8, 0xcc, 0xdf, 0x3d, 0x39, 0x86, 0x1a, 0xe7, 0x42, 
                0x17, 0x6c, 0x00, 0xfd, 0x09, 0xcf, 0x52, 0x1d, 0xdc, 0x83, 0x6d, 0xd1, 0xac, 0x83, 0x48, 0xa2, 
                0x1a, 0xdf, 0xc5, 0x03, 0x6c, 0x88, 0xae, 0xe1, 0x83, 0x4c, 0x79, 0x0e, 0x2f, 0xa1, 0x5d, 0x00, 
                0x0a, 0xde, 0x33, 0x0a, 0x38, 0x78, 0xe8, 0x1a, 0x85, 0xae, 0x78, 0x11, 0x50, 0xad, 0xdb, 0x05, 
                0x8e, 0x92, 0x5c, 0x0c, 0x74, 0x5f, 0xf3, 0xdb, 0x6b, 0xc7, 0x7c, 0xc6, 0x36, 0x12, 0xdf, 0xf5, 
                0x08, 0xc8, 0xe1, 0x7a, 0x2c, 0x88, 0xfb, 0xcc, 0x93, 0xb5, 0xd7, 0x49, 0xd0, 0xdd, 0x8a, 0xac, 
                0x43, 0x24, 0x49, 0x4f, 0x15, 0x67, 0x57, 0xb4, 0xe4, 0x11, 0x8e, 0xb5, 0x5b, 0x09, 0xb5, 0x71, 
                0x5e, 0x3b, 0x77, 0x13, 0x1e, 0xc5, 0x51, 0x55, 0xe9, 0x00, 0x51, 0xf6, 0x39, 0x46, 0xf4, 0xca, 
                0x82, 0x31, 0xd1, 0xfc, 0x2f, 0x9d, 0x94, 0xb0, 0xfd, 0xcc, 0x36, 0x2c, 0x17, 0x16, 0xf5, 0xc6, 
                0x35, 0xce, 0xb7, 0xaf, 0x45, 0x53, 0xc5, 0x4e, 0x59, 0x1c, 0xc1, 0x87, 0x47, 0x57, 0xb0, 0x52, 
                0x4c, 0x41, 0x1c, 0xe8, 0xa1, 0x39, 0x44, 0x5f, 0xbe, 0x4c, 0xf1, 0x1f, 0x38, 0x0d, 0x06, 0xe5, 
                0x9b, 0xab, 0x48, 0xe9, 0x84, 0x7e, 0x77, 0xee, 0x71, 0x6d, 0xb5, 0xb5, 0xa1, 0x24, 0xe3, 0xd6, 
                0x36, 0x15, 0x65, 0x65, 0xe2, 0x81, 0x52, 0xc6, 0xf0, 0xdb, 0x80, 0x25, 0xab, 0x46, 0xd2, 0xe9, 
                0xb5, 0x9f, 0xd6, 0x04, 0x36, 0x8a, 0x5f, 0xe8, 0xd1, 0x8a, 0x95, 0x84, 0xc4, 0x3e, 0x0f, 0x93, 
                0x29, 0x2f, 0x00, 0xc1, 0x53, 0xfd, 0xbc, 0x06, 0x07, 0xed, 0xd5, 0x91, 0x56, 0xc2, 0x07, 0x4a, 
                0xdf, 0x6f, 0x45, 0x60, 0xd4, 0x36, 0x35, 0x3c, 0x1b, 0xa1, 0xdd, 0xc4, 0x97, 0xa7, 0x9d, 0x81, 
                0x62, 0xb4, 0x03, 0x93, 0x81, 0xcc, 0xcb, 0xf0, 0x5b, 0xc7, 0x8c, 0x6c, 0x81, 0x0d, 0x61, 0x47, 
                0xf3, 0x04, 0x3e, 0xce, 0xc7, 0x37, 0x56, 0x91, 0x87, 0x10, 0x4b, 0xde, 0x16, 0xac, 0x46, 0xfc, 
                0x89, 0x7d, 0xa9, 0xe0, 0x98, 0xc0, 0x1d, 0xa1, 0x1b, 0x4b, 0x0e, 0x25, 0x24, 0xdf, 0x0d, 0xd0 
            }
        },
        .ucRsved = 0x4d,
        .uiRsved1 = 0x329612d3,
        .uiCheckSum = 0x7e6952d4
    },
    .aucHdcp1XKeyId = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
    .aucHdcp2XKeyId = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
    .bUseDefaultKey = HV_TRUE,
    .bHdcp1XValid = HV_TRUE,
    .bHdcp2XValid = HV_TRUE,
    .bModifyFlag = HV_FALSE
};
#else
static HDCPDataDBRegion s_stDefaultHDCPDataDBRegion =
{
    .usCheckCrc = 0x0,
    .usVersion = 0x0,
    .uiMagicNumber = DATABASE_VALID_MAGIC_NUMBER,
    .stKey =
    {
        .stHdcp1xRxKey =
        {
            /*Bksv key input hear*/
            .aucBksv =
            {
                0xb5, 0x93, 0x68, 0xca, 0xb4
            },
            /*Dks key input hear*/
            .aucDks =
            {
                0x99, 0x1b, 0x46, 0x9c, 0x8c, 0xf9, 0xd0, 0xfd,
                0xfe, 0x1b, 0xf3, 0x91, 0x21, 0x7e, 0xd8, 0x18,
                0xb3, 0x87, 0x4b, 0x05, 0xbf, 0x1f, 0x47, 0xd8,
                0xed, 0x6a, 0x14, 0x48, 0xd6, 0x17, 0x00, 0x08,
                0x4b, 0x3f, 0x2e, 0x49, 0x9c, 0x9e, 0x12, 0xa6,
                0xdd, 0xee, 0x32, 0x5a, 0xc6, 0x35, 0xdb, 0xf2,
                0x93, 0x38, 0x53, 0x59, 0x10, 0xaf, 0xcc, 0x90,
                0x0c, 0x9c, 0x16, 0xba, 0xb6, 0x94, 0xc4, 0x8c,
                0xcd, 0xcf, 0x70, 0xa0, 0xa2, 0xae, 0xbb, 0xfc,
                0xac, 0x2d, 0x67, 0x98, 0x92, 0xff, 0x2e, 0xdb,
                0x97, 0x45, 0x87, 0x49, 0x93, 0x49, 0x69, 0x3b,
                0xaf, 0xa2, 0xe5, 0x56, 0x51, 0x71, 0x24, 0xc3,
                0xf3, 0x3f, 0x5f, 0xf0, 0xc3, 0xba, 0x84, 0xbc,
                0x05, 0xa9, 0x70, 0xa4, 0x9a, 0x09, 0x88, 0xe8,
                0xc7, 0x84, 0x55, 0xb2, 0x25, 0x64, 0xf2, 0xcf,
                0x8a, 0x86, 0x69, 0x0b, 0x1c, 0x93, 0xcb, 0x0a,
                0x41, 0x60, 0x12, 0xd9, 0x8a, 0x51, 0xea, 0x39,
                0x32, 0x70, 0xda, 0x53, 0xbf, 0x4f, 0x7e, 0xf6,
                0xc3, 0xe8, 0x9d, 0x90, 0x72, 0x58, 0xfc, 0x0e,
                0x4d, 0xcd, 0xbd, 0x1a, 0x0c, 0x50, 0x96, 0x70,
                0x88, 0x14, 0x60, 0x7b, 0x08, 0x72, 0xbc, 0xe8,
                0xdd, 0x9b, 0x29, 0x10, 0x3b, 0xce, 0x1c, 0xef,
                0x25, 0x9a, 0x9e, 0xcf, 0x11, 0x3f, 0x77, 0x48,
                0xe4, 0xab, 0x8c, 0xc6, 0x39, 0xad, 0x03, 0xbd,
                0x5d, 0x52, 0x06, 0xcf, 0x1c, 0xf7, 0x8a, 0xbe,
                0x24, 0x9b, 0xe5, 0x7d, 0x55, 0x8d, 0x70, 0x3d,
                0x59, 0xe3, 0x93, 0xea, 0xb9, 0x2c, 0x85, 0x6e,
                0x72, 0xfb, 0x41, 0xcb, 0x2d, 0x86, 0xb1, 0x48,
                0xed, 0x0b, 0x2b, 0x58, 0x71, 0xc8, 0xb0, 0x70,
                0x18, 0x90, 0x14, 0xbc, 0xcb, 0x28, 0x9c, 0x79,
                0x79, 0x62, 0xca, 0x1e, 0xf5, 0xc3, 0x47, 0x51,
                0x43, 0x77, 0x56, 0x9e, 0xe7, 0x10, 0x45, 0x9c,
                0x80, 0xf8, 0x98, 0x56, 0x83, 0x69, 0x7f, 0x96,
                0x73, 0x1d, 0x51, 0x6f, 0x8d, 0xec, 0x37, 0x40,
                0xba, 0x93, 0xcc, 0x9d, 0x64, 0x34, 0x9d, 0x87
            }
        },
        .stHdcp2xRxKey =
        {
            .aucHdcp2xRxLc128 =
            {
                0xb5, 0xd8, 0xe9, 0xab, 0x5f, 0x8a, 0xfe, 0xca, 0x38, 0x55, 0xb1, 0xa5, 0x1e, 0xc9, 0xbc, 0x0f
            },
            .aucHdcp2xRxCert =
            {
                0xfc, 0x24, 0x4a, 0x3c, 0x8f, 0xe7, 0x07, 0xd7, 0x19, 0xb0, 0xca, 0x7d, 0x07, 0xce, 0xcc, 0xb7,
                0x3b, 0x5d, 0xfb, 0x0a, 0xc3, 0xfc, 0xbe, 0x36, 0x62, 0x34, 0x1f, 0x66, 0x45, 0x59, 0xfa, 0xe7,
                0x84, 0x4a, 0x11, 0xf2, 0x44, 0xef, 0x85, 0xb3, 0xd8, 0xca, 0x5d, 0x31, 0x18, 0x08, 0xe3, 0xfe,
                0x6b, 0xee, 0x61, 0x73, 0x67, 0x7f, 0xde, 0xa9, 0xd2, 0x16, 0xee, 0x06, 0x17, 0xae, 0x02, 0x0c,
                0x13, 0xcf, 0x8a, 0x6e, 0x52, 0xc9, 0xcc, 0x7d, 0x8d, 0xbe, 0x81, 0x64, 0x4b, 0x0a, 0xe2, 0x49,
                0xc3, 0xc0, 0x86, 0x2a, 0xc3, 0x24, 0x84, 0x7f, 0xa7, 0x45, 0x60, 0x96, 0xe4, 0x59, 0x51, 0x0b,
                0x3c, 0x00, 0x09, 0x5f, 0xb5, 0x8b, 0x6c, 0xc0, 0x06, 0x6b, 0x48, 0xb3, 0xf1, 0x64, 0x32, 0x29,
                0x79, 0xf0, 0xe9, 0xd1, 0xba, 0x89, 0x04, 0x41, 0xb3, 0x81, 0x50, 0x97, 0x54, 0xc7, 0xec, 0x33,
                0xc9, 0x6d, 0xfd, 0x60, 0x3d, 0x01, 0x00, 0x01, 0x10, 0x00, 0x95, 0x8e, 0xc8, 0xca, 0x9f, 0xc2,
                0x94, 0x7f, 0x8b, 0x32, 0x98, 0xd1, 0x4d, 0x3c, 0x8e, 0xa1, 0x42, 0xa5, 0x6d, 0x87, 0x26, 0x6b,
                0xfd, 0x81, 0xbf, 0xbe, 0x51, 0x6e, 0x61, 0x46, 0x88, 0xf5, 0x0e, 0xf8, 0x56, 0x05, 0x95, 0x17,
                0x73, 0x16, 0xda, 0xd1, 0xcf, 0xb0, 0x5e, 0xb0, 0x1c, 0xab, 0x2d, 0xe6, 0x3f, 0x6d, 0xca, 0x8e,
                0xd2, 0x72, 0x4b, 0xd6, 0xf2, 0x29, 0x2a, 0x62, 0x74, 0xfe, 0x5a, 0xf4, 0x0d, 0xdb, 0x08, 0xa2,
                0xa6, 0x41, 0xe3, 0xed, 0xd6, 0xe4, 0xbe, 0xeb, 0x76, 0xd0, 0x07, 0x1c, 0xf4, 0x6e, 0xd2, 0x5b,
                0xc8, 0x89, 0xd7, 0x2d, 0xc5, 0x3a, 0xaa, 0xf9, 0xe6, 0x02, 0x21, 0xc5, 0xee, 0x4e, 0xa9, 0x93,
                0x40, 0xf4, 0xe6, 0xb3, 0x1e, 0xfe, 0x9f, 0x89, 0xf5, 0xc1, 0xfe, 0x36, 0x9a, 0x1c, 0xb8, 0x0f,
                0xd0, 0xa8, 0xbc, 0x00, 0x81, 0x1b, 0xe4, 0xbb, 0xf5, 0x7b, 0x52, 0x5b, 0x52, 0x21, 0xf1, 0xf7,
                0xfe, 0xd9, 0x3b, 0x68, 0xf9, 0xde, 0xa8, 0x73, 0xff, 0x63, 0x9e, 0x38, 0xe2, 0xac, 0xaa, 0x55,
                0x40, 0xbc, 0x7a, 0xc8, 0xbc, 0x8c, 0xe8, 0x4e, 0x5b, 0x7e, 0xc0, 0x06, 0x9e, 0xb3, 0x49, 0x3f,
                0x29, 0xd8, 0x16, 0x5e, 0x99, 0xee, 0xc9, 0x35, 0x86, 0x7b, 0xb8, 0xa5, 0x24, 0xd4, 0x23, 0xbb,
                0x5c, 0x81, 0x66, 0xa7, 0x21, 0x21, 0x64, 0x5c, 0x98, 0x87, 0x72, 0x9b, 0x86, 0x8b, 0xfd, 0xd3,
                0x8e, 0x50, 0x9a, 0x21, 0xae, 0x1e, 0x70, 0x7c, 0x7e, 0xf7, 0x50, 0xc3, 0x79, 0xaa, 0xe7, 0x7a,
                0x14, 0x28, 0x7b, 0x2b, 0x0c, 0xf8, 0xce, 0xe2, 0x46, 0xcf, 0xeb, 0x95, 0x1d, 0xff, 0x72, 0xab,
                0x8d, 0xa9, 0x2a, 0x6a, 0xe0, 0x9b, 0x72, 0x44, 0x70, 0xbe, 0x7f, 0xa5, 0x2a, 0x2c, 0xb4, 0xed,
                0x96, 0x44, 0x48, 0x80, 0x90, 0x60, 0x87, 0x21, 0x1e, 0xb6, 0xfb, 0xa8, 0xfc, 0x92, 0x14, 0xcb,
                0xe8, 0x0e, 0x3a, 0x50, 0x98, 0x7d, 0x43, 0x3d, 0x18, 0xc5, 0xe2, 0xbf, 0x94, 0xb3, 0xcd, 0xee,
                0xe1, 0x4f, 0x58, 0x3e, 0x08, 0xe7, 0x74, 0xae, 0x24, 0xb9, 0x8a, 0x72, 0x0e, 0x6f, 0x17, 0x70,
                0xf8, 0x81, 0x04, 0x5e, 0xbe, 0x5d, 0xed, 0x30, 0x81, 0x9f, 0xb1, 0x06, 0x98, 0x15, 0x97, 0xab,
                0x03, 0x8d, 0x7d, 0x9d, 0xb2, 0x4e, 0xdc, 0x0d, 0xb0, 0x25, 0xcf, 0xa5, 0x48, 0x73, 0x4d, 0x60,
                0xfc, 0x6d, 0x4b, 0x09, 0xae, 0x59, 0x21, 0xcf, 0xd5, 0x6b, 0xe0, 0x24, 0x83, 0x00, 0x1b, 0xfb,
                0x27, 0x09, 0x48, 0xc5, 0x28, 0x95, 0xea, 0x1b, 0xd3, 0x7f, 0xec, 0x45, 0xc4, 0x1a, 0x79, 0x37,
                0xe8, 0xe1, 0xb6, 0x33, 0x3b, 0x4c, 0x54, 0x87, 0x27, 0x9f, 0x32, 0x70, 0xb1, 0x31, 0x84, 0x22,
                0xbe, 0x54, 0x4f, 0xcd, 0xeb, 0x4e, 0xfc, 0x68, 0xc4, 0xe2
            },
            .aucHdcp2xRxPrivKey =
            {
                0xf6, 0x1c, 0x97, 0xce, 0x1f, 0x6b, 0x27, 0xb5, 0x2b, 0xe6, 0xff, 0x25, 0x98, 0xc3, 0x02, 0x79,
                0xa7, 0x90, 0xbb, 0xc6, 0x64, 0xaf, 0x98, 0x44, 0xb0, 0x01, 0xe0, 0xf7, 0x73, 0xe3, 0xd5, 0x2b,
                0x5a, 0x43, 0x3e, 0xc3, 0xe1, 0x52, 0x52, 0x30, 0x56, 0x5a, 0xe3, 0x5e, 0xc2, 0xc0, 0x17, 0xbf,
                0x88, 0x21, 0xe3, 0x91, 0x61, 0x51, 0xd7, 0xdd, 0x82, 0xfb, 0x4d, 0x41, 0x90, 0xd9, 0x2c, 0xd7,
                0xf0, 0x50, 0x21, 0x20, 0x95, 0x8e, 0x87, 0x85, 0xb9, 0x22, 0x6d, 0x0b, 0xfd, 0x70, 0xfc, 0x3f,
                0xec, 0xc2, 0x2d, 0x6e, 0xcf, 0xa1, 0xed, 0xeb, 0x5d, 0xf9, 0x74, 0x96, 0xbf, 0x37, 0x29, 0x41,
                0xe5, 0xf0, 0x2d, 0x7c, 0x3f, 0x17, 0x98, 0xfa, 0xa8, 0x7f, 0xbb, 0x65, 0xb0, 0xc1, 0x66, 0x27,
                0x77, 0x2a, 0xb1, 0x3c, 0xb0, 0xaa, 0xd5, 0x53, 0x78, 0xd2, 0xba, 0x1c, 0x80, 0x31, 0xc5, 0x0b,
                0x32, 0x4d, 0x67, 0xcd, 0xae, 0x68, 0x45, 0x66, 0x67, 0x41, 0xc0, 0x76, 0x9b, 0xc1, 0x87, 0xf8,
                0xfb, 0x81, 0xbe, 0x8f, 0x6f, 0x36, 0xe0, 0xa5, 0x71, 0x60, 0x00, 0xee, 0x32, 0xd6, 0xa7, 0x54,
                0x44, 0x0f, 0xa8, 0x7d, 0x7a, 0xc9, 0x4b, 0x99, 0x2b, 0x9d, 0x4a, 0x09, 0xad, 0x3e, 0x7b, 0xdc,
                0x1e, 0xe3, 0xe6, 0x52, 0x69, 0x94, 0xc3, 0xcd, 0x37, 0x9f, 0x4b, 0x8c, 0x12, 0x22, 0x01, 0x63,
                0xe1, 0xa8, 0x1c, 0xb3, 0x60, 0x3c, 0xaa, 0x7d, 0xa3, 0x4e, 0xf4, 0x5e, 0xe1, 0xea, 0x0a, 0xb4,
                0x6c, 0x3a, 0x1a, 0x37, 0x87, 0xb9, 0x62, 0x94, 0x35, 0x76, 0x5d, 0x48, 0x80, 0xdd, 0xe7, 0x5b,
                0xfd, 0xf2, 0xfe, 0x83, 0x41, 0x2b, 0x83, 0x77, 0x3c, 0x6a, 0x55, 0x2a, 0x34, 0x44, 0x27, 0x0c,
                0xc0, 0x15, 0xd2, 0xc0, 0x4e, 0x94, 0xdc, 0x24, 0xb9, 0xbc, 0x07, 0x0f, 0x64, 0x41, 0x57, 0xe9,
                0x0c, 0x7b, 0x10, 0x3b, 0xe2, 0x1c, 0x6b, 0x0c, 0x2a, 0x5e, 0x02, 0x6e, 0xfd, 0x9e, 0x9f, 0xe0,
                0xb6, 0xcb, 0xc4, 0xe2, 0x75, 0x25, 0x6d, 0xaf, 0x82, 0x7f, 0x7b, 0x16, 0x67, 0x86, 0x3c, 0x70,
                0x04, 0x71, 0xcd, 0xf6, 0xc7, 0xa2, 0xe0, 0x41, 0xec, 0x26, 0x29, 0xce, 0x89, 0xaa, 0x3f, 0xae,
                0xc5, 0x0d, 0xc6, 0x6e, 0xbf, 0xb5, 0xdc, 0x01, 0x5a, 0x56, 0x0e, 0x29, 0x1a, 0xfb, 0xe5, 0x1c
            }
        },
        .ucRsved = 0x00,
        .uiRsved1 = 0x00000000,
        .uiCheckSum = 0x00000000
    },
    .aucHdcp1XKeyId = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
    .aucHdcp2XKeyId = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
    .bUseDefaultKey = HV_TRUE,
    .bHdcp1XValid = HV_TRUE,
    .bHdcp2XValid = HV_TRUE,
    .bModifyFlag = HV_FALSE
};
#endif

static GammaDataDBRegion s_stDefaultGammaDataDBRegion ={
    .ucGmaNum = 0x1,
    .aucGammaIndex={
        0x22,0, 0, 0, 0, 0, 0
    },
    .auiGamma = {
    #include"hv_Database_Pq_DefaultGamma.h"
    },
    .ucGammaCompress = 0,
};



/*Gamma load from flash*/
static GammaDataDBRegion s_stGammaDataDBRegion = {0};

/*User data load from flash*/
static UserDataDBRegion s_stUserDataDBRegion = {0};
#ifdef CONFIG_DB_USERDATA
static UserDataDBRegion s_stUserBackDBRegion = {0};
#endif

/*Factory data load from flash*/
static FactoryDataDBRegion s_stFactoryDataDBRegion = {0};

/*TimeRecord data load from flash*/
static TimeRecDBRegion s_stTimeRecDBRegion = {0};

/*System data load from flash*/
static SystemDataDBRegion s_stSystemDataDBRegion = {0};

/*hdcp load from flash*/
static HDCPDataDBRegion s_stHDCPDataDBRegion = {0};
/*hdmiedid load from flash*/
static HdmiEdidDBRegion s_stHdmiEdidDBRegion = {0};
static HdmiEdidDBRegion s_stHdmi1EdidDBRegion = {0};
/*dpedid load from flash*/
static DpEdidDBRegion s_stDpEdidDBRegion = {0};
static DpEdidDBRegion s_stDp1EdidDBRegion = {0};



/*Diag data*/
static DiagDataDBRegion s_stDiagDataDBRegion =
{
    .stDisplayDebug =
    {
        .ucVideoDataPathMode = 0,
        .usMaxMainFrameBufferHsize = PANEL_H_ACTIVE,
        .usMaxMainFrameBufferVsize = PANEL_V_ACTIVE,

        .usMaxPipFrameBufferHsize = PANEL_H_ACTIVE / 2,
        .usMaxPipFrameBufferVsize = PANEL_V_ACTIVE / 2,
        .bHflipEnable = 0,
        .bVflipEnable = 0,
    },
    
    .ucDBHueR = 128,
    .ucDBHueG = 128,
    .ucDBHueB = 128,
    .ucDBHueC = 128,
    .ucDBHueY = 128,
    .ucDBHueM = 128,

    .ucDBSatR = 128,
    .ucDBSatG = 128,
    .ucDBSatB = 128,
    .ucDBSatC = 128,
    .ucDBSatY = 128,
    .ucDBSatM = 128,

    .ucDBLumR = 128,
    .ucDBLumG = 128,
    .ucDBLumB = 128,
    .ucDBLumC = 128,
    .ucDBLumY = 128,
    .ucDBLumM = 128,

    .ucDBHueAll =
    {
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
    },
    .ucDBSatAll =
    {
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
    },
    .ucDBLumAll =
    {
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
        0x80,0x80, 0x80,0x80, 0x80,0x80, 0x80,0x80,
    },

    .ucDBPqBypassEn = 0,
    .bModifyFlag = HV_FALSE,
};

DpEdidDBRegion s_stDefaultDpEdidDBRegion = 
{
    .usCheckCrc = 0x0000,
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_DEFAULT_EDID)
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_PXP)
    .ucNumber = 3,
#else
    .ucNumber = 1,
#endif
#else
    .ucNumber = 0,
#endif
    .uiMagicNumber = DATABASE_VALID_MAGIC_NUMBER,
    .astDpEdid =
    {
#ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_QHD
        /* QHD165Hz */
        {
            .eEdidType = EDID_TYPE_DEFAULT,
            .uiEdidLen = 512,
            .acEdid =
            {
                #include "hv_edid_DP_QHD165Hz_VRR.h"
            }
        },
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_PXP)
        /* PBP */
        {
            .eEdidType = EDID_TYPE_PBP,
            .uiEdidLen = 512,
            .acEdid =
            {
                #include "hv_edid_DP_PBP.h"
            }
        },

        /* PIP */
        {
            .eEdidType = EDID_TYPE_PIP,
            .uiEdidLen = 512,
            .acEdid =
            {
                #include "hv_edid_DP_PIP.h"
            }
        },
#endif /* End of PXP */
#endif /* End of QHD */

#ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_UHD
        /* 4K60Hz */
        {
            .eEdidType = EDID_TYPE_DEFAULT,
            .uiEdidLen = 512,
            .acEdid =
            {
                #include "hv_edid_DP_4K60Hz_VRR.h"
            }
        },
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_PXP)
        /* PBP */
        {
            .eEdidType = EDID_TYPE_PBP,
            .uiEdidLen = 512,
            .acEdid =
            {
                #include "hv_edid_DP_PBP_UHD.h"
            }
        },

        /* PIP */
        {
            .eEdidType = EDID_TYPE_PIP,
            .uiEdidLen = 512,
            .acEdid =
            {
                #include "hv_edid_DP_PIP_UHD.h"
            }
        },
#endif /* End of PXP */
#endif /* End of UHD */
    },
};

HdmiEdidDBRegion s_stDefaultHdmiEdidDBRegion = 
{
    .usCheckCrc = 0x0,
    .uiMagicNumber = DATABASE_VALID_MAGIC_NUMBER,
    .astHdmiEdid =
    {
#ifdef  CONFIG_USER_PANEL_RESOLUTION_TYPE_UHD
        {
            .eEdidType = EDID_TYPE_DEFAULT,
            .uiEdidLen = 256,
            .acEdid =
            {
                #include "hv_edid_HdmiFRL_3840X2160@60.h"
            }
        },
        {
            .eEdidType = EDID_TYPE_TMDS,
            .uiEdidLen = 256,
            .acEdid =
            {
                #include "hv_edid_HdmiTMDS_3840X2160@60.h"
            }
        },
        {
            .eEdidType = EDID_TYPE_TMDS_VRR,
            .uiEdidLen = 256,
            .acEdid =
            {
                #include "hv_edid_HdmiTMDS_3840X2160@60.h"
            }
        },
        {
            .eEdidType = EDID_TYPE_FRL,
            .uiEdidLen = 256,
            .acEdid =
            {
                #include "hv_edid_HdmiFRL_3840X2160@60.h"
            }
        },
        {
            .eEdidType = EDID_TYPE_FRL_VRR,
            .uiEdidLen = 256,
            .acEdid =
            {
                #include "hv_edid_HdmiFRL_3840X2160@60.h"
            }
        },
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_PXP)
        {
            .eEdidType = EDID_TYPE_PBP,
            .uiEdidLen = 256,
            .acEdid =
            {
                #include "hv_edid_HdmiPBP_1920X2160@60.h"
            }
        },
        {
            .eEdidType = EDID_TYPE_PIP,
            .uiEdidLen = 256,
            .acEdid =
            {
                #include "hv_edid_HdmiPIP_1920X1080@60.h"
            }
        },
#endif
#else
        /* QHD144Hz User Define */
        {
            .eEdidType = EDID_TYPE_DEFAULT,
            .uiEdidLen = 512,
            .acEdid =
            {
#ifdef CONFIG_USER_HKC_EDP_SN270ES01_QHD165
                #include "hv_edid_HdmiFRL_NoVRR_2560X1440@165.h"
#else
                #include "hv_edid_HdmiFRL_NoVRR_2560X1440@180.h"
#endif
            }
        },
        /* QHD144Hz */
        {
            .eEdidType = EDID_TYPE_TMDS,
            .uiEdidLen = 256,
            .acEdid =
            {
                #include "hv_edid_HdmiTMDS_NoVRR_2560X1440@144.h"
            }
        },
        /* QHD144Hz */
        {
            .eEdidType = EDID_TYPE_TMDS_VRR,
            .uiEdidLen = 256,
            .acEdid =
            {
                #include "hv_edid_HdmiTMDS_FreeSyncVRR_2560X1440@144.h"
            }
        },
        {
            .eEdidType = EDID_TYPE_FRL,
            .uiEdidLen = 512,
            .acEdid =
            {
#ifdef CONFIG_USER_HKC_EDP_SN270ES01_QHD165
                #include "hv_edid_HdmiFRL_NoVRR_2560X1440@165.h"
#else
                #include "hv_edid_HdmiFRL_NoVRR_2560X1440@180.h"
#endif
            }
        },
        /* QHD144Hz */
        {
            .eEdidType = EDID_TYPE_FRL_VRR,
            .uiEdidLen = 512,
            .acEdid =
            {
#ifdef CONFIG_USER_HKC_EDP_SN270ES01_QHD165
                #include "hv_edid_HdmiFRL_FreeSyncVRR_2560X1440@165.h"
#else
                #include "hv_edid_HdmiFRL_FreeSyncVRR_2560X1440@180.h"
#endif
            }
        },
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_PXP)
        {
            .eEdidType = EDID_TYPE_PBP,
            .uiEdidLen = 256,
            .acEdid =
            {
                #include "hv_edid_HdmiPBP_1280X1440@60.h"
            }
        },
        {
            .eEdidType = EDID_TYPE_PIP,
            .uiEdidLen = 256,
            .acEdid =
            {
                #include "hv_edid_HdmiPIP_1280X720@60.h"
            }
        },
#endif
#endif

    },
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_DEFAULT_EDID)
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_PXP)
    .ucNumber = 7,
#else
    .ucNumber = 5,
#endif
#else
    .ucNumber = 0,
#endif
    .bModifyFlag = HV_FALSE
};

UserDataDBRegion* Hv_Common_Db_GetUserDataDBRegionPtr(VOID)
{
    return &s_stUserDataDBRegion;
}

FactoryDataDBRegion* Hv_Common_Db_GetFactoryDataDBRegionPtr(VOID)
{
    return &s_stFactoryDataDBRegion;
}

volatile FactoryDataDBRegion* Hv_Common_Db_GetDefaultFactoryDataDBRegionPtr(VOID)
{
    return &s_stDefaultFactoryDataDBRegion;
}

TimeRecDBRegion* Hv_Common_Db_GetTimeRecDBRegionPtr(VOID)
{
    return &s_stTimeRecDBRegion;
}

SystemDataDBRegion* Hv_Common_Db_GetSystemDataDBRegionPtr(VOID)
{
    return &s_stSystemDataDBRegion;
}

DiagDataDBRegion* Hv_Common_Db_GetDiagDataDBRegionPtr(VOID)
{
    return &s_stDiagDataDBRegion;
}

HDCPDataDBRegion* Hv_Common_Db_GetHDCPDataDBRegionPtr(VOID)
{
    return &s_stDefaultHDCPDataDBRegion;
}

HDCPKeyDataDBRegion* Hv_Common_Db_GetHDCPKeyDataDBRegionPtr(VOID)
{
    return &s_stDefaultHDCPDataDBRegion.stKey;
}

GammaDataDBRegion* Hv_Common_Db_GetGammaDataDBRegionPtr(VOID)
{
    return &s_stGammaDataDBRegion;
}

HdmiEdidDBRegion* Hv_Common_Db_GetHdmiEdidDBRegionPtr(VOID)
{
    return &s_stHdmiEdidDBRegion;
}

HdmiEdidDBRegion* Hv_Common_Db_GetHdmi1EdidDBRegionPtr(VOID)
{
    return &s_stHdmi1EdidDBRegion;
}

DpEdidDBRegion* Hv_Common_Db_GetDpEdidDBRegionPtr(VOID)
{
    return &s_stDpEdidDBRegion;
}

DpEdidDBRegion* Hv_Common_Db_GetDp1EdidDBRegionPtr(VOID)
{
    return &s_stDp1EdidDBRegion;
}

PanelDataDBRegion* Hv_Common_Db_GetPanelDataDBRegionPtr(VOID)
{
    return Hv_Panel_GetPanelDataDBRegionPtr();
}

UINT32 Hv_Common_Db_GetUserDataDBRegionAddress(VOID)
{
    return USER_DATA_START_ADDRESS;
}

UINT32 Hv_Common_Db_GetFactoryDataDBRegionAddress(VOID)
{
    return FACTORY_DATA_START_ADDRESS;
}

UINT32 Hv_Common_Db_GetSystemDataDBRegionAddress(VOID)
{
    return SYSTEM_DATA_START_ADDRESS;
}
UINT32 Hv_Common_Db_GetHDCPDataDBRegionAddress(VOID)
{
    return HDCP_DATA_START_ADDRESS;
}

UINT32 Hv_Common_Db_GetGammaDataDBRegionAddress(VOID)
{
    return GAMMA_DATA_START_ADDRESS;
}

UINT32 Hv_Common_Db_GetDpEdidDBRegionAddress(VOID)
{
    return DPEDID_DATA_START_ADDRESS;
}

UINT32 Hv_Common_Db_GetHdmiEdidDBRegionAddress(VOID)
{
    return HDMIEDID_DATA_START_ADDRESS;
}

UINT32 Hv_Common_Db_GetPanelDataDBRegionAddress(VOID)
{
    return PANEL_DATA_START_ADDRESS;
}

UINT32 Hv_Common_Db_GetTimeRecDBRegionAddress(VOID)
{
    return TIME_DATA_START_ADDRESS;
}

static USHORT16 _CRC16(UCHAR8 *pucData, UINT32 uiSize)
{
    USHORT16 usCrc  = 0xFFFF;
    UINT32 uiLoop   = 0;
    UCHAR8 ucIndex  = 0;

    /* skip crc self. */
    for (uiLoop = 2; uiLoop < uiSize; uiLoop++)
    {
        usCrc ^= pucData[uiLoop];
        for (ucIndex = 0; ucIndex < 8; ucIndex++)
        {
            if (usCrc & 0x0001)
            {
                usCrc >>= 1;
                usCrc ^= 0xa001;
            }
            else
            {
                usCrc >>= 1;
            }
        }
    }

    return usCrc;
}


UCHAR8 HV_Common_GetHdmiEdidStatus(VOID)
{
    return HV_R8(HV_R32(SW_DUMMY_PQTOOL_FAC_HDMIEDID)-OFFSET_OF(HdmiEdidDBRegion, astHdmiEdid)+OFFSET_OF(HdmiEdidDBRegion, bModifyFlag))&0xff;
}

VOID HV_Common_SetHdmiEdidStatus(UCHAR8 ucStatus)
{

    Hv_Common_Db_GetHdmiEdidDBRegionPtr()->bModifyFlag      = ucStatus;
    HV_W8((HV_R32(SW_DUMMY_PQTOOL_FAC_HDMIEDID)-OFFSET_OF(HdmiEdidDBRegion, astHdmiEdid)+OFFSET_OF(HdmiEdidDBRegion, bModifyFlag)), ucStatus);
    return;
}

VOID HV_Common_SetHdmiEdidMagic(UINT32 uiMagic)
{
    HV_W32((HV_R32(SW_DUMMY_PQTOOL_FAC_HDMIEDID)-OFFSET_OF(HdmiEdidDBRegion, astHdmiEdid)+OFFSET_OF(HdmiEdidDBRegion, uiMagicNumber)), uiMagic);
    return;
}

UCHAR8 HV_Common_GetHdmi1EdidStatus(VOID)
{
    return HV_R8(HV_R32(SW_DUMMY_PQTOOL_FAC_HDMI1EDID)-OFFSET_OF(HdmiEdidDBRegion, astHdmiEdid)+OFFSET_OF(HdmiEdidDBRegion, bModifyFlag))&0xff;
}

VOID HV_Common_SetHdmi1EdidStatus(UCHAR8 ucStatus)
{

    Hv_Common_Db_GetHdmi1EdidDBRegionPtr()->bModifyFlag      = ucStatus;
    HV_W8((HV_R32(SW_DUMMY_PQTOOL_FAC_HDMI1EDID)-OFFSET_OF(HdmiEdidDBRegion, astHdmiEdid)+OFFSET_OF(HdmiEdidDBRegion, bModifyFlag)), ucStatus);
    return;
}

VOID HV_Common_SetHdmi1EdidMagic(UINT32 uiMagic)
{
    HV_W32((HV_R32(SW_DUMMY_PQTOOL_FAC_HDMI1EDID)-OFFSET_OF(HdmiEdidDBRegion, astHdmiEdid)+OFFSET_OF(HdmiEdidDBRegion, uiMagicNumber)), uiMagic);
    return;
}

UCHAR8 HV_Common_GetDpEdidStatus(VOID)
{
    return HV_R8(HV_R32(SW_DUMMY_PQTOOL_FAC_DPEDID)-OFFSET_OF(DpEdidDBRegion, astDpEdid)+OFFSET_OF(DpEdidDBRegion, bModifyFlag))&0xff;
}

VOID HV_Common_SetDpEdidStatus(UCHAR8 ucStatus)
{

    HV_W8((HV_R32(SW_DUMMY_PQTOOL_FAC_DPEDID)-OFFSET_OF(DpEdidDBRegion, astDpEdid)+OFFSET_OF(DpEdidDBRegion, bModifyFlag)), ucStatus);
    return;
}

VOID HV_Common_SetDpEdidMagic(UINT32 uiMagic)
{
    HV_W32((HV_R32(SW_DUMMY_PQTOOL_FAC_DPEDID)-OFFSET_OF(DpEdidDBRegion, astDpEdid)+OFFSET_OF(DpEdidDBRegion, uiMagicNumber)), uiMagic);
    return;
}

UCHAR8 HV_Common_GetDp1EdidStatus(VOID)
{
    return HV_R8(HV_R32(SW_DUMMY_PQTOOL_FAC_DP1EDID)-OFFSET_OF(DpEdidDBRegion, astDpEdid)+OFFSET_OF(DpEdidDBRegion, bModifyFlag))&0xff;
}

VOID HV_Common_SetDp1EdidStatus(UCHAR8 ucStatus)
{

    HV_W8((HV_R32(SW_DUMMY_PQTOOL_FAC_DP1EDID)-OFFSET_OF(DpEdidDBRegion, astDpEdid)+OFFSET_OF(DpEdidDBRegion, bModifyFlag)), ucStatus);
    return;
}

VOID HV_Common_SetDp1EdidMagic(UINT32 uiMagic)
{
    HV_W32((HV_R32(SW_DUMMY_PQTOOL_FAC_DP1EDID)-OFFSET_OF(DpEdidDBRegion, astDpEdid)+OFFSET_OF(DpEdidDBRegion, uiMagicNumber)), uiMagic);
    return;
}

UCHAR8 HV_Common_GetGammaStatus(VOID)
{
    return HV_R8(HV_R32(SW_DUMMY_PQTOOL_FAC_GAMMA)-OFFSET_OF(GammaDataDBRegion, ucGmaNum)+OFFSET_OF(GammaDataDBRegion, bModifyFlag))&0xff;
}

VOID HV_Common_SetGammaStatus(UCHAR8 ucStatus)
{

    HV_W8((HV_R32(SW_DUMMY_PQTOOL_FAC_GAMMA)-OFFSET_OF(GammaDataDBRegion, ucGmaNum)+OFFSET_OF(GammaDataDBRegion, bModifyFlag)), ucStatus);
    return;
}

VOID HV_Common_SetGammaMagic(UINT32 uiMagic)
{

    HV_W32((HV_R32(SW_DUMMY_PQTOOL_FAC_GAMMA)-OFFSET_OF(GammaDataDBRegion, ucGmaNum)+OFFSET_OF(GammaDataDBRegion, uiMagicNumber)), uiMagic);
    return;
}
UCHAR8 HV_Common_GetHdcpStatus(VOID)
{
    //return HV_R32(HV_R32(SW_DUMMY_PQTOOL_FAC_HDCP)+OFFSET_OF(HDCPDataDBRegion, bModifyFlag))&0xff;
    return HV_R32(HV_R32(SW_DUMMY_PQTOOL_FAC_HDCP)-OFFSET_OF(HDCPDataDBRegion, stKey)+OFFSET_OF(HDCPDataDBRegion, bModifyFlag))&0xff;
}

VOID HV_Common_SetHdcpStatus(UCHAR8 ucStatus)
{

    HV_W32((HV_R32(SW_DUMMY_PQTOOL_FAC_HDCP)-OFFSET_OF(HDCPDataDBRegion, stKey)+OFFSET_OF(HDCPDataDBRegion, bModifyFlag)), ucStatus);
    return;
}

VOID HV_Common_SetHdcpMagic(UINT32 uiMagic)
{

    HV_W32((HV_R32(SW_DUMMY_PQTOOL_FAC_HDCP)-OFFSET_OF(HDCPDataDBRegion, stKey)+OFFSET_OF(HDCPDataDBRegion, uiMagicNumber)), uiMagic);
    return;
}

VOID HV_Common_SetHdcp1Valid(UCHAR8 ucValid)
{
    HV_W8((HV_R32(SW_DUMMY_PQTOOL_FAC_HDCP)-OFFSET_OF(HDCPDataDBRegion, stKey)+OFFSET_OF(HDCPDataDBRegion, bHdcp1XValid)), ucValid);
    return;
}
VOID HV_Common_SetHdcp2Valid(UCHAR8 ucValid)
{
    HV_W8((HV_R32(SW_DUMMY_PQTOOL_FAC_HDCP)-OFFSET_OF(HDCPDataDBRegion, stKey)+OFFSET_OF(HDCPDataDBRegion, bHdcp2XValid)), ucValid);
    return;
}

static VOID UpdateEdidCecAddr(UCHAR8* aucEdidData, UINT32 uiEdidLength, UCHAR8 ucSteep)
{
    UINT32 uiBlockTagAddr    = HV_EDID_BLOCK_DATA_SIZE;
    UINT32 uiDataBlockOffset = 0;
    UCHAR8 ucDataBlockHead   = 0;
    UCHAR8 ucDataBlockLength = 0;
    USHORT16 usCheckSum      = 0;

    HV_ASSERT_VALID_PTR_VOID(aucEdidData);

    for(uiBlockTagAddr = HV_EDID_BLOCK_DATA_SIZE; uiBlockTagAddr < uiEdidLength; uiBlockTagAddr += HV_EDID_BLOCK_DATA_SIZE)
    {
        /* 超找到 CTA Block */
        if((aucEdidData)[uiBlockTagAddr] == HV_EDID_CTA_BLOCK_TAG)
        {
            for(uiDataBlockOffset = 4; uiDataBlockOffset < aucEdidData[uiBlockTagAddr + 2]; uiDataBlockOffset += (ucDataBlockLength + 1))
            {
                ucDataBlockHead = aucEdidData[uiBlockTagAddr + uiDataBlockOffset];
                ucDataBlockLength = ucDataBlockHead & 0x1F;

                ucDataBlockHead >>= 5;

                /* 查找到HDMI 1.4 DataBlock */
                if(  (ucDataBlockHead == 0x3)
                  && (uiDataBlockOffset + 6 < (aucEdidData[uiBlockTagAddr + 2]))
                  && (aucEdidData[uiBlockTagAddr + uiDataBlockOffset + 1] == 0x03)
                  && (aucEdidData[uiBlockTagAddr + uiDataBlockOffset + 2] == 0x0C)
                  && (aucEdidData[uiBlockTagAddr + uiDataBlockOffset + 3] == 0x00))
                {
                    /* 替换掉HDMI CEC地址及CheckSum */
                    aucEdidData[uiBlockTagAddr  + uiDataBlockOffset + 4] += ucSteep;
                    usCheckSum = aucEdidData[uiBlockTagAddr  + 127] + 0x100;
                    usCheckSum -= ucSteep;
                    aucEdidData[uiBlockTagAddr  + 127] = (UCHAR8)(usCheckSum & 0xFF);

                    return;
                }
            }
        }
    }

    return;
}

static VOID UpdateEdidFactoryInfoOnBaseBlock(UCHAR8* pucEdidUpdate)
{
    if(pucEdidUpdate[0] != 0x00 || pucEdidUpdate[1] != 0xFF || pucEdidUpdate[2] != 0xFF || pucEdidUpdate[3] != 0xFF 
        || pucEdidUpdate[4] != 0xFF || pucEdidUpdate[5] != 0xFF || pucEdidUpdate[6] != 0xFF || pucEdidUpdate[7] != 0x00)
    {
        HV_LOG_ERROR(SYSTEM, "Edid is INVALID");
        return;
    }

#if HV_PROJECT_CONFIG_EDID_UP_FCTWEEK
    const UCHAR8 ucWeek = s_stFactoryDataDBRegion.ucFactWeek;
    Hv_Mw_InputPort_InsertEdidBlockData(0x10, 0x10, pucEdidUpdate, &ucWeek);
#endif

#if HV_PROJECT_CONFIG_EDID_UP_FCTYEAR
    const UCHAR8 ucYear = s_stFactoryDataDBRegion.ucFactYear;
    Hv_Mw_InputPort_InsertEdidBlockData(0x11, 0x11, pucEdidUpdate, &ucYear);
#endif

#if HV_PROJECT_CONFIG_EDID_UP_SN_VENDOR
    UINT32 uiProductSn = s_stFactoryDataDBRegion.uiProductSN;
    Hv_Mw_InputPort_InsertEdidBlockData(0x0C, 0x0F, pucEdidUpdate, (const UCHAR8*)(&uiProductSn));
#endif

#if HV_PROJECT_CONFIG_EDID_UP_DESC_SN
    const CHAR8* pcDescSn = s_stFactoryDataDBRegion.acDescSn;
    Hv_Mw_InputPort_InsertEdidDescSn(pucEdidUpdate, pcDescSn);
#endif
}

Status Hv_Common_ToolRegInit()
{
    UINT32 uiGmaAddr = 0;
    UINT32 uiEdidAddr = 0;


    uiEdidAddr = (UINT32)(Hv_Common_Db_GetHdmiEdidDBRegionPtr());
    uiEdidAddr &= 0x7FFFFFFF;
    /* HDMI EDID For Factory */
    HV_W32(SW_DUMMY_PQTOOL_FAC_HDMIEDID, uiEdidAddr + OFFSET_OF(HdmiEdidDBRegion, astHdmiEdid));

    uiEdidAddr = (UINT32)(Hv_Common_Db_GetHdmi1EdidDBRegionPtr());
    uiEdidAddr &= 0x7FFFFFFF;
    /* HDMI1 EDID For Factory */
    HV_W32(SW_DUMMY_PQTOOL_FAC_HDMI1EDID, uiEdidAddr + OFFSET_OF(HdmiEdidDBRegion, astHdmiEdid));

    uiEdidAddr = (UINT32)(Hv_Common_Db_GetDpEdidDBRegionPtr());
    uiEdidAddr &= 0x7FFFFFFF;
    /* DP EDID For Factory */
    HV_W32(SW_DUMMY_PQTOOL_FAC_DPEDID, uiEdidAddr + OFFSET_OF(DpEdidDBRegion, astDpEdid));

    uiEdidAddr = (UINT32)(Hv_Common_Db_GetDp1EdidDBRegionPtr());
    uiEdidAddr &= 0x7FFFFFFF;
    /* DP1 EDID For Factory */
    HV_W32(SW_DUMMY_PQTOOL_FAC_DP1EDID, uiEdidAddr + OFFSET_OF(DpEdidDBRegion, astDpEdid));

    /*hdcp*/
    HV_W32(SW_DUMMY_PQTOOL_FAC_HDCP, ((UINT32)(Hv_Common_Db_GetHDCPDataDBRegionPtr()) & 0x7FFFFFFF)+OFFSET_OF(HDCPDataDBRegion, stKey));

    /*gamma*/
    uiGmaAddr = (UINT32)(Hv_Common_Db_GetGammaDataDBRegionPtr());
    uiGmaAddr &= 0x7FFFFFFF;
    HV_W32(SW_DUMMY_PQTOOL_FAC_GAMMA,  uiGmaAddr + OFFSET_OF(GammaDataDBRegion, ucGmaNum));

    return HV_SUCCESS;
}


static VOID Hv_Mw_DataBase_MonitorData_Save(UINT32 uiAddress, UCHAR8 *pucData, UINT32 uiDataSize)
{
    UINT32 uiBlkSize = 0;
    UINT32 uiBlkNum  = 0;
    UINT32 uiBlkLoop = 0;
    UINT32 uiTempAdr = 0;

    UCHAR8 *pcReadData = NULL;
    HV_LOG_DEBUG(SYSTEM, "Save uiAddress %x, size %x", uiAddress, uiDataSize);
    uiBlkSize   = ALLIGNUP16(uiDataSize);
    uiBlkNum    = SECTOR_SIZE / uiBlkSize;
    HV_LOG_DEBUG(SYSTEM, "Save uiBlkSize %x, uiBlkNum %x", uiBlkSize, uiBlkNum);
    pcReadData = Hv_Vos_Malloc(uiBlkSize);
    if (NULL == pcReadData)
    {
        return;
    }

    for (uiBlkLoop = 0; uiBlkLoop < uiBlkNum; uiBlkLoop++)
    {
        uiTempAdr = uiAddress + uiBlkLoop * uiBlkSize;
        HV_LOG_DEBUG(SYSTEM, "Save uiBlkLoop %x, uiTempAdr %x, uiBlkSize %x", uiBlkLoop, uiTempAdr, uiBlkSize);
        Hv_Drv_Flash_OnlyRead(uiTempAdr, pcReadData, uiBlkSize);
        if ((*(UINT32 *)pcReadData == 0xFFFFFFFF)
             && (*(UINT32 *)(pcReadData + uiBlkSize - 4) == 0xFFFFFFFF))
        {
            break;
        }
    }
    HV_LOG_DEBUG(SYSTEM, "loop over uiBlkLoop %x uiTempAdr %x", uiBlkLoop, uiTempAdr);
    if (uiBlkLoop == uiBlkNum)
    {
        HV_LOG_INFO(SYSTEM, "erase uiTempAdr %x", uiTempAdr);
        Hv_Drv_Flash_OnlyErase(uiAddress, SECTOR_SIZE);
        uiBlkLoop = 0;
    }

    Hv_Drv_Flash_OnlyWrite(uiAddress + uiBlkLoop  *uiBlkSize, pucData, uiDataSize);
    Hv_Vos_Free(pcReadData);
    return;
}

Status Hv_Mw_DataBase_MonitorData_Load(UINT32 uiAddress, UCHAR8 *pucData, UINT32 uiDataSize)
{
    UINT32 uiBlkSize = 0;
    UINT32 uiBlkNum  = 0;
    UINT32 uiBlkLoop = 0;
    UINT32 uiTempAdr = 0;

    UCHAR8 *pcReadData = NULL;
    UCHAR8 *pcTempData = NULL;
    HV_LOG_DEBUG(SYSTEM, "Load uiAddress %x, size %x", uiAddress, uiDataSize);
    uiBlkSize   = ALLIGNUP16(uiDataSize);
    uiBlkNum    = SECTOR_SIZE / uiBlkSize;
    uiTempAdr   = uiAddress;
    HV_LOG_DEBUG(SYSTEM, "Load uiBlkSize %x, uiBlkNum %x", uiBlkSize, uiBlkNum);
    pcReadData = Hv_Vos_Malloc(uiBlkSize);
    if (NULL == pcReadData)
    {
        return HV_FAILURE;
    }

    for (uiBlkLoop = uiBlkNum; uiBlkLoop > 0; uiBlkLoop--)
    {
        uiTempAdr = uiAddress + (uiBlkLoop - 1) * uiBlkSize;
        HV_LOG_DEBUG(SYSTEM, "Load uiBlkLoop %x uiTempAdr %x", uiBlkLoop - 1, uiTempAdr);
        Hv_Drv_Flash_ReadXIP(uiTempAdr, pcReadData, uiBlkSize);
        HV_LOG_DEBUG(SYSTEM, "Load over", uiBlkLoop - 1, uiTempAdr);
        if ((*(UINT32 *)pcReadData == 0xFFFFFFFF)
            && (*(UINT32 *)(pcReadData + uiBlkSize - 4) == 0xFFFFFFFF))
        {
            continue;
        }
        pcTempData = pcReadData;
        HV_LOG_DEBUG(SYSTEM, "read header %x", *(UINT32 *)pcTempData);
        pcTempData += 4;

        HV_LOG_DEBUG(SYSTEM, "read magic %x", *(UINT32 *)pcTempData);
        if (*(UINT32 *)pcTempData != DATABASE_VALID_MAGIC_NUMBER)
        {
            Hv_Vos_Free(pcReadData);
            return HV_FAILURE;
        }

        Hv_Vos_Memcpy(pucData, pcReadData, uiDataSize);
        break;
    }
    HV_LOG_DEBUG(SYSTEM, "addr %x Blk %x", uiTempAdr,uiBlkLoop);
    Hv_Vos_Free(pcReadData);
    if (0 == uiBlkLoop)
    {
        return HV_FAILURE;
    }

    return HV_SUCCESS;
}

static VOID Hv_Common_Db_InitUser(VOID)
{
    UINT32 uiSize       = 0;
    USHORT16 usCheckCrc = 0;
    UCHAR8 *pcDbData    = NULL;
    BOOL bDataBaseValid = HV_FALSE;
#ifdef CONFIG_DB_USERDATA
    USHORT16 usCheckCrcBack = 0;
    BOOL  bDataBackValid    = HV_FALSE;
    UserDataDBRegion stTempUserDataDBRegion = {0};
#endif

#ifndef HV_BOARD_CONFIG_USER_IN_E2P
    Hv_Mw_DataBase_MonitorData_Load(USER_DATA_START_ADDRESS, (UCHAR8*)&s_stUserDataDBRegion, sizeof(UserDataDBRegion));

    /*check user data valid*/
    if (DATABASE_VALID_MAGIC_NUMBER == s_stUserDataDBRegion.uiMagicNumber)
    {
        bDataBaseValid = HV_TRUE;
        if (s_stDefaultUserDataDBRegion.usVersion > s_stUserDataDBRegion.usVersion)
        {
            bDataBaseValid = HV_FALSE;
        }
        uiSize      = sizeof(UserDataDBRegion);
        pcDbData    = (UCHAR8 *)(&s_stUserDataDBRegion);
        usCheckCrc  = _CRC16(pcDbData, uiSize);
        if (s_stUserDataDBRegion.usCheckCrc != usCheckCrc)
        {
            bDataBaseValid = HV_FALSE;
            HV_LOG_DEBUG(SYSTEM, "user db check need %x, act %x!!!", s_stUserDataDBRegion.usCheckCrc, usCheckCrc);
        }
    }
    else
    {
        bDataBaseValid = HV_FALSE;
    }
    if (HV_TRUE == bDataBaseValid)
    {
        s_usUserRWVersion = s_stUserDataDBRegion.usRWVersion;
    }

#ifdef CONFIG_DB_USERDATA
    Hv_Mw_DataBase_MonitorData_Load(USER_BACK_START_ADDRESS, (UCHAR8*)&stTempUserDataDBRegion, sizeof(UserDataDBRegion));
    /*check user data valid*/
    if (DATABASE_VALID_MAGIC_NUMBER == stTempUserDataDBRegion.uiMagicNumber)
    {
        bDataBackValid = HV_TRUE;
        if (s_stDefaultUserDataDBRegion.usVersion > stTempUserDataDBRegion.usVersion)
        {
            bDataBackValid = HV_FALSE;
        }
        uiSize      = sizeof(UserDataDBRegion);
        pcDbData    = (UCHAR8 *)(&stTempUserDataDBRegion);
        usCheckCrc  = _CRC16(pcDbData, uiSize);
        if (stTempUserDataDBRegion.usCheckCrc != usCheckCrc)
        {
            bDataBackValid = HV_FALSE;
            HV_LOG_DEBUG(SYSTEM, "user back db check need %x, act %x!!!", stTempUserDataDBRegion.usCheckCrc, usCheckCrc);
        }
    }
    else
    {
        bDataBackValid = HV_FALSE;
    }
    if (HV_TRUE == bDataBackValid)
    {
        s_usUserRWVersionBack = stTempUserDataDBRegion.usRWVersion;
    }
    if ((s_usUserRWVersionBack > s_usUserRWVersion) && (s_usUserRWVersionBack != 0xffff))
    {
        Hv_Vos_Memcpy(&s_stUserDataDBRegion, &stTempUserDataDBRegion, sizeof(s_stUserDataDBRegion));
    }
    HV_LOG_DEBUG(SYSTEM, "user rwversion %d, back %d!!!", s_usUserRWVersion, s_usUserRWVersionBack);
#endif

#else
    Hv_Drv_Eeprom_Read(0, USER_DATA_START_ADDRESS, (UCHAR8*)&s_stUserDataDBRegion, sizeof(UserDataDBRegion));
    if (DATABASE_VALID_MAGIC_NUMBER != s_stUserDataDBRegion.uiMagicNumber)
    {
        bDataBaseValid = HV_FALSE;
    }
#endif

    if ((HV_FALSE == bDataBaseValid)
#ifdef CONFIG_DB_USERDATA
        && (HV_FALSE == bDataBackValid)
#endif
        )
    {
        /*copy default data to global variables*/
        Hv_Vos_Memcpy(&s_stUserDataDBRegion, &s_stDefaultUserDataDBRegion, sizeof(s_stUserDataDBRegion));
        s_stUserDataDBRegion.usStructSize = sizeof(s_stUserDataDBRegion);

        HV_LOG_DEBUG(SYSTEM, "write default user to flash!!!");

#ifndef HV_BOARD_CONFIG_USER_IN_E2P
        /*设置modify标志后，databsesync定时器超时会自动将UserDataDBRegion,FactoryDataDBRegion,SystemDataDBRegion数据反写到flash中
        这样反写flash不会占用系统启动时间!!!*/
        Hv_Common_Db_GetUserDataDBRegionPtr()->bModifyFlag = 1;
#else
        Hv_Drv_Eeprom_Write(0, USER_DATA_START_ADDRESS,  (UCHAR8*)&s_stDefaultUserDataDBRegion, sizeof(s_stUserDataDBRegion));
#endif
    }

    return;
}

static VOID Hv_Common_Db_InitSystem(VOID)
{
    UINT32 uiSize       = 0;
    USHORT16 usCheckCrc = 0;
    UCHAR8 *pcDbData    = NULL;
    BOOL bDataBaseValid = HV_FALSE;

    Hv_Mw_DataBase_MonitorData_Load(SYSTEM_DATA_START_ADDRESS, (UCHAR8*)&s_stSystemDataDBRegion, sizeof(SystemDataDBRegion));

    /*check system data valid*/
    if (DATABASE_VALID_MAGIC_NUMBER == s_stSystemDataDBRegion.uiMagicNumber)
    {
        bDataBaseValid = HV_TRUE;
        if (s_stDefaultSystemDataDBRegion.usVersion > s_stSystemDataDBRegion.usVersion)
        {
            bDataBaseValid = HV_FALSE;
        }
        uiSize      = sizeof(SystemDataDBRegion);
        pcDbData    = (UCHAR8 *)(&s_stSystemDataDBRegion);
        usCheckCrc  = _CRC16(pcDbData, uiSize);
        if (s_stSystemDataDBRegion.usCheckCrc != usCheckCrc)
        {
            bDataBaseValid = HV_FALSE;
            HV_LOG_DEBUG(SYSTEM, "system db check need %x, act %x!!!", s_stSystemDataDBRegion.usCheckCrc, usCheckCrc);
        }
    }
    else
    {
        bDataBaseValid = HV_FALSE;
    }

    if (HV_FALSE == bDataBaseValid)
    {
        /*copy default data to global variables*/
        Hv_Vos_Memcpy(&s_stSystemDataDBRegion, &s_stDefaultSystemDataDBRegion, sizeof(SystemDataDBRegion));

        HV_LOG_DEBUG(SYSTEM, "write default system to flash!!!");

        /*设置modify标志后，databsesync定时器超时会自动将UserDataDBRegion,FactoryDataDBRegion,SystemDataDBRegion数据反写到flash中
        这样反写flash不会占用系统启动时间!!!*/
        Hv_Common_Db_GetSystemDataDBRegionPtr()->bModifyFlag = 1;
    }
    return;
}

static VOID Hv_Common_Db_InitFactory(VOID)
{
    UINT32 uiSize       = 0;
    USHORT16 usCheckCrc = 0;
    UCHAR8 *pcDbData    = NULL;
    BOOL bDataBaseValid = HV_FALSE;

    Hv_Mw_DataBase_MonitorData_Load(FACTORY_DATA_START_ADDRESS, (UCHAR8*)&s_stFactoryDataDBRegion, sizeof(FactoryDataDBRegion));

    /*check facotry data valid*/
    if (DATABASE_VALID_MAGIC_NUMBER == s_stFactoryDataDBRegion.uiMagicNumber)
    {
        bDataBaseValid = HV_TRUE;
        if (s_stDefaultFactoryDataDBRegion.usVersion > s_stFactoryDataDBRegion.usVersion)
        {
            bDataBaseValid = HV_FALSE;
        }
        uiSize      = sizeof(FactoryDataDBRegion);
        pcDbData    = (UCHAR8 *)(&s_stFactoryDataDBRegion);
        usCheckCrc  = _CRC16(pcDbData, uiSize);
        if (s_stFactoryDataDBRegion.usCheckCrc != usCheckCrc)
        {
            bDataBaseValid = HV_FALSE;
            HV_LOG_DEBUG(SYSTEM, "factory db check need %x, act %x!!!", s_stFactoryDataDBRegion.usCheckCrc, usCheckCrc);
        }
    }
    else
    {
        bDataBaseValid = HV_FALSE;
    }

    if (HV_FALSE == bDataBaseValid)
    {
        /*copy default data to global variables*/
        Hv_Vos_VolatileMemcpy(&s_stFactoryDataDBRegion, &s_stDefaultFactoryDataDBRegion, sizeof(s_stFactoryDataDBRegion));

        HV_LOG_DEBUG(SYSTEM, "write default fac to flash!!!");

        s_stTimeRecDBRegion.usPanelOnTimeHour   = 0;
        s_stTimeRecDBRegion.usPanelOnTimeMin    = 0;
        s_stTimeRecDBRegion.uiMagicNumber       = DATABASE_VALID_MAGIC_NUMBER;

        /*设置modify标志后，databsesync定时器超时会自动将UserDataDBRegion,FactoryDataDBRegion,SystemDataDBRegion数据反写到flash中
        这样反写flash不会占用系统启动时间!!!*/
        Hv_Common_Db_GetFactoryDataDBRegionPtr()->bModifyFlag = 1;
        Hv_Common_Db_GetTimeRecDBRegionPtr()->bModifyFlag = 1;
    }
    else
    {
        /*copy default data to global variables*/
        UINT32 srcAddr = (UINT32)(&s_stFactoryDataDBRegion);
        UINT32 destAddr = (UINT32)(&s_stDefaultFactoryDataDBRegion);
        
        for(UINT32 uiLoop = 0; uiLoop < sizeof(s_stFactoryDataDBRegion); uiLoop++)
        {
            *((UCHAR8 *)destAddr)= *((UCHAR8 *)srcAddr);

            destAddr++;
            srcAddr++;
        }
    }

    return;
}

static VOID Hv_Common_Db_InitTimeRec(VOID)
{
    BOOL bDataBaseValid = HV_FALSE;

    Hv_Mw_DataBase_MonitorData_Load(TIME_DATA_START_ADDRESS, (UCHAR8*)&s_stTimeRecDBRegion, sizeof(TimeRecDBRegion));

    /*check time record valid*/
    if (DATABASE_VALID_MAGIC_NUMBER == s_stTimeRecDBRegion.uiMagicNumber)
    {
        bDataBaseValid = HV_TRUE;
    }
    else
    {
        bDataBaseValid = HV_FALSE;
    }
    if (HV_FALSE == bDataBaseValid)
    {
        s_stTimeRecDBRegion.usPanelOnTimeHour   = 0;
        s_stTimeRecDBRegion.usPanelOnTimeMin    = 0;
        s_stTimeRecDBRegion.uiMagicNumber       = DATABASE_VALID_MAGIC_NUMBER;

        HV_LOG_INFO(SYSTEM, "write default time to flash!!!");

        /*设置modify标志后，databsesync定时器超时会自动将UserDataDBRegion,FactoryDataDBRegion,SystemDataDBRegion数据反写到flash中
        这样反写flash不会占用系统启动时间!!!*/
        Hv_Common_Db_GetTimeRecDBRegionPtr()->bModifyFlag = 1;
    }
    return;
}

static VOID Hv_Common_Db_InitHdcp(VOID)
{
    USHORT16 usCrc = 0;
    Hv_Drv_Flash_ReadXIP(HDCP_DATA_START_ADDRESS, (UCHAR8*)&s_stHDCPDataDBRegion, sizeof(HDCPDataDBRegion));
    usCrc  = _CRC16((UCHAR8 *)&s_stHDCPDataDBRegion, sizeof(HDCPDataDBRegion));
    HV_LOG_DEBUG(SYSTEM, "%d %d", usCrc, s_stHDCPDataDBRegion.usCheckCrc);
    /*key on rom or in Code*/
    if (HV_TRUE == s_stFactoryDataDBRegion.ucUseSeperatorHDCPKey)
    {
        /*checkout HDCP ok*/
        if((s_stHDCPDataDBRegion.usCheckCrc != usCrc) ||
           (s_stHDCPDataDBRegion.uiMagicNumber != DATABASE_VALID_MAGIC_NUMBER))/*no hdcp in flash*/
        {
            HV_LOG_DEBUG(SYSTEM,"HDCP not found, use default...");
        }
        else/*hdcp on rom, copy to default*/
        {
            HV_LOG_DEBUG(SYSTEM,"HDCP found, copy to default...");
            Hv_Vos_Memcpy(&s_stDefaultHDCPDataDBRegion, &s_stHDCPDataDBRegion, sizeof(HDCPDataDBRegion));
        }
    }
    else
    {
         HV_LOG_DEBUG(SYSTEM,"use default...");
        /*use default*/
    }
    return;
}

static VOID Hv_Common_Db_InitGamma(VOID)
{
    Hv_Drv_Flash_ReadXIP(GAMMA_DATA_START_ADDRESS, (UCHAR8*)&s_stGammaDataDBRegion, sizeof(GammaDataDBRegion));
    /*check gamma OK*/
    if((s_stGammaDataDBRegion.uiMagicNumber != DATABASE_VALID_MAGIC_NUMBER)||(s_stGammaDataDBRegion.uiEndMagicNumber != GAMMA_END_MAGIC_NUMBER))
    {
        HV_LOG_INFO(SYSTEM,"GAMA not found, write...");
        UINT32 uiAddr = 0;
        uiAddr = (UINT32)Hv_Common_Db_GetSystemDataDBRegionPtr();
        Hv_Vos_Memcpy(&s_stGammaDataDBRegion, &s_stDefaultGammaDataDBRegion, sizeof(GammaDataDBRegion));
        Hv_Common_Db_GetGammaDataDBRegionPtr()->bModifyFlag = HV_TRUE;
    }
    else
    {
        HV_LOG_DEBUG(SYSTEM,"GAMMA found");
		Hv_Common_Db_GetGammaDataDBRegionPtr()->bModifyFlag = HV_FALSE;
    }
    return;
}

static VOID Hv_Common_Db_InitHdmiEdid(VOID)
{
    Hv_Drv_Flash_ReadXIP(HDMIEDID_DATA_START_ADDRESS, (UCHAR8*)&s_stHdmiEdidDBRegion, sizeof(HdmiEdidDBRegion));
    /*check HDMI edid*/
    if(s_stHdmiEdidDBRegion.uiMagicNumber != DATABASE_VALID_MAGIC_NUMBER)/*no edid found*/
    {
        HV_LOG_DEBUG(SYSTEM, "H_EDID not found");
        Hv_Vos_Memcpy(&s_stHdmiEdidDBRegion, &s_stDefaultHdmiEdidDBRegion, sizeof(HdmiEdidDBRegion));
        for(UINT32 i = 0; i < s_stHdmiEdidDBRegion.ucNumber && i < HDMI_EDID_MAX_NUMBER; i++)
        {
            UpdateEdidFactoryInfoOnBaseBlock((s_stHdmiEdidDBRegion.astHdmiEdid[i]).acEdid);
        }
    }
    else
    {
        HV_LOG_DEBUG(SYSTEM, "H_EDID found");
    }

    Hv_Drv_Flash_ReadXIP(HDMIEDID_DATA_START_ADDRESS + (4 * 1024), (UCHAR8*)&s_stHdmi1EdidDBRegion, sizeof(HdmiEdidDBRegion));
    if(s_stHdmi1EdidDBRegion.uiMagicNumber != DATABASE_VALID_MAGIC_NUMBER)/*no edid found*/
    {
        HV_LOG_DEBUG(SYSTEM, "H_EDID1 not found");
        Hv_Vos_Memcpy(&s_stHdmi1EdidDBRegion, &s_stDefaultHdmiEdidDBRegion, sizeof(HdmiEdidDBRegion));

        for(UINT32 i = 0; i < s_stHdmi1EdidDBRegion.ucNumber && i < HDMI_EDID_MAX_NUMBER; i++)
        {
            UpdateEdidFactoryInfoOnBaseBlock((s_stHdmi1EdidDBRegion.astHdmiEdid[i]).acEdid);
            UpdateEdidCecAddr((s_stHdmi1EdidDBRegion.astHdmiEdid[i]).acEdid, (s_stHdmi1EdidDBRegion.astHdmiEdid[i]).uiEdidLen, 0x10);
        }
    }
    else
    {
        HV_LOG_DEBUG(SYSTEM, "H_EDID1 found");
    }
    return;
}

static VOID Hv_Common_Db_InitDPEdid(VOID)
{
    Hv_Drv_Flash_ReadXIP(DPEDID_DATA_START_ADDRESS, (UCHAR8*)&s_stDpEdidDBRegion, sizeof(DpEdidDBRegion));
    /*check DP edid*/
    if(s_stDpEdidDBRegion.uiMagicNumber != DATABASE_VALID_MAGIC_NUMBER)/*no edid found*/
    {
        HV_LOG_DEBUG(SYSTEM, "D_EDID not found");
        Hv_Vos_Memcpy(&s_stDpEdidDBRegion, &s_stDefaultDpEdidDBRegion, sizeof(DpEdidDBRegion));

        for(UINT32 i = 0; i < s_stDpEdidDBRegion.ucNumber && i < DP_EDID_MAX_NUMBER; i++)
        {
            UpdateEdidFactoryInfoOnBaseBlock((s_stDpEdidDBRegion.astDpEdid[i]).acEdid);
        }
    }
    else
    {
        HV_LOG_DEBUG(SYSTEM, "D_EDID found");
    }
    Hv_Drv_Flash_ReadXIP(DPEDID_DATA_START_ADDRESS + (4 * 1024), (UCHAR8*)&s_stDp1EdidDBRegion, sizeof(DpEdidDBRegion));
    if(s_stDp1EdidDBRegion.uiMagicNumber != DATABASE_VALID_MAGIC_NUMBER)/*no edid found*/
    {
        HV_LOG_DEBUG(SYSTEM, "D_EDID not found");
        Hv_Vos_Memcpy(&s_stDp1EdidDBRegion, &s_stDefaultDpEdidDBRegion, sizeof(DpEdidDBRegion));

        for(UINT32 i = 0; i < s_stDp1EdidDBRegion.ucNumber && i < DP_EDID_MAX_NUMBER; i++)
        {
            UpdateEdidFactoryInfoOnBaseBlock((s_stDp1EdidDBRegion.astDpEdid[i]).acEdid);
        }
    }
    else
    {
        HV_LOG_DEBUG(SYSTEM, "D_EDID found");
    }
    return;
}

Status Hv_Common_Db_Init(VOID)
{
    Hv_Common_ToolRegInit();
    Hv_Common_Db_InitUser();
    Hv_Common_Db_InitSystem();
    Hv_Common_Db_InitFactory();
    Hv_Common_Db_InitTimeRec();
    Hv_Panel_InitPanelParam();
    /*hdcp init must after factory init. */
    Hv_Common_Db_InitHdcp();
    Hv_Common_Db_InitGamma();
    Hv_Common_Db_InitHdmiEdid();
    Hv_Common_Db_InitDPEdid();

    return HV_SUCCESS;
}

static Status Hv_Mw_DataBase_SyncUser(VOID)
{
    UINT32 uiSize   = 0;
    UINT32 uiLoop   = 0;
    USHORT16 usCheckCrc = 0;
    UCHAR8 *pcDbData    = NULL;
    UCHAR8 ucRet        = HV_SUCCESS;

    //HV_COMMON_DATABASE_SET(UserData, ucContrast, (HV_COMMON_DATABASE_GET(UserData, ucContrast)+1));
    if (HV_FALSE == HV_COMMON_DATABASE_GET(UserData, bModifyFlag))
    {
        return HV_SUCCESS;
    }

    Hv_Vos_TaskEnterCritical();
    Hv_Common_Db_GetUserDataDBRegionPtr()->usRWVersion++;
    Hv_Common_Db_GetUserDataDBRegionPtr()->bModifyFlag = 0;
    uiSize      = sizeof(UserDataDBRegion);
    pcDbData    = Hv_Vos_Malloc(uiSize);
    /*申请失败不必释放内存*/
    HV_ASSERT_VALID_PTR_RET(pcDbData, HV_FAILURE);
    Hv_Vos_Memcpy(pcDbData, Hv_Common_Db_GetUserDataDBRegionPtr(), uiSize);
    usCheckCrc  = _CRC16(pcDbData, uiSize);
    pcDbData[0] = (usCheckCrc >> 0) & 0xff;
    pcDbData[1] = (usCheckCrc >> 8) & 0xff;
    Hv_Vos_TaskExitCritical();

#ifdef CONFIG_DB_USERDATA
        if ((s_usUserRWVersionBack == 0xffff) || (s_usUserRWVersion == 0xffff))
        {
            s_usUserRWVersionBack = 0;
            s_usUserRWVersion = 0;
        }
        if (s_usUserRWVersionBack < s_usUserRWVersion)
        {
            HV_LOG_INFO(SYSTEM, "UserData back modifyed check %x, rw version %d", usCheckCrc, Hv_Common_Db_GetUserDataDBRegionPtr()->usRWVersion);
            s_usUserRWVersionBack = Hv_Common_Db_GetUserDataDBRegionPtr()->usRWVersion;
            Hv_Mw_DataBase_MonitorData_Save(USER_BACK_START_ADDRESS, (UCHAR8*)pcDbData, uiSize);
        }
        else
#endif
        {
            HV_LOG_INFO(SYSTEM, "UserData modifyed check %x, rw version %d", usCheckCrc, Hv_Common_Db_GetUserDataDBRegionPtr()->usRWVersion);
            s_usUserRWVersion = Hv_Common_Db_GetUserDataDBRegionPtr()->usRWVersion;
            Hv_Mw_DataBase_MonitorData_Save(USER_DATA_START_ADDRESS, (UCHAR8*)pcDbData, uiSize);
        }

    /*释放内存*/
    Hv_Vos_Free(pcDbData);
    return ucRet;
}

static Status Hv_Mw_DataBase_SyncSystem(VOID)
{
    UINT32 uiSize   = 0;
    UINT32 uiLoop   = 0;
    USHORT16 usCheckCrc = 0;
    UCHAR8 *pcDbData    = NULL;
    UCHAR8 ucRet        = HV_SUCCESS;

    if (HV_FALSE == HV_COMMON_DATABASE_GET(SystemData, bModifyFlag))
    {
        return HV_SUCCESS;
    }

    Hv_Vos_TaskEnterCritical();
    Hv_Common_Db_GetSystemDataDBRegionPtr()->bModifyFlag = HV_FALSE;
    uiSize      = sizeof(SystemDataDBRegion);
    pcDbData    = Hv_Vos_Malloc(uiSize);
    /*申请失败不必释放内存*/
    HV_ASSERT_VALID_PTR_RET(pcDbData, HV_FAILURE);
    Hv_Vos_Memcpy(pcDbData, Hv_Common_Db_GetSystemDataDBRegionPtr(), uiSize);
    usCheckCrc  = _CRC16(pcDbData, uiSize);
    pcDbData[0] = (usCheckCrc >> 0) & 0xff;
    pcDbData[1] = (usCheckCrc >> 8) & 0xff;
    Hv_Vos_TaskExitCritical();

    HV_LOG_INFO(SYSTEM, "SystemData modifyed check %x", usCheckCrc);
    Hv_Mw_DataBase_MonitorData_Save(SYSTEM_DATA_START_ADDRESS, (UCHAR8*)pcDbData, uiSize);

    /*释放内存*/
    Hv_Vos_Free(pcDbData);
    return ucRet;
}

Status Hv_Mw_DataBase_SyncFactory(VOID)
{
    UINT32   uiSize     = sizeof(FactoryDataDBRegion);
    USHORT16 usCheckCrc = 0;
    UCHAR8   ucRet      = HV_SUCCESS;

    if (HV_FALSE == HV_COMMON_DATABASE_GET(FactoryData, bModifyFlag))
    {
        return HV_SUCCESS;
    }

    UCHAR8   *pcDbData  = Hv_Vos_Malloc(uiSize);
    /*申请失败不必释放内存*/
    HV_ASSERT_VALID_PTR_RET(pcDbData, HV_FAILURE);

    Hv_Vos_TaskEnterCritical();

    Hv_Common_Db_GetFactoryDataDBRegionPtr()->bModifyFlag = HV_FALSE;
    Hv_Vos_Memcpy(pcDbData, Hv_Common_Db_GetFactoryDataDBRegionPtr(), uiSize);

    Hv_Vos_TaskExitCritical();

    usCheckCrc  = _CRC16(pcDbData, uiSize);

    pcDbData[0] = (usCheckCrc >> 0) & 0xff;
    pcDbData[1] = (usCheckCrc >> 8) & 0xff;

    HV_LOG_INFO(SYSTEM, "FactoryData modifyed check %x", usCheckCrc);

    HV_COMMON_DATABASE_SET(FactoryData, usCheckCrc, usCheckCrc);

    Hv_Mw_DataBase_MonitorData_Save(FACTORY_DATA_START_ADDRESS, (UCHAR8*)pcDbData, uiSize);

    /*释放内存*/
    Hv_Vos_Free(pcDbData);
    return ucRet;
}

static Status Hv_Mw_DataBase_SyncTimeRec(VOID)
{
    UINT32 uiSize   = 0;
    UINT32 uiLoop   = 0;
    USHORT16 usCheckCrc = 0;
    UCHAR8 *pcDbData    = NULL;
    UCHAR8 ucRet        = HV_SUCCESS;

    if (HV_FALSE == HV_COMMON_DATABASE_GET(TimeRec, bModifyFlag))
    {
        return HV_SUCCESS;
    }

    Hv_Vos_TaskEnterCritical();
    Hv_Common_Db_GetTimeRecDBRegionPtr()->bModifyFlag = HV_FALSE;
    uiSize      = sizeof(TimeRecDBRegion);
    pcDbData    = Hv_Vos_Malloc(uiSize);
    /*申请失败不必释放内存*/
    HV_ASSERT_VALID_PTR_RET(pcDbData, HV_FAILURE);
    Hv_Vos_Memcpy(pcDbData, Hv_Common_Db_GetTimeRecDBRegionPtr(), uiSize);
    usCheckCrc  = _CRC16(pcDbData, uiSize);
    pcDbData[0] = (usCheckCrc >> 0) & 0xff;
    pcDbData[1] = (usCheckCrc >> 8) & 0xff;
    Hv_Vos_TaskExitCritical();

    HV_LOG_INFO(SYSTEM, "TimeRec modifyed check %x", usCheckCrc);
    Hv_Mw_DataBase_MonitorData_Save(TIME_DATA_START_ADDRESS, (UCHAR8*)pcDbData, uiSize);

    /*释放内存*/
    Hv_Vos_Free(pcDbData);
    return ucRet;
}

static Status Hv_Mw_DataBase_SyncGamma(VOID)
{
    UCHAR8 ucRet = HV_SUCCESS;

    UINT32 uiI      = 0;
    UINT32 uiAddr   = 0;
    UINT32 uiValue  = 0;

    GammaDataDBRegion *pstGammaData = NULL;

    if (HV_FALSE == HV_COMMON_DATABASE_GET(GammaData, bModifyFlag))
    {
        return HV_SUCCESS;
    }

    HV_LOG_DEBUG(SYSTEM, "GammaData has modifyed");

    Hv_Vos_TaskEnterCritical();
    HV_Common_SetGammaStatus(HV_FALSE);
    HV_Common_SetGammaMagic(DATABASE_VALID_MAGIC_NUMBER);
    pstGammaData = Hv_Vos_Malloc(sizeof(GammaDataDBRegion));
    HV_ASSERT_VALID_PTR_RET(pstGammaData, HV_FAILURE);
    uiAddr = (INT32)Hv_Common_Db_GetGammaDataDBRegionPtr();
    for (uiI = 0; uiI < sizeof(pstGammaData->auiGamma) + 16; uiI++)/* 8=1(number) + 7(curve) + 4compress + 4 magic*/
    {
        uiValue  = HV_R8(HV_R32(SW_DUMMY_PQTOOL_FAC_GAMMA) + uiI);
        *((UCHAR8*)((&pstGammaData->ucGmaNum) + uiI)) = uiValue;
    }
    Hv_Vos_TaskExitCritical();
    Hv_Common_Db_GetGammaDataDBRegionPtr()->bModifyFlag     = HV_FALSE;
    Hv_Common_Db_GetGammaDataDBRegionPtr()->uiMagicNumber   = DATABASE_VALID_MAGIC_NUMBER;
    Hv_Common_Db_GetGammaDataDBRegionPtr()->uiEndMagicNumber   = GAMMA_END_MAGIC_NUMBER;
    pstGammaData->bModifyFlag   = HV_FALSE;
    pstGammaData->uiMagicNumber = DATABASE_VALID_MAGIC_NUMBER;
    pstGammaData->uiEndMagicNumber = GAMMA_END_MAGIC_NUMBER;
    ucRet = Hv_Drv_Flash_WriteMonitorData(GAMMA_DATA_START_ADDRESS, (UCHAR8*)pstGammaData , sizeof(GammaDataDBRegion));

    Hv_Vos_Free(pstGammaData);
    return ucRet;
}

Status Hv_Mw_DataBase_SyncHdmiEdid(VOID)
{
    UCHAR8 ucRet = HV_SUCCESS;

    UINT32 uiI      = 0;
    UINT32 uiAddr   = 0;
    UINT32 uiValue  = 0;

    HdmiEdidDBRegion *pstEdidData = NULL;

    if (HV_FALSE == HV_Common_GetHdmiEdidStatus())
    {
        return HV_SUCCESS;
    }

    HV_LOG_INFO(SYSTEM, "hdmiedid modifyed");

    Hv_Vos_TaskEnterCritical();
    HV_Common_SetHdmiEdidStatus(HV_FALSE);
    HV_Common_SetHdmiEdidMagic(DATABASE_VALID_MAGIC_NUMBER);
    pstEdidData = Hv_Vos_Malloc(sizeof(HdmiEdidDBRegion));
    HV_ASSERT_VALID_PTR_RET(pstEdidData, HV_FAILURE);

    for (uiI = 0; uiI < sizeof(pstEdidData->astHdmiEdid); uiI ++)
    {
        *((UCHAR8*)(((UINT32)pstEdidData) + uiI + OFFSET_OF(HdmiEdidDBRegion, astHdmiEdid))) =  HV_R8(HV_R32(SW_DUMMY_PQTOOL_FAC_HDMIEDID) + uiI); 
    }
    Hv_Vos_TaskExitCritical();
    Hv_Common_Db_GetHdmiEdidDBRegionPtr()->bModifyFlag      = HV_FALSE;
    Hv_Common_Db_GetHdmiEdidDBRegionPtr()->uiMagicNumber    = DATABASE_VALID_MAGIC_NUMBER;
    pstEdidData->bModifyFlag    = HV_FALSE;
    pstEdidData->uiMagicNumber  = DATABASE_VALID_MAGIC_NUMBER;
    pstEdidData->ucNumber = Hv_Common_Db_GetHdmiEdidDBRegionPtr()->ucNumber;

    for(UINT32 i = 0; i < pstEdidData->ucNumber && i < HDMI_EDID_MAX_NUMBER; i++)
    {
        UpdateEdidFactoryInfoOnBaseBlock(((pstEdidData->astHdmiEdid)[i]).acEdid);
    }

    ucRet = Hv_Drv_Flash_WriteMonitorData(HDMIEDID_DATA_START_ADDRESS, (UCHAR8*)pstEdidData , sizeof(HdmiEdidDBRegion));

    Hv_Vos_Free(pstEdidData);

    Hv_Mw_HdmiRx_UpdateEdidRobust(LINK_PORT_INDEX_HDMI_RX0);

    return ucRet;
}

Status Hv_Mw_DataBase_SyncHdmi1Edid(VOID)
{
    UCHAR8 ucRet = HV_SUCCESS;

    UINT32 uiI      = 0;
    UINT32 uiAddr   = 0;
    UINT32 uiValue  = 0;

    HdmiEdidDBRegion *pstEdidData = NULL;

    if (HV_FALSE == HV_Common_GetHdmi1EdidStatus())
    {
        return HV_SUCCESS;
    }

    HV_LOG_INFO(SYSTEM, "hdmi1edid modifyed");

    Hv_Vos_TaskEnterCritical();
    HV_Common_SetHdmi1EdidStatus(HV_FALSE);
    HV_Common_SetHdmi1EdidMagic(DATABASE_VALID_MAGIC_NUMBER);
    pstEdidData = Hv_Vos_Malloc(sizeof(HdmiEdidDBRegion));
    HV_ASSERT_VALID_PTR_RET(pstEdidData, HV_FAILURE);

    for (uiI = 0; uiI < sizeof(pstEdidData->astHdmiEdid); uiI ++)
    {
        *((UCHAR8*)(((UINT32)pstEdidData) + uiI + OFFSET_OF(HdmiEdidDBRegion, astHdmiEdid))) =  HV_R8(HV_R32(SW_DUMMY_PQTOOL_FAC_HDMI1EDID) + uiI); 
    }
    Hv_Vos_TaskExitCritical();
    Hv_Common_Db_GetHdmi1EdidDBRegionPtr()->bModifyFlag      = HV_FALSE;
    Hv_Common_Db_GetHdmi1EdidDBRegionPtr()->uiMagicNumber    = DATABASE_VALID_MAGIC_NUMBER;
    pstEdidData->bModifyFlag    = HV_FALSE;
    pstEdidData->uiMagicNumber  = DATABASE_VALID_MAGIC_NUMBER;
    pstEdidData->ucNumber = Hv_Common_Db_GetHdmi1EdidDBRegionPtr()->ucNumber;

    for(UINT32 i = 0; i < pstEdidData->ucNumber && i < HDMI_EDID_MAX_NUMBER; i++)
    {
        UpdateEdidFactoryInfoOnBaseBlock(((pstEdidData->astHdmiEdid)[i]).acEdid);
    }

    ucRet = Hv_Drv_Flash_WriteMonitorData(HDMIEDID_DATA_START_ADDRESS + (4 * 1024), (UCHAR8*)pstEdidData , sizeof(HdmiEdidDBRegion));

    Hv_Vos_Free(pstEdidData);

    Hv_Mw_HdmiRx_UpdateEdidRobust(LINK_PORT_INDEX_HDMI_RX1);

    return ucRet;
}

static Status Hv_Mw_DataBase_SyncDPEdid(VOID)
{
    UCHAR8 ucRet = HV_SUCCESS;

    UINT32 uiI      = 0;
    UINT32 uiAddr   = 0;
    UINT32 uiValue  = 0;

    DpEdidDBRegion *pstEdidData = NULL;

    if (HV_FALSE == HV_Common_GetDpEdidStatus())
    {
        return HV_SUCCESS;
    }

    HV_LOG_INFO(SYSTEM, "dpedid modifyed");
    Hv_Vos_TaskEnterCritical();

    HV_Common_SetDpEdidStatus(0);
    HV_Common_SetDpEdidMagic(DATABASE_VALID_MAGIC_NUMBER);
    pstEdidData = Hv_Vos_Malloc(sizeof(DpEdidDBRegion));
    HV_ASSERT_VALID_PTR_RET(pstEdidData, HV_FAILURE);

    for(uiI = 0; uiI < sizeof(pstEdidData->astDpEdid); uiI ++)
    {
        *((UCHAR8*)(((UINT32)pstEdidData) + uiI + OFFSET_OF(DpEdidDBRegion, astDpEdid))) =  HV_R8(HV_R32(SW_DUMMY_PQTOOL_FAC_DPEDID) + uiI); 
    }
    Hv_Vos_TaskExitCritical();

    Hv_Common_Db_GetDpEdidDBRegionPtr()->bModifyFlag    = HV_FALSE;
    Hv_Common_Db_GetDpEdidDBRegionPtr()->uiMagicNumber  = DATABASE_VALID_MAGIC_NUMBER;
    pstEdidData->bModifyFlag    = HV_FALSE;
    pstEdidData->uiMagicNumber  = DATABASE_VALID_MAGIC_NUMBER;
    pstEdidData->ucNumber = Hv_Common_Db_GetDpEdidDBRegionPtr()->ucNumber;

    for(UINT32 i = 0; i < pstEdidData->ucNumber && i < DP_EDID_MAX_NUMBER; i++)
    {
        UpdateEdidFactoryInfoOnBaseBlock(((pstEdidData->astDpEdid)[i]).acEdid);
        UpdateEdidFactoryInfoOnBaseBlock(((Hv_Common_Db_GetDpEdidDBRegionPtr()->astDpEdid)[i]).acEdid);
    }

    ucRet = Hv_Drv_Flash_WriteMonitorData(DPEDID_DATA_START_ADDRESS, (UCHAR8*)pstEdidData , sizeof(DpEdidDBRegion));

    Hv_Vos_Free(pstEdidData);

    Hv_Mw_DpRx_UpdtEdidRobust(LINK_PORT_INDEX_DP_RX0);

    return ucRet;
}

static Status Hv_Mw_DataBase_SyncDP1Edid(VOID)
{
    UCHAR8 ucRet = HV_SUCCESS;

    UINT32 uiI      = 0;
    UINT32 uiAddr   = 0;
    UINT32 uiValue  = 0;

    DpEdidDBRegion *pstEdidData = NULL;

    if (HV_FALSE == HV_Common_GetDp1EdidStatus())
    {
        return HV_SUCCESS;
    }

    HV_LOG_INFO(SYSTEM, "dp1edid modifyed");
    Hv_Vos_TaskEnterCritical();

    HV_Common_SetDp1EdidStatus(0);
    HV_Common_SetDp1EdidMagic(DATABASE_VALID_MAGIC_NUMBER);
    pstEdidData = Hv_Vos_Malloc(sizeof(DpEdidDBRegion));
    HV_ASSERT_VALID_PTR_RET(pstEdidData, HV_FAILURE);

    for(uiI = 0; uiI < sizeof(pstEdidData->astDpEdid); uiI ++)
    {
        *((UCHAR8*)(((UINT32)pstEdidData) + uiI + OFFSET_OF(DpEdidDBRegion, astDpEdid))) =  HV_R8(HV_R32(SW_DUMMY_PQTOOL_FAC_DP1EDID) + uiI); 
    }
    Hv_Vos_TaskExitCritical();

    Hv_Common_Db_GetDp1EdidDBRegionPtr()->bModifyFlag    = HV_FALSE;
    Hv_Common_Db_GetDp1EdidDBRegionPtr()->uiMagicNumber  = DATABASE_VALID_MAGIC_NUMBER;
    pstEdidData->bModifyFlag    = HV_FALSE;
    pstEdidData->uiMagicNumber  = DATABASE_VALID_MAGIC_NUMBER;
    pstEdidData->ucNumber = Hv_Common_Db_GetDp1EdidDBRegionPtr()->ucNumber;

    for(UINT32 i = 0; i < pstEdidData->ucNumber && i < DP_EDID_MAX_NUMBER; i++)
    {
        UpdateEdidFactoryInfoOnBaseBlock(((pstEdidData->astDpEdid)[i]).acEdid);
        UpdateEdidFactoryInfoOnBaseBlock(((Hv_Common_Db_GetDp1EdidDBRegionPtr()->astDpEdid)[i]).acEdid);
    }

    ucRet = Hv_Drv_Flash_WriteMonitorData(DPEDID_DATA_START_ADDRESS + (4 * 1024), (UCHAR8*)pstEdidData , sizeof(DpEdidDBRegion));

    Hv_Vos_Free(pstEdidData);

    Hv_Mw_DpRx_UpdtEdidRobust(LINK_PORT_INDEX_DP_RX1);

    return ucRet;
}

Status Hv_Mw_DataBase_SyncHdcp(VOID)
{
    UCHAR8 ucRet    = HV_SUCCESS;

    UINT32 uiI      = 0;
    UINT32 uiAddr   = 0;
    UINT32 uiValue  = 0;

    DpEdidDBRegion *pstEdidData = NULL;

    if (HV_FALSE == HV_Common_GetHdcpStatus())
    {
        return HV_SUCCESS;
    }
    HV_LOG_INFO(SYSTEM, "HDCPData modifyed");

    Hv_Vos_TaskEnterCritical();
    HV_Common_SetHdcpStatus(HV_FALSE);
    HV_Common_SetHdcpMagic(DATABASE_VALID_MAGIC_NUMBER);
    HDCPDataDBRegion* pstHDCPData = Hv_Vos_Malloc(sizeof(HDCPDataDBRegion));
    HV_ASSERT_VALID_PTR_RET(pstHDCPData, HV_FAILURE);

    for(uiI = 0; uiI < sizeof(pstHDCPData->stKey); uiI++)
    {
        *((UCHAR8*)(((UINT32)pstHDCPData) + uiI + OFFSET_OF(HDCPDataDBRegion, stKey))) =  HV_R8(HV_R32(SW_DUMMY_PQTOOL_FAC_HDCP) + uiI); 
    }

    //pstHDCPData->uiMagicNumber    = DATABASE_VALID_MAGIC_NUMBER;
    *((UINT32*)((UINT32)pstHDCPData + OFFSET_OF(HDCPDataDBRegion,uiMagicNumber))) = DATABASE_VALID_MAGIC_NUMBER;
    pstHDCPData->bModifyFlag      = HV_FALSE;
    pstHDCPData->bUseDefaultKey   = HV_FALSE;
    //pstHDCPData->bHdcp1XValid     = Hv_Common_Db_GetHDCPDataDBRegionPtr()->bHdcp1XValid;
    //pstHDCPData->bHdcp2XValid     = Hv_Common_Db_GetHDCPDataDBRegionPtr()->bHdcp2XValid;
    *((UCHAR8*)((UINT32)pstHDCPData + OFFSET_OF(HDCPDataDBRegion, bHdcp1XValid))) = Hv_Common_Db_GetHDCPDataDBRegionPtr()->bHdcp1XValid;
    *((UCHAR8*)((UINT32)pstHDCPData + OFFSET_OF(HDCPDataDBRegion, bHdcp2XValid))) = Hv_Common_Db_GetHDCPDataDBRegionPtr()->bHdcp2XValid;
    pstHDCPData->usCheckCrc       = _CRC16((UCHAR8 *)pstHDCPData, sizeof(HDCPDataDBRegion));
    Hv_Vos_TaskExitCritical();

    Hv_Common_Db_GetHDCPDataDBRegionPtr()->bModifyFlag      = HV_FALSE;
    Hv_Common_Db_GetHDCPDataDBRegionPtr()->uiMagicNumber    = DATABASE_VALID_MAGIC_NUMBER;

    ucRet = Hv_Drv_Flash_WriteMonitorData(HDCP_DATA_START_ADDRESS, (UCHAR8*)pstHDCPData , sizeof(HDCPDataDBRegion));

    Hv_Vos_Free(pstHDCPData);
    return ucRet;
}

Status Hv_Mw_DataBase_Sync(VOID)
{
    UCHAR8 ucRet = HV_SUCCESS;

    ucRet |= Hv_Mw_DataBase_SyncUser();
    ucRet |= Hv_Mw_DataBase_SyncSystem();
    ucRet |= Hv_Mw_DataBase_SyncFactory();
    ucRet |= Hv_Mw_DataBase_SyncTimeRec();
    ucRet |= Hv_Mw_DataBase_SyncGamma();
    ucRet |= Hv_Mw_DataBase_SyncHdmiEdid();
    ucRet |= Hv_Mw_DataBase_SyncHdmi1Edid();
    ucRet |= Hv_Mw_DataBase_SyncDPEdid();
    ucRet |= Hv_Mw_DataBase_SyncDP1Edid();

    ucRet |= Hv_Mw_DataBase_SyncHdcp();

    return ucRet;
}

Status Hv_Mw_DataBase_ResumeUserData( VOID )
{
    BOOL bNeedReconfig = HV_FALSE;
    UCHAR8 ucRet = HV_SUCCESS;
    USHORT16 usSourceBackup = HV_COMMON_DATABASE_GET(UserData,ucVideoSource);
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_PXP)
    USHORT16 usPxpSourceBackup = HV_COMMON_DATABASE_GET(UserData,ucPxPVideoSource);
#endif

    /*TODU call module resume API*/
    /*普通消息直接判决变化恢复配置即可*/

    /*对于需要发送通知消息的API需要判断是否变化，变化才需要真正的发送配置消息. 对于多次重配消息合并成一条重配消息即可
    不必额外重复发送消息导致反复重配闪屏*/
    if ((s_stDefaultUserDataDBRegion.ucProportion != s_stUserDataDBRegion.ucProportion)
#ifdef CONFIG_USER_DOUBLE_CHANNEL_ON
        || (s_stDefaultUserDataDBRegion.ucPxPMode != s_stUserDataDBRegion.ucPxPMode)
#endif
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_MAGNIFY)
        || (s_stDefaultUserDataDBRegion.bMagnifyGlassSw != s_stUserDataDBRegion.bMagnifyGlassSw)
#endif
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_FREESYNC)
        || (s_stDefaultUserDataDBRegion.ucFreeSync != s_stUserDataDBRegion.ucFreeSync)
#endif
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_ADAPTIVESYNC)
        || (s_stDefaultUserDataDBRegion.ucAdaptiveSync != s_stUserDataDBRegion.ucAdaptiveSync)
#endif
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_GSYNC)
        || (s_stDefaultUserDataDBRegion.ucGSync != s_stUserDataDBRegion.ucGSync)
#endif
        || (s_stDefaultUserDataDBRegion.enHdrSwitch != s_stUserDataDBRegion.enHdrSwitch))
    {
        bNeedReconfig = HV_TRUE;
    }
    Hv_Vos_Memcpy(&s_stUserDataDBRegion, &s_stDefaultUserDataDBRegion, sizeof(UserDataDBRegion));
    Hv_Panel_UpdaeDefaultDynamicPanlParam();
    /*send reconfig 消息需要放到s_stUserDataDBRegion被恢复以后, 
    SystemTask会获取s_stUserDataDBRegion的配置，放在Hv_Vos_Memcpy可以保证此时s_stUserDataDBRegion以是出厂默认值*/
    HV_COMMON_DATABASE_SET(UserData,ucVideoSource,usSourceBackup);
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_PXP)
    HV_COMMON_DATABASE_SET(UserData,ucPxPVideoSource,usPxpSourceBackup);
#endif
    if (bNeedReconfig)
    {
        HV_ASSERT_SUCCESS(Hv_Mw_Video_DataPathReconfig());
    }

    /*write default data to flash*/
#ifndef HV_BOARD_CONFIG_USER_IN_E2P
    HV_LOG_INFO(SYSTEM, "resume userdata ...");
    Hv_Drv_Flash_OnlyErase(USER_DATA_START_ADDRESS, 0x1000);
    ucRet = Hv_Drv_Flash_WriteMonitorData(USER_DATA_START_ADDRESS, (UCHAR8*)&s_stDefaultUserDataDBRegion, sizeof(UserDataDBRegion));
    #ifdef CONFIG_DB_USERDATA
        s_usUserRWVersionBack = 0;
        Hv_Drv_Flash_OnlyErase(USER_BACK_START_ADDRESS, 0x1000);
        //ucRet |= Hv_Drv_Flash_WriteMonitorData(USER_BACK_START_ADDRESS, (UCHAR8*)&s_stDefaultUserDataDBRegion, sizeof(UserDataDBRegion));
    #endif
#else
    ucRet = Hv_Drv_Eeprom_Write(0, USER_DATA_START_ADDRESS, (UCHAR8*)&s_stDefaultUserDataDBRegion, sizeof(UserDataDBRegion));
#endif
    return ucRet;
}

Status Hv_Mw_DataBase_ResumeSystemData( VOID )
{
    UCHAR8 ucRet = HV_SUCCESS;
    Hv_Vos_Memcpy(&s_stSystemDataDBRegion, &s_stDefaultSystemDataDBRegion, sizeof(SystemDataDBRegion));

    /*System数据用户无法动态修改,如果有需要调用API恢复的在此处调用恢复*/

    /*write default data to flash*/
    ucRet = Hv_Drv_Flash_WriteMonitorData(SYSTEM_DATA_START_ADDRESS, (UCHAR8*)&s_stDefaultSystemDataDBRegion, sizeof(SystemDataDBRegion));

    return ucRet;
}
 
const UserDataDBRegion *Hv_Mw_DataBase_GetDefaultUserDataPtr(VOID)
{
    return &s_stDefaultUserDataDBRegion;
}

/************************ Ddcci Sync Start***********************************/
Status Hv_Mw_DataBase_DdcSyncFactory(VOID)
{
    UINT32   uiSize     = sizeof(FactoryDataDBRegion);
    USHORT16 usCheckCrc = 0;
    UCHAR8   ucRet      = HV_SUCCESS;

    if (HV_FALSE == HV_COMMON_DATABASE_GET(FactoryData, bModifyFlag))
    {
        return HV_SUCCESS;
    }

    UCHAR8 *pcDbData  = Hv_Vos_Malloc(uiSize);
    /*申请失败不必释放内存*/
    HV_ASSERT_VALID_PTR_RET(pcDbData, HV_FAILURE);

    Hv_Vos_TaskEnterCritical();

    Hv_Common_Db_GetFactoryDataDBRegionPtr()->bModifyFlag = HV_FALSE;
    Hv_Vos_Memcpy(pcDbData, Hv_Common_Db_GetFactoryDataDBRegionPtr(), uiSize);

    Hv_Vos_TaskExitCritical();

    usCheckCrc  = _CRC16(pcDbData, uiSize);

    pcDbData[0] = (usCheckCrc >> 0) & 0xff;
    pcDbData[1] = (usCheckCrc >> 8) & 0xff;

    HV_LOG_INFO(SYSTEM, "FactoryData modifyed check %x", usCheckCrc);

    HV_COMMON_DATABASE_SET(FactoryData, usCheckCrc, usCheckCrc);

    Hv_Mw_DataBase_MonitorData_Save(FACTORY_DATA_START_ADDRESS, (UCHAR8*)pcDbData, uiSize);

    /*释放内存*/
    Hv_Vos_Free(pcDbData);

    Hv_Vos_Memcpy((VOID *)Hv_Common_Db_GetDefaultFactoryDataDBRegionPtr(), Hv_Common_Db_GetFactoryDataDBRegionPtr(), uiSize);
    
    return ucRet;
}

Status Hv_Mw_DataBase_DdcSyncGamma(VOID)
{
    UCHAR8 ucRet = HV_SUCCESS;
    UINT32 uiAddr   = 0;

    if (HV_FALSE == HV_COMMON_DATABASE_GET(GammaData, bModifyFlag))
    {
        return HV_SUCCESS;
    }

    HV_LOG_INFO(SYSTEM, "GammaData has modifyed");

    Hv_Vos_TaskEnterCritical();
    HV_COMMON_DATABASE_SET(GammaData, bModifyFlag, HV_FALSE);
    HV_COMMON_DATABASE_SET(GammaData, uiMagicNumber, DATABASE_VALID_MAGIC_NUMBER);
    uiAddr = (INT32)Hv_Common_Db_GetGammaDataDBRegionPtr();
    Hv_Vos_TaskExitCritical();
    Hv_Common_Db_GetGammaDataDBRegionPtr()->ucGmaNum     = 1;
    Hv_Common_Db_GetGammaDataDBRegionPtr()->aucGammaIndex[0]   = 0;
    Hv_Common_Db_GetGammaDataDBRegionPtr()->aucGammaIndex[1]   = 0;
    Hv_Common_Db_GetGammaDataDBRegionPtr()->aucGammaIndex[2]   = 0x22;
    Hv_Common_Db_GetGammaDataDBRegionPtr()->aucGammaIndex[3]   = 0;
    Hv_Common_Db_GetGammaDataDBRegionPtr()->aucGammaIndex[4]   = 0;
    Hv_Common_Db_GetGammaDataDBRegionPtr()->aucGammaIndex[5]   = 0;
    Hv_Common_Db_GetGammaDataDBRegionPtr()->aucGammaIndex[6]   = 0;
    Hv_Common_Db_GetGammaDataDBRegionPtr()->bModifyFlag     = HV_FALSE;
    Hv_Common_Db_GetGammaDataDBRegionPtr()->uiMagicNumber   = DATABASE_VALID_MAGIC_NUMBER;
	Hv_Common_Db_GetGammaDataDBRegionPtr()->uiEndMagicNumber   = GAMMA_END_MAGIC_NUMBER;

    ucRet = Hv_Drv_Flash_WriteMonitorData(GAMMA_DATA_START_ADDRESS, (UCHAR8*)uiAddr , sizeof(GammaDataDBRegion));

    return ucRet;
}

Status Hv_Mw_DataBase_DdcSyncHdmiEdid(VOID)
{
    UCHAR8 ucRet = HV_SUCCESS;

    if (HV_FALSE == HV_COMMON_DATABASE_GET(HdmiEdid, bModifyFlag))
    {
        return HV_SUCCESS;
    }

    HV_LOG_INFO(SYSTEM, "hdmi0 edid sync");

    Hv_Common_Db_GetHdmiEdidDBRegionPtr()->bModifyFlag      = HV_FALSE;
    Hv_Common_Db_GetHdmiEdidDBRegionPtr()->uiMagicNumber    = DATABASE_VALID_MAGIC_NUMBER;

    for (UINT32 i = 0; i < Hv_Common_Db_GetHdmiEdidDBRegionPtr()->ucNumber && i < HDMI_EDID_MAX_NUMBER; i++)
    {
        UpdateEdidFactoryInfoOnBaseBlock(Hv_Common_Db_GetHdmiEdidDBRegionPtr()->astHdmiEdid[i].acEdid);
    }

    ucRet = Hv_Drv_Flash_WriteMonitorData(HDMIEDID_DATA_START_ADDRESS, (UCHAR8 *)Hv_Common_Db_GetHdmiEdidDBRegionPtr(), sizeof(HdmiEdidDBRegion));
    
    return ucRet;
}


Status Hv_Mw_DataBase_DdcSyncHdmi1Edid(VOID)
{
    UCHAR8 ucRet = HV_SUCCESS;

    if (HV_FALSE == HV_COMMON_DATABASE_GET(Hdmi1Edid, bModifyFlag))
    {
        return HV_SUCCESS;
    }

    HV_LOG_INFO(SYSTEM, "hdmi1 edid sync");

    Hv_Common_Db_GetHdmi1EdidDBRegionPtr()->bModifyFlag      = HV_FALSE;
    Hv_Common_Db_GetHdmi1EdidDBRegionPtr()->uiMagicNumber    = DATABASE_VALID_MAGIC_NUMBER;

    for (UINT32 i = 0; i < Hv_Common_Db_GetHdmi1EdidDBRegionPtr()->ucNumber && i < HDMI_EDID_MAX_NUMBER; i++)
    {
        UpdateEdidFactoryInfoOnBaseBlock(Hv_Common_Db_GetHdmi1EdidDBRegionPtr()->astHdmiEdid[i].acEdid);

        // 一般厂商提供的edid的cec addr都是修改好的
        // UpdateEdidCecAddr(Hv_Common_Db_GetHdmi1EdidDBRegionPtr()->astHdmiEdid[i].acEdid, Hv_Common_Db_GetHdmi1EdidDBRegionPtr()->astHdmiEdid[i].uiEdidLen, 0x10);
    }

    ucRet = Hv_Drv_Flash_WriteMonitorData(HDMIEDID_DATA_START_ADDRESS + (4 * 1024), (UCHAR8 *)Hv_Common_Db_GetHdmi1EdidDBRegionPtr(), sizeof(HdmiEdidDBRegion));

    return ucRet;
}

Status Hv_Mw_DataBase_DdcSyncDPEdid(VOID)
{
    UCHAR8 ucRet = HV_SUCCESS;

    DpEdidDBRegion *pstDpEdidData = Hv_Common_Db_GetDpEdidDBRegionPtr();

    if (HV_FALSE == HV_COMMON_DATABASE_GET(DpEdid, bModifyFlag))
    {
        return HV_SUCCESS;
    }

    HV_LOG_INFO(SYSTEM, "dp0 edid sync");
    
    Hv_Common_Db_GetDpEdidDBRegionPtr()->bModifyFlag    = HV_FALSE;
    Hv_Common_Db_GetDpEdidDBRegionPtr()->uiMagicNumber  = DATABASE_VALID_MAGIC_NUMBER;

    for (UINT32 i = 0; i < pstDpEdidData->ucNumber && i < DP_EDID_MAX_NUMBER; i++)
    {
        UpdateEdidFactoryInfoOnBaseBlock(pstDpEdidData->astDpEdid[i].acEdid);
        UpdateEdidFactoryInfoOnBaseBlock(((Hv_Common_Db_GetDpEdidDBRegionPtr()->astDpEdid)[i]).acEdid);
    }

    ucRet = Hv_Drv_Flash_WriteMonitorData(DPEDID_DATA_START_ADDRESS, (UCHAR8 *)pstDpEdidData , sizeof(DpEdidDBRegion));

    return ucRet;
}

Status Hv_Mw_DataBase_DdcSyncDP1Edid(VOID)
{
    UCHAR8 ucRet = HV_SUCCESS;

    DpEdidDBRegion *pstDpEdidData = Hv_Common_Db_GetDp1EdidDBRegionPtr();

    if (HV_FALSE == HV_COMMON_DATABASE_GET(Dp1Edid, bModifyFlag))
    {
        return HV_SUCCESS;
    }

    HV_LOG_INFO(SYSTEM, "dp1 edid sync");
    
    Hv_Common_Db_GetDp1EdidDBRegionPtr()->bModifyFlag    = HV_FALSE;
    Hv_Common_Db_GetDp1EdidDBRegionPtr()->uiMagicNumber  = DATABASE_VALID_MAGIC_NUMBER;

    for (UINT32 i = 0; i < pstDpEdidData->ucNumber && i < DP_EDID_MAX_NUMBER; i++)
    {
        UpdateEdidFactoryInfoOnBaseBlock(pstDpEdidData->astDpEdid[i].acEdid);
        UpdateEdidFactoryInfoOnBaseBlock(((Hv_Common_Db_GetDp1EdidDBRegionPtr()->astDpEdid)[i]).acEdid);
    }

    ucRet = Hv_Drv_Flash_WriteMonitorData(DPEDID_DATA_START_ADDRESS + (4 * 1024), (UCHAR8 *)pstDpEdidData , sizeof(DpEdidDBRegion));

    return ucRet;
}

Status Hv_Mw_DataBase_DdcSyncHdcp(VOID)
{
    UCHAR8 ucRet    = HV_SUCCESS;

    if (HV_FALSE == HV_COMMON_DATABASE_GET(HDCPData, bModifyFlag))
    {
        return HV_SUCCESS;
    }
    HV_LOG_INFO(SYSTEM, "HDCPData modifyed");

    Hv_Common_Db_GetHDCPDataDBRegionPtr()->bModifyFlag      = HV_FALSE;
    Hv_Common_Db_GetHDCPDataDBRegionPtr()->uiMagicNumber    = DATABASE_VALID_MAGIC_NUMBER;
    Hv_Common_Db_GetHDCPDataDBRegionPtr()->bUseDefaultKey   = HV_FALSE;
    Hv_Common_Db_GetHDCPDataDBRegionPtr()->usCheckCrc       = _CRC16((UCHAR8 *)Hv_Common_Db_GetHDCPDataDBRegionPtr(), sizeof(HDCPDataDBRegion));

    ucRet = Hv_Drv_Flash_WriteMonitorData(HDCP_DATA_START_ADDRESS, (UCHAR8*)Hv_Common_Db_GetHDCPDataDBRegionPtr() , sizeof(HDCPDataDBRegion));

    return ucRet;
}

Status Hv_Mw_DataBase_DdcSync(VOID)
{
    
    UCHAR8 ucRet = HV_SUCCESS;

    ucRet |= Hv_Mw_DataBase_SyncUser();
    ucRet |= Hv_Mw_DataBase_SyncSystem();
    ucRet |= Hv_Mw_DataBase_SyncTimeRec();

    ucRet |= Hv_Mw_DataBase_DdcSyncFactory();
    ucRet |= Hv_Mw_DataBase_DdcSyncGamma();
    ucRet |= Hv_Mw_DataBase_DdcSyncHdmiEdid();
    ucRet |= Hv_Mw_DataBase_DdcSyncHdmi1Edid();
    ucRet |= Hv_Mw_DataBase_DdcSyncDPEdid();
    ucRet |= Hv_Mw_DataBase_DdcSyncDP1Edid();
    ucRet |= Hv_Mw_DataBase_DdcSyncHdcp();

    return ucRet;
}

/************************ Ddcci Sync End***********************************/

