/* 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 "drv_MapleApi.h"
#include "b2r_drvif.h"
#include "vdp_if.h"
#include "vdec_if.h"
#include "drv_hdmi2.h"
#include "nptv_debug.h"
#include "bepqapi.h"
#include "msdc_if.h"
#include "x_pdwnc.h"
#include "CustomCtrl.h"
#include "pe_if.h"
#include "mute_if.h"
#include "drv_display.h"
#include "osd_drvif.h"
#include "drv_lcdim_v2.h"
#include "ostg_if.h"
#include "drv_scart.h"
#include "drv_lbox.h"
#include "vdp_display.h"
#include "hw_ycproc.h"
#include "hw_ospe.h"
#include "hdmi_if.h"
#include "drv_fd.h"
#include "drv_vrr.h"
#ifdef CC_SUPPORT_DOLBY_VISION
#include "drv_dolby_drvif.h"
#endif
////////////////////////////////////////////////////////////////////////////////
#define MAPLE_SYS_DEBUG 1
extern UINT32 dwOpticalSensorAvgValue;
extern BOOL fgYUVout;
extern SRM_TV_MODE_T _eApplicationMode;
extern UINT8 gAgingInit;

extern LCDTIMING_INFO_T lcdtimingInfo;
#if defined(SUPPORT_PANEL_GRAPH_MODE)
extern TIMING_INFO_T GFXTimingInfo;
#endif

#ifdef CC_PowerCons_Ctrl
extern UINT8 C_BL_POWER_LIMIT;
#endif

extern UINT8 gWFDProtocol;
EXTERN UINT32 waYSH3DHist[YSH_3D_HIST_NUM];

EXTERN UINT32 _u4LBoxDetectionEnable;
EXTERN UINT8 u1HdmiIf_GetActivePort(UINT8 u1Path);

EXTERN void vHDMIEDIDReadEDID(UINT8 u1Type, UINT8* pBuff, UINT32* pOffset);
EXTERN UINT32 SRM_IsEpgMode(VOID);


CUST_4BAND_HIST_T CUST_4BAND_HIST_VALUE;

E_CUST_PIC_CONTROL_STATE CUST_PIC_CONTROL_STATE;

////////////////////////////////////////////////////////////////////////////////
static void DEBUG_GetSignalFormat(UINT8 bPath, CUST_SIG_FMT_T* pSignalFormat)
{
    #if MAPLE_SYS_DEBUG
    LOG(2, "====== DRVCUST_GetSignalFormat(%d) ======\n", bPath);
    LOG(2, "eSigSta             %d\n", pSignalFormat->eSigSta);  	
    LOG(2, "u4Width             %d\n", pSignalFormat->u4Width); 				
    LOG(2, "u4Height            %d\n", pSignalFormat->u4Height);        	
    LOG(2, "u4CodecWidth        %d\n", pSignalFormat->u4CodecWidth);   
    LOG(2, "u4CodecHeight       %d\n", pSignalFormat->u4CodecHeight); 	
    LOG(2, "eContentType	    %d\n", pSignalFormat->eContentType);   
    LOG(2, "eScanType	        %d\n", pSignalFormat->eScanType); 			
    LOG(2, "eColorSystem	    %d\n", pSignalFormat->eColorSystem);   
    LOG(2, "eFrameRate	        %d\n", pSignalFormat->eFrameRate); 			
    LOG(2, "eStreamingType	    %d\n", pSignalFormat->eStreamingType); 
    LOG(2, "eDimension	        %d\n", pSignalFormat->eDimension); 			
    LOG(2, "e3dFormat	        %d\n", pSignalFormat->e3dFormat); 			
    LOG(2, "eColorimetry	    %d\n", pSignalFormat->eColorimetry);  // ?
    LOG(2, "eColorFormat	    %d\n", pSignalFormat->eColorFormat);  // ?
    LOG(2, "eColorDepth	        %d\n", pSignalFormat->eColorDepth); 		
    LOG(2, "eColorSpace	        %d\n", pSignalFormat->eColorSpace);    	
    LOG(2, "ePhotoColorSpace 	%d\n", pSignalFormat->ePhotoColorSpace);
    LOG(2, "eDynamicRange	    %d\n", pSignalFormat->eDynamicRange); 
    LOG(2, "eAspect	            %d\n", pSignalFormat->eAspect); 				
    LOG(2, "eVideoCodec	        %d\n", pSignalFormat->eVideoCodec); 
    LOG(2, "eCromaSample	    %d\n", pSignalFormat->eCromaSample);
    LOG(2, "eHdmi4kPhoto	    %d\n", pSignalFormat->eHdmi4kPhoto);
	LOG(2, "eHDRType	        %d\n", pSignalFormat->eHDRType);
	LOG(2, "eDoviType	        %d\n", pSignalFormat->eDoviType);
	LOG(2, "u4SrcFrameRate	        %d\n", pSignalFormat->u4SrcFrameRate);
    #endif
}
static void DEBUG_GetOutputVideoFormat(CUST_OUT_FMT_T* pOutVdoFmt)
{
    #if MAPLE_SYS_DEBUG
    LOG(2, "====== DRVCUST_GetOutputVideoFormat ======\n");
    LOG(2, "u4Htotal		    %d\n", pOutVdoFmt->u4Htotal);
    LOG(2, "u4Vtotal		    %d\n", pOutVdoFmt->u4Vtotal);
    LOG(2, "u4ActX			    %d\n", pOutVdoFmt->u4ActX);
    LOG(2, "u4ActY			    %d\n", pOutVdoFmt->u4ActY);
    LOG(2, "u4ActWidth		    %d\n", pOutVdoFmt->u4ActWidth);
    LOG(2, "u4ActHeight		    %d\n", pOutVdoFmt->u4ActHeight);
    LOG(2, "eFrameRate		    %d\n", pOutVdoFmt->eFrameRate);
    LOG(2, "eDimension		    %d\n", pOutVdoFmt->eDimension);
    LOG(2, "e3dFormat		    %d\n", pOutVdoFmt->e3dFormat);
    LOG(2, "eColorimetry	    %d\n", pOutVdoFmt->eColorimetry);
    LOG(2, "eColorFormat	    %d\n", pOutVdoFmt->eColorFormat);
    LOG(2, "eColorDepth		    %d\n", pOutVdoFmt->eColorDepth);
    LOG(2, "eColorSpace		    %d\n", pOutVdoFmt->eColorSpace);
    LOG(2, "eDynamicRange	    %d\n", pOutVdoFmt->eDynamicRange);
    LOG(2, "ePath			    %d\n", pOutVdoFmt->ePath);
	LOG(2, "bCtrlBitValid		%d\n", pOutVdoFmt->bCtrlBitValid);
    #endif
}

static void DEBUG_GetVideoFrameDelay(CUST_VDO_DELAY_INFO_T* pVdoDelayInfo)
{    
    #if MAPLE_SYS_DEBUG
    LOG(2, "====== DRVCUST_GetVideoFrameDelay ======\n");
    LOG(2, "u4MCVP              %d\n", pVdoDelayInfo->u4MCVP);                  
    LOG(2, "u4Scaler            %d\n", pVdoDelayInfo->u4Scaler);                
    LOG(2, "u4MJC               %d\n", pVdoDelayInfo->u4MJC);       
    #endif
}

static void DEBUG_GetMCVPMeter(CUST_MCVP_METER_T* pMcvpMeter)
{    

    LOG(2, "====== DRVCUST_GetMCVPMeter ======\n");
    LOG(2, "u1NoiseLevel              %d\n", pMcvpMeter->u1NoiseLevel);                  
    LOG(2, "u1BlockNoiseLevel            %d\n", pMcvpMeter->u1BlockNoiseLevel);                
    LOG(2, "u4FrmDiff               %d\n", pMcvpMeter->u4FrmDiff);     
	LOG(2, "u1FreqHpfH              %d\n", pMcvpMeter->u1FreqHpfH);                  
    LOG(2, "u1FreqHpfV            %d\n", pMcvpMeter->u1FreqHpfV);                
    LOG(2, "u1FreqBpfH               %d\n", pMcvpMeter->u1FreqBpfH);

}


////////////////////////////////////////////////////////////////////////////////
E_CUST_INPUT_TYPE DRVCUST_GetInputType(UINT8 bPath)
{    
    D_AP_INPUT_TYPE eType = BEPQ_AP_Get_Input_Type(bPath);

	switch (eType)
    {
        case D_AP_INPUT_TYPE_A_RF:
			return E_CUST_INPUT_TYPE_A_RF;
			
        case D_AP_INPUT_TYPE_D_RF:
			return E_CUST_INPUT_TYPE_D_RF;
			
		case D_AP_INPUT_TYPE_COMPOSITE:
			return E_CUST_INPUT_TYPE_COMPOSITE;
			
		case D_AP_INPUT_TYPE_COMPONENT:
			return E_CUST_INPUT_TYPE_COMPONENT;
			
		case D_AP_INPUT_TYPE_SCART:
			return E_CUST_INPUT_TYPE_SCART;
			
		case D_AP_INPUT_TYPE_A_PC:
			return E_CUST_INPUT_TYPE_A_PC;
			
		case D_AP_INPUT_TYPE_HDMI:
			return E_CUST_INPUT_TYPE_HDMI;
			
		case D_AP_INPUT_TYPE_APPLICATION:
			return E_CUST_INPUT_TYPE_IPTV;
			
		case D_AP_INPUT_TYPE_SONY_PHOTO_APP:
			return E_CUST_INPUT_TYPE_DNLA;
			
		case D_AP_INPUT_TYPE_JELLY_FISH:
			return E_CUST_INPUT_TYPE_IPTV;
			
		case D_AP_INPUT_TYPE_NETFLIX:
			return E_CUST_INPUT_TYPE_BROWSER;
			
		case D_AP_INPUT_TYPE_MIRACAST:
			return E_CUST_INPUT_TYPE_WIFI_DISPLAY;

		case D_AP_INPUT_TYPE_GENERAL_APP:
        default:        
            return E_CUST_INPUT_TYPE_UNKNOWN;
    }
    
}


void DRVCUST_GetSignalFormat(UINT8 bPath, CUST_SIG_FMT_T* pSignalFormat)
{
    UINT8 bSignalType = bGetSignalType(bPath);
    UINT8 u1ColorSys = vDrvGetColorSystem(bPath);
    HDMI_IF_COLOR_DEPTH_T eHdmiIfColorDepth = eHdmiIf_GetDeepColorStatus(bPath);
	UINT8 eB2rIfColorDepth ;
	UINT8 u1ScartMode = bDrvGetScartInputMode();
	HDMI_IF_SINGAL_FORMAT eHdmiColorFormat = eHdmiIf_GetSignalFormat(bPath);
    UINT32 u4VideoRange, u4HDRType;
	E_CUST_DOVI_TYPE eDovimode;
	UINT8 u1InFrameRate;
	VDEC_CHROMA_SIMPLE_INFO_T rChromaSimpleInfo;
	B2R_CUST_INFO_T t_B2RCustInfo;
	UINT32 u4B2RSrcFRMRate;
	UINT8   u1AspInfo = 0;
	E_CUST_INPUT_TYPE eInputType = BEPQ_AP_Get_Input_Type(bPath);
	CUST_PIC_SETTING_T rPicInfoFromAP;
	UCHAR ucEsId=VDP_Vdp2Es(bPath);
    if((pSignalFormat == NULL) || (bPath > VDP_2))
    {
        LOG(0,"%s invalid input PARAM\n",__FUNCTION__);
        return;
    }
	BEPQ_AP_Get_Pic_Setting(&rPicInfoFromAP);
	u1InFrameRate = bDrvVideoGetRefreshRate(bPath);
	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(B2R_Get_Cust_info(bPath, B2R_GET_TYPE_BIT_DEPTH, &eB2rIfColorDepth, sizeof(UINT8)))
	{
		    LOG(4, "\n====== B2R_GET_TYPE_BIT_DEPTH fail ======\n");
	}

	if(B2R_Get_Cust_info(bPath, B2R_GET_TYPE_ASPINFO, &u1AspInfo, sizeof(UINT8)))
	{
		    LOG(4, "\n====== B2R_Get_Cust_ASP_info fail ======\n");
	}
	if(B2R_Get_Cust_info(bPath, B2R_GET_TYPE_SRC_FRMRATE, &u4B2RSrcFRMRate, sizeof(UINT32)))
	{
		    LOG(4, "\n====== B2R_GET_TYPE_SRC_FRMRATE fail ======\n");
	}
    switch (bDrvVideoSignalStatus(bPath))
    {
        case SV_VDO_STABLE:
            pSignalFormat->eSigSta = E_CUST_SIG_STA_STABLE;
            break;
        case SV_VDO_NOSIGNAL:
            pSignalFormat->eSigSta = E_CUST_SIG_STA_NO_SIG;
            break;
        case SV_VDO_NOSUPPORT:    
        case SV_VDO_UNKNOWN:
        default:        
            pSignalFormat->eSigSta = E_CUST_SIG_STA_UNKNOWN;
            break;
    }
    
    pSignalFormat->u4Width = wDrvVideoInputWidth(bPath);
    pSignalFormat->u4Height = wDrvVideoInputHeight(bPath);
    
    if(bSignalType == SV_ST_MPEG)
    {
		pSignalFormat->u4CodecWidth = t_B2RCustInfo.rResolution.u4OrgWidth;
	    pSignalFormat->u4CodecHeight= t_B2RCustInfo.rResolution.u4OrgHeight;
    }
	else
	{
		pSignalFormat->u4CodecWidth = 0;
	    pSignalFormat->u4CodecHeight= 0;
	}
    if ((bSignalType == SV_ST_VGA) || (BEPQ_AP_Get_Input_Type(bPath) == E_CUST_INPUT_TYPE_BROWSER))
    {
        pSignalFormat->eContentType = E_CUST_CONTENT_TYPE_GRAPHICS;    
    }
    else if (bSignalType == SV_ST_DVI)
    {
        pSignalFormat->eContentType = fgHdmiIf_IsVideoTiming(bPath) 
            ? E_CUST_CONTENT_TYPE_VIDEO : E_CUST_CONTENT_TYPE_GRAPHICS; 
    }   
    else
    {
        pSignalFormat->eContentType = E_CUST_CONTENT_TYPE_VIDEO;    // VIDEO todo : photo
    }
    
    pSignalFormat->eScanType = bDrvVideoIsSrcInterlace(bPath) 
        ? E_CUST_SCAN_TYPE_INTERLACE : E_CUST_SCAN_TYPE_PROGRESSIVE;

    if ((bSignalType == SV_ST_TV) || (bSignalType == SV_ST_AV) || (bSignalType == SV_ST_SV)) 
    {
        switch((UINT8)bHwTvdMode())
        {
            case(UINT8)SV_CS_SECAM:
                pSignalFormat->eColorSystem = E_CUST_COLOR_SYSTEM_SECAM;
                break;        
            case(UINT8)SV_CS_NTSC358:
                pSignalFormat->eColorSystem = E_CUST_COLOR_SYSTEM_NTSC_358;
                break;    
            case(UINT8)SV_CS_NTSC443:
                pSignalFormat->eColorSystem = E_CUST_COLOR_SYSTEM_NTSC_443;
                break;           
            case(UINT8)SV_CS_PAL_M:
                pSignalFormat->eColorSystem = E_CUST_COLOR_SYSTEM_PAL_M;
                break;           
            case(UINT8)SV_CS_PAL_N:
                pSignalFormat->eColorSystem = E_CUST_COLOR_SYSTEM_PAL_N;
                break;        
            case(UINT8)SV_CS_PAL_60:
                pSignalFormat->eColorSystem = E_CUST_COLOR_SYSTEM_PAL60;
                break;        
            case(UINT8)SV_CS_PAL:
                pSignalFormat->eColorSystem = E_CUST_COLOR_SYSTEM_PAL;
                break;    
            default:
                pSignalFormat->eColorSystem = E_CUST_COLOR_SYSTEM_UNKNOWN;
                break;   
        }
    }
    else
    {
        pSignalFormat->eColorSystem = E_CUST_COLOR_SYSTEM_UNKNOWN;
    }

    switch (u1InFrameRate)
    {
        case 8:
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_8;
            break;
        case 10:
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_10;
            break;
        case 12:
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_12;
            break;
        case 24:
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_24;
            break;
        case 25:
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_25;
            break;
        case 30:
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_30;
            break;        
        case 48:
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_48;
            break;
        case 50:
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_50;
            break;
        case 96:
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_96;
            break;                  
        case 100:
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_100;
            break;  
        case 120:
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_120;
            break;  
        case 60:           
        default:        
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_60;
            break;                 
    }

    if(bPath == VDP_1 &&
        (eVRRGetSyncMode() == E_VRR_SYNC_MODE_FREERUN ||
        eVRRGetSyncMode() == E_VRR_SYNC_MODE_DIRECT))
    {
        if(u1InFrameRate <= 50)
        {
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_50;
        }
        else if(u1InFrameRate <= 60)
        {
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_60;
        }
        else if(u1InFrameRate <= 96)
        {
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_96;
        }
        else if(u1InFrameRate <= 100)
        {
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_100;
        }
        else if(u1InFrameRate <= 120)
        {
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_120;
        }
        else
        {
            pSignalFormat->eFrameRate = E_CUST_FRAME_RATE_UNKNWON;
        }
    }
    if(bSignalType == SV_ST_MPEG)
    {
	    if(t_B2RCustInfo.u4resolutionChg)
	    {
	        pSignalFormat->eStreamingType = E_CUST_STREAMING_TYPE_ADAPTIVE;   
	    }
	    else
	    {
	        pSignalFormat->eStreamingType = E_CUST_STREAMING_TYPE_NORMAL; 
	    }
    }
	else
	{
		pSignalFormat->eStreamingType = E_CUST_STREAMING_TYPE_NORMAL; 
	}
    switch(u4DrvTDTVGetTag3D(bPath))
    {
        case TDTV_TAG3D_NOT_SUPPORT:
            pSignalFormat->eDimension = E_CUST_DIMENSION_2D;
            pSignalFormat->e3dFormat = E_CUST_3D_FMT_UNKNOWN;
            break;
        case TDTV_TAG3D_FS:
            pSignalFormat->eDimension = E_CUST_DIMENSION_3D;
            pSignalFormat->e3dFormat = E_CUST_3D_FMT_FS;
            break;
        case TDTV_TAG3D_FP:
            pSignalFormat->eDimension = E_CUST_DIMENSION_3D;
            pSignalFormat->e3dFormat = E_CUST_3D_FMT_FP;
            break;
        case TDTV_TAG3D_TB:
            pSignalFormat->eDimension = E_CUST_DIMENSION_3D;
            pSignalFormat->e3dFormat = E_CUST_3D_FMT_TB;
            break;
        case TDTV_TAG3D_SBS:
            pSignalFormat->eDimension = E_CUST_DIMENSION_3D;
            pSignalFormat->e3dFormat = E_CUST_3D_FMT_SS;
            break;
        case TDTV_TAG3D_LI:
        case TDTV_TAG3D_CB:
        case TDTV_TAG3D_DA:
            pSignalFormat->eDimension = E_CUST_DIMENSION_3D;
            pSignalFormat->e3dFormat = E_CUST_3D_FMT_UNKNOWN;
            break;
        case TDTV_TAG3D_2D:
        default:
            pSignalFormat->eDimension = E_CUST_DIMENSION_2D;
            pSignalFormat->e3dFormat = E_CUST_3D_FMT_UNKNOWN;
            break;
    }

    if(((bSignalType == SV_ST_TV) || (bSignalType == SV_ST_AV) || (bSignalType == SV_ST_SV))
        ||((bSignalType == SV_ST_MPEG)&&((t_B2RCustInfo.eColorID == ColorSpace_sRGB)||
            (t_B2RCustInfo.eColorID == ColorSpace_sYCC)||(t_B2RCustInfo.eColorID == ColorSpace_AdobeRGB)))
        ||((bSignalType == SV_ST_DVI)&&(DRVCUST_HDMIIsPhotoMode())))
    {
        pSignalFormat->eColorimetry = E_CUST_COLMT_601; 
    }
    else if((bSignalType == SV_ST_MPEG)&&((t_B2RCustInfo.eColorID == ColorSpace_BT2020) || (t_B2RCustInfo.eColorID == ColorSpace_BT202C)))
    {
		pSignalFormat->eColorimetry = E_CUST_COLMT_2020;
    }
    else if((bSignalType == SV_ST_DVI)&&(DRVCUST_HDMIWithValidAviInfo()))
    {
        switch(DRVCUST_HDMIGetColorimetry())
        {  
            case SV_COLOR_HDMI_Colorimetry_601:
            case SV_COLOR_HDMI_Colorimetry_XVYCC601:
            case SV_COLOR_HDMI_Colorimetry_sYCC601:
            case SV_COLOR_HDMI_Colorimetry_AdobeYCC601:
                pSignalFormat->eColorimetry = E_CUST_COLMT_601;
                break;
            case SV_COLOR_HDMI_Colorimetry_709:
            case SV_COLOR_HDMI_Colorimetry_XVYCC709:
                pSignalFormat->eColorimetry = E_CUST_COLMT_709;
                break;
            case SV_COLOR_HDMI_Colorimetry_BT2020:
                pSignalFormat->eColorimetry = E_CUST_COLMT_2020;
                break;
            case SV_COLOR_HDMI_Colorimetry_RGB:
            case SV_COLOR_HDMI_Colorimetry_AdobeRGB:
            case SV_COLOR_HDMI_Colorimetry_UnKnown:
            default:    
                pSignalFormat->eColorimetry = E_CUST_COLMT_UNKOWN;
                break;
        }
    }
    else
    {
        pSignalFormat->eColorimetry = (pSignalFormat->u4Height >= 720) ? 
                                      E_CUST_COLMT_709 : E_CUST_COLMT_601;
    }

    /*
    switch(u1ColorSys)
    {
        case SV_COLOR_YCBCR_SD:
            pSignalFormat->eColorimetry = E_CUST_COLMT_601;    
            break;
        case SV_COLOR_YCBCR_HD:    
            pSignalFormat->eColorimetry = E_CUST_COLMT_709;    
            break;
        case SV_COLOR_YUV_2020:     // PQ : TBD
            pSignalFormat->eColorimetry = E_CUST_COLMT_2020;   
            break;
        case SV_COLOR_RGB_SD:
        case SV_COLOR_RGB_HD:
        case SV_COLOR_YUV_NTSC: 
        case SV_COLOR_YUV_NTSCJ:        
        case SV_COLOR_YUV_PAL:
        default:
            pSignalFormat->eColorimetry = E_CUST_COLMT_UNKOWN;    // PQ
            break;
    }
    */
    
    if ((u1ColorSys == SV_COLOR_RGB_SD) || (u1ColorSys == SV_COLOR_RGB_HD))
    {        
        pSignalFormat->eColorFormat = E_CUST_COL_FMT_RGB;       
    }
    else if (bSignalType == SV_ST_DVI)
    {
    	switch(eHdmiColorFormat)
    	{
    		case HDMI_IF_FORMAT_YC420:
				pSignalFormat->eColorFormat = E_CUST_COL_FMT_YUV_420;
				break;
			case HDMI_IF_FORMAT_YC422:
				pSignalFormat->eColorFormat = E_CUST_COL_FMT_YUV_422;
				break;
			case HDMI_IF_FORMAT_YC444:
				pSignalFormat->eColorFormat = E_CUST_COL_FMT_YUV_444;
				break;
			default:
				pSignalFormat->eColorFormat = E_CUST_COL_FMT_RGB;
				break;
    	}
    }
    else if (bSignalType == SV_ST_MPEG)
    {
        pSignalFormat->eColorFormat = E_CUST_COL_FMT_YUV_420;  
    }
	else if ((eInputType == E_CUST_INPUT_TYPE_SCART) && (u1ScartMode == SCART_COLOR_RGB))
    {
        pSignalFormat->eColorFormat = E_CUST_COL_FMT_RGB;  
    }
    else
    {
        pSignalFormat->eColorFormat = E_CUST_COL_FMT_YUV_422;   // VIDEO todo : photo
    }

    if (bSignalType == SV_ST_VGA)
    {
        pSignalFormat->eColorDepth = E_CUST_COL_DEPTH_8; 
    }
    else if (bSignalType == SV_ST_DVI)
    {
        switch (eHdmiIfColorDepth)
        {            
            case HDMI_IF_COLOR_DEPTH_10BIT:
                pSignalFormat->eColorDepth = E_CUST_COL_DEPTH_10;     
                break;
            case HDMI_IF_COLOR_DEPTH_12BIT:
                pSignalFormat->eColorDepth = E_CUST_COL_DEPTH_12;  
                break;
            default:
            case HDMI_IF_COLOR_DEPTH_8BIT:
                pSignalFormat->eColorDepth = E_CUST_COL_DEPTH_8;   
                break;
         }
    }

	else if (bSignalType == SV_ST_MPEG)
    {
        switch (eB2rIfColorDepth)
        {            
            case B2R_IF_COLOR_DEPTH_10BIT:
                pSignalFormat->eColorDepth = E_CUST_COL_DEPTH_10;     
                break;
            case B2R_IF_COLOR_DEPTH_12BIT:
                pSignalFormat->eColorDepth = E_CUST_COL_DEPTH_12;  
                break;
            default:
            case B2R_IF_COLOR_DEPTH_8BIT:
                pSignalFormat->eColorDepth = E_CUST_COL_DEPTH_8;   
                break;
         }
    }
    else
    {
        pSignalFormat->eColorDepth = E_CUST_COL_DEPTH_10;   // VIDEO todo : photo
    }
    if (bSignalType == SV_ST_DVI)
    {  
	    switch(DRVCUST_HDMIGetVideoColorSpace())    //DVI video
        {
            case SV_COLOR_HDMI_Normal:
                pSignalFormat->eColorSpace = E_CUST_COL_SPACE_NORMAL;
                break;
            case SV_COLOR_HDMI_xvYCC:
                pSignalFormat->eColorSpace = E_CUST_COL_SPACE_XV_COLOR;
                break;
            case SV_COLOR_HDMI_BT2020:
                pSignalFormat->eColorSpace = E_CUST_COL_SPACE_BT2020;
                break;
            case SV_COLOR_HDMI_BT2020c:
                pSignalFormat->eColorSpace = E_CUST_COL_SPACE_BT202C;
                break;
            case SV_COLOR_HDMI_sRGB:
            case SV_COLOR_HDMI_Adobe_RGB:
            case SV_COLOR_HDMI_sYCC:
            default:
                pSignalFormat->eColorSpace = E_CUST_COL_SPACE_UNKNOWN;
                break;
        }      
        switch(DRVCUST_HDMIGetPhotoColorSpace())    //DVI Photo
        {
            case SV_COLOR_HDMI_sRGB:
	            pSignalFormat->ePhotoColorSpace = E_CUST_PHOTO_COL_SPACE_SRGB;
                break;
            case SV_COLOR_HDMI_sYCC:
                pSignalFormat->ePhotoColorSpace = E_CUST_PHOTO_COL_SPACE_SYCC;
                break;
            case SV_COLOR_HDMI_Adobe_RGB:
	            pSignalFormat->ePhotoColorSpace = E_CUST_PHOTO_COL_SPACE_ADOBE_RGB;
                break;
            case SV_COLOR_HDMI_xvYCC:
            case SV_COLOR_HDMI_BT2020:
            case SV_COLOR_HDMI_BT2020c:
            case SV_COLOR_HDMI_Normal:
            default:
	            pSignalFormat->ePhotoColorSpace = E_CUST_PHOTO_COL_SPACE_UNKNOWN;
                break;
        }
    }
    else if(bSignalType == SV_ST_MPEG)
    {
	    switch(t_B2RCustInfo.eColorID)
	    {
	    	case ColorSpace_Normal:
	            pSignalFormat->eColorSpace = E_CUST_COL_SPACE_NORMAL; 
				pSignalFormat->ePhotoColorSpace = E_CUST_PHOTO_COL_SPACE_UNKNOWN;
			    break;
			case ColorSpace_XVColor:
	            pSignalFormat->eColorSpace = E_CUST_COL_SPACE_XV_COLOR; 
				pSignalFormat->ePhotoColorSpace = E_CUST_PHOTO_COL_SPACE_UNKNOWN;
			    break;
		    case ColorSpace_BT202C:
	            pSignalFormat->eColorSpace = E_CUST_COL_SPACE_BT202C;  
				pSignalFormat->ePhotoColorSpace = E_CUST_PHOTO_COL_SPACE_UNKNOWN;
			    break;
			case ColorSpace_BT2020:
	            pSignalFormat->eColorSpace = E_CUST_COL_SPACE_BT2020;  
				pSignalFormat->ePhotoColorSpace = E_CUST_PHOTO_COL_SPACE_UNKNOWN;
			    break;
			case ColorSpace_sRGB:
				pSignalFormat->eColorSpace = E_CUST_COL_SPACE_UNKNOWN;
	            pSignalFormat->ePhotoColorSpace = E_CUST_PHOTO_COL_SPACE_SRGB;  
			    break;
			case ColorSpace_sYCC:
				pSignalFormat->eColorSpace = E_CUST_COL_SPACE_UNKNOWN;
	            pSignalFormat->ePhotoColorSpace = E_CUST_PHOTO_COL_SPACE_SYCC;  
			    break;
			case ColorSpace_AdobeRGB:
				pSignalFormat->eColorSpace = E_CUST_COL_SPACE_UNKNOWN;
	            pSignalFormat->ePhotoColorSpace = E_CUST_PHOTO_COL_SPACE_ADOBE_RGB; 
			    break;
			case ColorSpace_NS: 
			default:
			    pSignalFormat->eColorSpace = E_CUST_COL_SPACE_UNKNOWN;
			    pSignalFormat->ePhotoColorSpace = E_CUST_PHOTO_COL_SPACE_UNKNOWN;
			    break;
		}
    }
    else
    {
        pSignalFormat->eColorSpace = E_CUST_COL_SPACE_NORMAL;
        pSignalFormat->ePhotoColorSpace = E_CUST_PHOTO_COL_SPACE_UNKNOWN;
    }

    switch (bSignalType)
    {
        case SV_ST_DVI:
            u4VideoRange = u1HdmiIf_RgbRange(bPath);
            u4VideoRange = (u4VideoRange == SV_HDMI_RANGE_DEFAULT) ? DRVCUST_HDMIRange(bPath) : u4VideoRange;
            break;
        case SV_ST_VGA:
            u4VideoRange = SV_HDMI_RANGE_FULL;
            break;
		case SV_ST_MPEG:
			u4VideoRange = DRVCUST_GetVideoRange(bPath);
            u4VideoRange = (u4VideoRange == SV_HDMI_RANGE_DEFAULT) ? DRVCUST_HDMIRange(bPath) : u4VideoRange;
            break;
        default:
            u4VideoRange = SV_HDMI_RANGE_LIMIT;
            break;
    }

	if((eInputType ==  E_CUST_INPUT_TYPE_HDMI) || (eInputType ==  E_CUST_INPUT_TYPE_WIFI_DISPLAY))
	{
		if(rPicInfoFromAP.eDrange == E_CUST_DRANGE_UI_AUTO)
		{
			switch (u4VideoRange)
		    {
		        case SV_HDMI_RANGE_FULL:
		            pSignalFormat->eDynamicRange = E_CUST_DRANGE_FULL;       
		            break;
		        case SV_HDMI_RANGE_LIMIT:
		            pSignalFormat->eDynamicRange = E_CUST_DRANGE_LIMITED;       
		            break;
		        default:
		            pSignalFormat->eDynamicRange = E_CUST_DRANGE_LIMITED;
		            break;
		    }
		}
		else if(rPicInfoFromAP.eDrange == E_CUST_DRANGE_UI_FULL)
		{
			pSignalFormat->eDynamicRange = E_CUST_DRANGE_FULL; 
		}
		else
		{
			pSignalFormat->eDynamicRange = E_CUST_DRANGE_LIMITED; 
		}
	}
	else
	{
		pSignalFormat->eDynamicRange = E_CUST_DRANGE_LIMITED; 
	}
    
    
    
    //pSignalFormat->eAspect = E_CUST_ASPECT_UNKNOWN;             // VIDEO : TBD	
    if(bSignalType == SV_ST_MPEG)
	{
        UINT32 u4DAR;
        switch(u1AspInfo)
        {
            case MPEG_ASPECT_RATIO_4_3:
                pSignalFormat->eAspect = E_CUST_ASPECT_4_3;   
                break;
            case MPEG_ASPECT_RATIO_16_9:
                pSignalFormat->eAspect = E_CUST_ASPECT_16_9;
                break;
            case MPEG_ASPECT_RATIO_1_1:
                if(pSignalFormat->u4Height != 0)
                {
                    u4DAR = (100 * pSignalFormat->u4Width) / pSignalFormat->u4Height;
                    if (((u4DAR *3) >> 2) < 110)
                    {
                        pSignalFormat->eAspect = E_CUST_ASPECT_4_3;
                    }
                    else
                    {
                        pSignalFormat->eAspect = E_CUST_ASPECT_16_9;
                    }
                    break;
                }
            default:
                pSignalFormat->eAspect = E_CUST_ASPECT_UNKNOWN;
                break;
        }
    }
    else if(bSignalType == SV_ST_DVI)
    {
        pSignalFormat->eAspect = (E_CUST_ASPECT)DRVCUST_HDMIGetAspectRatio();
    }
    else
    {
        pSignalFormat->eAspect = E_CUST_ASPECT_UNKNOWN;
    }
        
    if(bSignalType == SV_ST_MPEG)
    {
	    switch(t_B2RCustInfo.eCodecInfo)
	    {
			case E_VDEC_CODEC_MPEG1:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_MPEG1;   
			    break;
			case E_VDEC_CODEC_MPEG2:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_MPEG2;  
			    break;
			case E_VDEC_CODEC_MPEG4_VISUAL:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_MPEG4_VISUAL;  
			    break;
			case E_VDEC_CODEC_AVC:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_AVC; 
			    break;
			case E_VDEC_CODEC_HEVC:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_HEVC; 
			    break;
			case E_VDEC_CODEC_AVS:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_AVS;  
			    break;
			case E_VDEC_CODEC_XVID:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_XVID;  
			    break;
			case E_VDEC_CODEC_VC1:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_VC1;   
			    break;
			case E_VDEC_CODEC_REAL:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_REAL;  
			    break;
			case E_VDEC_CODEC_VP8:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_VP8;  
			    break;
			case E_VDEC_CODEC_MOTION_JPEG:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_MOTION_JPEG;  
			    break;
			case E_VDEC_CODEC_JPEG:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_JPEG; 
				break;
	        case E_VDEC_CODEC_MPO:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_MPO;  
			    break;
			case E_VDEC_CODEC_RAW:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_RAW;  
				break;
			case E_VDEC_CODEC_VP9:
	            pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_REAL;  
				break;
			default:
			    pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_UNKNOWN;
			    break;
		}
    }
	else
	{
		pSignalFormat->eVideoCodec = E_CUST_VDO_CODEC_UNKNOWN;
	}
	if (VDEC_QueryChromaInfo(ucEsId, &rChromaSimpleInfo))
	{
		if(rChromaSimpleInfo.fgChromaLocationInfoPresentFlag==1)
		{
			if((rChromaSimpleInfo.u4ChromaSampleLocTypeTopField==2)||(rChromaSimpleInfo.u4ChromaSampleLocTypeBottomField==2))
			{
				pSignalFormat->eCromaSample = E_CUST_CHROMA_SAMPLE_TYPE_2; 
			}
			else
			{
				pSignalFormat->eCromaSample = E_CUST_CHROMA_SAMPLE_TYPE_0; 
			}
				
		}
		else
		{
				pSignalFormat->eCromaSample = E_CUST_CHROMA_SAMPLE_TYPE_0; 
		}
		
	}
	else
	{
		if(rChromaSimpleInfo.fgChromaLocationInfoPresentFlag==0)
		{
			pSignalFormat->eCromaSample = E_CUST_CHROMA_SAMPLE_TYPE_0;  
		}
		else
		{
			pSignalFormat->eCromaSample = E_CUST_CHROMA_SAMPLE_TYPE_INVALID;
		}
		
	}
	if(bSignalType == SV_ST_DVI)
	{
		pSignalFormat->eHdmi4kPhoto = u1HdmiIf_Get4KpsSta(bPath) ? E_CUST_HDMI_4K_PHOTO_ON : E_CUST_HDMI_4K_PHOTO_OFF;
	}
	else
	{
        pSignalFormat->eHdmi4kPhoto =  E_CUST_HDMI_4K_PHOTO_OFF;   
	}

	switch(bSignalType)
	{
		case SV_ST_DVI:
			u4HDRType = (UINT32)DRVCUST_HDMIGetHDRType(SV_VP_MAIN);
			break;
		case SV_ST_MPEG:
			#ifdef CC_SUPPORT_DOLBY_VISION
			if(u4DolbyGetCustSourceInfo(SV_VP_MAIN))//(t_B2RCustInfo.tHdrInfo.tHdr10Info.e_HdrType==HDR_TYPE_DOVI)
			{
				u4HDRType = E_CUST_HDR_TYPE_HDR3;
			}
			else
			#endif
			{
				if(t_B2RCustInfo.tHdrDetectInfo.u4SEIHDRContent == 18)
				{
					u4HDRType = E_CUST_HDR_TYPE_HDR2;
				}
				else if(t_B2RCustInfo.tHdrDetectInfo.u4SEIHDRContent == 16)
				{
					u4HDRType = E_CUST_HDR_TYPE_HDR1;
				}
				else if(t_B2RCustInfo.tHdrDetectInfo.u4VUIHDRContent== 16)
				{
					u4HDRType = E_CUST_HDR_TYPE_HDR1;
				}
				else if(t_B2RCustInfo.tHdrDetectInfo.u4VUIHDRContent== 18)
				{
					u4HDRType = E_CUST_HDR_TYPE_HDR2;
				}
				else
				{
					u4HDRType = E_CUST_HDR_TYPE_SDR;
				}
			}
			if(DRVCUST_GetVP9HDRType() != SV_VP9_HDR_TYPE_NONE)
			{
				u4HDRType = DRVCUST_GetVP9HDRType();
			}
			break;
		default:
			u4HDRType = SV_HDR_TYPE_SDR;
			break;
			
	}



	pSignalFormat->eHDRType = u4HDRType;

/*
	if((bSignalType == SV_ST_DVI) || (bSignalType == SV_ST_MPEG))
	{
		switch(rPicInfoFromAP.eTransFunc)
		{
			case E_CUST_TRANSFER_FUNC_UI_AUTO:
				switch(u4HDRType)
				{
					case SV_HDR_TYPE_SDR:						
					pSignalFormat->eHDRType= E_CUST_HDR_TYPE_SDR;
						break;
					case SV_HDR_TYPE_HDR1:
						pSignalFormat->eHDRType = E_CUST_HDR_TYPE_HDR1;
						break;
					case SV_HDR_TYPE_HDR2:
						pSignalFormat->eHDRType = E_CUST_HDR_TYPE_HDR2;
						break;
					default:
						pSignalFormat->eHDRType = E_CUST_HDR_TYPE_SDR;
						break;					
				}
					
				break;
			case E_CUST_TRANSFER_FUNC_UI_HDR1:
				pSignalFormat->eHDRType = E_CUST_HDR_TYPE_HDR1;
				break;
			case E_CUST_TRANSFER_FUNC_UI_HDR2:
				pSignalFormat->eHDRType = E_CUST_HDR_TYPE_HDR2;
				break;
			default:
				pSignalFormat->eHDRType = E_CUST_HDR_TYPE_SDR;
				break;			
		}
	}
	else
	{
		pSignalFormat->eHDRType = E_CUST_HDR_TYPE_SDR;
	}
	*/
	DRVCUST_GetDOVIType(bPath,&eDovimode);
	pSignalFormat->eDoviType = eDovimode;
	if(bSignalType == SV_ST_MPEG)
	{
		pSignalFormat->u4SrcFrameRate = u4B2RSrcFRMRate;
	}
	else
	{
		pSignalFormat->u4SrcFrameRate = bDrvVideoGetSRCFrameRate(bPath);
	}

    pSignalFormat->u4IsEPGMode = SRM_IsEpgMode();
    LOG(0,"@MTK_FHD stable:%d wxh:%dx%d fr:%d epgmode:%d \n",
        pSignalFormat->eSigSta,pSignalFormat->u4Width,pSignalFormat->u4Height,
        pSignalFormat->eFrameRate,pSignalFormat->u4IsEPGMode);
	DEBUG_GetSignalFormat(bPath, pSignalFormat);

}

E_CUST_WINDOW_MODE DRVCUST_GetWindowMode(void)
{
    SRM_TV_MODE_T mode = SRM_GetTvMode();

    switch (mode)
    {        
        case SRM_TV_MODE_TYPE_PIP:
            return E_CUST_WINDOW_MODE_PIP;
        case SRM_TV_MODE_TYPE_POP:
            return E_CUST_WINDOW_MODE_PAP;
        default:
        case SRM_TV_MODE_TYPE_NORMAL:
            return E_CUST_WINDOW_MODE_SINGLE;
    }
}

E_CUST_MUTE_STATE DRVCUST_GetPlaneMuteState(UINT8 bPath)
{
	BOOL bMute;
    if(bPath > VDP_2)
    {
        LOG(0,"%s invalid input PARAM\n",__FUNCTION__);
        return E_CUST_MUTE_STATE_MUTE;
    }
	bMute =  ((bPath == SV_VP_MAIN) ? fgMainMuteOn() : fgPIPMuteOn());
    return bMute ? E_CUST_MUTE_STATE_MUTE : E_CUST_MUTE_STATE_UNMUTE;
}

E_CUST_MUTE_STATE DRVCUST_GetOutputMuteState(UINT8 u1TxPath)
{
    if(u1TxPath > VDP_2)
    {
        LOG(0,"%s invalid input PARAM\n",__FUNCTION__);
        return E_CUST_MUTE_STATE_MUTE;
    }
    if (u1TxPath) // Physical Gfx
    {
        return u4DrvGfxOutputMute() ? E_CUST_MUTE_STATE_MUTE : E_CUST_MUTE_STATE_UNMUTE;
    }
    else // Physical Video
    {
        return u4DrvVideoOutputMute() ? E_CUST_MUTE_STATE_MUTE : E_CUST_MUTE_STATE_UNMUTE;
    }
}

void DRVCUST_GetOutputPosition(UINT8 bPath, CUST_OUT_POSI_T* pOutPosition)
{   
    VRM_INFO_T* vrmInfo = VRMGetVRMInfo(bPath, VRM_MODULE_MIXER);

    if((pOutPosition == NULL) || (bPath > VDP_2))
    {
        LOG(0,"%s invalid input PARAM\n",__FUNCTION__);
        return;
    }
    if(vrmInfo)
    {
        if((bGetVideoDecType(bPath) == SV_VD_NA) || (bGetVideoDecType(bPath) == SV_VD_MAX))
        {
            pOutPosition->u4X = 0;
            pOutPosition->u4Y = 0;
            pOutPosition->u4Width = 0;
            pOutPosition->u4Height = 0;
        }
        else
        {
            pOutPosition->u4X = vrmInfo->u2X;
            pOutPosition->u4Y = vrmInfo->u2Y;
            pOutPosition->u4Width = vrmInfo->u2Width;
            pOutPosition->u4Height = vrmInfo->u2Height;

            if(GetPANEL4K2K_TYPE() == PANEL_TYPE_4K2K_60_SRS)
            {
                pOutPosition->u4X *= 2;
                pOutPosition->u4Y *= 2;
                pOutPosition->u4Width *= 2;
                pOutPosition->u4Height *= 2;
            }
        }
    }
#if MAPLE_SYS_DEBUG	 
    LOG(2, "====== DRVCUST_GetOutputPosition ======\n");
    LOG(2, "u4X 			 %d\n", pOutPosition->u4X);
    LOG(2, "u4Y 			 %d\n", pOutPosition->u4Y);
    LOG(2, "u4Width 		 %d\n", pOutPosition->u4Width);
    LOG(2, "u4Height		 %d\n", pOutPosition->u4Height);
    LOG(2, "bPath 		 %d\n", bPath);
#endif

}

void DRVCUST_GetSourceArea(UINT8 u1BeHandle, CUST_SRC_AREA_T* pSclReq)
{
    UINT8 u1Path;
	UINT32 u4Width;
	UINT32 u4Height;
	u1Path = DRVCUST_GetPathByBeHandle(u1BeHandle);

    if((pSclReq == NULL) || (u1Path > VDP_2 + 1))//main sub gfx
    {
        LOG(0,"%s invalid input PARAM\n",__FUNCTION__);
        return;
    }	
	pSclReq->u4SrcX 			= 0;//prVrmInfo->u2X;
	pSclReq->u4SrcY 			= 0;//prVrmInfo->u2Y;
	pSclReq->u4SrcWidth 		= 1920;//prVrmInfo->u2Width;
	pSclReq->u4SrcHeight		= 1080;//prVrmInfo->u2Height;
	
	u4Width  = u4GetPlaneWidth(u1GetOutputPlane(SV_VP_MAIN));
	u4Height = u4GetPlaneHeight(u1GetOutputPlane(SV_VP_MAIN));
	if (u4Width == 0 || u4Height == 0)
	{
		printf("Plane Weight/Height(%d,%d) error!!!!!!!!!!!!!!!!!!!!!\n",u4Width,u4Height);
	   // return (SV_FAIL);
	}
    switch(GetPANEL4K2K_TYPE())
    {
        case PANEL_TYPE_4K2K_60:
        case PANEL_TYPE_4K2K_60_SRS:
        case PANEL_TYPE_MAX:
            if((u1Path == SV_VP_MAIN) || (u1Path == SV_VP_PIP))
            {
                pSclReq->u4SrcWidth		= u4Width;
                pSclReq->u4SrcHeight	= u4Height;
                if(GetPANEL4K2K_TYPE() == PANEL_TYPE_4K2K_60_SRS && !fgIsMJCToOSTG())
                {
                    pSclReq->u4SrcWidth *= 2;
                    pSclReq->u4SrcHeight *= 2;
                }
            }
            else//gfx path
            {
                switch(GraphMode_GetPanelType())
                {
                    case PANEL_TYPE_4K2K_30:
                        pSclReq->u4SrcWidth		= 3840;//prVrmInfo->u2Width;
                        pSclReq->u4SrcHeight		= 2160;//prVrmInfo->u2Height;
                        break;
                    case PANEL_TYPE_4K1K_60:
                    case PANEL_TYPE_2K1K_60:
                    default:
                        pSclReq->u4SrcWidth		= 1920;//prVrmInfo->u2Width;
                        pSclReq->u4SrcHeight		= 1080;//prVrmInfo->u2Height;
                        break;
                }
            }
            break;
        case PANEL_TYPE_4K1K_120:
            if((u1Path == SV_VP_MAIN) || (u1Path == SV_VP_PIP))
            {
              pSclReq->u4SrcWidth = 3840;
              pSclReq->u4SrcHeight = 1080;
            }
            break;
        case PANEL_TYPE_2K1K_120:
        default:
            break;
    }
    
#if MAPLE_SYS_DEBUG
    LOG(2,"in DRVCUST_GetSourceArea u1Path (%d),SRCR(x,y,w,h)=(%d,%d,%d,%d)\n",u1Path,pSclReq->u4SrcX,pSclReq->u4SrcY,pSclReq->u4SrcWidth,pSclReq->u4SrcHeight);
#endif
}

void DRVCUST_GetScalingRequest(UINT8 u1BeHandle, CUST_DEST_AREA_T* pSclReq)
{
    if(pSclReq == NULL) 
    {
        LOG(0,"%s invalid input PARAM\n",__FUNCTION__);
        return;
    }	


    //always return 4k2k in trinity
    pSclReq->u4DestX = 0;
    pSclReq->u4DestY = 0;
    pSclReq->u4DestWidth = 3840;
    pSclReq->u4DestHeight= 2160;

	#if MAPLE_SYS_DEBUG
	LOG(2,"in DRVCUST_GetScalingRequest PNL type(%d),u1Path(%d),OUTR(x,y,w,h)=(%d,%d,%d,%d)\n",GetPANEL4K2K_TYPE(),pSclReq->u4DestX,pSclReq->u4DestY,pSclReq->u4DestWidth,pSclReq->u4DestHeight);
    #endif
}

void DRVCUST_GetOutputFormat(UINT8 u1TxPath, CUST_OUT_FMT_T* pOutFmt)
{
	UINT8 u1FrameRate;
       
    if (u1TxPath == 0)
    {
    	/*
        pOutFmt->u4ActX = 384;//vrmInfo->u2X;
        pOutFmt->u4ActY = 36;//vrmInfo->u2Y;
        pOutFmt->u4ActWidth = 3840;//vrmInfo->u2Width;
        pOutFmt->u4ActHeight = 1080;//= vrmInfo->u2Height;
        pOutFmt->u4Htotal = 4400;//vrmInfo->u2HTotal;       
        pOutFmt->u4Vtotal = 1125;//vrmInfo->u2VTotal;
        */
       	pOutFmt->u4ActX = lcdtimingInfo.u4HSyncWidth+ lcdtimingInfo.u4HBP;
        pOutFmt->u4ActY = lcdtimingInfo.u4VSyncWidth + lcdtimingInfo.u4VBP;
        pOutFmt->u4ActWidth = lcdtimingInfo.u4HActive;
        pOutFmt->u4ActHeight = lcdtimingInfo.u4VActive;
        pOutFmt->u4Htotal = lcdtimingInfo.u4HTotal;   
        pOutFmt->u4Vtotal = lcdtimingInfo.u4VTotal;   
        u1FrameRate = vDrvGetLCDFreq();

	
 
    switch(u4DrvTDTVDispModeQuery())
    {
        case E_TD_OUT_3D_FS:
            pOutFmt->eDimension = E_CUST_DIMENSION_3D;
            pOutFmt->e3dFormat = E_CUST_3D_FMT_FS;
            break;
        case E_TD_OUT_3D_LI:
            pOutFmt->eDimension = E_CUST_DIMENSION_3D;
            pOutFmt->e3dFormat = E_CUST_3D_FMT_LI;
            break;
        case E_TD_OUT_NATIVE:
        default:
            pOutFmt->eDimension = E_CUST_DIMENSION_2D;
            pOutFmt->e3dFormat = E_CUST_3D_FMT_UNKNOWN;
            break;
    }  
    

    switch(PANEL_GetControlWord() & DISP_BIT_MSK)
    {
        case DISP_24BIT:
            pOutFmt->eColorDepth = E_CUST_COL_DEPTH_8;
            break;
        case DISP_30BIT:
            pOutFmt->eColorDepth = E_CUST_COL_DEPTH_10;
            break;
        case DISP_36BIT:
            pOutFmt->eColorDepth = E_CUST_COL_DEPTH_12;
            break;
        default:
            pOutFmt->eColorDepth = E_CUST_COL_DEPTH_UNKNOWN;
            break;
    }

	if(fgYUVout)
	{
		pOutFmt->eColorimetry = E_CUST_COLMT_601; 
		pOutFmt->eColorFormat = E_CUST_COL_FMT_YUV_444;
		pOutFmt->eColorSpace = E_CUST_COL_SPACE_NORMAL;     
    	pOutFmt->eDynamicRange = E_CUST_DRANGE_LIMITED;  
	}
	else
	{
		pOutFmt->eColorimetry = E_CUST_COLMT_UNKOWN;
		pOutFmt->eColorFormat = E_CUST_COL_FMT_RGB;
		pOutFmt->eColorSpace = E_CUST_COL_SPACE_UNKNOWN;     
    	pOutFmt->eDynamicRange = E_CUST_DRANGE_FULL; 
	}
    
      
    pOutFmt->ePath = (pOutFmt->u4ActHeight > 1088) ? E_CUST_PATH_BYPASS: E_CUST_PATH_PQ;
	pOutFmt->bCtrlBitValid = (pOutFmt->u4ActHeight > 1088) ? 1 : 0;
	if(fgPhotoRasterModeIn4k && (bGetSignalType(SV_VP_MAIN) == SV_ST_MPEG))//4k photo only in pq path
	{
	    pOutFmt->ePath = E_CUST_PATH_PQ;
		pOutFmt->bCtrlBitValid = 0;
	}
		
    }
	else
	{
	    #if defined(SUPPORT_PANEL_GRAPH_MODE)
		pOutFmt->u4ActX = GFXTimingInfo.u4HSyncWidth+ GFXTimingInfo.u4HBP;
        pOutFmt->u4ActY = GFXTimingInfo.u4VSyncWidth + GFXTimingInfo.u4VBP;
        pOutFmt->u4ActWidth = GFXTimingInfo.u4HActive;
        pOutFmt->u4ActHeight = GFXTimingInfo.u4VActive;
        pOutFmt->u4Htotal = GFXTimingInfo.u4HTotal;   
        pOutFmt->u4Vtotal = GFXTimingInfo.u4VTotal;   
        u1FrameRate =  GFXTimingInfo.u1FrameRate; 
        #endif

		pOutFmt->eDimension = E_CUST_DIMENSION_2D;
        pOutFmt->e3dFormat = E_CUST_3D_FMT_UNKNOWN;
		pOutFmt->eColorDepth = E_CUST_COL_DEPTH_8;
		pOutFmt->eColorimetry = E_CUST_COLMT_UNKOWN;
		pOutFmt->eColorFormat = E_CUST_COL_FMT_RGB;
		pOutFmt->eColorSpace = E_CUST_COL_SPACE_UNKNOWN;     
    	pOutFmt->eDynamicRange = E_CUST_DRANGE_FULL; 

		pOutFmt->ePath = E_CUST_PATH_BYPASS;
		pOutFmt->bCtrlBitValid = 1;
	}
	
	switch (u1FrameRate)
    {
        case 8:
            pOutFmt->eFrameRate = E_CUST_FRAME_RATE_8;
            break;
        case 10:
            pOutFmt->eFrameRate = E_CUST_FRAME_RATE_10;
            break;
        case 12:
            pOutFmt->eFrameRate = E_CUST_FRAME_RATE_12;
            break;
        case 24:
            pOutFmt->eFrameRate = E_CUST_FRAME_RATE_24;
            break;
        case 25:
            pOutFmt->eFrameRate = E_CUST_FRAME_RATE_25;
            break;
        case 30:
            pOutFmt->eFrameRate = E_CUST_FRAME_RATE_30;
            break;        
        case 48:
            pOutFmt->eFrameRate = E_CUST_FRAME_RATE_48;
            break;
        case 50:
            pOutFmt->eFrameRate = E_CUST_FRAME_RATE_50;
            break;
        case 96:
            pOutFmt->eFrameRate = E_CUST_FRAME_RATE_96;
            break;                  
        case 100:
            pOutFmt->eFrameRate = E_CUST_FRAME_RATE_100;
            break;  
        case 120:
            pOutFmt->eFrameRate = E_CUST_FRAME_RATE_120;
            break;  
        case 60:           
        default:        
            pOutFmt->eFrameRate = E_CUST_FRAME_RATE_60;
            break;                 
    }  
	DEBUG_GetOutputVideoFormat(pOutFmt);

}

UINT8 DRVCUST_GetBorderPlaneRequest(UINT8 u1BeHandle)
{
	return 0;//to do
}

UINT8 DRVCUST_GetBlurRequest(UINT8 u1BeHandle)
{
	return 0;//to do
}


void DRVCUST_GetMCVPMeter(CUST_MCVP_METER_T* pMcvpMeter)
{
    pMcvpMeter->u1NoiseLevel = u1DrvNRGetOriNoiseLevel();
    pMcvpMeter->u1BlockNoiseLevel = u1DrvNXNRGetBlkConf();
    pMcvpMeter->u4FrmDiff = u4DrvDIGetMotionLevel();
    vDrvDIGetFreqStatus(&pMcvpMeter->u1FreqHpfV, &pMcvpMeter->u1FreqHpfH, &pMcvpMeter->u1FreqBpfH);
	vDrvNRGetBNRBlockSize(&pMcvpMeter->u2BlockSizeH, &pMcvpMeter->u2BlockSizeV);
}

E_CUST_CADENSE DRVCUST_GetCadense(void)
{
    EXTERN UINT8 bDrvGetFilmStatus(void);
    EXTERN UINT8 u1DI_Is50HZ;  
    UINT8 u1FilmMode = bDrvGetFilmStatus();
    E_CUST_CADENSE bCustCandense;
    
    if(u1DI_Is50HZ == SV_TRUE)
    {
        switch(u1FilmMode)
        {
            case E_DI_FILM_22:
                bCustCandense = E_CUST_CADENSE_22;
                break;
            case E_DI_FILM_44:
                bCustCandense = E_CUST_CADENSE_44;
                break;
            case E_DI_FILM_66:
                bCustCandense = E_CUST_CADENSE_66;
                break;
            default:
                bCustCandense = E_CUST_CADENSE_UNKOWN;
                break;
        }
    }
    else  	
    {
        switch(u1FilmMode)
        {
            case E_DI_FILM_32:
                bCustCandense = E_CUST_CADENSE_32;
                break;
            case E_DI_FILM_22:
                bCustCandense = E_CUST_CADENSE_22;
                break;
            case E_DI_FILM_2224:
                bCustCandense = E_CUST_CADENSE_2224;
                break;
            case E_DI_FILM_2332:
                bCustCandense = E_CUST_CADENSE_2332;
                break;
            case E_DI_FILM_32322:
                bCustCandense = E_CUST_CADENSE_32322;
                break;
            case E_DI_FILM_55:
                bCustCandense = E_CUST_CADENSE_55;
                break;
            case E_DI_FILM_64:
                bCustCandense = E_CUST_CADENSE_64;
                break;
            case E_DI_FILM_87:
                bCustCandense = E_CUST_CADENSE_87;
                break;
            default:
                bCustCandense = E_CUST_CADENSE_UNKOWN;
                break;
        }
    }
    if(bDrvVideoIsSrcInterlace(VDP_1) == SV_FALSE) 
    {   
        bCustCandense = E_CUST_CADENSE_UNKOWN;
    }
    #if MAPLE_SYS_DEBUG    
    //LOG(2, "\n====== DRVCUST_GetCadense: (%d)======\n",bCustCandense); 
    #endif
    return bCustCandense;
}


void DRVCUST_GetVRRStatus(E_CUST_VSYNC_MODE* pVsyncMode,E_CUST_FRAME_RATE* pFrameRate)
{
    UINT8 bSignalType = bGetSignalType(VDP_1);

    if(pVsyncMode != NULL && pFrameRate != NULL)
    {
        UINT8 u1FrameRate = 0;
        u1FrameRate = bDrvVideoGetRefreshRate(VDP_1);
        *pVsyncMode = eVRRGetSyncMode();
        if(*pVsyncMode == E_VRR_SYNC_MODE_FREERUN)
        {
            if(u1FrameRate <= 60)
            {
                *pFrameRate = E_CUST_FRAME_RATE_60;
            }
            else if(u1FrameRate <= 120)
            {
                *pFrameRate = E_CUST_FRAME_RATE_120;
            }
            else
            {
                *pFrameRate = E_CUST_FRAME_RATE_UNKNWON;
            }
        }
        else if(*pVsyncMode == E_VRR_SYNC_MODE_DIRECT)
        {
            if(u1FrameRate <= 50)
            {
                *pFrameRate = E_CUST_FRAME_RATE_50;
            }
            else if(u1FrameRate <= 60)
            {
                *pFrameRate = E_CUST_FRAME_RATE_60;
            }
            else if(u1FrameRate <= 96)
            {
                *pFrameRate = E_CUST_FRAME_RATE_96;
            }
            else if(u1FrameRate <= 100)
            {
                *pFrameRate = E_CUST_FRAME_RATE_100;
            }
            else if(u1FrameRate <= 120)
            {
                *pFrameRate = E_CUST_FRAME_RATE_120;
            }
            else
            {
                *pFrameRate = E_CUST_FRAME_RATE_UNKNWON;
            }
        }
        else
        {
            *pFrameRate = E_CUST_FRAME_RATE_UNKNWON;
        }
    }
}

E_CUST_FRAME_RATE DRVCUST_GetMJCInputFrequency(void)
{
	E_CUST_FRAME_RATE ret;	
    VRM_INFO_T* vrmInfo;
    UINT8 u1FrameRate = 0;
    u1FrameRate = bDrvVideoGetRefreshRate(VDP_1);
    
    vrmInfo = VRMGetVRMInfo(SV_VP_MAIN, VRM_MODULE_MJC);

    switch (vrmInfo->u2FrameRate)
    {
        case 8:
            ret = E_CUST_FRAME_RATE_8;
            break;
        case 10:
            ret = E_CUST_FRAME_RATE_10;
            break;
        case 12:
            ret = E_CUST_FRAME_RATE_12;
            break;
        case 24:
            ret = E_CUST_FRAME_RATE_24;
            break;
        case 25:
            ret = E_CUST_FRAME_RATE_25;
            break;
        case 30:
            ret = E_CUST_FRAME_RATE_30;
            break;        
        case 48:
            ret = E_CUST_FRAME_RATE_48;
            break;
        case 50:
            ret = E_CUST_FRAME_RATE_50;
            break;
        case 96:
            ret = E_CUST_FRAME_RATE_96;
            break;                  
        case 100:
            ret = E_CUST_FRAME_RATE_100;
            break;  
        case 120:
            ret = E_CUST_FRAME_RATE_120;
            break;  
        case 60:           
        default:        
            ret = E_CUST_FRAME_RATE_60;
            break;                 
    }
    if(eVRRGetSyncMode() == E_VRR_SYNC_MODE_FREERUN)
    {
        if(u1FrameRate <= 60)
        {
            ret = E_CUST_FRAME_RATE_60;
        }
        else if(u1FrameRate <= 120)
        {
            ret = E_CUST_FRAME_RATE_120;
        }
        else
        {
            ret = E_CUST_FRAME_RATE_UNKNWON;
        }
    }
    else if(eVRRGetSyncMode() == E_VRR_SYNC_MODE_DIRECT)
    {
        if(u1FrameRate <= 50)
        {
            ret = E_CUST_FRAME_RATE_50;
        }
        else if(u1FrameRate <= 60)
        {
            ret = E_CUST_FRAME_RATE_60;
        }
        else if(u1FrameRate <= 96)
        {
            ret = E_CUST_FRAME_RATE_96;
        }
        else if(u1FrameRate <= 100)
        {
            ret = E_CUST_FRAME_RATE_100;
        }
        else if(u1FrameRate <= 120)
        {
            ret = E_CUST_FRAME_RATE_120;
        }
        else
        {
            ret = E_CUST_FRAME_RATE_UNKNWON;
        }
    }

	return ret;
}


void DRVCUST_GetPostProcMeter(CUST_POST_PROC_METER_T* pPostProcMeter)
{
    UINT16 u2Window[4];  

    if(pPostProcMeter == NULL)
    {
        LOG(0,"%s invalid input PARAM\n",__FUNCTION__);
        return;
    }

    vDrvGetSatHistWindow(u2Window);
    pPostProcMeter->u4X = u2Window[0];    
    pPostProcMeter->u4Y = u2Window[1];    
    pPostProcMeter->u4Width = u2Window[2] - u2Window[0] + 1;
    pPostProcMeter->u4Height = u2Window[3] - u2Window[1] + 1;
    vDrvGetAPLLR(&pPostProcMeter->u1APLL, &pPostProcMeter->u1APLR);
	vDrvGetASLLR(&pPostProcMeter->u1ASLL, &pPostProcMeter->u1ASLR);
    vDrvGetLuma113HistLR_Raw(pPostProcMeter->u4LumaHistL, pPostProcMeter->u4LumaHistR, 0);
    vDrvGetInputLumaMaxLR(&pPostProcMeter->u1LumaMaxL, &pPostProcMeter->u1LumaMaxR);
    vDrvGetInputLumaMinLR(&pPostProcMeter->u1LumaMinL, &pPostProcMeter->u1LumaMinR);
	vDrvGetInputLumaSumLR(&pPostProcMeter->u4LumaSumL, &pPostProcMeter->u4LumaSumR);
	vDrvGetSatHistLR(pPostProcMeter->u2SatHistL, pPostProcMeter->u2SatHistR, 0);
    vDrvGetHueHistLR(pPostProcMeter->u2HueHistL, pPostProcMeter->u2HueHistR, 0);   
	
}

void DRVCUST_GetPostProcTdHistMeter(UINT8* pData)
{
	UINT16 i, j, k; //for customer order
	UINT16 x, y; //for turnkey order
    if(pData == NULL)
    {
		return;
	}
	static UINT8 cust_ysh_bin[YSH_Y_NUM][YSH_S_NUM][YSH_H_NUM];//32 bit is 4Byte, 1 Byte means 1Bin, will return to Customer
	static UINT8 turnkey_hys_bin[YSH_H_NUM][YSH_Y_NUM][YSH_S_NUM];//this is inside MTK turnkey order
	vDrvGetYSH3DHistHW();
	//below for re-ordering the waYSH3DHist[] to turnkey_hys_bin bin order
	for(x = 0 ; x < YSH_H_NUM; x++)
	{
		for(y = 0 ; y < YSH_Y_NUM; y++)
		{
			turnkey_hys_bin[x][y][0] =(UINT8) (waYSH3DHist[x*6+y*2]&0x000000FF);
			turnkey_hys_bin[x][y][1] =(UINT8) ((waYSH3DHist[x*6+y*2]&0x0000FF00)>>8);
			turnkey_hys_bin[x][y][2] =(UINT8) ((waYSH3DHist[x*6+y*2]&0x00FF0000)>>16);
			turnkey_hys_bin[x][y][3] =(UINT8) ((waYSH3DHist[x*6+y*2]&0xFF000000)>>24);
			turnkey_hys_bin[x][y][4] =(UINT8) (waYSH3DHist[x*6+y*2+1]&0x000000FF);
			turnkey_hys_bin[x][y][5] =(UINT8) ((waYSH3DHist[x*6+y*2+1]&0x0000FF00)>>8);
			turnkey_hys_bin[x][y][6] =(UINT8) ((waYSH3DHist[x*6+y*2+1]&0x00FF0000)>>16);
			turnkey_hys_bin[x][y][7] =(UINT8) ((waYSH3DHist[x*6+y*2+1]&0xFF000000)>>24);
		}
	}
	//below for re-ordering the turnkey_hys_bin[] to cust_ysh_bin bin order
	for(i = 0 ; i < YSH_Y_NUM; i++)
	{
		for(j = 0 ; j < YSH_S_NUM; j++)
		{
			for(k = 0 ; k < YSH_H_NUM; k++)
			{
				cust_ysh_bin[i][j][k] = turnkey_hys_bin[k][i][j]; //order remapping for cust spec
			}
		}
	}
	for(i = 0; i < YSH_H_NUM; i++)
	{
		for(j = 0; j < YSH_Y_NUM; j++)
		{
			for(k = 0; k < YSH_S_NUM; k++)
			{
				LOG(3,"bin[%d][%d][%d]:%02x  ", i, j, k, turnkey_hys_bin[i][j][k]);
			}
			LOG(3,"\n");
		}
		LOG(3,"\n");
		LOG(3,"\n");
	}
	LOG(3,"\n");

	for(i= 0 ; i<72;i++)
	LOG(3,"bin[%d]:%00000008x  ",i, waYSH3DHist[i]);
	x_memcpy(pData, cust_ysh_bin, sizeof(cust_ysh_bin));
}

void DRVCUST_GetLdMeter(CUST_LD_METER_T* pLdMeter)
{
	vDrvLcdimGetBlkinfo(pLdMeter->u1LdMaxRGB);
	u1DrvGetRGBHist(pLdMeter->u2LdMaxHist, 4096);
	vDrvGetLcDimDimmingResultHW(pLdMeter->u2LdDimInfo);
}

UINT8 DRVCUST_GetAnalogDecNoiseLevel(UINT8 bPath)
{
    // signal level : db value
    UINT8 u1aNL;
    if (bGetVideoDecType(bPath) == SV_VD_TVD3D) 
    {
    	u1aNL=bTvdSignalStrengthLevel(1);
        return u1aNL;
    }
	else
	{
	    return 0;
	}
}

UINT8 DRVCUST_GetOpticalSensorLevel(void)
{    
    return dwOpticalSensorAvgValue;
}

UINT8 DRVCUST_GetIlluminance(void)
{
    UINT32 u4OpticalSensorValue = DRVCUST_GetOpticalSensorLevel();
    const UINT32 u4offSet = 63500;

    //Convert Digital Value to Lux
    return (u4OpticalSensorValue * 958 < u4offSet) ? 0 : ((u4OpticalSensorValue * 958 - u4offSet) / 1000);
}

UINT8 DRVCUST_GetTemperatureSensorLevel(void)
{
	INT32 i4ReadTemperature = CustomQueryTemperature();
	UINT8 u1Temperature = 0;
	
	u1Temperature = (i4ReadTemperature & 0xFF);
	
	if(i4ReadTemperature & 0xFFFFFF00)
	{
		u1Temperature = 0;
	}
	
	return u1Temperature;
}

UINT8 DRVCUST_GetBLPowerLimit(void)
{
	#ifdef CC_PowerCons_Ctrl
	return C_BL_POWER_LIMIT;
	#endif
	return 255;
}


UINT8 DRVCUST_GetPwmSetting(void)
{  
    return 0;   // PQ
}

void DRVCUST_GetVideoFrameDelay(CUST_VDO_DELAY_INFO_T* pVdoDelayInfo)
{

    if(pVdoDelayInfo == NULL) 
    {
        LOG(0,"%s invalid input PARAM\n",__FUNCTION__);
        return;
    }

    pVdoDelayInfo->u4MCVP = u1DrvDIGetFrameDelay10x(SV_VP_MAIN);
    pVdoDelayInfo->u4Scaler = u1DrvScpipGetFrmDelay10x(SV_VP_MAIN);
    pVdoDelayInfo->u4MJC = u1DrvMJCGetFrmDelay10x();    

}

void DRVCUST_GetHistoryData(CUST_HISTORY_DATA_T* pHistoryData)
{
    BESYS_AP_Get_History_Data(pHistoryData);    // APP
}

void DRVCUST_GetPowerState(CUST_POWER_STATE_T* pPowerState)
{
	#ifdef CC_SUPPORT_STR
    if(ostg_get_fgPanelPowerState())
    {
    	pPowerState->ePanelState = E_CUST_PANEL_STATE_ON;
    }
	else
	{
    	pPowerState->ePanelState = E_CUST_PANEL_STATE_OFF;
    }
	#else
	pPowerState->ePanelState = E_CUST_PANEL_STATE_ON;
	#endif	
	//LOG(2, "ePanelState	    %d\n", pPowerState->ePanelState); 
}

UINT32 DRVCUST_GetPanleIDMatchState(void)
{
    UINT8 u1Val=0;
    
	EEPROM_Read(0xb105, (UPTR)(void *)&u1Val, 1);

    return (UINT32)u1Val;
}

UINT32 DRVCUST_GetDecoderAvgBitRate(UINT8 ucEsId)
{    
    UINT32 u4BitRate = 0;    
    VDEC_GetDataSizePerSecond(ucEsId, &u4BitRate);   

    return u4BitRate;
}


UINT32 DRVCUST_BePartitionRead(E_CUST_BE_PART ePartId, UINT32 u4Offset, VOID *pvBuf, UINT32 u4BufSize)
{
	UINT64 u8Offset;
	UINT32 u4RelPartId=0 ;

    LOG(2, "DRVCUST_BePartitionRead\n");
	if(ePartId >= E_CUST_PART_MAX)
	{
		Printf("%s error : partid is invalid\n", __FUNCTION__);
		return 1 ;
	}
	if (DRVCUST_InitQuery(eBELPartitionId, &u4RelPartId) != 0 )
	{
		Printf("%s error query BE ID\n", __FUNCTION__);
		return 1;
	}
	u4RelPartId += ePartId ;

	u8Offset = ((UINT64)((UINT64)u4RelPartId << 32)) | u4Offset ;
	return MSDCPART_Read(u8Offset, (UPTR) pvBuf, u4BufSize);
}

UINT32 DRVCUST_SopqPartitionRead(E_CUST_SPQ_PART ePartId, UINT32 u4Offset, VOID *pvBuf, UINT32 u4BufSize)
{
	UINT64 u8Offset;
	UINT32 u4RelPartId=0 ;

    LOG(2, "DRVCUST_SopqPartitionRead\n");
	if(ePartId >= E_CUST_PART_SPMAX)
	{
		Printf("%s error : partid is invalid\n", __FUNCTION__);
		return 1 ;
	}

	if(ePartId == E_CUST_PART_SPQD)
	{
		if (DRVCUST_InitQuery(eSPQDPartition, &u4RelPartId) != 0 )
		{
			Printf("%s error eSPQDPartition ID\n", __FUNCTION__);
			return 1;
		}	
	}
	else
	{
		if (DRVCUST_InitQuery(eSPQCPartition, &u4RelPartId) != 0 )
		{
			Printf("%s error eSPQCPartition ID\n", __FUNCTION__);
			return 1;
		}	
	}

	u8Offset = ((UINT64)((UINT64)u4RelPartId << 32)) | u4Offset ;
	return MSDCPART_Read(u8Offset, (UPTR) pvBuf, u4BufSize);
}

UINT16 DRVCUST_GetAdcValue(E_CUST_ADC_PORT eAdcPort)
{
	UINT32 u4Channel ;
	switch (eAdcPort)
    {
        case E_CUST_ADC_PORT_SCART_FS:
        case E_CUST_ADC_PORT_KEY:
        case E_CUST_ADC_PORT_LIGHT_SENSOR:
		case E_CUST_ADC_PORT_BL_ERR_DET:
		case E_CUST_ADC_PORT_PANEL_PWR_DET:
		case E_CUST_ADC_PORT_USB_OC2_DET:
		case E_CUST_ADC_PORT_RF_AGCI:
		case E_CUST_ADC_PORT_X_SYSTEM_RST:
		case E_CUST_ADC_PORT_12V_DET:
		case E_CUST_ADC_PORT_5V_DET:
			u4Channel = eAdcPort;
			break;
		case E_CUST_ADC_PORT_ADIN5_SRV:
			u4Channel = 5;
			break;
		case E_CUST_ADC_PORT_ADIN7_SRV:
			u4Channel = 7;
        default:        
			break;

    }
//	u4Channel = eAdcPort;

	return (UINT16) PDWNC_ReadServoADCChannelValue(u4Channel) ;

}

void DRVCUST_GetScreenSaver(CUST_SCREEN_SAVER_T* pScreenSaver)
{
	BESYS_AP_Get_Screen_Saver(pScreenSaver);    // APP
}

void DRVCUST_GetAgingMode(CUST_AGING_MODE_T* pAgingMode)
{
	if(gAgingInit)
	{
		BESYS_AP_Get_Aging_Mode(pAgingMode);    // APP
	}
	else
	{
		pAgingMode->bAgingMode = DRVCUST_EepromReadByte(0x7D0);	//get from EEProm
	}
	//LOG(2, "DRVCUST_GetAgingMode  = %d\n", pAgingMode->bAgingMode);
}

void DRVCUST_GetTvOutputFormat(CUST_TV_OUT_FMT_T* pTvOutFmt)
{
    /*
	switch (arMJCPrm.arFRCConfig.u13DModeOut)
    {
        
		case E_VDO_MJC_OUT_2D:
			pTvOutFmt->eDimension = E_CUST_DIMENSION_2D; 
			break;
		case E_VD0_MJC_OUT_FS:
		case E_VD0_MJC_OUT_HPR:
        case E_VD0_MJC_OUT_FPR:
			pTvOutFmt->eDimension = E_CUST_DIMENSION_3D; 
			break;
		case E_VD0_MJC_OUT_OTHER:
			pTvOutFmt->eDimension = E_CUST_DIMENSION_UNKNOWN; 
			break;	
        default:    
			pTvOutFmt->eDimension = E_CUST_DIMENSION_2D; 
			break;

    }
	*/

}

extern UINT8 u1VRMTNRPathOn(void);
void DRVCUST_GetMuffinScalerInfo(UINT8 bPath, CUST_SCL_AREA_T* pScalerArea)
{
	VRM_INFO_T* vrmInfo;

    if((pScalerArea == NULL) || (bPath > VDP_2))
    {
        LOG(0,"%s invalid input PARAM\n",__FUNCTION__);
        return;
    }

    vrmInfo = VRMGetVRMInfo(bPath, VRM_MODULE_PDS);

	pScalerArea->t_DownScalerInput.u4Width = vrmInfo->u2Width;
	pScalerArea->t_DownScalerInput.u4Height= vrmInfo->u2Height;

    if((bPath == VDP_1) && u1VRMTNRPathOn())
    {
    	vrmInfo = VRMGetVRMInfo(SV_VP_TNR, VRM_TNR_MODULE_REGEN);
    }
    else
    {
    	vrmInfo = VRMGetVRMInfo(bPath, VRM_MODULE_REGEN);
    }


	pScalerArea->t_DownScalerOutput.u4Width = vrmInfo->u2Width;
	pScalerArea->t_DownScalerOutput.u4Height= vrmInfo->u2Height;

	vrmInfo = VRMGetVRMInfo(bPath, VRM_MODULE_FSC);

	pScalerArea->t_ScalerInput.u4Width = vrmInfo->u2Width;
	pScalerArea->t_ScalerInput.u4Height= vrmInfo->u2Height;

	vrmInfo = VRMGetVRMInfo(bPath, VRM_MODULE_MIXER);

    if(GetPANEL4K2K_TYPE() == PANEL_TYPE_4K2K_60_SRS && !fgApiVideoIsVgaTiming(bPath))
    {
        pScalerArea->t_ScalerOutput.u4Width = vrmInfo->u2Width / 2;
        pScalerArea->t_ScalerOutput.u4Height= vrmInfo->u2Height / 2;
    }
    else
    {
        pScalerArea->t_ScalerOutput.u4Width = vrmInfo->u2Width;
        pScalerArea->t_ScalerOutput.u4Height= vrmInfo->u2Height;
    }

	pScalerArea->t_ScalerTiming.u4Width = u4ScpipGetPanelWidth(E_FSC_TG);
	pScalerArea->t_ScalerTiming.u4Height = u4ScpipGetPanelHeight(E_FSC_TG);
	LOG(0,"in DRVCUST_GetMuffinScalerInfo scaler output timing(%d,%d)\n",pScalerArea->t_ScalerTiming.u4Width,pScalerArea->t_ScalerTiming.u4Height);

	
}

void DRVCUST_GetOsdState(BOOL* bOsdState)
{
	if(bOsdState == NULL)
    {        
        Printf("DRVCUST_GetOsdState NULL pointer \n");
        return;
    }
	*bOsdState = OSD_BASE_IsDisplaying();
}

void DRVCUST_GetModelVariationInfoStartAddress(UINT32* pAddress)
{
	if(pAddress == NULL)
    {        
        Printf("DRVCUST_GetModelVariationInfoStartAddress NULL pointer \n");
        return;
    }
	*pAddress = 0x10000;
}

void DRVCUST_GetScreenMirroringConfig(UINT8 bPath, CUST_SCR_MIRROR_CONFIG_T* pScrMirrorConfig)
{
	D_AP_INPUT_TYPE eType = BEPQ_AP_Get_Input_Type(bPath);
    if((pScrMirrorConfig == NULL) || (bPath > VDP_2))
    {
        LOG(0,"%s invalid input PARAM\n",__FUNCTION__);
        return;
    }


	if(eType == D_AP_INPUT_TYPE_MIRACAST)
		{
		
		if(gWFDProtocol == 0)
		{
			pScrMirrorConfig->eProtocol = CUST_SCR_MIRROR_PROTOCOL_UDP;
		}
		else if(gWFDProtocol == 1)
		{
			pScrMirrorConfig->eProtocol = CUST_SCR_MIRROR_PROTOCOL_TCP;
		}
		else
		{
			pScrMirrorConfig->eProtocol = CUST_SCR_MIRROR_PROTOCOL_UNKNOWN;
		}
	}
	else
	{
		pScrMirrorConfig->eProtocol = CUST_SCR_MIRROR_PROTOCOL_UNKNOWN;
	}
}

void DRVCUST_GetLetterBoxDetection(CUST_LETTER_BOX_INFO_T* pLetterBoxInfo)
{
	UINT32 u4LBoxX = 0;
    UINT32 u4LBoxY = 0;
    UINT32 u4LBoxWidth = 0;
    UINT32 u4LBoxHeight = 0;
	UINT32 u4LBoxVValid, u4LBoxHValid;
	UINT32 u4Width = wDrvVideoInputWidth(SV_VP_MAIN);
	UINT32 u4Height = wDrvVideoInputHeight(SV_VP_MAIN);
	
	LboxQueryRegion(&u4LBoxX, &u4LBoxY, &u4LBoxWidth, &u4LBoxHeight, &u4LBoxHValid, &u4LBoxVValid);

    if((u4LBoxVValid == 0)	|| ((_u4LBoxDetectionEnable & LBOX_ONOFF_AP)!=LBOX_ONOFF_AP))
    {
        pLetterBoxInfo->u4LBoxUpFinal = 0;
        pLetterBoxInfo->u4LBoxLowFinal = 0;
    }
    else
    {
        // use LBOY result
        pLetterBoxInfo->u4LBoxUpFinal = u4LBoxY;
        pLetterBoxInfo->u4LBoxLowFinal = u4Height - u4LBoxHeight - u4LBoxY;
    }

    if((u4LBoxHValid == 0) || ((_u4LBoxDetectionEnable & LBOX_ONOFF_AP)!=LBOX_ONOFF_AP))
    {
        pLetterBoxInfo->u4LBoxLeftFinal = 0;
        pLetterBoxInfo->u4LBoxRightFinal = 0;
    }
    else
    {
        // use LBOY result
        pLetterBoxInfo->u4LBoxLeftFinal = u4LBoxX;
        pLetterBoxInfo->u4LBoxRightFinal = u4Width - u4LBoxWidth - u4LBoxX;
    }
	
 //   Printf(" -Letbox T %d B %d L %d R %d \n", 
//		(int)pLetterBoxInfo->u4LBoxUpFinal, (int)pLetterBoxInfo->u4LBoxLowFinal, (int)pLetterBoxInfo->u4LBoxLeftFinal, (int)pLetterBoxInfo->u4LBoxRightFinal);
	
    return ;
}

//sce capture
void DRVCUST_GetScePixMonData(CUST_SCE_CAP_DATA_T* pData)
{

	pData->SceInput.u2Y_G= IO32ReadFldAlign(CAP_IN_DATA_MAIN, CAP_IN_Y);
	pData->SceInput.u2Cb_B= IO32ReadFldAlign(CAP_IN_DATA_MAIN, CAP_IN_CB);
	pData->SceInput.u2Cr_R= IO32ReadFldAlign(CAP_IN_DATA_MAIN_CR, CAP_IN_CR);

	pData->SceOutput.u2Y_G= IO32ReadFldAlign(CAP_OUT_DATA_MAIN, CAP_OUT_Y);
	pData->SceOutput.u2Cb_B= IO32ReadFldAlign(CAP_OUT_DATA_MAIN, CAP_OUT_CB);
	pData->SceOutput.u2Cr_R= IO32ReadFldAlign(CAP_OUT_DATA_MAIN_CR, CAP_OUT_CR);
}

//ostg captue
void DRVCUST_GetOstgPixMonData(CUST_CAP_DATA_T* pData)
{
	pData->u2Cr_R = IO32ReadFldAlign(DUMP_04, POS_OUT_R);
	pData->u2Y_G  = IO32ReadFldAlign(DUMP_04, POS_OUT_G);
	pData->u2Cb_B = IO32ReadFldAlign(DUMP_05, POS_OUT_B);
}

void DRVCUST_Get4bandFreqHist(CUST_4BAND_HIST_T* pData)
{
	UINT8 i;
	if(pData!=NULL)
	{
        x_memcpy(pData, &CUST_4BAND_HIST_VALUE, sizeof(CUST_4BAND_HIST_T));				
	}
	else
	{
        LOG(2, "DRVCUST_Get4bandFreqHist Failed !!!!\n");
	}
}

void DRVCUST_GetDecoderMeter(UINT8 bPath, CUST_DECODER_METER_T* pDecoderMeter)
{
    B2R_QP_VAL_T t_B2RGetQPValue;

    if (B2R_Get_Cust_info(bPath, B2R_GET_TYPE_QP_INFO, &t_B2RGetQPValue, sizeof(B2R_QP_VAL_T)))
    {
        pDecoderMeter->b1Valid  = SV_FALSE;
        pDecoderMeter->s1QpPPS  = 0x80;
        pDecoderMeter->s1QpPictrue = 0x80;
        pDecoderMeter->s1QpMB   = 0x80;
    }
    else
    {
        pDecoderMeter->b1Valid              = SV_TRUE;
        pDecoderMeter->s1QpPPS              = t_B2RGetQPValue.i4PPSLayerQp;
        pDecoderMeter->s1QpPictrue          = t_B2RGetQPValue.i4SliceLayerQp;
        pDecoderMeter->s1QpMB               = t_B2RGetQPValue.i4MBLayerQp;
		pDecoderMeter->u1QpMin				= t_B2RGetQPValue.i4QpMin;
		pDecoderMeter->u1QpMax				= t_B2RGetQPValue.i4QpMax;
        pDecoderMeter->u1PictureCodingType  = t_B2RGetQPValue.tDecInfo.u1PictureCodingType;
        pDecoderMeter->u4GeneratedBit       = t_B2RGetQPValue.tDecInfo.u4GeneratedBit;
        pDecoderMeter->u1OddEven            = t_B2RGetQPValue.tDecInfo.u1OddEven;
        pDecoderMeter->u1color_primaries    = t_B2RGetQPValue.tDecInfo.u1color_primaries;
        pDecoderMeter->u1transfer_characteristics = t_B2RGetQPValue.tDecInfo.u1transfer_characteristics;
        pDecoderMeter->u1matrix_coefficients = t_B2RGetQPValue.tDecInfo.u1matrix_coefficients;

        x_memcpy(pDecoderMeter->u1ScalingListIntra, t_B2RGetQPValue.tDecInfo.u1ScalingListIntra, sizeof(pDecoderMeter->u1ScalingListIntra));
        x_memcpy(pDecoderMeter->u1ScalingListInter, t_B2RGetQPValue.tDecInfo.u1ScalingListInter, sizeof(pDecoderMeter->u1ScalingListInter));
        x_memcpy(pDecoderMeter->u1UserData, t_B2RGetQPValue.tDecInfo.u1UserData, sizeof(pDecoderMeter->u1UserData));
    }
}

UPTR DRVCUST_GetVirtual2PhysicalAddress(UPTR* pVirtualAddress)
{
	return PHYSICAL(pVirtualAddress);
}

UPTR DRVCUST_GetPhysical2VirtualAddress(UPTR* pPhysicalAddress)
{
	return VIRTUAL(pPhysicalAddress);
}

void DRVCUST_GetPicControlState(E_CUST_PIC_CONTROL_STATE *pPicControlState)
{
	*pPicControlState = CUST_PIC_CONTROL_STATE;
}

UINT32 DRVCUST_GetOsdPixelCount(void)
{
	return (IO_READ32MSK(OSD_MIXER_OSTG1, 0, OSD_MIXER_INDEX_COUNTER_MASK) >> 9) +
		   (IO_READ32MSK(OSD_MIXER_OSTG2, 0, OSD_MIXER_INDEX_COUNTER_MASK) >> 9);
}

void DRVCUST_GetColorimetryConvCapability(UINT32* pSize, CUST_COL_CONV_CAPABILITY_PATTERN_T* pColConvCapabilityPattern)
{
	UINT8 i;
	if(pSize==NULL)
	{
		LOG(0, "pSize initial Failed !!!!\n");
		return;
	}
	if(pColConvCapabilityPattern==NULL)
	{
		LOG(0, "pColConvCapabilityPattern initial Failed !!!!\n");
		return;
	}
	*pSize = sizeof(supported_pattern_list)/sizeof(supported_pattern_list[0]);
	//pColConvCapabilityPattern = supported_pattern_list;
	x_memcpy(pColConvCapabilityPattern,supported_pattern_list,sizeof(supported_pattern_list));

	LOG(0, "*pSize=%d\n\n\n",*pSize);
	for(i=0; i<*pSize; i++)
	{
			LOG(0, "supported_pattern_list[%d]={%d  %d  %d} !!!!\n",i,supported_pattern_list[i].block,supported_pattern_list[i].src,supported_pattern_list[i].dst);

		LOG(0, "\n");
	}
}

void DRVCUST_ReadEDID(UINT8 u1Type, UINT8* pBuff, UINT32* pOffset)
{
    vHDMIEDIDReadEDID(u1Type, pBuff, pOffset);
}

UINT8 DRVCUST_GetHDMIPortNumber(void)
{
    UINT8 u1Port;
    u1Port = u1HdmiIf_GetActivePort(SV_VP_MAX);
    LOG(0, "DrvCust Get Hdmi Port Number:%d\n", u1Port);
    return u1Port;
}

UINT8 DRVCUST_GetOsdPixCountAlphaThresh(void)
{
	if(IO_READ32MSK(OSD_MIXER_OSTG1, 0, OSD_MIXER_INDEX_THD_MASK)==IO_READ32MSK(OSD_MIXER_OSTG2, 0, OSD_MIXER_INDEX_THD_MASK))
    	return IO_READ32MSK(OSD_MIXER_OSTG2, 0, OSD_MIXER_INDEX_THD_MASK);
    else
    {
    	LOG(0, "DRVCUST_GetOsdPixCountAlphaThreshFail\n");
    	return 0;
    }
}
void DRVCUST_GetPqTdHistConfig(CUST_TDHIST_CONFIG_PARAM_T* pData)
{
	if(pData == NULL)
	{
		return;
	}

	pData->ysh_3d_hist_cen = IO32ReadFldAlign(YSH_3D_HIST_CTRL_0, YSH_3D_HIST_CEN);
	pData->ysh_3d_nonlinear_norm = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_9, YSH_3D_NONLINEAR_NORM);
	pData->ysh_3d_norm_variance = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_9, YSH_3D_NORM_VARIANCE);
	pData->ysh_3d_y_interval[0] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_0, YSH_3D_Y_INTERVAL_0);
	pData->ysh_3d_y_interval[1] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_0, YSH_3D_Y_INTERVAL_1);
	
	pData->ysh_3d_s_interval[0] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_0, YSH_3D_S_INTERVAL_0);
	pData->ysh_3d_s_interval[1] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_1, YSH_3D_S_INTERVAL_1);
	pData->ysh_3d_s_interval[2] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_1, YSH_3D_S_INTERVAL_2);
	pData->ysh_3d_s_interval[3] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_2, YSH_3D_S_INTERVAL_3);
	pData->ysh_3d_s_interval[4] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_2, YSH_3D_S_INTERVAL_4);
	pData->ysh_3d_s_interval[5] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_3, YSH_3D_S_INTERVAL_5);
	pData->ysh_3d_s_interval[6] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_3, YSH_3D_S_INTERVAL_6);
	
	pData->ysh_3d_h_interval[0] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_4, YSH_3D_H_INTERVAL_0);
	pData->ysh_3d_h_interval[1] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_4, YSH_3D_H_INTERVAL_1);	
	pData->ysh_3d_h_interval[2] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_5, YSH_3D_H_INTERVAL_2);	
	pData->ysh_3d_h_interval[3] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_5, YSH_3D_H_INTERVAL_3);	
	pData->ysh_3d_h_interval[4] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_6, YSH_3D_H_INTERVAL_4);	
	pData->ysh_3d_h_interval[5] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_6, YSH_3D_H_INTERVAL_5);	
	pData->ysh_3d_h_interval[6] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_7, YSH_3D_H_INTERVAL_6);	
	pData->ysh_3d_h_interval[7] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_7, YSH_3D_H_INTERVAL_7);	
	pData->ysh_3d_h_interval[8] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_8, YSH_3D_H_INTERVAL_8);	
	pData->ysh_3d_h_interval[9] = IO32ReadFldAlign(YSH_3D_HIST_CONFIG_8, YSH_3D_H_INTERVAL_9);	
	pData->ysh_3d_h_interval[10]= IO32ReadFldAlign(YSH_3D_HIST_CONFIG_9, YSH_3D_H_INTERVAL_10);

	
}
void DRVCUST_TestWatchdogReset(UINT8 u1WatchdogID)
{
    if (0 == u1WatchdogID) {
        PDWNC_Reboot();
    }
    else if (1 == u1WatchdogID) {
        PDWNC_Reboot1();
    }
    else if (2 == u1WatchdogID) {
        PDWNC_Reboot2();
    }
    else {
    	LOG(0, "DRVCUST_TestWatchdogReset: Invalid ID: %d!\n", u1WatchdogID);
    }
}

BOOL DRVCUST_IsMaintenanceReset(void)
{
    return (BOOL)((PDWNC_ReadWakeupReason() == PDWNC_WAKE_UP_REASON_WATCHDOG)
           && ((u4IO32Read4B(PDWNC_WDTCTL) & 0x07000000) == 0x04000000));
}
void DRVCUST_GetDOVIType(UINT8 bPath, E_CUST_DOVI_TYPE* pSignalFormat)
{
	if(pSignalFormat == NULL)
	{
		LOG(0, "Pointer E_CUST_DOVI_TYPE* Invalid !\n");
		return;
	}
	
	if(bPath != VDP_1)
	{
		LOG(0, " DOVI only supported in Main Path!\n");
		*pSignalFormat = E_CUST_DOVI_TYPE_NONE;
		return;
	}
	if(!u4DolbyGetCustSourceInfo(bPath))
	{
		LOG(0, " Current source is Not DOVI!\n");
		*pSignalFormat = E_CUST_DOVI_TYPE_NONE;
		return;
	}
	else
	{
		*pSignalFormat = u4DolbyGetDoviType();//value from DV loop
	}
}

void DRVCUST_GetRGBSensorLevel(CUST_RGB_SENSOR_LEVEL_T *pRgbSensorLevel)
{
    UINT16 r_level = 0x0000;
    UINT16 g_level = 0x0000;
    UINT16 b_level = 0x0000;
    UINT16 c_level = 0x0000;
    UINT16 ir_level = 0x0000;

    if (pRgbSensorLevel == NULL)
    {
        LOG(0, "%s invalid input PARAM!\n", __FUNCTION__);
        return;
    }
    pRgbSensorLevel->device_error = CustomQueryRGBSensorData(&r_level, &g_level, &b_level, &c_level, &ir_level);
    pRgbSensorLevel->r_level = r_level;
    LOG(2, "%s r_level = 0x%04X\n", __FUNCTION__, pRgbSensorLevel->r_level);
    pRgbSensorLevel->g_level = g_level;
    LOG(2, "%s g_level = 0x%04X\n", __FUNCTION__, pRgbSensorLevel->g_level);
    pRgbSensorLevel->b_level = b_level;
    LOG(2, "%s b_level = 0x%04X\n", __FUNCTION__, pRgbSensorLevel->b_level);
    pRgbSensorLevel->c_level = c_level;
    LOG(2, "%s c_level = 0x%04X\n", __FUNCTION__, pRgbSensorLevel->c_level);
    pRgbSensorLevel->ir_level = ir_level;
    LOG(2, "%s ir_level = 0x%04X\n", __FUNCTION__, pRgbSensorLevel->ir_level);
}

UINT8 DRVCUST_GetRGBSensorID(void)
{
    return CustomQueryRGBSensorDeviceID();
}

void DRVCUST_GetPqFaceDetInfo(UINT8* u1Num)
{
	*u1Num = bDrvFDVdoHasFace();
}

void DRVCUST_GetPqSkinLumaHistMeter(UINT32* u4LumaHist)
{

	static UINT32 waSkinLumaHist_Raw[2][SKIN_LUMA_HIST_NUM];
	UINT8 i = 0;
	if(u4LumaHist == NULL)
	{
		LOG(0, "Err! Pointer u4LumaHist is Null!! \n");
	}

	vDrvGetSkinLumaHistLR_Raw(&waSkinLumaHist_Raw[0][0], &waSkinLumaHist_Raw[1][0], 0);
	for(i = 0; i < SKIN_LUMA_HIST_NUM; i++)//no 3D case
	{
		u4LumaHist[i] = waSkinLumaHist_Raw[0][i];
	}
}
void DRVCUST_GetDolbyVisionGlobalDimming(CUST_GLOBAL_DIMMING_INFO_T *pGlobalDimmingInfo)
{
	if(NULL== pGlobalDimmingInfo)
	{
		LOG(0, "DRVCUST_GetDolbyVisionGlobalDimming:input  Parameter Incorrect!,pGlobalDimmingInfo is NULL!\n");
		return;
	}
	
#ifdef CC_SUPPORT_DOLBY_VISION
	pGlobalDimmingInfo->dv_en = u4DolbyGetCustSourceInfo(VDP_1);
	if(u4DolbyGetCustSourceInfo(VDP_1)==1  \
			&& u4DolbyGetGlobalDimmingInfo()==1 \
			&& u4DolbyGetGdPwmValue() != 256	\
			&& u1DolbyGetPicModeReadyFlag() == true \
			&& 	doviGdInfoAfterVideoPmwSnc.u4DvGdValid == true)
		{
			pGlobalDimmingInfo->dv_gd_en = true;
		}
		else
		{
			pGlobalDimmingInfo->dv_gd_en = false;
		}
		pGlobalDimmingInfo->gd_bl_duty = doviGdInfoAfterVideoPmwSnc.u4DvGdDuty;
		//also can ext to send more info to sony,such as sence change flag,the next gd value,and other ext info carryed in dv matedata
		
		if(ptr_gd_debug_info && (doviGdInfoAfterVideoPmwSnc.u4VdpOutputDomainFrameNr < MAX_GD_DEBUG_INFO_FRAME_CNT) )
		{
			HAL_GetTime(&(ptr_gd_debug_info[doviGdInfoAfterVideoPmwSnc.u4VdpOutputDomainFrameNr].tSonyGetDvInfoStap));
			ptr_gd_debug_info[doviGdInfoAfterVideoPmwSnc.u4VdpOutputDomainFrameNr].u4SonyGetDvEn = pGlobalDimmingInfo->dv_en;
			ptr_gd_debug_info[doviGdInfoAfterVideoPmwSnc.u4VdpOutputDomainFrameNr].u4SonyGetDvGdEn = pGlobalDimmingInfo->dv_gd_en;
			ptr_gd_debug_info[doviGdInfoAfterVideoPmwSnc.u4VdpOutputDomainFrameNr].u4SonyGetDvGdDuty = pGlobalDimmingInfo->gd_bl_duty;
			//can ext more info such as cur duty source frame number  /cur duty match source video crc and so on
		}
	#else
	pGlobalDimmingInfo->dv_en = 0;
	pGlobalDimmingInfo->dv_gd_en = 0;
	#endif
	if(IO32ReadFldAlign(DOLBY_DEBUG, DOLBY_DEBUG_GD_LOG))
	{
		LOG(0,"[DVGD] dv_en = %d, dv_gd_en = %d, gd_bl_duty = %d \n",pGlobalDimmingInfo->dv_en,pGlobalDimmingInfo->dv_gd_en,pGlobalDimmingInfo->gd_bl_duty);
	}
	return ;
}




