/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

#include "general.h"
#include "util.h"
#include "pe_if.h"
#include "drv_nr.h"
#include "drv_nr_int.h"
#include "video_def.h"
#include "drv_video.h"
#include "api_backlt.h"
#include "drv_contrast.h"
#include "api_eep.h"
#include "eepdef.h"
#include "drv_tvd.h"
#include "vdo_misc.h"
#include "vdp_drvif.h"
#include "vdp_if.h"
#include "drv_scpos.h"
#include "eeprom_if.h"
#include "u_drv_cust.h"
#include "drvcust_if.h"
#include "drv_hdtv.h"
#include "drv_mpeg.h"
#include "x_debug.h"
#include "x_hal_5381.h"
#include "drv_vdoclk.h"
#include "drv_adcset.h"
#include "drv_autocolor.h"
#include "source_select.h"
#include "drv_pq_cust.h"
#include "drv_dvi2.h"
#include "drv_hdmi2.h"
#include "hdmi_if.h"
#include "drv_mhl.h"
#include "srm_drvif.h"
#include "drv_meter.h"
#include "drv_od.h"
#include "nptv_debug.h"
#include "panel.h"
#include "drv_default.h"
#include "drv_ldmspi.h"
#include "drv_upscaler.h"
#include "drv_mjc_if.h"
#include "hw_od.h"
#include "hw_lcdim_v2.h"
#include "drv_scaler.h"
#include "osd_drvif.h"
#include "vdo_rm.h"
#include "drv_tdtv.h"
#include "mute_if.h"
#include "drv_dvi2com.h"

//#if defined(CC_SUPPORT_4K2K)
#include "sony_video_drv_4k2k.c"
//#else
//#include "sony_video_drv.c"
//#endif
#include "hw_ycproc.h"
#include "hw_tdsharp.h"
#ifndef CC_CP_CUST
#include "hw_ttd.h"
#endif
#include "hw_scpip_pq.h"
#include "hw_mjc.h"
#include "hw_ldmspi.h"
#include "hw_sw.h"
#ifdef CC_LCE_SUPPORT
#include "hw_lc_bitplus.h"
#endif

#include "drv_MapleGetApiAp.c"
#include "drv_MapleGetApiSys.c"
#include "drv_MapleSetApi.c"
#include "drv_MapleAudGetApi.c"
#include "MapleAudApi_cmd.c"

#include "MapleApi_cmd.c"
#include "bepqapi.h"
#include "CustomCtrl.h"

#ifdef CC_PowerCons_Ctrl
#include "sony_PowerConsumptionCtrl.h"
#include "../../pcmcia/pcmcia_if.h"
#include "../../pcmcia/pcmcia_hw.h"
#endif 

#include "ATV/priv_drv/sony_drv_inc/pq_gamma_if.h"
#include "ATV/priv_drv/sony_drv_inc/Sony_drv_cb.h"
#include "ATV/priv_drv/sony_drv_inc/wb_pbm.h"
#ifdef CC_SUPPORT_DOLBY_VISION
#include "drv_dolby_drvif.h"
#endif

#include "frametrack_drvif.h"

#include "api_srch_if.h"

#ifndef CC_MTK_LOADER
static HANDLE_T _hSRSCtrlSemaphore;
static BOOL bSRSCtrlLoopInit = FALSE;
static BOOL bSRSCtrlSemaInit = FALSE;
static void _SRSCtrlLoop(void);

#endif

void DRVCUST_PqModeChange(UINT8 bPath);
UINT8 DRVCUST_VideoGetHDRType(void);
void DRVCUST_SetHdmiCcirDither(UINT8 bPath);
void DRVCUST_SetOSDIndexEnable(UINT8 u1OnOff);

typedef enum
{
    E_NR_CUST_ADAP_NL    = 0,
    E_NR_CUST_ADAP_XNR   = 1,
    E_NR_CUST_ADAP_RNR   = 2,
    E_NR_CUST_ADAP_MOANR = 3,
    E_NR_CUST_ADAP_FUNC_MAX
} E_NR_DFT_ADAP_FUNC;


typedef enum
{
    E_SCE_VIVID = 0,
    E_SCE_ST_OFF,
    E_SCE_ST_LOW,
    E_SCE_ST_MID,
    E_SCE_ST_HIGH,
    E_SCE_CI_LOW,
    E_SCE_CI_MID,
    E_SCE_CI_HIGH,
    E_SCE_PH_LOW,
    E_SCE_PH_MID,
    E_SCE_PH_HIGH,
    E_SCE_VIVID_BT2020,
    E_SCE_ST_OFF_BT2020,
    E_SCE_ST_LOW_BT2020,
    E_SCE_ST_MID_BT2020,
    E_SCE_ST_HIGH_BT2020,
    E_SCE_CI_LOW_BT2020,
    E_SCE_CI_MID_BT2020,
    E_SCE_CI_HIGH_BT2020,
    E_SCE_PH_LOW_BT2020,
    E_SCE_PH_MID_BT2020,
    E_SCE_PH_HIGH_BT2020,
    E_SCE_HLG_Off,
    E_SCE_HLG_Low,
    E_SCE_HLG_Mid,
    E_SCE_HLG_High,
    E_SCE_DV_OFF,
    E_SCE_DV_LOW,
    E_SCE_DV_MID,
    E_SCE_DV_HIGH,
} E_CUST_SCE_MODE;

typedef enum
{
    E_LCE_VIVID = 0,
    E_LCE_ST_OFF,
    E_LCE_ST_LOW,
    E_LCE_ST_MID,
    E_LCE_ST_HIGH,
    E_LCE_CI_LOW,
    E_LCE_CI_MID,
    E_LCE_CI_HIGH,
    E_LCE_PH_LOW,
    E_LCE_PH_MID,
    E_LCE_PH_HIGH,
    E_LCE_VIVID_HDR10,
    E_LCE_ST_OFF_HDR10,
    E_LCE_ST_LOW_HDR10,
    E_LCE_ST_MID_HDR10,
    E_LCE_ST_HIGH_HDR10,
    E_LCE_CI_LOW_HDR10,
    E_LCE_CI_MID_HDR10,
    E_LCE_CI_HIGH_HDR10,
    E_LCE_PH_LOW_HDR10,
    E_LCE_PH_MID_HDR10,
    E_LCE_PH_HIGH_HDR10,
    E_LCE_VIVID_HLG,
    E_LCE_ST_OFF_HLG,
    E_LCE_ST_LOW_HLG,
    E_LCE_ST_MID_HLG,
    E_LCE_ST_HIGH_HLG,
    E_LCE_CI_LOW_HLG,
    E_LCE_CI_MID_HLG,
    E_LCE_CI_HIGH_HLG,
    E_LCE_PH_LOW_HLG,
    E_LCE_PH_MID_HLG,
    E_LCE_PH_HIGH_HLG,
    E_LCE_DV_VIVID,
    E_LCE_DV_OFF,
    E_LCE_DV_LOW,
    E_LCE_DV_MID,
    E_LCE_DV_HIGH,
} E_CUST_LCE_MODE;


typedef enum
{
    E_SCE_UI_OFF = 0,
    E_SCE_UI_LOW,
    E_SCE_UI_MID,
    E_SCE_UI_HIGH,
} E_CUST_SCE_UI_MODE;

typedef enum
{
    E_SMART_PIC_VIVID,
    E_SMART_PIC_STANDARD,
    E_SMART_PIC_CINEMA,
	E_SMART_PIC_GAME,
	E_SMART_PIC_GRAPHICS,
    E_SMART_PIC_PHOTO,
	E_SMART_PIC_CUSTOM,
	E_SMART_PIC_USER1,
    E_SMART_PIC_USER2,
	E_SMART_PIC_DV_DARK,
	E_SMART_PIC_DV_BRIGHT,
	E_SMART_PIC_DV_VIVIDE,
	E_SMART_PIC_NETFLIX_DV,
	E_SMART_PIC_NETFLIX_SDR,
	E_SMART_PIC_RESERVED_1,
	E_SMART_PIC_RESERVED_2,
} E_CUST_SMART_PIC_MODE;



typedef enum
{
    E_CT_COOL = 0,
    E_CT_NEUTRAL,
    E_CT_WARM1,
    E_CT_WARM2,
    E_CT_PHOTO,
    E_CT_MAX,
} E_CUST_COLOR_TEMP_MODE;

enum
{
	DEMO_PQ_OFF			= 0,
	DEMO_PQ_ON_RIGHT 	= 1,
	DEMO_PQ_ON_LEFT 	= 2
};

enum
{
	E_OSTG_MODULE_ALL = 0x0,
	E_OSTG_MODULE_XVYCC2,
	E_OSTG_MODULE_LCD,
	E_OSTG_MODULE_DITHER_BEFORE_OPTION3,
	E_OSTG_MODULE_GAMMA_OPTION3,
	E_OSTG_MODULE_DITHER_AFTER_OPTION3,
	E_OSTG_MODULE_R2Y
};
typedef struct _WB_TEST_PTN_STATUS{
    UINT8 u1PtnOnOff;
    UINT8 u1BlueStretchOnOff;
    UINT8 u1XvYccOnOff;
    UINT8 u1OPCOnOff;
    UINT8 u1MuteOnOff;  
    UINT8 u1LDOnOff;
    UINT8 u1PreDitherSel;
    UINT8 u1PostDitherSel;
    UINT8 u1ODOnOff;
}WB_TEST_PTN_STATUS;

UCHAR *ucDither_Type[E_DITHER_MODE_MAX]={
	"Dither Disable",
	"InputBitDepth(12),OutputBitDepth(12)",
	"InputBitDepth(12),OutputBitDepth(10)",
	"InputBitDepth(12),OutputBitDepth(8)",
	"InputBitDepth(12),OutputBitDepth(6)",
};


extern INT32 COLOR_TRANSFORM_ADJ[15];
extern void vMjcGetParams(MailBoxCb callback, UINT32 req_id, mtk_params *m_params);
extern void vMjcGetBlackBeltPosition(MailBoxCb callback, UINT32 req_id, CUST_MEMC_BLACK_BELT_T *stMEMCBlackBelt);
extern void vMjcGetEndCreditRollFlag(MailBoxCb callback, UINT32 req_id, UINT8 *pEndCreditRollFlag);
extern void vMjcGetTelopFlag(MailBoxCb callback, UINT32 req_id, UINT8 *pGetTelopFlag);

extern UINT32 DRVCUST_Get_InterMemc_type(void);

//DEMO modules

#define DEMO_TDC			1	<<	0	//driver not support now
#define DEMO_MDDI			1	<<	1	//driver not support now
#define DEMO_HSHARP			1	<<	2	//driver not support now
#define DEMO_2DNR			1	<<	3
#define DEMO_3DNR			1	<<	4
#define DEMO_TDSHARP		1	<<	5
#define DEMO_COLOR			1	<<	6
#define DEMO_ECTI			1	<<	7

EXTERN CUST_COL_CONV_TABLE_PARAM_T CUST_COL_CONV_TABLE_PARAM[COL_CONV_MAX_NUM];

static UINT8 gbSmartPicIndex = 0;
static UINT8 gbSceUi = 0;
static UINT8 gbLceUi = 0;

static UINT8 gbOdUi = 0;
static UINT8 gbGammaUi = 0;
static UINT16 gu2RawDataTblIndex = 0;
static UINT16 gu2RawDataCaseIndex = 0;
BOOL fgCriticalSection = SV_FALSE;
BOOL fgYUVout = SV_FALSE;


UINT8* SRS_Table_A = NULL;
UINT8* SRS_Table_B = NULL;

AUTO_COLORTEMP_SETS_INFO_T stCTInfo;
UINT32 bi1GammaOfst;
extern MMAppInfo sMMAppInfo;

UINT8 	u1BePath[3];
UINT8 u1Connet[3] = {SV_FALSE,SV_FALSE,SV_FALSE};

extern UINT16 pPedestalMatrixISR[15];
extern UINT32 DEFAULT_XVYCC_MATRIX[9];
UINT16 DRVCUST_pMecbethMatrix[15]={0};
UINT16 u2WBGain[SV_RGB_RGB] = {0x200, 0x200, 0x200};
UINT16 u2WBOfst[SV_RGB_RGB] = {0x00, 0x00, 0x00};
UINT8 bWBFlatPreOnoff = SV_FALSE;
INT32 DRVCUST_Matrix[E_MTX_MAX][15]={0};

#define MAX_COEF_TPYE 5
#define MAX_VC_COEF_IDX    11
#define MAX_VY_COEF_IDX    9
#define MAX_VC_COEF_HD_IDX    5
#define MAX_VY_COEF_HD_IDX    5

#define EN_PEDASTAL_IN_SUB_PATH 1

#define EEPROM_GAMMA_CCT_ADD 0x3200
#define GAMMA_BYTES		342	//57 * 3 *2
#define CUSTOM_GAMMA_BASE 0x3C00
#define GAMMA_MAGIC00 0x10
#define GAMMA_MAGIC01 0x20

#define GAMMA_CTRL_POINT_NUM_PBM 57
#define GAMMA_CTRL_POINT_NUM2_PBM 33		//For salvia
#define GAMMA_CTRL_POINT_NUM_TRACK 11
#define GAMMA_10P_OFST_CTRL_POINT_NUM 11
#define GAMMA_20P_OFST_CTRL_POINT_NUM 21

#define NUM_OF_TEMP_GAMMA 0x80


static UINT8 bGammaInit = SV_FALSE;

extern UINT16 u2GammaDecodedTable[3][GAMMA_INDEX];
extern INT32 _iUsedCtlValue_R[EEP_WB_PBM_NUM_PT], _iUsedCtlValue_G[EEP_WB_PBM_NUM_PT], _iUsedCtlValue_B[EEP_WB_PBM_NUM_PT];
extern INT32 _iUsedColorTemp;
extern UINT8 u1IsForceWBEepReload(void);

static SONY_DRV_CB_ST  callback_funcs;
extern SRM_TV_MODE_T _eApplicationMode;
extern UINT8 u1FrontDitherSetting;
extern UINT8 u1PostDitherSetting;
extern UINT8 u1PreMatrixtoOS;
extern UINT16 const COLOR_TRANSFORM[SV_COLORTRANS_MAX][15];
extern INT32 const RGB2YUV[15];
extern INT32 const SRC_VGA_RGB_YUV2RGB[15];
extern INT32 const SRC_RGB_YUV2RGB[15];
extern INT32 const SRC_YUV_YUV2YUV[15];
extern INT32 const SRC_YUV_YUV2RGB[15];
extern INT32 const SRC_YUV_YUV2RGBEXTLVL[15];
extern INT32 const SRC_VGA_YUV_YUV2RGBEXTLVL[15];
extern INT32 const SRC_YUV_YUV2RGB_HD[15];
extern INT32 const SRC_YUV_YUV2RGBEXTLVL_HD[15];
extern INT32 const SRC_VGA_YUV_YUV2RGBEXTLVL_HD[15];
extern INT32 const SRC_BT2020_YUV_YUV2RGB_CL[15];
extern INT32 const SRC_BT2020_YUV_YUV2RGBEXTLVL_CL[15];

extern UINT8 bManualLumaCurve;


UINT8 u1ColorTransIdx_ext=0xFF;
UINT8 bColorIndex=0xFF;
UINT8 bPreGammaSel=0xFF;
UINT16 wHwGammaCurve[SV_RGB_RGB][GAMMA_INDEX];
INT16 i2WB20PUIValue[3][21] ={0};
UINT8 bVideoRangeMode = DRV_CUSTOM_HDMI_RANGE_LIMIT;
UINT8 bIsMetaData = SV_FALSE;
UINT8 bIsSeamless = SV_FALSE;
static UINT8 bIsPIP = SV_FALSE;

static UINT8 bGammaLinear = SV_FALSE;

static UINT8 u1WB_GAM_RGB[SV_RGB_RGB][GAMMA_CTRL_POINT_NUM_TRACK];
static UINT8 u1WB_OFST_RGB[E_CT_MAX][SV_RGB_RGB][GAMMA_CTRL_POINT_NUM_TRACK];
static UINT8 u1WB_GAM_GAIN[GAMMA_CTRL_POINT_NUM_TRACK];
static UINT16 u2WB_INP_LVL[GAMMA_CTRL_POINT_NUM_TRACK];
static UINT16 u2WB_INP_LVL_Fac[GAMMA_CTRL_POINT_NUM_TRACK];
static UINT8 u1WB_BASE_GAIN_RGB_EEP[E_CT_MAX][SV_RGB_RGB];

#ifdef CC_MAPLE_CUST_DRV
static E_CUST_WB_OFFSET_20P eWbOffset20pEn = E_CUST_WB_OFFSET_20P_DIS;
static UINT8 u120POfst[E_CT_MAX][SV_RGB_RGB][GAMMA_20P_OFST_CTRL_POINT_NUM];
static UINT8 u1Gam10P_20PGain[GAMMA_20P_OFST_CTRL_POINT_NUM];
static UINT16 u2Inplvl10P_20P[GAMMA_20P_OFST_CTRL_POINT_NUM];
static INT32 i4Ctrl10P_20POfst[SV_RGB_RGB][GAMMA_20P_OFST_CTRL_POINT_NUM];
//static INT32 i4Gam10POfst[SV_RGB_RGB][GAMMA_INDEX];
static INT32 (* pi4Gam10P_20POfst)[GAMMA_INDEX] = NULL;
#endif

static UINT8 PreHDRType = SV_HDR_TYPE_UNKNOWN;
static UINT8 fgIsPreOSD3En = 0xFF;
UINT8 IsHDRFlg = SV_FALSE;
VP9_HDR_TYPE_E eVP9HDRType = SV_VP9_HDR_TYPE_NONE;

static UINT8 su1AddCondition = 0xff;

#ifdef CC_SUPPORT_PHOTO8K
static CUST_DIVPHOTO_FUNC_TBL_T stDivPhotoFuncTbl;
static CUST_DIVPHOTO_FUNC_TBL_T stDivPhotoFuncTblCrc;

static CUST_DIVPHOTO_REGION_T stDivPhotoRegion[E_CUST_DIV_UNKNOWN] = {
        {0xffffffff, 0xffffffff},
        {0, 0}, {3840, 0},
        {0, 2160}, {3840, 2160},
        {0xffffffff, 0xffffffff},
};
#endif

MEMC_MODE_INFO_TYPE _stMemcModeInfo;


#ifdef CC_MAPLE_CUST_DRV
//For Sakura
static UINT16 u2CtlPos_PBM[GAMMA_CTRL_POINT_NUM_PBM] = {0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E,
												     	0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E,
												  	 	0x20, 0x22, 0x24, 0x26, 0x28, 0x2A, 0x2C, 0x2E,
												  	 	0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E,
												   	 	0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78,
												   	 	0x80, 0x88, 0x90, 0x98, 0xA0, 0xA8, 0xB0, 0xB8,
												   	 	0xC0, 0xC8, 0xD0, 0xD8, 0xE0, 0xE8, 0xF0, 0xF8, 0x100}; 
#else
//For Salvia
static UINT16 u2CtlPos_PBM[GAMMA_CTRL_POINT_NUM2_PBM] = {0x00, 0x04, 0x08, 0x0B, 0x10, 0x14, 0x18, 0x1C,
														  0x20, 0x24, 0x28, 0x2C, 0x30, 0x34, 0x38, 0x3C,
														  0x40, 0x4C, 0x58, 0x64, 0x70, 0x7C, 0x88, 0x94,
														  0xA0, 0xAC, 0xB8, 0xC4, 0xD0, 0xDC, 0xE8, 0xF4, 0x100};
#endif
//257 base value for tracking mode
/*
static INT32 u4WB_BASE_VALUE[GAMMA_INDEX] = {0,   16,   32,   48,   64,   80,   96,  112,  128,  144,  160,  176,  192,  208,  224,  240,
										   256,  272,  288,  304,  320,  336,  352,  368,  384,  400,  416,  432,  448,  464,  480,  496,
										   512,  528,  544,  560,  576,  592,  608,  624,  640,  656,  672,  688,  704,  720,  736,  752,
										   768,  784,  800,  816,  832,  848,  864,  880,  896,  912,  928,  944,  960,  976,  992, 1008,
										  1024, 1040, 1056, 1072, 1088, 1104, 1120, 1136, 1152, 1168, 1184, 1200, 1216, 1232, 1248, 1264,
										  1280, 1296, 1312, 1328, 1344, 1360, 1376, 1392, 1408, 1424, 1440, 1456, 1472, 1488, 1504, 1520,
										  1536, 1552, 1568, 1584, 1600, 1616, 1632, 1648, 1664, 1680, 1696, 1712, 1728, 1744, 1760, 1776,
										  1792, 1808, 1824, 1840, 1856, 1872, 1888, 1904, 1920, 1936, 1952, 1968, 1984, 2000, 2016, 2032,
										  2048, 2064, 2080, 2096, 2112, 2128, 2144, 2160, 2176, 2192, 2208, 2224, 2240, 2256, 2272, 2288,
										  2304, 2320, 2336, 2352, 2368, 2384, 2400, 2416, 2432, 2448, 2464, 2480, 2496, 2512, 2528, 2544,
										  2560, 2576, 2592, 2608, 2624, 2640, 2656, 2672, 2688, 2704, 2720, 2736, 2752, 2768, 2784, 2800,
										  2816, 2832, 2848, 2864, 2880, 2896, 2912, 2928, 2944, 2960, 2976, 2992, 3008, 3024, 3040, 3056,
										  3072, 3088, 3104, 3120, 3136, 3152, 3168, 3184, 3200, 3216, 3232, 3248, 3264, 3280, 3296, 3312,
										  3328, 3344, 3360, 3376, 3392, 3408, 3424, 3440, 3456, 3472, 3488, 3504, 3520, 3536, 3552, 3568,
										  3584, 3600, 3616, 3632, 3648, 3664, 3680, 3696, 3712, 3728, 3744, 3760, 3776, 3792, 3808, 3824,
										  3840, 3856, 3872, 3888, 3904, 3920, 3936, 3952, 3968, 3984, 4000, 4016, 4032, 4048, 4064, 4080, 4096};

*/


const  UINT16 PANEL_GAMMA_REMAP_TBL[]=
{
    #include "maple_GammaRemapTbl.h"
};

extern UINT16 OSDMatrix_RGB2YUV601[12];

/*****using notes*******
1. coeff bit width is 10bit, 0x100 is 1 time. offset bit width is 10bit, real use it to 8 bit,0xFF equal to 10bit 1023.
2. bit 12 is sign bit. 1 is stands for negative value. ex. -0.5, then the setting is 0x1080
3. the video output sequence is CbYCr, so the matrix is for RGB->CbYCr convertion.
************************/
UINT16 OSDMatrix_HDR_RGB2YUV601[][12]=
{
	{	 
		// HDR1 coefficient controll for LPT model. 0.5 tiems gain and 10% offset RGB->YUV601(RGB is first convert to BT2020)
		0x0019, 0x1014, 0x1005,
		0x0021, 0x0042, 0x0018,
		0x1010, 0x101B, 0x002B,
		0x0080, 0x0026, 0x0080	
	},
	{ 
		// HDR2 coefficient controll for LPT model.1 tiems gain and 0% offset RGB->YUV601(RGB is first convert to BT2020)
		0x002D, 0x1023, 0x100A,
		0x003B, 0x0075, 0x002C,
		0x101C, 0x1031, 0x004D,
		0x0080, 0x0010, 0x0080	
	}
};

UINT16 const OSDRGB2RGB_HDR_CTL[][12]=
{
    {   // HDR1 coefficient controll  0.56 tiems gain and 10% offset 709->2020
        0x004F, 0x002D, 0x0014,
        0x0018, 0x0067, 0x0010,
        0x0007, 0x0015, 0x0073,
        0x001A, 0x001A, 0x001A
    },
    
	{	// HDR2 coefficient controll. 1.0 times gain and 0% offset,709->2020
		0x008C, 0x0051, 0x0023,
		0x002B, 0x00B8, 0x001D,
		0x000C, 0x0026, 0x00CE,
		0x0000, 0x0000, 0x0000
	}
};
UINT16 const OSDRGBF2RGBL_HDR_CTL[][12]=
{
	//Full -> limit case
    {   // HDR1 coefficient controll  0.56 tiems gain and 10% offset 709->2020
        0x0044, 0x0027, 0x0011,
        0x0015, 0x0058, 0x00E,
        0x0006, 0x0012, 0x0063,
        0x002A, 0x002A, 0x002A
    },
    
	{	// HDR2 coefficient controll. 0.9 times gain and 0% offset,709->2020+		
		0x006C, 0x003E, 0x001B,
		0x0021, 0x008E, 0x0016,
		0x0009, 0x001E, 0x009F, 		
		0x0010, 0x0010, 0x0010
	}
};

UINT16 const OSDRGB2RGB_SDR_CTL[][12]=
{	
	{ //without offset for BFM(MTK only) model
		0x0100, 0x0000, 0x0000,
		0x0000, 0x0100, 0x0000,
		0x0000, 0x0000, 0x0100,
		0x0000, 0x0000, 0x0000
	},
		
	{ // reserve
		0x0100, 0x0000, 0x0000,
		0x0000, 0x0100, 0x0000,
		0x0000, 0x0000, 0x0100,
		0x0000, 0x0000, 0x0000
	}
};

extern UINT16 const OSDRGBF2RGBL_SDR_CTL[][12];

static INT32 i4DynGammaIndex=0x40;

enum
{
    SCAL_COEF_HY,
    SCAL_COEF_HC,
    SCAL_COEF_VY,
    SCAL_COEF_VC,
    SCAL_COEF_MAX,
};


UINT8 u1SatHistBoundary[] = {5, 13, 21, 29, 37, 45, 58}; //{1, 4, 9, 16, 25, 36, 49};
//HDR
PANEL_GAMUT_T panel_Gamut;
TONE_MAP_T    tone_mapping;

#ifdef DRV_CUST_HDR
UINT32 XVYCC_MATRIX_BT2020NCL[9] =
{
// TODO_RGB2020TORGB709
    0x2A45,    0x1DA64,    0x1FB56,
    0x1F807,    0x0881,    0x1FF77,
    0x1FED6,    0x1F990,    0x0799
};
extern UINT32 DEFAULT_XVYCC_MATRIX[9];
extern UINT8 gbIsHdrFlg;
#endif
UINT8 u1CONV_TBL_M3_BE_DFT[E_INPUT_MAX][E_MTX_MAX]={
	{1,0,0,0,0},
	{1,0,0,0,0},
	{2,1,0,0,0},
	{3,1,0,0,0},
	{4,1,0,0,0},
	{5,0,0,0,0},
	{6,5,0,0,0},
	{7,0,0,0,0},
	{8,7,0,0,0},
	{9,1,0,0,0},
	{10,1,0,0,0},
	{11,1,0,0,0},
	{12,1,0,0,0},
	{13,5,0,0,0},
	{14,5,0,0,0},
};
UINT8 u1CONV_TBL_M3_PQ_DFT[E_INPUT_MAX][E_MTX_MAX]={
	{1,0,0,0,0},
	{1,0,9,0,1},
	{2,1,9,0,1},
	{3,1,9,0,1},
	{4,1,9,0,1},
	{5,1,9,0,1},
	{6,1,9,0,1},
	{7,0,11,9,1},
	{8,7,11,9,1},
	{9,1,9,0,1},
	{10,1,9,0,1},
	{11,1,9,0,1},
	{12,1,9,0,1},
	{13,1,9,0,0},
	{14,1,9,0,0},
};
UINT8 u1CONV_TBL_M3_ONLY_DFT[E_INPUT_MAX][E_MTX_MAX]={
	{1,0,0,0,0},
	{1,0,10,0,0},
	{2,1,10,0,0},
	{3,1,10,0,0},
	{4,1,10,0,0},
	{5,1,10,0,0},
	{6,1,10,0,0},
	{7,0,12,10,0},
	{8,7,12,10,0},
	{9,1,10,0,0},
	{10,1,10,0,0},
	{11,1,10,0,0},
	{12,1,10,0,0},
	{13,1,10,0,0},
	{14,1,10,0,0},
	
};

UINT8 u1CONV_TBL_DFT[E_INPUT_MAX][E_MTX_MAX]={
	{1,0,0,0,0},
	{1,0,0,0,0},
	{2,1,0,0,0},
	{3,1,0,0,0},
	{4,1,0,0,0},
	{5,0,0,0,0},
	{6,5,0,0,0},
	{7,0,0,0,0},
	{8,7,0,0,0},
	{9,1,0,0,0},
	{10,1,0,0,0},
	{11,1,0,0,0},
	{12,1,0,0,0},
	{13,1,0,0,0},
	{14,1,0,0,0},
};



#ifdef CC_PowerCons_Ctrl
void DRVCUST_PowerConsCtrlStatusCheck(void);
#endif

#ifdef DRV_SUPPORT_CUST_ANR
static NR_ADAP_WREG_BASE_T _rCustNrWRegState[E_NR_CUST_ADAP_FUNC_MAX+1] =
{
    {fgDrvAnrAutoOnNL,  fgDrvAnrFromSWOff, vDrvAnrSetNL,  vDrvAnrResetNL,  NR_WR_ST_IDLE},
    {fgDrvAnrAutoOnXNR, fgDrvAnrFromSWOff, vDrvAnrSetXNR, vDrvAnrResetXNR, NR_WR_ST_IDLE},
    {fgDrvAnrAutoOnRNR, fgDrvAnrFromSWRNR, vDrvAnrSetRNR, vDrvAnrResetRNR, NR_WR_ST_IDLE},
    {fgDrvAnrAutoOnMOANR, fgDrvAnrFromSWMOANR, vDrvAnrSetMOANR, vDrvAnrResetMOANR, NR_WR_ST_IDLE},
    {NULL, NULL, NULL, NULL, NR_WR_ST_NULL}
};

static void DRVCUST_AnrProc(const NR_NM_STA_T* prNmSta, const NR_NM_ANA_T* prNmAna)
{
    UINT32 u4NoiseLvl;
    UINT32 u4MaxNL;

    u4MaxNL = _SWR(NR_NM_03, MAX_NOISE_LVL);
    u4NoiseLvl = ((_SWR(NR_NM_00, FORCE_NOISE_LVL_EN)) ? _SWR(NR_NM_00, FORCE_NOISE_LVL) : prNmAna->u1NoiseLevel);
    u4NoiseLvl = MIN(u4NoiseLvl, u4MaxNL);

    if (_rCustNrWRegState[E_NR_CUST_ADAP_NL].fgAutoOn())
    {
        vDrvAnrNLProc(u4NoiseLvl);
    }

    if (_rCustNrWRegState[E_NR_CUST_ADAP_XNR].fgAutoOn())
    {
        vDrvAnrDCAlphaProc(u4NoiseLvl);
    }

    if (_rCustNrWRegState[E_NR_CUST_ADAP_RNR].fgAutoOn())
    {
        vDrvAnrRnrProc(u4NoiseLvl);
    }

    if (_rCustNrWRegState[E_NR_CUST_ADAP_MOANR].fgAutoOn())
    {
        vDrvAnrMoAnrProc(u4NoiseLvl, prNmAna->u1MoIdx);
    }
}
#endif


#ifndef CC_MTK_LOADER

BOOL bSRSCtrlProcReady(VOID)
{
    if(bSRSCtrlSemaInit && bSRSCtrlLoopInit)
        return TRUE;
    else
        return FALSE;
}
void vSRSCtrlProc(void)
{
#ifdef CC_FBM_SUPPORT_SRS
    //Used to send event to sony ko
    //In order to avoid mainloop stop due to ISR ng
    if(IS_DISP_4K2K_TYPE3 || ((PANEL_GetControlWord() & DISP_TYPE_MASK) == 0))
    {
        DRVCUST_SendEvent(E_CUST_OUT_SCALING_CHANGE, SV_VP_MAIN);
    }

#endif
}

static void _SRSCtrlLoop(void)
{
    while(TRUE && bSRSCtrlSemaInit)
    {
        VERIFY(x_sema_lock(_hSRSCtrlSemaphore, X_SEMA_OPTION_WAIT) == OSR_OK);
        vSRSCtrlProc();
    }
}

void vSRSCtrlProcUnlock(void)
{
    x_sema_unlock(_hSRSCtrlSemaphore);
}


#endif

//extern PE_UI_RANGE_TBL rPEUITable;

UINT32 DRVCUST_IsColorSpaceTypeBT2020(void)
{	
	CUST_PIC_SETTING_T prApPictureInfo;
	CUST_SIG_FMT_T pSignalFormat_M,pSignalFormat_P;
	
	BEPQ_AP_Get_Pic_Setting(&prApPictureInfo);

	pSignalFormat_M.eColorSpace = E_CUST_COL_SPACE_NORMAL;
	pSignalFormat_P.eColorSpace = E_CUST_COL_SPACE_NORMAL;
	
	if(bDrvVideoSignalStatus(VDP_1) == SV_VDO_STABLE)
	{
		DRVCUST_GetSignalFormat(VDP_1, &pSignalFormat_M);
	}
	
	if(bDrvVideoSignalStatus(VDP_2) == SV_VDO_STABLE)
	{
		DRVCUST_GetSignalFormat(VDP_2, &pSignalFormat_P);
	}
	
	switch(prApPictureInfo.eColorSpace)
	{
		case E_CUST_COL_SPACE_UI_AUTO:			
			if((pSignalFormat_M.eColorSpace == E_CUST_COL_SPACE_BT202C) 
				|| (pSignalFormat_M.eColorSpace == E_CUST_COL_SPACE_BT2020)
				|| (pSignalFormat_P.eColorSpace == E_CUST_COL_SPACE_BT202C)
				|| (pSignalFormat_P.eColorSpace == E_CUST_COL_SPACE_BT2020))
			{
				return SV_TRUE;
			}
			else
			{
				return SV_FALSE;
			}
			break;
		case E_CUST_COL_SPACE_UI_SRGB_709:
			return SV_FALSE;
			break;	
		case E_CUST_COL_SPACE_UI_DCI:
			return SV_FALSE;
			break;		
		case E_CUST_COL_SPACE_UI_ADOBE_RGB:
			return SV_FALSE;
			break;		
		case E_CUST_COL_SPACE_UI_2020:
			return SV_TRUE;
			break;
		default:
			return SV_FALSE;
			break;
	}	

}

UINT8 vApiGetUIColorSpace(void) //for SCE Index A/B/C/D   -->SDR/HDR10/HLG/DV
{
	CUST_PIC_SETTING_T rPicInfoFromAP;
	UINT8 u1HdrType = DRVCUST_VideoGetHDRType();
	UINT8 u1ColorSpaceIdx = 0;

	BEPQ_AP_Get_Pic_Setting(&rPicInfoFromAP);
	
	if(u1HdrType == SV_HDR_TYPE_HDR3) //DV return D
	{
		u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_D;
	}
	else
	{
		if (rPicInfoFromAP.eTransFunc == E_CUST_TRANSFER_FUNC_UI_AUTO)
		{
			if(u1HdrType==SV_HDR_TYPE_SDR)
			{
				if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_AUTO) //need to detect
				{
					if(DRVCUST_IsColorSpaceTypeBT2020())
					{
						u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_B;
					}
					else
					{
						u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
					}
				}
				else if((rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_SRGB_709)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_DCI)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_ADOBE_RGB))
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
				}
				else if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_2020)
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_B;
				}
			}
			else if(u1HdrType==SV_HDR_TYPE_HDR1)
			{
				if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_AUTO) //need to detect
				{
					if(DRVCUST_IsColorSpaceTypeBT2020())
					{
						u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_B;
					}
					else
					{
						u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
					}
				}
				else if((rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_SRGB_709)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_DCI)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_ADOBE_RGB))
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
				}
				else if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_2020)
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_B;
				}
			}
			else if(u1HdrType==SV_HDR_TYPE_HDR2)
			{
				if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_AUTO) //need to detect
				{
					if(DRVCUST_IsColorSpaceTypeBT2020())
					{
						u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_C;
					}
					else
					{
						u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
					}
				}
				else if((rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_SRGB_709)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_DCI)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_ADOBE_RGB))
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
				}
				else if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_2020)
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_C;
				}
			}
			//else if(u1HdrType==SV_HDR_TYPE_HDR3)
			//{
			//
			//}
			else if(u1HdrType==SV_HDR_TYPE_UNKNOWN)
			{
				if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_AUTO) //need to detect
				{
					if(DRVCUST_IsColorSpaceTypeBT2020())
					{
						u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_B;
					}
					else
					{
						u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
					}
				}
				else if((rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_SRGB_709)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_DCI)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_ADOBE_RGB))
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
				}
				else if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_2020)
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_B;
				}
			}
		}
		else if(rPicInfoFromAP.eTransFunc == E_CUST_TRANSFER_FUNC_UI_OFF)
		{
			if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_AUTO) //need to detect
			{
				if(DRVCUST_IsColorSpaceTypeBT2020())
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_B;
				}
				else
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
				}
			}
			else if((rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_SRGB_709)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_DCI)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_ADOBE_RGB))
			{
				u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
			}
			else if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_2020)
			{
				u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_B;
			}
		}
		else if(rPicInfoFromAP.eTransFunc == E_CUST_TRANSFER_FUNC_UI_HDR10)
		{
			if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_AUTO) //need to detect
			{
				if(DRVCUST_IsColorSpaceTypeBT2020())
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_B;
				}
				else
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
				}
			}
			else if((rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_SRGB_709)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_DCI)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_ADOBE_RGB))
			{
				u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
			}
			else if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_2020)
			{
				u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_B;
			}
		}
		else if(rPicInfoFromAP.eTransFunc == E_CUST_TRANSFER_FUNC_UI_HLG)
		{
			if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_AUTO) //need to detect
			{
				if(DRVCUST_IsColorSpaceTypeBT2020())
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_C;
				}
				else
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
				}
			}
			else if((rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_SRGB_709)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_DCI)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_ADOBE_RGB))
			{
				u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
			}
			else if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_2020)
			{
				u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_C;
			}
		}
		else //off-->sdr
		{
			if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_AUTO) //need to detect
			{
				if(DRVCUST_IsColorSpaceTypeBT2020())
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_B;
				}
				else
				{
					u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
				}
			}
			else if((rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_SRGB_709)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_DCI)||(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_ADOBE_RGB))
			{
				u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_A;
			}
			else if(rPicInfoFromAP.eColorSpace == E_CUST_COL_SPACE_UI_2020)
			{
				u1ColorSpaceIdx = SV_SCE_CLOR_TYPE_B;
			}
		}
	}
	return u1ColorSpaceIdx ;
}
UINT16 vApiFlashPqGetSceId()
{
	UINT32 u4SCEId;
	UINT8 u1UIColorTYPE = vApiGetUIColorSpace();

	if(u1UIColorTYPE == SV_SCE_CLOR_TYPE_D)//DV //9,19,11,12
	{
		if (gbSceUi == E_SCE_UI_OFF)
    	{
			u4SCEId = E_SCE_DV_OFF; 
    	} 
    	else if(gbSceUi == E_SCE_UI_LOW)
    	{
			u4SCEId = E_SCE_DV_LOW;
    	}
    	else if(gbSceUi == E_SCE_UI_MID)
    	{
			u4SCEId = E_SCE_DV_MID;
    	}
    	else if(gbSceUi == E_SCE_UI_HIGH)
    	{
			u4SCEId = E_SCE_DV_HIGH;
    	}
    	else
    	{
			u4SCEId = E_SCE_DV_OFF;
    	}
    	
	}
	else if(u1UIColorTYPE == SV_SCE_CLOR_TYPE_C)//HLG //no DV smart Pic 
	{
		if (gbSceUi == E_SCE_UI_OFF)
    	{
			u4SCEId = E_SCE_HLG_Off; 
    	} 
    	else if(gbSceUi == E_SCE_UI_LOW)
    	{
			u4SCEId = E_SCE_HLG_Low;
    	}
    	else if(gbSceUi == E_SCE_UI_MID)
    	{
			u4SCEId = E_SCE_HLG_Mid;
    	}
    	else if(gbSceUi == E_SCE_UI_HIGH)
    	{
			u4SCEId = E_SCE_HLG_High;
    	}
    	else
    	{
			u4SCEId = E_SCE_HLG_Off;
    	}
    	
	}
	else if(u1UIColorTYPE == SV_SCE_CLOR_TYPE_B)//BT2020
	{
		if (gbSceUi == E_SCE_UI_OFF)
    	{
			u4SCEId = E_SCE_ST_OFF_BT2020; //No DV smart Picture this jugement is SCE UI OFF
    	}    
    	//Blow is judge from Smart PICs
    	else 
	    {
	    	if (gbSmartPicIndex == E_SMART_PIC_VIVID) //samrt pic 0
		    {
		        if (gbSceUi == E_SCE_UI_LOW)
		            u4SCEId = E_SCE_ST_LOW_BT2020;
		        else if (gbSceUi == E_SCE_UI_MID)
		            u4SCEId = E_SCE_ST_MID_BT2020;
		        else    //HIGH OFF
		            u4SCEId = E_SCE_VIVID_BT2020;
		    }
		    else if ((gbSmartPicIndex == E_SMART_PIC_STANDARD)||(gbSmartPicIndex == E_SMART_PIC_GAME)||(gbSmartPicIndex == E_SMART_PIC_GRAPHICS)
			||(gbSmartPicIndex == E_SMART_PIC_CUSTOM)||(gbSmartPicIndex == E_SMART_PIC_USER1)||(gbSmartPicIndex == E_SMART_PIC_USER2)
			||(gbSmartPicIndex == E_SMART_PIC_NETFLIX_SDR)||(gbSmartPicIndex == E_SMART_PIC_RESERVED_1)||(gbSmartPicIndex == E_SMART_PIC_RESERVED_2)) ////smart PIC 1,3,4,6,7,8,13,14,15
		    {        
		        if (gbSceUi == E_SCE_UI_LOW)
		            u4SCEId = E_SCE_ST_LOW_BT2020;
		        else if (gbSceUi == E_SCE_UI_MID)
		            u4SCEId = E_SCE_ST_MID_BT2020;
		        else
		            u4SCEId = E_SCE_ST_HIGH_BT2020;        
		    } 
		    else if (gbSmartPicIndex == E_SMART_PIC_CINEMA)//smart PIC 2
		    {        
		        if (gbSceUi == E_SCE_UI_LOW)
		            u4SCEId = E_SCE_CI_LOW_BT2020;
		        else if (gbSceUi == E_SCE_UI_MID)
		            u4SCEId = E_SCE_CI_MID_BT2020;
		        else
		            u4SCEId = E_SCE_CI_HIGH_BT2020;        
		    }  
		    else if (gbSmartPicIndex == E_SMART_PIC_PHOTO) //smart PIC 5
		    {        
		        if (gbSceUi == E_SCE_UI_LOW)
		            u4SCEId = E_SCE_PH_LOW_BT2020;
		        else if (gbSceUi == E_SCE_UI_MID)
		            u4SCEId = E_SCE_PH_MID_BT2020;
		        else
		            u4SCEId = E_SCE_PH_HIGH_BT2020;
		    }
		    else
		    {        
		        LOG(0, "Unknown SCE : SmartPic  %d    SCE  %d\n", gbSmartPicIndex, gbSceUi);
		        u4SCEId = E_SCE_VIVID_BT2020;
		    }
		}
		
	}
	else if(u1UIColorTYPE == SV_SCE_CLOR_TYPE_A)//SDR
	{
		if (gbSceUi == E_SCE_UI_OFF)
    	{
			u4SCEId = E_SCE_ST_OFF; //No DV smart Picture this jugement is SCE UI OFF
    	}    
    	//Blow is judge from Smart PICs
    	else 
    	{
	    	if (gbSmartPicIndex == E_SMART_PIC_VIVID) //samrt pic 0
		    {
		        if (gbSceUi == E_SCE_UI_LOW)
		            u4SCEId = E_SCE_ST_LOW;
		        else if (gbSceUi == E_SCE_UI_MID)
		            u4SCEId = E_SCE_ST_MID;
		        else    //HIGH OFF
		            u4SCEId = E_SCE_VIVID;
		    }
		    else if ((gbSmartPicIndex == E_SMART_PIC_STANDARD)||(gbSmartPicIndex == E_SMART_PIC_GAME)||(gbSmartPicIndex == E_SMART_PIC_GRAPHICS)
			||(gbSmartPicIndex == E_SMART_PIC_CUSTOM)||(gbSmartPicIndex == E_SMART_PIC_USER1)||(gbSmartPicIndex == E_SMART_PIC_USER2)
			||(gbSmartPicIndex == E_SMART_PIC_NETFLIX_SDR)||(gbSmartPicIndex == E_SMART_PIC_RESERVED_1)||(gbSmartPicIndex == E_SMART_PIC_RESERVED_2)) ////smart PIC 1,3,4,6,7,8,13,14,15
		    {        
		        if (gbSceUi == E_SCE_UI_LOW)
		            u4SCEId = E_SCE_ST_LOW;
		        else if (gbSceUi == E_SCE_UI_MID)
		            u4SCEId = E_SCE_ST_MID;
		        else
		            u4SCEId = E_SCE_ST_HIGH;        
		    } 
		    else if (gbSmartPicIndex == E_SMART_PIC_CINEMA)//smart PIC 2
		    {        
		        if (gbSceUi == E_SCE_UI_LOW)
		            u4SCEId = E_SCE_CI_LOW;
		        else if (gbSceUi == E_SCE_UI_MID)
		            u4SCEId = E_SCE_CI_MID;
		        else
		            u4SCEId = E_SCE_CI_HIGH;        
		    }  
		    else if (gbSmartPicIndex == E_SMART_PIC_PHOTO) //smart PIC 5
		    {        
		        if (gbSceUi == E_SCE_UI_LOW)
		            u4SCEId = E_SCE_PH_LOW;
		        else if (gbSceUi == E_SCE_UI_MID)
		            u4SCEId = E_SCE_PH_MID;
		        else
		            u4SCEId = E_SCE_PH_HIGH;
		    }
		    else
		    {        
		        LOG(0, "Unknown SCE : SmartPic  %d    SCE  %d\n", gbSmartPicIndex, gbSceUi);
		        u4SCEId = E_SCE_VIVID;
		    }
		  }
		
	}
	else //SDR
	{
		if (gbSceUi == E_SCE_UI_OFF)
    	{
			u4SCEId = E_SCE_ST_OFF; //No DV smart Picture this jugement is SCE UI OFF
    	}    
    	//Blow is judge from Smart PICs
    	else 
    	{
	    	if (gbSmartPicIndex == E_SMART_PIC_VIVID) //samrt pic 0
		    {
		        if (gbSceUi == E_SCE_UI_LOW)
		            u4SCEId = E_SCE_ST_LOW;
		        else if (gbSceUi == E_SCE_UI_MID)
		            u4SCEId = E_SCE_ST_MID;
		        else    //HIGH OFF
		            u4SCEId = E_SCE_VIVID;
		    }
		    else if ((gbSmartPicIndex == E_SMART_PIC_STANDARD)||(gbSmartPicIndex == E_SMART_PIC_GAME)||(gbSmartPicIndex == E_SMART_PIC_GRAPHICS)
			||(gbSmartPicIndex == E_SMART_PIC_CUSTOM)||(gbSmartPicIndex == E_SMART_PIC_USER1)||(gbSmartPicIndex == E_SMART_PIC_USER2)
			||(gbSmartPicIndex == E_SMART_PIC_NETFLIX_SDR)||(gbSmartPicIndex == E_SMART_PIC_RESERVED_1)||(gbSmartPicIndex == E_SMART_PIC_RESERVED_2)) ////smart PIC 1,3,4,6,7,8,13,14,15
		    {        
		        if (gbSceUi == E_SCE_UI_LOW)
		            u4SCEId = E_SCE_ST_LOW;
		        else if (gbSceUi == E_SCE_UI_MID)
		            u4SCEId = E_SCE_ST_MID;
		        else
		            u4SCEId = E_SCE_ST_HIGH;        
		    } 
		    else if (gbSmartPicIndex == E_SMART_PIC_CINEMA)//smart PIC 2
		    {        
		        if (gbSceUi == E_SCE_UI_LOW)
		            u4SCEId = E_SCE_CI_LOW;
		        else if (gbSceUi == E_SCE_UI_MID)
		            u4SCEId = E_SCE_CI_MID;
		        else
		            u4SCEId = E_SCE_CI_HIGH;        
		    }  
		    else if (gbSmartPicIndex == E_SMART_PIC_PHOTO) //smart PIC 5
		    {        
		        if (gbSceUi == E_SCE_UI_LOW)
		            u4SCEId = E_SCE_PH_LOW;
		        else if (gbSceUi == E_SCE_UI_MID)
		            u4SCEId = E_SCE_PH_MID;
		        else
		            u4SCEId = E_SCE_PH_HIGH;
		    }
		    else
		    {        
		        LOG(0, "Unknown SCE : SmartPic  %d    SCE  %d\n", gbSmartPicIndex, gbSceUi);
		        u4SCEId = E_SCE_VIVID;
		    }
		  }
		
	}
	LOG(0, "u1SCEIDX IN GET %d,sCE UI %d \n", u4SCEId,gbSceUi);

	return u4SCEId;

}


UINT16 vApiFlashPqGetLceId(void)
{
	UINT32 u4LCEId = 0;
	UINT8 u1HDRTYPE = DRVCUST_VideoGetHDRType();
	
 if ((u1HDRTYPE == SV_HDR_TYPE_SDR)||(u1HDRTYPE == SV_HDR_TYPE_UNKNOWN))//sdr  A type
	{
		if (gbLceUi == E_SCE_UI_OFF)
		{
			u4LCEId = E_LCE_ST_OFF;

		} 
		else
		{
			if (gbSmartPicIndex == E_SMART_PIC_VIVID)
			{
				if (gbLceUi == E_SCE_UI_LOW)
					u4LCEId = E_LCE_ST_LOW;
				else if (gbLceUi == E_SCE_UI_MID)
					u4LCEId = E_LCE_ST_MID;
				else	
					u4LCEId = E_LCE_VIVID;
			}
			else if ((gbSmartPicIndex == E_SMART_PIC_STANDARD)||(gbSmartPicIndex == E_SMART_PIC_GAME)||(gbSmartPicIndex == E_SMART_PIC_GRAPHICS)
				||(gbSmartPicIndex == E_SMART_PIC_RESERVED_1)||(gbSmartPicIndex == E_SMART_PIC_RESERVED_2)) 
			{		 
				if (gbLceUi == E_SCE_UI_LOW)
					u4LCEId = E_LCE_ST_LOW;
				else if (gbLceUi == E_SCE_UI_MID)
					u4LCEId = E_LCE_ST_MID;
				else
					u4LCEId = E_LCE_ST_HIGH;		
			} 
			else if ((gbSmartPicIndex == E_SMART_PIC_CINEMA)||(gbSmartPicIndex == E_SMART_PIC_CUSTOM)||(gbSmartPicIndex == E_SMART_PIC_USER1)
			||(gbSmartPicIndex == E_SMART_PIC_USER2)||(gbSmartPicIndex == E_SMART_PIC_NETFLIX_SDR))
			{		 
				if (gbLceUi == E_SCE_UI_LOW)
					u4LCEId = E_LCE_CI_LOW;
				else if (gbLceUi == E_SCE_UI_MID)
					u4LCEId = E_LCE_CI_MID;
				else
					u4LCEId = E_LCE_CI_HIGH;		
			}  
			else if (gbSmartPicIndex == E_SMART_PIC_PHOTO) 
			{		 
				if (gbLceUi == E_SCE_UI_LOW)
					u4LCEId = E_LCE_PH_LOW;
				else if (gbLceUi == E_SCE_UI_MID)
					u4LCEId = E_LCE_PH_MID;
				else
					u4LCEId = E_LCE_PH_HIGH;
			}
			else
			{		 
				LOG(0, "Unknown LCE : SmartPic	%d	  LCE  %d\n", gbSmartPicIndex, gbLceUi);
				u4LCEId = E_SCE_VIVID;
			}
		}
	}
	else if((u1HDRTYPE == SV_HDR_TYPE_HDR1)||(u1HDRTYPE == SV_HDR_TYPE_HDR2))//B /c HDR10/HLGtype
	{
		if (gbLceUi == E_SCE_UI_OFF)
	    {
			u4LCEId = E_LCE_ST_OFF;
	    }
	    else
	    {
		    if (gbSmartPicIndex == E_SMART_PIC_VIVID)
		    {
		        if (gbLceUi == E_SCE_UI_LOW)
		            u4LCEId = E_LCE_ST_LOW;
		        else if (gbLceUi == E_SCE_UI_MID)
		            u4LCEId = E_LCE_ST_MID;
		        else    
		            u4LCEId = E_LCE_VIVID;
		    }
			else if ((gbSmartPicIndex == E_SMART_PIC_STANDARD)||(gbSmartPicIndex == E_SMART_PIC_GAME)
				||(gbSmartPicIndex == E_SMART_PIC_GRAPHICS)
				//||(gbSmartPicIndex == E_SMART_PIC_NETFLIX_SDR)
				||(gbSmartPicIndex == E_SMART_PIC_RESERVED_1)||(gbSmartPicIndex == E_SMART_PIC_RESERVED_2)) //1,3,4,14,15
			{		 
				if (gbLceUi == E_SCE_UI_LOW)
					u4LCEId = E_LCE_ST_LOW;
				else if (gbLceUi == E_SCE_UI_MID)
					u4LCEId = E_LCE_ST_MID;
				else
					u4LCEId = E_LCE_ST_HIGH;		
			} 
			else if ((gbSmartPicIndex == E_SMART_PIC_CINEMA)||(gbSmartPicIndex == E_SMART_PIC_CUSTOM) //2,6,7,8
				||(gbSmartPicIndex == E_SMART_PIC_USER1)||(gbSmartPicIndex == E_SMART_PIC_USER2))
			{		 
				if (gbLceUi == E_SCE_UI_LOW)
					u4LCEId = E_LCE_CI_LOW;
				else if (gbLceUi == E_SCE_UI_MID)
					u4LCEId = E_LCE_CI_MID;
				else
					u4LCEId = E_LCE_CI_HIGH;		
			}  
			else if (gbSmartPicIndex == E_SMART_PIC_PHOTO) 
			{		 
				if (gbLceUi == E_SCE_UI_LOW)
					u4LCEId = E_LCE_PH_LOW;
				else if (gbLceUi == E_SCE_UI_MID)
					u4LCEId = E_LCE_PH_MID;
				else
					u4LCEId = E_LCE_PH_HIGH;
			}
			else
			{		 
				LOG(0, "Unknown SCE : SmartPic	%d	  SCE  %d\n", gbSmartPicIndex, gbLceUi);
				u4LCEId = E_LCE_VIVID;
			}

		   
		}
		// for BT2020 need different LCE curve, so need another group of Lce curve.
		if(!((gbSmartPicIndex == E_SMART_PIC_DV_DARK)||(gbSmartPicIndex == E_SMART_PIC_DV_BRIGHT)||(gbSmartPicIndex == E_SMART_PIC_DV_VIVIDE)
			||(gbSmartPicIndex == E_SMART_PIC_NETFLIX_DV)))
		{
		
			u4LCEId = (u4LCEId + 11*u1HDRTYPE);//from HDR10 add on
		}
	}
	else if(u1HDRTYPE == SV_HDR_TYPE_HDR3)//DV part
	{
		//DV part  
		if(((gbSmartPicIndex == E_SMART_PIC_DV_DARK)||(gbSmartPicIndex == E_SMART_PIC_DV_BRIGHT)
			||(gbSmartPicIndex == E_SMART_PIC_NETFLIX_DV)))
		{
			if ((gbLceUi == E_SCE_UI_OFF))
				u4LCEId = E_LCE_DV_OFF;
			else if (gbLceUi == E_SCE_UI_LOW)
				u4LCEId = E_LCE_DV_LOW;
			else if (gbLceUi == E_SCE_UI_MID)
				u4LCEId = E_LCE_DV_MID;
			else
				u4LCEId = E_LCE_DV_HIGH;
		}
		else//(gbSmartPicIndex == E_SMART_PIC_DV_VIVIDE)
		{
			if ((gbLceUi == E_SCE_UI_OFF))
				u4LCEId = E_LCE_DV_OFF;
			else if (gbLceUi == E_SCE_UI_LOW)
				u4LCEId = E_LCE_DV_LOW;
			else if (gbLceUi == E_SCE_UI_MID)
				u4LCEId = E_LCE_DV_MID;
			else
				u4LCEId = E_LCE_DV_VIVID;
		}
		
	
	}
	else
	{
		u4LCEId = E_LCE_VIVID;
	}
	LOG(0, "u1LCEIDX IN GET %d,sCE UI %d \n", u4LCEId,gbLceUi);

	return u4LCEId;
}


UINT16 vApiFlashPqGetMinSceId()
{
    //This is sample code : SCE ID can be decided 
    //by panel id , ui setting, picture mode .....
    //UINT8 bPanelIdx = GetCurrentPanelIndex();

    return (1);
}

void vApiFlashPqSetSceId(UINT8 bIndex)
{
    gbSceUi = bIndex;
	LOG(1,"***gbSceUi=%d *****\n", gbSceUi);
}

void vApiFlashPqSetLceId(UINT8 bIndex)
{
    gbLceUi = bIndex;
	LOG(1,"***gbLceUi=%d *****\n", gbLceUi);
}

UINT16 vApiFlashPqGetOdId(void)
{
    //UINT8 bPanelIdx = GetCurrentPanelIndex();   
    
    return gbOdUi;
}

void vApiFlashPqSetOdId(UINT8 bIndex)
{
    gbOdUi = bIndex;
}

UINT16 vApiFlashPqGetGammaId()
{
    return gbGammaUi;
}

void vApiFlashPqSetGammaId(UINT8 bIndex)
    {
    if (bIndex == D_AP_PIC_COL_TMP_COOL)
    {
    	gbGammaUi = E_CT_COOL;
    }
	else if (bIndex == D_AP_PIC_COL_TMP_NATURAL)
    {
    	gbGammaUi = E_CT_NEUTRAL;
    }
	else if (bIndex == D_AP_PIC_COL_TMP_WARM)
    {
        if (gbSmartPicIndex == D_AP_PIC_MODE_PHOTO)
    	{
            gbGammaUi = E_CT_WARM1;
    	}    
        else
        {
            gbGammaUi = E_CT_WARM1;
			//just keep
    }    
    }
	else if (bIndex == D_AP_PIC_COL_TMP_EXPERT1)
    {
        if (gbSmartPicIndex == D_AP_PIC_MODE_PHOTO)
        {
            gbGammaUi = E_CT_WARM2;
        }
        else
        {
            gbGammaUi = E_CT_WARM2;
			//just keep
    }
    }
	else if (bIndex == D_AP_PIC_COL_TMP_EXPERT2)
    {
        if (gbSmartPicIndex == D_AP_PIC_MODE_PHOTO)
        {
            gbGammaUi = E_CT_PHOTO;
        }
        else
        {
            gbGammaUi = E_CT_WARM2;
        }
    }    
    else
    {        
        LOG(0, "Unknown Gamma : SmartPic  %d    Gamma  %d\n", gbSmartPicIndex, gbGammaUi);
        gbGammaUi = E_CT_COOL;
}
}

UINT16 vApiFlashPqGetQtyId(UINT8 bIndex)
{
	UNUSED(bIndex);

	return (0);

}


void vApiFlashPqSetSmartPicId(UINT8 bIndex)
{
#if 0    
#ifndef CC_DRIVER_PROGRAM    
	UINT8 i4UiIndex, j;

	Printf("Smart Pic XXXXX %d\n", bIndex);
#endif
#endif
    gbSmartPicIndex = bIndex;
	LOG(1,"gbSmartPicIndex =%d ***\n", gbSmartPicIndex);
	
#if (defined CC_SUPPORT_DOLBY_VISION && defined CC_DOLBY_SDK_SUPPORT)
	if(u4DolbyGetCustSourceInfo(VDP_1))
	{
	    vDolbySetPicMode(bIndex);//used for set dolby pic mode ready flag
	}
#endif

#if 0
#ifndef CC_DRIVER_PROGRAM
#ifdef __KERNEL__   
	ASSERT(rPEUITable.ptUiPicMinMaxDftTbl!=NULL && gbSmartPicIndex<rPEUITable.bSmartPicNum);   
	// update all source UI default table, since the table is same
	for (i4UiIndex = 0; i4UiIndex < (UINT8)EVDP_VIS_MAX; i4UiIndex++)
	{
		for(j=0; j< rPEUITable.bUIPQItemNum; j++)
		{
			if(rPEUITable.ptUiPicMinMaxDftTbl[gbSmartPicIndex][j].rPQItemType >=PE_ARG_BRIGHTNESS &&
				rPEUITable.ptUiPicMinMaxDftTbl[gbSmartPicIndex][j].rPQItemType < PE_ARG_NS)
			{
/*				printf("rPEUITable.ptUiPicMinMaxDftTbl[%d][%d].rPQItemType| %x, Min %x, Max %x, Dft %x \n", gbSmartPicIndex,j,rPEUITable.ptUiPicMinMaxDftTbl[gbSmartPicIndex][j].rPQItemType,
					rPEUITable.ptUiPicMinMaxDftTbl[gbSmartPicIndex][j].rPQItemRange.i4Min, rPEUITable.ptUiPicMinMaxDftTbl[gbSmartPicIndex][j].rPQItemRange.i4Max,
					rPEUITable.ptUiPicMinMaxDftTbl[gbSmartPicIndex][j].rPQItemRange.i4Dft);
*/
				PE_SetUiRange(i4UiIndex, rPEUITable.ptUiPicMinMaxDftTbl[gbSmartPicIndex][j].rPQItemType, 
														 &(rPEUITable.ptUiPicMinMaxDftTbl[gbSmartPicIndex][j].rPQItemRange));
			}
		}
}
#endif
#endif
#endif
}

UINT8 vApiFlashPqGetSmartPicId()
{
	if((gbSmartPicIndex == E_SMART_PIC_RESERVED_1)||(gbSmartPicIndex == E_SMART_PIC_RESERVED_2))
	{
		return E_SMART_PIC_CINEMA;
	}
	else
	{
    	return (gbSmartPicIndex);
	}
}

UINT8 DRVCUST_GetUISmartPicId()
{
    return (gbSmartPicIndex);
}


UINT16 u2ApiFlashPqGetRawDataTblId(void)
{
    return gu2RawDataTblIndex;
}

UINT16 u2ApiFlashPqGetRawDataCaseId(void)
{
    return gu2RawDataCaseIndex;
}

void vApiFlashPqSetRawDataTblId(UINT16 u2Index)
{
    gu2RawDataTblIndex = u2Index;
}

void vApiFlashPqSetRawDataCaseId(UINT16 u2Index)
{
    gu2RawDataCaseIndex = u2Index;
}

UINT8 bApiFlashPqUpdateRawDataEx(UINT16 u2TblId, UINT16 u2CaseId)
{
	RAWDATA_INFO stRawInfo;
	vApiFlashPqSetRawDataTblId(u2TblId);
	vApiFlashPqSetRawDataCaseId(u2CaseId);

	bApiFlashPqUpdateRawData();
	bApiFlashPqGetRawDataInfo(&stRawInfo);
	bApiFlashPqSetRawData(stRawInfo.u2RegNum, stRawInfo.pRegTbl, stRawInfo.pDataTbl);

	return SV_TRUE;
}


void DRVCUST_SetMacbethOnOff(UINT8 bOnoff, UINT16 u2Ylvl, UINT16 u2Ulvl, UINT16 u2Vlvl)
{
	if(bOnoff)
	{
		memset(DRVCUST_pMecbethMatrix, 0x00, sizeof(DRVCUST_pMecbethMatrix));
		DRVCUST_pMecbethMatrix[12] = u2Ylvl;
		DRVCUST_pMecbethMatrix[13] = u2Ulvl;
		DRVCUST_pMecbethMatrix[14] = u2Vlvl;
		
		x_memcpy(pPedestalMatrixISR, DRVCUST_pMecbethMatrix, sizeof(DRVCUST_pMecbethMatrix));
        vApiRegisterVideoEvent(PE_EVENT_COLOR_TRANSFORM, SV_VP_MAIN, SV_ON);
	}
	else
	{
		vVdoSetColorTransform(SV_VP_MAIN);
	}
}

void cbSony_GammaOSDControl(void* pvArg);

void DRVCUST_SetWBTestPtnOnOff(UINT8 bOnoff, UINT16 u2Rlvl, UINT16 u2Glvl, UINT16 u2Blvl)
{
    static WB_TEST_PTN_STATUS WBTestPtnStatus = {SV_OFF, SV_OFF, SV_OFF, SV_OFF, SV_OFF, SV_OFF, SV_OFF};
    static INT32 DRVCUST_pWBTestPtnMatrix[15]={0};
    UINT8 u1bOSDOnOff;
    
	if(bOnoff)
	{
	    if(SV_OFF == WBTestPtnStatus.u1PtnOnOff)
	    {
            //get status
            WBTestPtnStatus.u1PtnOnOff = SV_ON;
            
            //disable blue stretch
            WBTestPtnStatus.u1BlueStretchOnOff = bDrvGetBlueStretchOnOff();
            if(WBTestPtnStatus.u1BlueStretchOnOff)
            {
                vDrvSetBlueStretchOnOff(SV_VP_MAIN, SV_OFF);
            }

            
            //disable xvycc
            WBTestPtnStatus.u1XvYccOnOff = bDrvGetxvYCCOnOff();
            if(WBTestPtnStatus.u1XvYccOnOff)
            {
                vDrvxvYCCOnOff(SV_OFF);
            }
            
            //disable OPC
            WBTestPtnStatus.u1OPCOnOff = IO32ReadFldAlign(DBL_00, DBL_ENABLE);
            if(WBTestPtnStatus.u1OPCOnOff)
            {
                vIO32WriteFldAlign(DBL_00, SV_OFF, DBL_ENABLE);
            }
            
            //disable Mute
            WBTestPtnStatus.u1MuteOnOff = fgMainMuteOn();
            if(WBTestPtnStatus.u1MuteOnOff)
            {
                vDrvMainMute(SV_OFF);
            }

            if(3 == IO32ReadFldAlign(OSTG_01, REG_OP_SEL))
            {
                #ifdef CC_MAPLE_CUST_DRV
                //disable LD
                WBTestPtnStatus.u1LDOnOff = !IO32ReadFldAlign(LD2_MODE_00, C_LD_BYPASS);
                vIO32WriteFldAlign(LD2_MODE_00, SV_TRUE, C_LD_BYPASS);
                #endif

                //disable PreDither
                WBTestPtnStatus.u1PreDitherSel = IO32ReadFldAlign(OS_DITHER_00, DITHER_LFSR_EN);
                vOSTG_IO32WriteFldAlign(OS_DITHER_00, 0, DITHER_LFSR_EN);

                //disable PostDither
                WBTestPtnStatus.u1PostDitherSel = IO32ReadFldAlign(OS_DITHER_03, REG_LFSR_EN_POST);
                vOSTG_IO32WriteFldAlign(OS_DITHER_03, 0, REG_LFSR_EN_POST);
                     
                //disable OD
                WBTestPtnStatus.u1ODOnOff = IO32ReadFldAlign(OD_REG54, BYPASS_ALL_SYNC_V);
                vIO32WriteFldAlign(OD_REG54, SV_TRUE, BYPASS_ALL_SYNC_V);
            }

            //disable OSD
            u1bOSDOnOff = SV_ON;
            cbSony_GammaOSDControl(&u1bOSDOnOff);
	    }
	    
		memset(DRVCUST_pWBTestPtnMatrix, 0x00, sizeof(DRVCUST_pWBTestPtnMatrix));
		DRVCUST_pWBTestPtnMatrix[12] = u2Rlvl;
		DRVCUST_pWBTestPtnMatrix[13] = u2Glvl;
		DRVCUST_pWBTestPtnMatrix[14] = u2Blvl;
		
		vLoadOSColorMatrix(SV_VP_MAIN, DRVCUST_pWBTestPtnMatrix);
	}
	else
	{
	    if(SV_ON == WBTestPtnStatus.u1PtnOnOff)
	    {
            //set status
            WBTestPtnStatus.u1PtnOnOff = SV_OFF;
            
            vDrvSetBlueStretchOnOff(SV_VP_MAIN, WBTestPtnStatus.u1BlueStretchOnOff);
            vDrvxvYCCOnOff(WBTestPtnStatus.u1XvYccOnOff);
            vIO32WriteFldAlign(DBL_00, WBTestPtnStatus.u1XvYccOnOff, DBL_ENABLE);
            vDrvMainMute(WBTestPtnStatus.u1MuteOnOff);
            if(3 == IO32ReadFldAlign(OSTG_01, REG_OP_SEL))
            {
                #ifdef CC_MAPLE_CUST_DRV
                vIO32WriteFldAlign(LD2_MODE_00, WBTestPtnStatus.u1LDOnOff, C_LD_BYPASS);
                #endif
                vIO32WriteFldAlign(OS_DITHER_00, WBTestPtnStatus.u1PreDitherSel, DITHER_LFSR_EN);
                vIO32WriteFldAlign(OS_DITHER_03, WBTestPtnStatus.u1PostDitherSel, REG_LFSR_EN_POST);
                vIO32WriteFldAlign(OD_REG54, WBTestPtnStatus.u1ODOnOff, BYPASS_ALL_SYNC_V);
            }

            u1bOSDOnOff = SV_OFF;
            cbSony_GammaOSDControl(&u1bOSDOnOff);
	    }
	    
	    vLoadOSColorMatrix(SV_VP_MAIN, COLOR_TRANSFORM_ADJ);
	}
}

/*
DRV_WB_TEST_PTN DRVCUST_GetWBTestPtnOnOff(void)
{
    DRV_WB_TEST_PTN temp;
    
    return temp;
}
*/

void DRVCUST_SetPGAM_EN(UINT8 bOnoff)
{
    bGammaLinear = (bOnoff==0) ? 1 : 0;
    DRVCUST_SET_GAMMA();
    //vDrvGammaOnOff(bOnoff);
}

UINT8 DRVCUST_GetPGAM_EN(void)
{
    return (!bGammaLinear);
}

void DRVCUST_ReadRGBGainOfst(void)
{
	u2WBGain[SV_RGB_R] = wDrvGetRGain1(SV_VP_MAIN);
	u2WBGain[SV_RGB_G] = wDrvGetGGain1(SV_VP_MAIN);
	u2WBGain[SV_RGB_B] = wDrvGetBGain1(SV_VP_MAIN);
	u2WBOfst[SV_RGB_R] = dwDrvGetROffset11(SV_VP_MAIN);
	u2WBOfst[SV_RGB_G] = dwDrvGetGOffset11(SV_VP_MAIN);
	u2WBOfst[SV_RGB_B] = dwDrvGetBOffset11(SV_VP_MAIN);
}

void DRVCUST_SetUWBFLAT(UINT8 bOnoff)
{
    bOnoff = bOnoff ? SV_TRUE : SV_FALSE;
	if(bOnoff == bWBFlatPreOnoff)
		return;
	
	if(bOnoff)
	{
		DRVCUST_ReadRGBGainOfst();
		
		vHalVideoRGBGain(SV_VP_MAIN, SV_RGB_R, 0x200);
	    vHalVideoRGBGain(SV_VP_MAIN, SV_RGB_G, 0x200);
	    vHalVideoRGBGain(SV_VP_MAIN, SV_RGB_B, 0x200);
	    vHalVideoRGBOffset(SV_VP_MAIN, SV_RGB_R ,0);
	    vHalVideoRGBOffset(SV_VP_MAIN, SV_RGB_G ,0);
	    vHalVideoRGBOffset(SV_VP_MAIN, SV_RGB_B ,0);
	}
	else
	{
		vHalVideoRGBGain(SV_VP_MAIN, SV_RGB_R, u2WBGain[SV_RGB_R]);
	    vHalVideoRGBGain(SV_VP_MAIN, SV_RGB_G, u2WBGain[SV_RGB_G]);
	    vHalVideoRGBGain(SV_VP_MAIN, SV_RGB_B, u2WBGain[SV_RGB_B]);
	    vHalVideoRGBOffset(SV_VP_MAIN, SV_RGB_R, u2WBOfst[SV_RGB_R]);
	    vHalVideoRGBOffset(SV_VP_MAIN, SV_RGB_G, u2WBOfst[SV_RGB_G]);
	    vHalVideoRGBOffset(SV_VP_MAIN, SV_RGB_B, u2WBOfst[SV_RGB_B]);
	}

    bWBFlatPreOnoff = bOnoff;
	DRVCUST_SET_GAMMA();
}

UINT8 DRVCUST_GetUWBFLAT(void)
{
    return (bWBFlatPreOnoff ? SV_TRUE : SV_FALSE);
}

void DRVCUST_Set4BandFilterRangHw(CUST_4BAND_FILTER_RANGE * pFilterRange)
{
	if(pFilterRange!=NULL)
	{
		vIO32WriteFldAlign(PRE_DS_FIL_14, pFilterRange->h_filter_h_start, H_FILTER_H_START);
		vIO32WriteFldAlign(PRE_DS_FIL_14, pFilterRange->h_filter_v_start, H_FILTER_V_START);
		
		vIO32WriteFldAlign(PRE_DS_FIL_15, pFilterRange->h_filter_h_size, H_FILTER_H_SIZE);
		vIO32WriteFldAlign(PRE_DS_FIL_15, pFilterRange->h_filter_v_size, H_FILTER_V_SIZE);
	}
}

void DRVCUST_Set4BandHFilterHw(CUST_4BAND_H_FILTER * pFiltersetting)
{
	UINT8 i;
	UINT32 temp;
	//set band0
	vIO32WriteFldAlign(PRE_DS_FIL_16, pFiltersetting->bitshift_a0, BITSHIFT_A0);
	vIO32WriteFldAlign(PRE_DS_FIL_16, pFiltersetting->bitshift_b0, BITSHIFT_B0);
	vIO32WriteFldAlign(PRE_DS_FIL_16, pFiltersetting->h_filter_switch_0, H_FILTER_SWITCH_0);
	vIO32WriteFldAlign(PRE_DS_FIL_97, pFiltersetting->h_filter_band0_div, H_FILTER_BAND0_DIV);
	for(i=0; i<7; i++)
	{
		temp = (pFiltersetting->h_filter_band0_coef[3*i]&0x3FF) << 20 |
				(pFiltersetting->h_filter_band0_coef[3*i+1]&0x3FF)<<10 |
				pFiltersetting->h_filter_band0_coef[3*i+2]&0x3FF;
		if(i<6)
		{
			vIO32Write4B(PRE_DS_FIL_00 + 4*i, temp);	
		}
		else
		{
			vIO32Write4B(PRE_DS_FIL_00 + 4*(i+1), temp);	
		}
	}

	//set band1
	vIO32WriteFldAlign(PRE_DS_FIL_16, pFiltersetting->bitshift_a1, BITSHIFT_A1);
	vIO32WriteFldAlign(PRE_DS_FIL_16, pFiltersetting->bitshift_b1, BITSHIFT_B1);
	vIO32WriteFldAlign(PRE_DS_FIL_16, pFiltersetting->h_filter_switch_1, H_FILTER_SWITCH_1);
	vIO32WriteFldAlign(PRE_DS_FIL_97, pFiltersetting->h_filter_band1_div, H_FILTER_BAND1_DIV);	
	for(i=0; i<4; i++)
	{
		if(i<3)
		{
			temp = (pFiltersetting->h_filter_band1_coef[4*i]&0xFF) << 24 |
				(pFiltersetting->h_filter_band1_coef[4*i+1]&0xFF) <<16 |
				(pFiltersetting->h_filter_band1_coef[4*i+2]&0xFF) <<8 |
				pFiltersetting->h_filter_band1_coef[4*i+3]&0xFF;
			if(i<2)
			{
				vIO32Write4B(PRE_DS_FIL_07 + 4*i, temp);
			}
			else
			{
				vIO32Write4B(PRE_DS_FIL_07 + 4*(i+1), temp);
			}
		}
		else
		{		
			temp = (pFiltersetting->h_filter_band1_coef[4*i]&0xFF) <<16 |
				(pFiltersetting->h_filter_band1_coef[4*i+1]&0xFF)<<8 |
				pFiltersetting->h_filter_band1_coef[4*i+2]&0xFF;
			vIO32Write4B(PRE_DS_FIL_07 + 4*(i+1), temp);
		}
	}	
	
	//set band2
	vIO32WriteFldAlign(PRE_DS_FIL_16, pFiltersetting->bitshift_a2, BITSHIFT_A2);
	vIO32WriteFldAlign(PRE_DS_FIL_16, pFiltersetting->bitshift_b2, BITSHIFT_B2);
	vIO32WriteFldAlign(PRE_DS_FIL_16, pFiltersetting->h_filter_switch_2, H_FILTER_SWITCH_2);
	vIO32WriteFldAlign(PRE_DS_FIL_97, pFiltersetting->h_filter_band2_div, H_FILTER_BAND2_DIV);
	for(i=0; i<4; i++)
	{
		if(i<3)
		{
			temp = (pFiltersetting->h_filter_band2_coef[4*i]&0xFF) << 24 |
				(pFiltersetting->h_filter_band2_coef[4*i+1]&0xFF)<<16 |
				(pFiltersetting->h_filter_band2_coef[4*i+2]&0xFF)<<8 |
				pFiltersetting->h_filter_band2_coef[4*i+3]&0xFF;
			if(i<1)
			{
				vIO32Write4B(PRE_DS_FIL_0B + 4*i, temp);
			}
			else
			{
				vIO32Write4B(PRE_DS_FIL_0B + 4*(i+1), temp);
			}
		}
		else
		{		
			temp = (pFiltersetting->h_filter_band2_coef[4*i]&0xFF) <<16 |
				(pFiltersetting->h_filter_band2_coef[4*i+1]&0xFF)<<8 |
				pFiltersetting->h_filter_band2_coef[4*i+2]&0xFF;
			vIO32Write4B(PRE_DS_FIL_0B + 4*(i+1), temp);
		}
	}
	
	//set band3
	vIO32WriteFldAlign(PRE_DS_FIL_16, pFiltersetting->bitshift_a3, BITSHIFT_A3);
	vIO32WriteFldAlign(PRE_DS_FIL_16, pFiltersetting->bitshift_b3, BITSHIFT_B3);
	vIO32WriteFldAlign(PRE_DS_FIL_16, pFiltersetting->h_filter_switch_3, H_FILTER_SWITCH_3);
	vIO32WriteFldAlign(PRE_DS_FIL_97, pFiltersetting->h_filter_band3_div, H_FILTER_BAND3_DIV);
	for(i=0; i<4; i++)
	{
		if(i<3)
		{
			temp = (pFiltersetting->h_filter_band3_coef[4*i]&0xFF) << 24 |
				(pFiltersetting->h_filter_band3_coef[4*i+1]&0xFF)<<16 |
				(pFiltersetting->h_filter_band3_coef[4*i+2]&0xFF)<<8 |
				pFiltersetting->h_filter_band3_coef[4*i+3]&0xFF;
			vIO32Write4B(PRE_DS_FIL_0F + 4*i, temp);
		}
		else
		{		
			temp = (pFiltersetting->h_filter_band3_coef[4*i]&0xFF) <<16 |
				(pFiltersetting->h_filter_band3_coef[4*i+1]&0xFF)<<8 |
				pFiltersetting->h_filter_band3_coef[4*i+2]&0xFF;
			vIO32Write4B(PRE_DS_FIL_0F + 4*(i+1), temp);
		}
	}	

}

void DRVCUST_Get4BandFreqHistHw(CUST_4BAND_HIST_T *pHistValue )
{
	UINT8 i;
	
	if(pHistValue!=NULL)
	{
		for(i=0; i<16; i++)
		{
			pHistValue->a0_hist[i]= u4IO32Read4B(PRE_DS_FIL_17+4*i);
			pHistValue->b0_hist[i]= u4IO32Read4B(PRE_DS_FIL_27+4*i);
			
			pHistValue->a1_hist[i]= u4IO32Read4B(PRE_DS_FIL_37+4*i);
			pHistValue->b1_hist[i]= u4IO32Read4B(PRE_DS_FIL_47+4*i);
			
			pHistValue->a2_hist[i]= u4IO32Read4B(PRE_DS_FIL_57+4*i);
			pHistValue->b2_hist[i]= u4IO32Read4B(PRE_DS_FIL_67+4*i);
			
			pHistValue->a3_hist[i]= u4IO32Read4B(PRE_DS_FIL_77+4*i);
			pHistValue->b3_hist[i]= u4IO32Read4B(PRE_DS_FIL_87+4*i);
		}
	}
}

/*
* For Sakura eeprom dual bank
*  @i4Ret   0        SUCCESS.
*  @i4Ret   1        FAIL.
*/
UINT8 DRVCUST_DoubleEepromWrite(UINT64 u8Offset, UPTR u4MemPtr, UINT32 u4MemLen)
{
    UINT8 i;
    INT32 i4Ret;

#if defined(CC_MAPLE_CUST_DRV)
    UINT32 u4Series = 0;
    UNUSED(DRVCUST_InitQuery(eGetSeries, &u4Series));
    if( u4Series == 0x04 )  // 0x04: FY18 Uroboros
    {
        // skip eeprom write for FY18 models
        return 0;
    }
#endif
    
    for(i=0; i<2; i++)
    {
        i4Ret = EEPROM_Write(u8Offset,(UPTR)u4MemPtr, u4MemLen);

    	if(i4Ret)
    	{
    		Printf("Double EEP Write Error\n");
    		return (1);
    	}
	}
	
	return (0);
}

UINT8 DRVCUST_EepromReadByte(UINT16 waddr)
{
	INT32 i4Ret;
	UINT8 u4Data = 0;
	
	i4Ret = EEPROM_Read(waddr, (UPTR)&u4Data, 1);

	if(i4Ret)
	{
		Printf("EEP ReadByte Error\n");
		return (0);
	}
	return (u4Data);
}

BOOL DRVCUST_EepromWriteByte(UINT16 waddr, UINT8 u1Data)
{
	INT32 i4Ret;
	
	i4Ret = DRVCUST_DoubleEepromWrite(waddr, (UPTR)&u1Data, 1);
	
	if(i4Ret)
	{
		return (SV_FALSE);
	}
	else
	{
		return (SV_TRUE);
	}
}

#ifdef CC_SONY_GAMMA 
void CheckToEnablePBM(void)
{
	/*
    UINT8 bPBMOnOff,bMagic1,bMagic2;
    EEPROM_Read(CUSTOM_GAMMA_BASE,(UPTR)&bMagic1, 1);
    EEPROM_Read((CUSTOM_GAMMA_BASE+0x1),(UPTR)&bMagic2, 1); 
    
    bPBMOnOff = ((bApiEepromReadByte(EEP_PBM_GAMMA_ONOFF)==0x01)&&
                  (bMagic1 == GAMMA_MAGIC00)&&
                  (bMagic2 == GAMMA_MAGIC01));
    //vIO32WriteFldAlign(CUST_GAMMA_01, bPBMOnOff, CUST_GAMMA_PBM_ON);
    */
}

void DRVCUST_SetPBMGammaByte(UINT8 bOnOff)
{
    DRVCUST_EepromWriteByte(EEP_WB_LUT_ADJ_ON, bOnOff);
}
UINT8 DRVCUST_GetPBMGammaByte(void)
{
	return DRVCUST_EepromReadByte(EEP_WB_LUT_ADJ_ON);
}

void DRVCUST_TurnOnInkMark(UINT8 ui1_onOff)
{
    if(ui1_onOff)
    {
        vRegWriteFldAlign(DBG_CFG_MAIN, 1, INK_EN);
        vRegWriteFldAlign(DBG_CFG_MAIN, 0, Y_INK_MODE);
        vRegWriteFldAlign(DBG_CFG_MAIN, 0, CB_INK_MODE);
        vRegWriteFldAlign(DBG_CFG_MAIN, 0, CR_INK_MODE);

        // ink color
        vRegWriteFldMulti(INK_DATA_MAIN,
            P_Fld(0x100, INK_DATA_Y) |
            P_Fld(0, INK_DATA_CB));
        vRegWriteFldAlign(INK_DATA_MAIN_CR, 0, INK_DATA_CR);
    }
    else
    {
        vRegWriteFldAlign(DBG_CFG_MAIN, 0, INK_EN);
    }
}
void DRVCUST_SetInkMark(UINT16 ui2_x, UINT16 ui2_y)
{
    vRegWriteFldMulti(POS_MAIN, P_Fld(ui2_x, SCE_POS_X)|P_Fld(ui2_y, SCE_POS_Y));
}
#endif
void DRVCUST_SetOutputRGB2YUV(void)
{
	UINT8 u1PanelIdx = GetCurrentPanelIndex();
	
	//if((u1PanelIdx == PANEL_LG_42_WU5_SLB1_VB1) || (u1PanelIdx == PANEL_VB1_V420DK1_KS1) || (u1PanelIdx == PANEL_4K1K_VB1))
	if(IS_DISP_4K2K_FORMAT_YUV444)
	{
		//vIO32WriteFldAlign(OSTG_01, SV_ON, REG_RGB2YUV_BYPASS);
		fgYUVout = SV_TRUE;
	}
}

void DRVCUST_4KBE_OSTG_Bypass(void)
{
#ifdef CC_COMBINE_4K_2K
		UINT32 u4ModelType = 0;
	    UINT32 u4BeType = 0;

	    UNUSED(DRVCUST_InitQuery(eGet2KModelSupport, &u4ModelType));
	    UNUSED(DRVCUST_InitQuery(eGet4KModelBEType, &u4BeType));
		if((u4BeType==0) && (!IsPQICExists()))
		{
			//2K/4K Model 
		}
		else
		{
            //BE modell
            //Blue Stretch
            vOSTG_IO32WriteFldAlign(BLUESTCH_00, SV_ON, C_BS_BYPASS);

			//bypass OS 3x3 //temperal fix
           //vOSTG_IO32WriteFldAlign(YCBCR2RGB_00, SV_ON, YUV2RGB_BYPASS_MAIN);			
           //vOSTG_IO32WriteFldAlign(YCBCR2RGB_00, SV_ON, YUV2RGB_BYPASS_PIP);			

            //xvYCC
            //vDrvxvYCCOnOff(SV_OFF);
            //tempral fix
            vOSTG_IO32WriteFldAlign(XVYCC_00, 0x1, REG_BYPASS_XV_IN2OUT);
            vOSTG_IO32WriteFldAlign(XVYCC_00, 0x0, REG_ROUND_12TO10);            
            vOSTG_IO32WriteFldAlign(OSTG_00, 0x0, REG_XVYCC_CLIP_EN);
            
			//vDrvxvYCC2OnOff(SV_OFF);

            //OPC
            vOSTG_IO32WriteFldAlign(DBL_00, SV_OFF, DBL_ENABLE);			

            //Gamma Option3
            vOSTG_IO32WriteFldAlign(OSTG_01, SV_ON, REG_BYPASS_OP3);

            //Local Dimming
            vOSTG_IO32WriteFldAlign(LD2_MODE_00, SV_TRUE, C_LD_BYPASS);

            //Dither 1 & 2
            //vOSTG_IO32WriteFldAlign(OS_DITHER_00, 0, DITHER_LFSR_EN);
            //vOSTG_IO32WriteFldAlign(OS_DITHER_03, 0, REG_LFSR_EN_POST);



            //vOSTG_IO32WriteFldAlign(RGBOFFSET_00, 0, R_OFFSET_PIP);
            //vOSTG_IO32WriteFldAlign(RGBOFFSET_01, 0, G_OFFSET_PIP);
            //vOSTG_IO32WriteFldAlign(RGBOFFSET_02, 0, B_OFFSET_PIP);

            
            //vOSTG_IO32WriteFldAlign(RGBOFFSET_00, 0, R_OFFSET_MAIN);
            //vOSTG_IO32WriteFldAlign(RGBOFFSET_01, 0, G_OFFSET_MAIN);
            //vOSTG_IO32WriteFldAlign(RGBOFFSET_02, 0, B_OFFSET_MAIN);

            //OD
            vDrvODBypass(SV_ON);

            // POST
            if(!IsPQICExists())  //LPT model will use SCE.
            {
                vDrvSCEAllOnOff(SV_OFF);
                //Vertical CTI
                vDrvSCPQVCTIOnOff(SV_OFF);
            }
		}
#endif
}

void DRVCUST_HwInit(void)
{
#ifdef DRV_SUPPORT_CUST_ANR
    NR_FW_ANR_RegisterCustFunc(DRVCUST_AnrProc, _rCustNrWRegState);
#endif
    WB_EEP_Data_Init_To_Default();

	DRVCUST_4KBE_OSTG_Bypass();
		
    return;
}

void DRVCUST_SRSInit(void)
{     

    //SRS_Table_A = (UINT8*)x_mem_alloc(SRS_TBL_A_SIZE*SRS_TBL_A_NUM); 
    //SRS_Table_B = (UINT8*)x_mem_alloc(SRS_TBL_B_SIZE*SRS_TBL_B_NUM);	

	#if defined(CC_FBM_SUPPORT_SRS)
	FBM_POOL_T* prPool = FBM_GetPoolInfoAuto((UCHAR)FBM_POOL_TYPE_SRS, NULL); 
	
	SRS_Table_A = (UINT8*)VIRTUAL(prPool->u4Addr);
	SRS_Table_B = (UINT8*)VIRTUAL(prPool->u4Addr +  (SRS_TBL_A_SIZE*SRS_TBL_A_NUM));
	#endif
	
	if ((SRS_Table_A == NULL) || (SRS_Table_B == NULL))
    {
        LOG(0, "SRS Table memory alloc Failed \n");
		return;
    }

	x_memset(SRS_Table_A, 0, (SRS_TBL_A_SIZE*SRS_TBL_A_NUM));  
	x_memset(SRS_Table_B, 0, (SRS_TBL_B_SIZE*SRS_TBL_B_NUM)); 
	
}

void DRVCUST_MURA_CUCInit(void)
{	
	// from MVI , if not support no need to init(HW default is disable)
	if(IsSupportMura()|| IsSupportCuc())
	{	
		// set Demura clk. 
		vIO32WriteFldAlign(CKGEN_REG_SRE_OCLK_CKCFG, 0x2, FLD_QPQE_QCLK_SEL);
		vIO32WriteFldAlign(CKGEN_REG_SRE_OCLK_CKCFG, 0x2, FLD_QPQE_ZCLK_SEL);
		vIO32WriteFldAlign(CKGEN_REG_SRE_OCLK_CKCFG, 0x0, FLD_QPQE_VOCLK_SEL);

		//sw rest
		vOSTG_IO32WriteFldAlign(DEMURA_CTRL_0, SV_ON, C_QPQE_SW_RST);
		vOSTG_IO32WriteFldAlign(DEMURA_CTRL_0, SV_OFF, C_QPQE_SW_RST);

		//enable Demura
		vOSTG_IO32WriteFldAlign(DEMURA_CTRL_0, SV_ON, C_QPQE_CLK_EN);
		vOSTG_IO32WriteFldAlign(DEMURA_CTRL_0, SV_OFF, C_DEMURA_BYPASS);	

		//enable QPQE
		vOSTG_IO32WriteFldAlign(DEMURA_CTRL_0, SV_OFF, C_QPQE_DISABLE);
		printf("ZDO support Mura Cuc\n");
	}
	else
	{
		printf("ZDO not support Mura Cuc\n");
	}
}

void sonyDrv_RegisterCallback(void);

void DRVCUST_VideoInit(void)
{
#ifndef CC_MTK_LOADER
    INT32     i4Ret;
    HANDLE_T  hSRSCtrlThread;
#endif
    sonyDrv_RegisterCallback();
    DRVCUST_AdaptiveBacklightInit();
    DRVCUST_SRSInit();
	DRVCUST_SetOutputRGB2YUV();  // no need to use R2Y for 4KBE  model
	//DRVCUST_MURA_CUCInit();	
	DRVCUST_COL_CON_PARAM_INIT();
	DRVCUST_SetOSDIndexEnable(SV_ON);
	vIO32WriteFldAlign(VDP_SCPQ_01, SV_ON, SCPQ_CUST_UPCOEFF);
	vIO32WriteFldAlign(DRV_CUST_OO, SV_ON, DRV_CUST_UIMAPING);

	//sw register init
	vIO32WriteFldAlign(GLOBAL_ADJ_0A, 0x200, EXT3_ADJ_BRI);
	vIO32WriteFldAlign(GLOBAL_ADJ_0B, 0x200, EXT3_ADJ_BRI);

    _stMemcModeInfo.u1MemcPicMode = D_AP_PIC_MODE_IGNORE;
    _stMemcModeInfo.u1MemcSrc.eMainInputType = D_AP_INPUT_GRP_IGNORE;
    _stMemcModeInfo.u1MemcSrc.eSubInputType= D_AP_INPUT_GRP_IGNORE;

#ifndef CC_MTK_LOADER
    if(!bSRSCtrlSemaInit)
    {
        i4Ret = x_sema_create(&_hSRSCtrlSemaphore, X_SEMA_TYPE_BINARY, X_SEMA_STATE_LOCK);
        VERIFY(i4Ret == OSR_OK);
        if(i4Ret == OSR_OK)
        {
            bSRSCtrlSemaInit = TRUE;
        }
    }
    if(!bSRSCtrlLoopInit)
    {
        i4Ret = x_thread_create(&hSRSCtrlThread, "SRSCtrl_thread", MLVDO_STACK_SIZE, MLVDO_THREAD_PRIORITY,(x_os_thread_main_fct)_SRSCtrlLoop, 0, NULL);
        VERIFY(i4Ret == OSR_OK);
        if(i4Ret == OSR_OK)
        {
            bSRSCtrlLoopInit = TRUE;
        }
    }
#endif
}

void DRVCUST_HUPSCaleCoeff(UINT8 bPath)
{

}

void DRVCUST_VUPSCaleCoeff(UINT8 bPath)
{
    
}

void DRVCUST_VdoModeChgDone(UINT8 bPath)
{
    DRVCUST_4KBE_OSTG_Bypass();

    DRVCUST_SendEvent(E_CUST_SIGNAL_FMT_CHANGE, bPath);
    DRVCUST_SendEvent(E_CUST_VDO_DELAY_CHANGE, 0);

    if (sony_pq_func && sony_pq_func->pq_vdo_mode_chg_done_func)
    {
        sony_pq_func->pq_vdo_mode_chg_done_func();
    }

    DRVCUST_ReadRGBGainOfst();
    DRVCUST_SetHdmiCcirDither(bPath);
    
    bDrvBWSavingModeChk();
}

static UINT8 DRVCUST_GetSRSOnOff(void)
{
	static UINT8 u1Cnt = 0;
	UINT8 u1SRSOnOff = 0;

	//Following is for SRS bypass when 3D, and delay to enable when 2D stable.
	if(_fgAutoSearch || u1DrvTDTVCurIs3DMode() || (bDrvVideoSignalStatus(SV_VP_MAIN) != SV_VDO_STABLE))
	{
		 u1SRSOnOff = SV_OFF;
		 u1Cnt = 8;
	}
	else
	{
		if(u1Cnt != 0)
		{
			u1Cnt--;
		}
		else
		{
			u1SRSOnOff = SV_ON;
		}
	}
	return u1SRSOnOff;
}
static void DRVCUST_SRSCtrl(void)
{
	static UINT8 u1PreSRSOnOff = 0;
	UINT8 u1SRSOnOff = 0;

	u1SRSOnOff = DRVCUST_GetSRSOnOff();
	if(u1PreSRSOnOff != u1SRSOnOff)
	{
		u1PreSRSOnOff = u1SRSOnOff;
		DRVCUST_SharpnessEnhanceEn(u1PreSRSOnOff);
	}
}
static void DRVCUST_SendMuteEvent(void)
{
	static UINT8 u1PreMuteOnOff[VDP_NS] = {0xFF, 0xFF};
	UINT8 u1CurMuteOnOff[VDP_NS];
	UINT32 u4Path;
	for(u4Path = SV_VP_MAIN; u4Path <= SV_VP_PIP; u4Path++)
	{
		u1CurMuteOnOff[u4Path] = _u4DrvVideoGetMute(u4Path);
		if(u1CurMuteOnOff[u4Path] != u1PreMuteOnOff[u4Path])
		{
			u1PreMuteOnOff[u4Path] = u1CurMuteOnOff[u4Path];
			if(SV_ON == u1CurMuteOnOff[u4Path])
			{
			   LOG(2,"Send VIDEO mute event ----------------u4Path(%d)\n",u4Path);
		        DRVCUST_SendEvent(E_CUST_PLANE_MUTE_CHANGE, u4Path);
			}
		}
	}
}
static void DRVCUST_RecalOutput(void)
{
	static UINT32 u1PreTVInPIP_POP = 0;
	UINT8 u1CurTVInPIP_POP;
	//if(!IS_DISP_4K2K_TYPE3)
	{
		if((_eApplicationMode == SRM_TV_MODE_TYPE_PIP) || (_eApplicationMode == SRM_TV_MODE_TYPE_POP))
		{
		    u1CurTVInPIP_POP = 1;
		}
		else
		{
		    u1CurTVInPIP_POP = 0;
		}

        if(u1PreTVInPIP_POP != u1CurTVInPIP_POP)
        {
            LOG(1,"Recal output frame rate when PIP/pop change\n");
            if(bDrvVideoSignalStatus(SV_VP_MAIN) == SV_VDO_STABLE)
            {
                vDrvCalPanelFrameRate(wDrvVideoGetVTotal(SV_VP_MAIN), bDrvVideoGetRefreshRate(SV_VP_MAIN));
            }
            else
            {
                vDrvCalPanelFrameRate(wDrvGetOutputVTotal(), bOUTPUT_REFRESH_RATE);
            }
            u1PreTVInPIP_POP = u1CurTVInPIP_POP;
        }
	}
}

#if defined(CC_MAPLE_CUST_DRV) && defined(CC_MT5890) && defined(CC_SUPPORT_4KBE) 
EXTERN UINT8 _u1tvmode_scart;
EXTERN UINT32 GetPANEL4K2K_TYPE(void);
static void DRVCUST_BEConnectCtrl(void)
{
    static UINT32 u4PrePanelType = 0;
    static UINT32 u4PreTVMode = 0;
    static UINT32 u4PreScartOnOff = 0;
    static UCHAR u4PreVdpEnable = 0;
    UCHAR ucVdpEnable = 0;
    VDP_GetEnable(SV_VP_PIP,&ucVdpEnable);
    
    if((GetPANEL4K2K_TYPE()!= u4PrePanelType) || (u4PreTVMode != SRM_GetTvMode()) ||
        (_u1tvmode_scart != u4PreScartOnOff) || (u4PreVdpEnable != ucVdpEnable))
    {
        if(!ucVdpEnable ||  //Sub vdp is disabled
            (_u1tvmode_scart == 1) ||  // TV scart out on
            (GetPANEL4K2K_TYPE() != PANEL_TYPE_4K1K_60) ||  //Panel type is not 4k1k
            (SRM_GetTvMode() == SRM_TV_MODE_TYPE_NORMAL)   //TV mode is not pip/pop
            )
        {
            if(u1Connet[SV_VP_PIP])
            {
                LOG(1,"Disconnect BE sub\n");
                DRVCUST_BE_Disconnect(E_CUST_BE_TX_PATH_VIDEO, SV_VP_PIP);
            }
        }
        else
        {
            if(!u1Connet[SV_VP_PIP])
            {
                LOG(1,"Connect BE sub\n");
                DRVCUST_BE_Connect(E_CUST_BE_TX_PATH_VIDEO,E_CUST_BE_SCL_TYPE_VIDEO,E_CUST_BE_PLANE_ORDER_1,SV_VP_PIP);
                DRVCUST_SendEvent(E_CUST_SCALING_REQ_CHANGE, SV_VP_PIP);
                DRVCUST_SendEvent(E_CUST_SRC_AREA_CHANGE, SV_VP_PIP);
            }
        }

        u4PrePanelType = GetPANEL4K2K_TYPE();
        u4PreTVMode = SRM_GetTvMode();
        u4PreScartOnOff = _u1tvmode_scart;
        u4PreVdpEnable = ucVdpEnable;
    }

}
#endif

EXTERN UINT8 _u1tvmode_scart;
UINT8 u1MetaDataVerify = 0;
static void DRVCUST_BEMetaDataCtrl(void)
{
#if defined(CC_COMBINE_4K_2K)
    //TODO,  POP/PIP, force output 4K60 by Front scaler.
    UINT32 u4Val1;
    DRVCUST_OptQuery(eGet4KModelBEType,&u4Val1);

    if(u4Val1 || u1MetaDataVerify)	 //Only for BE model
    {
        UINT8 u1CurPnlType = GetPANEL4K2K_TYPE();
        UINT32 u4CurPlaneHeight = u4GetPlaneHeight(VDP_PQPATH);

        if(u1MetaDataVerify || ((PANEL_TYPE_4K2K_60 == u1CurPnlType) && (u4CurPlaneHeight == 1080) && (_u1tvmode_scart == 0)))
        {
            #define FIX_FRAME_NUM 1
            #define FIX_DRAM_LINE_PITCH 8  //1920
            #define FIX_OUT_W 1920
            #define FIX_OUT_H 1060
            #define FIX_FRAME_SIZE  1082   //2048*1082/2048
            #define FIX_OUT_X 0
            #define FIX_OUT_Y 1100

            UINT32 u4BaseAddr = 0;
            FBM_POOL_T *prPool = FBM_GetPoolInfo(FBM_POOL_TYPE_SCPOS_PIP);
            u4BaseAddr = (prPool->u4Addr>>11);

            vScpipSetResImportEnable(VDP_2, SV_OFF);
            vScpipSetMaskStart(VDP_2,FIX_OUT_X,FIX_OUT_Y);
            //Fix Back Dram mode
            vScpipSetFrontMode(VDP_2,SV_OFF);
            vScpipSetBackMode(VDP_2,SV_ON);
            //Fix Output Resolution & Position
            vScpipSetOutputResolution(VDP_2,FIX_OUT_W,FIX_OUT_H);
            //Fix Frame number to 1
            vScpipSetBufNum(VDP_2,FIX_FRAME_NUM);
            //Set Dram line pitch
            vScpipSetDramLinePitch(VDP_2, FIX_DRAM_LINE_PITCH);

            //Set Dram YUV Addr
            vScpipSetDramWidthHeight(VDP_2, FIX_OUT_W, FIX_OUT_H);
            vScpipSetDramHVPitch(VDP_2, FIX_OUT_W, FIX_OUT_H);
            vScpipSetDramSrcWidth(VDP_2, FIX_OUT_W);
            vScpipSetDramSrcHeight( VDP_2, FIX_OUT_H);

            SCPIP_WRITE_FLD(SCPIP_DRAM_M_04+getDramOffset(VDP_2), u4BaseAddr , DRAM_M_04_DA_ADDR_BASE_MSB_Y);
            SCPIP_WRITE_FLD(SCPIP_DRAM_M_05+getDramOffset(VDP_2), u4BaseAddr + FIX_FRAME_SIZE , DRAM_M_05_DA_ADDR_BASE_LSB_Y);
            SCPIP_WRITE_FLD(SCPIP_DRAM_M_06+getDramOffset(VDP_2), u4BaseAddr + FIX_FRAME_SIZE , DRAM_M_06_DA_ADDR_BASE_MSB_U);
            SCPIP_WRITE_FLD(SCPIP_DRAM_M_07+getDramOffset(VDP_2), u4BaseAddr + FIX_FRAME_SIZE*2 , DRAM_M_07_DA_ADDR_BASE_LSB_U);
            SCPIP_WRITE_FLD(SCPIP_DRAM_M_08+getDramOffset(VDP_2), u4BaseAddr + FIX_FRAME_SIZE , DRAM_M_08_DA_ADDR_BASE_MSB_V);
            SCPIP_WRITE_FLD(SCPIP_DRAM_M_09+getDramOffset(VDP_2), u4BaseAddr + FIX_FRAME_SIZE*2 , DRAM_M_09_DA_ADDR_BASE_LSB_V);
            SCPIP_WRITE_FLD(SCPIP_DRAM_M_0A+getDramOffset(VDP_2), u4BaseAddr + FIX_FRAME_SIZE*2 , DRAM_M_0A_DA_WADDR_HI_LIMIT);
            SCPIP_WRITE_FLD(SCPIP_DRAM_M_0B+getDramOffset(VDP_2), u4BaseAddr, DRAM_M_0B_DA_WADDR_LO_LIMIT);

            //Force Write OFF,Read ON
            vScpipSetDramWrite(VDP_2,SV_OFF);
            vScpipSetDramRead(VDP_2,SV_ON);
            //Turn off new address mode
            vScpipSetDramNewAddrMode(VDP_2,SV_OFF);

            if(_u4DrvVideoGetMute(VDP_1) || u4DrvVideoOutputMute())
            {
                vDrvSetForceUmute(VDP_2, SV_FORCE_UNMUTE_TYPE_ALL, SV_OFF);
            }
            else
            {
                vDrvSetForceUmute(VDP_2, SV_FORCE_UNMUTE_TYPE_ALL, SV_ON);
            }

            // sub works with new addr off mode.
            SCPIP_WRITE_FLD(SCPIP_DRAM_P_29, 0xFF, DRAM_P_29_DA_RD_ULTRA_ASSERT_THR);
            SCPIP_WRITE_FLD(SCPIP_DRAM_P_29, 0xFF, DRAM_P_29_DA_RD_ULTRA_RELEASE_THR);
            SCPIP_WRITE_FLD(SCPIP_DRAM_P_29, 0xFF, DRAM_P_29_DA_RD_PREULTRA_ASSERT_THR);
            SCPIP_WRITE_FLD(SCPIP_DRAM_P_29, 0xFF, DRAM_P_29_DA_RD_PREULTRA_RELEASE_THR);

            if(!bIsMetaData)
            {
                bIsMetaData = SV_TRUE;
            }
        }
        else
        {
            if(bIsMetaData)
            {	
                vScpipSetMaskStart(VDP_2,0xFFFF,0);
                vDrvSetForceUmute(VDP_2, SV_FORCE_UNMUTE_TYPE_ALL, SV_OFF);
                vScpipSetOutputResolution(VDP_2,0,0);

                vScpipSetDramUltra(SV_VP_PIP);

                bIsMetaData = SV_FALSE;
            }
        }
    }

#endif
}

#ifdef CC_MIN_LOW_LATENCY_SUPPORT
extern BOOL bDrvIsMinLowLatencyDlySupport(UINT8 bPath);
extern void vDrvDISetFrcLineExt(UINT8 u1VdpId,UINT16 u2Cnt);
BOOL bIsMinLowLatencyMode = FALSE;

static void DRVCUST_FrameDlyContrlProc(void)
{
    if(IO32ReadFldAlign(FRAME_DELAY_CONTROL,FRAME_DELAY_CONTROL_DIS) == 0)
    {
        //Following is customer spec

        // 1. Signal stabel  
        // 2. HDMI input
        // 3. Game/Graphic mode 
        if((bDrvVideoSignalStatus(SV_VP_MAIN) != SV_VDO_STABLE) ||
            (bGetSignalType(SV_VP_MAIN) != SV_ST_DVI) ||
            (vGetVDPColorMode(SV_VP_MAIN) != SV_COLOR_MODE_444))
        {
            bIsMinLowLatencyMode = FALSE;
            return;
        }


        // 4. FRC line and Frame track line setting
        //Husky MIB display mode only
        if(bDrvIsMinLowLatencyDlySupport(SV_VP_MAIN))
        {
            UINT16 u2TargetLine;
            UINT16  u2Tolerance = 40;
            UINT16  NewVFp;
            UINT8 u1Mode = 0;
            E_TG_MODULE eCurTgModule;

            u1Mode = getScalerMode(VDP_1);

            if(fgFrameTrackIsFlgSet(FRAME_TRACK_MODE_DDDS_BY_REF))
            {
                eCurTgModule = E_REF_TG;
            }
            else
            {
                eCurTgModule = E_FSC_TG;
            }

            NewVFp = u4ScpipGetVsyncFp(eCurTgModule);

            if(u4ScpipGetVTModeCtrl(eCurTgModule))
            {
                NewVFp = u4ScpipGetPanelVtotal(eCurTgModule)-u4ScpipGetPanelHeight(eCurTgModule)-u4ScpipGetVsyncFp(eCurTgModule)-u4ScpipGetVsyncBp(eCurTgModule);
            }

            if(bDrvVideoIsSrcInterlace(SV_VP_MAIN))
            {
                u2Tolerance = 200;

                if((eCurTgModule == E_FSC_TG) && GetPANEL4K2K_TYPE() == PANEL_TYPE_4K2K_60_SRS)
                {
                    u2Tolerance /= 2;
                }
            }
            else if(VDP_SCPOS_DISPMODE_OFF == u1Mode)
            {
                u2Tolerance = 0;
            }

            u2TargetLine = u4ScpipGetPanelVtotal(eCurTgModule) - NewVFp - u2Tolerance;

            //FRC line
            if(u4GetFlipMirrorModule(SV_VP_MAIN) != FLIP_BY_PSCAN)
            {
                vDrvDISetFrcLineExt(SV_VP_MAIN,0);
            }
            else if(u4GetFlipMirrorModule(SV_VP_MAIN) != FLIP_BY_SCALER)
            {
                vScpipSetReadPosGen(SV_VP_MAIN,2);
            }

            if((eCurTgModule == E_REF_TG))
            {
                vScpipRefSetFrmTrkLines(u2TargetLine);
            }
            else
            {
                //Frame track line
                vScpipSetFrmTrkLines(u2TargetLine);
            }

            bIsMinLowLatencyMode = TRUE;
        }
        else
        {
            bIsMinLowLatencyMode = FALSE;
        }

    }
}
#endif
extern UINT8 u1NeedSendEventToSony ;

void DRVCUST_VideoMainloop()
{
	static UINT8 bOSD_En, bPreOSD_En;
	static UINT8 u1PreIs3DFmt = 0;
	static UINT8 u1PreMuteSta = 0;
	UINT32 u4BeType;
	UINT8 fgIsOSD3En;
	
	VDP_SEAMLESS_INFO_T tb2rVrmInfo;
	static VDP_SEAMLESS_INFO_T tPreb2rVrmInfo;
	DRVCUST_AdaptiveBacklightProc();
	vScpipSetSuperGameMode(SV_VP_MAIN, DRVCUST_SuperGameMode(SV_VP_MAIN));

	if (sony_pq_func && sony_pq_func->pq_video_main_loop_func)
	{
		sony_pq_func->pq_video_main_loop_func();
	}
	#ifdef CC_PowerCons_Ctrl
	DRVCUST_PowerConsCtrlStatusCheck();
	#endif
	//CustomReadTemperature();

	bOSD_En = OSD_BASE_IsDisplaying();

	if(bOSD_En != bPreOSD_En)
	{
		bPreOSD_En = bOSD_En;
		DRVCUST_SendEvent(E_CUST_OSD_STATE_CHANGE, 0);
	}
	DRVCUST_PanelGammaRemapProc();
	
	DRVCUST_SRSCtrl();
	DRVCUST_BEMetaDataCtrl();
    DRVCUST_RecalOutput();
	#if defined(CC_MAPLE_CUST_DRV) && defined(CC_MT5890) && defined(CC_SUPPORT_4KBE) 
	DRVCUST_BEConnectCtrl();
    #endif
	DRVCUST_SendMuteEvent();
    if(VDP_SET_ERROR != VDP_GetSeamlessInfo(VDP_1, &tb2rVrmInfo))
    {
        if((tPreb2rVrmInfo.u4SrcWidth  != tb2rVrmInfo.u4SrcWidth)
			||(tPreb2rVrmInfo.u4SrcHeight  != tb2rVrmInfo.u4SrcHeight)
			||(bIsSeamless == SV_FALSE))           
        { 
			if(!fgGetPEUIResetFlg(SV_VP_MAIN)&&(bIsSeamless==SV_FALSE))
			{
				tPreb2rVrmInfo = tb2rVrmInfo;
				DRVCUST_PqModeChange(VDP_1);
				bIsSeamless = SV_TRUE;
			}
        }            
    }
	else
	{
		bIsSeamless = SV_FALSE;
    }

	
	
	UNUSED(DRVCUST_InitQuery(eGet4KModelBEType, &u4BeType));

	UNUSED(OSD_PLA_GetEnable(OSD_PLANE_3, &fgIsOSD3En));

	if((DRVCUST_VideoGetHDRType()!= PreHDRType) || (fgIsOSD3En != fgIsPreOSD3En))
	{
		PreHDRType = DRVCUST_VideoGetHDRType();
		fgIsPreOSD3En = fgIsOSD3En;
		if((u4BeType == 0)||(IsPQICExists()))
		{
			// only without BE model need change OSD setting when HDR video
			DRVCUST_SetOSDHDRMatrixCoeff(); 	
			bApiVideoProc(VDP_1, PE_ARG_BLUE_STRETCH);  // force to update bluestretch for HDR need to disable it.
		}
		
		DRVCUST_SendEvent(E_CUST_SIGNAL_FMT_CHANGE, SV_VP_MAIN);
	}
	if(IS_DISP_4K2K_TYPE3 || ((PANEL_GetControlWord() & DISP_TYPE_MASK) == 0))
	{
		if(u1NeedSendEventToSony)
		{
			u1NeedSendEventToSony = 0;
			DRVCUST_SendEvent(E_CUST_OUT_SCALING_CHANGE, SV_VP_MAIN);
		}
			
	}
    #ifdef CC_MIN_LOW_LATENCY_SUPPORT
    DRVCUST_FrameDlyContrlProc();
    #endif
    
	
}

void DRVCUST_OutVSyncISR()
{

//	static UINT8 PreHDRType = 0;
/*
    vDrvLcdimProc();
    if( IO32ReadFldAlign(ADAP_LCDIM_SPI, SPI_AUTO_VSYNC_EN)== SV_TRUE)
    {
        vDrvLcdimSpiCommandGen(E_SPI_PAGE_WRITE, 0);
    }
    */
    if (sony_pq_func && sony_pq_func->pq_out_vsync_isr_func)
    {
        sony_pq_func->pq_out_vsync_isr_func();
    }
    
    DRVCUST_Gamma_ISR();

}

void DRVCUST_PostOutVSyncISR()
{  
	if(fgCriticalSection)
	{
		fgCriticalSection = SV_FALSE;
	}
	// for no-double buffer hardware register and software register
	if (u4BufFlag&E_CUST_PQ_BUF_FLUSH)
	{		 
	
		if (u4BufFlag&E_CUST_PQ_BUF_PARTIALY)	   
		{			 
			x_memcpy((DEFAULT_SCE_TBL + ENUM_Y_SLOPE*SCE_HUE_SLICE), u1SceYSlope, SCE_LUMA_HUE_SLICE);	
			LOG(4, "E_CUST_PQ_BUF_PARTIALY \n");
		}
		
		if (u4BufFlag&E_CUST_PQ_BUF_PARTIALS)	   
		{			 
			x_memcpy((DEFAULT_SCE_TBL + ENUM_S_GAIN1*SCE_HUE_SLICE), u1SceSGain1, SCE_HUE_SLICE);
			x_memcpy((DEFAULT_SCE_TBL + ENUM_S_GAIN2*SCE_HUE_SLICE), u1SceSGain2, SCE_HUE_SLICE);
			x_memcpy((DEFAULT_SCE_TBL + ENUM_S_GAIN3*SCE_HUE_SLICE), u1SceSGain3, SCE_HUE_SLICE);
			LOG(4, "E_CUST_PQ_BUF_PARTIALS \n");
		}
		if (u4BufFlag&E_CUST_PQ_BUF_PARTIALS_P)	   
		{			 
			x_memcpy((DEFAULT_SCE_TBL + ENUM_S_P1*SCE_HUE_SLICE), u1SceSGainP1, SCE_HUE_SLICE);
			x_memcpy((DEFAULT_SCE_TBL + ENUM_S_P2*SCE_HUE_SLICE), u1SceSGainP2, SCE_HUE_SLICE);
			LOG(4, "E_CUST_PQ_BUF_PARTIALS_P \n");
		}
		if (u4BufFlag&E_CUST_PQ_BUF_COMTRAST)		
		{	
			vDrvSetSCEContrast(u2ContrastBuf); 
		}
		
		if (u4BufFlag&E_CUST_PQ_BUF_COLOR)			
		{		  
			vDrvSetSCESaturation(u2ColorBuf);  
		}
		
		if (u4BufFlag&E_CUST_PQ_BUF_HUE)			
		{		
			vDrvSetSCEHue((u2HueBuf <<2));
		}
		
		if (u4BufFlag&E_CUST_PQ_BUF_MATRIX) 		   
		{
			vDrvSetExtContrast(SV_VP_MAIN, u2MatrixContrastBuf); 
			vDrvSetExtSaturation(SV_VP_MAIN, u2MatrixColorBuf);
			vDrvSetExtBrightness(SV_VP_MAIN, u2MatrixBrightnessBuf);
		}
		
		if (u4BufFlag&E_CUST_PQ_BUF_SHARPNESS)		
		{			
			vDrvPostSharpGainHOffset(stSharpOfst.u1GainH[0], stSharpOfst.u1GainH[1], stSharpOfst.u1GainH[2]);
			vDrvPostSharpGainVOffset(stSharpOfst.u1GainV[0], stSharpOfst.u1GainV[1], stSharpOfst.u1GainV[2]);
			vDrvPostSharpGainDOffset(stSharpOfst.u1GainD[0], stSharpOfst.u1GainD[1], stSharpOfst.u1GainD[2]);
			vDrvPostSharpCorzHOffset(stSharpOfst.u1CorzH[0], stSharpOfst.u1CorzH[1], stSharpOfst.u1CorzH[2]);
			vDrvPostSharpCorzVOffset(stSharpOfst.u1CorzV[0], stSharpOfst.u1CorzV[1], stSharpOfst.u1CorzV[2]);
			vDrvPostSharpCorzDOffset(stSharpOfst.u1CorzD[0], stSharpOfst.u1CorzD[1], stSharpOfst.u1CorzD[2]);			
			vDrvHSharpGainOffset(stSharpOfst.u1HSHPGainLow[0], stSharpOfst.u1HSHPGainLow[1], stSharpOfst.u1HSHPGainMid[0], stSharpOfst.u1HSHPGainMid[1], stSharpOfst.u1HSHPGainHigh[0], stSharpOfst.u1HSHPGainHigh[1]);
			vDrvHSharpCorzOffset(stSharpOfst.u1HSHPCor[0], stSharpOfst.u1HSHPCor[1], stSharpOfst.u1HSHPCor[2]);
			vDrvPostSharpEDF1ThOffset(stSharpOfst.u1Edf1Th);
			vDrvPostSharpEdgeGainOffset(stSharpOfst.u1EdgeGain[0], stSharpOfst.u1EdgeGain[1], stSharpOfst.u1EdgeGain[2]);
			vDrvPostSharpDetailGainOffset(stSharpOfst.u1DetailGain[0], stSharpOfst.u1DetailGain[1], stSharpOfst.u1DetailGain[2]);
			vDrvPostSharpEDF2ThOffset(stSharpOfst.u1Edf2Th);
			vDrvPostSharpEDF2FGainOffset(stSharpOfst.u1Edf2FGain);
			vDrvPostSharpEDF2DGainOffset(stSharpOfst.u1Edf2DGain);
			vDrvPostSharpEDF2EGainOffset(stSharpOfst.u1Edf2EGain);
			vDrvPostSharpLTIGainOffset(stSharpOfst.u1LTIGain[0], stSharpOfst.u1LTIGain[1], stSharpOfst.u1LTIGain[2]);
			vDrvPostSharpLTICorzOffset(stSharpOfst.u1LTICorz[0], stSharpOfst.u1LTICorz[1], stSharpOfst.u1LTICorz[2]);
			vDrvPostSharpTapAdaptOffset(stSharpOfst.u1TapAdap[0], stSharpOfst.u1TapAdap[1], stSharpOfst.u1TapAdap[2],stSharpOfst.u1TapAdap[3]);
			vDrvPostSharpIbseOffset(stSharpOfst.u1Ibse[0], stSharpOfst.u1Ibse[1]);

			vDrvPostSharpParam_Cust();
			vDrvSCPQIbseParam_Cust();
		}
		
		if (u4BufFlag&E_CUST_PQ_BUF_SCE)	  
		{			 
			LOG(4, "E_CUST_PQ_BUF_SCE \n");
			vApiRegisterVideoEvent(PE_EVENT_SCE, VDP_1, SV_ON);
		}
		
		if (u4BufFlag&E_CUST_PQ_BUF_LUMA_CURVE) 	
		{
			vDrvADLSetLumaCurve65(u2LumaArrayBuf);
			vDrvADLSetLumaSecCurve65(u2SkinArrayBuf);
			vApiRegisterVideoEvent(PE_EVENT_LUMA_CURVE, VDP_1, SV_ON);
			vApiRegisterVideoEvent(PE_EVENT_LUMA_SEC_CURVE, VDP_1, SV_ON);
		}

		if (u4BufFlag&E_CUST_PQ_BUF_RGB_GAIN_OFST)		
		{			 
			vDrvSetRGain1(SV_VP_MAIN, stRGBGainOfst.u2RGain);
			vDrvSetGGain1(SV_VP_MAIN, stRGBGainOfst.u2GGain);
			vDrvSetBGain1(SV_VP_MAIN, stRGBGainOfst.u2BGain);
			vDrvSetROffset11(SV_VP_MAIN, stRGBGainOfst.u2ROffset);
			vDrvSetGOffset11(SV_VP_MAIN, stRGBGainOfst.u2GOffset);
			vDrvSetBOffset11(SV_VP_MAIN, stRGBGainOfst.u2BOffset);			  
		}

		if (u4BufFlag&E_CUST_PQ_BUF_YLEV)	   
		{		  
			vDrvSetYLevTable(u1YLevArrayBuf);
		}
		if (u4BufFlag&E_CUST_PQ_BUF_IBSE_YLEV)	   
		{		  
			vDrvSetIbseYLevTable(u1YLevIBSEArrayBuf);
		}

		if(u4BufFlag&E_CUST_PQ_BUF_4BAND_FREQ_RANGE)
		{
			DRVCUST_Set4BandFilterRangHw(&CUST_4BAND_HIST_FILTER_RANGE);
		}
		
		if(u4BufFlag&E_CUST_PQ_BUF_4BAND_FREQ_FILTER)
		{
			DRVCUST_Set4BandHFilterHw(&CUST_4BAND_HIST_FILTER);
		}	
		
		u4BufFlag = 0;
	}

	if (sony_pq_func && sony_pq_func->pq_post_out_vsync_isr_func)
	{
		sony_pq_func->pq_post_out_vsync_isr_func();
	}
}

void DRVCUST_GetYLevTable(UINT8* pYLev)
{
    if(NULL != pYLev)
    {
        pYLev[0] = IO32ReadFldAlign(SHARP_47, TDS_YLEV_P000);  
    	pYLev[1] = IO32ReadFldAlign(SHARP_47, TDS_YLEV_P064);  
    	pYLev[2] = IO32ReadFldAlign(SHARP_47, TDS_YLEV_P128);  
    	pYLev[3] = IO32ReadFldAlign(SHARP_47, TDS_YLEV_P192);
    	pYLev[4] = IO32ReadFldAlign(SHARP_48, TDS_YLEV_P256); 
    	pYLev[5] = IO32ReadFldAlign(SHARP_48, TDS_YLEV_P320);  
    	pYLev[6] = IO32ReadFldAlign(SHARP_48, TDS_YLEV_P384);  
    	pYLev[7] = IO32ReadFldAlign(SHARP_48, TDS_YLEV_P448);			
    	pYLev[8] = IO32ReadFldAlign(SHARP_49, TDS_YLEV_P512);  
    	pYLev[9] = IO32ReadFldAlign(SHARP_49, TDS_YLEV_P576);  
    	pYLev[10] = IO32ReadFldAlign(SHARP_49, TDS_YLEV_P640); 
    	pYLev[11] = IO32ReadFldAlign(SHARP_49, TDS_YLEV_P704); 
    	pYLev[12] = IO32ReadFldAlign(SHARP_4A, TDS_YLEV_P768); 
    	pYLev[13] = IO32ReadFldAlign(SHARP_4A, TDS_YLEV_P832); 
    	pYLev[14] = IO32ReadFldAlign(SHARP_4A, TDS_YLEV_P896); 
    	pYLev[15] = IO32ReadFldAlign(SHARP_4A, TDS_YLEV_P960); 
    	pYLev[16] = IO32ReadFldAlign(SHARP_4B, TDS_YLEV_P1024);  
	}
}
void DRVCUST_GetIbseYLevTable(UINT8* pYLev)
{
    if(NULL != pYLev)
    {
        pYLev[0] = IO32ReadFldAlign(SCFIR_14, SC_IBSE_YLEVEL_P0);  
    	pYLev[1] = IO32ReadFldAlign(SCFIR_14, SC_IBSE_YLEVEL_P16);  
    	pYLev[2] = IO32ReadFldAlign(SCFIR_14, SC_IBSE_YLEVEL_P32);  
    	pYLev[3] = IO32ReadFldAlign(SCFIR_14, SC_IBSE_YLEVEL_P48);
    	pYLev[4] = IO32ReadFldAlign(SCFIR_15, SC_IBSE_YLEVEL_P64); 
    	pYLev[5] = IO32ReadFldAlign(SCFIR_15, SC_IBSE_YLEVEL_P80);  
    	pYLev[6] = IO32ReadFldAlign(SCFIR_15, SC_IBSE_YLEVEL_P96);  
    	pYLev[7] = IO32ReadFldAlign(SCFIR_15, SC_IBSE_YLEVEL_P112);			
    	pYLev[8] = IO32ReadFldAlign(SCFIR_16, SC_IBSE_YLEVEL_P128);  
    	pYLev[9] = IO32ReadFldAlign(SCFIR_16, SC_IBSE_YLEVEL_P144);  
    	pYLev[10] = IO32ReadFldAlign(SCFIR_16, SC_IBSE_YLEVEL_P160); 
    	pYLev[11] = IO32ReadFldAlign(SCFIR_16, SC_IBSE_YLEVEL_P176); 
    	pYLev[12] = IO32ReadFldAlign(SCFIR_17, SC_IBSE_YLEVEL_P192); 
    	pYLev[13] = IO32ReadFldAlign(SCFIR_17, SC_IBSE_YLEVEL_P208); 
    	pYLev[14] = IO32ReadFldAlign(SCFIR_17, SC_IBSE_YLEVEL_P224); 
    	pYLev[15] = IO32ReadFldAlign(SCFIR_17, SC_IBSE_YLEVEL_P240); 
    	pYLev[16] = IO32ReadFldAlign(SCFIR_18, SC_IBSE_YLEVEL_P256);  
	}
}


UINT16 DRVCUST_GetContrast(void)
{
    return IO32ReadFldAlign(G_PIC_ADJ_MAIN_1, CONTRAST);
}

UINT16 DRVCUST_GetBrightness(void)
{
    return IO32ReadFldAlign(G_PIC_ADJ_MAIN_1, BRIGHTNESS);
}

UINT16 DRVCUST_GetColor(void)
{
    return IO32ReadFldAlign(G_PIC_ADJ_MAIN_2, SAT);
}

UINT16 DRVCUST_GetHue(void)
{
    return IO32ReadFldAlign(G_PIC_ADJ_MAIN_2, HUE);
}

UINT8 DRVCUST_GetBLHeaderFooter(UINT32 *u4CmdHeader, UINT32 *u4CmdFooter)
{
    if(NULL != u4CmdHeader && NULL != u4CmdFooter)
    {
        *u4CmdHeader = (IO32ReadFldAlign(LED_NHEAD, NHEAD_0) | (IO32ReadFldAlign(LED_NHEAD, NHEAD_1)<<16));  
        *u4CmdFooter = (IO32ReadFldAlign(LED_NFOOT, NFOOT_0) | (IO32ReadFldAlign(LED_NFOOT, NFOOT_1)<<16)); 
    }
    
    return 0;
}

void DRVCUST_GetADLLumaCurveHw(UINT16 * waLArray)
{
	UINT8 bi;

	ASSERT(waLArray!=NULL);

    for(bi = 0; bi < 16; bi++)
    {
    	waLArray[2*bi] = u4IO32Read4B(Y_FTN_1_0_MAIN + 4 * bi)&0xFF;
    	waLArray[2*bi + 1] = (u4IO32Read4B(Y_FTN_1_0_MAIN + 4 * bi)>>16)&0xFF;
	}
	waLArray[32] = u4IO32Read4B(Y_FTN_32_33_MAIN)&0xFF;
}

void DRVCUST_GetADLLumaCurve65Hw(UINT16 * waLArray)
{
	UINT8 bi;

	ASSERT(waLArray!=NULL);

	for(bi = 0; bi < 32; bi++)
    {
    	waLArray[2*bi] = u4IO32Read4B(Y_FTN_1_0_MAIN + 4 * bi)&0xFF;
    	waLArray[2*bi + 1] = (u4IO32Read4B(Y_FTN_1_0_MAIN + 4 * bi)>>16)&0xFF;
	}
	waLArray[64] = u4IO32Read4B(Y_FTN_64_MAIN)&0xFF;
}

void DRVCUST_GetADLSecondLumaCurveHw(UINT16 * waSLArray)
{
	UINT8 bi;

	ASSERT(waSLArray!=NULL);

	for(bi = 0; bi < 16; bi++)
    {
    	waSLArray[2*bi] = u4IO32Read4B(Y_FTN2_1_0_MAIN + 4 * bi)&0xFF;
    	waSLArray[2*bi + 1] = (u4IO32Read4B(Y_FTN2_1_0_MAIN + 4 * bi)>>16)&0xFF;
	}
	waSLArray[32] = u4IO32Read4B(Y_FTN2_33_32_MAIN)&0xFF;
}

void DRVCUST_GetADLSecondLumaCurve65Hw(UINT16 * waSLArray)
{
	UINT8 bi;

	ASSERT(waSLArray!=NULL);

	for(bi = 0; bi < 32; bi++)
    {
    	waSLArray[2*bi] = u4IO32Read4B(Y_FTN2_1_0_MAIN + 4 * bi)&0xFF;
    	waSLArray[2*bi + 1] = (u4IO32Read4B(Y_FTN2_1_0_MAIN + 4 * bi)>>16)&0xFF;
	}
	waSLArray[64] = u4IO32Read4B(Y_FTN2_64_MAIN)&0xFF;
}

void DRVCUST_GetLumaCurve(UINT16* waLArray, UINT16* waSkinLArray)
{
    UINT8 u1CurveMode = vDrvADLGetLumaCurveMode();

	if(u1CurveMode == 1)
	{
        DRVCUST_GetADLLumaCurveHw(waLArray);
        DRVCUST_GetADLSecondLumaCurveHw(waSkinLArray);
    }
	else
	{
		DRVCUST_GetADLLumaCurve65Hw(waLArray);
        DRVCUST_GetADLSecondLumaCurve65Hw(waSkinLArray);
	}
}

UINT8 DRVCUST_CheckSetExclusiveReg(UINT8 u1Enable)
{
    if(u1Enable)
    {
        if((2 == IO32ReadFldAlign(SCE_CFG_MAIN, COLOR_YHIST_TYPE))
        && (0 == IO32ReadFldAlign(SCE_CFG_MAIN, YCURVE_33_EN))
        && (1 == bManualLumaCurve)
        && (0 == IO32ReadFldAlign(ADAPTIVE_REG, ADAPTIVE_LUMA)))
        {
            return SV_TRUE;
        }
        else
        {
            return SV_FALSE;
        }
    }
    else
    {
        if((0 == IO32ReadFldAlign(SCE_CFG_MAIN, COLOR_YHIST_TYPE))
        && (1 == IO32ReadFldAlign(SCE_CFG_MAIN, YCURVE_33_EN))
        && (0 == bManualLumaCurve)
        && (1 == IO32ReadFldAlign(ADAPTIVE_REG, ADAPTIVE_LUMA)))
        {
            return SV_TRUE;
        }
        else
        {
            return SV_FALSE;
        }
    }
}
void DRVCUST_GetLdHwParam(CUST_LD_HW_PARAM_T* pLDHWParam)
{     
	//vDrvLcDimGetHWParam(pLDHWParam);
}

void DRVCUST_GetLdSwParam(CUST_LD_SW_PARAM_T* pLDSWParam)
{     
	//vDrvLcDimGetSWParam(pLDSWParam);
}

void DRVCUST_GetLdSwTable(UINT16 *u2LDGainLimitTable_LOW_BND, UINT16 *u2LDGainLimitTable_UP_BND)
{     
	//vDrvLcDimGetSWTable(u2LDGainLimitTable_LOW_BND, u2LDGainLimitTable_UP_BND);
}

void DRVCUST_PostDEEndISR(void)
{   
	if (!fgIsMJCToOSTG()) //PSC off
	{
		if(!fgCriticalSection)
		{
			fgCriticalSection = SV_TRUE;
		}
	}
	// for double buffer hardware register 
    if (u4BufFlag&E_CUST_PQ_BUF_FLUSH)
    {
    //move to postoutput ISR, avoiding Flag cleared before set data.
     /*   if (u4BufFlag&E_CUST_PQ_BUF_LUMA_CURVE)     
        {
            vDrvADLSetLumaCurve65(u2LumaArrayBuf);
			vDrvADLSetLumaSecCurve65(u2SkinArrayBuf);
			vApiRegisterVideoEvent(PE_EVENT_LUMA_CURVE, VDP_1, SV_ON);
			vApiRegisterVideoEvent(PE_EVENT_LUMA_SEC_CURVE, VDP_1, SV_ON);
        }*/

        if (u4BufFlag&E_CUST_PQ_BUF_SRS)
        {
            vDrvSetSRS(PhyAddrBuf_A, PhyAddrBuf_B);
        }
    }

    if (sony_pq_func && sony_pq_func->pq_post_de_end_isr_func)
    {
        sony_pq_func->pq_post_de_end_isr_func();
    }
}

void DRVCUST_VdoInISR()
{
    if (sony_pq_func && sony_pq_func->pq_vdo_in_isr_func)
    {
        sony_pq_func->pq_vdo_in_isr_func();
    }

    DRVCUST_Get4BandFreqHistHw(&CUST_4BAND_HIST_VALUE);
}
void DRVCUST_PSCDeFallingISR(void)
{
    if (fgIsMJCToOSTG()) //PSC on
    {
       if(!fgCriticalSection)
		{
			fgCriticalSection = SV_TRUE;
		}
    }

}

E_CUST_RESULT BeAllocateResource(UINT8 u1TxPath, E_CUST_BE_SCL_TYPE eBeSclType, CUST_BE_SCL_CONFIG_T* pSclConfig, UINT8* u1BeHandle)
{
	if (sony_be_func && sony_be_func->be_allocate_resource)
    {
        return sony_be_func->be_allocate_resource(u1TxPath, eBeSclType, pSclConfig, u1BeHandle);
    }
	
	return E_CUST_RESULT_ERROR_NOT_READY;
}

E_CUST_RESULT BeFreeResource(UINT8 u1BeHandle)
{
	if (sony_be_func && sony_be_func->be_free_resource)
    {
        return sony_be_func->be_free_resource(u1BeHandle);
    }
	return E_CUST_RESULT_ERROR_NOT_READY;
}

E_CUST_RESULT BeAssociatePath(UINT8 u1BeHandle, UINT8 bPath)
{
	if (sony_be_func && sony_be_func->be_associate_path)
    {
        return sony_be_func->be_associate_path(u1BeHandle, bPath);
    }
	return E_CUST_RESULT_ERROR_NOT_READY;
}

E_CUST_RESULT BeDissociatePath(UINT8 u1BeHandle, UINT8 bPath)
{
	if (sony_be_func && sony_be_func->be_dissociate_path)
    {
        return sony_be_func->be_dissociate_path(u1BeHandle, bPath);
    }
	return E_CUST_RESULT_ERROR_NOT_READY;
}

void PqAssociatePath(UINT8 bPqPath, UINT8 bPath)
{
    if (sony_pq_func && sony_pq_func->pq_associate_path)
    {
        sony_pq_func->pq_associate_path(bPqPath, bPath);
    }
}

void PqDissociatePath(UINT8 bPath)
{
    if (sony_pq_func && sony_pq_func->pq_dissociate_path)
    {
        sony_pq_func->pq_dissociate_path(bPath);
    }
}

UINT8 DRVCUST_GetPathByBeHandle(UINT8 u4BeHandle)
{
    UINT32 u4Index;

    for (u4Index = 0; u4Index < sizeof(u1BePath); u4Index++)
    {
        if (u1BePath[u4Index] == u4BeHandle)
        {
            break;
        }
    }

    return u4Index;
}

UINT8 DRVCUST_BE_Connect(UINT8 u1TxPath, UINT8 u1BeSclType , UINT8 u1PlaneOrder, UINT8 bPath)
{
	UINT8 u1BeHandle = 0;
	CUST_BE_SCL_CONFIG_T pSclConfig;
	//VRM_INFO_T* prVrmInfo;


    //prVrmInfo = VRMGetVRMInfo(bPath, VRM_MODULE_MIXER);
    
	pSclConfig.u1PlaneOrder 	= u1PlaneOrder;
	//pSclConfig.u4SrcX 			= vrmInfo->u2X;
	//pSclConfig.u4SrcY 			= vrmInfo->u2Y;
	//pSclConfig.u4SrcWidth 		= vrmInfo->u2Width;
	//pSclConfig.u4SrcHeight		= vrmInfo->u2Height;
	//pSclConfig.u4DestX			= vrmInfo->u2X;
	//pSclConfig.u4DestY 		= vrmInfo->u2Y;
	//pSclConfig.u4DestWidth 	= vrmInfo->u2Width;
	//pSclConfig.u4DestHeight	= vrmInfo->u2Height;
	
	//temporal solution
	pSclConfig.u4SrcX 			= 0;//prVrmInfo->u2X;
	pSclConfig.u4SrcY 			= 0;//prVrmInfo->u2Y;
        //Fix SRK BE issue WA
	pSclConfig.u4SrcWidth 		= 3840;//prVrmInfo->u2Width;
	pSclConfig.u4SrcHeight		= 2160;//prVrmInfo->u2Height;
	pSclConfig.u4DestX			= 0;
	pSclConfig.u4DestY 		= 0;
	pSclConfig.u4DestWidth 	= 3840;
	pSclConfig.u4DestHeight	= 2160;
	if(bPath == SV_VP_PIP)
	{
	    pSclConfig.u4SrcX 			= 1920;//prVrmInfo->u2X;
		pSclConfig.u4SrcY 			= 0;//prVrmInfo->u2Y;
		pSclConfig.u4SrcWidth 		= 1920;//prVrmInfo->u2Width;
		pSclConfig.u4SrcHeight		= 1080;//prVrmInfo->u2Height;
		pSclConfig.u4DestX			= 1920;
		pSclConfig.u4DestY 		= 0;
		pSclConfig.u4DestWidth 	= 1920;
		pSclConfig.u4DestHeight	= 2160;
	}

	
	if(u1TxPath == E_CUST_BE_TX_PATH_GFX)
	{
	    u1Connet[2]= SV_TRUE;
	}
    if(bPath == SV_VP_MAIN)
	{
	    u1Connet[0]= SV_TRUE;
	}
	else if(bPath == SV_VP_PIP)
	{
	    u1Connet[1]= SV_TRUE;
	}
	if(bPath != SV_VP_PIP)
	{
		if(BeAllocateResource(u1TxPath, u1BeSclType, &pSclConfig, &u1BeHandle))
		{
		    LOG(0," DRVCUST_BE_Connect Allocate resouce fail u1TxPath(%d),u1BeSclType(%d)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",u1TxPath,u1BeSclType);
			return SV_FAIL;
		}
	}
	if(u1TxPath == E_CUST_BE_TX_PATH_VIDEO)
	{
		if(bPath == SV_VP_MAIN)
		{
			u1BePath[0] = u1BeHandle;
		}
		else 
		{
			u1BePath[1] = u1BePath[0];
		}
	}
	else
	{
		u1BePath[2] = u1BeHandle;
	}

	if(bPath > SV_VP_PIP)
	{
		return SV_SUCCESS;
	}
	
	if(BeAssociatePath(u1BeHandle,bPath))
	{
	    LOG(0," BeAssociatePath fail bPath(%d) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",bPath);
		return SV_FAIL;
	}

	return SV_SUCCESS;
	

	
}

UINT8 DRVCUST_BE_Disconnect(UINT8 u1TxPath, UINT8 bPath)
{
	UINT8 u1BeHandle;
	
	if(u1TxPath == E_CUST_BE_TX_PATH_VIDEO)
	{
		if(bPath == SV_VP_MAIN)
		{
			u1BeHandle = u1BePath[0];
			u1Connet[0]= SV_FALSE;
		}
		else
		{
			u1BeHandle = u1BePath[1];
			u1Connet[1]= SV_FALSE;
		}
	}
	else
	{
		u1BeHandle = u1BePath[2];
		u1Connet[2]= SV_FALSE;
	}
	
	if(BeDissociatePath(u1BeHandle, bPath))
	{
		return SV_FAIL;
	}
    if(bPath != SV_VP_PIP)
	{
		if(BeFreeResource(u1BeHandle))
		{
			return SV_FAIL;
		}
	}

	return SV_SUCCESS;
	
}

void DRVCUST_PQ_Associate(UINT8 bPqPath, UINT8 bPath)
{
	PqAssociatePath(bPqPath, bPath);
}

void DRVCUST_PQ_Disassociate(UINT8 bPqPath)
{
	PqDissociatePath(bPqPath);
}

UINT32 DRVCUST_RGBOfstRemap(UINT32 u4Value)
{
    return u4Value<<2;
}

UINT16 DRVCUST_Y2RMap(void)
{
    //HSI SPEC change , Always -16 For video mode / Special Mode , 
    //because of DEMO Mode Support
    return  0;
}

/* @ Auto NR default Initial setting
 *      1: low
 *      2: Middle
 */
UINT8 DRVCUST_AutoNRDefSet(void)
{
    return 2;
}

/* @ Auto NR noise level implement
 * @ return noise level
 */
UINT8 DRVCUST_NoiseLevel(void)
{
#if 0
    UINT8 bNoiseLevel = NM_INVALIDLEVEL;
    UINT8 bRFNMLevel;

    if((bGetVideoDecType(bDrvNRGetCurrentPath())==SV_VD_TVD3D)&&
        	 (bGetSignalType(bDrvNRGetCurrentPath())==SV_ST_TV))// TVD RF source
    {

        bRFNMLevel = bTvdSignalStrengthLevel(1);   //RF level 0 ~ 80

        if(bRFNMLevel > 75)
        {
            bNoiseLevel = NM_LEVEL1_3;
        }
        else if(bRFNMLevel > 69)
        {
            bNoiseLevel = NM_LEVEL2;
        }
        else if(bRFNMLevel > 59)
        {
            bNoiseLevel = NM_LEVEL3;
        }
        else if(bRFNMLevel > 55)
        {
            bNoiseLevel = NM_LEVEL4;
        }
        else
        {
            bNoiseLevel = NM_LEVEL5;
        }
    }
    else
    {
        bNoiseLevel = vDrvNMLevel();   //content NR, Noise level 0 ~ 4
    }
    
    return bNoiseLevel;
#endif
    return 0;
}

void DRVCUST_SET_DEFAULT_GAMMA_REMAP(void)
{
    vIO32WriteFldAlign(ADAPTIVE_RGB_GAMMA_REG, 0x40, ADAPTIVE_RGB_GAMMA_SEL);
}

void DRVCUST_SetGammaRemapForceLoad(UINT8 bForceLoadGamma)
{
	//if have remap spec, need to modify... Currently, set to default, means no remap
	DRVCUST_SET_DEFAULT_GAMMA_REMAP();
	vIO32WriteFldAlign(ADAPTIVE_RGB_GAMMA_REG, bForceLoadGamma, ADAPTIVE_RGB_GAMMA_FORCE_LOAD);
}

void DRVCUST_GAMMA_REMAP_CALC(UINT32 u4GammaSel)
{
	UINT32 i;
	EXTERN UINT16 u2GammaDecodedTable[3][257];

	UINT16 *wTmpGammaCurve; 
	UINT16 GammaLength = 2*3*257;
	const UINT16 *pwRemapTable=NULL;
	UINT32 u4Index,u4IndexNxt;
	UINT32 u4CurrentCh;
	UINT8  bDecayUpTh,bDecayLowTh;
	UINT16 bAlpha;
	UINT8  bGammaBlendingEn;

	bDecayUpTh= IO32ReadFldAlign(ADAPTIVE_RGB_GAMMA_REG_01, ADAPTIVE_RGB_GAMMA_DECAY_UPTH);
	bDecayLowTh= IO32ReadFldAlign(ADAPTIVE_RGB_GAMMA_REG_01, ADAPTIVE_RGB_GAMMA_DECAY_LOWTH);
	bGammaBlendingEn= IO32ReadFldAlign(ADAPTIVE_RGB_GAMMA_REG_01, ADAPTIVE_RGB_GAMMA_BLENING_EN);
	if((wTmpGammaCurve = x_mem_alloc(GammaLength)) == NULL)
		return;
	
	if(u4GammaSel > 50)
	{
		bGammaBlendingEn = 0;
	}
	
	if(u4GammaSel <= NUM_OF_TEMP_GAMMA)
	{
		pwRemapTable=PANEL_GAMMA_REMAP_TBL+u4GammaSel*0x100;		
	}

	bDecayUpTh = MAX(bDecayLowTh+1,bDecayUpTh);



	if(pwRemapTable!=NULL)
	{ 

		for(u4CurrentCh=0; u4CurrentCh<3; ++u4CurrentCh)
		{
			for(i=0;i<256;++i)
			{
				if(i >= bDecayUpTh)
				{
					bAlpha = 100;
				}
				else if(i <= bDecayLowTh) 
				{
					bAlpha = 15;
				}
				else
				{
					bAlpha = (85 * (i - bDecayLowTh) / (bDecayUpTh - bDecayLowTh)) + 15;
				}
				
				if(!bGammaBlendingEn)
				{
					u4Index = (pwRemapTable[i] >> 2)&0xFF;
					u4IndexNxt = MIN(u4Index + 1,0xFF);
				}
				else
				{
					u4Index = ((i*4 + (((pwRemapTable[i] - i*4) * bAlpha )/100)) >> 2)&0xFF;
					u4IndexNxt = MIN(u4Index + 1,0xFF);
				}

				wTmpGammaCurve[u4CurrentCh*257 + i] = 
					((wHwGammaCurve[u4CurrentCh][u4Index] * (4-(pwRemapTable[i]&3)) +
						wHwGammaCurve[u4CurrentCh][u4IndexNxt]*(pwRemapTable[i]&3) + 2)>>2);
			}
		}

		wTmpGammaCurve[256] = wHwGammaCurve[0][256];
		wTmpGammaCurve[1*257+256] = wHwGammaCurve[1][256];
		wTmpGammaCurve[2*257+256] = wHwGammaCurve[2][256];
		
	}
	else
	{
		for(i=0;i<257;++i)
		{
			/*wTmpGammaCurve[0][i]=wHwGammaCurve[0][i];
			wTmpGammaCurve[1][i]=wHwGammaCurve[1][i];
			wTmpGammaCurve[2][i]=wHwGammaCurve[2][i];*/  // modify to fix warning "Frame size bigger than 1024Byte"
			wTmpGammaCurve[i]=wHwGammaCurve[0][i];
			wTmpGammaCurve[1*257+i]=wHwGammaCurve[1][i];
			wTmpGammaCurve[2*257+i]=wHwGammaCurve[2][i];
		}	
	}
	
    LOG(5, "***********HW GAMMA CURVE AFTER REMAP***********\n  Idx	  R 	G	  B\n");
	for(i=0; i<257; i++)
    {
		LOG(5, " %d  %d  %d  %d\n", i, wTmpGammaCurve[i], wTmpGammaCurve[1*257+i], wTmpGammaCurve[2*257+i]);
    }
	LOG(5, "***********HW GAMMA CURVE AFTER REMAP END***********\n");	
	
	x_memcpy(u2GammaDecodedTable, wTmpGammaCurve, GammaLength); 	
	x_mem_free(wTmpGammaCurve);
	wTmpGammaCurve = NULL;
}

/*
void DRVCUST_PANEL_GAMMA_REMAP(UINT32 u4GammaSel)
{
    
	i4DynGammaIndex = u4GammaSel + 0x10;
	DRVCUST_GAMMA_REMAP_CALC(i4DynGammaIndex);	
}
*/

void DRVCUST_PanelGammaRemapProc(void)
{
	//Gamma Proc for Gamma Remap.
    if ((bGammaInit && ((bPreGammaSel!= IO32ReadFldAlign(ADAPTIVE_RGB_GAMMA_REG, ADAPTIVE_RGB_GAMMA_SEL)) || 
		IO32ReadFldAlign(ADAPTIVE_RGB_GAMMA_REG, ADAPTIVE_RGB_GAMMA_FORCE_LOAD)))
        /*&&(bAingFlag == FALSE)&&(fgpicturemodechange == SV_FALSE)*/)
    {
        bPreGammaSel= IO32ReadFldAlign(ADAPTIVE_RGB_GAMMA_REG, ADAPTIVE_RGB_GAMMA_SEL);
        DRVCUST_GAMMA_REMAP_CALC(bPreGammaSel);
        vDrvSetGammaWritePingPongFlag(SV_TRUE);
        vIO32WriteFldAlign(ADAPTIVE_RGB_GAMMA_REG, SV_FALSE, ADAPTIVE_RGB_GAMMA_FORCE_LOAD);
    }
}
void DRVCUST_PANEL_GAMMA_REMAP(UINT32 u4GammaSel)
{
    UNUSED(u4GammaSel);
}

void DRVCUST_SetBlackLvlCtrl(UINT8 bPath)
{    
#if 0 // Below is SAMPLE CODE for function customization.
    UINT8 bLevel = GET_BLK_LVL(bPath);
    if (bPath == SV_VP_MAIN)
    {
        if(fgIsMainDVI())
        {
            SET_MATRIX_PED(SV_OFF);
            switch (bLevel)
            {
                case SV_OFF:
                    vSetHDMIRangeMode(SV_HDMI_RANGE_FORCE_FULL);
                    break;
                case SV_ON:
                    vSetHDMIRangeMode(SV_HDMI_RANGE_FORCE_LIMIT);
                    break;
                default:
                    vSetHDMIRangeMode(SV_HDMI_RANGE_FORCE_AUTO);
                    break;                
            }
        }
        else if (fgIsMainTvd3d() || fgIsMainYPbPr())
        {
            SET_MATRIX_PED(bLevel);
            vSetHDMIRangeMode(SV_HDMI_RANGE_FORCE_AUTO);
        }
        else
        {
            SET_MATRIX_PED(SV_OFF);
            vSetHDMIRangeMode(SV_HDMI_RANGE_FORCE_AUTO);
        }
    }
    else
    {
        SET_MATRIX_PED(SV_OFF);
        vSetHDMIRangeMode(SV_HDMI_RANGE_FORCE_AUTO);
    }
#endif
}
BOOL vDrvGetHDRCapabilities(UINT32* u4OutNumTypes, UINT32* u4Types, UINT32* u4maxLuminance, UINT32* u4maxAverageLuminance, UINT32* u4minLuminance )
{
	UINT32 u4HdrNumTypes = 2;
	UINT32 u4HdrTypes[HDR_TYPE] = {2,3};//1:HDR_TYPE_DOLBY_VISION,2:HDR_TYPE_HDR10,3:HDR_TYPE_HLG
	UINT32 u4HdrMaxLuminance = 2000;
	UINT32 u4HdrMaxAverageLuminance = 1000;
	UINT32 u4HdrMinLuminance = 5;
#if (defined (CC_MT5886)  || defined (CC_MT5893) || defined(CC_MT5895))
#ifdef CC_SUPPORT_DOLBY_VISION
    UINT8  u1Dovi;
    EEPROM_Read(0x1020c, (UPTR)(&u1Dovi), 0x1);
    if(u1Dovi == 0x1)
    {
        //add efuse config
        u4HdrNumTypes = 3;
        u4HdrTypes[0] = 1;
        u4HdrTypes[1] = 2;
        u4HdrTypes[2] = 3;
    }
#endif
#endif
	if(u4Types == NULL)
	{
		if(u4OutNumTypes != NULL )
		{
				*u4OutNumTypes = u4HdrNumTypes;  
		  }
		  else
		  {
				LOG(0,"****vDrvGetHDRCapabilities u4OutNumTypes is NULL****\n");
		  }
		 LOG(0,"****vDrvGetHDRCapabilities u4Types is NULL****\n");
		return SV_FALSE;
	}
	else if((u4maxLuminance == NULL )||(u4maxAverageLuminance == NULL)||(u4minLuminance == NULL) )
	{
		 LOG(0,"****vDrvGetHDRCapabilities other element is NULL****\n");
		 return SV_FALSE;
	}
	//TO-be
	*u4OutNumTypes = u4HdrNumTypes;    
	x_memcpy(u4Types, u4HdrTypes, u4HdrNumTypes*sizeof(UINT32));
	*u4maxLuminance = u4HdrMaxLuminance;
	*u4maxAverageLuminance = u4HdrMaxAverageLuminance;
	*u4minLuminance = u4HdrMinLuminance;
	
	LOG(0,"****vDrvGetHDRCapabilities u4maxLuminance=%d, u4maxAverageLuminance=%d, u4minLuminance=%d ****\n",
		*u4maxLuminance, *u4maxAverageLuminance, *u4minLuminance);
	return SV_TRUE;
}

UINT32 DRVCUST_HDMIRange(UINT8 bPath)
{
    return (fgIsDvi2VideoTiming(bPath) ? SV_HDMI_RANGE_LIMIT : SV_HDMI_RANGE_FULL);
}

void DRVCUST_SetVideoRange(UINT8 bMode)
{
	bVideoRangeMode = bMode;
}

UINT8 DRVCUST_GetVideoRange(UINT8 bPath)
{
	E_CUST_INPUT_TYPE eInputType = BEPQ_AP_Get_Input_Type(bPath);
	if(eInputType == E_CUST_INPUT_TYPE_WIFI_DISPLAY)
	{
		return bVideoRangeMode;
	}
	else
	{
		return (UINT8)DRV_CUSTOM_HDMI_RANGE_LIMIT;
	}
}

BOOL DRVCUST_HDMIWithValidAviInfo(void)
{
    UINT8 u1Type = SV_VP_MAIN;
	HDMI_IF_INFOFRAME rIfInfo;

	fgHdmiIf_GetInfoframe(u1Type,HDMI_IF_InfoFrame_AVI,&rIfInfo);
	if(rIfInfo.HDMI_FrameSize != 0)
	{
		return TRUE;
	}
	return FALSE;
}

//TRUE:photo
//FALSE:video
extern DviStatus_t DviSta[2];
BOOL DRVCUST_HDMIIsPhotoMode(void)
{
    UINT8 u1Type = SV_VP_MAIN;
    HDMI_IF_INFOFRAME rIfInfo;
    UINT8 u1DviTiming = DviSta[u1Type]._bDviTiming;

	fgHdmiIf_GetInfoframe(u1Type,HDMI_IF_InfoFrame_AVI,&rIfInfo);
    if(rIfInfo.HDMI_FrameSize != 0)    //Valid AviInfo
    {
		if((rIfInfo.HDMI_FrameData[8]&0x30) == 0x10)//CN1,CN0=0,1
		{
		    if((u1DviTiming == MODE_1080i_50) || (u1DviTiming == MODE_1080i) \
		        || (u1DviTiming == MODE_1080p_50) || (u1DviTiming == MODE_1080p_60)\
		        || (u1DviTiming == MODE_480P) || (u1DviTiming == MODE_576P)\
		        || (u1DviTiming == MODE_3840_2160P_25) || (u1DviTiming == MODE_3840_2160P_30))
		    {
		        return TRUE;//photo
		    }
		}
    }
    return FALSE;
}

UINT8 DRVCUST_HDMIGetVideoColorSpace(void)
{
    UINT8 u1Type = SV_VP_MAIN;
    UINT8 u1ColorSpc = SV_COLOR_HDMI_Normal;
    UINT8 u1ColorInfo; //Y1 Y0
    UINT8 u1Colorimetry;//C1 C0
    UINT8 u1ExtColorrimetryEC0; //EC0
    UINT8 u1ExtColorrimetryEC1; //EC1
    UINT8 u1ExtColorrimetryEC2; //EC2
    HDMI_IF_INFOFRAME rIfInfo;

	fgHdmiIf_GetInfoframe(u1Type,HDMI_IF_InfoFrame_AVI,&rIfInfo);
    if(rIfInfo.HDMI_FrameSize == 0)    //Valid AviInfo
    {
        return SV_COLOR_HDMI_Normal;
    }

	u1ColorInfo = (rIfInfo.HDMI_FrameData[4] & 0x60) >> 5;
    u1Colorimetry =	(rIfInfo.HDMI_FrameData[5]& 0xC0) >> 6;
    u1ExtColorrimetryEC0 = (rIfInfo.HDMI_FrameData[6] & 0x10) >> 4;
    u1ExtColorrimetryEC1 = (rIfInfo.HDMI_FrameData[6] & 0x20) >> 5;
    u1ExtColorrimetryEC2 = (rIfInfo.HDMI_FrameData[6] & 0x40) >> 6;
    if(u1ColorInfo != 0)//Y1,Y0 != 00
    {
        if(u1Colorimetry == 0x3) //C1,C0 == 11
        {
            if(u1ExtColorrimetryEC2 == 0x1)//EC2 == 1
            {
                if(u1ExtColorrimetryEC1 == 0x1) //EC1 == 1
                {
                    u1ColorSpc = SV_COLOR_HDMI_BT2020;
                }
                else
                {
                    if(u1ExtColorrimetryEC0 == 0x1) //EC0 == 1
                    {
                        u1ColorSpc = SV_COLOR_HDMI_BT2020c;
                    }
                }
            }
            else
            {
                u1ColorSpc = SV_COLOR_HDMI_xvYCC;
            }
        }
    }
    else
    {
        if(u1Colorimetry == 0x3) //C1,C0 == 11
        {
            if((u1ExtColorrimetryEC2 == 0x1)&&(u1ExtColorrimetryEC1 == 0x1))////go to (b-2) EC2 == 1 //EC1 == 1
            {
                u1ColorSpc = SV_COLOR_HDMI_BT2020;
            }
        }
    }

    return u1ColorSpc;
}

UINT8 DRVCUST_HDMIGetPhotoColorSpace(void)
{    
    UINT8 u1Type = SV_VP_MAIN;
    UINT8 u1ColorSpc = SV_COLOR_HDMI_sRGB;
    UINT8 u1ColorInfo; //Y1 Y0
    UINT8 u1Colorimetry;//C1 C0
    UINT8 u1ExtColorrimetry; //EC2 EC1 EC0
	HDMI_IF_INFOFRAME rIfInfo;
    
	fgHdmiIf_GetInfoframe(u1Type,HDMI_IF_InfoFrame_AVI,&rIfInfo);
    if(rIfInfo.HDMI_FrameSize == 0)    //Valid AviInfo
    {
        return SV_COLOR_HDMI_sRGB;
    }

    u1ColorInfo = (rIfInfo.HDMI_FrameData[4] & 0x60) >> 5;
    u1Colorimetry =	(rIfInfo.HDMI_FrameData[5]& 0xC0) >> 6;
    u1ExtColorrimetry = (rIfInfo.HDMI_FrameData[6] & 0x70) >> 4;
    if(u1ColorInfo != 0)//Y1,Y0 != 00
    {
        if(u1Colorimetry == 0x3) //C1,C0 == 11
        {
            if(u1ExtColorrimetry == 0x3)// EC2,EC1,EC0 == 001
            {
                u1ColorSpc = SV_COLOR_HDMI_Adobe_RGB;
            }
            else
            {
                u1ColorSpc = SV_COLOR_HDMI_sYCC;
            }
        }
    }
    else
    {
        if(u1Colorimetry == 0x3) //C1,C0 == 11
        {
            if(u1ExtColorrimetry == 0x4)// EC2,EC1,EC0 == 100
            {
                u1ColorSpc = SV_COLOR_HDMI_Adobe_RGB;
            }
        }
    }
    
    return u1ColorSpc;
}

UINT8 DRVCUST_HDMIGetColorimetry(void)
{
    UINT8 u1Type = SV_VP_MAIN;
    UINT8 u1ECValue = 0;
	UINT8 u1CNValue = 0;
    UINT8 u1ColorInfo; //Y1 Y0
    UINT8 u1Colorimetry;//C1 C0
    UINT8 u1ExtColorrimetry; //EC2 EC1 EC0
    HDMI_IF_INFOFRAME rIfInfo;

	fgHdmiIf_GetInfoframe(u1Type,HDMI_IF_InfoFrame_AVI,&rIfInfo);
    if(rIfInfo.HDMI_FrameSize != 0)    //Valid AviInfo
    {
        u1ColorInfo = rIfInfo.HDMI_FrameData[4] & 0x60;
        u1CNValue =	rIfInfo.HDMI_FrameData[5]& 0xC0;
        u1ECValue = rIfInfo.HDMI_FrameData[6] & 0x70;
        
    	if((u1ColorInfo & 0x60) != 0x00 )//YCC
    	{
    		if(u1CNValue == 0x40)
    		{
    			return SV_COLOR_HDMI_Colorimetry_601;
    		}
    		else if(u1CNValue == 0x80)
    		{
    			return SV_COLOR_HDMI_Colorimetry_709;
    		}
    		else //refer extended colorimetry
    	    {
    	    	if(u1ECValue == 0x00)
    	    	{
    	    		return SV_COLOR_HDMI_Colorimetry_XVYCC601;
    	    	}
    			else if(u1ECValue == 0x10)
    			{
    				return SV_COLOR_HDMI_Colorimetry_XVYCC709;
    			}
    			else if(u1ECValue == 0x20)
    			{
    				return SV_COLOR_HDMI_Colorimetry_sYCC601;
    			}
    			else if(u1ECValue == 0x30)
    			{
    				return SV_COLOR_HDMI_Colorimetry_AdobeYCC601;
    			}
    			else if((u1ECValue == 0x60) || (u1ECValue == 0x50))
    			{
    				return SV_COLOR_HDMI_Colorimetry_BT2020;
    			}
    	    }
    	}
    	else //RGB
    	{
    		if( u1CNValue == 0x00) //no data
    		{
    			return SV_COLOR_HDMI_Colorimetry_RGB;
    		}
    		else if(u1CNValue == 0xc0)//refer extended colorimetry
    		{
    			u1ECValue = u1ECValue >> 4;
    			if((u1ECValue & 0x7) == 0x4)
    			{
    				return SV_COLOR_HDMI_Colorimetry_AdobeRGB;
    			}
    			else if((u1ECValue & 0x7) == 0x6)
    			{
    				return SV_COLOR_HDMI_Colorimetry_BT2020;
    			}
    		}
    	}
    }
	return SV_COLOR_HDMI_Colorimetry_UnKnown;
}


UINT8 DRVCUST_HDMIGetAspectRatio(void)
{
    UINT8 u1Type = SV_VP_MAIN;
    UINT8 u1R4Value=0;
	UINT8 u1M2Value=0;
	UINT8 u1Ret=E_CUST_ASPECT_UNKNOWN;
    HDMI_IF_INFOFRAME rIfInfo;

	fgHdmiIf_GetInfoframe(u1Type,HDMI_IF_InfoFrame_AVI,&rIfInfo);
	if(rIfInfo.HDMI_FrameSize != 0)    //Valid AviInfo
    {
    	u1R4Value = rIfInfo.HDMI_FrameData[5] & 0xF;
		u1M2Value = (rIfInfo.HDMI_FrameData[5] >>4) & 0x3;
		switch(u1R4Value)
		{
			case 0x8:
				if(u1M2Value == 1)
				{
					u1Ret = E_CUST_ASPECT_4_3;
				}
				else if(u1M2Value == 2)
				{
					u1Ret = E_CUST_ASPECT_16_9;
				}
				else
				{
					u1Ret=E_CUST_ASPECT_UNKNOWN;
				}
				break;
			case 0x9:
				u1Ret = E_CUST_ASPECT_4_3;
				break;
			case 0xa:
				u1Ret = E_CUST_ASPECT_16_9;
				break;
			case 0xb:
				u1Ret = E_CUST_ASPECT_14_9;
				break;
			default:
				u1Ret=E_CUST_ASPECT_UNKNOWN;
				break;
		}
	}

	return u1Ret;
}

UINT8 DRVCUST_HDMIGetColorSpace(UINT8 bPath)
{
    return (UINT8)eHdmiIf_GetColorSpace(bPath);
}


UINT8 DRVCUST_HDMIGetHDRType(UINT8 bPath)
{
    HDMI_IF_INFOFRAME rIfInfo;
    UINT8 u1EOTF = 0;

	#if 0
    if(u1HdmiIf_GetDolbyVision(bPath))
    {
        return SV_HDR_TYPE_HDR3;
    }
	#endif
	#ifdef CC_SUPPORT_DOLBY_VISION
	if(u4DolbyGetCustSourceInfo(SV_VP_MAIN))
	{
		 return SV_HDR_TYPE_HDR3;
	}
	#endif
    u1EOTF = u1HdmiIf_GetHdrEOTF(bPath);
    if(HDMI_INVALID_HDR_EOTF_VALUE == u1EOTF)
    {
        return SV_HDR_TYPE_UNKNOWN;
    }

    if(u1EOTF == 2)
    {
        return SV_HDR_TYPE_HDR1;
    }
    else if(u1EOTF == 3)
    {
        return SV_HDR_TYPE_HDR2;
    }

    return SV_HDR_TYPE_SDR;
}


BOOL DRVCUST_HDMIGetHDRInfo(UINT8 bPath, SV_HDR_INFO_T* prHDRInfo)
{
    HDMI_IF_HDR_METADATA rHdmiIfHdrMetaData;
    HDR_ETOF_MODE eEOTF = SV_HDRTYPE_UNKNOWN;
    UINT8 u1HdmiParseEOTF = 0;

    if(prHDRInfo == NULL)
    {
        return FALSE;
    }

    u1HdmiParseEOTF = u1HdmiIf_GetHdrEOTF(bPath);
    if(HDMI_INVALID_HDR_EOTF_VALUE == u1HdmiParseEOTF)
    {
        LOG(1,"No EOTF is valid!\n");
        return FALSE;
    }

    switch (u1HdmiParseEOTF)
    {
        case 0:
            eEOTF = SV_HDRTYPE_SDR;
            break;
        case 1:
            eEOTF = SV_HDRTYPE_HDR;
            break;
        case 2:
            eEOTF = SV_HDRTYPE_ST2084;
            break;
        case 3:
            eEOTF = SV_HDRTYPE_HLG;
            break;
        default:
            eEOTF = SV_HDRTYPE_Future_EOTF;
            break;
    }
    prHDRInfo->eEOTF = eEOTF;

    vHdmiIf_GetHdrMetadata(bPath,&rHdmiIfHdrMetaData);
    prHDRInfo->au2Primaries_x[0] = (rHdmiIfHdrMetaData.au1HdrMetadata[1]<<8) | rHdmiIfHdrMetaData.au1HdrMetadata[0];
    prHDRInfo->au2Primaries_y[0] = (rHdmiIfHdrMetaData.au1HdrMetadata[3]<<8) | rHdmiIfHdrMetaData.au1HdrMetadata[2];
    prHDRInfo->au2Primaries_x[1] = (rHdmiIfHdrMetaData.au1HdrMetadata[5]<<8) | rHdmiIfHdrMetaData.au1HdrMetadata[4];
    prHDRInfo->au2Primaries_y[1] = (rHdmiIfHdrMetaData.au1HdrMetadata[7]<<8) | rHdmiIfHdrMetaData.au1HdrMetadata[6];
    prHDRInfo->au2Primaries_x[2] = (rHdmiIfHdrMetaData.au1HdrMetadata[9]<<8) | rHdmiIfHdrMetaData.au1HdrMetadata[8];
    prHDRInfo->au2Primaries_y[2] = (rHdmiIfHdrMetaData.au1HdrMetadata[11]<<8) | rHdmiIfHdrMetaData.au1HdrMetadata[10];

    prHDRInfo->u2White_Point_x = (rHdmiIfHdrMetaData.au1HdrMetadata[13]<<8) | rHdmiIfHdrMetaData.au1HdrMetadata[12];
    prHDRInfo->u2White_Point_y = (rHdmiIfHdrMetaData.au1HdrMetadata[15]<<8) | rHdmiIfHdrMetaData.au1HdrMetadata[14];

    prHDRInfo->u2MaxLuminance = (rHdmiIfHdrMetaData.au1HdrMetadata[17]<<8) | rHdmiIfHdrMetaData.au1HdrMetadata[16];
    prHDRInfo->u2MinLuminance = (rHdmiIfHdrMetaData.au1HdrMetadata[19]<<8) | rHdmiIfHdrMetaData.au1HdrMetadata[18];
    prHDRInfo->u2ContentLevel = (rHdmiIfHdrMetaData.au1HdrMetadata[21]<<8) | rHdmiIfHdrMetaData.au1HdrMetadata[20];
    prHDRInfo->u2FrameAverageLevel = (rHdmiIfHdrMetaData.au1HdrMetadata[23]<<8) | rHdmiIfHdrMetaData.au1HdrMetadata[22];
        
    return TRUE;
}

UINT8 DRVCUST_MMGetHDRType(UINT8 bPath)
{	
	B2R_CUST_INFO_T t_B2RCustInfo;	
	
	if(B2R_Get_Cust_info(bPath, B2R_GET_TYPE_CUST_INFO, &t_B2RCustInfo, sizeof(B2R_CUST_INFO_T)))
	{
			LOG(4, "\n====== B2R_Get_Cust_info fail ======\n");
	}
	//if(t_B2RCustInfo.tHdrInfo.tHdr10Info.e_HdrType==HDR_TYPE_DOVI)
	#ifdef CC_SUPPORT_DOLBY_VISION
	if(u4DolbyGetCustSourceInfo(SV_VP_MAIN))//(t_B2RCustInfo.tHdrInfo.tHdr10Info.e_HdrType==HDR_TYPE_DOVI)
	{
		return	SV_HDR_TYPE_HDR3;
	}
	else
	#endif
	{
		if(t_B2RCustInfo.tHdrDetectInfo.u4SEIHDRContent == 18)
		{
			return	SV_HDR_TYPE_HDR2;
		}
		else if(t_B2RCustInfo.tHdrDetectInfo.u4SEIHDRContent == 16)
		{
			return	SV_HDR_TYPE_HDR1;
		}
		else if(t_B2RCustInfo.tHdrDetectInfo.u4VUIHDRContent== 16)
		{
			return	SV_HDR_TYPE_HDR1;
		}
		else if(t_B2RCustInfo.tHdrDetectInfo.u4VUIHDRContent== 18)
		{
			return	SV_HDR_TYPE_HDR2;
		}
		else
		{
			return	SV_HDR_TYPE_SDR;
		}
	}

}


void DRCUST_SetVP9HDRType(VP9_HDR_TYPE_E eHDRType)
{
	eVP9HDRType = eHDRType;
}

UINT8 DRVCUST_GetVP9HDRType(void)
{
	return (UINT8)eVP9HDRType;
}

UINT8 DRVCUST_MMGetColorSpace(UINT8 bPath)
{
	B2R_CUST_INFO_T t_B2RCustInfo;	
	
	if(B2R_Get_Cust_info(bPath, B2R_GET_TYPE_CUST_INFO, &t_B2RCustInfo, sizeof(B2R_CUST_INFO_T)))
	{
		    LOG(4, "\n====== B2R_Get_Cust_info fail ======\n");
	}

	return t_B2RCustInfo.eColorID;
}

UINT32 DRVCUST_GetOSMatrix709(UINT8 bPath)
{
    UINT32 u4Matrix709;

#if 1
    u4Matrix709 = GET_MATRIX_HD_709 && (wDrvVideoInputHeight(bPath) >= 720);
#else
    UINT32 u4ScrTiming = bDrvVideoGetSourceTypeTiming(bPath);
    u4Matrix709 = ((u4ScrTiming >= SOURCE_TYPE_TIMING_MM_SD_I) && (u4ScrTiming <= SOURCE_TYPE_TIMING_MM_1080IP_HD)) ? 
                    SV_FALSE : (GET_MATRIX_HD_709 && (wDrvVideoInputHeight(bPath) >= 720));
#endif
    return u4Matrix709;

}

UINT8 DRVCUST_MMAPPGetTiming(UINT8 bOutputTiming)
{
    switch(bOutputTiming)
	{
		case SOURCE_TYPE_TIMING_MM_1080I_50: 
		case SOURCE_TYPE_TIMING_MM_1080I_60: 
		case SOURCE_TYPE_TIMING_MM_1080P_24:
		case SOURCE_TYPE_TIMING_MM_1080P_25:
		case SOURCE_TYPE_TIMING_MM_1080P_50:
		case SOURCE_TYPE_TIMING_MM_1080P_60:    
            return SOURCE_TYPE_TIMING_NET_1080IP;

       	case SOURCE_TYPE_TIMING_MM_720P_SD:
		case SOURCE_TYPE_TIMING_MM_720P_HD:
            return SOURCE_TYPE_TIMING_NET_720P;

		case SOURCE_TYPE_TIMING_MM_SD_P:
			return SOURCE_TYPE_TIMING_NET_SD_P;
			
		case SOURCE_TYPE_TIMING_MM_SD_I:
            return SOURCE_TYPE_TIMING_NET_SD_I;
        default:
            return (bOutputTiming);
    }
	
}

UINT8 DRVCUST_GetIsPIP(void)
{
    return bIsPIP;
}

static void DRVCUST_SetIsPIP(UINT8 data)
{
    switch (data) 
    {
        case 0x01:
            bIsPIP = SV_TRUE;
            break;
        default:
            bIsPIP = SV_FALSE;
            break;
    }
}

UINT8 DRVCUST_VideoGetHDRType(void)
{	
	UINT8 bSignalType = bGetSignalType(SV_VP_MAIN);
	UINT8 u1VideoHDRType;
	CUST_PIC_SETTING_T rPicInfoFromAP;
	
	BEPQ_AP_Get_Pic_Setting(&rPicInfoFromAP);
	
	if(DRVCUST_GetIsPIP() == SV_TRUE)  
	{
		return SV_HDR_TYPE_SDR;
	}
	#ifdef CC_SUPPORT_DOLBY_VISION
	if(u4DolbyGetCustSourceInfo(SV_VP_MAIN))
	{
		return SV_HDR_TYPE_HDR3;
	}
	#endif
	switch(bSignalType)
	{
		case SV_ST_DVI:
			u1VideoHDRType = DRVCUST_HDMIGetHDRType(SV_VP_MAIN);
			break;
		case SV_ST_MPEG:
			u1VideoHDRType = DRVCUST_MMGetHDRType(SV_VP_MAIN);
			break;
		default:
			u1VideoHDRType = SV_HDR_TYPE_SDR;
			break;
			
	}

	if(DRVCUST_GetVP9HDRType() != SV_VP9_HDR_TYPE_NONE)
	{
		u1VideoHDRType = DRVCUST_GetVP9HDRType();
	}

	switch(rPicInfoFromAP.eTransFunc)
	{
		case E_CUST_TRANSFER_FUNC_UI_AUTO:
			return	u1VideoHDRType; 			
			break;
		case E_CUST_TRANSFER_FUNC_UI_HDR10:
			return SV_HDR_TYPE_HDR1;
			break;
		case E_CUST_TRANSFER_FUNC_UI_HLG:
			return SV_HDR_TYPE_HDR2;
			break;
		default:
			#ifdef CC_SUPPORT_DOLBY_VISION
			if(u4DolbyGetCustSourceInfo(SV_VP_MAIN))
			{
				return SV_HDR_TYPE_HDR3;
			}
			else
			#endif
			{
				return SV_HDR_TYPE_SDR;
			}
			break;				
	}
}


UINT8 DRVCUST_GetOriHDRType(void)
{
    UINT8 bSignalType = bGetSignalType(SV_VP_MAIN);
	UINT8 u1VideoHDRType;
	CUST_PIC_SETTING_T rPicInfoFromAP;
	
	BEPQ_AP_Get_Pic_Setting(&rPicInfoFromAP);
	
	switch(bSignalType)
	{
		case SV_ST_DVI:
			u1VideoHDRType = DRVCUST_HDMIGetHDRType(SV_VP_MAIN);
			break;
		case SV_ST_MPEG:
			u1VideoHDRType = DRVCUST_MMGetHDRType(SV_VP_MAIN);
			break;
		default:
			u1VideoHDRType = SV_HDR_TYPE_SDR;
			break;			
	}

	return (UINT8)u1VideoHDRType;

}

void DRVCUST_SetOSDHDRMatrixCoeff(void)
{
    //mark OSD setting, keep HDRFlg judgment.
    if((DRVCUST_VideoGetHDRType()==SV_HDR_TYPE_HDR1) || (DRVCUST_VideoGetHDRType()==SV_HDR_TYPE_HDR2))
    {
		IsHDRFlg = SV_TRUE;
	}
	else
	{
		IsHDRFlg = SV_FALSE;
	}
/*
	if(IsPQICExists()) 
	{
		if(DRVCUST_VideoGetHDRType()==SV_HDR_TYPE_HDR1)
		{
			OSD_PLA_SetMatrixAndOffset(OSD_PLANE_1, OSDRGBF2RGBL_HDR_CTL[0]);
			OSD_PLA_SetMatrixAndOffset(OSD_PLANE_2, OSDRGBF2RGBL_HDR_CTL[0]);
			OSD_PLA_SetMatrixAndOffset(OSD_PLANE_3, OSDRGBF2RGBL_HDR_CTL[0]);
			UNUSED(OSD_PLA_SetPremulEn(OSD_PLANE_3, SV_OFF));
			vIO32WriteFldAlign(GLOBAL_ADJ_0A, 0x200, EXT3_ADJ_BRI);
			IsHDRFlg = SV_TRUE;
		}
		else if(DRVCUST_VideoGetHDRType()==SV_HDR_TYPE_HDR2)
		{
			OSD_PLA_SetMatrixAndOffset(OSD_PLANE_1, OSDRGBF2RGBL_HDR_CTL[1]);
			OSD_PLA_SetMatrixAndOffset(OSD_PLANE_2, OSDRGBF2RGBL_HDR_CTL[1]);
			OSD_PLA_SetMatrixAndOffset(OSD_PLANE_3, OSDRGBF2RGBL_HDR_CTL[1]);
			UNUSED(OSD_PLA_SetPremulEn(OSD_PLANE_3, SV_OFF));
			vIO32WriteFldAlign(GLOBAL_ADJ_0A, 0x200, EXT3_ADJ_BRI);
			IsHDRFlg = SV_TRUE;
		}
		else
		{
			if(fgIsPreOSD3En == SV_TRUE)
			{
				OSD_PLA_SetMatrixAndOffset(OSD_PLANE_1, OSDRGBF2RGBL_SDR_CTL[0]);
				OSD_PLA_SetMatrixAndOffset(OSD_PLANE_2, OSDRGBF2RGBL_SDR_CTL[0]);
				OSD_PLA_SetMatrixAndOffset(OSD_PLANE_3, OSDRGBF2RGBL_SDR_CTL[1]);
				vIO32WriteFldAlign(GLOBAL_ADJ_0A, 0x1C0, EXT3_ADJ_BRI); //0x200 no offset, 0x1C0, remove 64 offset
			}
			else
			{
				OSD_PLA_SetMatrixAndOffset(OSD_PLANE_1, OSDRGBF2RGBL_SDR_CTL[1]);
				OSD_PLA_SetMatrixAndOffset(OSD_PLANE_2, OSDRGBF2RGBL_SDR_CTL[1]);
				OSD_PLA_SetMatrixAndOffset(OSD_PLANE_3, OSDRGBF2RGBL_SDR_CTL[1]);
				vIO32WriteFldAlign(GLOBAL_ADJ_0A, 0x200, EXT3_ADJ_BRI);
			}
		
			UNUSED(OSD_PLA_SetPremulEn(OSD_PLANE_3, SV_ON));
			IsHDRFlg = SV_FALSE;
		}
		
		u1PreMatrixtoOS = SV_TRUE; // for OS matrix update for LPT.
	}
	else
        {
                if(DRVCUST_VideoGetHDRType()==SV_HDR_TYPE_HDR1)
                {
                        OSD_PLA_SetMatrixAndOffset(OSD_PLANE_1, OSDRGB2RGB_HDR_CTL[0]);
                        OSD_PLA_SetMatrixAndOffset(OSD_PLANE_2, OSDRGB2RGB_HDR_CTL[0]);
                        OSD_PLA_SetMatrixAndOffset(OSD_PLANE_3, OSDRGB2RGB_HDR_CTL[0]);
                        UNUSED(OSD_PLA_SetPremulEn(OSD_PLANE_3, SV_OFF));
                        IsHDRFlg = SV_TRUE;
                }
                else if(DRVCUST_VideoGetHDRType()==SV_HDR_TYPE_HDR2)
                {
                        OSD_PLA_SetMatrixAndOffset(OSD_PLANE_1, OSDRGB2RGB_HDR_CTL[1]);
                        OSD_PLA_SetMatrixAndOffset(OSD_PLANE_2, OSDRGB2RGB_HDR_CTL[1]);
                        OSD_PLA_SetMatrixAndOffset(OSD_PLANE_3, OSDRGB2RGB_HDR_CTL[1]);
                        UNUSED(OSD_PLA_SetPremulEn(OSD_PLANE_3, SV_OFF));
                        IsHDRFlg = SV_TRUE;
                }
                else
                {
                        OSD_PLA_SetMatrixAndOffset(OSD_PLANE_1, OSDRGB2RGB_SDR_CTL[0]);
                        OSD_PLA_SetMatrixAndOffset(OSD_PLANE_2, OSDRGB2RGB_SDR_CTL[0]);
                                OSD_PLA_SetMatrixAndOffset(OSD_PLANE_3, OSDRGB2RGB_SDR_CTL[0]);

                        UNUSED(OSD_PLA_SetPremulEn(OSD_PLANE_3, SV_ON));
                        IsHDRFlg = SV_FALSE;
		}
	}
	
	OSD_PLA_SetMatrixEnable(OSD_PLANE_1, SV_ON);
	OSD_PLA_SetMatrixEnable(OSD_PLANE_2, SV_ON);
	OSD_PLA_SetMatrixEnable(OSD_PLANE_3, SV_ON);
	*/	
}

extern OD_PARAM_T _ODParam;
void DRVCUST_SetODTable(void)
{
    //get OD table from flashPQ
    bApiFlashPqUpdateOD();

    //change OD table DMA, only support OD
    vDrvODSetDMA(OD_TABLE_CONFIG,OD_Table, sizeof(OD_Table));
    vDrvODMode(_ODParam.u1OD_ON);
    
    //channge OD table in Vsync
    //vApiRegisterVideoEvent(PE_EVENT_OD, SV_VP_MAIN, SV_ON);
}

#if 0
BOOL DRVCUST_WBSetPBMCtrlPointNum(UINT8 bSel)
{
	return DRVCUST_EepromWriteByte(EEP_WB_PBM_CTRL_POINT_SEL, bSel);
}
#endif

//Interpolate from 11 or 57 ctrl point to 257 point gamma curve
void DRVCUST_PBM_GAMLinearInterpolation(UINT32 u4CtrlCount, UINT16* u4CtrlPos, UINT16* u4TarCtrPos, INT32* iCtrlValue, INT32* OutputLut)
{
	int i, j;
	INT32 u4Temp;
	
	OutputLut[0] = iCtrlValue[0];
	OutputLut[256] = iCtrlValue[u4CtrlCount - 1];
	
	for(i=0; i<GAMMA_INDEX; i++)
	{
		for(j=0; j<u4CtrlCount-1; j++)
		{
			if((u4TarCtrPos[i] > u4CtrlPos[j]) && (u4TarCtrPos[i] <= u4CtrlPos[j+1]))
			{
				//Need do rounding
				u4Temp = (u4TarCtrPos[i] - u4CtrlPos[j]) * (iCtrlValue[j+1] - iCtrlValue[j]) * 10 / (u4CtrlPos[j+1] - u4CtrlPos[j]);
				OutputLut[i] = iCtrlValue[j] + ((u4Temp > 0) ? (u4Temp + 5)/10 : (u4Temp - 5)/10);
				break;
			}
		}
	}
	
	return;
}

#ifdef CC_MAPLE_CUST_DRV
//Only for Sakura, Salvia NO need
BOOL DRVCUST_GAMMA_Ofst_ADJ_UI(UINT8 u1Channel, UINT8 u1Index, UINT8 u1Value)
{
	UINT16 u2GammaIndex;
    
	u2GammaIndex = vApiFlashPqGetGammaId();

    LOG(2, "DRVCUST_GAMMA_Ofst_ADJ_UI: Channel: %d, Index: %d, Value: %d\n", u1Channel, u1Index, u1Value);
	//u1Channel: 0:R; 1:G; 2:B
	if(u1Channel>2 || u1Index>(GAMMA_20P_OFST_CTRL_POINT_NUM-1) || u1Value>255 || u1Value<0 || u2GammaIndex >= E_CT_MAX)
	{
		LOG(0, "Gamma Adjust UI error! Channel: %d, Index: %d, Value:%d, u2GammaIndex:%d\n",  u1Channel, u1Index, u1Value, u2GammaIndex);
		return SV_FALSE;
	}

	//AP set gamma!!!
	//DRVCUST_SET_GAMMA();

	i2WB20PUIValue[u1Channel][u1Index] = (INT16)(u1Value - 128);
	DRVCUST_SendEvent(E_CUST_WB_OFFSET_CHANGE, 0);
	
    u120POfst[u2GammaIndex][u1Channel][u1Index] = (UINT8)((INT32)u1Value);// - 20 + 128
    if(SV_FALSE == DRVCUST_EepromWriteByte(EEP_WB_20P_OFST_G0_START + 
		(u2GammaIndex*3*GAMMA_20P_OFST_CTRL_POINT_NUM + u1Channel*GAMMA_20P_OFST_CTRL_POINT_NUM + u1Index), u120POfst[u2GammaIndex][u1Channel][u1Index]))
	{
		Printf("Write Gamma to EEPROM Fail!!\n");
		return SV_FALSE;
	}
		
		return SV_TRUE;
}

BOOL DRVCUST_GAMMA_Ofst_ADJ_UI_GLOBLE(UINT8 u1Channel, UINT8 u1Index, UINT8 u1Value)
{
	UINT16 u2GammaIndex;
	u2GammaIndex = vApiFlashPqGetGammaId();

	LOG(2, "DRVCUST_GAMMA_Ofst_ADJ_UI: Channel: %d, Index: %d, Value: %d\n", u1Channel, u1Index, u1Value);
	//u1Channel: 0:R; 1:G; 2:B
	if(u1Channel>2 || u1Index>(GAMMA_20P_OFST_CTRL_POINT_NUM-1) || u1Value>255 || u1Value<0 || u2GammaIndex >= E_CT_MAX)
	{
		LOG(0, "Gamma Adjust UI error! Channel: %d, Index: %d, Value:%d, u2GammaIndex:%d\n",  u1Channel, u1Index, u1Value, u2GammaIndex);
		return SV_FALSE;
	}

	//AP set gamma!!!
	//DRVCUST_SET_GAMMA();

	i2WB20PUIValue[u1Channel][u1Index] = (INT16)(u1Value - 128);
	DRVCUST_SendEvent(E_CUST_WB_OFFSET_CHANGE, 0);
	u120POfst[u2GammaIndex][u1Channel][u1Index] = (UINT8)((INT32)u1Value );//- 20 + 128
	//below marked for delay time , every sigle value change , the whole arry be written
	/*
	if(SV_FALSE == DRVCUST_EepromWriteByte(EEP_WB_20P_OFST_G0_START + 
		(u2GammaIndex*3*GAMMA_10P_OFST_CTRL_POINT_NUM + u1Channel*GAMMA_10P_OFST_CTRL_POINT_NUM + u1Index), u110POfst[u2GammaIndex][u1Channel][u1Index]))
	{
		Printf("Write Gamma to EEPROM Fail!!\n");
		return SV_FALSE;
	}
	*/
	return SV_TRUE;
}

BOOL DRVCUST_GAMMA_Ofst_ADJ_UI_Write2EEP(VOID)
{

	if(SV_FALSE == EEPROM_Write(EEP_WB_20P_OFST_G0_START, (UPTR)u120POfst,(E_CT_MAX*SV_RGB_RGB*GAMMA_20P_OFST_CTRL_POINT_NUM)))
	{
		LOG(1,"Write Gamma to EEPROM Done!!\n");
		return SV_TRUE;
	}
	else
	{
		return SV_FALSE;
	}

}
VOID DRVCUST_GAMMA_Ofst_ADJ_UI_ReadEEP(VOID)
{
	UINT8 i;
	UINT8 j;
	UINT8 k;
	
	for(i=0;i<E_CT_MAX;i++)
	{
		for(j=0;j<SV_RGB_RGB;j++)
		{
			for(k=0;k<GAMMA_20P_OFST_CTRL_POINT_NUM;k++)
			{
				Printf("u120POfst[%d][%d][%d]=%d\n",i,j,k,u120POfst[i][j][k]);
			}
		}
		
	}
}

#endif

BOOL DRVCUST_SET_WB_GAM(UINT8 u1Channel, UINT8 u1Index, UINT8 u1Value)
{
    //u1Channel: 0:R; 1:G; 2:B
	if(u1Channel>2 || u1Index>(GAMMA_CTRL_POINT_NUM_TRACK-1) || u1Value<0)
	{
		LOG(0, "Tracking mode: Set WB_GAM_XX error! Channel: %d, Index: %d, Value:%d\n", u1Channel, u1Index, u1Value);
		return SV_FALSE;
	}

    if(SV_FALSE == DRVCUST_EepromWriteByte(EEP_WB_GAM0_START + (GAMMA_CTRL_POINT_NUM_TRACK*u1Channel + u1Index), u1Value))
	{
		LOG(0, "Tracking mode: Write WB_GAM_XX to EEPROM Fail!!\n");
		return SV_FALSE;
	}
	
    return SV_TRUE;
}

BOOL DRVCUST_SET_INP_LVL_WB(UINT8 u1Index, UINT16 u2Value)
{
    UINT8 u1Temp[2] = {0};
    //u1Channel: 0:R; 1:G; 2:B
	if(u1Index>(GAMMA_CTRL_POINT_NUM_TRACK-1) || u2Value>8192 || u2Value<0)
	{
		LOG(0, "Tracking mode: Set INP_LVL_WB_XX error! Index: %d, Value:%d\n", u1Index, u2Value);
		return SV_FALSE;
	}

    u1Temp[0] = (UINT8) (u2Value & 0xFF);
    u1Temp[1] = (UINT8) ((u2Value>>8) & 0xFF);
    
    if(SV_TRUE == DRVCUST_DoubleEepromWrite(EEP_WB_INP_LVL_START, (UPTR)u1Temp, 2))//DRVCUST_EepromWriteByte(EEP_WB_INP_LVL_START + u1Index*2, u1Value))
	{
		LOG(0, "Tracking mode: Write INP_LVL_WB_XX to EEPROM Fail!!\n");
		return SV_FALSE;
	}
	
    return SV_TRUE;
}

BOOL DRVCUST_SET_WB_GAM_GAIN(UINT8 u1Index, UINT8 u1Value)
{
	if(u1Index>(GAMMA_CTRL_POINT_NUM_TRACK-1) || u1Value<0)
	{
		LOG(0, "Tracking mode: Set WB_GAM_GAIN_XX error! Index: %d, Value:%d\n", u1Index, u1Value);
		return SV_FALSE;
	}

    if(SV_FALSE == DRVCUST_EepromWriteByte(EEP_WB_GAM_GAIN_START + u1Index, u1Value))
	{
		LOG(0, "Tracking mode: Write WB_GAM_GAIN_XX to EEPROM Fail!!\n");
		return SV_FALSE;
	}
	
    return SV_TRUE;
}

BOOL DRVCUST_SET_WB_BASE_GAIN(UINT8 u1ColorTemp, UINT8 u1Channel, UINT8 u1Value)
{
    //u1Channel: 0:R; 1:G; 2:B
	if(u1Channel>2)
	{
		LOG(0, "Tracking mode: Set WB_GAM_XX error! Channel: %d, Index: %d, Value:%d\n", u1Channel, u1Value);
		return SV_FALSE;
	}

    if(SV_FALSE == DRVCUST_EepromWriteByte(EEP_WB_BASE_GAIN_START + (u1ColorTemp*3 + u1Channel), u1Value))
	{
		LOG(0, "Tracking mode: Write WB_BASE_GAIN_XX to EEPROM Fail!!\n");
		return SV_FALSE;
	}
	
    return SV_TRUE;
}


BOOL DRVCUST_SET_WB_GAM_SEL(UINT8 u1Value)
{
	if(SV_FALSE == DRVCUST_EepromWriteByte(EEP_WB_GAM_SEL, u1Value))
	{
		LOG(0, "Tracking mode: Write WB_GAIN_SEL to EEPROM Fail!!\n");
		return SV_FALSE;
	}
	
    return SV_TRUE;
}

BOOL DRVCUST_SET_WB_OFST(UINT8 u1ColorTemp, UINT8 u1Channel, UINT8 u1Index, UINT8 u1Value)
{
    //u1Channel: 0:R; 1:G; 2:B
	if(u1Channel>2 || u1Index>(GAMMA_CTRL_POINT_NUM_TRACK-1) || u1Value<0)
	{
		LOG(0, "Tracking mode: Set WB_OFST_XX error! Channel: %d, Index: %d, Value:%d\n", u1Channel, u1Index, u1Value);
		return SV_FALSE;
	}

    if(SV_FALSE == DRVCUST_EepromWriteByte(EEP_WB_OFST_START + 
        (GAMMA_CTRL_POINT_NUM_TRACK*u1ColorTemp*3 + GAMMA_CTRL_POINT_NUM_TRACK*u1Channel + u1Index), u1Value))
	{
		LOG(0, "Tracking mode: Write WB_OFST_XX to EEPROM Fail!!\n");
		return SV_FALSE;
	}
	
    return SV_TRUE;
}

BOOL DRVCUST_SET_WBADJ_GODID_EEP(UINT8 u1Value)
{
    if(SV_FALSE == DRVCUST_EepromWriteByte(EEP_WB_WBADJ_GODID, u1Value))
    {
        LOG(0, "Write WBADJ_GODID to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}

BOOL DRVCUST_SET_WBADJ_PON_TIME_EEP(UINT8 u1Value)
{
    if(SV_FALSE == DRVCUST_EepromWriteByte(EEP_WB_WBADJ_PON_TIME, u1Value))
    {
        LOG(0, "Write WBADJ_PON_TIME to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}

BOOL DRVCUST_SET_WBADJ_JIG_VER_EEP(UINT16 u2Value)
{
    UINT8 u1Temp[2] = {0};

    LOG(1, "---->DRVCUST_SET_WBADJ_JIG_VER_EEP: %d\n", u2Value);
    u1Temp[0] = (UINT8)(u2Value & 0xFF);
    u1Temp[1] = (UINT8)((u2Value>>8) & 0xFF);
    
    if(SV_TRUE == DRVCUST_DoubleEepromWrite(EEP_WB_WBADJ_JJG_VER, (UPTR)u1Temp, 2))
    {
        LOG(0, "Write WBADJ_JIG_VER to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}

BOOL DRVCUST_SET_WBADJ_DS_DATE_EEP(UINT16 u2Value)
{
    UINT8 u1Temp[2] = {0};

    LOG(1, "---->DRVCUST_SET_WBADJ_DS_DATE_EEP: %d\n", u2Value);
    u1Temp[0] = (UINT8)(u2Value & 0xFF);
    u1Temp[1] = (UINT8)((u2Value>>8) & 0xFF);
    
    if(SV_TRUE == DRVCUST_DoubleEepromWrite(EEP_WB_WBADJ_DS_DATE, (UPTR)u1Temp, 2))
    {
        LOG(0, "Write WBADJ_DS_DATE to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}

BOOL DRVCUST_SET_WBADJ_ADJ_DATE_EEP(UINT16 u2Value)
{
    UINT8 u1Temp[2] = {0};

    LOG(1, "---->DRVCUST_SET_WBADJ_ADJ_DATE_EEP: %d\n", u2Value);
    u1Temp[0] = (UINT8)(u2Value & 0xFF);
    u1Temp[1] = (UINT8)((u2Value>>8) & 0xFF);
    
    if(SV_TRUE == DRVCUST_DoubleEepromWrite(EEP_WB_WBADJ_ADJ_DATE, (UPTR)u1Temp, 2))
    {
        LOG(0, "Write WBADJ_ADJ_DATE to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}

BOOL DRVCUST_SET_WBADJ_AGING1_EEP(UINT16 u2Value)
{
    UINT8 u1Temp[2] = {0};

    LOG(1, "---->DRVCUST_SET_WBADJ_AGING1_EEP: %d\n", u2Value);
    u1Temp[0] = (UINT8)(u2Value & 0xFF);
    u1Temp[1] = (UINT8)((u2Value>>8) & 0xFF);
    
    if(SV_TRUE == DRVCUST_DoubleEepromWrite(EEP_WB_WBADJ_AGING1, (UPTR)u1Temp, 2))
    {
        LOG(0, "Write WBADJ_AGING1 to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}

BOOL DRVCUST_SET_WBADJ_AGING2_EEP(UINT16 u2Value)
{
    UINT8 u1Temp[2] = {0};

    LOG(1, "---->DRVCUST_SET_WBADJ_AGING2_EEP: %d\n", u2Value);
    u1Temp[0] = (UINT8)(u2Value & 0xFF);
    u1Temp[1] = (UINT8)((u2Value>>8) & 0xFF);
    
    if(SV_TRUE == DRVCUST_DoubleEepromWrite(EEP_WB_WBADJ_AGING2, (UPTR)u1Temp, 2))
    {
        LOG(0, "Write WBADJ_AGING2 to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}

BOOL DRVCUST_SET_WBADJ_JJG_INFO1_EEP(UINT16 u2Value)
{
    UINT8 u1Temp[2] = {0};

    LOG(1, "---->DRVCUST_SET_WBADJ_JJG_INFO1_EEP: %d\n", u2Value);
    u1Temp[0] = (UINT8)(u2Value & 0xFF);
    u1Temp[1] = (UINT8)((u2Value>>8) & 0xFF);
    
    if(SV_TRUE == DRVCUST_DoubleEepromWrite(EEP_WB_WBADJ_JJG_INFO_1, (UPTR)u1Temp, 2))
    {
        LOG(0, "Write WBADJ_JJG_INFO_1 to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}

BOOL DRVCUST_SET_WBADJ_JJG_INFO2_EEP(UINT16 u2Value)
{
    UINT8 u1Temp[2] = {0};

    LOG(1, "---->DRVCUST_SET_WBADJ_JJG_INFO2_EEP: %d\n", u2Value);
    u1Temp[0] = (UINT8)(u2Value & 0xFF);
    u1Temp[1] = (UINT8)((u2Value>>8) & 0xFF);
    
    if(SV_TRUE == DRVCUST_DoubleEepromWrite(EEP_WB_WBADJ_JJG_INFO_2, (UPTR)u1Temp, 2))
    {
        LOG(0, "Write WBADJ_JJG_INFO_2 to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}

BOOL DRVCUST_SET_WB_INFO0_EEP(UINT16 u2Value)
{
    UINT8 u1Temp[2] = {0};

    LOG(1, "---->DRVCUST_SET_WB_INFO0_EEP: %d\n", u2Value);
    u1Temp[0] = (UINT8)(u2Value & 0xFF);
    u1Temp[1] = (UINT8)((u2Value>>8) & 0xFF);
    
    if(SV_TRUE == DRVCUST_DoubleEepromWrite(EEP_WB_INFO_0, (UPTR)u1Temp, 2))
    {
        LOG(0, "Write WBADJ_INFO_0 to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}

BOOL DRVCUST_SET_WB_INFO1_EEP(UINT16 u2Value)
{
    UINT8 u1Temp[2] = {0};

    LOG(1, "---->DRVCUST_SET_WB_INFO1_EEP: %d\n", u2Value);
    u1Temp[0] = (UINT8)(u2Value & 0xFF);
    u1Temp[1] = (UINT8)((u2Value>>8) & 0xFF);
    
    if(SV_TRUE == DRVCUST_DoubleEepromWrite(EEP_WB_INFO_1, (UPTR)u1Temp, 2))
    {
        LOG(0, "Write WBADJ_INFO_1 to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}

BOOL DRVCUST_SET_WB_INFO2_EEP(UINT16 u2Value)
{
    UINT8 u1Temp[2] = {0};

    LOG(1, "---->DRVCUST_SET_WB_INFO2_EEP: %d\n", u2Value);
    u1Temp[0] = (UINT8)(u2Value & 0xFF);
    u1Temp[1] = (UINT8)((u2Value>>8) & 0xFF);
    
    if(SV_TRUE == DRVCUST_DoubleEepromWrite(EEP_WB_INFO_2, (UPTR)u1Temp, 2))
    {
        LOG(0, "Write WBADJ_INFO_2 to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}

BOOL DRVCUST_SET_WB_INFO3_EEP(UINT16 u2Value)
{
    UINT8 u1Temp[2] = {0};

    LOG(1, "---->DRVCUST_SET_WB_INFO3_EEP: %d\n", u2Value);
    u1Temp[0] = (UINT8)(u2Value & 0xFF);
    u1Temp[1] = (UINT8)((u2Value>>8) & 0xFF);
    
    if(SV_TRUE == DRVCUST_DoubleEepromWrite(EEP_WB_INFO_3, (UPTR)u1Temp, 2))
    {
        LOG(0, "Write WBADJ_INFO_3 to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}

BOOL DRVCUST_SET_WB_INFO4_EEP(UINT16 u2Value)
{
    UINT8 u1Temp[2] = {0};

    LOG(1, "---->DRVCUST_SET_WB_INFO4_EEP: %d\n", u2Value);
    u1Temp[0] = (UINT8)(u2Value & 0xFF);
    u1Temp[1] = (UINT8)((u2Value>>8) & 0xFF);
    
    if(SV_TRUE == DRVCUST_DoubleEepromWrite(EEP_WB_INFO_4, (UPTR)u1Temp, 2))
    {
        LOG(0, "Write WBADJ_INFO_4 to EEPROM Fail!!\n");
        return SV_FALSE;
    }
    return SV_TRUE;
}
UINT8 DRVCUST_GET_WB_GAM(UINT8 u1Channel, UINT8 u1Index)
{
    //u1Channel: 0:R; 1:G; 2:B
	if(u1Channel>2 || u1Index>GAMMA_CTRL_POINT_NUM_TRACK-1)
	{
		LOG(0, "Tracking mode: Get WB_GAM_XX error! Channel: %d, Index: %d, Value:%d\n", u1Channel, u1Index);
		return SV_FALSE;
	}
	
    return DRVCUST_EepromReadByte(EEP_WB_GAM0_START + (GAMMA_CTRL_POINT_NUM_TRACK*u1Channel + u1Index));
}

UINT16 DRVCUST_GET_INP_LVL_WB(UINT8 u1Index)
{
    UINT8 u2Value[2] = {0};
    //u1Channel: 0:R; 1:G; 2:B
	if(u1Index>GAMMA_CTRL_POINT_NUM_TRACK-1)
	{
		LOG(0, "Tracking mode: Get INP_LVL_WB_XX error! Index: %d, Value:%d\n", u1Index);
		return SV_FALSE;
	}

    EEPROM_Read(EEP_WB_INP_LVL_START, (UPTR)u2Value, 2);
	
    return (u2Value[1]<<8 | u2Value[0]);
}

UINT8 DRVCUST_GET_WB_GAM_GAIN(UINT8 u1Index)
{
	if(u1Index>GAMMA_CTRL_POINT_NUM_TRACK-1)
	{
		LOG(0, "Tracking mode: Get WB_GAM_GAIN_XX error! Index: %d, Value:%d\n", u1Index);
		return SV_FALSE;
	}
	
    return DRVCUST_EepromReadByte(EEP_WB_GAM_GAIN_START + u1Index);
}

UINT8 DRVCUST_GET_WB_BASE_GAIN(UINT8 u1ColorTemp, UINT8 u1Channel)
{
    //u1Channel: 0:R; 1:G; 2:B
	if(u1Channel>2)
	{
		LOG(0, "Tracking mode: Get WB_GAM_XX error! Channel: %d, Index: %d, Value:%d\n", u1Channel);
		return SV_FALSE;
	}
	
    return DRVCUST_EepromReadByte(EEP_WB_BASE_GAIN_START + (u1ColorTemp*3 + u1Channel));
}

UINT8 DRVCUST_GET_WB_GAM_SEL(void)
{	
    return DRVCUST_EepromReadByte(EEP_WB_GAM_SEL);
}

UINT8 DRVCUST_GET_WB_OFST(UINT8 u1ColorTemp, UINT8 u1Channel, UINT8 u1Index)
{
    //u1Channel: 0:R; 1:G; 2:B
	if(u1Channel>2 || u1Index>GAMMA_CTRL_POINT_NUM_TRACK-1)
	{
		LOG(0, "Tracking mode: Get WB_OFST_XX error! Channel: %d, Index: %d, Value:%d\n", u1Channel, u1Index);
		return SV_FALSE;
	}
	
    return DRVCUST_EepromReadByte(EEP_WB_OFST_START + 
        (GAMMA_CTRL_POINT_NUM_TRACK*u1ColorTemp*3 + GAMMA_CTRL_POINT_NUM_TRACK*u1Channel + u1Index));
}

UINT8 DRVCUST_GET_WBADJ_GODID_EEP(void)
{
    return DRVCUST_EepromReadByte(EEP_WB_WBADJ_GODID);
}

UINT8 DRVCUST_GET_WBADJ_PON_TIME_EEP(void)
{
    return DRVCUST_EepromReadByte(EEP_WB_WBADJ_PON_TIME);
}

UINT16 DRVCUST_GET_WBADJ_JIG_VER_EEP(void)
{
    UINT8 u1Temp[2] = {0};

    EEPROM_Read(EEP_WB_WBADJ_JJG_VER, (UPTR)u1Temp, 2);
	
    return (UINT16)(u1Temp[1]<<8 | u1Temp[0]);
}

UINT16 DRVCUST_GET_WBADJ_DS_DATE_EEP(void)
{
    UINT8 u1Temp[2] = {0};

    EEPROM_Read(EEP_WB_WBADJ_DS_DATE, (UPTR)u1Temp, 2);
    
    return (UINT16)(u1Temp[1]<<8 | u1Temp[0]);
}



UINT16 DRVCUST_GET_WBADJ_ADJ_DATE_EEP(void)
{
    UINT8 u1Temp[2] = {0};

    EEPROM_Read(EEP_WB_WBADJ_ADJ_DATE, (UPTR)u1Temp, 2);
    
    return (UINT16)(u1Temp[1]<<8 | u1Temp[0]);
}


UINT16 DRVCUST_GET_WBADJ_AGING1_EEP(void)
{
    UINT8 u1Temp[2] = {0};

    EEPROM_Read(EEP_WB_WBADJ_AGING1, (UPTR)u1Temp, 2);
    
    return (UINT16)(u1Temp[1]<<8 | u1Temp[0]);
}


UINT16 DRVCUST_GET_WBADJ_AGING2_EEP(void)
{
    UINT8 u1Temp[2] = {0};

    EEPROM_Read(EEP_WB_WBADJ_AGING2, (UPTR)u1Temp, 2);
    
    return (UINT16)(u1Temp[1]<<8 | u1Temp[0]);
}


UINT16 DRVCUST_GET_WBADJ_JJG_INFO1_EEP(void)
{
    UINT8 u1Temp[2] = {0};

    EEPROM_Read(EEP_WB_WBADJ_JJG_INFO_1, (UPTR)u1Temp, 2);
    
    return (UINT16)(u1Temp[1]<<8 | u1Temp[0]);
}


UINT16 DRVCUST_GET_WBADJ_JJG_INFO2_EEP(void)
{
    UINT8 u1Temp[2] = {0};

    EEPROM_Read(EEP_WB_WBADJ_JJG_INFO_2, (UPTR)u1Temp, 2);
    
    return (UINT16)(u1Temp[1]<<8 | u1Temp[0]);
}


UINT16 DRVCUST_GET_WB_INFO0_EEP(void)
{
    UINT8 u1Temp[2] = {0};

    EEPROM_Read(EEP_WB_INFO_0, (UPTR)u1Temp, 2);
    
    return (UINT16)(u1Temp[1]<<8 | u1Temp[0]);
}


UINT16 DRVCUST_GET_WB_INFO1_EEP(void)
{
    UINT8 u1Temp[2] = {0};

    EEPROM_Read(EEP_WB_INFO_1, (UPTR)u1Temp, 2);
    
    return (UINT16)(u1Temp[1]<<8 | u1Temp[0]);
}


UINT16 DRVCUST_GET_WB_INFO2_EEP(void)
{
    UINT8 u1Temp[2] = {0};

    EEPROM_Read(EEP_WB_INFO_2, (UPTR)u1Temp, 2);
    
    return (UINT16)(u1Temp[1]<<8 | u1Temp[0]);
}


UINT16 DRVCUST_GET_WB_INFO3_EEP(void)
{
    UINT8 u1Temp[2] = {0};

    EEPROM_Read(EEP_WB_INFO_3, (UPTR)u1Temp, 2);
    
    return (UINT16)(u1Temp[1]<<8 | u1Temp[0]);
}


UINT16 DRVCUST_GET_WB_INFO4_EEP(void)
{
    UINT8 u1Temp[2] = {0};

    EEPROM_Read(EEP_WB_INFO_4, (UPTR)u1Temp, 2);
    
    return (UINT16)(u1Temp[1]<<8 | u1Temp[0]);
}

UINT8 DRVCUST_GET_WB_GAM_ForFac(UINT8 u1Channel, UINT8 u1Index)
{
    //u1Channel: 0:R; 1:G; 2:B
	if(u1Channel>2 || u1Index>GAMMA_CTRL_POINT_NUM_TRACK-1)
	{
		LOG(0, "Tracking mode: DRVCUST_GET_WB_GAM_ForFac error! Channel: %d, Index: %d\n", u1Channel, u1Index);
		return SV_FALSE;
	}
	
    return u1WB_GAM_RGB[u1Channel][u1Index];
}

UINT16 DRVCUST_GET_INP_LVL_WB_ForFac(UINT8 u1Index)
{
    //u1Channel: 0:R; 1:G; 2:B
	if(u1Index>GAMMA_CTRL_POINT_NUM_TRACK-1)
	{
		LOG(0, "Tracking mode: DRVCUST_GET_INP_LVL_WB_ForFac error! Index: %d\n", u1Index);
		return SV_FALSE;
	}
	
    return u2WB_INP_LVL_Fac[u1Index];
}

UINT8 DRVCUST_GET_WB_GAM_GAIN_ForFac(UINT8 u1Index)
{
	if(u1Index>GAMMA_CTRL_POINT_NUM_TRACK-1)
	{
		LOG(0, "Tracking mode: DRVCUST_GET_WB_GAM_GAIN_ForFac error! Index: %d\n", u1Index);
		return SV_FALSE;
	}
	
    return u1WB_GAM_GAIN[u1Index];
}

UINT8 DRVCUST_GET_WB_BASE_GAIN_ForFac(UINT8 u1Channel)
{
    //u1Channel: 0:R; 1:G; 2:B
	if(u1Channel>2)
	{
		LOG(0, "Tracking mode: DRVCUST_GET_WB_BASE_GAIN_ForFac error! Channel: %d\n", u1Channel);
		return SV_FALSE;
	}
	
    return u1WB_BASE_GAIN_RGB_EEP[stCTInfo.ui1CTIndex][u1Channel];
}

UINT8 DRVCUST_GET_WB_OFST_ForFac(UINT8 u1Channel, UINT8 u1Index)
{
    //u1Channel: 0:R; 1:G; 2:B
	if(u1Channel>2 || u1Index>GAMMA_CTRL_POINT_NUM_TRACK-1)
	{
		LOG(0, "Tracking mode: DRVCUST_GET_WB_OFST_ForFac error! Channel: %d, Index: %d\n", u1Channel, u1Index);
		return SV_FALSE;
	}
	
    return u1WB_OFST_RGB[stCTInfo.ui1CTIndex][u1Channel][u1Index];
}

#ifdef CC_MAPLE_CUST_DRV
void DRVCUST_SetWhiteBalanceOffset20pEnable(CUST_WB_OFFSET_20P_EN_T* pWbOffset20pEn)
{
	if(pWbOffset20pEn != NULL)
	{
		eWbOffset20pEn = pWbOffset20pEn->eWbOfst20pEn;
	}

	DRVCUST_SET_GAMMA();
}
#endif

void DRVCUST_SET_GAMMA(void)
{
	UINT32 i, j;
	UINT8 u1CttlPointNum;
	static UINT8 bBootUp=SV_TRUE;
	// static INT32 i4GamCurveRGB[SV_RGB_RGB][GAMMA_INDEX];
	INT32 (* i4GamCurveRGB)[GAMMA_INDEX] = NULL;
	static UINT8 u1GammaPBMMode;
	//UINT16 u2TarCtlPos[GAMMA_INDEX];
	UINT16 *u2TarCtlPos = NULL;
	UINT16 u2GammaIndex;
	UINT8 u110P_20POfst[E_CT_MAX][SV_RGB_RGB][GAMMA_20P_OFST_CTRL_POINT_NUM];
	static UINT8 u1UserOfstPointNumPrev = GAMMA_10P_OFST_CTRL_POINT_NUM;
	UINT8 u1UserOfstPointNum = GAMMA_10P_OFST_CTRL_POINT_NUM;
	
#ifdef CC_MAPLE_CUST_DRV
	UINT8 u1EepInplvl10P_20PBuf[GAMMA_20P_OFST_CTRL_POINT_NUM*sizeof(UINT16)];

	if( eWbOffset20pEn == E_CUST_WB_OFFSET_20P_DIS )
	{
		// User 10P adjustment mode
		u1UserOfstPointNum = GAMMA_10P_OFST_CTRL_POINT_NUM;
	}
	else
	{
		// User 20P adjustment mode
		u1UserOfstPointNum = GAMMA_20P_OFST_CTRL_POINT_NUM;
	}
#endif

	if (i4GamCurveRGB == NULL)
	{
		i4GamCurveRGB = (INT32 (*)[GAMMA_INDEX])x_mem_alloc(sizeof(INT32)*GAMMA_INDEX*SV_RGB_RGB);
		if (i4GamCurveRGB == NULL)
		{
			ASSERT(0);
			LOG(0, "%s:%d ERR: Alloc buffer fail.\n", __FUNCTION__, __LINE__);

			return ;
		}
		x_memset((void *)i4GamCurveRGB, 0, sizeof(INT32)*GAMMA_INDEX*SV_RGB_RGB);
	}

	if(u2TarCtlPos == NULL) 
	{
		u2TarCtlPos = (UINT16 *)x_mem_alloc(sizeof(UINT16)*GAMMA_INDEX);
		if(u2TarCtlPos == NULL)
		{
			ASSERT(0);
			LOG(0, "%s:%d ERR: Alloc buffer u2TarCtlPos fail.\n", __FUNCTION__, __LINE__);
			return ;
		}
		
		x_memset((void *)u2TarCtlPos, 0, sizeof(UINT16)*GAMMA_INDEX);
	}

	bGammaInit = SV_FALSE;
	vApiFlashPqSetGammaId(stCTInfo.ui1CTIndex);
	u2GammaIndex = vApiFlashPqGetGammaId();

	if(u2GammaIndex >= E_CT_MAX)
	{
		Printf("DRVCUST_SET_GAMMA Gamma index error!!\n");
		Printf("u2GammaIndex : %d\n", u2GammaIndex);
		if(u2TarCtlPos != NULL)
		{
			x_mem_free(u2TarCtlPos);
		}
		if(i4GamCurveRGB != NULL)
		{
			x_mem_free(i4GamCurveRGB);
		}
		return;
	}
	
	//PBM and Tracking use different gamma points.
	u1GammaPBMMode = DRVCUST_EepromReadByte(EEP_WB_LUT_ADJ_ON);
	//bColorIndex = MIN(E_CT_MAX-1, bColorIndex);

	LOG(1,"WB Method  %d, CT_Index:%d	 Gamma_Index : %d \n", u1GammaPBMMode, stCTInfo.ui1CTIndex, u2GammaIndex);
	
	//This for temporary check, because the EEPROM have NOT ready!!
	if((DRVCUST_EepromReadByte(EEP_WB_TRAK_MAGIC_NUM_START) != GAMMA_MAGIC00) &&
		(DRVCUST_EepromReadByte(EEP_WB_TRAK_MAGIC_NUM_START + 1) != GAMMA_MAGIC01) &&
		(DRVCUST_EepromReadByte(EEP_WB_PBM_MAGIC_NUM00) != GAMMA_MAGIC01) &&
		(DRVCUST_EepromReadByte(EEP_WB_PBM_MAGIC_NUM01) != GAMMA_MAGIC01))
	{
		bApiFlashPqUpdateGamma();
		vDrvGammaDecodeTable();
		vDrvSetGammaWritePingPongFlag(SV_TRUE); 
		if(u2TarCtlPos != NULL)
		{
			x_mem_free(u2TarCtlPos);
		}
		if(i4GamCurveRGB != NULL)
		{
			x_mem_free(i4GamCurveRGB);
		}
		return;
	}

	if(!u1GammaPBMMode)//Tracking	
	{
	   // UINT8 u1WB_INP_LVL_EEP_BUF[GAMMA_CTRL_POINT_NUM_TRACK*2]={0};
	   UINT8 * u1WB_INP_LVL_EEP_BUF = NULL;
		/*
		static UINT8 u1WB_GAM_RGB[SV_RGB_RGB][GAMMA_CTRL_POINT_NUM_TRACK];
		static UINT8 u1WB_OFST_RGB[E_CT_MAX][SV_RGB_RGB][GAMMA_CTRL_POINT_NUM_TRACK];
		static UINT8 u1WB_GAM_GAIN[GAMMA_CTRL_POINT_NUM_TRACK];
		static UINT16 u2WB_INP_LVL[GAMMA_CTRL_POINT_NUM_TRACK];
		static UINT8 u1WB_BASE_GAIN_RGB_EEP[E_CT_MAX][SV_RGB_RGB];
		*/

		//INT32 u4Determination_OFST[SV_RGB_RGB][GAMMA_CTRL_POINT_NUM_TRACK];
		INT32 (* u4Determination_OFST)[GAMMA_CTRL_POINT_NUM_TRACK] = NULL;
		//INT32 i4New_OFST[SV_RGB_RGB][GAMMA_CTRL_POINT_NUM_TRACK];
		//INT32 iWB_BASE_GAIN_RGB[E_CT_MAX][SV_RGB_RGB];
		INT32 (* iWB_BASE_GAIN_RGB)[SV_RGB_RGB] = NULL;
		Printf("Tracking \n\n");
		if(u1WB_INP_LVL_EEP_BUF == NULL)
		{
			u1WB_INP_LVL_EEP_BUF = (UINT8 *)x_mem_alloc(sizeof(UINT8)*GAMMA_CTRL_POINT_NUM_TRACK*2);

			if(u1WB_INP_LVL_EEP_BUF == NULL)
			{
				ASSERT(0);
				LOG(0, "%s:%d ERR: Alloc buffer u1WB_INP_LVL_EEP_BUF fail.\n", __FUNCTION__, __LINE__);
				return ;
			}
			
			x_memset((void *)u1WB_INP_LVL_EEP_BUF, 0, sizeof(UINT8)*GAMMA_CTRL_POINT_NUM_TRACK*2);
		}

		if(u4Determination_OFST == NULL)
		{
			u4Determination_OFST = (INT32 (*)[GAMMA_CTRL_POINT_NUM_TRACK])x_mem_alloc(sizeof(INT32)*SV_RGB_RGB*GAMMA_CTRL_POINT_NUM_TRACK);
			if(u4Determination_OFST == NULL)
			{
				ASSERT(0);
				LOG(0, "%s:%d ERR: Alloc buffer u4Determination_OFST fail.\n", __FUNCTION__, __LINE__);
				return ;
			}
			
			x_memset((void *)u4Determination_OFST, 0, sizeof(INT32)*SV_RGB_RGB*GAMMA_CTRL_POINT_NUM_TRACK);
		}

		if(iWB_BASE_GAIN_RGB == NULL)
		{
			iWB_BASE_GAIN_RGB = (INT32 (*)[SV_RGB_RGB])x_mem_alloc(sizeof(INT32)*E_CT_MAX*SV_RGB_RGB); 
			if(iWB_BASE_GAIN_RGB == NULL)
			{
				ASSERT(0);
				LOG(0, "%s:%d ERR: Alloc buffer iWB_BASE_GAIN_RGB fail.\n", __FUNCTION__, __LINE__);
				return ;
			}
			
			x_memset((void *)iWB_BASE_GAIN_RGB, 0, sizeof(INT32)*E_CT_MAX*SV_RGB_RGB);
		}
		
#ifdef CC_SONY_GAMMA
		/* init all gamma related parameters */
		//DRVCUST_Gamma_Init();
		//x_thread_delay(100);
#endif /* CC_SONY_GAMMA */

		if((DRVCUST_EepromReadByte(EEP_WB_TRAK_MAGIC_NUM_START) != GAMMA_MAGIC00) || 
			(DRVCUST_EepromReadByte(EEP_WB_TRAK_MAGIC_NUM_START + 1) != GAMMA_MAGIC01) || (bGammaLinear == SV_TRUE))
		{																																						  
			// Apply linear gamma			
			
			for (i=0; i<GAMMA_INDEX; i++)																														  
			{																																				  
				i4GamCurveRGB[SV_RGB_R][i] = i<<4;																										  
				i4GamCurveRGB[SV_RGB_G][i] = i<<4;																										  
				i4GamCurveRGB[SV_RGB_B][i] = i<<4;																										  
			}
		}																																						  
		else// Gamma was enabled																																  
		{
			// Get EEPROM Gamma
			if(bBootUp || u1IsForceWBEepReload())	//Read PBM data from EEPROM 1st time to initialize gamma
			{
				if(EEPROM_Read(EEP_WB_GAM0_START, (UPTR)&u1WB_GAM_RGB, GAMMA_CTRL_POINT_NUM_TRACK*SV_RGB_RGB))
				{
					Printf("Read Gamma from EEPROM Fail!!\n");
				}
				if(EEPROM_Read(EEP_WB_OFST_START, (UPTR)&u1WB_OFST_RGB, E_CT_MAX*SV_RGB_RGB*GAMMA_CTRL_POINT_NUM_TRACK))
				{
					Printf("Read Gamma from EEPROM Fail!!\n");
				}
				if(EEPROM_Read(EEP_WB_GAM_GAIN_START, (UPTR)&u1WB_GAM_GAIN, GAMMA_CTRL_POINT_NUM_TRACK))
				{
					Printf("Read Gamma from EEPROM Fail!!\n");
				}
				if(EEPROM_Read(EEP_WB_INP_LVL_START, (UPTR)u1WB_INP_LVL_EEP_BUF, GAMMA_CTRL_POINT_NUM_TRACK*2))
				{
					Printf("Read Gamma from EEPROM Fail!!\n");
				}
				u2WB_INP_LVL[0] = (u1WB_INP_LVL_EEP_BUF[0*2+1] << 8 | u1WB_INP_LVL_EEP_BUF[0*2]) >> 4;
				for(i=1; i<GAMMA_CTRL_POINT_NUM_TRACK; i++)
				{
					u2WB_INP_LVL[i] = u1WB_INP_LVL_EEP_BUF[i*2+1] << 8 | u1WB_INP_LVL_EEP_BUF[i*2];
					
					if(u2WB_INP_LVL[i] < u2WB_INP_LVL[i-1])
					{
						u2WB_INP_LVL[i] = (u2WB_INP_LVL[i-1]<=4096) ? u2WB_INP_LVL[i-1] : 4096;
					}
					u2WB_INP_LVL_Fac[i] = u2WB_INP_LVL[i];
					u2WB_INP_LVL[i] = u2WB_INP_LVL[i] >> 4;
				}
				if(EEPROM_Read(EEP_WB_BASE_GAIN_START, (UPTR)&u1WB_BASE_GAIN_RGB_EEP, SV_RGB_RGB*E_CT_MAX))
				{
					Printf("Read Gamma from EEPROM Fail!!\n");
				}
			}

			for(i=0; i<GAMMA_CTRL_POINT_NUM_TRACK; i++)
			{
				u4Determination_OFST[SV_RGB_R][i] = ((INT32)((u1WB_GAM_RGB[SV_RGB_R][i] - 128) + (u1WB_OFST_RGB[u2GammaIndex][SV_RGB_R][i] -128))) * u1WB_GAM_GAIN[i];
				u4Determination_OFST[SV_RGB_G][i] = ((INT32)((u1WB_GAM_RGB[SV_RGB_G][i] - 128) + (u1WB_OFST_RGB[u2GammaIndex][SV_RGB_G][i] -128))) * u1WB_GAM_GAIN[i];
				u4Determination_OFST[SV_RGB_B][i] = ((INT32)((u1WB_GAM_RGB[SV_RGB_B][i] - 128) + (u1WB_OFST_RGB[u2GammaIndex][SV_RGB_B][i] -128))) * u1WB_GAM_GAIN[i];
			}

			for(i=0; i<GAMMA_INDEX; i++)
			{
				u2TarCtlPos[i] = i;
			}

			//Only for debug log
			LOG(4, "***********Track GAMMA Parameter ***********\nCtrlIdx	 WB_GAM_R	 WB_GAM_G	 WB_GAM_B	 WB_OFST_R	  WB_OFST_G    WB_OFST_B\n");
			for(i=0; i<GAMMA_CTRL_POINT_NUM_TRACK; i++)
			{
				LOG(4, "  %04d	  %04d	  %04d	  %04d	  %04d	  %04d	  %04d\n", i, u1WB_GAM_RGB[SV_RGB_R][i], u1WB_GAM_RGB[SV_RGB_G][i], u1WB_GAM_RGB[SV_RGB_B][i],
					u1WB_OFST_RGB[u2GammaIndex][SV_RGB_R][i], u1WB_OFST_RGB[u2GammaIndex][SV_RGB_G][i], u1WB_OFST_RGB[u2GammaIndex][SV_RGB_B][i]);
			}

			for(i=0; i<GAMMA_CTRL_POINT_NUM_TRACK; i++)
			{
				if(i==0)
				{
					LOG(4, "WB_GAM_GAIN:\n");
				}
				LOG(4, "	%04d\n",  u1WB_GAM_GAIN[i]);
			}

			for(i=0; i<GAMMA_CTRL_POINT_NUM_TRACK; i++)
			{
				if(i==0)
				{
					LOG(4, "WB_INP_LVL:\n");
				}
				LOG(4, "  %04d\n", u2WB_INP_LVL[i]);
			}

			LOG(4, "WB_BASE_GAIN_RGB:	%04d	  %04d	  %04d\n", u1WB_BASE_GAIN_RGB_EEP[u2GammaIndex][SV_RGB_R], u1WB_BASE_GAIN_RGB_EEP[u2GammaIndex][SV_RGB_G], u1WB_BASE_GAIN_RGB_EEP[u2GammaIndex][SV_RGB_B]);
			
			LOG(4, "***********Track GAMMA Parameter END***********\n\n");

			LOG(3, "***********Track GAMMA u4Determination_OFST ***********\nCtrlIdx	R	 G	  B\n");
			for(i=0; i<GAMMA_CTRL_POINT_NUM_TRACK; i++)
			{
				for(j=0; j<SV_RGB_RGB; j++)
				{
					LOG(3, "  %04d	  %04d	  %04d	  %04d\n", i, u4Determination_OFST[SV_RGB_R][i], u4Determination_OFST[SV_RGB_G][i], u4Determination_OFST[SV_RGB_B][i]);
				}
			}
			LOG(3, "***********Track GAMMA u4Determination_OFST END***********\n\n");

			//New OFST, ofst interpolate from 11 ctrl point to 257 point.
			DRVCUST_PBM_GAMLinearInterpolation(GAMMA_CTRL_POINT_NUM_TRACK, u2WB_INP_LVL, u2TarCtlPos, u4Determination_OFST[0], i4GamCurveRGB[0]);
			DRVCUST_PBM_GAMLinearInterpolation(GAMMA_CTRL_POINT_NUM_TRACK, u2WB_INP_LVL, u2TarCtlPos, u4Determination_OFST[1], i4GamCurveRGB[1]);
			DRVCUST_PBM_GAMLinearInterpolation(GAMMA_CTRL_POINT_NUM_TRACK, u2WB_INP_LVL, u2TarCtlPos, u4Determination_OFST[2], i4GamCurveRGB[2]);

			//Only for debug log
			LOG(3, "***********Track GAMMA New Offset***********\nCtrlIdx  CtrlPos	R_OFST	G_OFST	B_OFST\n");
			for(i=0; i<GAMMA_INDEX; i++)
			{
				LOG(3, "  %04d	  %04d	  %04d	  %04d	  %04d\n", i, u2TarCtlPos[i], i4GamCurveRGB[0][i], i4GamCurveRGB[1][i], i4GamCurveRGB[2][i]);
			}
			LOG(3, "***********Track GAMMA New Offset END***********\n\n");
				
			for(i=0; i<E_CT_MAX; i++)
			{
				for(j=0; j<SV_RGB_RGB; j++)
				{
					iWB_BASE_GAIN_RGB[i][j] = u1WB_BASE_GAIN_RGB_EEP[i][j]; 	//convert from UINT8 to INT32, because the max the 0xff, if NOT convert,  (u1WB_BASE_GAIN_RGB_EEP + 1 >> 8) will error.

				}
			}

			for(i=0; i<GAMMA_INDEX; i++)
			{
				i4GamCurveRGB[SV_RGB_R][i] = ((u4WB_BASE_VALUE[i] * (iWB_BASE_GAIN_RGB[u2GammaIndex][SV_RGB_R] + 1))>>8) + i4GamCurveRGB[SV_RGB_R][i];
				i4GamCurveRGB[SV_RGB_G][i] = ((u4WB_BASE_VALUE[i] * (iWB_BASE_GAIN_RGB[u2GammaIndex][SV_RGB_G] + 1))>>8) + i4GamCurveRGB[SV_RGB_G][i];
				i4GamCurveRGB[SV_RGB_B][i] = ((u4WB_BASE_VALUE[i] * (iWB_BASE_GAIN_RGB[u2GammaIndex][SV_RGB_B] + 1))>>8) + i4GamCurveRGB[SV_RGB_B][i];
			}
		}
		
		if(u1WB_INP_LVL_EEP_BUF != NULL)
		{
			x_mem_free(u1WB_INP_LVL_EEP_BUF);
		}
		if(u4Determination_OFST != NULL)
		{
			x_mem_free(u4Determination_OFST);
		}
		if(iWB_BASE_GAIN_RGB != NULL)
		{
			x_mem_free(iWB_BASE_GAIN_RGB);
		}
	}	
	else // PBM 																																				  
	{																																							  
		if((DRVCUST_EepromReadByte(EEP_WB_PBM_MAGIC_NUM00) != GAMMA_MAGIC00) || 
			(DRVCUST_EepromReadByte(EEP_WB_PBM_MAGIC_NUM01) != GAMMA_MAGIC01) || (bGammaLinear == SV_TRUE))
		{																																						  
			// Apply linear gamma			
			
			for (i=0; i<GAMMA_INDEX; i++)																														  
			{																																				  
				i4GamCurveRGB[SV_RGB_R][i] = i<<4;																										  
				i4GamCurveRGB[SV_RGB_G][i] = i<<4;																										  
				i4GamCurveRGB[SV_RGB_B][i] = i<<4;																										  
			}
		}		
		else
		{
		// 5 Gamma for color temp
		// 3 channel R, G, B for each Gamma
		// 33 points for each channel
		// 2 bytes for each points 
		static UINT8 u1EEPGammaBuf[E_CT_MAX][SV_RGB_RGB][GAMMA_CTRL_POINT_NUM_PBM * 2];
		//UINT16 u2CtlPos[GAMMA_CTRL_POINT_NUM_PBM] = {0};
		UINT16 *u2CtlPos = NULL;
		
		//INT32 iCtlValue_RGB[SV_RGB_RGB][GAMMA_CTRL_POINT_NUM_PBM];
		INT32 (* iCtlValue_RGB)[GAMMA_CTRL_POINT_NUM_PBM] = NULL;
			
		LOG(0, "PBM GAMMA\n\n");

		if(u2CtlPos == NULL)
		{
			u2CtlPos = (UINT16 *)x_mem_alloc(sizeof(UINT16)*GAMMA_CTRL_POINT_NUM_PBM);
			if(u2CtlPos == NULL)
			{				
				ASSERT(0);
				LOG(0, "%s:%d ERR: Alloc buffer u2CtlPos fail.\n", __FUNCTION__, __LINE__);
				return ;
			}
			
			x_memset((void *)u2CtlPos, 0, sizeof(UINT16)*GAMMA_CTRL_POINT_NUM_PBM);
		}

		if(iCtlValue_RGB == NULL)
		{
			iCtlValue_RGB = (INT32 (*)[GAMMA_CTRL_POINT_NUM_PBM])x_mem_alloc(sizeof(INT32)*SV_RGB_RGB*GAMMA_CTRL_POINT_NUM_PBM); 
			if(iCtlValue_RGB == NULL)
			{
				ASSERT(0);
				LOG(0, "%s:%d ERR: Alloc buffer iCtlValue_RGB fail.\n", __FUNCTION__, __LINE__);
				return ;
			}
			
			x_memset((void *)iCtlValue_RGB, 0, sizeof(INT32)*SV_RGB_RGB*GAMMA_CTRL_POINT_NUM_PBM);
		}

#ifdef CC_MAPLE_CUST_DRV
		//For Sakura
		u1CttlPointNum = GAMMA_CTRL_POINT_NUM_PBM;
#else
		//For Salvia
		u1CttlPointNum = GAMMA_CTRL_POINT_NUM2_PBM;
#endif
		for(i=0; i< u1CttlPointNum; i++)
		{
			u2CtlPos[i] = u2CtlPos_PBM[i];
		}
		
		if(bBootUp || u1IsForceWBEepReload())//Read PBM data from EEPROM 1st time to initialize gamma
		{
			if(EEPROM_Read(EEP_WB_LUT_ADJ_G0_START,(UPTR)&u1EEPGammaBuf, E_CT_MAX*GAMMA_CTRL_POINT_NUM_PBM*2*SV_RGB_RGB))
			{
				Printf("Read Gamma from EEPROM Fail!!\n");
			}
		}

		LOG(3, "***********PBM GAMMA CONTROL POINT***********\n  CtrlIdx	CtrlPos    R	 G	  B\n");
		
		// Get EEPROM Gamma  from buffer (EEPROM already meet magic No.)
		for (i=0; i<u1CttlPointNum; i++)																														  
		{																																				  
			iCtlValue_RGB[SV_RGB_R][i] = (INT32)(u1EEPGammaBuf[u2GammaIndex][SV_RGB_R][i*2+1]<<8) |
										u1EEPGammaBuf[u2GammaIndex][SV_RGB_R][i*2];
																																							  
			iCtlValue_RGB[SV_RGB_G][i] = (INT32)(u1EEPGammaBuf[u2GammaIndex][SV_RGB_G][i*2+1]<<8) |
										u1EEPGammaBuf[u2GammaIndex][SV_RGB_G][i*2]; 
																																							  
			iCtlValue_RGB[SV_RGB_B][i] = (INT32)(u1EEPGammaBuf[u2GammaIndex][SV_RGB_B][i*2+1]<<8) |
										u1EEPGammaBuf[u2GammaIndex][SV_RGB_B][i*2]; 

			LOG(3, "  %d,  %d,	%04d, %04d, %04d\n", i, u2CtlPos[i], iCtlValue_RGB[SV_RGB_R][i], iCtlValue_RGB[SV_RGB_G][i], iCtlValue_RGB[SV_RGB_B][i]);
		}
		LOG(3, "***********PBM GAMMA CONTROL POINT END***********\n");
		
#if 1//def CC_Factory2K12
		for (i=0; i<u1CttlPointNum; ++i)
		{
			_iUsedCtlValue_R[i] = iCtlValue_RGB[SV_RGB_R][i];
			_iUsedCtlValue_G[i] = iCtlValue_RGB[SV_RGB_G][i];
			_iUsedCtlValue_B[i] = iCtlValue_RGB[SV_RGB_B][i];
		}
#endif

		for(i=0; i<GAMMA_INDEX; i++)
		{
			u2TarCtlPos[i] = i;
		}
		// GAMMA INTERPOLATION																																		
		DRVCUST_PBM_GAMLinearInterpolation(u1CttlPointNum, u2CtlPos, u2TarCtlPos, iCtlValue_RGB[SV_RGB_R], i4GamCurveRGB[SV_RGB_R]);	
		DRVCUST_PBM_GAMLinearInterpolation(u1CttlPointNum, u2CtlPos, u2TarCtlPos, iCtlValue_RGB[SV_RGB_G], i4GamCurveRGB[SV_RGB_G]); 
		DRVCUST_PBM_GAMLinearInterpolation(u1CttlPointNum, u2CtlPos, u2TarCtlPos, iCtlValue_RGB[SV_RGB_B], i4GamCurveRGB[SV_RGB_B]);																																										  

		if(u2CtlPos != NULL)
		{
			x_mem_free(u2CtlPos);
		}
		if(iCtlValue_RGB != NULL)
		{
			x_mem_free(iCtlValue_RGB);
		}
		}

	}		

	_iUsedColorTemp = u2GammaIndex;
	
#ifdef CC_MAPLE_CUST_DRV
	//Only for Sakura, Salvia NO need
	if(bBootUp || u1IsForceWBEepReload() || u1UserOfstPointNum!=u1UserOfstPointNumPrev)
	{
		u1UserOfstPointNumPrev = u1UserOfstPointNum;
		
		// Even with 10pt adjusment, offset notified from App is 20pt and stored in eeprom, so always read 20pt
		if(EEPROM_Read(EEP_WB_20P_OFST_G0_START,(UPTR)&u120POfst, E_CT_MAX*GAMMA_20P_OFST_CTRL_POINT_NUM*SV_RGB_RGB))
		{
			Printf("Read Gamma from EEPROM Fail!!\n");
		}

		if( u1UserOfstPointNum == GAMMA_10P_OFST_CTRL_POINT_NUM )
		{
			// User 10P adjustment mode - read INP_LVL and GAIN for 10P adjustment
			if(EEPROM_Read(EEP_WB_GAM_10P_GAIN_START,(UPTR)&u1Gam10P_20PGain, GAMMA_10P_OFST_CTRL_POINT_NUM))
			{
				Printf("Read Gamma from EEPROM Fail!!\n");
			}
			if(EEPROM_Read(EEP_INP_LVL_10P_START,(UPTR)&u1EepInplvl10P_20PBuf, GAMMA_10P_OFST_CTRL_POINT_NUM*2))
			{
				Printf("Read Gamma from EEPROM Fail!!\n");
			}
		}
		else
		{
			// User 20P adjustment mode - read INP_LVL and GAIN for 20P adjustment
			if(EEPROM_Read(EEP_WB_GAM_20P_GAIN_START,(UPTR)&u1Gam10P_20PGain, GAMMA_20P_OFST_CTRL_POINT_NUM))
			{
				Printf("Read Gamma from EEPROM Fail!!\n");
			}
			if(EEPROM_Read(EEP_INP_LVL_20P_START,(UPTR)&u1EepInplvl10P_20PBuf, GAMMA_20P_OFST_CTRL_POINT_NUM*2))
			{
				Printf("Read Gamma from EEPROM Fail!!\n");
			}
		}
		
		for(i=0; i<u1UserOfstPointNum; i++)
		{
			u2Inplvl10P_20P[i] = u1EepInplvl10P_20PBuf[i*2+1]<<8 | u1EepInplvl10P_20PBuf[i*2];
			u2Inplvl10P_20P[i] = u2Inplvl10P_20P[i] >> 4;
		}
	}

	// Copy User offset value according to adjustment point num (10pt or 20pt)
	for(i=0; i<SV_RGB_RGB; i++)
	{
		for(j=0; j<u1UserOfstPointNum; j++ )
		{
			if( u1UserOfstPointNum == GAMMA_10P_OFST_CTRL_POINT_NUM )
			{
				u110P_20POfst[u2GammaIndex][i][j] = u120POfst[u2GammaIndex][i][2*j];
			}
			else
			{
				u110P_20POfst[u2GammaIndex][i][j] = u120POfst[u2GammaIndex][i][j];
			}
		}
	}
	
	if(bWBFlatPreOnoff == SV_FALSE)
	{
		i4Ctrl10P_20POfst[SV_RGB_R][0] = 0;
		i4Ctrl10P_20POfst[SV_RGB_G][0] = 0;
		i4Ctrl10P_20POfst[SV_RGB_B][0] = 0;

		for(i=1; i<u1UserOfstPointNum; i++)
		{
			i4Ctrl10P_20POfst[SV_RGB_R][i] = ((INT32)u110P_20POfst[u2GammaIndex][SV_RGB_R][i] - 128) * u1Gam10P_20PGain[i];
			i4Ctrl10P_20POfst[SV_RGB_G][i] = ((INT32)u110P_20POfst[u2GammaIndex][SV_RGB_G][i] - 128) * u1Gam10P_20PGain[i];
			i4Ctrl10P_20POfst[SV_RGB_B][i] = ((INT32)u110P_20POfst[u2GammaIndex][SV_RGB_B][i] - 128) * u1Gam10P_20PGain[i];
		}

		//Only for debug log
		LOG(4, "***********User %dP GAMMA Parameters***********\n  CtrlIdx	  INP_LVL	 GAM_GAIN	 1OFST_R	  OFST_G	OFST_B\n", u1UserOfstPointNum-1);
		for (i=0; i<u1UserOfstPointNum; i++) 																													  
		{																																				  
			LOG(4, "  %d,  %04d,  %04d,  %04d,	  %04d,    %04d\n", i, u1Gam10P_20PGain[i], u2Inplvl10P_20P[i], u110P_20POfst[u2GammaIndex][SV_RGB_R][i], 
				u110P_20POfst[u2GammaIndex][SV_RGB_G][i], u110P_20POfst[u2GammaIndex][SV_RGB_B][i]);
		}
		LOG(4, "***********User %dP GAMMA Parameters END***********\n", u1UserOfstPointNum-1);
		
		LOG(3, "***********User %dP GAMMA CONTROL POINT***********\n  CtrlIdx	 R	  G    B\n", u1UserOfstPointNum-1);
		for (i=0; i<u1UserOfstPointNum; i++) 																													  
		{																																				  
			LOG(3, "  %d,  %04d,  %04d,    %04d,	%04d\n", i, u2Inplvl10P_20P[i], i4Ctrl10P_20POfst[0][i], i4Ctrl10P_20POfst[1][i], i4Ctrl10P_20POfst[2][i]);
		}
		LOG(3, "***********User %dP GAMMA CONTROL POINT END***********\n", u1UserOfstPointNum-1);

		for(i=0; i<GAMMA_INDEX; i++)
		{
			u2TarCtlPos[i] = i;
		}

		if (pi4Gam10P_20POfst == NULL)
		{
			pi4Gam10P_20POfst = (INT32 (*)[GAMMA_INDEX])x_mem_alloc(sizeof(INT32)*GAMMA_INDEX*SV_RGB_RGB);
			if (pi4Gam10P_20POfst == NULL)
			{
				ASSERT(0);
				LOG(0, "%s:%d ERR: Alloc buffer fail.\n", __FUNCTION__, __LINE__);

				return ;
			}
			x_memset((void *)pi4Gam10P_20POfst, 0, sizeof(INT32)*GAMMA_INDEX*SV_RGB_RGB);
		}

		if (pi4Gam10P_20POfst)
		{
			DRVCUST_PBM_GAMLinearInterpolation(u1UserOfstPointNum, u2Inplvl10P_20P, u2TarCtlPos, i4Ctrl10P_20POfst[SV_RGB_R], pi4Gam10P_20POfst[SV_RGB_R]);
			DRVCUST_PBM_GAMLinearInterpolation(u1UserOfstPointNum, u2Inplvl10P_20P, u2TarCtlPos, i4Ctrl10P_20POfst[SV_RGB_G], pi4Gam10P_20POfst[SV_RGB_G]);
			DRVCUST_PBM_GAMLinearInterpolation(u1UserOfstPointNum, u2Inplvl10P_20P, u2TarCtlPos, i4Ctrl10P_20POfst[SV_RGB_B], pi4Gam10P_20POfst[SV_RGB_B]);

			for(i=0; i<SV_RGB_RGB; i++)
			{
				for(j=0; j<GAMMA_INDEX; j++)
				{
					i4GamCurveRGB[i][j] += pi4Gam10P_20POfst[i][j] ;
				}
			}
		}
	}
#endif

	//Only for debug log
	LOG(5, "***********HW GAMMA CURVE AFTER INTP***********\n  Idx	  R 	G	  B\n");
	for(i=0; i<GAMMA_INDEX; i++)
	{
		LOG(5, " %04d  %04d  %04d  %04d\n", i, i4GamCurveRGB[0][i], i4GamCurveRGB[1][i], i4GamCurveRGB[2][i]);
	}
	LOG(5, "***********HW GAMMA CURVE AFTER INTP END***********\n");	

	for(i=0; i<GAMMA_INDEX; i++)
	{
		for(j=0; j<SV_RGB_RGB; j++)
		{
			if(i4GamCurveRGB[j][i] < 0)
			{
				i4GamCurveRGB[j][i] = 0;
			}
			if(i4GamCurveRGB[j][i] > ((i==GAMMA_INDEX-1) ? 4096 : 4095))
			{
				i4GamCurveRGB[j][i] = ((i==GAMMA_INDEX-1) ? 4096 : 4095);
			}
		}
	}
	
	u2GammaDecodedTable[SV_RGB_R][0] = (UINT16)(i4GamCurveRGB[SV_RGB_R][0]);																									  
	u2GammaDecodedTable[SV_RGB_G][0] = (UINT16)(i4GamCurveRGB[SV_RGB_G][0]);																									  
	u2GammaDecodedTable[SV_RGB_B][0] = (UINT16)(i4GamCurveRGB[SV_RGB_B][0]);																										  
	wHwGammaCurve[SV_RGB_R][0] = (UINT16)(i4GamCurveRGB[SV_RGB_R][0]);																											  
	wHwGammaCurve[SV_RGB_G][0] = (UINT16)(i4GamCurveRGB[SV_RGB_G][0]);																											  
	wHwGammaCurve[SV_RGB_B][0] = (UINT16)(i4GamCurveRGB[SV_RGB_B][0]);	

	//limter before to decoder table.																																							  
	for (i=1; i<GAMMA_INDEX; i++)																																	  
	{																																						  
		if ((i4GamCurveRGB[SV_RGB_R][i] < i4GamCurveRGB[SV_RGB_R][i-1]) || (i4GamCurveRGB[SV_RGB_R][i]==0)) 																				  
		{																																				  
			i4GamCurveRGB[SV_RGB_R][i] = i4GamCurveRGB[SV_RGB_R][i-1];																										  
		}																																				  
		if ((i4GamCurveRGB[SV_RGB_G][i] < i4GamCurveRGB[SV_RGB_G][i-1]) || (i4GamCurveRGB[SV_RGB_G][i]==0)) 																				  
		{																																				  
			i4GamCurveRGB[SV_RGB_G][i] = i4GamCurveRGB[SV_RGB_G][i-1];																										  
		}																																				  
		if ((i4GamCurveRGB[SV_RGB_B][i] < i4GamCurveRGB[SV_RGB_B][i-1]) || (i4GamCurveRGB[SV_RGB_B][i]==0)) 																				  
		{																																				  
			i4GamCurveRGB[SV_RGB_B][i] = i4GamCurveRGB[SV_RGB_B][i-1];																										  
		}																																				  
																																						  
		u2GammaDecodedTable[SV_RGB_R][i] = (UINT16)(i4GamCurveRGB[SV_RGB_R][i]);																									  
		u2GammaDecodedTable[SV_RGB_G][i] = (UINT16)(i4GamCurveRGB[SV_RGB_G][i]);																									  
		u2GammaDecodedTable[SV_RGB_B][i] = (UINT16)(i4GamCurveRGB[SV_RGB_B][i]);																									  
		wHwGammaCurve[SV_RGB_R][i] = (UINT16)(i4GamCurveRGB[SV_RGB_R][i]);																										  
		wHwGammaCurve[SV_RGB_G][i] = (UINT16)(i4GamCurveRGB[SV_RGB_G][i]);																										  
		wHwGammaCurve[SV_RGB_B][i] = (UINT16)(i4GamCurveRGB[SV_RGB_B][i]);	
	}			

	vDrvSetGammaWritePingPongFlag(SV_TRUE);
	
	bBootUp = SV_FALSE;
	bGammaInit = SV_TRUE;
	DRVCUST_SetGammaRemapForceLoad(SV_ON); //ForceGammaRemmap
	if(u2TarCtlPos != NULL)
	{
		x_mem_free(u2TarCtlPos);
	}
	if(i4GamCurveRGB != NULL)
	{
		x_mem_free(i4GamCurveRGB);
	}
}


UINT8 DRVCUST_GET_CTMode(void)
{
      return TRUE;
}


void DRVCUST_SET_YGAMMA(UINT32 i1Mode)
{
    EXTERN void vDrvADLSetYGamma(UINT8 bIndex);
    
    switch((INT8)i1Mode)
    {
        case -3:
            vDrvADLSetYGamma(9);
            break;
        case -2:
            vDrvADLSetYGamma(8);
            break;

        case -1:
            vDrvADLSetYGamma(7);

            break;
        case 1:
            vDrvADLSetYGamma(1);
            break;

        case 2:
            vDrvADLSetYGamma(3);
            break;
        case 3:
            vDrvADLSetYGamma(5);
            break;

        default:
            vDrvADLSetYGamma(0);
            break;
    }
	
	if (bi1GammaOfst != i1Mode)
		{		 
			bi1GammaOfst = i1Mode;
			DRVCUST_SendEvent(E_CUST_PIC_SETTING_CHANGE, 0);
		}

    return;
}

void DRVCUST_AutoColorTempUpdate(AUTO_COLORTEMP_SETS_INFO_T *aCTInfo)
{
	if(stCTInfo.ui1CTIndex != aCTInfo->ui1CTIndex)
	{
	    stCTInfo.ui1CTIndex = aCTInfo->ui1CTIndex;
		DRVCUST_SendEvent(E_CUST_PIC_SETTING_CHANGE, 0);
	}
        DRVCUST_SET_GAMMA();
    
}

void DRVCUST_MMAPProc(void)
{
    if (sMMAppInfo.u1AppType == 0xFF) /*Pretend for Netflix App */
    {
        //Update new QtyTbl
        bApiVideoProc(SV_VP_MAIN, PE_ARG_3D_NR);
        bApiVideoProc(SV_VP_MAIN, PE_ARG_NR);
        bApiVideoProc(SV_VP_MAIN, PE_ARG_MPEG_NR);
        bApiVideoProc(SV_VP_MAIN, PE_ARG_SHARPNESS);
    }
}

void DRVCUST_GetLcdimPanelOrder(UINT8 *u1PanelOrder, UINT8 u1BlockNum)
{
	UINT8 bIndex;
	UINT16 i;
    bIndex = GetCurrentPanelIndex();

    if(bIndex == PANEL_EPI_LGDV12GIPFHD120)          // 1 * 12, LGD protocal
    {
        UINT8 u1PanelOrderCust[12] = {0, 2, 4, 6, 8, 10, 11, 9, 7, 5, 3, 1};      // MTK IC HW Sequence            
        x_memcpy(u1PanelOrder, u1PanelOrderCust, sizeof(u1PanelOrderCust));
    }   
    else if(bIndex == PANEL_LG_47_EUH_PR)          // 8 * 2, AMS protocal
    {
        UINT8 u1PanelOrderCust[16] = {0, 15, 1, 14, 2, 13, 3, 12, 4, 11, 5, 10, 6, 9, 7, 8};      // MTK IC HW Sequence
        x_memcpy(u1PanelOrder, u1PanelOrderCust, sizeof(u1PanelOrderCust));
    }       
    else
    {
        for(i = 0; i < u1BlockNum; i++)
        {
            u1PanelOrder[i] = i;
        }
    }        
    
    LOG(0, "Panel Order = ");
    
    for(i = 0; i < u1BlockNum; i++)
    {
        LOG(0, "%d  ", u1PanelOrder[i]);
    }    
}

void DRVCUST_GetLcdimPanelDimGain(UINT8 *u1PanelDimGain, UINT8 u1BlockNum)
{
	UINT8 bIndex;
	UINT16 i;
    bIndex = GetCurrentPanelIndex();

    if(bIndex == PANEL_EPI_LGDV12GIPFHD120)          // 1 * 12, LGD protocal
    {
        UINT8 u1PanelDimGainCust[12] = {0x98, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x98};
        x_memcpy(u1PanelDimGain, u1PanelDimGainCust, sizeof(u1PanelDimGainCust));
    }
    else if(bIndex == PANEL_LG_47_EUH_PR)          // 8 * 2, AMS protocal
    {
        UINT8 u1PanelDimGainCust[16] = {0xFF, 0xFF, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xFF, 0xFF};
        x_memcpy(u1PanelDimGain, u1PanelDimGainCust, sizeof(u1PanelDimGainCust));
    }       
    else
    {
        for(i = 0; i < u1BlockNum; i++)
        {
            u1PanelDimGain[i] = 0x80;   //0x80 means gain 1
        }
    }        
    
    LOG(0, "Panel Dim Gain = ");
    
    for(i = 0; i < u1BlockNum; i++)
    {
        LOG(0, "%d  ", u1PanelDimGain[i]);
    }    
}
UINT32 DRVCUST_DemoRegion(void)
{  
    return DEMO_PQ_ON_RIGHT;
}

UINT32 DRVCUST_DemoModule(void)
{
    return (DEMO_3DNR | DEMO_TDSHARP | DEMO_COLOR | DEMO_ECTI );
}

void DRVCUST_SetDemoMode(E_CUST_DEMO_MODE eDemoMode, E_CUST_DEMO_PATTERN eDemoPattern, UINT32 u4DemoOption)
{ 
	UINT8 u1DemoModule = 0;
	UINT8 u1DemoEffect = 0;

	Region rDummyRegion;
    //support only Split demo.
    rDummyRegion.u1OnOff = SV_ON;
    rDummyRegion.wHEnd = 200;
    rDummyRegion.wHStart=0;
    rDummyRegion.wVEnd = 200;
    rDummyRegion.wVStart = 0;

	if(eDemoMode == E_CUST_DEMO_MODE_OFF)
	{
		u1DemoModule = 0;
		u1DemoEffect = DEMO_PQ_OFF;
	}
	else if(eDemoMode == E_CUST_DEMO_MODE_EFFECT_OFF)
	{
		u1DemoModule = 0;
		u1DemoEffect = DEMO_PQ_OFF;
	}
	else if(eDemoMode == E_CUST_DEMO_MODE_X_REALITY_PRO)
	{
		u1DemoModule = DEMO_HSHARP | DEMO_2DNR | DEMO_3DNR | DEMO_TDSHARP | DEMO_COLOR | DEMO_ECTI ;
		
		if(eDemoPattern == E_CUST_DEMO_PATTERN_SPLIT1_L_ON)
		{
			u1DemoEffect = DEMO_PQ_ON_LEFT;
		}
		else if(eDemoPattern == E_CUST_DEMO_PATTERN_SPLIT1_R_ON)
		{
			u1DemoEffect = DEMO_PQ_ON_RIGHT;
		}
		else if(eDemoPattern == E_CUST_DEMO_PATTERN_FULL_ON)
		{
			u1DemoEffect = DEMO_PQ_OFF;
		}
		else if(eDemoPattern == E_CUST_DEMO_PATTERN_FULL_OFF)
		{
			u1DemoEffect = DEMO_PQ_OFF;
		}
		else
		{
			u1DemoEffect = DEMO_PQ_OFF;
		}
	}
	else if(eDemoMode == E_CUST_DEMO_MODE_X_REALITY_PRO2)
	{
		u1DemoModule = DEMO_HSHARP | DEMO_2DNR | DEMO_3DNR | DEMO_TDSHARP | DEMO_ECTI ;
		
		if(eDemoPattern == E_CUST_DEMO_PATTERN_SPLIT1_L_ON)
		{
			u1DemoEffect = DEMO_PQ_ON_LEFT;
		}
		else if(eDemoPattern == E_CUST_DEMO_PATTERN_SPLIT1_R_ON)
		{
			u1DemoEffect = DEMO_PQ_ON_RIGHT;
		}
		else if(eDemoPattern == E_CUST_DEMO_PATTERN_FULL_ON)
		{
			u1DemoEffect = DEMO_PQ_OFF;
		}
		else if(eDemoPattern == E_CUST_DEMO_PATTERN_FULL_OFF)
		{
			u1DemoEffect = DEMO_PQ_OFF;
		}
		else
		{
			u1DemoEffect = DEMO_PQ_OFF;
		}
	}
	else if(eDemoMode == E_CUST_DEMO_MODE_THRILUMINOUS)
	{
		u1DemoModule = 0;
		u1DemoEffect = DEMO_PQ_OFF;
	}
	else
	{
		u1DemoModule = 0;
		u1DemoEffect = DEMO_PQ_OFF;
	}

	vApiVideoDemoMode(u1DemoEffect, rDummyRegion, u1DemoModule);

	if(eDemoMode == E_CUST_DEMO_MODE_THRILUMINOUS)
	{
		if(eDemoPattern == E_CUST_DEMO_PATTERN_FULL_OFF)
		{
			vDrvPreSharpOnOff(SV_VP_MAIN, SV_ON);
    		vDrvPostSharpOnOff(SV_ON);
			vDrvCTIROnOff(SV_ON);
			vDrvSCEAllOnOff(SV_OFF);
			vDrvNRSet2DNRBNROnOff(SV_ON);
			vDrvNRSet2DNRMNROnOff(SV_ON);
			vDrvNRSet2DNRSNROnOff(SV_ON);
			vDrvNRSet3DNROnOff(SV_ON);
			
		}
		else
		{
			vDrvPreSharpOnOff(SV_VP_MAIN, SV_ON);
    		vDrvPostSharpOnOff(SV_ON);
			vDrvCTIROnOff(SV_ON);
			vDrvSCEAllOnOff(SV_ON);
			vDrvNRSet2DNRBNROnOff(SV_ON);
			vDrvNRSet2DNRMNROnOff(SV_ON);
			vDrvNRSet2DNRSNROnOff(SV_ON);
			vDrvNRSet3DNROnOff(SV_ON);
		}
	}
	else if(eDemoMode == E_CUST_DEMO_MODE_X_REALITY_PRO)
	{
		if(eDemoPattern == E_CUST_DEMO_PATTERN_FULL_OFF)
		{
			vDrvPreSharpOnOff(SV_VP_MAIN, SV_OFF);
    		vDrvPostSharpOnOff(SV_OFF);
			vDrvCTIROnOff(SV_OFF);
			vDrvSCEAllOnOff(SV_OFF);
			vDrvNRSet2DNRBNROnOff(SV_OFF);
			vDrvNRSet2DNRMNROnOff(SV_OFF);
			vDrvNRSet2DNRSNROnOff(SV_OFF);
			vDrvNRSet3DNROnOff(SV_OFF);
		}
		else
		{
			vDrvPreSharpOnOff(SV_VP_MAIN, SV_ON);
    		vDrvPostSharpOnOff(SV_ON);
			vDrvCTIROnOff(SV_ON);
			vDrvSCEAllOnOff(SV_ON);
			vDrvNRSet2DNRBNROnOff(SV_ON);
			vDrvNRSet2DNRMNROnOff(SV_ON);
			vDrvNRSet2DNRSNROnOff(SV_ON);
			vDrvNRSet3DNROnOff(SV_ON);
		}
	}
	else if(eDemoMode == E_CUST_DEMO_MODE_X_REALITY_PRO2)
	{
		if(eDemoPattern == E_CUST_DEMO_PATTERN_FULL_OFF)
		{
			vDrvPreSharpOnOff(SV_VP_MAIN, SV_OFF);
    		vDrvPostSharpOnOff(SV_OFF);
			vDrvCTIROnOff(SV_OFF);
			vDrvSCEAllOnOff(SV_ON);
			vDrvNRSet2DNRBNROnOff(SV_OFF);
			vDrvNRSet2DNRMNROnOff(SV_OFF);
			vDrvNRSet2DNRSNROnOff(SV_OFF);
			vDrvNRSet3DNROnOff(SV_OFF);
		}
		else
		{
			vDrvPreSharpOnOff(SV_VP_MAIN, SV_ON);
    		vDrvPostSharpOnOff(SV_ON);
			vDrvCTIROnOff(SV_ON);
			vDrvSCEAllOnOff(SV_ON);
			vDrvNRSet2DNRBNROnOff(SV_ON);
			vDrvNRSet2DNRMNROnOff(SV_ON);
			vDrvNRSet2DNRSNROnOff(SV_ON);
			vDrvNRSet3DNROnOff(SV_ON);
		}
	}
	else
	{
			vDrvPreSharpOnOff(SV_VP_MAIN, SV_ON);
    		vDrvPostSharpOnOff(SV_ON);
			vDrvCTIROnOff(SV_ON);
			vDrvSCEAllOnOff(SV_ON);
			vDrvNRSet2DNRBNROnOff(SV_ON);
			vDrvNRSet2DNRMNROnOff(SV_ON);
			vDrvNRSet2DNRSNROnOff(SV_ON);
			vDrvNRSet3DNROnOff(SV_ON);
	}


	if(eDemoMode == E_CUST_DEMO_MODE_MOTION_FLOW)
	{
		if(eDemoPattern == E_CUST_DEMO_PATTERN_SPLIT1_L_ON)
		{
			MJC_SetDemo(MJC_DEMO_SIDEBYSIDE, MJC_INTP_FULL, MJC_INTP_OFF);
			//MJC_SetDemoBar(SV_ON, 128, 16, 128);
		}
		else if(eDemoPattern == E_CUST_DEMO_PATTERN_SPLIT1_R_ON)
		{
			MJC_SetDemo(MJC_DEMO_SIDEBYSIDE, MJC_INTP_OFF, MJC_INTP_FULL);
			//MJC_SetDemoBar(SV_ON, 128, 16, 128);
		}
		else if(eDemoPattern == E_CUST_DEMO_PATTERN_FULL_ON)
		{
			MJC_SetDemo(MJC_DEMO_SIDEBYSIDE, MJC_INTP_FULL, MJC_INTP_FULL);
			//MJC_SetDemoBar(SV_OFF, 128, 16, 128);
		}
		else if(eDemoPattern == E_CUST_DEMO_PATTERN_FULL_OFF)
		{
			MJC_SetDemo(MJC_DEMO_SIDEBYSIDE, MJC_INTP_OFF, MJC_INTP_OFF);
			//MJC_SetDemoBar(SV_OFF, 128, 16, 128);
		}
		else
		{
			MJC_SetDemo(MJC_DEMO_OFF, MJC_INTP_FULL, MJC_INTP_FULL);
			//MJC_SetDemoBar(SV_OFF, 128, 16, 128);
		}
	}

}

void DRVCUST_PqModeChange(UINT8 bPath)
{
    UINT32 i;
    
    
    
    for (i=0; i < (UINT8)PE_ARG_NS; i++)
    {
        switch (i)
        {
            // List all the quality items that do not update after mode change done.
            //  the back light is not relative to video timing, nor main/pip change.
            case PE_ARG_ADAPTIVE_BACK_LIGHT:
            case PE_ARG_BACK_LIGHT_LVL:
			case PE_ARG_R_GAIN:
            case PE_ARG_G_GAIN:
            case PE_ARG_B_GAIN:
            case PE_ARG_R_OFFSET:
            case PE_ARG_G_OFFSET:
            case PE_ARG_B_OFFSET:
			case PE_ARG_GAMMA:
                break;
            default:
                UNUSED(bApiVideoProc(bPath, (PE_ARG_TYPE)i));
                break;
        }
    }
    
}

UINT8 DRVCUST_SeamlessTimingRemaping(UINT8 bPath,UINT8 u1SrcTiming)
{
	UINT8 bAppType = VDP_GetPlayMode(bPath);
	UINT8 bIsIterlace = bDrvVideoIsSrcInterlace(bPath);
	UINT8 bFameRate = bDrvVideoGetRefreshRate(bPath);
    VDP_SEAMLESS_INFO_T tb2rVrmInfo;
	//add for seamless case, to load different QTY table according to real src width/height 
	//roughly remapping the timing according customer timing group request.
    if(VDP_SET_ERROR != VDP_GetSeamlessInfo(bPath, &tb2rVrmInfo))
    {
    	//Printf("Robin: width=%d, height=%d----\n", tb2rVrmInfo.u4SrcWidth, tb2rVrmInfo.u4SrcHeight);
    	if(tb2rVrmInfo.u4SrcHeight <=480)
    	{
    		if(bIsIterlace == SV_TRUE)
    		{
				if(bAppType == FBM_FBG_DTV_MODE)
					u1SrcTiming = SOURCE_TYPE_TIMING_DTV_SD_I_60;
				else
					u1SrcTiming = SOURCE_TYPE_TIMING_MM_SD_I;
    		}
			else
			{
				if(bAppType == FBM_FBG_DTV_MODE)
					u1SrcTiming = SOURCE_TYPE_TIMING_DTV_SD_P_60;
				else
					u1SrcTiming = SOURCE_TYPE_TIMING_MM_SD_P;
			}
    	}
		else
		if(tb2rVrmInfo.u4SrcHeight <=576)
		{
    		if(bIsIterlace == SV_TRUE)
    		{
				if(bAppType == FBM_FBG_DTV_MODE)
					u1SrcTiming = SOURCE_TYPE_TIMING_DTV_SD_I_50;
				else
					u1SrcTiming = SOURCE_TYPE_TIMING_MM_SD_I;
    		}
			else
			{
				if(bAppType == FBM_FBG_DTV_MODE)
					u1SrcTiming = SOURCE_TYPE_TIMING_DTV_SD_P_50;
				else
					u1SrcTiming = SOURCE_TYPE_TIMING_MM_SD_P;
			}
		}
		else
		if(tb2rVrmInfo.u4SrcHeight <=720)
		{
			if(bAppType == FBM_FBG_DTV_MODE)
				u1SrcTiming = SOURCE_TYPE_TIMING_DTV_720P_60;
			else
				u1SrcTiming = SOURCE_TYPE_TIMING_MM_720P_HD;
		}
		else
		if((tb2rVrmInfo.u4SrcHeight <=1080)&&(tb2rVrmInfo.u4SrcWidth<=1920))
		{
    		if(bIsIterlace == SV_TRUE)
    		{
				if(bAppType == FBM_FBG_DTV_MODE)
					u1SrcTiming = SOURCE_TYPE_TIMING_DTV_1080I_60;
				else
					u1SrcTiming = SOURCE_TYPE_TIMING_MM_1080I_60;
    		}
			else
			{
				if(bAppType == FBM_FBG_DTV_MODE)
					u1SrcTiming = SOURCE_TYPE_TIMING_DTV_1080P_60;
				else
					u1SrcTiming = SOURCE_TYPE_TIMING_MM_1080I_60;
			}
		}
		else
		{
			if((bFameRate == 50) || (bFameRate == 60))
			{
				if(bAppType == FBM_FBG_DTV_MODE)
					u1SrcTiming = SOURCE_TYPE_TIMING_DTV_2160P_60;
				else
					u1SrcTiming = SOURCE_TYPE_TIMING_MM_2160P_60;
			}
			else
			{
				if(bAppType == FBM_FBG_DTV_MODE)
					u1SrcTiming = SOURCE_TYPE_TIMING_DTV_2160P_30;
				else
					u1SrcTiming = SOURCE_TYPE_TIMING_MM_2160P_30;
			}
		}
    }
	return u1SrcTiming;
}
void DRVCUST_SendEvent(E_CUST_EVENT eCustEvent, UINT8 u1Option)
{
    if (sony_be_func && sony_be_func->be_send_event_func)
    {
        sony_be_func->be_send_event_func(eCustEvent, u1Option);
    }
    
    if (sony_pq_func && sony_pq_func->pq_send_event_func)
    {
        sony_pq_func->pq_send_event_func(eCustEvent, u1Option);
    }

	LOG(2, "DRVCUST_SendEvent  eCustEvent = %x u1Option = %d\n",eCustEvent, u1Option);

}

void DRVCUST_SendEcsCommand(UINT8* pData, UINT32 u4Size)
{
    if (sony_be_func && sony_be_func->be_send_ecs_func)
    {
        sony_be_func->be_send_ecs_func(pData, u4Size);
    }
    
    if (sony_pq_func && sony_pq_func->pq_send_ecs_func)
    {
        sony_pq_func->pq_send_ecs_func(pData, u4Size);
    }
}

void DRVCUST_SetBEGeneralData(UINT8* pData, UINT8 u1Size)
{
    if (sony_be_gen_func && sony_be_gen_func->be_set_general_data)
    {
        sony_be_gen_func->be_set_general_data(pData, u1Size);
    }
}

void DRVCUST_GetBEGeneralData(UINT8* pData, UINT8* u1Size)
{
    if (sony_be_gen_func && sony_be_gen_func->be_get_general_data)
    {
        sony_be_gen_func->be_get_general_data(pData, u1Size);
    }
}

void DRVCUST_SetColorPickData(UINT16 u1X, UINT16 u1Y)
{
    if (sony_be_gen_func && sony_be_gen_func->be_set_color_pickup_data)
    {
        sony_be_gen_func->be_set_color_pickup_data(u1X, u1Y);
    }
}

void DRVCUST_GetColorPickData(UINT16* pRed, UINT16* pGreen, UINT16* pBlue)
{
    if (sony_be_gen_func && sony_be_gen_func->be_get_color_pickup_data)
    {
        sony_be_gen_func->be_get_color_pickup_data(pRed, pGreen, pBlue);
    }
}

void DRVCUST_SetBEGenParam(UINT32 u4Type, UINT8 u1Data[255], UINT8 u1Size)
{
    LOG(5,"DRVCUST_SetBEGenParam, type:0x%x\n", u4Type);
    if (sony_be_gen_func && sony_be_gen_func->be_set_general_param)
    {
        sony_be_gen_func->be_set_general_param(u4Type, u1Data, u1Size);
    }
}
void DRVCUST_GetBEGenParam(UINT32 u4Type, UINT8* u1Data, UINT8* u1Size)
{
	if (sony_be_gen_func && sony_be_gen_func->be_get_general_param)
	{
		sony_be_gen_func->be_get_general_param(u4Type, u1Data, u1Size);
	}
}
void DRVCUST_SetPQGenParam(UINT32 u4Type, UINT8 u1Data[255], UINT8 u1Size)
{
    LOG(5,"DRVCUST_SetPQGenParam, type:0x%x\n", u4Type);
	if (sony_pq_gen_func && sony_pq_gen_func->pq_set_general_param)
	{
		sony_pq_gen_func->pq_set_general_param(u4Type, u1Data, u1Size);
	}
}
void DRVCUST_GetPQGenParam(UINT32 u4Type, UINT8* u1Data, UINT8* u1Size)
{
	if (sony_pq_gen_func && sony_pq_gen_func->pq_get_general_param)
	{
		sony_pq_gen_func->pq_get_general_param(u4Type, u1Data, u1Size);
	}
}

void DRVCUST_SetGenParam(UINT32 u4Type, UINT8 u1Data[255], UINT8 u1Size)
{
    LOG(5,"DRVCUST_SetGenParam, type:0x%x\n", u4Type);
    switch (u4Type) 
    {
        case 0x15:
            /* 0x15 -> PIP Status */
            DRVCUST_SetIsPIP(u1Data[0]);
            break;
        default:
            break;
    }
}

void DRVCUST_PanelPowerStateToBe(BOOL bOnOff)
{
    if (sony_be_func && sony_be_func->be_panel_power_func)
    {
        sony_be_func->be_panel_power_func(bOnOff);
    }
}

void DRVCUST_GetWBGammaTable(UINT8 u1Index, UINT16 * pData)
{
	if(u1Index > 4)
	{
		LOG(0, "Wrong WB Index \n");
	}
	else
	{
		EEPROM_Read((UINT64)((EEP_WB_LUT_ADJ_G0_START + GAMMA_BYTES * u1Index)), (UPTR)pData, GAMMA_BYTES);
	}
	LOG(2, "DRVCUST_GetWBGammaTable \n");
}
void DRVCUST_SetWBGammaTable(UINT8 u1Index, UINT16 * pData)
{
	if(u1Index > 4)
	{
		LOG(0, "Wrong WB Index \n");
	}
	else if(pData == NULL)
	{
		LOG(0, "Set Array is NULL \n");
	}
	else
	{
		DRVCUST_DoubleEepromWrite((UINT64)((EEP_WB_LUT_ADJ_G0_START + GAMMA_BYTES * u1Index)), (UPTR)pData, GAMMA_BYTES);
	}
	LOG(2, "DRVCUST_SetWBGammaTable \n");
}

UINT8 DRVCUST_SuperGameMode(UINT32 u4VdpId)
{
    BOOL ret = SV_ON;
    VRM_INFO_T* infoVRM;
    UINT8 u1InFR, u1OutFR;
    VDP_REGION_T rOutRegion;
    UCHAR ucFull;

	ret = SV_ON;//just for converity
#ifdef CC_MAPLE_CUST_DRV
    CUST_SCREEN_SETTING_T rScreenInfoFromAP;
#endif

    // 1. game mode
    if (SRM_IsGameMode(u4VdpId) == 0)
    {
        ret = SV_OFF;
    }
    
    // 2. Not flip-mirror
#ifdef CC_FLIP_MIRROR_SUPPORT
    if (u1GetFlipMirrorConfig() != 0)
    {
        ret = SV_OFF;
    }
#endif

    // 3. Not PIP/POP
    if (SRM_IsSubVideoDisplay() != 0)
    {
        ret = SV_OFF;
    }
    
    // 4. Input framerate 60  
    if (bDrvVideoGetRefreshRate(u4VdpId) != 60)
    {
        ret = SV_OFF;
    }
        
    // 5. Progressive
    if (bDrvVideoIsSrcInterlace(u4VdpId) != 0)
    {
        ret = SV_OFF;
    }
    
    // 6. CE timing
    if (fgApiVideoIsVgaTiming(u4VdpId) != 0)
    {
        ret = SV_OFF;
    }
    
    // 7. Write speed >= Read speed
    infoVRM = VRMGetVRMInfo(SV_VP_MAIN, VRM_MODULE_OMUX);
    u1InFR  = infoVRM->u2FrameRate;

    infoVRM = VRMGetVRMInfo(SV_VP_MAIN, VRM_MODULE_MIXER);
    u1OutFR = infoVRM->u2FrameRate;
    if (u1InFR < u1OutFR)
    {
        ret = SV_OFF;
    }

    // 9. No black on bottom
    VDP_GetOutRegion(u4VdpId, &ucFull, &rOutRegion);
    if (ucFull != 0 && (rOutRegion.u4Y + rOutRegion.u4Height) < VDP_MAX_REGION_HEIGHT)
    {
        ret = SV_OFF;
    }

#ifdef CC_MAPLE_CUST_DRV
    BEPQ_AP_Get_WideMode_Setting(&rScreenInfoFromAP);

    // 8. Wide mode "Full" or "Normal"
    if ((rScreenInfoFromAP.eWideMode != E_CUST_WIDE_MODE_FULL) &&( rScreenInfoFromAP.eWideMode != E_CUST_WIDE_MODE_NORMAL))
    {
        ret = SV_OFF;
    }

    // 10. Display area "Full Pixel" or "+1"
    if ((rScreenInfoFromAP.eDisplayArea != E_CUST_DISPLAY_AREA_FULL) && (rScreenInfoFromAP.eDisplayArea != E_CUST_DISPLAY_AREA_NORMAL))
    {
        ret = SV_OFF;
    }
#endif

    // 11. Vsync lock
    return ret;
}

// SONY power consumptaion control
#ifdef CC_PowerCons_Ctrl

#define PowerConsCtrl_ISSUE_DEBUG_MSG 1
static UINT8 volume_setting;
static BOOL speaker_unmute;
static BOOL mhl_use;
static BOOL lnb_use;
static BOOL ci_use;

UINT8 C_BL_POWER_LIMIT=255;

//HANDLE_T _hIRLedCtrlTimer = NULL_HANDLE;
HANDLE_T _hPowerConsCtrlMsgQue = NULL_HANDLE;
HANDLE_T _hPowerConsCtrlHandle = NULL_HANDLE;
  
void DRVCUST_PowerConsCtrl(void)
{
    UINT16 POWER_CONS_TOTAL_MAX;
	UINT16 POWER_CONS_TOTAL_TYP;
	UINT16 POWER_CONS_AUDIO_MAX;
	UINT16 POWER_CONS_AUDIO_TYP;
	UINT16 bl_power_limit_max;
	UINT16 bl_power_limit_TYP;
	UINT8 Model_ID=0;
	//Check model ID based on Option bit

	//Get related data from data table

	//start
	 if(power_cons_data_table[Model_ID].POWER_CONS_CTL_ON==1)
	{
	    //Check argument stability about 500msec
		x_thread_delay(500);
		//Calculate audio power consumption	
		//1.for maximum
		POWER_CONS_AUDIO_MAX=power_cons_data_table[Model_ID].AUDIO_PWR_OFFSET_MAX+(((UINT32)((power_cons_data_table[Model_ID].AUDIO_PWR_LIMIT_UP_MAX - power_cons_data_table[Model_ID].AUDIO_PWR_OFFSET_MAX)*volume_setting*speaker_unmute))/power_cons_data_table[Model_ID].AUDIO_VOLUME_TH_MAX);
		if (POWER_CONS_AUDIO_MAX > power_cons_data_table[Model_ID].AUDIO_PWR_LIMIT_UP_MAX) 
		{
			POWER_CONS_AUDIO_MAX = power_cons_data_table[Model_ID].AUDIO_PWR_LIMIT_UP_MAX;
		}
		if (POWER_CONS_AUDIO_MAX < power_cons_data_table[Model_ID].AUDIO_PWR_LIMIT_LOW_MAX) 
		{
			POWER_CONS_AUDIO_MAX = power_cons_data_table[Model_ID].AUDIO_PWR_LIMIT_LOW_MAX;
		}
		//2.for typical
		POWER_CONS_AUDIO_TYP=power_cons_data_table[Model_ID].AUDIO_PWR_OFFSET_TYP+(((UINT32)((power_cons_data_table[Model_ID].AUDIO_PWR_LIMIT_UP_TYP - power_cons_data_table[Model_ID].AUDIO_PWR_OFFSET_TYP)*volume_setting*speaker_unmute))/power_cons_data_table[Model_ID].AUDIO_VOLUME_TH_TYP);

		if (POWER_CONS_AUDIO_TYP > power_cons_data_table[Model_ID].AUDIO_PWR_LIMIT_UP_TYP) 
		{
			POWER_CONS_AUDIO_TYP = power_cons_data_table[Model_ID].AUDIO_PWR_LIMIT_UP_TYP;
		}
		if (POWER_CONS_AUDIO_TYP < power_cons_data_table[Model_ID].AUDIO_PWR_LIMIT_LOW_TYP) 
		{
			POWER_CONS_AUDIO_TYP = power_cons_data_table[Model_ID].AUDIO_PWR_LIMIT_LOW_TYP;
		}
		//Calculate total power consumptio
		//1.for maximum
		POWER_CONS_TOTAL_MAX = power_cons_data_table[Model_ID].BL_POWER_WATT_MAX+ POWER_CONS_AUDIO_MAX+ mhl_use*static_power_cons_data_table[0].POWER_CONS_MHL_MAX+ lnb_use * static_power_cons_data_table[0].POWER_CONS_LNB_MAX+ ci_use * static_power_cons_data_table[0].POWER_CONS_CI_MAX+ power_cons_data_table[Model_ID].POWER_CONS_BASE_MAX;
		//2.for typical
		POWER_CONS_TOTAL_TYP = power_cons_data_table[Model_ID].BL_POWER_WATT_TYP+ POWER_CONS_AUDIO_TYP+ mhl_use*static_power_cons_data_table[0].POWER_CONS_MHL_TYP+ lnb_use * static_power_cons_data_table[0].POWER_CONS_LNB_TYP+ ci_use * static_power_cons_data_table[0].POWER_CONS_CI_TYP+ power_cons_data_table[Model_ID].POWER_CONS_BASE_TYP;

		//Calculate C_BL_POWER_LIMIT
		//1.for maximum
        if (POWER_CONS_TOTAL_MAX > power_cons_data_table[Model_ID].POWER_CONS_LIMIT_MAX) 
		{
			bl_power_limit_max = POWER_CONS_TOTAL_MAX - power_cons_data_table[Model_ID].POWER_CONS_LIMIT_MAX;
        }
		else
		{
		    bl_power_limit_max = 0;
		}
		//2.for typical
        if (POWER_CONS_TOTAL_TYP > power_cons_data_table[Model_ID].POWER_CONS_LIMIT_TYP) 
		{
			bl_power_limit_TYP = POWER_CONS_TOTAL_TYP - power_cons_data_table[Model_ID].POWER_CONS_LIMIT_TYP;
        }
		else
		{
		    bl_power_limit_TYP = 0;
		}
        //Lower limit of bl_power_limit_typ
        if((power_cons_data_table[Model_ID].BL_POWER_WATT_TYP - bl_power_limit_TYP) < ((UINT32)(power_cons_data_table[Model_ID].BL_POWER_WATT_TYP * power_cons_data_table[Model_ID].BL_POWER_LIMIT_LOWER))/ 255) 
		{
			bl_power_limit_TYP = power_cons_data_table[Model_ID].BL_POWER_WATT_TYP - ((UINT32)(power_cons_data_table[Model_ID].BL_POWER_WATT_TYP*power_cons_data_table[Model_ID].BL_POWER_LIMIT_LOWER))/255;
        }
		//Use bigger value of "bl_power_limit_max" and "bl_power_limit_typ"
		if(bl_power_limit_max > bl_power_limit_TYP) 
		{
			C_BL_POWER_LIMIT = (((UINT32)((power_cons_data_table[Model_ID].BL_POWER_WATT_MAX - bl_power_limit_max)*255))/power_cons_data_table[Model_ID].BL_POWER_WATT_MAX);
		}
		else
		{
			C_BL_POWER_LIMIT = (((UINT32)((power_cons_data_table[Model_ID].BL_POWER_WATT_TYP - bl_power_limit_TYP)*255))/power_cons_data_table[Model_ID].BL_POWER_WATT_TYP);
		}
		LOG(1,"DRVCUST_PowerConsCtrl C_BL_POWER_LIMIT==%d \n",C_BL_POWER_LIMIT);
		
	}
    else
	{
		C_BL_POWER_LIMIT=255;
	}
	DRVCUST_SendEvent(E_CUST_BL_POWER_LIMIT_CHANGE, 0);
}
void DRVCUST_PowerConsCtrlHandle(void)
{
     //Printf("PowerConsCtrlHandle \n");
	 DRVCUST_PowerConsCtrl();
}

static void DRVCUST_PowerConsCtrlMsgHandle(void *pvArg)
{
    UINT16 u2MsgIdx;
    PowerCons_Change_STATE rPowerConsCtrlMsg;
    
    while (1)
    {
        SIZE_T zMsgSize = sizeof(PowerCons_Change_STATE);
        INT32  i4MsgRet;
     
        i4MsgRet = x_msg_q_receive(&u2MsgIdx, &rPowerConsCtrlMsg, &zMsgSize,
                                   &_hPowerConsCtrlMsgQue, 1, X_MSGQ_OPTION_WAIT);
        if (i4MsgRet == OSR_OK)
        {
          DRVCUST_PowerConsCtrlHandle();
            //PowerConsCtrlHandle(rPowerConsCtrlMsg.Mute_State,rPowerConsCtrlMsg.MHL_State,rPowerConsCtrlMsg.LNB_State,rPowerConsCtrlMsg.CI_State,rPowerConsCtrlMsg.u1volume_set);
        }
    }
}

void DRVCUST_PowerConsCtrlResourceInit(void)
{
    if (_hPowerConsCtrlMsgQue == NULL_HANDLE)
    {
        VERIFY(x_msg_q_create(&_hPowerConsCtrlMsgQue, "PowerConsCtrlMsgQue", 
                              sizeof(PowerCons_Change_STATE), 8) == OSR_OK);
        
        // Create the Led state handle handle task
        if (x_thread_create(&_hPowerConsCtrlHandle, "PowerConsCtrlHandle",
                            0x800, DRVCUST_OptGet(eReleaseWatchdogPriority),
                            DRVCUST_PowerConsCtrlMsgHandle, 0, NULL) != OSR_OK)
        {
            Printf("\nError: Create Power consumption ctrl handle thread fail\n");
            x_msg_q_delete(_hPowerConsCtrlMsgQue);
            _hPowerConsCtrlMsgQue = NULL_HANDLE;
        }
    }
}

void DRVCUST_PowerConsCtrlTrigger(bool Mute_State,bool MHL_State,bool LNB_State,bool CI_State, UINT8 u1volume_set)
{
#if PowerConsCtrl_ISSUE_DEBUG_MSG
    LOG(1,"Power Consumption Ctrl Trigger %d %d %d %d %d\n", Mute_State, MHL_State,LNB_State,CI_State,u1volume_set);
#endif

    PowerCons_Change_STATE rPowerConsCtrlMsg;
    DRVCUST_PowerConsCtrlResourceInit();
    if (_hPowerConsCtrlMsgQue != NULL_HANDLE)
    {
        rPowerConsCtrlMsg.Mute_State = Mute_State;
		rPowerConsCtrlMsg.MHL_State = MHL_State;
		rPowerConsCtrlMsg.LNB_State = LNB_State;
		rPowerConsCtrlMsg.CI_State = CI_State;
		rPowerConsCtrlMsg.u1volume_set = u1volume_set;

        UNUSED(x_msg_q_send(_hPowerConsCtrlMsgQue, &rPowerConsCtrlMsg,
                            sizeof(PowerCons_Change_STATE), 1));
    }
}

extern BOOL ADAC_AmpEnableFlag(void);
void DRVCUST_PowerConsCtrlStatusCheck(void)
{
     UINT32 u4Vuale;
     BOOL ci_use_tmp;
	 UINT8 volume_set_tmp;
	 BOOL MHL_use_tmp=0;
	 BOOL speaker_unmute_tmp;
	 
    //check CI status change  if bit9 and bit10,  are zeor, it means CI connected
    #if defined(CC_MT5893) || defined(CC_MT5895)
	u4Vuale = IO_READ32(PCMCIA_BASE, POD_REG_PBUS_STS); //confirm this with CI owner
	#else
    u4Vuale=u4IO32Read4B(0xf001f00c);
	#endif
    if((u4Vuale & 0x0600)==0x00)
    	ci_use_tmp=1;
    else
		ci_use_tmp=0;
	if(ci_use_tmp!=ci_use)
	{
    	ci_use=ci_use_tmp;
		DRVCUST_PowerConsCtrlTrigger(speaker_unmute,mhl_use,lnb_use,ci_use,volume_setting);
    }
	
	//check MHL status change
#if defined(CC_MT5890)
	if(_bIsMhlDevice==1)
    	MHL_use_tmp=1;
    else
		MHL_use_tmp=0;
#else
	//check MHL status change
	if(fgMHL3GetMhlCableStatus())
    	MHL_use_tmp=1;
    else
		MHL_use_tmp=0;
#endif
  
	if(MHL_use_tmp!=mhl_use)
	{
    	mhl_use=MHL_use_tmp;
		DRVCUST_PowerConsCtrlTrigger(speaker_unmute,mhl_use,lnb_use,ci_use,volume_setting);
    }
	//check AMP mute
	if(ADAC_AmpEnableFlag()==1)
    	speaker_unmute_tmp=1;
    else
		speaker_unmute_tmp=0;

	if(speaker_unmute_tmp!=speaker_unmute)
	{
    	speaker_unmute=speaker_unmute_tmp;
		DRVCUST_PowerConsCtrlTrigger(speaker_unmute,mhl_use,lnb_use,ci_use,volume_setting);
    }
    //check volume change
	volume_set_tmp=AUD_DspGetMasterVolume(AUD_DEC_MAIN);
    if(volume_set_tmp!=volume_setting)
    {
    	volume_setting=volume_set_tmp;
		DRVCUST_PowerConsCtrlTrigger(speaker_unmute,mhl_use,lnb_use,ci_use,volume_setting);
    }
}

#endif

UINT8 u1SonyFactoryMode = 0;
static UINT8 fgSrsBypass=0;
void DRVCUST_SharpnessEnhanceEn(UINT8 u1Onoff)
{
    CRIT_STATE_T csState;
    csState = x_crit_start();

    VRM_INFO_T* vrmInfo1;
    VRM_INFO_T* vrmInfo2;
    UINT32  u4BlankCounter = 0;
    vrmInfo1 = VRMGetVRMInfo(SV_VP_MAIN, VRM_MODULE_MIXER);
    vrmInfo2 = VRMGetVRMInfo(SV_VP_MAIN, VRM_MODULE_OSTG);
    
    if (IS_IC_5890_ES1() || IS_IC_5890_MPS1())
    {
       u4BlankCounter = 1023 ;// Process for ES1 and MPS1
    }
    else 
    {
       u4BlankCounter = 4095 ;// Process for ES3 and later version
    }

    if((vrmInfo1->u2Width > 1920) || (vrmInfo1->u2Height > 1080) || (vrmInfo2->u2HTotal- vrmInfo2->u2Width > u4BlankCounter))
    {
        u1Onoff = SV_OFF;
    }
	
	if(u1SonyFactoryMode) /* For Sakura F-SW factory tune issue */
	{
		u1Onoff = SV_OFF;
	}
    fgSrsBypass = u1Onoff;
    vScpipUpdateDelay();    
    
    x_crit_end(csState);
}
UINT8 DRVCUST_GetSrsStatus(void)
{
    return( fgSrsBypass );
}

void DRVCUST_SRSOnOff(UINT8 u1Onoff)
{
    if(u1Onoff == SV_ON)/*Core Reset (delay match reset) before SRS enable */
    {
        vIO32WriteFldAlign(SRS_1, 0x1, C_SRS_BYPASS);
        
        vIO32WriteFldAlign(SRS_1, 0x2, C_SRS_RST_CTRL);
        vIO32WriteFldAlign(SRS_1, 0x0, C_SRS_RST_CTRL); 
    }
	
    vIO32WriteFldAlign(TDPROC_MISC_SRS, u1Onoff, LINEBUF_4SRS_EN);
    vIO32WriteFldAlign(YCPROC_SRS, u1Onoff, SRS_EN);
    vIO32WriteFldAlign(SRS_1, !u1Onoff, C_SRS_BYPASS);
  
    vIO32WriteFldAlign(SRS_1, !u1Onoff, C_SRS_DSR_ZERO_EN);
}

void DRVCUST_SharpnessEnhanceCFGInit(void)
{
    vIO32WriteFldAlign(SRS_0, 1, C_SRS_DRAM_RD_EN);
	vIO32WriteFldAlign(SRS_2, 1, C_SRS_DRAM_ADR_B_EN);
	vIO32WriteFldAlign(SRS_3, 0x38, C_LUT_A_DAT_CNT);
	vIO32WriteFldAlign(SRS_3, 1, C_SRS_4K1K_MASK_EN);
	
}

UINT16 DRVCUST_QtyUIMapping(UINT8 u1SrcTypTmg, UINT16 u2QtyItem, INT32 i4UiRangeMin, INT32 i4UiRangeDft,INT32 i4UiRangeMax,INT16 i2Min, INT16 i2Max, INT16 i2Dft, INT16 i2Cur)
{
    UINT16 ReturnVal = 0;

	if((u2QtyItem >= QUALITY_HSHARP_LOW) && (u2QtyItem <= QUALITY_HSHARP_HIGH_NEG))
	{
		if ((i4UiRangeMin == 0) && (i4UiRangeMax == 0))
		{
		    ReturnVal = i4UiRangeDft;
		}
		else
		{
		if(i2Dft > 50)
		{
			if(i2Cur < 50)
			{
				ReturnVal = (UINT16) ((i2Cur - 0) * (0x40 - MIN(0x40, i4UiRangeMin)) /
		                                (50 - 0) + i4UiRangeMin);
			}
			else
			{
				if (i2Cur > i2Dft)
		        {
		            // Prevent UI_max, UI_dft miss setting, and div=0.
		            if ((i2Max - i2Dft) <= 0)
		            {
		                ReturnVal = i4UiRangeDft;
		            }
		            else
		            {
		                ReturnVal = (UINT16) ((i2Cur - i2Dft) * (i4UiRangeMax - i4UiRangeDft) /
		                            (i2Max - i2Dft) + i4UiRangeDft);
		            }
		        }
		        // Get HW value for UI_current < UI_default.
		        else
		        {
		            // Prevent UI_dft, UI_min miss setting, and div=0.
		            if ((i2Dft - i2Min) <= 0)
		            {
		                ReturnVal = i4UiRangeDft;
		            }
		            else
		            {
		                ReturnVal = (UINT16) ((i2Cur - 50) * (MAX(0x40, i4UiRangeDft) - 0x40) /
		                                (i2Dft - 50) + 0x40);
		            }
		        }
			}
		}
		else
		{
			if(i2Cur < 50)
			{
				ReturnVal = (UINT16) ((i2Cur - 0) * (0x40 - MIN(0x40, i4UiRangeMin)) /
		                                (50 - 0) + i4UiRangeMin);
			}
			else
			{
				ReturnVal = (UINT16) ((i2Cur - 50) * (MAX(0x40, i4UiRangeMax) - 0x40) /
		                            (i2Max - 50) + 0x40);
			}
		}
		}
	}
	else if((u2QtyItem >= QUALITY_HSHARP_LOW_CORING) && (u2QtyItem <= QUALITY_CTIR_COR))
	{
		if ((i4UiRangeMin == 0) && (i4UiRangeMax == 0))
		{
		    ReturnVal = i4UiRangeDft;
		}
		else
		{
		if(i2Dft > 50)
		{
			if(i2Cur < 50)
			{
				ReturnVal = i4UiRangeMin;
			}
			else
			{
				if (i2Cur > i2Dft)
		        {
		            // Prevent UI_max, UI_dft miss setting, and div=0.
		            if ((i2Max - i2Dft) <= 0)
		            {
		                ReturnVal = i4UiRangeDft;
		            }
		            else
		            {
		                ReturnVal = (UINT16) ((i2Cur - i2Dft) * (i4UiRangeMax - i4UiRangeDft) /
		                            (i2Max - i2Dft) + i4UiRangeDft);
		            }
		        }
		        // Get HW value for UI_current < UI_default.
		        else
		        {
		            // Prevent UI_dft, UI_min miss setting, and div=0.
		            if ((i2Dft - i2Min) <= 0)
		            {
		                ReturnVal = i4UiRangeDft;
		            }
		            else
		            {
		                ReturnVal = (UINT16) ((i2Cur - 50) * (i4UiRangeDft - i4UiRangeMin) /
		                                (i2Dft - 50) + i4UiRangeMin);
		            }
		        }
			}
		}
		else
		{
			if(i2Cur < 50)
			{
				ReturnVal = i4UiRangeMin;
			}
			else
			{
				ReturnVal = (UINT16) ((i2Cur - 50) * (MAX(i4UiRangeMax, i4UiRangeMin) - i4UiRangeMin) /
		                            (i2Max - 50) + i4UiRangeMin);
			}
		}
	}
	}
	else if((u2QtyItem >= QUALITY_BITPLUS_IN_LCE_DRE_BITPLUS_AVG_FLT_EN) && (u2QtyItem <= QUALITY_BITPLUS_IN_LCE_C_LUMA_HIST_IN_SEL))
	{
        if (((i4UiRangeMin == 0) && (i4UiRangeMax == 0)) || (i2Cur == i2Dft))
        {
            ReturnVal = i4UiRangeDft;
        }
        else  //mapping as customer request
        {
            ReturnVal = (UINT16)((i2Cur - i2Min) * (i4UiRangeMax - i4UiRangeMin) /
                (i2Max-1 - i2Min) + i4UiRangeMin);
        }
    }
	else
	{

		 // Some qty_item does not need mapping, return default HW value.
		    // or UI_cur == UI_dft, return default HW value.
		    if (((i4UiRangeMin == 0) && (i4UiRangeMax == 0)) || (i2Cur == i2Dft))
		    {
		        ReturnVal = i4UiRangeDft;
		    }
		    else
		    {
		        // Get HW value for UI_current > UI_default.
		        if (i2Cur > i2Dft)
		        {
		            // Prevent UI_max, UI_dft miss setting, and div=0.
		            if ((i2Max - i2Dft) <= 0)
		            {
		                ReturnVal = i4UiRangeDft;
		            }
		            else
		            {
		                ReturnVal = (UINT16) ((i2Cur - i2Dft) * (i4UiRangeMax - i4UiRangeDft) /
		                            (i2Max - i2Dft) + i4UiRangeDft);
		            }
		        }
		        // Get HW value for UI_current < UI_default.
		        else
		        {
		            // Prevent UI_dft, UI_min miss setting, and div=0.
		            if ((i2Dft - i2Min) <= 0)
		            {
		                ReturnVal = i4UiRangeDft;
		            }
		            else
		            {
		                ReturnVal = (UINT16) ((i2Cur - i2Min) * (i4UiRangeDft - i4UiRangeMin) /
		                                (i2Dft - i2Min) + i4UiRangeMin);
		            }
		        }
		    }
		}
		return ReturnVal;
}

void DRVCUST_CalVideoColorMatrix(UINT8 bPath, UINT16 wBriValue, UINT16 wContValue,
                          UINT16 wSatValue, UINT16 wHueValue)
{

}

void DRVCUST_FrontDitherOnoff(UINT8 bOnOff)
{
	UINT8 u1Round, u1Rither, u1Edither, u1LFSR;

	u1Round = u1FrontDitherSetting & 0x1;
	u1Rither = (u1FrontDitherSetting >>1) & 0x1;
	u1Edither = (u1FrontDitherSetting >>2) & 0x1;
	u1LFSR = (u1FrontDitherSetting >>3) & 0x1;

	if(bOnOff)
	{
		vIO32WriteFldAlign(OS_DITHER_00, u1Round, DITHER_ROUND_EN);
		vIO32WriteFldAlign(OS_DITHER_00, u1Rither, RDITHER_EN);
		vIO32WriteFldAlign(OS_DITHER_00, u1Edither, EDITHER_EN);
		vIO32WriteFldAlign(OS_DITHER_00, u1LFSR, DITHER_LFSR_EN);
	}
	else
	{
		vIO32WriteFldAlign(OS_DITHER_00, 0x0, DITHER_ROUND_EN);
		vIO32WriteFldAlign(OS_DITHER_00, 0x0, RDITHER_EN);
		vIO32WriteFldAlign(OS_DITHER_00, 0x0, EDITHER_EN);
		vIO32WriteFldAlign(OS_DITHER_00, 0x0, DITHER_LFSR_EN);
	}

}

void DRVCUST_PostDitherOnOff(UINT8 bOnOff)
{
	UINT8 u1Round, u1Rither, u1Edither, u1LFSR;

	u1Round = u1PostDitherSetting & 0x1;
	u1Rither = (u1PostDitherSetting >>1) & 0x1;
	u1Edither = (u1PostDitherSetting >>2) & 0x1;
	u1LFSR = (u1PostDitherSetting >>3) & 0x1;

	if(bOnOff)
	{
		vIO32WriteFldAlign(OS_DITHER_03, u1Round, REG_ROUND_EN_POST);
		vIO32WriteFldAlign(OS_DITHER_03, u1Rither, REG_RDITHER_EN_POST);
		vIO32WriteFldAlign(OS_DITHER_03, u1Edither, REG_EDITHER_EN_POST);
		vIO32WriteFldAlign(OS_DITHER_03, u1LFSR, REG_LFSR_EN_POST);
	}
	else
	{
		vIO32WriteFldAlign(OS_DITHER_03, 0x0, REG_ROUND_EN_POST);
		vIO32WriteFldAlign(OS_DITHER_03, 0x0, REG_RDITHER_EN_POST);
		vIO32WriteFldAlign(OS_DITHER_03, 0x0, REG_EDITHER_EN_POST);
		vIO32WriteFldAlign(OS_DITHER_03, 0x0, REG_LFSR_EN_POST);
	}

}
void DRVCUST_SetOSTGModuleOnOff(UINT8 u1Module, UINT8 bOnOff)
{
	//the all ostg module includes the modules between OSD video blending and LVDS output.

    LOG(1,"DRVCUST_SetOSTGModuleOnOff u1Module=%d, bOnOff=%d--\n",u1Module, bOnOff);
	
	switch(u1Module)
	{
		case E_OSTG_MODULE_ALL:	
			vDrvxvYCC2OnOff(bOnOff);
			vDrvSetLcDimOnOff(bOnOff);
			DRVCUST_FrontDitherOnoff(bOnOff);
			vDrvGammaOnOff(bOnOff);
			DRVCUST_PostDitherOnOff(bOnOff);
			vIO32WriteFldAlign(OSTG_01, bOnOff,REG_RGB2YUV_EN);
			break;
		case E_OSTG_MODULE_XVYCC2:
			//vDrvxvYCC2OnOff(bOnOff);
			vIO32WriteFldAlign(XVYCC_17, !bOnOff,REG_XVS_3X3_DISABLE);
			break;
		case E_OSTG_MODULE_LCD:
			vDrvSetLcDimOnOff(bOnOff);
			break;
		case E_OSTG_MODULE_DITHER_BEFORE_OPTION3:
			DRVCUST_FrontDitherOnoff(bOnOff);
			break;
		case E_OSTG_MODULE_GAMMA_OPTION3:
			vDrvGammaOnOff(bOnOff);
			break;
		case E_OSTG_MODULE_DITHER_AFTER_OPTION3:
			DRVCUST_PostDitherOnOff(bOnOff);
			break;
		case E_OSTG_MODULE_R2Y:
			vIO32WriteFldAlign(OSTG_01, bOnOff,REG_RGB2YUV_EN);
			break;
		default:
			break;
	}
}

#if 1//def CC_Factory2K12
/* BEGIN SONY, ramesh, 21/07/09 */

///////////////BEGIN SONY DRV CALLBACK/////////////////

#define NULL_CHK(ptr)  \
          do {                                              \
            if (ptr == NULL)\
            {\
                    return;\
            } } while (0)


extern INT32 OSD_PLA_Enable(UINT32 u4Plane, BOOL fgEnable);

/* >>> START, cheah 31-Jul-09, callback for Sony GammaWB adj + AutoWB */
void cbSony_GammaOSDControl(void* pvArg)
{
    BOOL* bOnOff = (BOOL*)pvArg;
    NULL_CHK(pvArg);

    /* disable/enable OSD */
    if (*bOnOff)
    {
        //OSD_PLA_Force_Off(TRUE);    //OSD_PLA_Force_Off
        OSD_PLA_Enable(OSD_PLANE_1, FALSE);
        OSD_PLA_Enable(OSD_PLANE_2, FALSE);
        OSD_PLA_Enable(OSD_PLANE_3, FALSE);
		//OSD_PLA_Enable_Ex(OSD_PLANE_2, 0);
    }
    else
    {
        //OSD_PLA_Force_Off(FALSE);   //OSD_PLA_Force_Off
        OSD_PLA_Enable(OSD_PLANE_1, TRUE);
        OSD_PLA_Enable(OSD_PLANE_2, TRUE);
        OSD_PLA_Enable(OSD_PLANE_3, TRUE);
        //OSD_PLA_Enable_Ex(OSD_PLANE_2, 1);
    }
}

void cbSony_GammaSetPat(void* pvArg)
{
	ST_PARAM_GAM_PTG* gam_param = (ST_PARAM_GAM_PTG*)pvArg;
	NULL_CHK(pvArg);
	
	if (gam_param->onOff == SV_TRUE)
	{
		/* toggle off first to avoid gamma curve corruption */
		vDrvGammaUnmute(); 
		/* turn ON gamma pattern */
		vDrvGammaMute(gam_param->wGammaR, \
                      gam_param->wGammaG, \
                      gam_param->wGammaB);
	}
	else
	{
		/* turn OFF gamma pattern */
		vDrvGammaUnmute(); 
	}
}

void cbSony_GammaSetSCEPat(void* pvArg)
{
	extern INT32 const YCBCR2RGBOS[3][15];	
	extern INT32 COLOR_TRANSFORM_ADJ[15];
    INT32 COLOR_TRANSFORM_Y2R[15];
    static UINT8 fgOnOff = SV_OFF;
    ST_PARAM_SCE_PTG* sce_param = (ST_PARAM_SCE_PTG*)pvArg;
    NULL_CHK(pvArg);

    vDrvSCEPatGen(sce_param->onOff, sce_param->data);
    vDrvSCEAllOnOff(sce_param->sceProc);       
    if (sce_param->onOff) 
    { 
        fgOnOff = bDrvGetBlueStretchOnOff(); /* store latest setting */
        if (fgOnOff)
        {
            vDrvSetBlueStretchOnOff(SV_VP_MAIN, SV_OFF); /* bypass blue stretch */
        }
        
		x_memcpy(COLOR_TRANSFORM_Y2R, YCBCR2RGBOS[0], sizeof(COLOR_TRANSFORM_Y2R));
        vLoadOSColorMatrix(SV_VP_MAIN, COLOR_TRANSFORM_Y2R);
        vOSTGVideoPlaneHWMute(SV_VP_MAIN,0); //Disable HDMI mute during pattern on
        _vDrvVideoForceUnMute(0, 1);
    }
    else
    { 
        if (fgOnOff != bDrvGetBlueStretchOnOff())
        {
            vDrvSetBlueStretchOnOff(SV_VP_MAIN, fgOnOff); /* restore user blue stretch setting */
        }
        
        vOSTGVideoPlaneHWMute(SV_VP_MAIN,1); //Enable HDMI mute
        _vDrvVideoForceUnMute(0, 0);		
        vLoadOSColorMatrix(SV_VP_MAIN, COLOR_TRANSFORM_ADJ);
    }	
}


void cbSony_WBSetGainOfst(void* pvArg)
{
	ST_PARAM_WB_T* wb_param = (ST_PARAM_WB_T*)pvArg;
	NULL_CHK(pvArg);
	
	/* Color Gain */
	vHalVideoRGBGain(SV_VP_MAIN, SV_RGB_R, wb_param->wGainR);
	vHalVideoRGBGain(SV_VP_MAIN, SV_RGB_G, wb_param->wGainG);
	vHalVideoRGBGain(SV_VP_MAIN, SV_RGB_B, wb_param->wGainB);
	
	/* Color offset */
	vHalVideoRGBOffset(SV_VP_MAIN, SV_RGB_R, wb_param->wOfstR);
	vHalVideoRGBOffset(SV_VP_MAIN, SV_RGB_G, wb_param->wOfstG);
	vHalVideoRGBOffset(SV_VP_MAIN, SV_RGB_B, wb_param->wOfstB);
}

void sonyDrv_RegisterCallback(void)
{
  UINT8 i;
  
  for(i=0; i < CB_DRV_FUNC_COUNT; i++)
  {
    callback_funcs.cbDrv[i] = NULL;
  }

  callback_funcs.cbDrv[CB_DRV_GAM_OSD_CONTROL]       = cbSony_GammaOSDControl;
  callback_funcs.cbDrv[CB_DRV_GAM_PATGEN_GAM]        = cbSony_GammaSetPat;
  callback_funcs.cbDrv[CB_DRV_GAM_PATGEN_SCE]        = cbSony_GammaSetSCEPat;
  callback_funcs.cbDrv[CB_DRV_WB_GAINOFST]           = cbSony_WBSetGainOfst;

  sonyDrvRegisterCallback(&callback_funcs);
}
#endif

#ifdef DRV_CUST_HDR
void DRVCUST_SetOpenHDRXvyccOnOff(UINT8 bPath, UINT8 u1OnOff)
{
    vDrvxvYCC2Load3x3Matrix(XVYCC_MATRIX_BT2020NCL);
    if(SV_VP_MAIN == bPath)
    {
        vIO32WriteFldAlign(XVYCC_17, !u1OnOff, REG_XVS_3X3_DISABLE);
        vIO32WriteFldAlign(XVYCC_17, u1OnOff, REG_XVS_GM_SRGB);                 
        vIO32WriteFldAlign(XVYCC_17, u1OnOff, REG_XVS_AGM_SRGB);
        vDrvxvYCC2OnOff(u1OnOff);
    }
}

UINT8 DRVCUST_HDRDetectInfo(UINT8 bPath)
{
	UINT8 u1DecType;
	UINT8  bSigMode = bDrvVideoSignalStatus(bPath);
	SV_HDR_INFO_T prHDRHDMIInfo;
	B2R_CUST_INFO_T prHDRMMPInfo;
	
	
	memset(&prHDRHDMIInfo, 0, sizeof(SV_HDR_INFO_T));
	memset(&prHDRMMPInfo, 0, sizeof(B2R_CUST_INFO_T));
	INT32 fgMMPIsHdr = B2R_Get_Cust_info(bPath, B2R_GET_TYPE_CUST_INFO, &prHDRMMPInfo,sizeof(B2R_CUST_INFO_T));//INT32 B2R_Get_Cust_info (UCHAR ucVdpId, B2R_GET_CUST_TYPE_T   e_set_type, VOID* pv_get_info,  SIZE_T z_set_info_size)
	BOOL fgHdmiIsHdr = DRVCUST_HDMIGetHDRInfo(bPath,&prHDRHDMIInfo); 
	u1DecType = (bPath == SV_VP_MAIN) ? _rMChannel.bDecType : _rPChannel.bDecType;
	

    if((bSigMode != (UINT8)SV_VDO_STABLE))
    {
       
        return FALSE;
    }
    if(IO32ReadFldAlign(HDR_00, Force_HDR_M))
    {
        //force HDR
        gbIsHdrFlg=1;
        LOG(0,"Force HDR!\n");
        return TRUE;
	}
	else
	{
        gbIsHdrFlg=0;   	
        vIO32WriteFldAlign(HDR_01, prHDRHDMIInfo.eEOTF, HDR_HDMI_INFO); 
        vIO32WriteFldAlign(HDR_01, prHDRMMPInfo.u4HDRContent, HDR_MMP_INFO);
        vIO32WriteFldAlign(HDR_00, 0, FLG_HDR_HDMI);
        vIO32WriteFldAlign(HDR_00, 0, FLG_HDR_MMP);
        
    	switch (u1DecType)
        {	
    		case SV_VD_DVI:
    			if(!fgHdmiIsHdr)
    			{
    				LOG(2,"HDR HDMI FALSE!");
    				return FALSE;
    			}
    			else
    			{
    				switch(prHDRHDMIInfo.eEOTF)
    				{
    					case SV_HDRTYPE_ST2084:
    					    vIO32WriteFldAlign(HDR_00, 1, FLG_HDR_HDMI);
    					    gbIsHdrFlg=1;
    						LOG(2,"HDR HDMI ST2084! \n");
    						return TRUE;
    						break;
    					default:
    					    LOG(2,"HDR HDMI info:%d \n",prHDRHDMIInfo.eEOTF);
    						return FALSE;
    						break;
    				}	
    			}
    			 break;
    		case SV_VD_MPEGHD:
            case SV_VD_MPEGSD:
    			if(prHDRMMPInfo.u4HDRContent == 16)
    			{
                    vIO32WriteFldAlign(HDR_00, 1, FLG_HDR_MMP);
                    gbIsHdrFlg=1;
    				LOG(2,"HDR MMP ST2084! \n");
    				return TRUE;
    			}
    			else
    			{
                    LOG(2,"HDR MMP info:%d \n",prHDRMMPInfo.u4HDRContent);
    				return FALSE;
    			}	
    			break;
    	}
    	return FALSE;
	}		
}
void vHDROnOffProc(UINT8 u1OnOff)
{
    LOG(2,"HDR------------>u1OnOff%d \n",u1OnOff);
    DRVCUST_SetOpenHDRXvyccOnOff(SV_VP_MAIN, u1OnOff);
    vIO32WriteFldAlign(SCE_CFG_MAIN,u1OnOff,ADAP_LUMA_BP);
    vDrvVideoColorMatrix(SV_VP_MAIN);
}
void vDrvSetHDREnable(UINT8 bPath,UINT8 u1Enable)
{
	if(bPath == SV_VP_MAIN)
    {
        vIO32WriteFldAlign(HDR_00, u1Enable, HDR_UI_EN_M);			
    }   
    LOG(0,"SET DrvHDR Path[%d]:%d  /n",bPath,u1Enable);	
    vIO32WriteFldAlign(HDR_00, SV_ON, FLG_HDR_ModeChange);
}
void vDrvHDRQueryStatus(UINT8 bPath)
{
	UINT8 u1DecType; 
	UINT8 u1HDMIEOTFType = IO32ReadFldAlign(HDR_01, HDR_HDMI_INFO);
	UINT8 u1MMPEOTFType = IO32ReadFldAlign(HDR_01, HDR_MMP_INFO);
	
	u1DecType = (bPath == SV_VP_MAIN) ? _rMChannel.bDecType : _rPChannel.bDecType;

	LOG(0, "Source            = %-s\n",
        u1DecType == SV_VD_DVI ? "DVI" :
        u1DecType == SV_VD_MPEGHD ? "MPGEHD" :
        u1DecType == SV_VD_MPEGSD ? "MPGESD" : "Unknown");
    
    if(bPath == SV_VP_MAIN)
    {
    	LOG(0, "HDR Force  : %d\n", IO32ReadFldAlign(HDR_00, Force_HDR_M));
        LOG(0, "HDR Enable : %d\n", IO32ReadFldAlign(HDR_00, HDR_UI_EN_M));
    }
    else
    {
    	LOG(0, "HDR Force  : %d\n", IO32ReadFldAlign(HDR_00, Force_HDR_P));
        LOG(0, "HDR Enable : %d\n", IO32ReadFldAlign(HDR_00, HDR_UI_EN_P));
    }
    switch (u1DecType)
    {	
		case SV_VD_DVI:
		    if(IO32ReadFldAlign(HDR_00, FLG_HDR_HDMI))
		    {
		        LOG(0,"HDMI EOTF Type        = %-s (%d)\n",
		             u1HDMIEOTFType == 0 ? "SDR" :
		             u1HDMIEOTFType == 1 ? "SDR" :
                     u1HDMIEOTFType == 2 ? "SMPTE2084" :
                     u1HDMIEOTFType == 3 ? "Future HDR" : "Unknow Type",u1HDMIEOTFType);
		    }
		    else
		    {
                LOG(0, "Fail HDR! EOTF Type:%d \n",u1HDMIEOTFType);
		    }
			break;
		case SV_VD_MPEGHD:
        case SV_VD_MPEGSD:
            if(IO32ReadFldAlign(HDR_00, FLG_HDR_MMP))
		    {
		        LOG(0,"MMP EOTF Type        = %-s (%d)\n",
                     u1MMPEOTFType == 16 ? "SMPTE2084 HDR" : "Unknow Type",u1MMPEOTFType);
		    }
		    else
		    {
                LOG(0, "Fail HDR! EOTF Type:%d \n",u1MMPEOTFType);
		    }
			break;
   }
}
void vDrvForceHDR(UINT8 bPath,UINT8 u1ForceOnOff)
{
    if(bPath == SV_VP_MAIN)
    {
        vIO32WriteFldAlign(HDR_00, u1ForceOnOff, Force_HDR_M);
    }

    if((bDrvVideoSignalStatus(bPath) == (UINT8)SV_VDO_STABLE))
    {       
        vHDROnOffProc(u1ForceOnOff);
    }
    LOG(0,"Force DrvHDR Path[%d]:%d  /n",bPath,u1ForceOnOff);	
}
#endif

void vDRVCUST_VideoSuspend(void)
{
    // bDYNHDRHootBoot = SV_TRUE;

    return ;
}

void DRVCUST_Resume(void)
{
	PreHDRType = SV_HDR_TYPE_SDR;
	bIsSeamless = SV_FALSE;
	eVP9HDRType = SV_VP9_HDR_TYPE_NONE;
	//DRVCUST_MURA_CUCInit();
	DRVCUST_4KBE_OSTG_Bypass();
}


void DRVCUST_INXMsAutoMuteDisable(void)
{
    cmiMstFrcAutoMuteOff();
}

void DRVCUST_XvyccInit(void)
{
#ifdef DRV_CUST_HDR
    if(DRV_CUST_HDR)
    {
        vIO32WriteFldAlign(XVYCC_17, SV_OFF, REG_XVS_BYPASS);
        vIO32WriteFldAlign(XVYCC_17, SV_OFF, REG_XVS_DISABLE);
        vIO32WriteFldAlign(XVYCC_17, SV_OFF, REG_XVS_GM_SRGB);
        vIO32WriteFldAlign(XVYCC_17, SV_OFF, REG_XVS_AGM_SRGB);
        vIO32WriteFldAlign(XVYCC_17, SV_ON, REG_XVS_3X3_DISABLE);
        vIO32WriteFldAlign(XVYCC_17, SV_OFF, REG_XVS_DISABLE_AG);
        vIO32WriteFldAlign(XVYCC_17, SV_OFF, REG_XVS_DISABLE_G);
        vIO32WriteFldAlign(OSTG_00, SV_ON, R_LD_SRC_SEL);
        vIO32WriteFldAlign(XVYCC_22, 0xFFF, REG_XVS_GM_G_4096);
        vIO32WriteFldAlign(XVYCC_22, 0xFFF, REG_XVS_GM_R_4096);
        vIO32WriteFldAlign(XVYCC_23, 0xFFF, REG_XVS_GM_B_4096);
    }
#endif

    // xvYCC HW init
    vIO32WriteFldAlign(XVYCC_10, 0xFFF, REG_GAMMA_G_SRAM_4096);
    vIO32WriteFldAlign(XVYCC_10, 0xFFF, REG_GAMMA_R_SRAM_4096);
    vIO32WriteFldAlign(XVYCC_11, 0xFFF, REG_GAMMA_B_SRAM_4096);
#ifdef DRV_CUST_HDR
    vDrvxvYCCLoad3x3Matrix(DEFAULT_XVYCC_MATRIX);
#endif
}

//-=============================================

UINT16 DRVCUST_GetPanelNits(void)
{
    UINT16 PanelNits = 350;
//TO-BE by cust

    return PanelNits;
    
}
UINT8 DRVCUST_GetPanelMode(void)
{
//TO-BE by cust
//709 return 0,other return 1
 if(1)
  {
     return SV_FALSE;
  }
  else
  {
    //DRVCUST_GetPanelGamut must set
     return SV_TRUE;
  }    
}

PANEL_GAMUT_T DRVCUST_GetPanelGamut(void)
{
    panel_Gamut.BT2020_c00=0;
    panel_Gamut.BT2020_c01=0;
    panel_Gamut.BT2020_c02=0;
    panel_Gamut.BT2020_c10=0;
    panel_Gamut.BT2020_c11=0;
    panel_Gamut.BT2020_c12=0;
    panel_Gamut.BT2020_c20=0;
    panel_Gamut.BT2020_c21=0;        
    panel_Gamut.BT2020_c22=0;

    panel_Gamut.BT709_c00=0;
    panel_Gamut.BT709_c01=0;
    panel_Gamut.BT709_c02=0;
    panel_Gamut.BT709_c10=0;
    panel_Gamut.BT709_c11=0;
    panel_Gamut.BT709_c12=0;
    panel_Gamut.BT709_c20=0;
    panel_Gamut.BT709_c21=0;        
    panel_Gamut.BT709_c22=0;
    
    return panel_Gamut;
    
};
TONE_MAP_T DRVCUST_GetToneMap(void)
{
    //TO-BE by cust
    tone_mapping.reg_p1 = 256;
    tone_mapping.reg_p2 = 11151;
    tone_mapping.reg_p3 = 18204;
    tone_mapping.reg_p4 = 25258;
    tone_mapping.reg_p5 = 32311;
    tone_mapping.reg_p6 = 39374;
    tone_mapping.reg_p7 = 47794;
    tone_mapping.reg_p8 = 56222;
    tone_mapping.reg_p9 = 64651;
    tone_mapping.reg_p10 = 74017;
    tone_mapping.reg_p11 = 83269;
    tone_mapping.reg_p12 = 90979;
    tone_mapping.reg_p13 = 107708;
    tone_mapping.reg_p14 = 144139;
    tone_mapping.reg_p15 = 228089;
    tone_mapping.reg_p16 = 454594;

    tone_mapping.reg_slope0 = 65535;
    tone_mapping.reg_slope1 = 65535;
    tone_mapping.reg_slope2 = 65535;
    tone_mapping.reg_slope3 = 65535;
    tone_mapping.reg_slope4 = 28815;
    tone_mapping.reg_slope5 = 25914;
    tone_mapping.reg_slope6 = 22952;
    tone_mapping.reg_slope7 = 20110;
    tone_mapping.reg_slope8 = 17702;
    tone_mapping.reg_slope9 = 23305;
    tone_mapping.reg_slope10 = 18892;
    tone_mapping.reg_slope11 = 22670;
    tone_mapping.reg_slope12 = 14927;
    tone_mapping.reg_slope13 = 5668;
    tone_mapping.reg_slope14 = 3271;
    tone_mapping.reg_slope15 = 1984;
    
    return tone_mapping;
    
};
void DRVCUST_COL_CON_PARAM_INIT(void)
{
	UINT32 u4BeType = 0;
	UINT8 i=0;
	UINT8 j=0;
	UNUSED(DRVCUST_InitQuery(eGet4KModelBEType, &u4BeType));  //u4BeType =1 4K BE model, u4BeType=0 without BE model.

	x_memset(CUST_COL_CONV_TABLE_PARAM, 0, sizeof(CUST_COL_CONV_TABLE_PARAM_T)*COL_CONV_MAX_NUM);
	
	for(i=0;i<E_INPUT_MAX; i++)
		{
			for(j=1; j<E_MTX_MAX; j++)
			{
				if(u1CONV_TBL_M3_BE_DFT[i][j]==0)
				{
					u1CONV_TBL_M3_BE_DFT[i][j]=u1CONV_TBL_M3_BE_DFT[i][j-1];
				}
				if(u1CONV_TBL_M3_PQ_DFT[i][j]==0)
				{
					u1CONV_TBL_M3_PQ_DFT[i][j]=u1CONV_TBL_M3_PQ_DFT[i][j-1];
				}
				if(u1CONV_TBL_M3_ONLY_DFT[i][j]==0)
				{
					u1CONV_TBL_M3_ONLY_DFT[i][j]=u1CONV_TBL_M3_ONLY_DFT[i][j-1];
				}
			}
		}
	if(u4BeType==0)
	{
		if(IsPQICExists())
		{
			x_memcpy(u1CONV_TBL_DFT,u1CONV_TBL_M3_PQ_DFT,sizeof(u1CONV_TBL_DFT));
		}
		else
		{
			x_memcpy(u1CONV_TBL_DFT,u1CONV_TBL_M3_ONLY_DFT,sizeof(u1CONV_TBL_DFT));
		}

	}
	else
	{
		x_memcpy(u1CONV_TBL_DFT,u1CONV_TBL_M3_BE_DFT,sizeof(u1CONV_TBL_DFT));
	}

}

UINT8 DRVCUST_SetConTblDFT(UINT8 u1input, UINT8 u1blk, UINT8 u1src, UINT8 u1dst)
{
	UINT32 u4BeType = 0;
	UNUSED(DRVCUST_InitQuery(eGet4KModelBEType, &u4BeType));  //u4BeType =1 4K BE model, u4BeType=0 without BE model.
	UINT8 i,j;
	if((u1CONV_TBL_DFT[u1input][u1blk]==u1dst)&&(u1CONV_TBL_DFT[u1input][u1blk-1]==u1src))
	{
          	LOG(0, "err!! this setting already exists\n");
		return SV_FALSE;
		
	}

	
	if(u4BeType==0)
	{
		if(IsPQICExists())
		{
			u1CONV_TBL_M3_PQ_DFT[u1input][u1blk-1] = u1src;
			u1CONV_TBL_M3_PQ_DFT[u1input][u1blk] = u1dst;
		}
		else
		{
			u1CONV_TBL_M3_ONLY_DFT[u1input][u1blk-1] = u1src;
			u1CONV_TBL_M3_ONLY_DFT[u1input][u1blk] = u1dst;
		}

	}
	else
	{
		u1CONV_TBL_M3_BE_DFT[u1input][u1blk-1] = u1src;
		u1CONV_TBL_M3_BE_DFT[u1input][u1blk] = u1dst;
	}

//////////////
	for(i=0;i<E_INPUT_MAX; i++)
	{
		for(j=1; j<E_MTX_MAX; j++)
		{
			if(u1CONV_TBL_M3_BE_DFT[i][j]==0)
			{
				u1CONV_TBL_M3_BE_DFT[i][j]=u1CONV_TBL_M3_BE_DFT[i][j-1];
			}
			if(u1CONV_TBL_M3_PQ_DFT[i][j]==0)
			{
				u1CONV_TBL_M3_PQ_DFT[i][j]=u1CONV_TBL_M3_PQ_DFT[i][j-1];
			}
			if(u1CONV_TBL_M3_ONLY_DFT[i][j]==0)
			{
				u1CONV_TBL_M3_ONLY_DFT[i][j]=u1CONV_TBL_M3_ONLY_DFT[i][j-1];
			}
		}
	}
////////////////
	if(u4BeType==0)
	{
		if(IsPQICExists())
		{
			x_memcpy(u1CONV_TBL_DFT,u1CONV_TBL_M3_PQ_DFT,sizeof(u1CONV_TBL_DFT));
		}
		else
		{
			x_memcpy(u1CONV_TBL_DFT,u1CONV_TBL_M3_ONLY_DFT,sizeof(u1CONV_TBL_DFT));
		}

	}
	else
	{
		x_memcpy(u1CONV_TBL_DFT,u1CONV_TBL_M3_BE_DFT,sizeof(u1CONV_TBL_DFT));
	}

	return SV_TRUE;
}

void DRVCUST_GetConTblMtxDFT_PRE(UINT8 u1Input)
{
	UINT8 i,j;
	INT32 u4MtxBuff[15];
	UINT8 u4ColorSys =_bMAIN_COLOR_SYS;
	//from M setting
	if(u1ConvTblParamIDX==0)//if S not set convtable , set 0 to specific
	{
		for(i=0;i<E_INPUT_MAX; i++)
		{
			for(j=1; j<E_MTX_MAX; j++)
			{
				if(u1CONV_TBL_DFT[i][j]==0)
				{
					u1CONV_TBL_DFT[i][j]=u1CONV_TBL_DFT[i][j-1];
				}
			}
		}
	}
	switch (u1Input)
	{
		case E_601_LIMITED:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_601_LIMITED)
			{

				if(u4ColorSys==SV_COLOR_YUV_NTSC)
				{
					for(i=0;i<15;i++)
					{
						u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YUVNTSC_2_YCBCR601L][i] ;//601l->601l
						
					}
					u1ColorTransIdx_ext = SV_COLORTRANS_YUVNTSC_2_YCBCR601L;
				}
				else if(u4ColorSys==SV_COLOR_YUV_NTSCJ)
				{
					for(i=0;i<15;i++)
					{
						u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YUVNTSCJ_2_YCBCR601L][i] ;//601l->601l
						
					}
					u1ColorTransIdx_ext = SV_COLORTRANS_YUVNTSCJ_2_YCBCR601L;
				}
				else if(u4ColorSys==SV_COLOR_YUV_PAL)
				{
					for(i=0;i<15;i++)
					{
						u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YUVPAL_2_YCBCR601L][i] ;//601l->601l
						
					}
					u1ColorTransIdx_ext = SV_COLORTRANS_YUVPAL_2_YCBCR601L;
				}
				else
				{
					for(i=0;i<15;i++)
					{
						u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR601L][i] ;//601l->601l
						
					}
					u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR601L;
				}




				
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_709_LIMITED)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR709L][i] ;//601l->709l
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR709L;
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_RGB_FULL)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_RGBF][i] ;//601l->RGBF
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_RGBF;
			}
			else
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR601L][i] ;//601l->601l
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR601L;
			}
			x_memcpy(DRVCUST_Matrix[E_MTX_PRE],u4MtxBuff,sizeof(u4MtxBuff));
			break;
		case E_601_FULL:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_601_FULL)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR601L][i] ;//601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR601L;
			}
				
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_601_LIMITED)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601F_2_YCBCR601L][i] ;//601F->601l
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601F_2_YCBCR601L;
			}
			
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_RGB_FULL)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601F_2_RGBF][i] ;//601F->RGBF
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601F_2_RGBF;
			}	
			else
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR601L][i] ;//601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR601L;
			}
			x_memcpy(DRVCUST_Matrix[E_MTX_PRE],u4MtxBuff,sizeof(u4MtxBuff));
			break;
		case E_709_LIMITED:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_709_LIMITED)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR601L][i] ;//601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR601L;
			}
				
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_601_LIMITED)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR709L_2_YCBCR601L][i] ;//709l->601l
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR709L_2_YCBCR601L;
			}
			

			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_RGB_FULL)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR709L_2_RGBF][i] ;//709l->RGBF
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR709L_2_RGBF;
			}	
			else
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR601L][i] ;//601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR601L;
			}
			x_memcpy(DRVCUST_Matrix[E_MTX_PRE],u4MtxBuff,sizeof(u4MtxBuff));
			break;
		case E_709_FULL:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_709_FULL)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR601L][i] ;//601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR601L;
			}	
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_601_LIMITED)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR709F_2_YCBCR601L][i] ;//709F->601l
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR709F_2_YCBCR601L;
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_RGB_FULL)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR709F_2_RGBF][i] ;//709F->RGBF
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR709F_2_RGBF;
			}	
			else
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR601L][i] ;//601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR601L;
			}	
			x_memcpy(DRVCUST_Matrix[E_MTX_PRE],u4MtxBuff,sizeof(u4MtxBuff));
			break;
		case E_2020_LIMITED:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_2020_LIMITED)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR601L][i] ;//601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR601L;
			}	
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_601_LIMITED)//pre
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_BT2020L_2_YCBCR601L][i] ;//2020L->601l
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_BT2020L_2_YCBCR601L;
			}				
			else
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR601L][i] ;//601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR601L;
			}
			x_memcpy(DRVCUST_Matrix[E_MTX_PRE],u4MtxBuff,sizeof(u4MtxBuff));
			break;
		case E_2020_FULL:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_2020_FULL)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR601L][i] ;//601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR601L;
			}	
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_601_LIMITED)//pre
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_BT2020F_2_YCBCR601L][i] ;//2020F->601l
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_BT2020F_2_YCBCR601L;
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_2020_LIMITED)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601F_2_YCBCR601L][i] ;//2020F->2020l ->601F->601L
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601F_2_YCBCR601L;
			}	
			else
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR601L][i] ;//601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR601L;
			}
			x_memcpy(DRVCUST_Matrix[E_MTX_PRE],u4MtxBuff,sizeof(u4MtxBuff));
			break;
		case E_2020YC_LIMITED:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_2020YC_LIMITED)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_BT2020CL_2_BT2020CL][i] ;//Same as 601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_BT2020CL_2_BT2020CL;
			}
			else
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_BT2020CL_2_BT2020CL][i] ;//Same as 601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_BT2020CL_2_BT2020CL;
				//just keep
			}
			x_memcpy(DRVCUST_Matrix[E_MTX_PRE],u4MtxBuff,sizeof(u4MtxBuff));
			break;
		case E_2020YC_FULL:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_2020YC_FULL)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_BT2020CL_2_BT2020CL][i] ;//Same as 601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_BT2020CL_2_BT2020CL;
			}	
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_2020YC_LIMITED)//pre
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_BT2020CF_2_BT2020CL][i] ;//2020cF->2020cl ->601F->601L
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_BT2020CF_2_BT2020CL;
			}
			else
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_BT2020CL_2_BT2020CL][i] ;//Same as 601l->601l  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_BT2020CL_2_BT2020CL;
			}
			x_memcpy(DRVCUST_Matrix[E_MTX_PRE],u4MtxBuff,sizeof(u4MtxBuff));
			break;
			
		case E_RGB_LIMITED:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_RGB_LIMITED)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_RGBF_2_RGBF][i] ;//RGB  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_RGBF_2_RGBF;
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_601_LIMITED)//pre
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_RGBL_2_YCBCR601L][i] ;//RGBL->601L
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_RGBL_2_YCBCR601L;
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_709_LIMITED)//pre
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_RGBL_2_YCBCR709L][i] ;//RGBL->709L
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_RGBL_2_YCBCR709L;
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_RGB_FULL)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_RGBL_2_RGBF][i] ;//RGBL->RGBF
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_RGBL_2_RGBF;
			}
				
			else
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_RGBL_2_RGBF][i] ;//RGBL->RGBF
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_RGBL_2_RGBF;
			}
			x_memcpy(DRVCUST_Matrix[E_MTX_PRE],u4MtxBuff,sizeof(u4MtxBuff));
			break;
		case E_RGB_FULL:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_RGB_FULL)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_RGBF_2_RGBF][i] ;//RGB  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_RGBF_2_RGBF;
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_601_LIMITED)//pre
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_RGBF_2_YCBCR601L][i] ;//RGBF->601L
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_RGBF_2_YCBCR601L;
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_709_LIMITED)//pre
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_RGBF_2_YCBCR709L][i] ;//RGBF->709L
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_RGBF_2_YCBCR709L;
			}
			
			else
				{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_RGBF_2_RGBF][i] ;//RGB  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_RGBF_2_RGBF;
			}
			x_memcpy(DRVCUST_Matrix[E_MTX_PRE],u4MtxBuff,sizeof(u4MtxBuff));
			break;
		case E_RGB2020_LIMITED:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_RGB2020_LIMITED)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_RGBF_2_RGBF][i] ;//RGB  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_RGBF_2_RGBF;
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_601_LIMITED)//pre
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_BT2020RGBL_2_YCBCR601L][i] ;//RGB2020l->601L
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_BT2020RGBL_2_YCBCR601L;
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_2020_LIMITED)//pre
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_BT2020_RGBL_2_BT2020_NCL_L][i] ;//(bt2020rgbl ->bt2020l)
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_BT2020_RGBL_2_BT2020_NCL_L;
			}
			
			else
				{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_RGBF_2_RGBF][i] ;//RGB  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_RGBF_2_RGBF;
			}
			x_memcpy(DRVCUST_Matrix[E_MTX_PRE],u4MtxBuff,sizeof(u4MtxBuff));
			break;
		case E_RGB2020_FULL:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_RGB2020_FULL)
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_RGBF_2_RGBF][i] ;//RGB  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_RGBF_2_RGBF;
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_601_LIMITED)//pre
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_BT2020RGBF_2_YCBCR601L][i] ;//RGB2020F->601L
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_BT2020RGBF_2_YCBCR601L;
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_PRE]==E_2020_LIMITED)//pre
			{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_BT2020_RGBF_2_BT2020_NCL_L][i] ;//(bt2020rgbF ->bt2020l)
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_BT2020_RGBF_2_BT2020_NCL_L;
			}
			
			else
				{
				for(i=0;i<15;i++)
				{
					u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_RGBF_2_RGBF][i] ;//RGB  1:1 TRANS
					
				}
				u1ColorTransIdx_ext = SV_COLORTRANS_RGBF_2_RGBF;
			}
			x_memcpy(DRVCUST_Matrix[E_MTX_PRE],u4MtxBuff,sizeof(u4MtxBuff));
			break;
			
		default:
		{
			for(i=0;i<15;i++)
			{
				u4MtxBuff[i] = COLOR_TRANSFORM[SV_COLORTRANS_YCBCR601L_2_YCBCR601L][i] ;//601l->601l
				
			}
			u1ColorTransIdx_ext = SV_COLORTRANS_YCBCR601L_2_YCBCR601L;
		}
		x_memcpy(DRVCUST_Matrix[E_MTX_PRE],u4MtxBuff,sizeof(u4MtxBuff));
		break;

	}
	//from S setting
	for(i=0; i<u1ConvTblParamIDX;i++)
	{
		if((CUST_COL_CONV_TABLE_PARAM[i].input==u1Input)&&(CUST_COL_CONV_TABLE_PARAM[i].type==E_MODIFY_BY_MATRIX_COEFFICIENT))
		{
				if(CUST_COL_CONV_TABLE_PARAM[i].block==E_MTX_PRE)
				{
					x_memcpy(DRVCUST_Matrix[E_MTX_PRE],CUST_COL_CONV_TABLE_PARAM[i].matrix,sizeof(UINT32)*15);
					u1ColorTransIdx_ext = 0xFF;
				}
			
		}
	}
	for (i=0;i<15;i++)
	{
		LOG(1, "DRVCUST_Matrix[E_MTX_PRE][%d]=%d\n",i,DRVCUST_Matrix[E_MTX_PRE][i]);
	}

	LOG(1, "u1CONV_TBL_DFT[%d][0]=%d\n",u1Input,u1CONV_TBL_DFT[u1Input][0]);
	LOG(1, "u1CONV_TBL_DFT[%d][1]=%d\n",u1Input,u1CONV_TBL_DFT[u1Input][1]);
	LOG(1, "u1CONV_TBL_DFT[%d][2]=%d\n",u1Input,u1CONV_TBL_DFT[u1Input][2]);
	LOG(1, "u1CONV_TBL_DFT[%d][3]=%d\n",u1Input,u1CONV_TBL_DFT[u1Input][3]);
	LOG(1, "u1CONV_TBL_DFT[%d][4]=%d\n",u1Input,u1CONV_TBL_DFT[u1Input][4]);

}
void DRVCUST_GetConTblMtxDFT_OS(UINT8 u1Input)
{
	UINT8 i,j;
	INT32 u4MtxBuff[15];
	//from M setting
	switch (u1CONV_TBL_DFT[u1Input][E_MTX_PRE])
	{
		case E_601_LIMITED:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_601_LIMITED)
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2YUV,sizeof(SRC_YUV_YUV2YUV)); //601l->601l
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_RGB_LIMITED)
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2RGB,sizeof(SRC_YUV_YUV2RGB)); //601l->RGBl
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_RGB_FULL)
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2RGBEXTLVL,sizeof(SRC_YUV_YUV2RGBEXTLVL)); //601l->RGBF
			}
			else
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2RGBEXTLVL,sizeof(SRC_YUV_YUV2RGBEXTLVL)); //601l->RGBF
			}
			
			break;
		case E_601_FULL:
			//maybe no this case
			if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_601_FULL)
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2YUV,sizeof(SRC_YUV_YUV2YUV)); //601F->601F
			}
			else
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2RGBEXTLVL,sizeof(SRC_YUV_YUV2RGBEXTLVL)); //601l->RGBF
			}	
			break;
		case E_709_LIMITED:

			if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_709_LIMITED)
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2YUV,sizeof(SRC_YUV_YUV2YUV)); //709l->709l
			}	
			//else if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_RGB_FULL)
			else
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2RGBEXTLVL,sizeof(SRC_YUV_YUV2RGBEXTLVL)); //601l->RGBF
			}
			break;
		case E_709_FULL:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_709_FULL)
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2YUV,sizeof(SRC_YUV_YUV2YUV)); //709F->709F
			}	
			else
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2RGBEXTLVL,sizeof(SRC_YUV_YUV2RGBEXTLVL)); //601l->RGBF
			}	
			break;
		case E_2020_LIMITED:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_2020_LIMITED)//pre
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2YUV,sizeof(SRC_YUV_YUV2YUV)); //2020l->2020l
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_RGB_LIMITED)
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_BT2020_YUV_YUV2RGB_CL,sizeof(SRC_BT2020_YUV_YUV2RGB_CL)); //2020l->2020l
			}
			else if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_RGB_FULL)
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_BT2020_YUV_YUV2RGBEXTLVL_CL,sizeof(SRC_BT2020_YUV_YUV2RGBEXTLVL_CL)); //2020l->2020F
			}	
			else
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2YUV,sizeof(SRC_YUV_YUV2YUV)); //2020l->2020l
			}	
			break;
		case E_2020_FULL:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_2020_FULL)//pre
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2YUV,sizeof(SRC_YUV_YUV2YUV)); //2020F->2020F
			}	
			else
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2YUV,sizeof(SRC_YUV_YUV2YUV)); //2020F->2020F
				//just keep
			}
			break;
		case E_2020YC_LIMITED:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_2020YC_LIMITED)//pre
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2YUV,sizeof(SRC_YUV_YUV2YUV)); //2020CL->2020CL
			}
			else
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2YUV,sizeof(SRC_YUV_YUV2YUV)); //2020CL->2020CL
				//just keep
			}	
			break;
		case E_2020YC_FULL:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_2020YC_FULL)//pre
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2YUV,sizeof(SRC_YUV_YUV2YUV)); //2020CF->2020CF
			}
			else
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2YUV,sizeof(SRC_YUV_YUV2YUV)); //2020CF->2020CF
				//just keep
			}	
			break;
		case E_RGB_LIMITED:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_RGB_LIMITED)//pre
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_RGB_YUV2RGB,sizeof(SRC_RGB_YUV2RGB)); //RGBL->RGBL
			}		
			else
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_RGB_YUV2RGB,sizeof(SRC_RGB_YUV2RGB)); //RGBL->RGBL
				//just keep
			}
			break;
		case E_RGB_FULL:
			if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==E_RGB_FULL)//pre
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_RGB_YUV2RGB,sizeof(SRC_RGB_YUV2RGB)); //RGBF->RGBF
			}
			else
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_RGB_YUV2RGB,sizeof(SRC_RGB_YUV2RGB)); //RGBF->RGBF
				//just keep
			}
			break;
		default:
			{
				x_memcpy(DRVCUST_Matrix[E_MTX_OS],SRC_YUV_YUV2RGBEXTLVL,sizeof(SRC_YUV_YUV2RGBEXTLVL)); //601l->RGBF
			}
			break;

	}
	//from S setting
	for(i=0; i<u1ConvTblParamIDX;i++)
	{
		if((CUST_COL_CONV_TABLE_PARAM[i].input==u1Input)&&(CUST_COL_CONV_TABLE_PARAM[i].type==E_MODIFY_BY_MATRIX_COEFFICIENT))
		{
				if(CUST_COL_CONV_TABLE_PARAM[i].block==E_MTX_OS)
				{
					x_memcpy(DRVCUST_Matrix[E_MTX_OS],CUST_COL_CONV_TABLE_PARAM[i].matrix,sizeof(UINT32)*15);
				}
		}
	}
	for (i=0;i<15;i++)
	{
		LOG(1, "DRVCUST_Matrix[E_MTX_OS][%d]=%d\n",i,DRVCUST_Matrix[E_MTX_OS][i]);
	}

}

void DRVCUST_GetConTblMtxDFT_XV1(UINT8 u1Input)
{
	UINT8 i,j;
	INT32 u4MtxBuff[15];
	//from M setting
	if(u1CONV_TBL_DFT[u1Input][E_MTX_OS]==u1CONV_TBL_DFT[u1Input][E_MTX_XV1])
	{
		for(i=0;i<15;i++)
		{
			DRVCUST_Matrix[E_MTX_XV1][i]=0;
		}
	}
	else
	{
		//from S setting
		for(i=0; i<u1ConvTblParamIDX;i++)
		{
			if((CUST_COL_CONV_TABLE_PARAM[i].input==u1Input)&&(CUST_COL_CONV_TABLE_PARAM[i].type==E_MODIFY_BY_MATRIX_COEFFICIENT))
			{
					if(CUST_COL_CONV_TABLE_PARAM[i].block==E_MTX_XV1)
					{
						x_memcpy(DRVCUST_Matrix[E_MTX_XV1],CUST_COL_CONV_TABLE_PARAM[i].matrix,sizeof(UINT32)*15);
					}
			}
		}
	}
	for (i=0;i<9;i++)
	{
		LOG(1, "DRVCUST_Matrix[E_MTX_XV1][%d]=%d\n",i,DRVCUST_Matrix[E_MTX_XV1][i]);
		DEFAULT_XVYCC_MATRIX[i]=DRVCUST_Matrix[E_MTX_XV1][i];
	}       
	LOG(1,"u1CONV_TBL_DFT[u1Input][E_MTX_XV1]=%d,u1CONV_TBL_DFT[u1Input][E_MTX_OS]=%d\n",u1CONV_TBL_DFT[u1Input][E_MTX_XV1],u1CONV_TBL_DFT[u1Input][E_MTX_OS]);
	
}

void DRVCUST_GetConTblMtxDFT_R2Y(UINT8 u1Input)
{
	UINT8 i,j;
	INT32 u4MtxBuff[15];
	//from M setting
	if(u1CONV_TBL_DFT[u1Input][E_MTX_XV1]==u1CONV_TBL_DFT[u1Input][E_MTX_R2Y])
	{
		vOSTG_IO32WriteFldAlign(OSTG_01, 0, REG_RGB2YUV_EN);
	}
	else
	{
		switch (u1CONV_TBL_DFT[u1Input][E_MTX_XV1])
		{
			case E_RGB_FULL:
				if(u1CONV_TBL_DFT[u1Input][E_MTX_R2Y]==E_601_LIMITED) 
				{
					vOSTG_IO32WriteFldAlign(OSTG_01, 1, REG_RGB2YUV_EN);
					vOSTG_IO32WriteFldAlign(OSTG_01, 2, R_R2Y_TABLE_SEL);
				}
					
				else if(u1CONV_TBL_DFT[u1Input][E_MTX_R2Y]==E_601_FULL) 
				{
					vOSTG_IO32WriteFldAlign(OSTG_01, 1, REG_RGB2YUV_EN);
					vOSTG_IO32WriteFldAlign(OSTG_01, 0, R_R2Y_TABLE_SEL);
				}	
				else if(u1CONV_TBL_DFT[u1Input][E_MTX_R2Y]==E_709_LIMITED) 
				{
					vOSTG_IO32WriteFldAlign(OSTG_01, 1, REG_RGB2YUV_EN);
					vOSTG_IO32WriteFldAlign(OSTG_01, 3, R_R2Y_TABLE_SEL);
				}	
				else if(u1CONV_TBL_DFT[u1Input][E_MTX_R2Y]==E_709_FULL) 
				{
					vOSTG_IO32WriteFldAlign(OSTG_01, 1, REG_RGB2YUV_EN);
					vOSTG_IO32WriteFldAlign(OSTG_01, 1, R_R2Y_TABLE_SEL);
				}
				else
				{
					vOSTG_IO32WriteFldAlign(OSTG_01, 0, REG_RGB2YUV_EN);
				}
				break;
			default:
				{
					vOSTG_IO32WriteFldAlign(OSTG_01, 0, REG_RGB2YUV_EN);
				}
				break;
		}
	}
	//from S setting
	LOG(1,"u1CONV_TBL_DFT[u1Input][E_MTX_XV1]=%d,u1CONV_TBL_DFT[u1Input][E_MTX_R2Y]=%d\n",u1CONV_TBL_DFT[u1Input][E_MTX_XV1],u1CONV_TBL_DFT[u1Input][E_MTX_R2Y]);
	LOG(0,"only u1CONV_TBL_DFT[u1Input][E_MTX_XV1]=10(RGB_F) can be set \n");
}

BOOL DRVCUST_GetDVMMPInputFlag(void)
{
	if((DRVCUST_MMGetHDRType(SV_VP_MAIN)==SV_HDR_TYPE_HDR3)&&(bGetSignalType(SV_VP_MAIN)==SV_ST_MPEG))
	{
		return SV_TRUE;
		LOG(2, "\n====== DV input case true ======\n");
	}
	else
	{
		return SV_FALSE;
		LOG(2, "\n====== DV input case false ======\n");
	}
}

void DRVCUST_EdidUpdateNotify(void)
{
    LOG(0,"%s\n", __FUNCTION__);
	if (sony_be_ext_func)
	{
		sony_be_ext_func->be_ext_edid_write();
	}
}

void DRVCUST_SetHdmiCcirDither(UINT8 bPath)
{
	UINT8 u1HDR_Type = DRVCUST_HDMIGetHDRType(bPath);
	UINT8 u1ActivePort;
	u1ActivePort = (UINT8)eActiveHdmiPort[bPath];
	if(u1HDR_Type == 3)//DV
	{
		#ifdef CC_SUPPORT_DOLBY_VISION
		if(u4DolbyGetIdkVersion()>1)//1.5.1 CCIR off
		{
			vCCIR2SetDither(bPath, SV_OFF);
		}
		else
		#endif
		{
			vCCIR2SetDither(bPath, SV_ON);
		}
	}
	else
	{
		vCCIR2SetDither(bPath, SV_ON);
	}

}

void DRVCUST_GetDitherSetting(UINT8 bPath)
{
	UINT8 u1ColorFMT;
	CUST_SIG_FMT_T pSignalFormat;
	CUST_DITHER_T dither[E_CUST_DITHER_BLOCK_MAX];
	DRVCUST_GetSignalFormat(bPath, &pSignalFormat);
	Printf("eColorFormat	    %d\n", pSignalFormat.eColorFormat);
	dither[E_CUST_DITHER_BLOCK_CCIR0].onoff = (IO32ReadFldAlign(CCIR_DITHER_EN, CCIR0_DITHER_EN)&&IO32ReadFldAlign(CCIR0_DITHER_00, CCIR0_DITHER_LFSR_EN));
	dither[E_CUST_DITHER_BLOCK_CCIR0].type  = IO32ReadFldAlign(CCIR0_DITHER_02, CCIR0_DRMOD_R)+1;
	dither[E_CUST_DITHER_BLOCK_CCIR1].onoff = (IO32ReadFldAlign(CCIR_DITHER_EN, CCIR1_DITHER_EN)&&IO32ReadFldAlign(CCIR1_DITHER_00, CCIR1_DITHER_LFSR_EN));
	dither[E_CUST_DITHER_BLOCK_CCIR1].type  = IO32ReadFldAlign(CCIR1_DITHER_02, CCIR1_DRMOD_R)+1;
	dither[E_CUST_DITHER_BLOCK_OSTG0].onoff = IO32ReadFldAlign(OS_DITHER_00, DITHER_LFSR_EN);
	dither[E_CUST_DITHER_BLOCK_OSTG0].type  = IO32ReadFldAlign(OS_DITHER_02, DRMOD_R)+1;
	dither[E_CUST_DITHER_BLOCK_OSTG1].onoff = dither[E_CUST_DITHER_BLOCK_OSTG0].onoff;//ch1 is the same setting as ch0
	dither[E_CUST_DITHER_BLOCK_OSTG1].type  = dither[E_CUST_DITHER_BLOCK_OSTG0].type;
	dither[E_CUST_DITHER_BLOCK_OSTG_POST0].onoff = IO32ReadFldAlign(OS_DITHER_03, REG_LFSR_EN_POST);
	dither[E_CUST_DITHER_BLOCK_OSTG_POST0].type  = IO32ReadFldAlign(OS_DITHER_05, REG_DRMOD_R_POST)+1;
	dither[E_CUST_DITHER_BLOCK_OSTG_POST1].onoff = dither[E_CUST_DITHER_BLOCK_OSTG_POST0].onoff;//ch1 is the same setting as ch0
	dither[E_CUST_DITHER_BLOCK_OSTG_POST1].type  = dither[E_CUST_DITHER_BLOCK_OSTG_POST0].type;
	Printf("BLOCK INDEX:\n");
	Printf("0:E_CUST_DITHER_BLOCK_CCIR0\n");
	Printf("1:E_CUST_DITHER_BLOCK_CCIR1\n");
	Printf("2:E_CUST_DITHER_BLOCK_OSTG0\n");
	Printf("3:E_CUST_DITHER_BLOCK_OSTG1\n");
	Printf("4:E_CUST_DITHER_BLOCK_OSTG_POST0\n");
	Printf("5:E_CUST_DITHER_BLOCK_OSTG_POST1\n");
	Printf("MODE INDEX:\n");
	Printf("0:E_DITHER_MODE_DISABLE\n");
	Printf("1:E_DITHER_MODE_ENABLE_12BIT\n");
	Printf("2:E_DITHER_MODE_ENABLE_10BIT\n");
	Printf("3:E_DITHER_MODE_ENABLE_8BIT\n");
	Printf("4:E_DITHER_MODE_ENABLE_6BIT\n");
	Printf("CCIR0     :		Enable(%d) Type(%d) %s\n", dither[E_CUST_DITHER_BLOCK_CCIR0].onoff,dither[E_CUST_DITHER_BLOCK_CCIR0].type,ucDither_Type[dither[E_CUST_DITHER_BLOCK_CCIR0].type]);
	Printf("CCIR1     :		Enable(%d) Type(%d) %s\n", dither[E_CUST_DITHER_BLOCK_CCIR1].onoff,dither[E_CUST_DITHER_BLOCK_CCIR1].type,ucDither_Type[dither[E_CUST_DITHER_BLOCK_CCIR1].type]);
	Printf("OSTG0     :		Enable(%d) Type(%d) %s\n", dither[E_CUST_DITHER_BLOCK_OSTG0].onoff,dither[E_CUST_DITHER_BLOCK_OSTG0].type,ucDither_Type[dither[E_CUST_DITHER_BLOCK_OSTG0].type]);
	Printf("OSTG1     :		Enable(%d) Type(%d) %s\n", dither[E_CUST_DITHER_BLOCK_OSTG1].onoff,dither[E_CUST_DITHER_BLOCK_OSTG1].type,ucDither_Type[dither[E_CUST_DITHER_BLOCK_OSTG1].type]);
	Printf("POST_OSTG0     :		Enable(%d) Type(%d) %s\n", dither[E_CUST_DITHER_BLOCK_OSTG_POST0].onoff,dither[E_CUST_DITHER_BLOCK_OSTG_POST0].type,ucDither_Type[dither[E_CUST_DITHER_BLOCK_OSTG_POST0].type]);
	Printf("POST_OSTG1     :		Enable(%d) Type(%d) %s\n", dither[E_CUST_DITHER_BLOCK_OSTG_POST1].onoff,dither[E_CUST_DITHER_BLOCK_OSTG_POST1].type,ucDither_Type[dither[E_CUST_DITHER_BLOCK_OSTG_POST1].type]);


}

void DRVCUST_SetDitherSetting(UINT8 onoff,UINT8 u1DitherBLK,UINT8 u1DitherMode)
{
	Printf("BLOCK INDEX:\n");
	Printf("0:E_CUST_DITHER_BLOCK_CCIR0\n");
	Printf("1:E_CUST_DITHER_BLOCK_CCIR1\n");
	Printf("2:E_CUST_DITHER_BLOCK_OSTG0\n");
	Printf("3:E_CUST_DITHER_BLOCK_OSTG1\n");
	Printf("4:E_CUST_DITHER_BLOCK_OSTG_POST0\n");
	Printf("5:E_CUST_DITHER_BLOCK_OSTG_POST1\n");
	Printf("MODE INDEX:\n");
	Printf("0:E_DITHER_MODE_DISABLE\n");
	Printf("1:E_DITHER_MODE_ENABLE_12BIT\n");
	Printf("2:E_DITHER_MODE_ENABLE_10BIT\n");
	Printf("3:E_DITHER_MODE_ENABLE_8BIT\n");
	Printf("4:E_DITHER_MODE_ENABLE_6BIT\n");
	
	Printf("\nCurrent setting is BLK: %d Mode:%d\n",u1DitherBLK,u1DitherMode);
	
	if((u1DitherBLK==E_CUST_DITHER_BLOCK_CCIR0)||(u1DitherBLK==E_CUST_DITHER_BLOCK_CCIR1))
	{
		if(u1DitherMode == E_DITHER_MODE_ENABLE_10BIT)
		{
			vCCIR2SetDither(SV_VP_MAIN,onoff);
		}
		else
		{
			printf("CCIR need to set 12 to 10 only\n");
		}
	}
	else if((u1DitherBLK==E_CUST_DITHER_BLOCK_OSTG0) ||(u1DitherBLK==E_CUST_DITHER_BLOCK_OSTG1))
	{
		vOSTG_IO32WriteFldAlign(OS_DITHER_00, onoff, DITHER_LFSR_EN);
		vOSTG_IO32WriteFldAlign(OS_DITHER_02, u1DitherMode-1, DRMOD_R);
		vOSTG_IO32WriteFldAlign(OS_DITHER_02, u1DitherMode-1, DRMOD_G);
		vOSTG_IO32WriteFldAlign(OS_DITHER_02, u1DitherMode-1, DRMOD_B);//ch0 and ch1 should be the same
		
	}
	else if((u1DitherBLK==E_CUST_DITHER_BLOCK_OSTG_POST0) ||(u1DitherBLK==E_CUST_DITHER_BLOCK_OSTG_POST1))
	{
		vOSTG_IO32WriteFldAlign(OS_DITHER_03, onoff, REG_LFSR_EN_POST);
		vOSTG_IO32WriteFldAlign(OS_DITHER_05, u1DitherMode-1, REG_DRMOD_R_POST);
		vOSTG_IO32WriteFldAlign(OS_DITHER_05, u1DitherMode-1, REG_DRMOD_G_POST);
		vOSTG_IO32WriteFldAlign(OS_DITHER_05, u1DitherMode-1, REG_DRMOD_B_POST);//ch0 and ch1 should be the same
		
	}
	else
	{
		printf("u1DitherBLK need to set 0~5 only	    %d\n");
	}
	
	

}

void DRVCUST_SetOSDIndexEnable(UINT8 u1OnOff)
{

	vIO32WriteFldAlign(OSD_MIX_2, u1OnOff,REG_OSD_INDEX_EN);

}

void DRVCUST_SetAddtionalRestrictionCondition(E_CUST_RESTRICT_COND eAddCondition)
{
    UINT8 bSigMode;

    if(eAddCondition > E_CUST_RESTRICT_COND_BE_VIDEO_PATH_3)
    {
        LOG(0,"Invalid Add condition:%d \n",eAddCondition);
    }
    su1AddCondition = eAddCondition;

    bSigMode = bDrvVideoSignalStatus(SV_VP_MAIN);
    if(bSigMode == (UINT8)SV_VDO_STABLE)
    {
       //not notify when DTV input now move into api_notify layer
       UINT8 rep = (!fgSkipNptvNfy()) || (!fgIsMainTvd3d());
       rep |= 0x80;
       LOG(0,"bSigMode:%d rep:%d \n",fgSkipNptvNfy(),fgIsMainTvd3d());
       vApiNotifySigChg(SV_VP_MAIN,bSigMode,rep);
    }
    else
    {
        LOG(0,"Set condition with unstable:%d \n",bSigMode);
    }
}

UINT8 DRVCUST_GetAddtionalRestrictionCondition(void)
{
    return su1AddCondition;
}


#ifdef CC_SUPPORT_PHOTO8K

void DRVCUST_RegisterDivPhotoFunc(CUST_DIVPHOTO_FUNC_TBL_T *pDivPhotoFuncTbl)
{
    LOG(0,"DRVCUST_RegisterDivPhotoFunc \n");
    if(pDivPhotoFuncTbl == NULL)
    {
        //when the timing of deinitialize, this function will called with NULL parameter.
        x_memset(&stDivPhotoFuncTbl,0,sizeof(CUST_DIVPHOTO_FUNC_TBL_T));
        x_memset(&stDivPhotoFuncTblCrc,0,sizeof(CUST_DIVPHOTO_FUNC_TBL_T));
        LOG(1,"deinitialize Div Photo Func \n");
    }
    else
    {
        stDivPhotoFuncTbl.GetVB1Mode = pDivPhotoFuncTbl->GetVB1Mode;
        stDivPhotoFuncTblCrc.GetVB1Mode = ~(UPTR)(pDivPhotoFuncTbl->GetVB1Mode);

        stDivPhotoFuncTbl.ReplyVB1ModeChange = pDivPhotoFuncTbl->ReplyVB1ModeChange;
        stDivPhotoFuncTblCrc.ReplyVB1ModeChange = ~(UPTR)(pDivPhotoFuncTbl->ReplyVB1ModeChange);

        stDivPhotoFuncTbl.GetState = pDivPhotoFuncTbl->GetState;
        stDivPhotoFuncTblCrc.GetState = ~(UPTR)(pDivPhotoFuncTbl->GetState);

        stDivPhotoFuncTbl.ReplyStateChange = pDivPhotoFuncTbl->ReplyStateChange;
        stDivPhotoFuncTblCrc.ReplyStateChange = ~(UPTR)(pDivPhotoFuncTbl->ReplyStateChange);

        stDivPhotoFuncTbl.GetMetaInfo = pDivPhotoFuncTbl->GetMetaInfo;
        stDivPhotoFuncTblCrc.GetMetaInfo = ~(UPTR)(pDivPhotoFuncTbl->GetMetaInfo);

        stDivPhotoFuncTbl.GetFadeDuration = pDivPhotoFuncTbl->GetFadeDuration;
        stDivPhotoFuncTblCrc.GetFadeDuration = ~(UPTR)(pDivPhotoFuncTbl->GetFadeDuration);

        LOG(1,"init Div Photo Func \n");
    }
}

UINT32 DRVCUST_GetVB1Mode(void)
{
    UINT32 u4Vb1Mode;
    LOG(0,"DRVCUST_GetVB1Mode \n");

    if(!VDP_CHECK_CB_FUNC_VERIFY(stDivPhotoFuncTbl.GetVB1Mode,stDivPhotoFuncTblCrc.GetVB1Mode))
    {
        //  When callback function is not registered, please return 0.
        LOG(0,"[%s] Call back not registerd \n",__FUNCTION__);
        return 0;
    }

    u4Vb1Mode = stDivPhotoFuncTbl.GetVB1Mode();

    return u4Vb1Mode;
}

void DRVCUST_ReplyVB1ModeChange(BOOL bResult)
{
    LOG(0,"DRVCUST_ReplyVB1ModeChange \n");

    if(!VDP_CHECK_CB_FUNC_VERIFY(stDivPhotoFuncTbl.ReplyVB1ModeChange,stDivPhotoFuncTblCrc.ReplyVB1ModeChange))
    {
        //  When callback function is not registered, please return this function without doing anything.
        LOG(0,"[%s] Call back not registerd \n",__FUNCTION__);
        return;
    }

    stDivPhotoFuncTbl.ReplyVB1ModeChange(bResult);
}

UINT32 DRVCUST_GetDivPhotoState(void)
{
    UINT32 u4DivPhotoState;
    LOG(0,"DRVCUST_GetDivPhotoState \n");

    if(!VDP_CHECK_CB_FUNC_VERIFY(stDivPhotoFuncTbl.GetState,stDivPhotoFuncTblCrc.GetState))
    {
        //  When callback function is not registered, please return 0.
        LOG(0,"[%s] Call back not registerd \n",__FUNCTION__);
        return 0;
    }

    u4DivPhotoState = stDivPhotoFuncTbl.GetState();

    return u4DivPhotoState;
}

void DRVCUST_ReplyDivPhotoStateChange( UINT32 u4State, BOOL  bResult)
{
    LOG(0,"DRVCUST_ReplyDivPhotoStateChange \n");

    if(!VDP_CHECK_CB_FUNC_VERIFY(stDivPhotoFuncTbl.ReplyStateChange,stDivPhotoFuncTblCrc.ReplyStateChange))
    {
        //  When callback function is not registered, please return this function without doing anything.
        LOG(0,"[%s] Call back not registerd \n",__FUNCTION__);
        return;
    }

    stDivPhotoFuncTbl.ReplyStateChange(u4State,bResult);
}

void DRVCUST_GetDivPhotoMetaInfo(CUST_DIVPHOTO_META_INFO_T *pDivPhotoMetainfo)
{
    LOG(0,"DRVCUST_GetDivPhotoMetaInfo \n");

    if(!VDP_CHECK_CB_FUNC_VERIFY(stDivPhotoFuncTbl.GetMetaInfo,stDivPhotoFuncTblCrc.GetMetaInfo))
    {
        //  When callback function is not registered, please return this function without doing anything.
        LOG(0,"[%s] Call back not registerd \n",__FUNCTION__);
        return;
    }

    stDivPhotoFuncTbl.GetMetaInfo(pDivPhotoMetainfo);
}

UINT32  DRVCUST_GetDivPhotoFadeDuration(void)
{
    UINT32 u4FadeDuration;
    LOG(0,"DRVCUST_GetDivPhotoFadeDuration \n");

    if(!VDP_CHECK_CB_FUNC_VERIFY(stDivPhotoFuncTbl.GetFadeDuration,stDivPhotoFuncTblCrc.GetFadeDuration))
    {
        //  When callback function is not registered, please return 0.
        LOG(0,"[%s] Call back not registerd \n",__FUNCTION__);
        return 0;
    }

    u4FadeDuration = stDivPhotoFuncTbl.GetFadeDuration();

    return u4FadeDuration;
}

void DRVCUST_SetB2RPhotoMode(UINT32 u4Mode)
{
    LOG(0,"DRVCUST_SetB2RPhotoMode \n");

    if(u4Mode >= E_CUST_UNKNOWN_PHOTO_MODE)
    {
        LOG(0,"Unknown B2R photo mode \n");
        return;
    }

    VDP_B2R_SetPhotoMode(VDP_1,u4Mode);
}

void DRVCUST_SetB2RDivPhotoState(UINT32 u4DivPhotoState)
{
    LOG(0,"DRVCUST_SetB2RDivPhotoState \n");

    if(u4DivPhotoState >= E_CUST_DIV_UNKNOWN)
    {
        LOG(0,"Unknown B2R div photo state \n");
    }

    LOG(0,"st:%d h:%d v:%d \n",u4DivPhotoState,stDivPhotoRegion[u4DivPhotoState].u4HRegion,
                stDivPhotoRegion[u4DivPhotoState].u4VRegion);
    CLIP(u4DivPhotoState, 0, E_CUST_DIV_UNKNOWN);
    VDP_B2R_SetDivPhotoState(VDP_1, stDivPhotoRegion[u4DivPhotoState].u4HRegion,
                stDivPhotoRegion[u4DivPhotoState].u4VRegion);
}

#endif


void DRVCUST_MEMC_GetSonyParams(MailBoxCb callback, UINT32 req_id)
{
	UINT8 u1RetSts=0;
	mtk_params m_params;
	
	vMjcGetParams(callback, req_id, &m_params);
}

void DRVCUST_MEMC_GetBlackBeltPosition(MailBoxCb callback, UINT32 req_id)
{
	UINT8 u1RetSts=0;
	CUST_MEMC_BLACK_BELT_T stMEMCBlackBelt;
	
	vMjcGetBlackBeltPosition(callback, req_id, &stMEMCBlackBelt);

}

void DRVCUST_MEMC_GetEndCreditRollFlag(MailBoxCb callback, UINT32 req_id)
{
	UINT8 u1RetSts=0;
	UINT8 EndCreditRollFlag;
	UINT8 u1Ret=0;

	vMjcGetEndCreditRollFlag(callback, req_id, &EndCreditRollFlag);

}

void DRVCUST_MEMC_GetTelopFlag(MailBoxCb callback, UINT32 req_id)
{
	UINT8 u1RetSts=0;
	UINT8 GetTelopFlag;
	UINT8 u1Ret=0;

	vMjcGetTelopFlag(callback, req_id, &GetTelopFlag);

}


void DRVCUST_MEMC_VideoDelayAdjustment(MailBoxCb callback, UINT32 req_id, UINT16 u2AdditionalDelay)
{
	UINT16 u2AdditionalDelayReturn;
	
	LOG(1,"[%s] AdditionalDelay input:%d \n",__FUNCTION__, u2AdditionalDelay);

    vMjcVideoDelayAdjustment(callback, req_id, u2AdditionalDelay, &u2AdditionalDelayReturn);


}


void DRVCUST_MEMC_SetVideoFormat(UINT8 u1InputWidth,UINT8 u1OutputWidth,UINT8 u1InputFrequency,UINT8 u1OutputFrequency)
{
	LOG(1,"[%s] InW:%d OutH:%d InFR:%d OutFR:%D \n",__FUNCTION__,
		u1InputWidth, u1OutputWidth, u1InputFrequency, u1OutputFrequency);

	vMjcSetVideoFormat(u1InputWidth, u1OutputWidth, u1InputFrequency, u1OutputFrequency);
}

void DRVCUST_MEMC_SetVideoMode(UINT8 u1Mode)
{
	LOG(1,"[%s] Mode:%d \n",__FUNCTION__, u1Mode);

	vMjcSetVideoMode(u1Mode);
}

void DRVCUST_MEMC_SetOsdBypassWin(MailBoxCb callback, UINT32 req_id, UINT8 u1WinID,UINT8 u1WinEn,UINT16 u2WinStartX,UINT16 u2WinStartY,UINT16 u2WinWidth,UINT16 u2WinHeight)
{
	LOG(1,"[%s] WinID:%d WinEn:%d WinX:%d WinY:%d WinW:%d WinH:%d \n",__FUNCTION__,
		u1WinID, u1WinEn, u2WinStartX, u2WinStartY, u2WinWidth, u2WinHeight);

	vMjcSetOsdBypassWin(callback, req_id, u1WinID, u1WinEn, u2WinStartX, u2WinStartY, u2WinWidth, u2WinHeight);
}

void DRVCUST_MEMC_SetMfcDemo(MailBoxCb callback, UINT32 req_id, UINT8 u1DemoMode,UINT8 u1BoarderLineWidth,UINT8 u1BoarderColor)
{
	LOG(1,"[%s] DemoMode:%d UINT8 BoarderLineWidth:%d BoarderColor:%d \n",__FUNCTION__,
		u1DemoMode, u1BoarderLineWidth, u1BoarderColor);

	vMjcSetMfcDemo(callback, req_id, u1DemoMode, u1BoarderLineWidth, u1BoarderColor);
}

void DRVCUST_MEMC_FilmCadanceControl(MailBoxCb callback, UINT32 req_id, UINT16 u2CadenceEnable)
{
	LOG(1,"[%s] CadenceEn:%d \n",__FUNCTION__, u2CadenceEnable);

	vMjcFilmCadanceControl(callback, req_id, u2CadenceEnable);
}

void DRVCUST_MEMC_DeflickerControl(MailBoxCb callback, UINT32 req_id, UINT8 u1DeflickerLevel,
	UINT8 u1AutoThLUp,UINT8 u1AutoThMUp,UINT8 u1AutoThHUp,UINT8 u1AutoThLDown,UINT8 u1AutoThMDown,UINT8 u1AutoThHDown)
{
	LOG(0,"[%s][reserved] DeflickerLevel:%d \n",__FUNCTION__, u1DeflickerLevel);
	LOG(0,"[%s][reserved] AutoLUp:%d AutoMUp:%d AutoHUp:%d AutoLDown:%d AutoMDown:%d AutoHDown:%d \n",__FUNCTION__, 
		u1AutoThLUp, u1AutoThMUp, u1AutoThHUp, u1AutoThLDown, u1AutoThMDown, u1AutoThHDown);

	vMjcDeflickerControl(callback, req_id, u1DeflickerLevel, u1AutoThLUp, u1AutoThMUp, u1AutoThHUp, u1AutoThLDown, u1AutoThMDown, u1AutoThHDown);
}

void DRVCUST_MEMC_Set_RelPosRatioIndex(MailBoxCb callback, UINT32 req_id, UINT8 u1Index)
{
	LOG(1,"[%s] Idx:%d \n",__FUNCTION__, u1Index);

	vMjcSet_RelPosRatioIndex(callback, req_id, u1Index);
}

void DRVCUST_MEMC_SetChaosLevelKeep(MailBoxCb callback, UINT32 req_id, UINT8 u1KeepValue)
{
	LOG(1,"[%s] KeepValue:%d \n",__FUNCTION__, u1KeepValue);

	vMjcSetChaosLevelKeep(callback, req_id, u1KeepValue);
}

void DRVCUST_MEMC_SetBlackBeltSel(MailBoxCb callback, UINT32 req_id, UINT8 u1Sel)
{
	LOG(1,"[%s] Sel:%d \n",__FUNCTION__,u1Sel);

	vMjcSetBlackBeltSel(callback, req_id, u1Sel);
}

void DRVCUST_MEMC_FunctionEnable(MailBoxCb callback, UINT32 req_id, UINT8 u1FunctionSel,UINT8 u1Enable,UINT8 u1Parameter1)
{
	LOG(1,"[%s] FuncSel:%d Em:%d Para:%d \n",__FUNCTION__, u1FunctionSel, u1Enable, u1Parameter1);

	vMjcFunctionEnable(callback, req_id, u1FunctionSel, u1Enable, u1Parameter1);
}

void DRVCUST_MEMC_OriInputResolutionInfo(MailBoxCb callback, UINT32 req_id, UINT16 u2Width,UINT16 u2Height)
{
	LOG(1,"[%s] W:%d H:%d \n",__FUNCTION__, u2Width, u2Height);

	vMjcOriInputResolutionInfo(callback, req_id, u2Width, u2Height);
}

void DRVCUST_MEMC_SetModelName(MailBoxCb callback, UINT32 req_id, UINT8 u1ModelName,UINT8 u1PanelSize,UINT8 u1BackLightType)
{
	LOG(1,"[%s] ModelName:%d PnlSize:%d BackLightType:%d \n",__FUNCTION__, u1ModelName, u1PanelSize, u1PanelSize);

	vMjcSetModelName(callback, req_id, u1ModelName, u1PanelSize, u1PanelSize);
}

void DRVCUST_MEMC_PicMode(UINT8 u1PictureMode)
{
	LOG(1,"[%s] PicMode:%d \n",__FUNCTION__, u1PictureMode);

	vMjcPicMode(u1PictureMode);
}

void DRVCUST_MEMC_ImpremetationFrame(MailBoxCb callback, UINT32 req_id, UINT8 u1Enable,UINT8 u1Index)
{
	LOG(1,"[%s] En:%d Idx:%d \n",__FUNCTION__, u1Enable, u1Index);

	vMjcImpremetationFrame(callback, req_id, u1Enable, u1Index);
}

void DRVCUST_MEMC_PositionRatioTable(MailBoxCb callback, UINT32 req_id, UINT8 u1Enable)
{
	LOG(1,"[%s] En:%d \n",__FUNCTION__, u1Enable);

	vMjcPositionRatioTable(callback, req_id, u1Enable);
}

void DRVCUST_MEMC_ShowfileCadenceErrorEnable(MailBoxCb callback, UINT32 req_id, UINT8 u1Enable)
{
	LOG(1,"[%s] En:%d \n",__FUNCTION__, u1Enable);

	vMjcShowfileCadenceErrorEnable(callback, req_id, u1Enable);
}

void DRVCUST_RequestSpecialPostMute(BOOL bEnable)
{
    LOG(0,"DRVCUST_RequestSpecialPostMute %d \n",bEnable);
    u4DrvSetVideoSpecialMute(bEnable);
}


//table num 0:4k2kHFR 1:other
void DRVCUST_SetVDECSignalPath(UINT32 num,UINT32 path)
{
    LOG(0,"DRVCUST_SetVDECSignalPath num:%d path:%d \n",num,path);
    vDrvSetVDECSignalPath(num,path);
}

UINT32 DRVCUST_GetVDECSignalPath(UINT32 num)
{
    LOG(3,"DRVCUST_GetVDECSignalPath num:%d \n",num);
    return u4DrvGetVDECSignalPath(num);
}

void vDrvLCEUpdateBitPlusParam(void)
{
#ifdef CC_LCE_SUPPORT
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_00, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_BITPLUS_AVG_FLT_EN), LCC_DRE_BITPLUS_AVG_FLT_EN); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_00, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_BITPLUS_DETECT_EN), LCC_DRE_BITPLUS_DETECT_EN); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_03, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_BITPLUS_HIGH_LVL_OUT_OFT), LCC_DRE_BITPLUS_HIGH_LVL_OUT_OFT); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_03, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_BITPLUS_HIGH_LVL_PXL_SLOPE), LCC_DRE_BITPLUS_HIGH_LVL_PXL_SLOPE); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_03, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_BITPLUS_HIGH_LVL_PXL_TH), LCC_DRE_BITPLUS_HIGH_LVL_PXL_TH); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_04, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_BITPLUS_TO_ALI_WGT), LCC_DRE_BITPLUS_TO_ALI_WGT); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_10, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_DIFF_SLOPE), LCC_DRE_DIFF_SLOPE); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_10, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_DIFF_TH), LCC_DRE_DIFF_TH); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_10, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_DIFF_WGT), LCC_DRE_DIFF_WGT); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_11, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_BITPLUS_CHROMA_SLOPE), LCC_DRE_BITPLUS_CHROMA_SLOPE); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_11, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_BITPLUS_CHROMA_TH2), LCC_DRE_BITPLUS_CHROMA_TH2); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_11, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_BITPLUS_CHROMA_TH1), LCC_DRE_BITPLUS_CHROMA_TH1); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_11, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_BITPLUS_CHROMA_VWIN_SEL), LCC_DRE_BITPLUS_CHROMA_VWIN_SEL); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_12, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_CONTOUR_RANGE_SLOPE1), LCC_DRE_CONTOUR_RANGE_SLOPE1); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_12, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_CONTOUR_RANGE_TH1), LCC_DRE_CONTOUR_RANGE_TH1); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_12, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_DIFFCOUNT_SLOPE1), LCC_DRE_DIFFCOUNT_SLOPE1); 
	vIO32WriteFldAlign(LCC_DISP_AAL_DRE_BITPLUS_12, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_DRE_DIFFCOUNT_TH1), LCC_DRE_DIFFCOUNT_TH1);
#endif	
	vIO32WriteFldAlign(SCE_CFG_MAIN, wReadQualityTable(QUALITY_BITPLUS_IN_LCE_C_LUMA_HIST_IN_SEL), C_LUMA_HIST_IN_SEL);           
}

BOOL DRVCUST_MEMC_SetMode(UINT8 u1MEMCMode, UINT8 u1ColorMode)
{
	LOG(1,"[%s] Set MEMC Mode:%d, MEMC Colorimetry:%d\n",__FUNCTION__, u1MEMCMode, u1ColorMode);

	return vMjcSetMode(u1MEMCMode, u1ColorMode);

}

void DRVCUST_MEMC_GetMode(UINT8 *u1MEMCMode, UINT8 *u1ColorMode)
{
	vMjcGetMode(u1MEMCMode, u1ColorMode);
	LOG(1,"[%s] Get MEMC Mode:%d, MEMC Colorimetry:%d\n",__FUNCTION__, *u1MEMCMode, *u1ColorMode);
}

UINT8 IsSrcHDMI(D_AP_INPUT_GRP_T eSrc)
{
    if(eSrc == D_AP_INPUT_GRP_HDMI1 || eSrc == D_AP_INPUT_GRP_HDMI2 || 
        eSrc == D_AP_INPUT_GRP_HDMI3 || eSrc == D_AP_INPUT_GRP_HDMI4)
    {
        return SV_TRUE;
    }
    else
    {
        return SV_FALSE;
    }
}

UINT8 IsSrcComp(D_AP_INPUT_GRP_T eSrc)
{
    //composite & component
    if(eSrc == D_AP_INPUT_GRP_AV1 || eSrc == D_AP_INPUT_GRP_AV2 || 
        eSrc == D_AP_INPUT_GRP_COMPONENT)
    {
        return SV_TRUE;
    }
    else
    {
        return SV_FALSE;
    }
}

UINT8 IsSrcDigital(D_AP_INPUT_GRP_T eSrc)
{
    /*
    usb  application
    broadcast dtv/atv
    iptv application/gen app
    general gen app/netflix
    photo   photo
    game    JELLYFISH
    */
    if(eSrc == D_AP_INPUT_GRP_APPLICATION || eSrc == D_AP_INPUT_GRP_GENERAL_APP ||
        eSrc == D_AP_INPUT_GRP_DTV || eSrc == D_AP_INPUT_GRP_ATV ||
        eSrc == D_AP_INPUT_GRP_NETFLIX || eSrc == D_AP_INPUT_GRP_SONY_PHOTO_APP ||
        eSrc == D_AP_INPUT_GRP_SONY_JELLYFISH)
    {
        return SV_TRUE;
    }
    else
    {
        return SV_FALSE;
    }
}

UINT8 IsSpePicMode(D_AP_PIC_MODE ePicMode)
{
    if(ePicMode == D_AP_PIC_MODE_GAME || ePicMode == D_AP_PIC_MODE_GRAPHICS || 
        ePicMode == D_AP_PIC_MODE_PHOTO)
    {
        return SV_TRUE;
    }
    else
    {
        return SV_FALSE;
    }
}

UINT8 u1DbgMemcMode = DRV_CUSTOM_MEMC_MODE_END;
UINT8 u1DbgColorMode = DRV_CUSTOM_MEMC_COLOR_MODE_END;
UINT8 u1DbgMemcDynModeFix = DRV_CUSTOM_MEMC_MODE_END;
UINT8 u1DbgMemcDynColorFix = DRV_CUSTOM_MEMC_COLOR_MODE_END;


void DRVCUST_MEMC_CalDynMode(void)
{
    UINT8 u1MEMCMode = DRV_CUSTOM_MEMC_MODE_END;
    UINT8 u1ColorMode = DRV_CUSTOM_MEMC_COLOR_MODE_END;

    UINT8 u1CurMEMCMode, u1CurColorMode;

    //signal stable check.
    //type3 or internale memc check

    if(bDrvVideoSignalStatus(VDP_1) != SV_VDO_STABLE)
    {
        LOG(0,"Signal unstable, ignore memc mode update \n");
        return;
    }

    if(IS_DISP_4K2K_TYPE3 || !DRVCUST_Get_InterMemc_type())
    {
        LOG(0,"not support intr memc, ignore memc mode update \n");
        return;
    }

    if((u1DbgMemcDynModeFix < DRV_CUSTOM_MEMC_MODE_END) && 
        (u1DbgMemcDynColorFix < DRV_CUSTOM_MEMC_COLOR_MODE_END))
    {
        LOG(0,"cli fix memc Dynamic mode \n");
        DRVCUST_MEMC_SetMode(u1DbgMemcDynModeFix, u1DbgMemcDynColorFix);
        return;
    }

    if(((GetPANEL4K2K_TYPE() == PANEL_TYPE_2K1K_120) || (GetPANEL4K2K_TYPE() == PANEL_TYPE_4K1K_120)) && !fgApiVideoIsVgaTiming(VDP_1))
    {
        u1MEMCMode = DRV_CUSTOM_4k1k_REPEAT_MODE;

        if(IsSrcHDMI(_stMemcModeInfo.u1MemcSrc.eMainInputType))
        {
            u1ColorMode = DRV_CUSTOM_RGB444_MODE;
        }
        else if(IsSrcDigital(_stMemcModeInfo.u1MemcSrc.eMainInputType))
        {
            u1ColorMode = DRV_CUSTOM_YUV422_MODE;
        }
    }
    else if(IsSpePicMode(_stMemcModeInfo.u1MemcPicMode))
    {
        u1MEMCMode = DRV_CUSTOM_REPEAT_MODE;

        if(IsSrcHDMI(_stMemcModeInfo.u1MemcSrc.eMainInputType) ||
            IsSrcComp(_stMemcModeInfo.u1MemcSrc.eMainInputType))
        {
            u1ColorMode = DRV_CUSTOM_RGB444_MODE;
        }
        else if(IsSrcDigital(_stMemcModeInfo.u1MemcSrc.eMainInputType))
        {
            u1ColorMode = DRV_CUSTOM_YUV422_MODE;
        }
    }
    else
    {
        if(IsSrcHDMI(_stMemcModeInfo.u1MemcSrc.eMainInputType) ||
            IsSrcComp(_stMemcModeInfo.u1MemcSrc.eMainInputType) ||
            IsSrcDigital(_stMemcModeInfo.u1MemcSrc.eMainInputType))
        {
            //non standard src, not update memc mode.
            u1MEMCMode = DRV_CUSTOM_NORMAL_MODE;
            u1ColorMode = DRV_CUSTOM_YUV422_MODE;
        }
    }

    if(DRVCUST_Get_InterMemc_type() && !u1DrvIsPnl4k2k60WithMemc() && PANEL_Is4K2K60())
    {
        LOG(0,"paneless not support normal mode, force change to repeat mode (%d)(%d)(%d)\n",
            DRVCUST_Get_InterMemc_type(),!u1DrvIsPnl4k2k60WithMemc(),PANEL_Is4K2K60());
        if(((GetPANEL4K2K_TYPE() == PANEL_TYPE_2K1K_120) || (GetPANEL4K2K_TYPE() == PANEL_TYPE_4K1K_120)) && !fgApiVideoIsVgaTiming(VDP_1))
        {
            u1MEMCMode = DRV_CUSTOM_4k1k_REPEAT_MODE;
        }
        else
        {
            u1MEMCMode = DRV_CUSTOM_REPEAT_MODE;
        }
    }
    else if(bDrvIsHdmiVRRMode())
    {
        if(bDrvVideoGetRefreshRate(VDP_1) <= 60)
        {
            u1MEMCMode = DRV_CUSTOM_REPEAT_MODE;
        }
        else
        {
            u1MEMCMode = DRV_CUSTOM_4k1k_REPEAT_MODE;
        }
    }

    DRVCUST_MEMC_GetMode(&u1CurMEMCMode, &u1CurColorMode);

    if(u1MEMCMode != DRV_CUSTOM_MEMC_MODE_END &&
        u1ColorMode != DRV_CUSTOM_MEMC_COLOR_MODE_END)
    {
        if(u1CurMEMCMode != u1MEMCMode || u1CurColorMode != u1ColorMode)
        {
            u1DbgMemcMode = u1MEMCMode;
            u1DbgColorMode = u1ColorMode;
            LOG(0,"Update Memc mode:%d color:%d \n", u1MEMCMode, u1ColorMode);
            DRVCUST_MEMC_SetMode(u1MEMCMode, u1ColorMode);
        }
        else
        {
            LOG(0,"Memc Mode no change, ignore(%d)(%d) \n", u1MEMCMode, u1ColorMode);
        }
    }
}

void DRVCUST_MEMC_SetInfo(MEMC_MODE_INFO_TYPE *pMemcInfo)
{
    _stMemcModeInfo.u1MemcPicMode = pMemcInfo->u1MemcPicMode;
    _stMemcModeInfo.u1MemcSrc.eMainInputType = pMemcInfo->u1MemcSrc.eMainInputType;
    _stMemcModeInfo.u1MemcSrc.eSubInputType = pMemcInfo->u1MemcSrc.eSubInputType;
    LOG(0,"Update Memc Info PicMode:%d Main:%d Sub:%d \n", _stMemcModeInfo.u1MemcPicMode,
        _stMemcModeInfo.u1MemcSrc.eMainInputType, _stMemcModeInfo.u1MemcSrc.eSubInputType);

    DRVCUST_MEMC_CalDynMode();
}


void DRVCUST_GetMEMCModeInfo(MEMC_MODE_INFO_TYPE *pMemcInfo)
{
    if(pMemcInfo != NULL)
    {
        pMemcInfo->u1MemcPicMode = _stMemcModeInfo.u1MemcPicMode;
        pMemcInfo->u1MemcSrc.eMainInputType = _stMemcModeInfo.u1MemcSrc.eMainInputType;
        pMemcInfo->u1MemcSrc.eSubInputType = _stMemcModeInfo.u1MemcSrc.eSubInputType;
    }
}

void DRVCUST_MEMC_DumpInfo()
{
    UINT8 u1MEMCMode, u1ColorMode;
    Printf("Fix Dyn Mode(%d) Color(%d)  \n",u1DbgMemcDynModeFix,u1DbgMemcDynColorFix);
    LOG(0,"PicMode:%d MainSrc:%d SubSrc:%d\n", _stMemcModeInfo.u1MemcPicMode,
        _stMemcModeInfo.u1MemcSrc.eMainInputType, _stMemcModeInfo.u1MemcSrc.eSubInputType);
    LOG(0,"Input Framerate:%d SigStatus:%d \n", 
        bDrvVideoGetRefreshRate(VDP_1), bDrvVideoSignalStatus(VDP_1));
    LOG(0,"HDMI:%d Comp:%d Digital:%d \n", 
        IsSrcHDMI(_stMemcModeInfo.u1MemcSrc.eMainInputType), 
        IsSrcComp(_stMemcModeInfo.u1MemcSrc.eMainInputType),
        IsSrcDigital(_stMemcModeInfo.u1MemcSrc.eMainInputType));

    DRVCUST_MEMC_GetMode(&u1MEMCMode, &u1ColorMode);
    LOG(0,"Set Memc Mode:%d Color:%d \n", u1DbgMemcMode , u1DbgColorMode);
    LOG(0,"Get Memc Mode:%d Color:%d \n", u1MEMCMode, u1ColorMode);
}
void DRVCUST_SetHDMISignalPath(UINT32 u4Num, UINT32 u4SigPath)
{
    UINT8 u1Ret = 0;
    LOG(0,"[%s]Set HDMI Signal path:u4Num=%d u4SigPath=%d\n",__FUNCTION__,u4Num,u4SigPath);
   u1Ret =  u1vDrvSetHdmiSignalPath(u4Num,u4SigPath);
   if(u1Ret != TRUE)
    {
        LOG(0,"vDrvSetHdmiSignalPath set fail,please check it!!!\n");
    }
   else
    {
        LOG(0,"vDrvSetHdmiSignalPath set successfully!!!\n");
    }
}
UINT32 DRVCUST_GetHDMISignalPath(void)
{
    UINT32 u1Ret = 0;

   u1Ret = u4DrvGetHdmiSignalPath();

    LOG(0,"[%s]Set HDMI Signal path:u8Num=%d u1SigPath=%d\n",__FUNCTION__,u1Ret);
    return u1Ret;
}

UINT32 DRVCUST_MEMC_ColorMapping(UINT32 u4ClrFmt)
{
    UINT32 u4MemcFmt;

    switch(u4ClrFmt)
    {
        case E_601_LIMITED:
            u4MemcFmt = MJC_COLORTRANS_YCBCR601L_2_YCBCR601L;
            break;
        case E_601_FULL:
            u4MemcFmt = MJC_COLORTRANS_YCBCR601F_2_YCBCR601L;
            break;
        case E_709_LIMITED:
            u4MemcFmt = MJC_COLORTRANS_YCBCR709L_2_YCBCR601L;
            break;
        case E_709_FULL:
            u4MemcFmt = MJC_COLORTRANS_YCBCR709F_2_YCBCR601L;
            break;
        case E_2020_LIMITED:
            u4MemcFmt = MJC_COLORTRANS_BT2020CL_2_BT2020CL;
            break;
        case E_2020_FULL:
            u4MemcFmt = MJC_COLORTRANS_BT2020CF_2_BT2020CL;
            break;
        case E_2020YC_LIMITED:
            u4MemcFmt = MJC_COLORTRANS_BT2020L_2_YCBCR601L;
            break;
        case E_2020YC_FULL:
            u4MemcFmt = MJC_COLORTRANS_BT2020F_2_YCBCR601L;
            break;
        case E_RGB_LIMITED:
            u4MemcFmt = MJC_COLORTRANS_RGBL_2_YCBCR601L;
            break;
        case E_RGB_FULL:
            u4MemcFmt = MJC_COLORTRANS_RGBF_2_YCBCR601L;
            break;
        case E_RGB2020_LIMITED:
            u4MemcFmt = MJC_COLORTRANS_BT2020_RGBL_2_BT2020_NCL_L;
            break;
        case E_RGB2020_FULL:
            u4MemcFmt = MJC_COLORTRANS_BT2020_RGBF_2_BT2020_NCL_L;
            break;
        default:
            u4MemcFmt = MJC_COLORTRANS_MAX;
    }

    return u4MemcFmt;
}

void DRVCUST_MEMC_SetColorFormat(UINT32 u4ClrFmt)
{
    LOG(0,"[%s] u1Byp=%d Color=%d \n",__FUNCTION__,u1DrvIsVdpBypCase(),DRVCUST_MEMC_ColorMapping(u4ClrFmt));
    vDrvMJC_SetColorFormat(u1DrvIsVdpBypCase(),DRVCUST_MEMC_ColorMapping(u4ClrFmt));
}

