//<MStar Software>
//******************************************************************************
// MStar Software
// Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
// All software, firmware and related documentation herein ("MStar Software") are
// intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
// law, including, but not limited to, copyright law and international treaties.
// Any use, modification, reproduction, retransmission, or republication of all
// or part of MStar Software is expressly prohibited, unless prior written
// permission has been granted by MStar.
//
// By accessing, browsing and/or using MStar Software, you acknowledge that you
// have read, understood, and agree, to be bound by below terms ("Terms") and to
// comply with all applicable laws and regulations:
//
// 1. MStar shall retain any and all right, ownership and interest to MStar
//    Software and any modification/derivatives thereof.
//    No right, ownership, or interest to MStar Software and any
//    modification/derivatives thereof is transferred to you under Terms.
//
// 2. You understand that MStar Software might include, incorporate or be
//    supplied together with third party`s software and the use of MStar
//    Software may require additional licenses from third parties.
//    Therefore, you hereby agree it is your sole responsibility to separately
//    obtain any and all third party right and license necessary for your use of
//    such third party`s software.
//
// 3. MStar Software and any modification/derivatives thereof shall be deemed as
//    MStar`s confidential information and you agree to keep MStar`s
//    confidential information in strictest confidence and not disclose to any
//    third party.
//
// 4. MStar Software is provided on an "AS IS" basis without warranties of any
//    kind. Any warranties are hereby expressly disclaimed by MStar, including
//    without limitation, any warranties of merchantability, non-infringement of
//    intellectual property rights, fitness for a particular purpose, error free
//    and in conformity with any international standard.  You agree to waive any
//    claim against MStar for any loss, damage, cost or expense that you may
//    incur related to your use of MStar Software.
//    In no event shall MStar be liable for any direct, indirect, incidental or
//    consequential damages, including without limitation, lost of profit or
//    revenues, lost or damage of data, and unauthorized system use.
//    You agree that this Section 4 shall still apply without being affected
//    even if MStar Software has been modified by MStar in accordance with your
//    request or instruction for your use, except otherwise agreed by both
//    parties in writing.
//
// 5. If requested, MStar may from time to time provide technical supports or
//    services in relation with MStar Software to you for your use of
//    MStar Software in conjunction with your or your customer`s product
//    ("Services").
//    You understand and agree that, except otherwise agreed by both parties in
//    writing, Services are provided on an "AS IS" basis and the warranty
//    disclaimer set forth in Section 4 above shall apply.
//
// 6. Nothing contained herein shall be construed as by implication, estoppels
//    or otherwise:
//    (a) conferring any license or right to use MStar name, trademark, service
//        mark, symbol or any other identification;
//    (b) obligating MStar or any of its affiliates to furnish any person,
//        including without limitation, you and your customers, any assistance
//        of any kind whatsoever, or any information; or
//    (c) conferring any license or right under any intellectual property right.
//
// 7. These terms shall be governed by and construed in accordance with the laws
//    of Taiwan, R.O.C., excluding its conflict of law rules.
//    Any and all dispute arising out hereof or related hereto shall be finally
//    settled by arbitration referred to the Chinese Arbitration Association,
//    Taipei in accordance with the ROC Arbitration Law and the Arbitration
//    Rules of the Association by three (3) arbitrators appointed in accordance
//    with the said Rules.
//    The place of arbitration shall be in Taipei, Taiwan and the language shall
//    be English.
//    The arbitration award shall be final and binding to both parties.
//
//******************************************************************************
//<MStar Software>
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008-2009 MStar Semiconductor, Inc.
// All rights reserved.
//
// Unless otherwise stipulated in writing, any and all information contained
// herein regardless in any format shall remain the sole proprietary of
// MStar Semiconductor Inc. and be kept in strict confidence
// ("MStar Confidential Information") by the recipient.
// Any unauthorized act including without limitation unauthorized disclosure,
// copying, use, reproduction, sale, distribution, modification, disassembling,
// reverse engineering and compiling of the contents of MStar Confidential
// Information is unlawful and strictly prohibited. MStar hereby reserves the
// rights to any and all damages, losses, costs and expenses resulting therefrom.
//
////////////////////////////////////////////////////////////////////////////////

#define  _MDRV_PQ_CUS_C_

#ifdef MSOS_TYPE_LINUX
#include <pthread.h>
#endif
#if !defined(MSOS_TYPE_LINUX_KERNEL)
#include "string.h"
#else
#include <linux/string.h>
#endif

#if (defined MSOS_TYPE_LINUX) || (defined ANDROID)
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h> // O_RDWR
#endif

#include "MsCommon.h"
//#include "MsVersion.h"
#include "MsOS.h"
#include "MsTypes.h"
//#include "hwreg_utility2.h"
#include "color_reg.h"
#include "utopia.h"
#include "utopia_dapi.h"

#include "drvXC_IOPort.h"
#include "apiXC.h"
//#include "apiXC_Ace.h"
#include "drvMVOP.h"

#include "drvPQ_Define.h"
#include "drvPQ_Define_cus.h"

#include "drvPQ_Declare.h"
#include "drvPQ.h"
#include "drvPQ_cus.h"
#include "drvPQ_Datatypes.h"
#include "PQ_context.h"
#include "mhal_pq.h"
#include "mhal_pq_cus.h"
#include "mhal_pq_adaptive.h"
#include "drvPQ_Bin.h"
#include "apiPNL.h"
#include "drvPQ_VR.h"
#include "mdrv_xc_io.h"
#include "mdrv_xc_st.h"

#include "QualityMode.h"
#include "apiPQ_v2.h"
#include "PQ_private.h"
#include "utopia_dapi.h"
#if PQ_ENABLE_DEBUG
extern MS_U16 _u16PQDbgSwitch;
#endif

#ifndef UNUSED //to avoid compile warnings...
#define UNUSED(var) (void)(var)
#endif

#ifdef MSOS_TYPE_LINUX_KERNEL
#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
#endif

#ifndef PQ_GRULE_SLZ_ENABLE
#define PQ_GRULE_SLZ_ENABLE 0
#endif

#ifndef PQ_QM_HDMI_4K2K
#define PQ_QM_HDMI_4K2K 0
#endif

#ifndef PQ_QM_DTV_4K2K
#define PQ_QM_DTV_4K2K 0
#endif

#ifndef PQ_OSD_BW_VER
#define PQ_OSD_BW_VER 1
#endif

#ifndef ENABLE_PQ_UFSC_DLC
#define ENABLE_PQ_UFSC_DLC   0
#endif

#ifndef ENABLE_PQ_UFSC_BYPASS
#define ENABLE_PQ_UFSC_BYPASS 0
#endif

#ifndef PQ_DS_ENABLE
#define PQ_DS_ENABLE 0
#endif

#ifndef PQ_SUPPORT_DTV_720I
#define PQ_SUPPORT_DTV_720I 0
#endif
/********************************************************************************
// PQ_IOCTL_SET_UC_FEATURE is flag for set UCNR  During SetWin(if enable this switch please sync CL641359)
// and please check  PQ excel skipRule(UC_CTL/UCDi/MADi_EODiW/MADi_SSTMADi_Motion need skip)item to prevent to set UCNR twice
**********************************************************************************/
#ifndef PQ_IOCTL_SET_UC_FEATURE
#define PQ_IOCTL_SET_UC_FEATURE   0
#endif

#ifndef PQ_VIP_OFF_MINUS16
#define PQ_VIP_OFF_MINUS16 0
#endif

#ifndef PQ_SUPPORT_DVI_IMODE
#define PQ_SUPPORT_DVI_IMODE 0
#endif

#ifndef PQ_QM_PREVIEW
#define PQ_QM_PREVIEW 0
#endif

#ifndef PQ_GROUPNUM_BIN_VERSION
#define PQ_GROUPNUM_BIN_VERSION (0)
#endif

#define PQMODE_DBG(x)   //x
#define PQ_IS_4K2K_INPUT(HSize,Vsize)  (((HSize) > 3800) && ((Vsize) >= 1900))
#define GateFor30P      (450)
#define GateFor120P     (650)

#define PQ_CFD_ANALOG_VERSION 0
#define PQ_CFD_LINEAR_RGB_VERSION 0
#define PQ_CFD_FIRE_VERSION 0
#define PQ_GAMEMODE_GRULE_LVL0 (0)
#define PQ_GAMEMODE_GRULE_LVL1 (1)
#define PQ_GAMEMODE_GRULE_INDEX_ON (0)
#define PQ_GAMEMODE_GRULE_INDEX_OFF (1)
#define PQ_GAMEMODE_GRULE_INDEX_LVL0 (3)
#define PQ_GAMEMODE_GRULE_INDEX_LVL1 (4)

//for YMY autodownload test
#define OPEN_PQ_YMY_TEST_CASE (FALSE)
static MS_BOOL _MDrv_PQ_openYMYTestCase(void);

//#define TRACE_DBG
extern MS_U16 _u16PQSrcType[PQ_MAX_WINDOW];
extern MS_U16 _u16PQDbgSwitch;

extern MS_BOOL gbPQBinEnable;
extern MS_PQBin_Header_Info stPQBinHeaderInfo[MAX_PQ_BIN_NUM];
extern MS_PQTextBin_Header_Info stPQTextBinHeaderInfo[MAX_PQ_TEXT_BIN_NUM];
extern MS_BOOL gbEnablePQTextBin;
extern MS_PQ_Vd_Info _stVD_Info[PQ_MAX_WINDOW];
extern MS_PQ_MuliMedia_Info _stMultiMedia_Info[PQ_MAX_WINDOW];
extern MS_PQ_Mode_Info  _stMode_Info[PQ_MAX_WINDOW];
extern MS_U8 _u8ModeIndex[PQ_MAX_WINDOW];
extern MS_PQ_Hdmi_Info _stHDMI_Info[PQ_MAX_WINDOW];
extern MS_PQ_Dtv_Info _stDTV_Info[PQ_MAX_WINDOW];
extern MS_BOOL _bOSD_On;
extern MS_BOOL _gbMemfmt422[PQ_MAX_WINDOW];
extern MS_BOOL _gbMemfmt422[PQ_MAX_WINDOW];
extern MS_BOOL _bDS_En;
extern MS_U16 _u16RW_Method;
extern MS_BOOL _bRWNumIsReset[PQ_MAX_WINDOW];
extern MS_BOOL bSetFrameCount;
extern MS_U16 _gu16SetMemfmt_Madi[PQ_MAX_WINDOW];
extern MS_U16 _gu16SetMemfmt_Madi_Motion[PQ_MAX_WINDOW];

MS_BOOL _gIsH264 = 0;
MS_BOOL _gIsMVC4kx1k = 0;
MS_BOOL _gbIsG3D = 0; //priority for G3D
MS_BOOL _gIsMMplayer=0;
MS_BOOL _gIsRmvb[PQ_MAX_WINDOW] = {0,0};
MS_BOOL _gIsNetworkMM = 0;
MS_BOOL _gbSubWin_En = FALSE; //indicate subwindow enable or not, for bw setting
MS_BOOL _gIsDualDecode = 0;
MS_BOOL _gIs1KTraveling = 0;
MS_BOOL _gIsThroughMode = FALSE;
static MS_U16 gu16DisplayWidth = 0;
MS_BOOL _gManualDsEnable = FALSE;
static PQ_DYNAMIC_CONTRAST_FUNCTION_TYPE _enDLCModeOn[PQ_MAX_WINDOW];

MS_U32 u32IPModeAddress[PQ_MAX_WINDOW][E_PQ_XC_IP_MAX] = {{0x280, 0x280,
                                                 0x2A0, 0x2A0, 0x2A0, 0x2A0, 0x2A0, 0x2A0, 0x2A0, 0x2A0, 0x2A1, 0x2A1, 0x2A1,
                                                 0x2E6, 0x2E6, 0x2E6, 0x2E6, 0x2E6, 0x2E6, 0x2E6, 0x2E6, 0x2E7, 0xB86
                                                 }, {0, 0, 0, 0}};
MS_U8 u8IPModeAddressMask[PQ_MAX_WINDOW][E_PQ_XC_IP_MAX] = {{1, 2,
                                                   1, 2, 4, 8, 16, 32, 64, 128, 1, 2, 4,
                                                   1, 2, 4, 8, 16, 32, 64, 128, 1, 1},
                                                   {0, 0,
                                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
MS_U32 u32IPParameterSize[PQ_MAX_WINDOW][E_PQ_XC_IP_MAX] = {{0x286, 0x28C,
                                                      0x2A8, 0x2AE, 0x2B4, 0x2BA, 0x2C0, 0x2C6, 0x2CC, 0x2D2, 0x2DE, 0x2E4, 0x2D8,
                                                      0x2EC, 0x2F2, 0x2F8, 0x2FE, 0xB04, 0xB0A, 0xB10, 0xB16, 0xB1C, 0xB84},
                                                   {0, 0,
                                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
MS_U32 u32IPParameterAddress[PQ_MAX_WINDOW][E_PQ_XC_IP_MAX] = {{0x282, 0x288,
                                                   0x2A4, 0x2AA, 0x2B0, 0x2B6, 0x2BC, 0x2C2, 0x2C8, 0x2CE, 0x2DA, 0x2E0, 0x2D4,
                                                   0x2E8, 0x2EE, 0x2F4, 0x2FA, 0xB00, 0xB06, 0xB0C, 0xB12, 0xB18, 0xB80},
                                                   {0, 0,
                                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};


ST_PQ_GRULE_INFO g_stPQ_GruleINFO[E_PQ_GRULE_NUM] =
{
    {E_PQ_GRULE_EDGE_ENHANCER_OFF   ,E_PQ_GRULE_IP_EDGE_ENHANCER    ,PQ_GRule_EDGE_ENHANCER_Off_Main     ,PQ_MAIN_WINDOW ,PQ_XC0_STD    ,FALSE  ,NULL},
    {E_PQ_GRULE_EDGE_ENHANCER_LOW   ,E_PQ_GRULE_IP_EDGE_ENHANCER    ,PQ_GRule_EDGE_ENHANCER_Low_Main     ,PQ_MAIN_WINDOW ,PQ_XC0_STD    ,FALSE  ,NULL},
    {E_PQ_GRULE_EDGE_ENHANCER_MID   ,E_PQ_GRULE_IP_EDGE_ENHANCER    ,PQ_GRule_EDGE_ENHANCER_Middle_Main  ,PQ_MAIN_WINDOW ,PQ_XC0_STD    ,FALSE  ,NULL},
    {E_PQ_GRULE_EDGE_ENHANCER_HIGH  ,E_PQ_GRULE_IP_EDGE_ENHANCER    ,PQ_GRule_EDGE_ENHANCER_High_Main    ,PQ_MAIN_WINDOW ,PQ_XC0_STD    ,FALSE  ,NULL},
    {E_PQ_GRULE_ABF_OFF             ,E_PQ_GRULE_IP_ABF              ,PQ_GRule_ABFGRule_Off_Main          ,PQ_MAIN_WINDOW ,PQ_XC0_STD    ,FALSE  ,NULL},
    {E_PQ_GRULE_ABF_LOW             ,E_PQ_GRULE_IP_ABF              ,PQ_GRule_ABFGRule_Low_Main          ,PQ_MAIN_WINDOW ,PQ_XC0_STD    ,FALSE  ,NULL},
    {E_PQ_GRULE_ABF_MID             ,E_PQ_GRULE_IP_ABF              ,PQ_GRule_ABFGRule_Middle_Main       ,PQ_MAIN_WINDOW ,PQ_XC0_STD    ,FALSE  ,NULL},
    {E_PQ_GRULE_ABF_HIGH            ,E_PQ_GRULE_IP_ABF              ,PQ_GRule_ABFGRule_High_Main         ,PQ_MAIN_WINDOW ,PQ_XC0_STD    ,FALSE  ,NULL},
    {E_PQ_GRULE_BWLE_OFF            ,E_PQ_GRULE_IP_BWLE             ,PQ_GRule_BWLE_Off_Main              ,PQ_MAIN_WINDOW ,PQ_XC0_STD    ,FALSE  ,NULL},
    {E_PQ_GRULE_BWLE_LOW            ,E_PQ_GRULE_IP_BWLE             ,PQ_GRule_BWLE_Low_Main              ,PQ_MAIN_WINDOW ,PQ_XC0_STD    ,FALSE  ,NULL},
    {E_PQ_GRULE_BWLE_MID            ,E_PQ_GRULE_IP_BWLE             ,PQ_GRule_BWLE_Middle_Main           ,PQ_MAIN_WINDOW ,PQ_XC0_STD    ,FALSE  ,NULL},
    {E_PQ_GRULE_BWLE_HIGH           ,E_PQ_GRULE_IP_BWLE             ,PQ_GRule_BWLE_High_Main             ,PQ_MAIN_WINDOW ,PQ_XC0_STD    ,FALSE  ,NULL},
};


#if (PQ_ENABLE_PIP)
static PQ_DISPLAY_TYPE genDisplayType = PQ_DISPLAY_ONE;
#endif

#if PQ_GRULE_DDR_SELECT_ENABLE
extern BW_INFO_t bw_info;
#endif
#if PQ_DLC_CTL_FOR_MVC4KX1K
extern MS_BOOL _gIsMVC4kx1k;
#endif
#if (PQ_QM_BYPASS_COLOR)
extern MS_BOOL _bBypassModeOn[PQ_MAX_WINDOW];
#endif

#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
extern MS_BOOL _bCustomerMainPQEn;
#endif
#if ENABLE_PQ_CUSTOMER_BIN_SUB_GRULE
extern MS_BOOL _bCustomerSubPQEn;
#endif

extern MS_BOOL _enPQDisplayType;

#ifdef UFO_XC_HDR
#if (UFO_XC_HDR_VERSION == 2)
#ifdef MSOS_TYPE_LINUX
static MS_S32   _s32FdScaler = -1;
#endif
#endif
#endif
#define TOTALBIN (11)
PQ_MITEST_PRIVATE MITestBinInfo[TOTALBIN] = {0};

#ifdef MSOS_TYPE_LINUX_KERNEL
PQ_MPEG_NR_FUNCTION_TYPE _eMPEGNRType[PQ_MAX_WINDOW] = {PQ_MPEG_NR_NUM,PQ_MPEG_NR_NUM};
PQ_3D_NR_FUNCTION_TYPE _e3DNRType[PQ_MAX_WINDOW] = {PQ_3D_NR_NUM,PQ_3D_NR_NUM};
PQ_PTP_FUNCTION_TYPE _ePTPType[PQ_MAX_WINDOW] = {PQ_PTP_NUM,PQ_PTP_NUM};
PQ_HDR_MODE _eHdrMode[PQ_MAX_WINDOW] = {PQ_HDR_NUM,PQ_HDR_NUM};
PQ_FEATURE_SWITCH_TYPE _eCtrType[PQ_MAX_WINDOW] = {PQ_FEATURE_SWITCH_NUM,PQ_FEATURE_SWITCH_NUM};
PQ_XVYCC_TYPE _eXvyccType[PQ_MAX_WINDOW]= {PQ_XVYCC_NUM,PQ_XVYCC_NUM};
PQ_DYNAMIC_CONTRAST_FUNCTION_TYPE _eDynamicContrastType[PQ_MAX_WINDOW] = {PQ_DynContr_NUM,PQ_DynContr_NUM};
PQ_FILM_MODE_FUNCTION_TYPE _eFilmModeType[PQ_MAX_WINDOW] = {PQ_FilmMode_NUM,PQ_FilmMode_NUM};
#endif

#if (defined(MSOS_TYPE_LINUX_KERNEL) && defined(CONFIG_MSTAR_XC_HDR_SUPPORT))
extern MS_BOOL MDrv_XC_CFDControl(ST_KDRV_XC_CFD_CONTROL_INFO *pstKdrvCFDCtrlInfo);
#endif
MS_BOOL MDrv_PQ_SendCfd(EN_PQ_CFD_CTRL_TYPE enCtrlType, void *pstCfdInfo, MS_U32 u32Size)
{
#ifdef UFO_XC_HDR
#if (UFO_XC_HDR_VERSION == 2)

    ST_PQ_CFD_CONTROL_INFO stCfdCtrlInfo;
    memset(&stCfdCtrlInfo, 0, sizeof(ST_PQ_CFD_CONTROL_INFO));
    stCfdCtrlInfo.enCtrlType = enCtrlType;
    stCfdCtrlInfo.pParam = pstCfdInfo;
    stCfdCtrlInfo.u32ParamLen = u32Size;
#if (defined MSOS_TYPE_LINUX) || (defined ANDROID)

    if(0 > _s32FdScaler)
    {
        _s32FdScaler = open("/dev/scaler", O_RDWR);

        if(0 > _s32FdScaler)
        {
            return FALSE;
        }
    }

    if (ioctl(_s32FdScaler, MDRV_XC_IOC_CFDCONCTRL, &stCfdCtrlInfo))
    {
        return FALSE;
    }

    return TRUE;
#elif (defined(MSOS_TYPE_LINUX_KERNEL) && defined(CONFIG_MSTAR_XC_HDR_SUPPORT))
    MDrv_XC_CFDControl((ST_KDRV_XC_CFD_CONTROL_INFO*)&stCfdCtrlInfo);
    return TRUE;
#else
    PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"MDrv_PQ_SendCfd unsupport OS type\n");
#endif
#endif
#endif
    return FALSE;
}

static MS_BOOL _MDrv_PQ_IsFBLMode(void* pInstance, PQ_WIN eWindow)
{
    MS_BOOL bIsFBL = FALSE;
#if (PQ_SUPPORT_MADI_VR == 1)
    MS_PQ_INFO stPQInfo;
    memset(&stPQInfo, 0, sizeof(MS_PQ_INFO));
    stPQInfo.u32Version = ST_PQ_INFO_VERSION;
    stPQInfo.u32Length = sizeof(MS_PQ_INFO);

    if(MDrv_PQ_GetInfo(&stPQInfo) == E_PQ_RET_OK)
    {
        bIsFBL = ((stPQInfo.u8FBLevel == E_XC_FB_LEVEL_FBL) ? TRUE : FALSE);
    }
    else
#endif
    {
        MS_U16 u16TabIdx = (gbPQBinEnable == FALSE) ? PQ_IP_NULL : PQ_BIN_IP_NULL;
        ST_PQ_IPInfo stIPInfo;
        ST_PQ_IPInfo stUpdatedIPInfo;
        memset(&stIPInfo, 0, sizeof(ST_PQ_IPInfo));
        memset(&stUpdatedIPInfo, 0, sizeof(ST_PQ_IPInfo));
#if (PQ_ENABLE_PIP == 1)
        stIPInfo.u16IPIdx = (eWindow == PQ_MAIN_WINDOW) ? PQ_IP_MADi_Main : MHal_PQ_Get_IPIndex(eWindow, E_PQ_IP_MADI);
#else
        stIPInfo.u16IPIdx = PQ_IP_MADi_Main;
#endif
        stIPInfo.enPQEngineType = PQ_XC0_STD;
        MHal_PQ_RemappingIP(pInstance, stIPInfo, &stUpdatedIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
        u16TabIdx = MDrv_PQ_GetTableIndex_Ex(eWindow, stUpdatedIPInfo.u16IPIdx, stUpdatedIPInfo.enPQEngineType);

        if((u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_FBL_DNR))
          || (u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_FBL_MIU)))
        {
            bIsFBL = TRUE;
        }
        else
        {
            bIsFBL = FALSE;
        }
    }

    return bIsFBL;
}

static MS_BOOL _MDrv_PQ_IsRFBLMode(void* pInstance, PQ_WIN eWindow)
{
    MS_BOOL bIsRFBL = FALSE;
#if (PQ_SUPPORT_MADI_VR == 1)
    MS_PQ_INFO stPQInfo;
    memset(&stPQInfo, 0, sizeof(MS_PQ_INFO));
    stPQInfo.u32Version = ST_PQ_INFO_VERSION;
    stPQInfo.u32Length = sizeof(MS_PQ_INFO);

    if(MDrv_PQ_GetInfo(&stPQInfo) == E_PQ_RET_OK)
    {
        bIsRFBL = ((stPQInfo.u8FBLevel == E_XC_FB_LEVEL_RFBL_DI) ? TRUE : FALSE);
    }
    else
#endif
    {
        MS_U16 u16TabIdx = (gbPQBinEnable == FALSE) ? PQ_IP_NULL : PQ_BIN_IP_NULL;
        ST_PQ_IPInfo stIPInfo;
        ST_PQ_IPInfo stUpdatedIPInfo;
        memset(&stIPInfo, 0, sizeof(ST_PQ_IPInfo));
        memset(&stUpdatedIPInfo, 0, sizeof(ST_PQ_IPInfo));
#if (PQ_ENABLE_PIP == 1)
        stIPInfo.u16IPIdx = (eWindow == PQ_MAIN_WINDOW) ? PQ_IP_MADi_Main : MHal_PQ_Get_IPIndex(eWindow, E_PQ_IP_MADI);
#else
        stIPInfo.u16IPIdx = PQ_IP_MADi_Main;
#endif
        stIPInfo.enPQEngineType = PQ_XC0_STD;
        MHal_PQ_RemappingIP(pInstance, stIPInfo, &stUpdatedIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
        u16TabIdx = MDrv_PQ_GetTableIndex_Ex(eWindow, stUpdatedIPInfo.u16IPIdx, stUpdatedIPInfo.enPQEngineType);

        if((u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_RFBL_2D))
          || (u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_RFBL_25D))
          || (u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_RFBL_3D))
          || (u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_RFBL_3D_YC))
          || (u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_RFBL_3D_FILM))
          || (u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_RFBL_MC))
          || (u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_24_RFBL_FILM))
          || (u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_24_RFBL_NFILM))
          || (u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_RFBL_P_MODE10_MOT))
          || (u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_RFBL_P_MODE8_MOT))
          || (u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_RFBL_P_MODE_MC))
          || (u16TabIdx == Hal_PQ_get_madi_idx(pInstance, (eWindow == PQ_MAIN_WINDOW) ? TRUE : FALSE, MS_MADI_RFBL_P_MODE8_MOT_Y8)))
        {
            bIsRFBL = TRUE;
        }
        else
        {
            bIsRFBL = FALSE;
        }
    }

    return bIsRFBL;
}

MS_BOOL MDrv_PQ_IsFBLMadi(void* pInstance, PQ_WIN eWindow)
{
    return (_MDrv_PQ_IsFBLMode(pInstance, eWindow) ||_MDrv_PQ_IsRFBLMode(pInstance, eWindow));
}

static MS_U16 _MDrv_PQ_GetAnalogIndex(PQ_WIN enWindow, PQ_INPUT_SOURCE_TYPE enInputSourceType)
{
    MS_U16 u16SrcType = 0;
#if defined(PQ_CFD_INFO) && defined(PQ_CFD_INFO_VERSION) && (PQ_CFD_INFO_VERSION == 1)
    PQ_VIDEOSTANDARD_TYPE enStandard;
    memset(&enStandard, 0, sizeof(PQ_VIDEOSTANDARD_TYPE));

    if(QM_IsSourceScartRGB(enInputSourceType, enWindow))
    {
        enStandard = QM_GetATVStandard(enWindow);
        switch(enStandard)
        {
            case E_PQ_VIDEOSTANDARD_NTSC_44:            // 480
            case E_PQ_VIDEOSTANDARD_NTSC_M:             // 480
            case E_PQ_VIDEOSTANDARD_PAL_M:              // 480
            case E_PQ_VIDEOSTANDARD_PAL_60:             // 480
                u16SrcType = E_PQ_CFD_ANALOG_RGB_NTSC;  // for 480
                break;
            case E_PQ_VIDEOSTANDARD_PAL_N:              // 576
            case E_PQ_VIDEOSTANDARD_PAL_BGHI:           // 576
            case E_PQ_VIDEOSTANDARD_SECAM:              // 576
            default:
                u16SrcType = E_PQ_CFD_ANALOG_RGB_PAL;   // for 576
                break;
        }
    }
    else
    {
        enStandard = QM_GetATVStandard(enWindow);
        switch(enStandard)
        {
            case E_PQ_VIDEOSTANDARD_PAL_M:
                u16SrcType = E_PQ_CFD_ANALOG_YUV_PAL;
                break;
            case E_PQ_VIDEOSTANDARD_PAL_N:
                u16SrcType = E_PQ_CFD_ANALOG_YUV_PAL;
                break;
            case E_PQ_VIDEOSTANDARD_NTSC_44:
                u16SrcType = E_PQ_CFD_ANALOG_YUV_NTSC;
                break;
            case E_PQ_VIDEOSTANDARD_PAL_60:
                u16SrcType = E_PQ_CFD_ANALOG_YUV_PAL;
                break;
            case E_PQ_VIDEOSTANDARD_NTSC_M:
                u16SrcType = E_PQ_CFD_ANALOG_YUV_NTSC;
                break;
            case E_PQ_VIDEOSTANDARD_SECAM:
                u16SrcType = E_PQ_CFD_ANALOG_YUV_SECAM;
                break;
            case E_PQ_VIDEOSTANDARD_PAL_BGHI:
            default:
                u16SrcType = E_PQ_CFD_ANALOG_YUV_PAL;
                break;
        }
    }
#else
    UNUSED(enWindow);
    UNUSED(enInputSourceType);
#endif
    return u16SrcType;
}

static void _MDrv_PQ_CFD_SetColorInfo(PQ_WIN enWindow, PQ_INPUT_SOURCE_TYPE enInputSourceType)
{
#if defined(PQ_CFD_INFO) && defined(PQ_CFD_INFO_VERSION) && (PQ_CFD_INFO_VERSION == 1)
    XC_CFD_CONTROL_INFO stCfdCtrl;
    ST_PQ_CFD_ANALOG stCfdAnalog;
    MS_U16 u16SrcType = 0;

    memset(&stCfdAnalog, 0, sizeof(ST_PQ_CFD_ANALOG));
    memset(&stCfdCtrl, 0, sizeof(XC_CFD_CONTROL_INFO));

    MS_U16 u16Input_HSize = QM_GetInputHSize(enWindow);
    MS_U16 u16Input_VSize = QM_GetInputVSize(enWindow);
    MS_BOOL bIsInterlaced = QM_IsInterlaced(enWindow);

    stCfdCtrl.enCtrlType = E_XC_CFD_CTRL_TYPE_MAX;

    if (QM_IsSourceVGA(enInputSourceType))
    {
        stCfdCtrl.enCtrlType = E_XC_CFD_CTRL_TYPE_VGA;
        u16SrcType=E_PQ_CFD_VGA;
    }
    else if (QM_IsSourceDVI_HDMIPC(enInputSourceType, enWindow))
    {
        stCfdCtrl.enCtrlType = E_XC_CFD_CTRL_TYPE_DVI;
        u16SrcType=E_PQ_CFD_DVI;
    }
    else if (QM_IsSourceYPbPr(enInputSourceType))
    {
        stCfdCtrl.enCtrlType = E_XC_CFD_CTRL_TYPE_YPBPR;
        if( QM_IsSourceYPbPr(enInputSourceType) &&
        (MDrv_PQ_Get_PointToPoint(enWindow)) && (!bIsInterlaced))
        {
            // YUV444 progressive
            u16SrcType = E_PQ_CFD_HDMI;
        }
        else if(QM_IsYPbPr_1920x1080_50I(enWindow) || QM_IsYPbPr_1920x1080_60I(enWindow)
        || QM_IsYPbPr_1920x1080_24P(enWindow) || QM_IsYPbPr_1920x1080_30P(enWindow)
        || QM_IsYPbPr_1920x1080_25P(enWindow) || QM_IsYPbPr_1920x1080_50P(enWindow)
        || QM_IsYPbPr_1920x1080_60P(enWindow))
        {
            u16SrcType = E_PQ_CFD_YPBPR_FHD;
        }
        else
        {
            u16SrcType = E_PQ_CFD_YPBPR_SD;
        }
    }
    else if (QM_IsSourceDTV(enInputSourceType))
    {
        stCfdCtrl.enCtrlType = E_XC_CFD_CTRL_TYPE_DTV;
        u16SrcType = E_PQ_CFD_DTV;
    }
    else if (QM_IsSourceMultiMedia(enInputSourceType))
    {
        stCfdCtrl.enCtrlType = E_XC_CFD_CTRL_TYPE_MM;

        if(QM_IsMultiMediaPHOTO(enWindow))
        {
            if ((u16Input_HSize <= 720) && (u16Input_VSize <= 576))
            {
                u16SrcType = E_PQ_CFD_PHOTO;
            }
            else if((u16Input_HSize < 1500) && (u16Input_VSize >= 1900) )
            {
                u16SrcType = E_PQ_CFD_MM;
            }
            else if((u16Input_HSize > 3000) && (u16Input_VSize > 1050))
            {
                u16SrcType = E_PQ_CFD_PHOTO;
            }
            else
            {
                u16SrcType = E_PQ_CFD_PHOTO;
            }
        }
        else
        {
            u16SrcType = E_PQ_CFD_MM;
        }
#if(PQ_QM_MM_PHOTO_RGB)
        MVOP_Handle stMvopHd = { E_MVOP_MODULE_MAIN };
        MVOP_RgbFormat enRGB = E_MVOP_RGB_NONE;
        if(MDrv_MVOP_GetCommand(&stMvopHd, E_MVOP_CMD_GET_RGB_FMT, & enRGB, sizeof(MVOP_RgbFormat)) == E_MVOP_OK)
        {
            if(u16SrcType == E_PQ_CFD_PHOTO && enRGB == E_MVOP_RGB_888)
            {
                u16SrcType = E_PQ_CFD_PHOTO_RGB;
            }
        }
#endif
    }
    else if (QM_IsSourceATV(enInputSourceType))
    {
        stCfdCtrl.enCtrlType = E_XC_CFD_CTRL_TYPE_TV;
        u16SrcType = _MDrv_PQ_GetAnalogIndex(enWindow, enInputSourceType);
    }
    else if (QM_IsSourceAV(enInputSourceType))
    {
        stCfdCtrl.enCtrlType = E_XC_CFD_CTRL_TYPE_CVBS;
        u16SrcType = _MDrv_PQ_GetAnalogIndex(enWindow, enInputSourceType);
    }
    else if (QM_IsSourceSV(enInputSourceType))
    {
        stCfdCtrl.enCtrlType = E_XC_CFD_CTRL_TYPE_SVIDEO;
        u16SrcType = _MDrv_PQ_GetAnalogIndex(enWindow, enInputSourceType);
    }
    else if (QM_IsSourceScart(enInputSourceType))
    {
        stCfdCtrl.enCtrlType = E_XC_CFD_CTRL_TYPE_SCART;
        u16SrcType = _MDrv_PQ_GetAnalogIndex(enWindow, enInputSourceType);
    }

    stCfdAnalog.u32Version = PQ_CFD_ANALOG_VERSION;
    stCfdAnalog.u16Length = sizeof(ST_PQ_CFD_ANALOG);
    stCfdAnalog.u8Win = enWindow;
    if (Hal_PQ_get_cfd_info_simplified_index(u16SrcType, &stCfdAnalog.u8ColorFormat, &stCfdAnalog.u8ColorDataFormat, &stCfdAnalog.bIsFullRange, &stCfdAnalog.u8ColorPrimaries, &stCfdAnalog.u8TransferCharacteristics, &stCfdAnalog.u8MatrixCoefficients) == TRUE)
    {
        if (QM_IsSourceVGA(enInputSourceType))
        {
            MDrv_PQ_SendCfd(E_PQ_CFD_CTRL_SET_VGA, &stCfdAnalog, sizeof(ST_PQ_CFD_ANALOG));
        }
        else if (QM_IsSourceATV(enInputSourceType))
        {
            MDrv_PQ_SendCfd(E_PQ_CFD_CTRL_SET_TV, &stCfdAnalog, sizeof(ST_PQ_CFD_ANALOG));
        }
        else if (QM_IsSourceAV(enInputSourceType))
        {
            MDrv_PQ_SendCfd(E_PQ_CFD_CTRL_SET_CVBS, &stCfdAnalog, sizeof(ST_PQ_CFD_ANALOG));
        }
        else if (QM_IsSourceSV(enInputSourceType))
        {
            MDrv_PQ_SendCfd(E_PQ_CFD_CTRL_SET_SVIDEO, &stCfdAnalog, sizeof(ST_PQ_CFD_ANALOG));
        }
        else if (QM_IsSourceYPbPr(enInputSourceType))
        {
            MDrv_PQ_SendCfd(E_PQ_CFD_CTRL_SET_YPBPR, &stCfdAnalog, sizeof(ST_PQ_CFD_ANALOG));
        }
        else if (QM_IsSourceScart(enInputSourceType))
        {
            MDrv_PQ_SendCfd(E_PQ_CFD_CTRL_SET_SCART, &stCfdAnalog, sizeof(ST_PQ_CFD_ANALOG));
        }
        else if (QM_IsSourceDVI_HDMIPC(enInputSourceType, enWindow))
        {
            MDrv_PQ_SendCfd(E_PQ_CFD_CTRL_SET_DVI, &stCfdAnalog, sizeof(ST_PQ_CFD_ANALOG));
        }
        else if (QM_IsSourceMultiMedia(enInputSourceType))
        {
            MDrv_PQ_SendCfd(E_PQ_CFD_CTRL_SET_MM, &stCfdAnalog, sizeof(ST_PQ_CFD_ANALOG));
        }
        else if (QM_IsSourceDTV(enInputSourceType))
        {
            MDrv_PQ_SendCfd(E_PQ_CFD_CTRL_SET_DTV, &stCfdAnalog, sizeof(ST_PQ_CFD_ANALOG));
        }
    }
#else
    UNUSED(enWindow);
    UNUSED(enInputSourceType);
#endif
}

static MS_BOOL _MDrv_PQ_IsSupportPQDSPlus(void)
{
    MS_BOOL bIsSupport = FALSE;
    MApi_XC_GetChipCaps(E_XC_SUPPORT_PQ_DS_PLUS,(MS_U32*)&bIsSupport, sizeof(MS_BOOL));
    return bIsSupport;
}

static MS_U16 _MDrv_PQ_InputSoureVGB_HDMIPC(PQ_WIN eWindow,PQ_INPUT_SOURCE_TYPE enInputSourceType)
{
    MS_U16 u16SrcType = 0;
    MS_U16 u16Input_HSize = QM_GetInputHSize(eWindow);
    MS_U16 u16Input_VSize = QM_GetInputVSize(eWindow);
    MS_U16 u16Disp_HSize = QM_GetDispHSize(eWindow);
    MS_U16 u16Disp_VSize = QM_GetDispVSize(eWindow);

    //DVI YUV mode is some special pattern gen timing in Korea company
    if(QM_IsSourceHDMI(enInputSourceType) && QM_HDMIPC_COLORYUV444(eWindow))
    {
#if (PQ_QM_HDMI_PC)
        // PC YUV444
        if (u16Input_HSize < u16Disp_HSize)
        {
            if (u16Input_VSize < u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_HDMI_444_PC_Hup_Vup_Main;
            }
            else if (u16Input_VSize > u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_HDMI_444_PC_Hup_Vdown_Main;
            }
            else
            {
                u16SrcType = (MS_U16)QM_HDMI_444_PC_Hup_Vno_Main;
            }
        }
        else if (u16Input_HSize > u16Disp_HSize)
        {
            if (u16Input_VSize < u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_HDMI_444_PC_Hdown_Vup_Main;
            }
            else if (u16Input_VSize > u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_HDMI_444_PC_Hdown_Vdown_Main;
            }
            else
            {
                u16SrcType = (MS_U16)QM_HDMI_444_PC_Hdown_Vno_Main;
            }
        }
        else
        {
            if (u16Input_VSize < u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_HDMI_444_PC_Hno_Vup_Main;
            }
            else if (u16Input_VSize > u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_HDMI_444_PC_Hno_Vdown_Main;
            }
            else
            {
#if (PQ_QM_HDMI_4K2K)
                if(PQ_IS_4K2K_INPUT(u16Input_HSize,u16Input_VSize))
                {
                    u16SrcType = (MS_U16)QM_HDMI_444_PC_Hno_Vno_4K_Main;
                }
                else
#endif
                {
                    u16SrcType = (MS_U16)QM_HDMI_444_PC_Hno_Vno_Main;
                }
            }
        }
#endif
    }
    else if (QM_IsSourceHDMI(enInputSourceType) && QM_HDMIPC_COLORYUV422(eWindow))
    {
#if (PQ_QM_HDMI_PC)
        // PC YUV422
        if (u16Input_HSize < u16Disp_HSize)
        {
            if (u16Input_VSize < u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_HDMI_422_PC_Hup_Vup_Main;
            }
            else if (u16Input_VSize > u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_HDMI_422_PC_Hup_Vdown_Main;
            }
            else
            {
                u16SrcType = (MS_U16)QM_HDMI_422_PC_Hup_Vno_Main;
            }
        }
        else if (u16Input_HSize > u16Disp_HSize)
        {
            if (u16Input_VSize < u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_HDMI_422_PC_Hdown_Vup_Main;
            }
            else if (u16Input_VSize > u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_HDMI_422_PC_Hdown_Vdown_Main;
            }
            else
            {
                u16SrcType = (MS_U16)QM_HDMI_422_PC_Hdown_Vno_Main;
            }
        }
        else
        {
            if (u16Input_VSize < u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_HDMI_422_PC_Hno_Vup_Main;
            }
            else if (u16Input_VSize > u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_HDMI_422_PC_Hno_Vdown_Main;
            }
            else
            {
                u16SrcType = (MS_U16)QM_HDMI_422_PC_Hno_Vno_Main;
            }
        }
#endif
    }
    else //(QM_HDMIPC_COLORRGB(eWindow)) & default
    {
#if (PQ_QM_PC)
        // PC RGB
        if (u16Input_HSize < u16Disp_HSize)
        {
            if (u16Input_VSize < u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_DVI_Dsub_HDMI_RGB_PC_Hup_Vup_Main;
            }
            else if (u16Input_VSize > u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_DVI_Dsub_HDMI_RGB_PC_Hup_Vdown_Main;
            }
            else
            {
                u16SrcType = (MS_U16)QM_DVI_Dsub_HDMI_RGB_PC_Hup_Vno_Main;
            }
        }
        else if (u16Input_HSize > u16Disp_HSize)
        {
            if (u16Input_VSize < u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_DVI_Dsub_HDMI_RGB_PC_Hdown_Vup_Main;
            }
            else if (u16Input_VSize > u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_DVI_Dsub_HDMI_RGB_PC_Hdown_Vdown_Main;
            }
            else
            {
                u16SrcType = (MS_U16)QM_DVI_Dsub_HDMI_RGB_PC_Hdown_Vno_Main;
            }
        }
        else
        {
            if (u16Input_VSize < u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_DVI_Dsub_HDMI_RGB_PC_Hno_Vup_Main;
            }
            else if (u16Input_VSize > u16Disp_VSize)
            {
                u16SrcType = (MS_U16)QM_DVI_Dsub_HDMI_RGB_PC_Hno_Vdown_Main;
            }
            else
            {
#if (PQ_QM_HDMI_4K2K)
                if(PQ_IS_4K2K_INPUT(u16Input_HSize,u16Input_VSize))
                {
                    u16SrcType = (MS_U16)QM_DVI_Dsub_HDMI_RGB_PC_Hno_Vno_4K_Main;
                }
                else
#endif
                {
                    u16SrcType = (MS_U16)QM_DVI_Dsub_HDMI_RGB_PC_Hno_Vno_Main;
                }
            }
        }
#endif
    }
    return u16SrcType;
}
static MS_U16 _MDrv_PQ_InputSoureHDMI(PQ_WIN eWindow,PQ_INPUT_SOURCE_TYPE enInputSourceType)
{
    MS_U16 u16SrcType = 0;
#if (PQ_QM_HMDI)
    MS_U16 u16Input_HSize = QM_GetInputHSize(eWindow);
    MS_U16 u16Input_VSize = QM_GetInputVSize(eWindow);
    MS_U16 u16Input_VFreq = QM_GetInputVFreq(eWindow);
    MS_BOOL bIsInterlaced = QM_IsInterlaced(eWindow);
    if( QM_IsSourceHDMI(enInputSourceType) && QM_HDMIPC_COLORRGB(eWindow) &&
        (MDrv_PQ_Get_PointToPoint(eWindow)) && (!bIsInterlaced) &&
        (!PQ_IS_4K2K_INPUT(u16Input_HSize,u16Input_VSize)))
    {
        // HDMI RGB progressive
        u16SrcType = QM_DVI_Dsub_HDMI_RGB_PC_Hno_Vno_Main;
    }
    else if( QM_IsSourceHDMI(enInputSourceType) && QM_HDMIPC_COLORYUV444(eWindow) &&
                (MDrv_PQ_Get_PointToPoint(eWindow)) && (!bIsInterlaced) &&
                 (!PQ_IS_4K2K_INPUT(u16Input_HSize,u16Input_VSize)))
    {
       //  HDMI YUV444 progressive
        u16SrcType = QM_HDMI_444_PC_Hno_Vno_Main;
    }
#if (PQ_SUPPORT_HDMI_4K2K_P2P == 1)
    else if( QM_IsSourceHDMI(enInputSourceType) && QM_HDMIPC_COLORRGB(eWindow) &&
             (MDrv_PQ_Get_PointToPoint(eWindow)) && (!bIsInterlaced) &&
             PQ_IS_4K2K_INPUT(u16Input_HSize,u16Input_VSize))
    {
        // HDMI 4K2K RGB progressive
        u16SrcType = QM_DVI_Dsub_HDMI_RGB_PC_Hno_Vno_4K_Main;
    }
    else if( QM_IsSourceHDMI(enInputSourceType) && QM_HDMIPC_COLORYUV444(eWindow) &&
             (MDrv_PQ_Get_PointToPoint(eWindow)) && (!bIsInterlaced) &&
             PQ_IS_4K2K_INPUT(u16Input_HSize,u16Input_VSize))
    {
       //  HDMI YUV444 progressive
        u16SrcType = QM_HDMI_444_PC_Hno_Vno_4K_Main;
    }
#endif
    else
    {
        // HDMI
        if ((u16Input_HSize < 800) && (u16Input_VSize < 500))
        {
            if (bIsInterlaced)
            {
#if (PQ_SUPPORT_DVI_IMODE == 1)
                if (QM_HDMIPC_COLORRGB(eWindow) && QM_IsSourceDVI_HDMIPC(enInputSourceType, eWindow))
                {
                    u16SrcType = QM_DVI_480i_Main;
                }
                else
#endif
                {
                    u16SrcType = QM_HDMI_480i_Main;
                }
            }
            else
                u16SrcType = QM_HDMI_480p_Main;
        }
        else if ((u16Input_HSize < 800) && (u16Input_VSize < 600))
        {
            if (bIsInterlaced)
            {
#if (PQ_SUPPORT_DVI_IMODE == 1)
                if(QM_HDMIPC_COLORRGB(eWindow) && QM_IsSourceDVI_HDMIPC(enInputSourceType, eWindow))
                {
                    u16SrcType = QM_DVI_576i_Main;
                }
                else
#endif
                {
                    u16SrcType = QM_HDMI_576i_Main;
                }
            }
            else
                u16SrcType = QM_HDMI_576p_Main;
        }
        else if ((u16Input_HSize < 1300) && (u16Input_VSize < 800) && (!bIsInterlaced))
        {
            if (u16Input_VFreq > 550)
            {
                u16SrcType = QM_HDMI_720p_60hz_Main;
            }
            else if(u16Input_VFreq > 250)
            {
                u16SrcType = QM_HDMI_720p_50hz_Main;
            }
            else
            {
                u16SrcType = QM_HDMI_720p_24hz_Main;
            }
        }
#if (PQ_QM_HDMI_4K2K)
        else if(PQ_IS_4K_INPUT(u16Input_HSize,u16Input_VSize))
        {
#if (PQ_QM_4K2K_60Hz)
            if (u16Input_VFreq > 450)
            {
                u16SrcType = QM_4K2K_60Hz_Main;
            }
            else if (u16Input_VFreq > 280)
            {
                u16SrcType = QM_4K2K_30Hz_Main;
            }
#else
            if (u16Input_VFreq > 280)
            {
                u16SrcType = QM_4K2K_30Hz_Main;
            }
#endif
            else
            {
                u16SrcType = QM_4K2K_24Hz_Main;
            }
        }
#endif
        else
        {
            if (bIsInterlaced)
            {
#if PQ_QM_HDMI_FP_VIDEO
                if(u16Input_VSize > 2000) //1920x2228 i.it will not go this path now, but may used in future.
                {
                    u16SrcType = QM_HDMI_FP_1080i_Main;
                }
                else
#endif
#if (PQ_SUPPORT_DVI_IMODE == 1)
                if(QM_HDMIPC_COLORRGB(eWindow) && QM_IsSourceDVI_HDMIPC(enInputSourceType, eWindow))
                {
                    if (u16Input_VFreq > 550)
                    {
                        u16SrcType = QM_DVI_1080i_60hz_Main;
                    }
                    else
                    {
                        u16SrcType = QM_DVI_1080i_50hz_Main;
                    }
                }
                else
#endif
                {
                    if (u16Input_VFreq > 550)
                    {
                        u16SrcType = QM_HDMI_1080i_60hz_Main;
                    }
                    else
                    {
                        u16SrcType = QM_HDMI_1080i_50hz_Main;
                    }
                }
            }
            else
            {
#if PQ_QM_HDMI_FP_VIDEO
                if((u16Input_HSize > 1910)
                   && (u16Input_HSize < 1930)
                   && (u16Input_VSize > 2218)
                    && (u16Input_VSize < 2238)) //1920x2228 i frame packing
                {
                    u16SrcType = QM_HDMI_FP_1080i_Main;
                }
                else if(((u16Input_HSize > 1430) && (u16Input_HSize < 1450))
                    && (((u16Input_VSize > 591) && (u16Input_VSize < 611)) || ((u16Input_VSize > 493) && (u16Input_VSize < 513))))
                {
                    u16SrcType = QM_HDMI_FP_1080i_Main;
                }
                else if((u16Input_HSize > 1910)
                        && (u16Input_HSize < 1930)
                        && (u16Input_VSize > 2195)
                        && (u16Input_VSize < 2215)) //1920x2205 p frame packing
                {
                    u16SrcType = QM_HDMI_FP_1080p_Main;
                }
                else if((u16Input_HSize > 1270)
                        && (u16Input_HSize < 1290)
                        && (u16Input_VSize > 1460)
                        && (u16Input_VSize < 1480)) //1280x1470 p frame packing
                {
                    u16SrcType = QM_HDMI_FP_720p_Main;
                }
                else
#endif
                // 1500 is for framepacking case vsize 2205
                if ((u16Input_VFreq > 550) || (u16Input_VSize > 1500))
                {
                    u16SrcType = QM_HDMI_1080p_60hz_Main;
                }
                else if(u16Input_VFreq > GateFor30P)
                {
                    u16SrcType = QM_HDMI_1080p_50hz_Main;
                }
                else  // Other timing
                {
                    u16SrcType = QM_HDMI_1080p_24hz_Main;
                }
            }
        }
    }
#else
    UNUSED(enWindow);
    UNUSED(enInputSourceType);
#endif
    return u16SrcType;
}
static MS_U16 _MDrv_PQ_InputSoureYPBPR(PQ_WIN eWindow,PQ_INPUT_SOURCE_TYPE enInputSourceType)
{
    MS_U16 u16SrcType = 0;
#if (PQ_QM_YPBPR)
    if (QM_IsYPbPr_720x480_60I(eWindow)){
        u16SrcType = QM_YPbPr_480i_Main;
    }
    else if (QM_IsYPbPr_720x480_60P(eWindow)){
        u16SrcType = QM_YPbPr_480p_Main;
    }
    else if (QM_IsYPbPr_720x576_50I(eWindow)){
        u16SrcType = QM_YPbPr_576i_Main;
    }
    else if (QM_IsYPbPr_720x576_50P(eWindow)){
        u16SrcType = QM_YPbPr_576p_Main;
    }
    else if (QM_IsYPbPr_1280x720_50P(eWindow)){
        u16SrcType = QM_YPbPr_720p_50hz_Main;
    }
    else if (QM_IsYPbPr_1280x720_60P(eWindow)){
        u16SrcType = QM_YPbPr_720p_60hz_Main;
    }
    else if (QM_IsYPbPr_1920x1080_50I(eWindow)){
        u16SrcType = QM_YPbPr_1080i_50hz_Main;
    }
    else if (QM_IsYPbPr_1920x1080_60I(eWindow)){
        u16SrcType = QM_YPbPr_1080i_60hz_Main;
    }
    else if (QM_IsYPbPr_1920x1080_24P(eWindow) || QM_IsYPbPr_1920x1080_30P(eWindow) || QM_IsYPbPr_1920x1080_25P(eWindow) ){
        u16SrcType = QM_YPbPr_1080p_24hz_Main;
    }
    else if (QM_IsYPbPr_1920x1080_50P(eWindow)){
        u16SrcType = QM_YPbPr_1080p_50hz_Main;
    }
    else if (QM_IsYPbPr_1920x1080_60P(eWindow)){
        u16SrcType = QM_YPbPr_1080p_60hz_Main;
    }
    else
    {
        u16SrcType = QM_YPbPr_720p_24hz_Main;
    }
#else
    UNUSED(enInputSourceType);
    UNUSED(eWindow);
#endif
    return u16SrcType;
}
static MS_U16 _MDrv_PQ_InputSoureDTV(PQ_WIN eWindow,PQ_INPUT_SOURCE_TYPE enInputSourceType)
{
    MS_U16 u16SrcType = 0;
    MS_U16 u16Input_HSize = QM_GetInputHSize(eWindow);
    MS_U16 u16Input_VSize = QM_GetInputVSize(eWindow);
    MS_U16 u16Input_VFreq = QM_GetInputVFreq(eWindow);
    MS_BOOL bIsInterlaced = QM_IsInterlaced(eWindow);
    MS_U16 u16Disp_HSize = QM_GetDispHSize(eWindow);
    MS_U16 u16Disp_VSize = QM_GetDispVSize(eWindow);

    ST_XC_GET_FB_LEVEL_EX stXCGetFBLevel;
    memset(&stXCGetFBLevel, 0, sizeof(ST_XC_GET_FB_LEVEL_EX));
    stXCGetFBLevel.u32Version = ST_XC_GET_FBLEVEL_VERSION;
    stXCGetFBLevel.u32Length = sizeof(ST_XC_GET_FB_LEVEL_EX);
    stXCGetFBLevel.stCropWin.height = u16Input_VSize;
    stXCGetFBLevel.stCropWin.width  = u16Input_HSize;
    stXCGetFBLevel.stDispWin.height = u16Disp_VSize;
    stXCGetFBLevel.stDispWin.width  = u16Disp_HSize;
    stXCGetFBLevel.bInterlace = bIsInterlaced;
    stXCGetFBLevel.eFBLevel = E_XC_FB_LEVEL_FBL;
    stXCGetFBLevel.u8InputSourceType = enInputSourceType;
    if(eWindow == PQ_MAIN_WINDOW)
    {
        stXCGetFBLevel.eWindow = MAIN_WINDOW;
    }
    else
    {
        stXCGetFBLevel.eWindow = SUB_WINDOW;
    }
#if (PQ_QM_DTV)
    if(QM_IsDTV_IFRAME(eWindow))
    {
        //If PQ has devide the iframe setting according to P/I mode, then use new PQ srctype
        if (u16Input_VSize < 720)
        {
            if (bIsInterlaced)
                u16SrcType = QM_DTV_iFrame_SD_interlace_Main;
            else
                u16SrcType = QM_DTV_iFrame_SD_progressive_Main;
        }
        else
        {
            if (bIsInterlaced)
                u16SrcType = QM_DTV_iFrame_HD_interlace_Main;
            else
                u16SrcType = QM_DTV_iFrame_HD_progressive_Main;
        }
    }
    else if (QM_IsDTV_MPEG2(eWindow))
    {
        if (u16Input_VSize < 500)
        {
            if ((u16Input_HSize < 400) && bIsInterlaced)
            {
                u16SrcType = QM_DTV_480i_352x480_MPEG2_Main;
            }
            else
            {
                if (bIsInterlaced)
                    u16SrcType = QM_DTV_480i_MPEG2_Main;
                else
                    u16SrcType = QM_DTV_480p_MPEG2_Main;
            }
        }
        else if (u16Input_VSize < 650)
        {
            if (bIsInterlaced)
                u16SrcType = QM_DTV_576i_MPEG2_Main;
            else
                u16SrcType = QM_DTV_576p_MPEG2_Main;
        }
        else if ((u16Input_VSize < 900) && (bIsInterlaced==0))
        {
            if (u16Input_VFreq > 550)
            {
                u16SrcType = QM_DTV_720p_60hz_MPEG2_Main;
            }
            else if(u16Input_VFreq > 250)
            {
                u16SrcType = QM_DTV_720p_50hz_MPEG2_Main;
            }
            else
            {
                u16SrcType = QM_DTV_720p_24hz_MPEG2_Main;
            }
        }
        else
        {
            if (bIsInterlaced)
            {
#if PQ_QM_DTV_4K2K
                if(PQ_IS_4K_INPUT(u16Input_HSize,u16Input_VSize))  // 4K2K case
                {
#if (PQ_QM_4K2K_60Hz)
                    if(u16Input_VFreq > GateFor30P)
                        u16SrcType = QM_DTV_4K2K_60Hz_MPEG2_Main;
                    else
#endif
                        u16SrcType = QM_DTV_4K2K_MPEG2_Main;
                }
                else
#endif
                if (u16Input_VFreq > 550)
                {
                    u16SrcType = QM_DTV_1080i_60hz_MPEG2_Main;
                }
                else
                {
                    u16SrcType = QM_DTV_1080i_50hz_MPEG2_Main;
                }
            }
            else
            {
#if PQ_QM_DTV_4K2K
                if(PQ_IS_4K_INPUT(u16Input_HSize,u16Input_VSize))  // 4K2K case
                {
                    if(MApi_XC_GetDynamicScalingStatus() == TRUE)
                    {
                        u16SrcType = QM_DTV_4K2K_DS_Main;
                    }
                    else
                    {
#if (PQ_QM_4K2K_60Hz)
                    if(u16Input_VFreq > GateFor30P)
                        u16SrcType = QM_DTV_4K2K_60Hz_MPEG2_Main;
                    else
#endif
                        u16SrcType = QM_DTV_4K2K_MPEG2_Main;
                    }
                }
                else
#endif
                if (u16Input_VFreq > 550)
                {
                    u16SrcType = QM_DTV_1080p_60hz_MPEG2_Main;
                }
                else if(u16Input_VFreq > 250)
                {
                    u16SrcType = QM_DTV_1080p_50hz_MPEG2_Main;
                }
                else
                {
                    u16SrcType = QM_DTV_1080p_24hz_MPEG2_Main;
                }

            }
        }
    }
    else // QM_IsDTV_H264(eWindow)
    {
        if ((u16Input_HSize < 1260) && (u16Input_VSize < 650))
        {
            if (u16Input_VSize < 500)
            {
                if ((u16Input_HSize < 400) && bIsInterlaced)
                {
                    u16SrcType = QM_DTV_480i_352x480_H264_Main;
                }
                else
                {
                    if (bIsInterlaced)
                        u16SrcType = QM_DTV_480i_H264_Main;
                    else
                        u16SrcType = QM_DTV_480p_H264_Main;
                }
            }
            else
            {
                if (bIsInterlaced)
                    u16SrcType = QM_DTV_576i_H264_Main;
                else
                    u16SrcType = QM_DTV_576p_H264_Main;
            }
        }
        else
        {
            if ((u16Input_VSize < 900) && (bIsInterlaced==0))
            {
                if (u16Input_VFreq > 550)
                {
                    u16SrcType = QM_DTV_720p_60hz_H264_Main;
                }
                else if(u16Input_VFreq > 250)
                {
                    u16SrcType = QM_DTV_720p_50hz_H264_Main;
                }
                else
                {
                    u16SrcType = QM_DTV_720p_24hz_H264_Main;
                }
            }
            else
            {
                if (bIsInterlaced)
                {
#if PQ_QM_DTV_4K2K
                    if(PQ_IS_4K_INPUT(u16Input_HSize,u16Input_VSize))  // 4K2K case
                    {
                        if(MApi_XC_GetDynamicScalingStatus() == TRUE)
                        {
                            u16SrcType = QM_DTV_4K2K_DS_Main;
                        }
                        else
                        {
#if (PQ_QM_4K2K_60Hz)
                        if(u16Input_VFreq > GateFor30P)
                            u16SrcType = QM_DTV_4K2K_60Hz_H264_Main;
                        else
#endif
                            u16SrcType = QM_DTV_4K2K_H264_Main;
                        }
                    }
                    else
#endif
#if (PQ_SUPPORT_DTV_720I == 1)
                    if((u16Input_HSize < 1900) && (u16Input_VSize < 900)) //1280x720i mode
                    {
                        u16SrcType = QM_DTV_720i_50hz_H264_Main;
                    }
                    else //1080i
#endif
                    {
                        if (u16Input_VFreq > 550)
                        {
                            u16SrcType = QM_DTV_1080i_60hz_H264_Main;
                        }
                        else
                        {
                            u16SrcType = QM_DTV_1080i_50hz_H264_Main;
                        }
                    }
                }
                else
                {
                    #if PQ_QM_DTV_4K2K
                    if(PQ_IS_4K_INPUT(u16Input_HSize,u16Input_VSize))  // 4K2K case
                    {
                        if(MApi_XC_GetDynamicScalingStatus() == TRUE)
                        {
                            u16SrcType = QM_DTV_4K2K_DS_Main;
                        }
                        else
                        {
                            #if (PQ_QM_4K2K_60Hz)
                            if(u16Input_VFreq > GateFor30P)
                                u16SrcType = QM_DTV_4K2K_60Hz_H264_Main;
                            else
                            #endif
                                u16SrcType = QM_DTV_4K2K_H264_Main;
                        }
                    }
                    else
                    #endif
                    if (u16Input_VFreq > 550)
                    {
                        u16SrcType = QM_DTV_1080p_60hz_H264_Main;
                    }
                    else if(u16Input_VFreq > 250)
                    {
                        u16SrcType = QM_DTV_1080p_50hz_H264_Main;
                    }
                    else
                    {
                        u16SrcType = QM_DTV_1080p_24hz_H264_Main;
                    }
                }
            }
        }
    }
#endif
#if (PQ_DTV_DS)
    if((MApi_XC_GetDynamicScalingStatus() == TRUE) && (bIsInterlaced == TRUE)
        && (!PQ_IS_4K_INPUT(u16Input_HSize,u16Input_VSize)))
    {
        u16SrcType = QM_DTV_FHD_I_DS_Main;
    }
#endif
    //When we get chipcaps is FbLevel,but the input SrcType is DTV4k2k(FBL),we should translate the srcType
    //so that do something about FbLevel like scaling
    if (MApi_XC_GetChipCaps(E_XC_FB_CAPS_GET_FB_LEVEL_EX, (MS_U32*)&stXCGetFBLevel, sizeof(ST_XC_GET_FB_LEVEL_EX)) == E_APIXC_RET_OK)
    {
        if(stXCGetFBLevel.eFBLevel == E_XC_FB_LEVEL_FB)
        {
#if (PQ_QM_PREVIEW)
            if(bIsInterlaced)
            {
                u16SrcType = QM_Multimedia_video_Preview_interlace_Main;

            }
            else
            {
                switch(u16SrcType)
                {
#if PQ_QM_DTV_4K2K
                    case QM_DTV_4K2K_MPEG2_Main:
                    case QM_DTV_4K2K_60Hz_MPEG2_Main:
                        if (u16Input_VFreq > 550)
                        {
                            u16SrcType = QM_Multimedia_video_Preview_progressive_Main;
                        }
                        else if(u16Input_VFreq > 250)
                        {
                            u16SrcType = QM_Multimedia_video_Preview_progressive_Main;
                        }
                        else
                        {
                            u16SrcType = QM_Multimedia_video_Preview_progressive_24hz_Main;
                        }
                        break;
                    case QM_DTV_4K2K_H264_Main:
                    case QM_DTV_4K2K_60Hz_H264_Main:
                        if (u16Input_VFreq > 550)
                        {
                            u16SrcType = QM_Multimedia_video_Preview_progressive_Main;
                        }
                        else if(u16Input_VFreq > 250)
                        {
                            u16SrcType = QM_Multimedia_video_Preview_progressive_Main;
                        }
                        else
                        {
                            u16SrcType = QM_Multimedia_video_Preview_progressive_24hz_Main;
                        }
                        break;
#endif
                    default:
                        printf("DTV curret is FB");
                        break;
                  }
            }

#else
            switch(u16SrcType)
            {
#if PQ_QM_DTV_4K2K
                case QM_DTV_4K2K_MPEG2_Main:
                case QM_DTV_4K2K_60Hz_MPEG2_Main:
                    if (u16Input_VFreq > 550)
                    {
                        u16SrcType = QM_DTV_1080p_60hz_MPEG2_Main;
                    }
                    else if(u16Input_VFreq > 250)
                    {
                        u16SrcType = QM_DTV_1080p_50hz_MPEG2_Main;
                    }
                    else
                    {
                        u16SrcType = QM_DTV_1080p_24hz_MPEG2_Main;
                    }
                    break;
                case QM_DTV_4K2K_H264_Main:
                case QM_DTV_4K2K_60Hz_H264_Main:
                    if (u16Input_VFreq > 550)
                    {
                        u16SrcType = QM_DTV_1080p_60hz_H264_Main;
                    }
                    else if(u16Input_VFreq > 250)
                    {
                        u16SrcType = QM_DTV_1080p_50hz_H264_Main;
                    }
                    else
                    {
                        u16SrcType = QM_DTV_1080p_24hz_H264_Main;
                    }
                    break;
#endif
                default:
                    printf("DTV curret is FB");
                    break;
             }
#endif
         }
    }
    return u16SrcType;
}
static MS_U16 _MDrv_PQ_InputSoureMultiMedia(PQ_WIN eWindow,PQ_INPUT_SOURCE_TYPE enInputSourceType)
{
    MS_U16 u16SrcType = 0;
    MS_U16 u16Input_HSize = QM_GetInputHSize(eWindow);
    MS_U16 u16Input_VSize = QM_GetInputVSize(eWindow);
    MS_U16 u16Input_VFreq = QM_GetInputVFreq(eWindow);
    MS_BOOL bIsInterlaced = QM_IsInterlaced(eWindow);
    MS_U16 u16Disp_HSize = QM_GetDispHSize(eWindow);
    MS_U16 u16Disp_VSize = QM_GetDispVSize(eWindow);
    XC_GET_DS_INFO stGetDSInfo;
    memset(&stGetDSInfo, 0, sizeof(XC_GET_DS_INFO));
    MApi_XC_GetDSInfo(&stGetDSInfo, sizeof(XC_GET_DS_INFO), MDrv_PQ_PQtoSC_WinMapping(eWindow));

    ST_XC_GET_FB_LEVEL_EX stXCGetFBLevel;
    memset(&stXCGetFBLevel, 0, sizeof(ST_XC_GET_FB_LEVEL_EX));
    stXCGetFBLevel.u32Version = ST_XC_GET_FBLEVEL_VERSION;
    stXCGetFBLevel.u32Length = sizeof(ST_XC_GET_FB_LEVEL_EX);
    stXCGetFBLevel.stCropWin.height = u16Input_VSize;
    stXCGetFBLevel.stCropWin.width  = u16Input_HSize;
    stXCGetFBLevel.stDispWin.height = u16Disp_VSize;
    stXCGetFBLevel.stDispWin.width  = u16Disp_HSize;
    stXCGetFBLevel.bInterlace = bIsInterlaced;
    stXCGetFBLevel.eFBLevel = E_XC_FB_LEVEL_FBL;
    stXCGetFBLevel.u8InputSourceType = enInputSourceType;
    if(eWindow == PQ_MAIN_WINDOW)
    {
        stXCGetFBLevel.eWindow = MAIN_WINDOW;
    }
    else
    {
        stXCGetFBLevel.eWindow = SUB_WINDOW;
    }
    if(IsSourceMultiMediaStreamingMode(_stMultiMedia_Info[eWindow].eType,enInputSourceType))
    {
        _gIsNetworkMM = TRUE;
    }
    else
    {
        _gIsNetworkMM = FALSE;
    }
    PQ_LEVEL_PRINTF(PQ_DBG_INFO,"\r\n _gIsNetworkMM = %u",_gIsNetworkMM);

#if (PQ_QM_MM_VIDEO) || (PQ_QM_MM_PHOTO)
#if PQ_QM_NETMM_VIDEO
    if(_gIsNetworkMM)
    {
        if ((u16Input_HSize <= 720) && (u16Input_VSize <= 576))
        {
            if (bIsInterlaced)
            {
                u16SrcType = QM_Multimedia_video_online_SD_interlace_Main;
            }
            else
            {
                if(u16Input_VFreq > GateFor30P)
                {
                    u16SrcType = QM_Multimedia_video_online_SD_progressive_Main;
                }
                else
                {
                    u16SrcType = QM_Multimedia_video_online_SD_progressive_24hz_Main;
                }
            }
        }
        else
        {
            if (bIsInterlaced)
            {
                u16SrcType = QM_Multimedia_video_online_HD_interlace_Main;
            }
            else
            {
                if(u16Input_VFreq > GateFor30P)
                {
                    u16SrcType = QM_Multimedia_video_online_HD_progressive_Main;
                }
                else
                {
                    u16SrcType = QM_Multimedia_video_online_HD_progressive_24hz_Main;
                }
            }
        }
    }
    else
#endif
#if ((defined  (ANDROID)||defined(MSOS_TYPE_LINUX_KERNEL)) && defined(UFO_XC_DS_PQ))

if(stGetDSInfo.bUpdate_DS_CMD || (_gManualDsEnable == TRUE))
{
    if(_stMultiMedia_Info[eWindow].eType == E_PQ_MULTIMEDIA_NUM)
    {
        _stMultiMedia_Info[eWindow].eType = E_PQ_MULTIMEDIA_MOVIE;
    }
}
#endif
    if (QM_IsMultiMediaMOVIE(eWindow)||IsSourceMultiMediaStreamingMode(eWindow,enInputSourceType))
    {
#if PQ_QM_HDMI_FP_VIDEO
        if((u16Input_HSize > 1910)
           && (u16Input_HSize < 1930)
           && (u16Input_VSize > 2218)
            && (u16Input_VSize < 2238)) //1920x2228 i frame packing
        {
            u16SrcType = QM_HDMI_FP_1080i_Main;
        }
        else if(((u16Input_HSize > 1430) && (u16Input_HSize < 1450))
            && (((u16Input_VSize > 591) && (u16Input_VSize < 611)) || ((u16Input_VSize > 493) && (u16Input_VSize < 513))))
        {
            u16SrcType = QM_HDMI_FP_1080i_Main;
        }
        else if((u16Input_HSize > 1910)
                && (u16Input_HSize < 1930)
                && (u16Input_VSize > 2195)
                && (u16Input_VSize < 2215)) //1920x2205 p frame packing
        {
            u16SrcType = QM_HDMI_FP_1080p_Main;
        }
        else if((u16Input_HSize > 1270)
                && (u16Input_HSize < 1290)
                && (u16Input_VSize > 1460)
                && (u16Input_VSize < 1480)) //1280x1470 p frame packing
        {
            u16SrcType = QM_HDMI_FP_720p_Main;
        }
        else
#endif

        if ((u16Input_HSize <= 720) && (u16Input_VSize <= 576))
        {
            if (bIsInterlaced)
            {
                u16SrcType = QM_Multimedia_video_SD_interlace_Main;
            }
            else
            {
#if PQ_QM_24HZMM_VIDEO
                if(u16Input_VFreq > GateFor30P)
                {
                    u16SrcType = QM_Multimedia_video_SD_progressive_Main;
                }
                else
                {
                    u16SrcType = QM_Multimedia_video_SD_progressive_24hz_Main;
                }
#else
                    u16SrcType = QM_Multimedia_video_SD_progressive_Main;
#endif
            }
        }
        else
        {
            if (bIsInterlaced)
            {
                u16SrcType = QM_Multimedia_video_HD_interlace_Main;
            }
            else
            {
#if PQ_QM_24HZMM_VIDEO
#if (PQ_QM_4K2K)
                if(_gIsMVC4kx1k)
                {
                    u16SrcType = QM_Multimedia_video_4K2K_FS_progressive_Main;
                }
                else
#endif
                if((u16Input_VFreq > GateFor30P) && !PQ_IS_4K_INPUT(u16Input_HSize, u16Input_VSize)) //update to use 4k decision macro
                {
                    u16SrcType = QM_Multimedia_video_HD_progressive_Main;
                }
#if (PQ_QM_4K2K)
                else if(PQ_IS_4K_INPUT(u16Input_HSize, u16Input_VSize)) //update to use 4k decision macro
                {
                    u16SrcType = QM_MM_4K2K_Main;
                }
#endif
                else
                {
                    u16SrcType = QM_Multimedia_video_HD_progressive_24hz_Main;
                }
#else
#if (PQ_QM_4K2K)
                if(_gIsMVC4kx1k)
                {
                    u16SrcType = QM_Multimedia_video_4K2K_FS_progressive_Main;
                }
                else
#endif
                {
                    u16SrcType = QM_Multimedia_video_HD_progressive_Main;
                }
#endif

#if (PQ_QM_4K2K)
                if((u16Input_HSize > 3000) && (u16Input_VSize > 1050) && (u16Input_VSize < 1900))
                {
#if (defined ENABLE_4K2K_NIKEU && ENABLE_4K2K_NIKEU == 1)
                    u16SrcType = QM_MM_4K1K_Main;
#else
#if (PQ_QM_4K2K_60Hz)
                    if(u16Input_VFreq > GateFor30P)
                    {
#if (PQ_DS_ENABLE)
                        if((MApi_XC_GetDynamicScalingStatus()))
                        {
                            if(_gIsNetworkMM)
                                u16SrcType = QM_NetWork_4K2K_DS_Main;
                            else
                                u16SrcType = QM_MM_4K2K_DS_Main;
                        }
                        else
#endif
                        {
                            u16SrcType = QM_MM_4K2K_60Hz_Main;
                        }
                    }
                    else
#endif
#if (PQ_DS_ENABLE)
                        if((MApi_XC_GetDynamicScalingStatus()))
                        {
                            if(_gIsNetworkMM)
                                u16SrcType = QM_NetWork_4K2K_DS_Main;
                            else
                                u16SrcType = QM_MM_4K2K_DS_Main;
                        }
                        else
#endif
                        {
                            u16SrcType = QM_MM_4K2K_Main;
                        }
#endif
                }
#if (PQ_DS_ENABLE)
                else if(QM_IS_FHD(u16Input_HSize,u16Input_VSize) && _MDrv_PQ_IsSupportPQDSPlus())
                {
                    if((MApi_XC_GetDynamicScalingStatus()) || (_gManualDsEnable == TRUE))
                    {
                        if(_gIsNetworkMM)
                        {
                            u16SrcType = QM_NetWork_FHD_P_DS_Main;
                        }
                        else
                        {
                            u16SrcType = QM_MM_FHD_P_DS_Main;
                        }
                    }
                    else
                    {
                        u16SrcType =QM_Multimedia_video_HD_progressive_Main;
                    }
                }
#endif
                else if(MDrv_PQ_GetPQPathStatus(E_PQ_4K_PATH, u16Input_HSize, u16Input_VSize))
                {
#if (PQ_QM_4K2K_60Hz)
                    if(u16Input_VFreq > GateFor30P)
                    {
#if (PQ_DS_ENABLE)
                        if((MApi_XC_GetDynamicScalingStatus()))
                        {
                            if(_gIsNetworkMM)
                                u16SrcType = QM_NetWork_4K2K_DS_Main;
                            else
                                u16SrcType = QM_MM_4K2K_DS_Main;
                        }
                        else
#endif
                        {
                            u16SrcType = QM_MM_4K2K_60Hz_Main;
                        }
                    }
                    else
#endif
                    {
#if (PQ_DS_ENABLE)
                        if((MApi_XC_GetDynamicScalingStatus()))
                        {
                            if(_gIsNetworkMM)
                                u16SrcType = QM_NetWork_4K2K_DS_Main;
                            else
                                u16SrcType = QM_MM_4K2K_DS_Main;
                        }
                        else
#endif
                        {
                            u16SrcType = QM_MM_4K2K_Main;
                        }
                    }
                }
#endif
            }
        }
    }
    else //QM_IsMultiMediaPHOTO(eWindow)
    {
        if ((u16Input_HSize <= 720) && (u16Input_VSize <= 576))
        {
            u16SrcType = QM_Multimedia_photo_SD_progressive_Main;
        }
#if (PQ_QM_4K2K)
        ///for 4K photo
        else if((u16Input_HSize < 1500) && (u16Input_VSize >= 1900) )
        {
            u16SrcType = QM_MM_non_4K2K_Main;
        }
        else if((u16Input_HSize > 3800) && (u16Input_VSize > 1050))
        {
            u16SrcType = QM_MM_4K2K_Photo_Main;
        }
#endif
        else
        {
            u16SrcType = QM_Multimedia_photo_HD_progressive_Main;
        }
#if(PQ_QM_MM_PHOTO_RGB)
        MVOP_Handle stMvopHd = { E_MVOP_MODULE_MAIN };
        MVOP_RgbFormat enRGB = E_MVOP_RGB_NONE;
        if(MDrv_MVOP_GetCommand(&stMvopHd, E_MVOP_CMD_GET_RGB_FMT, & enRGB, sizeof(MVOP_RgbFormat)) == E_MVOP_OK)
        {
            if(enRGB == E_MVOP_RGB_888)
            {
                switch(u16SrcType)
                {
                    case QM_Multimedia_photo_SD_progressive_Main:
                    case QM_MM_4K2K_Photo_Main:
                    case QM_Multimedia_photo_HD_progressive_Main:
                        u16SrcType = QM_MM_4K2K_Photo_444_Main;
                        break;
                    default:
                        break;
                }
            }
        }
#endif
    }
#endif
    //When we get chipcaps is FbLevel,but the input SrcType is MM(FBL),we should translate the srcType
    //so that do something about FbLevel like scaling
    if (MApi_XC_GetChipCaps(E_XC_FB_CAPS_GET_FB_LEVEL_EX, (MS_U32*)&stXCGetFBLevel, sizeof(ST_XC_GET_FB_LEVEL_EX)) == E_APIXC_RET_OK)
    {
        if(stXCGetFBLevel.eFBLevel == E_XC_FB_LEVEL_FB)
        {
#if (PQ_QM_PREVIEW)
            if(bIsInterlaced)
            {
                u16SrcType = QM_Multimedia_video_Preview_interlace_Main;

            }else
#endif
            {
                switch(u16SrcType)
                {
#if (PQ_DS_ENABLE)
                    case QM_MM_FHD_P_DS_Main:
#if (PQ_QM_PREVIEW)
                        u16SrcType = QM_Multimedia_video_Preview_progressive_Main;
#else
                        u16SrcType = QM_Multimedia_video_HD_progressive_Main;
#endif
                        break;
#endif
#if (PQ_QM_4K2K)
#if (PQ_DS_ENABLE)
                    case QM_MM_4K2K_DS_Main:
                    case QM_NetWork_4K2K_DS_Main:
#if (PQ_QM_PREVIEW)
                        u16SrcType = QM_Multimedia_video_Preview_progressive_Main;
#else
                        u16SrcType = QM_Multimedia_video_HD_progressive_Main;
#endif
                        break;
#endif
                    case QM_MM_4K2K_Main:
                    case QM_MM_4K2K_60Hz_Main:
                    case QM_MM_non_4K2K_Main:
#if (PQ_QM_PREVIEW)
                        u16SrcType = QM_Multimedia_video_Preview_progressive_Main;
#else
                        u16SrcType = QM_Multimedia_video_HD_progressive_Main;
#endif
                        break;
#endif
                    default:
                        printf("MM curret is FB");
                        break;
                }
            }
        }
    }

    return u16SrcType;
}
static MS_U16 _MDrv_PQ_InputSoureCVBS_ScartRGB(PQ_WIN eWindow,PQ_INPUT_SOURCE_TYPE enInputSourceType)
{
    MS_U16 u16SrcType = 0;
#if (PQ_QM_CVBS)
    PQ_VIDEOSTANDARD_TYPE eStandard = E_PQ_VIDEOSTANDARD_MAX;
    eStandard = QM_GetATVStandard(eWindow);
    switch(eStandard)
    {
    case E_PQ_VIDEOSTANDARD_PAL_M:
        u16SrcType = QM_SCART_AV_PAL_M_Main;
        break;
    case E_PQ_VIDEOSTANDARD_PAL_N:
        u16SrcType = QM_SCART_AV_PAL_N_Main;
        break;
    case E_PQ_VIDEOSTANDARD_NTSC_44:
        u16SrcType = QM_SCART_AV_NTSC_44_Main;
        break;
    case E_PQ_VIDEOSTANDARD_PAL_60:
        u16SrcType = QM_SCART_AV_PAL_60_Main;
        break;
    case E_PQ_VIDEOSTANDARD_NTSC_M:
        u16SrcType = QM_SCART_AV_NTSC_M_Main;
        break;
    case E_PQ_VIDEOSTANDARD_SECAM:
        u16SrcType = QM_SCART_AV_SECAM_Main;
        break;
    case E_PQ_VIDEOSTANDARD_PAL_BGHI:
        u16SrcType = QM_SCART_AV_PAL_BGHI_Main;
        break;
    default:
        u16SrcType = QM_SCART_AV_PAL_BGHI_Main;
        break;
    }
#else
    UNUSED(enInputSourceType);
    UNUSED(eWindow);
#endif
    return u16SrcType;
}
static MS_U16 _MDrv_PQ_InputSoureATV(PQ_WIN eWindow,PQ_INPUT_SOURCE_TYPE enInputSourceType)
{
    MS_U16 u16SrcType = 0;
#if (PQ_QM_CVBS)
    PQ_VIDEOSTANDARD_TYPE eStandard = E_PQ_VIDEOSTANDARD_MAX;
    eStandard = QM_GetATVStandard(eWindow);
    if (QM_FRONTEND_RFIN(eWindow))
    {
        switch(eStandard)
        {
        case E_PQ_VIDEOSTANDARD_PAL_M:
            u16SrcType = QM_RF_PAL_M_Main;
            break;
        case E_PQ_VIDEOSTANDARD_PAL_N:
            u16SrcType = QM_RF_PAL_N_Main;
            break;
        case E_PQ_VIDEOSTANDARD_NTSC_44:
            u16SrcType = QM_RF_NTSC_44_Main;
            break;
        case E_PQ_VIDEOSTANDARD_PAL_60:
            u16SrcType = QM_RF_PAL_60_Main;
            break;
        case E_PQ_VIDEOSTANDARD_NTSC_M:
            u16SrcType = QM_RF_NTSC_M_Main;
            break;
        case E_PQ_VIDEOSTANDARD_SECAM:
            u16SrcType = QM_RF_SECAM_Main;
            break;
        case E_PQ_VIDEOSTANDARD_PAL_BGHI:
            u16SrcType = QM_RF_PAL_BGHI_Main;
            break;
        default:
            u16SrcType = QM_RF_PAL_BGHI_Main;
            break;
        }
    }
    else // QM_FRONTEND_VIFIN(eWindow)
    {
        switch(eStandard)
        {
        case E_PQ_VIDEOSTANDARD_PAL_M:
            u16SrcType = QM_VIF_PAL_M_Main;
            break;
        case E_PQ_VIDEOSTANDARD_PAL_N:
            u16SrcType = QM_VIF_PAL_N_Main;
            break;
        case E_PQ_VIDEOSTANDARD_NTSC_44:
            u16SrcType = QM_VIF_NTSC_44_Main;
            break;
        case E_PQ_VIDEOSTANDARD_PAL_60:
            u16SrcType = QM_VIF_PAL_60_Main;
            break;
        case E_PQ_VIDEOSTANDARD_NTSC_M:
            u16SrcType = QM_VIF_NTSC_M_Main;
            break;
        case E_PQ_VIDEOSTANDARD_SECAM:
            u16SrcType = QM_VIF_SECAM_Main;
            break;
        case E_PQ_VIDEOSTANDARD_PAL_BGHI:
            u16SrcType = QM_VIF_PAL_BGHI_Main;
            break;
        default:
            u16SrcType = QM_VIF_PAL_BGHI_Main;
            break;
        }
    }
#else
    UNUSED(enInputSourceType);
    UNUSED(eWindow);
#endif
    return u16SrcType;
}
static MS_U16 _MDrv_PQ_InputSoureSV(PQ_WIN eWindow,PQ_INPUT_SOURCE_TYPE enInputSourceType)
{
    MS_U16 u16SrcType = 0;
#if (PQ_QM_CVBS)
    PQ_VIDEOSTANDARD_TYPE eStandard = E_PQ_VIDEOSTANDARD_MAX;
    eStandard = QM_GetATVStandard(eWindow);
    switch(eStandard)
    {
    case E_PQ_VIDEOSTANDARD_PAL_M:
        u16SrcType = (MS_U16)QM_SV_PAL_M_Main;
        break;
    case E_PQ_VIDEOSTANDARD_PAL_N:
        u16SrcType = (MS_U16)QM_SV_PAL_N_Main;
        break;
    case E_PQ_VIDEOSTANDARD_NTSC_44:
        u16SrcType = (MS_U16)QM_SV_NTSC_44_Main;
        break;
    case E_PQ_VIDEOSTANDARD_PAL_60:
        u16SrcType = (MS_U16)QM_SV_PAL_60_Main;
        break;
    case E_PQ_VIDEOSTANDARD_NTSC_M:
        u16SrcType = (MS_U16)QM_SV_NTSC_M_Main;
        break;
    case E_PQ_VIDEOSTANDARD_SECAM:
        u16SrcType = (MS_U16)QM_SV_SECAM_Main;
        break;
    case E_PQ_VIDEOSTANDARD_PAL_BGHI:
        u16SrcType = (MS_U16)QM_SV_PAL_BGHI_Main;
        break;
    default:
        u16SrcType = (MS_U16)QM_SV_PAL_BGHI_Main;
        break;
    }
#else
    UNUSED(enInputSourceType);
    UNUSED(eWindow);
#endif
    return u16SrcType;
}
static MS_U16 _MDrv_PQ_InputSoureAV(PQ_WIN eWindow,PQ_INPUT_SOURCE_TYPE enInputSourceType)
{
    MS_U16 u16SrcType = 0;
#if (PQ_QM_CVBS)
    PQ_VIDEOSTANDARD_TYPE eStandard = E_PQ_VIDEOSTANDARD_MAX;
    eStandard = QM_GetATVStandard(eWindow);
    switch(eStandard)
    {
    case E_PQ_VIDEOSTANDARD_PAL_M:
        u16SrcType = QM_AV_PAL_M_Main;
        break;
    case E_PQ_VIDEOSTANDARD_PAL_N:
        u16SrcType = QM_AV_PAL_N_Main;
        break;
    case E_PQ_VIDEOSTANDARD_NTSC_44:
        u16SrcType = QM_AV_NTSC_44_Main;
        break;
    case E_PQ_VIDEOSTANDARD_PAL_60:
        u16SrcType = QM_AV_PAL_60_Main;
        break;
    case E_PQ_VIDEOSTANDARD_NTSC_M:
        u16SrcType = QM_AV_NTSC_M_Main;
        break;
    case E_PQ_VIDEOSTANDARD_SECAM:
        u16SrcType = QM_AV_SECAM_Main;
        break;
    case E_PQ_VIDEOSTANDARD_PAL_BGHI:
        u16SrcType = QM_AV_PAL_BGHI_Main;
        break;
    default:
        u16SrcType = QM_AV_PAL_BGHI_Main;
        break;
    }
#else
    UNUSED(enInputSourceType);
    UNUSED(eWindow);
#endif
    return u16SrcType;
}
static MS_BOOL _MDrv_PQ_IsSourceSupportMainHFR(PQ_WIN eWindow)
{
#if defined(PQ_QM_HFR_PATH) && (PQ_QM_HFR_PATH==1)
    MS_BOOL bIsSupportHFR = FALSE;
    MS_BOOL bIsHFRPathEnable = FALSE;
    XC_ApiStatusEx stXCStatusEx;
    memset(&stXCStatusEx,0,sizeof(XC_ApiStatusEx));
    stXCStatusEx.u16ApiStatusEX_Length = sizeof(XC_ApiStatusEx);
    stXCStatusEx.u32ApiStatusEx_Version = API_STATUS_EX_VERSION;

    if(MApi_XC_GetStatusEx(&stXCStatusEx, eWindow) == sizeof(XC_ApiStatusEx))
    {
        bIsHFRPathEnable = stXCStatusEx.bIsHFRPathEnable;
    }
    MApi_XC_GetChipCaps(E_XC_SUPPORT_HFR_PATH,(MS_U32*)&bIsSupportHFR, sizeof(MS_BOOL));

    if(eWindow == PQ_MAIN_WINDOW)
    {
        if((bIsSupportHFR == TRUE) && (bIsHFRPathEnable == TRUE))
        {
            return TRUE;
        }
    }
#else
    UNUSED(eWindow);
#endif
    return FALSE;
}
static MS_U16 _MDrv_PQ_InputSource120Hz(PQ_WIN eWindow,MS_U16 u16SrcType,MS_U8 enInputSourceType)
{
#if defined(PQ_QM_HFR_PATH) && (PQ_QM_HFR_PATH==1)
    MS_U16 u16Input_HSize = QM_GetInputHSize(eWindow);
    MS_U16 u16Input_VSize = QM_GetInputVSize(eWindow);
    MS_BOOL bIsFRCBehindVOPOutput120Hz = FALSE;

    XC_ApiStatusEx stXC_ApiStatusEx;

    memset(&stXC_ApiStatusEx, 0, sizeof(XC_ApiStatusEx));
    stXC_ApiStatusEx.u16ApiStatusEX_Length = sizeof(XC_ApiStatusEx);
    stXC_ApiStatusEx.u32ApiStatusEx_Version = API_STATUS_EX_VERSION;
    MApi_XC_GetStatusEx(&stXC_ApiStatusEx, eWindow);
    bIsFRCBehindVOPOutput120Hz = IsVBY1_16LANE(stXC_ApiStatusEx.u16PanelInterfaceType);

    PQ_LEVEL_PRINTF(PQ_DBG_INFO,"PQ_Window[%d] HFR MAIN PATH %s\n",eWindow,_MDrv_PQ_IsSourceSupportMainHFR(eWindow)?"TRUE":"FALSE");
    PQ_LEVEL_PRINTF(PQ_DBG_INFO,"PQ_Window[%d] bIsFRCBehindVOPOutput120Hz %s\n",eWindow,bIsFRCBehindVOPOutput120Hz?"TRUE":"FALSE");
    PQ_LEVEL_PRINTF(PQ_DBG_INFO,"PQ_Window[%d] input frame rate %d\n",eWindow,QM_GetInputVFreq(eWindow));
    PQ_LEVEL_PRINTF(PQ_DBG_INFO,"PQ_Window[%d] _gIsNetworkMM %s\n",eWindow,_gIsNetworkMM?"TRUE":"FALSE");

    if((QM_GetInputVFreq(eWindow) < GateFor120P) || bIsFRCBehindVOPOutput120Hz == FALSE)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_INFO,"PQ_Window[%d] Unsupport\n");
        return u16SrcType;
    }
    if(_MDrv_PQ_IsSourceSupportMainHFR(eWindow) == TRUE) //HFR Path
    {
        if(QM_IsSourceMultiMedia(enInputSourceType))
        {
            if(_gIsNetworkMM == TRUE)
            {
                u16SrcType = (MS_U16)QM_NetWork_MM_4K2K_120Hz_Main;
            }
            else
            {
                u16SrcType = (MS_U16)QM_MM_4K2K_120Hz_Main;
            }
        }
        else if(QM_IsSourceHDMI(enInputSourceType))
        {
            if(MDrv_PQ_Get_PointToPoint(eWindow) &&
            (QM_HDMIPC_COLORYUV444(eWindow) || QM_HDMIPC_COLORRGB(eWindow)))
            {
                u16SrcType = (MS_U16)QM_4K2K_120Hz_PC_Main;
            }
            else
            {
                u16SrcType = (MS_U16)QM_4K2K_120Hz_Main;
            }
        }
        else
        {
            return u16SrcType;
        }
    }
    else if(QM_IsSourceVGA(enInputSourceType) || (QM_IsSourceDVI_HDMIPC(enInputSourceType, eWindow) && !QM_IsInterlaced(eWindow)))
    {
        if(QM_IsSourceVGA(enInputSourceType))
        {
            u16SrcType = (MS_U16)QM_DVI_Dsub_HDMI_PC_1080p_120hz_Main;
        }
        else if(QM_IsSourceHDMI(enInputSourceType))
        {
            if(QM_HDMIPC_COLORYUV444(eWindow) || QM_HDMIPC_COLORRGB(eWindow))
            {
                u16SrcType = (MS_U16)QM_DVI_Dsub_HDMI_PC_1080p_120hz_Main;
            }
            else
            {
                u16SrcType = (MS_U16)QM_DVI_Dsub_HDMI_VIDEO_1080p_120hz_Main;
            }
        }
        else
        {
            return u16SrcType;
        }
    }
    else if(QM_IsSourceHDMI(enInputSourceType) && !QM_IsInterlaced(eWindow))
    {
        if(MDrv_PQ_Get_PointToPoint(eWindow) &&
        (QM_HDMIPC_COLORYUV444(eWindow) || QM_HDMIPC_COLORRGB(eWindow)))
        {
            u16SrcType = (MS_U16)QM_HDMI_1080p_PC_120hz_Main;
        }
        else
        {
            u16SrcType = (MS_U16)QM_HDMI_1080p_120hz_Main;
        }
    }
    else if(QM_IsSourceMultiMedia(enInputSourceType))
    {
        if(_gIsNetworkMM == TRUE)
        {
            u16SrcType = (MS_U16)QM_NetWork_MM_FHD_P_DS_120Hz_Main;
        }
        else
        {
            u16SrcType = (MS_U16)QM_MM_FHD_P_DS_120Hz_Main;
        }
    }
    else
    {
        return u16SrcType;
    }
#else
    UNUSED(eWindow);
    UNUSED(enInputSourceType);
#endif
    return u16SrcType;
}
static MS_U16 _MDrv_PQ_InputSoureDolby(PQ_WIN eWindow,MS_U16 u16SrcType)
{
#if (PQ_QM_DOLBY == 1)
    MS_BOOL bDolby = FALSE;

    XC_CFD_STATUS stCfdStatus;
    memset(&stCfdStatus, 0, sizeof(XC_CFD_STATUS));
    stCfdStatus.u32Version = CFD_STATUS_VERSION;
    stCfdStatus.u16Length = sizeof(XC_CFD_STATUS);
    stCfdStatus.u8Win = MAIN_WINDOW;

    XC_CFD_CONTROL_INFO stCfdCtrlInfo;
    memset(&stCfdCtrlInfo, 0, sizeof(XC_CFD_CONTROL_INFO));
    stCfdCtrlInfo.enCtrlType = E_XC_CFD_CTRL_TYPE_STATUS;
    stCfdCtrlInfo.pParam = &stCfdStatus;
    stCfdCtrlInfo.u32ParamLen = sizeof(XC_CFD_STATUS);
    MApi_XC_HDR_Control(E_XC_HDR_CTRL_CFD_CONTROL, &stCfdCtrlInfo);

    if((stCfdStatus.u8VideoHdrType == E_XC_CFD_HDR_TYPE_DOLBY) && (stCfdStatus.bIsHdrRunning == TRUE))
    {
        bDolby = TRUE;
    }

    PQ_LEVEL_PRINTF(PQ_DBG_INFO,"PQ_Window[%d] %s",eWindow,bDolby?"Dolby":"Non-Dolby");

    if(bDolby)
    {
        switch(u16SrcType)
        {
#if (PQ_QM_HDMI_PC)
            case QM_HDMI_444_PC_Hup_Vup_Main:
            case QM_HDMI_444_PC_Hup_Vdown_Main:
            case QM_HDMI_444_PC_Hup_Vno_Main:
            case QM_HDMI_444_PC_Hdown_Vup_Main:
            case QM_HDMI_444_PC_Hdown_Vdown_Main:
            case QM_HDMI_444_PC_Hdown_Vno_Main:
            case QM_HDMI_444_PC_Hno_Vup_Main:
            case QM_HDMI_444_PC_Hno_Vdown_Main:
            case QM_HDMI_444_PC_Hno_Vno_Main:
            case QM_HDMI_444_PC_Hno_Vno_4K_Main:
            {
                u16SrcType = QM_HDMI_444_PC_Hno_Vno_4K_Dolby_Main;
                break;
            }
            case QM_HDMI_422_PC_Hup_Vup_Main:
            case QM_HDMI_422_PC_Hup_Vdown_Main:
            case QM_HDMI_422_PC_Hup_Vno_Main:
            case QM_HDMI_422_PC_Hdown_Vup_Main:
            case QM_HDMI_422_PC_Hdown_Vdown_Main:
            case QM_HDMI_422_PC_Hdown_Vno_Main:
            case QM_HDMI_422_PC_Hno_Vup_Main:
            case QM_HDMI_422_PC_Hno_Vdown_Main:
            case QM_HDMI_422_PC_Hno_Vno_Main:
            {
                u16SrcType = QM_HDMI_422_PC_Hno_Vno_Dolby_Main;
                break;
            }
#endif
#if (PQ_QM_HMDI)
            case QM_4K2K_60Hz_Main:
            {
                u16SrcType = QM_HDMI_4K2K_60Hz_Dolby_Main;
                break;
            }
            case QM_4K2K_24Hz_Main:
            case QM_4K2K_30Hz_Main:
            {
                u16SrcType = QM_HDMI_4K2K_30Hz_Dolby_Main;
                break;
            }
            case QM_HDMI_1080i_50hz_Main:
            case QM_HDMI_1080i_60hz_Main:
            case QM_HDMI_1080p_24hz_Main:
            case QM_HDMI_1080p_60hz_Main:
            case QM_HDMI_1080p_50hz_Main:
            case QM_HDMI_FP_1080i_Main:
            case QM_HDMI_FP_1080p_Main:
            {
                u16SrcType = QM_HDMI_1080p_60hz_Dolby_Main;
                break;
            }
#if defined(PQ_QM_HFR_PATH) && (PQ_QM_HFR_PATH==1)
            case QM_4K2K_120Hz_Main:
            {
                u16SrcType = QM_HDMI_4K2K_120Hz_Dolby_Main;
                break;
            }
#endif

#endif
            default:
            {
                break;
            }
        }
    }
#else
    UNUSED(eWindow);
    UNUSED(u16SrcType);
#endif
    return u16SrcType;
}

static MS_U16 _MDrv_PQ_InputSourceUnLock(PQ_WIN enWindow, MS_U16 u16SrcType)
{
    MS_BOOL bIsInterlaced = QM_IsInterlaced(enWindow);
    MS_U16 u16Input_VFreq = QM_GetInputVFreq(enWindow);
    return MHal_PQ_InputSourceUnLock(enWindow,u16SrcType,bIsInterlaced,u16Input_VFreq);
}

static MS_U16 _MDrv_PQ_SetByPassMode(PQ_WIN eWindow,MS_U16 u16SrcType)
{
#if (PQ_QM_BYPASS_COLOR)
    MS_BOOL bIsInterlaced = QM_IsInterlaced(eWindow);
    //  Only when bypass mode is on .
    if (_bBypassModeOn[eWindow])
    {
        if (bIsInterlaced)
        {
            u16SrcType = QM_BypassColor_interlace_Main;
        }
        else
        {
            u16SrcType = QM_BypassColor_progressive_Main;
        }
        return u16SrcType;
    }
#else
    UNUSED(eWindow);
    UNUSED(u16SrcType);
#endif
    return u16SrcType;
}
static EN_PQ_SOURCETYPE _MDrv_InputSourceType(PQ_WIN eWindow, PQ_INPUT_SOURCE_TYPE enInputSourceType)
{
    EN_PQ_SOURCETYPE enPQSourceType =E_PQ_SOURCETYPE_MAX;
#if ENABLE_VGA_EIA_TIMING
    // Only Progressiv mode
    if ((QM_IsSourceVGA(enInputSourceType) || QM_IsSourceDVI_HDMIPC(enInputSourceType, eWindow)|| QM_IsSourceHDMI_PC(enInputSourceType, eWindow)) && (!QM_IsInterlaced(eWindow)))
#else
    // Only DVI progressive mode, VGA could be interlace
    if (QM_IsSourceVGA(enInputSourceType) || (QM_IsSourceDVI_HDMIPC(enInputSourceType, eWindow) && !QM_IsInterlaced(eWindow)))
#endif
    {
        PQ_LEVEL_PRINTF(PQ_DBG_INFO,"Input Source is %s PC mode\n",(QM_IsSourceVGA(enInputSourceType))?"VGA":"HDMI");
        enPQSourceType = E_PQ_SOURCETYPE_VGB_HDMIPC;
    }
    else if (QM_IsSourceHDMI(enInputSourceType)
#if ENABLE_VGA_EIA_TIMING
             || QM_IsSourceVGA(enInputSourceType) //interlace VGA comes here
#endif
            )
    {
        PQ_LEVEL_PRINTF(PQ_DBG_INFO,"Input Source is HDMI\n");
        enPQSourceType = E_PQ_SOURCETYPE_HDMI;
    }
    else if (QM_IsSourceYPbPr(enInputSourceType))
    {
        PQ_LEVEL_PRINTF(PQ_DBG_INFO,"Input Source is YPBPR\n");
        enPQSourceType = E_PQ_SOURCETYPE_YPBPR;
    }
    else if (QM_IsSourceDTV(enInputSourceType))
    {
        PQ_LEVEL_PRINTF(PQ_DBG_INFO,"Input Source is DTV\n");
        enPQSourceType = E_PQ_SOURCETYPE_DTV;
    }
    else if (QM_IsSourceMultiMedia(enInputSourceType))
    {
        PQ_LEVEL_PRINTF(PQ_DBG_INFO,"Input Source is MM\n");
        enPQSourceType = E_PQ_SOURCETYPE_MULTIMEDIA;
    }
    else if (QM_IsSourceScartCVBS(enInputSourceType, eWindow) || QM_IsSourceScartRGB(enInputSourceType, eWindow))
    {
        PQ_LEVEL_PRINTF(PQ_DBG_INFO,"Input Source is %s\n",(QM_IsSourceScartCVBS(enInputSourceType, eWindow))?"CVBS":"SCARTRGB");
        enPQSourceType = E_PQ_SOURCETYPE_CVBS_SCARTRGB;
    }
    else if (QM_IsSourceATV(enInputSourceType))
    {
        PQ_LEVEL_PRINTF(PQ_DBG_INFO,"Input Source is ATV\n");
        enPQSourceType = E_PQ_SOURCETYPE_ATV;
    }
    else if(QM_IsSourceSV(enInputSourceType))
    {
        PQ_LEVEL_PRINTF(PQ_DBG_INFO,"Input Source is SV\n");
        enPQSourceType = E_PQ_SOURCETYPE_SV;
    }
    else // AV
    {
        PQ_LEVEL_PRINTF(PQ_DBG_INFO,"Input Source is AV\n");
        enPQSourceType = E_PQ_SOURCETYPE_AV;
    }
    return enPQSourceType;
}
MS_U16 QM_InputSourceToIndex(void* pInstance, PQ_WIN eWindow, PQ_INPUT_SOURCE_TYPE enInputSourceType)
{
    MS_U16 u16SrcType = 0;
    PQ_LEVEL_PRINTF(PQ_DBG_INFO,"\r\n QM: Src[%d] = %u, H = %u, V = %u",eWindow,enInputSourceType,QM_GetInputHSize(eWindow),QM_GetInputVSize(eWindow));
    PQ_LEVEL_PRINTF(PQ_DBG_INFO,"\r\n QM: VFreq = %u, %s mode",QM_GetInputVFreq(eWindow),(QM_IsInterlaced(eWindow))?"Interlaced":"Progressive");
    PQ_LEVEL_PRINTF(PQ_DBG_INFO,"\r\n QM: DispH = %u, DispV = %u",QM_GetDispHSize(eWindow),QM_GetDispVSize(eWindow));

    switch(_MDrv_InputSourceType(eWindow,enInputSourceType))
    {
        case E_PQ_SOURCETYPE_VGB_HDMIPC:
            u16SrcType = _MDrv_PQ_InputSoureVGB_HDMIPC(eWindow,enInputSourceType);
        break;
        case E_PQ_SOURCETYPE_HDMI:
            u16SrcType = _MDrv_PQ_InputSoureHDMI(eWindow,enInputSourceType);
        break;
        case E_PQ_SOURCETYPE_YPBPR:
            u16SrcType = _MDrv_PQ_InputSoureYPBPR(eWindow,enInputSourceType);
        break;
        case E_PQ_SOURCETYPE_DTV:
            u16SrcType = _MDrv_PQ_InputSoureDTV(eWindow,enInputSourceType);
        break;
        case E_PQ_SOURCETYPE_MULTIMEDIA:
            u16SrcType = _MDrv_PQ_InputSoureMultiMedia(eWindow,enInputSourceType);
        break;
        case E_PQ_SOURCETYPE_CVBS_SCARTRGB:
            u16SrcType = _MDrv_PQ_InputSoureCVBS_ScartRGB(eWindow,enInputSourceType);
        break;
        case E_PQ_SOURCETYPE_ATV:
            u16SrcType = _MDrv_PQ_InputSoureATV(eWindow,enInputSourceType);
        break;
        case E_PQ_SOURCETYPE_SV:
            u16SrcType = _MDrv_PQ_InputSoureSV(eWindow,enInputSourceType);
        break;
        case E_PQ_SOURCETYPE_AV:
            u16SrcType = _MDrv_PQ_InputSoureAV(eWindow,enInputSourceType);
        break;
        default:
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"ERROR!! Can't find ScrType\n");
            return u16SrcType;
        }
    }
    u16SrcType = _MDrv_PQ_InputSourceUnLock(eWindow, u16SrcType);
    u16SrcType = _MDrv_PQ_InputSource120Hz(eWindow,u16SrcType,enInputSourceType);
    u16SrcType = _MDrv_PQ_InputSoureDolby(eWindow,u16SrcType);
    u16SrcType = _MDrv_PQ_SetByPassMode(eWindow,u16SrcType);

    _MDrv_PQ_CFD_SetColorInfo(eWindow, enInputSourceType);

    printf("[Load PQ] Panel index=%d, Source index=%d\n", MDrv_PQBin_GetPanelIdx(pInstance), u16SrcType);
    return u16SrcType;
}

void MDrv_PQ_SetColorThroughMode_U2(void* pInstance, PQ_WIN eWindow, MS_BOOL bEn)
{
    _gIsThroughMode = bEn;
}

void SYMBOL_WEAK MDrv_PQ_SetColorThroughMode(PQ_WIN eWindow, MS_BOOL bEn)
{
#ifdef UFO_XC_PQ_SUPPORT_REPEATER_COLOR_THROUGH_MODE
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return ;
    }

    stPQ_SetColorThroughMode PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.bEn = bEn;
    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SET_COLOR_THROUGH_MODE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return;
    }
    else
    {
        return;
    }
#else
    PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"\33[1;33m[UFO_XC_PQ_SUPPORT_REPEATER_COLOR_THROUGH_MODE]\33[m\n");
    return;
#endif

}

MS_U16 QM_InputSourceToIndex_UFSC(void* pInstance,PQ_WIN eWindow, MS_U8 enInputSourceType)
{
    MS_U16 u16SrcType = 0;
#if defined(ENABLE_PQ_BIN_UFSC) && ENABLE_PQ_BIN_UFSC
    MS_U16 u16Input_HSize = QM_GetInputHSize(eWindow);
    MS_U16 u16Input_VSize = QM_GetInputVSize(eWindow);
    MS_BOOL bRGB444 = FALSE, bYUV422 = FALSE;

    XC_ApiStatusEx stDrvStatusEx;
    memset(&stDrvStatusEx, 0, sizeof(XC_ApiStatusEx));
    stDrvStatusEx.u16ApiStatusEX_Length = sizeof(XC_ApiStatusEx);
    stDrvStatusEx.u32ApiStatusEx_Version = API_STATUS_EX_VERSION;
    MApi_XC_GetStatusEx(&stDrvStatusEx, MAIN_WINDOW);
    if (stDrvStatusEx.bMemYUVFmt)
    {
        if (stDrvStatusEx.bMemFmt422)
        {
            bYUV422 = TRUE;
        }
    }
    else
    {
        bRGB444 = TRUE;
    }

#if(ENABLE_PQ_UFSC_DLC)
    if(E_XC_3D_OUTPUT_MODE_NONE != MApi_XC_Get_3D_Output_Mode())
    {
        u16SrcType = QM_FSC_3D_UFSC; /// 3d
    }
    else
#endif
 if(
    ((MDrv_PQBin_GetPanelIdx_UFSC(pInstance)==PQ_BIN_PNLTYPE_4K2K) && (MDrv_PQ_GetPQPathStatus(E_PQ_UFSC_4K_PATH, u16Input_HSize, u16Input_VSize))) ||
    (!(MDrv_PQBin_GetPanelIdx_UFSC(pInstance)==PQ_BIN_PNLTYPE_4K2K) )
    )
    {
#if(ENABLE_PQ_UFSC_BYPASS)
    #if (PQ_QM_DTV)
        if((QM_IsSourceDTV(enInputSourceType)) && (QM_IsDTV_IFRAME(eWindow)))
        {
            u16SrcType = QM_4K2K_PQbypass_UFSC; //QM_4K2K_PQbypass_UFSC
        }
        else
    #endif
#endif
        {
            if (bRGB444)
            {
                if( MApi_XC_GetDynamicScalingStatus())
                {
                    u16SrcType = QM_4K2K_RGB444_DS_UFSC;//4K2K_RGB444_DS
                }
                else
                {
                   u16SrcType = QM_4K2K_RGB444_UFSC; //4K2K_RGB444
                }
            }
            else if (bYUV422)
            {
                if( MApi_XC_GetDynamicScalingStatus())
                {
                    u16SrcType = QM_4K2K_YUV422_DS_UFSC;//4K2K_YUV422_DS
                }
                else
                {
                    u16SrcType = QM_4K2K_YUV422_UFSC; //4K2K_YUV422
                }
            }
            else
            {
                if( MApi_XC_GetDynamicScalingStatus())
                {
                    u16SrcType = QM_4K2K_YUV444_DS_UFSC;//4K2K_YUV444_DS
                }
                else
                {
                    u16SrcType = QM_4K2K_YUV444_UFSC; //4K2K_YUV444
                }
            }
        }
    }
    else
    {
#if(ENABLE_PQ_UFSC_BYPASS)
    #if (PQ_QM_DTV)
        if((QM_IsSourceDTV(enInputSourceType)) && (QM_IsDTV_IFRAME(eWindow)))
        {
            u16SrcType = QM_FHD_PQBypass_UFSC; //QM_FHD_PQBypass_UFSC
        }
        else
    #endif
#endif
        {
            if (bRGB444)
            {
                if( MApi_XC_GetDynamicScalingStatus())
                {
                    u16SrcType = QM_FHD_RGB444_DS_UFSC; //FHD_RGB444_DS
                }
                else
                {
                    u16SrcType = QM_FHD_RGB444_UFSC; //FHD_RGB444
                }
            }
            else if (bYUV422)
            {
                if( MApi_XC_GetDynamicScalingStatus())
                {
                    u16SrcType = QM_FHD_YUV422_DS_UFSC; //FHD_YUV422_DS
                }
                else
                {
                    u16SrcType = QM_FHD_YUV422_UFSC; //FHD_YUV422
                }
            }
            else
            {
                if( MApi_XC_GetDynamicScalingStatus())
                {
                    u16SrcType = QM_FHD_YUV444_DS_UFSC; //FHD_YUV444_DS
                }
                else
                {
                    u16SrcType = QM_FHD_YUV444_UFSC; //FHD_YUV444
                }
            }
        }
    }
    printf("[Load UFSC PQ] Source index=%d\n", u16SrcType);
#endif
    return u16SrcType;
}
#if (ENABLE_PQ_BIN_CF)
MS_U16 QM_InputSourceToIndex_CF(void* pInstance,PQ_WIN eWindow, MS_U8 enInputSourceType)
{
    MS_U16 u16SrcType = 0;

#if (CFD_STATUS_VERSION >=2)
    XC_CFD_STATUS stCfdStatus;
    memset(&stCfdStatus, 0, sizeof(XC_CFD_STATUS));
    stCfdStatus.u32Version=CFD_STATUS_VERSION;
    stCfdStatus.u16Length=sizeof(XC_CFD_STATUS);
    stCfdStatus.u8Win=eWindow;

     XC_CFD_CONTROL_INFO stCfdCtrlInfo;
     memset(&stCfdCtrlInfo, 0, sizeof(XC_CFD_CONTROL_INFO));
     stCfdCtrlInfo.enCtrlType = E_XC_CFD_CTRL_TYPE_STATUS;
     stCfdCtrlInfo.pParam = &stCfdStatus;
     stCfdCtrlInfo.u32ParamLen = sizeof(XC_CFD_STATUS);
     MApi_XC_HDR_Control(E_XC_HDR_CTRL_CFD_CONTROL, &stCfdCtrlInfo);

    u16SrcType=stCfdStatus.u8ColorType;
    printf("[Load CF PQ] Source index=%d\n", u16SrcType);
#else
    PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Wrong Color format type, Please check CFD_STATUS_VERSION\n");
#endif
    return u16SrcType;
}
#endif

MS_U16 QM_InputSourceToIndex_TMO(void* pInstance, PQ_WIN eWindow, MS_U8 enInputSourceType)
{
    MS_U16 u16SrcType = 0;
#if (CFD_STATUS_VERSION >=2)
    XC_CFD_STATUS stCfdStatus;
    memset(&stCfdStatus, 0, sizeof(XC_CFD_STATUS));
    stCfdStatus.u32Version=CFD_STATUS_VERSION;
    stCfdStatus.u16Length=sizeof(XC_CFD_STATUS);
    stCfdStatus.u8Win=eWindow;
#if (ENABLE_PQ_BIN_TMO)
    XC_CFD_CONTROL_INFO stCfdCtrlInfo;
    memset(&stCfdCtrlInfo, 0, sizeof(XC_CFD_CONTROL_INFO));
    stCfdCtrlInfo.enCtrlType = E_XC_CFD_CTRL_TYPE_STATUS;
    stCfdCtrlInfo.pParam = &stCfdStatus;
    stCfdCtrlInfo.u32ParamLen = sizeof(XC_CFD_STATUS);
    MApi_XC_HDR_Control(E_XC_HDR_CTRL_CFD_CONTROL, &stCfdCtrlInfo);

    u16SrcType=stCfdStatus.u8TMOColorType;
#endif

#else
    PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Wrong Color format type, Please check CFD_STATUS_VERSION\n");
#endif
    return u16SrcType;
}

#if (ENABLE_PQ_BIN_HSY)
MS_BOOL QM_InputSourceToIndex_HSY(PQ_WIN eWindow, MS_U8 enInputSourceType, MS_U32 *pu32label)
{
    if(NULL == pu32label)
    {
        PQ_LEVEL_PRINTF((PQ_DBG_ERROR|PQ_DBG_HSY),"\033[1;32m pu32label is NULL!\033[m\n");
        return FALSE;
    }

    MS_U16 u16Input_HSize = QM_GetInputHSize(eWindow);
    MS_U16 u16Input_VSize = QM_GetInputVSize(eWindow);
    MS_U16 u16Input_VFreq = QM_GetInputVFreq(eWindow);
    MS_BOOL bIsInterlaced = QM_IsInterlaced(eWindow);
    MS_BOOL bReturn = TRUE;
    MS_U32 label[LEN_CONFIG] = {0};

    XC_ApiStatusEx stXCStatusEx;

    memset(&stXCStatusEx, 0, sizeof(XC_ApiStatusEx));
    stXCStatusEx.u16ApiStatusEX_Length = sizeof(XC_ApiStatusEx);
    stXCStatusEx.u32ApiStatusEx_Version = API_STATUS_EX_VERSION;

    if(MApi_XC_GetStatusEx(&stXCStatusEx,MDrv_PQ_PQtoSC_WinMapping(eWindow)) == sizeof(XC_ApiStatusEx))
    {
        if(stXCStatusEx.bHDuplicate)
        {
            u16Input_HSize = u16Input_HSize/2;
        }
    }

    //SDR/HDR
    XC_CFD_STATUS stCfdStatus;
    memset(&stCfdStatus, 0, sizeof(XC_CFD_STATUS));
    stCfdStatus.u32Version=CFD_STATUS_VERSION;
    stCfdStatus.u16Length=sizeof(XC_CFD_STATUS);
    stCfdStatus.u8Win=eWindow;
    XC_CFD_CONTROL_INFO stCfdCtrlInfo;
    memset(&stCfdCtrlInfo, 0, sizeof(XC_CFD_CONTROL_INFO));
    stCfdCtrlInfo.enCtrlType = E_XC_CFD_CTRL_TYPE_STATUS;
    stCfdCtrlInfo.pParam = &stCfdStatus;
    stCfdCtrlInfo.u32ParamLen = sizeof(XC_CFD_STATUS);
    MApi_XC_HDR_Control(E_XC_HDR_CTRL_CFD_CONTROL, &stCfdCtrlInfo);

    //  Source
    if(QM_IsSourceHDMI(enInputSourceType))
    {
        SET_SOURCE(label, SOURCE_HDMI);
    }
    else if(QM_IsSourceAV(enInputSourceType))
    {
        SET_SOURCE(label, SOURCE_AV);
    }
    else if(QM_IsSourceATV(enInputSourceType))
    {
        SET_SOURCE(label, SOURCE_ATV);
    }
    else if(QM_IsSourceDTV(enInputSourceType))
    {
        SET_SOURCE(label, SOURCE_DTV);
    }
    else if(QM_IsSourceScart(enInputSourceType))
    {
        SET_SOURCE(label, SOURCE_SCART);
    }
    else if(QM_IsSourceVGA(enInputSourceType))
    {
        SET_SOURCE(label, SOURCE_PC);
    }
    else if(QM_IsSourceDVI_HDMIPC(enInputSourceType,eWindow)) //DVI
    {
        SET_SOURCE(label, SOURCE_DVI);
    }
    else if(IsSourceMultiMediaMovieMode(eWindow, enInputSourceType))
    {
        SET_SOURCE(label, SOURCE_MM_VIDEO);
    }
    else if(IsSourceMultiMediaPhotoMode(eWindow, enInputSourceType))
    {
        SET_SOURCE(label, SOURCE_MM_PHOTO);
    }
    else if(QM_IsSourceYPbPr(enInputSourceType))
    {
        SET_SOURCE(label, SOURCE_YPBPR);
    }
    else if(IsSourceMultiMediaStreamingMode(eWindow, enInputSourceType))
    {
        SET_SOURCE(label, SOURCE_MM_ONLINE);
    }
    else
    {
        bReturn = FALSE;
    }

    //  Interlaced
    if(bIsInterlaced)
    {
        SET_SCANNING(label, SCANNING_INTERLACED);
    }
    else
    {
        SET_SCANNING(label, SCANNING_PROGRESSIVE);
    }

    //  Input Size
    if(QM_ISATVStandard_NTSC(eWindow) && (QM_IsSourceAV(enInputSourceType) || QM_IsSourceATV(enInputSourceType)))
    {
        SET_RESOLUTION(label, RESOLUTION_480);
    }
    else if(QM_ISATVStandard_PAL(eWindow) && (QM_IsSourceAV(enInputSourceType) || QM_IsSourceATV(enInputSourceType)))
    {
        SET_RESOLUTION(label, RESOLUTION_576);
    }
    else if ((u16Input_HSize < 800) && (u16Input_VSize < 500))
    {
        SET_RESOLUTION(label, RESOLUTION_480);
    }
    else if((u16Input_HSize < 800) && (u16Input_VSize < 600))
    {
        SET_RESOLUTION(label, RESOLUTION_576);
    }
    else if((u16Input_HSize < 1300) && (u16Input_VSize < 800))
    {
        SET_RESOLUTION(label, RESOLUTION_720);
    }
    else if((u16Input_HSize < 1930) && (u16Input_VSize < 1090))
    {
        SET_RESOLUTION(label, RESOLUTION_1080);
    }
    else if((u16Input_HSize < 3900) && (u16Input_VSize < 2200))
    {
        SET_RESOLUTION(label, RESOLUTION_4K2K);
    }
    else
    {
        SET_RESOLUTION(label, RESOLUTION_8K4K);
    }

    //  Input VFreq
    if(u16Input_VFreq < 280)
    {
        SET_FRAME_RATE(label, FRAME_RATE_24);
    }
    else if(u16Input_VFreq < 350)
    {
        SET_FRAME_RATE(label, FRAME_RATE_30);
    }
    else if(u16Input_VFreq < 550)
    {
        SET_FRAME_RATE(label, FRAME_RATE_50);
    }
    else if(u16Input_VFreq < 650)
    {
        SET_FRAME_RATE(label, FRAME_RATE_60);
    }
    else if(u16Input_VFreq < 1250)
    {
        SET_FRAME_RATE(label, FRAME_RATE_120);
    }
    else if(u16Input_VFreq < 1500)
    {
        SET_FRAME_RATE(label, FRAME_RATE_144);
    }
    else if(u16Input_VFreq < 2500)
    {
        SET_FRAME_RATE(label, FRAME_RATE_240);
    }
    else
    {
        bReturn = FALSE;
    }

    //  HDR
    if(stCfdStatus.u8VideoHdrType == 0)
    {
        SET_HDR_SDR(label, HDR_SDR_SDR);
    }
    else if(stCfdStatus.u8VideoHdrType == BIT(1))
    {
        SET_HDR_SDR(label, HDR_SDR_HDR);
    }
    else if(stCfdStatus.u8VideoHdrType == BIT(3))
    {
        SET_HDR_SDR(label, HDR_SDR_HLG);
    }
    else if(stCfdStatus.u8VideoHdrType == BIT(0))
    {
        SET_HDR_SDR(label, HDR_SDR_DOLBY);
    }
    else if(stCfdStatus.u8VideoHdrType == BIT(2))
    {
        SET_HDR_SDR(label, HDR_SDR_TECHNICOLOR);
    }
    else
    {
        bReturn = FALSE;
    }

    //Color Space
    if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_BT_709)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_BT_709);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_SRGB)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_SRGB);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_DOLBY)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_DOLBY);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_XVYCC)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_XVYCC);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_BT_470_6)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_BT_470_6);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_BT_601_625)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_BT_601_625);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_PAL)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_PAL);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_SECAM)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_SECAM);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_BT_601_525)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_BT_601_525);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_NTSC)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_NTSC);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_SMPTE_170M)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_SMPTE_170M);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_SMPTE_240M)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_SMPTE_240M);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_GENERIC_FILM)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_GENERIC_FILM);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_BT2020_CL)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_BT2020_CL);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_BT2020_NCL)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_BT2020_NCL);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_CIEXYZ)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_CIEXYZ);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_P3)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_P3);
    }
    else if(stCfdStatus.u8ColorType == E_QM_COLOR_SPACE_ADOBERGB)
    {
        SET_COLOR_SPACE(label, COLOR_SPACE_ADOBERGB);
    }
    else
    {
        bReturn = FALSE;
    }

    PQ_LEVEL_PRINTF(PQ_DBG_HSY,"HSY Label=[%x %x]\n", label[0], label[1]);
    memcpy(pu32label, label, LEN_CONFIG*sizeof(MS_U32));

    return bReturn;
}
#endif

#if PQ_GRULE_OSD_BW_ENABLE
static void _MDrv_PQ_LoadOSD_BWTable(void* pInstance, PQ_WIN eWindow, MS_U16 u16PQ_OSD_BW_Idx)
{
    if(eWindow == PQ_MAIN_WINDOW)
    {
        MS_U16 u16Index=0, u16IPIdx = 0, u16TabIdx = 0;
        ST_PQ_IPInfo stGRuleIPInfo;
        ST_PQ_IPInfo stUpdatedGRuleIPInfo;
        memset(&stGRuleIPInfo, 0, sizeof(ST_PQ_IPInfo));
        memset(&stUpdatedGRuleIPInfo, 0, sizeof(ST_PQ_IPInfo));
        stGRuleIPInfo.u16IPIdx = PQ_GRule_OSD_BW_Main;
        stGRuleIPInfo.u16GruleMaxIPNum = PQ_GRULE_OSD_BW_IP_NUM_Main;
        stGRuleIPInfo.u16GruleLevelMainNum = PQ_GRULE_OSD_BW_NUM_Main;
        stGRuleIPInfo.enPQEngineType = PQ_XC0_STD;
        MHal_PQ_RemappingGruleIP(pInstance, stGRuleIPInfo, &stUpdatedGRuleIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
        if(MHal_PQ_Support_GroupIPBIN())
        {
            if(stUpdatedGRuleIPInfo.enPQEngineType == PQ_XC0_STD)
            {
                MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,stUpdatedGRuleIPInfo.u16IPIdx,PQ_BIN_STD_MAIN ,&stUpdatedGRuleIPInfo.u16GruleLevelMainNum, &stUpdatedGRuleIPInfo.u16GruleMaxIPNum ,&stPQBinHeaderInfo[PQ_BIN_STD_MAIN]);
            }
            else
            {
                MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,stUpdatedGRuleIPInfo.u16IPIdx,PQ_BIN_EXT_MAIN ,&stUpdatedGRuleIPInfo.u16GruleLevelMainNum, &stUpdatedGRuleIPInfo.u16GruleMaxIPNum ,&stPQBinHeaderInfo[PQ_BIN_EXT_MAIN]);
            }
        }
        if(u16PQ_OSD_BW_Idx > stUpdatedGRuleIPInfo.u16GruleLevelMainNum)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",u16PQ_OSD_BW_Idx,(stUpdatedGRuleIPInfo.u16GruleLevelMainNum-1));
            PQ_ASSERT(0);
            return;
        }

        for(u16Index = 0; u16Index < stUpdatedGRuleIPInfo.u16GruleMaxIPNum; u16Index++)
        {
            u16IPIdx = MDrv_PQ_GetGRule_IPIndex_Ex_U2(pInstance, eWindow, stUpdatedGRuleIPInfo.u16IPIdx, u16Index, stUpdatedGRuleIPInfo.enPQEngineType);

            if(u16PQ_OSD_BW_Idx == stUpdatedGRuleIPInfo.u16GruleLevelMainNum)  // see it as default
            {
                u16TabIdx = MDrv_PQ_GetTableIndex_Ex_U2(pInstance,eWindow, u16IPIdx, stUpdatedGRuleIPInfo.enPQEngineType);
            }
            else
            {
                u16TabIdx = MDrv_PQ_GetGRule_TableIndex_Ex(eWindow, stUpdatedGRuleIPInfo.u16IPIdx, u16PQ_OSD_BW_Idx, u16Index, stUpdatedGRuleIPInfo.enPQEngineType);
            }

            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[NR]SRC: %u, NR: %u, NRIPIdx:%u, IPIdx:%u, u8TabIdx:%u\n",
                               _u16PQSrcType[eWindow], u16PQ_OSD_BW_Idx, u16Index, u16IPIdx, u16IPIdx);

            MDrv_PQ_LoadTable_Ex_U2(pInstance, eWindow, u16TabIdx, u16IPIdx, stUpdatedGRuleIPInfo.enPQEngineType);
        }
    }
    else
    {
        UNUSED(pInstance);
        UNUSED(u16PQ_OSD_BW_Idx);
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[PQ] Sub Window not support OSD BW Table\n");
    }
}


void MDrv_PQ_LoadOSD_BWTable(void* pInstance, PQ_WIN eWindow, PQ_OSD_BW_FUNCTION_TYPE enOSD_BW_Type)
{
    if(eWindow == PQ_MAIN_WINDOW)
    {
        MS_U16 u16PQ_NRIdx;
        if(enOSD_BW_Type == PQ_OSD_BW_ON)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"On\n");

#if (PQ_OSD_BW_VER == 1)
#if PQ_GRULE_DDR_SELECT_ENABLE
            if(bw_info.u32Miu1MemSize == 0)
            {
                u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_1DDR_On_Main);
                _MDrv_PQ_LoadOSD_BWTable(pInstance, eWindow, u16PQ_NRIdx);
            }
            else
            {
                u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_2DDR_On_Main);
                _MDrv_PQ_LoadOSD_BWTable(pInstance, eWindow, u16PQ_NRIdx);
            }
#else
            u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_On_Main);
            _MDrv_PQ_LoadOSD_BWTable(pInstance, eWindow, u16PQ_NRIdx);
#endif
#elif (PQ_OSD_BW_VER == 2)
#if PQ_GRULE_DDR_SELECT_ENABLE
            if(bw_info.bDDR2 == FALSE) // DDR 3
            {
                 if(MApi_XC_GetMirrorModeTypeEx(MAIN_WINDOW) != MIRROR_NORMAL)
                 {
                     PQMADi_DBG(printf("MDrv_PQ_GetMADiFromGrule_OSDBW_Ver2: DDR3 mirror\n"));
                     u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_On_DDR3_Mirror_Main);
                     _MDrv_PQ_LoadOSD_BWTable(pInstance, eWindow, u16PQ_NRIdx);
                 }
                 else
                 {
                     PQMADi_DBG(printf("MDrv_PQ_GetMADiFromGrule_OSDBW_Ver2: DDR3 non-mirror\n"));
                     u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_On_DDR3_Main);
                     _MDrv_PQ_LoadOSD_BWTable(pInstance, eWindow, u16PQ_NRIdx);
                 }
            }
            else // DDR 2
            {
                 if(MApi_XC_GetMirrorModeTypeEx(MAIN_WINDOW) != MIRROR_NORMAL)
                 {
                     PQMADi_DBG(printf("MDrv_PQ_GetMADiFromGrule_OSDBW_Ver2: DDR2 mirror\n"));
                     u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_On_DDR2_Mirror_Main);
                     _MDrv_PQ_LoadOSD_BWTable(pInstance, eWindow, u16PQ_NRIdx);
                 }
                 else
                 {
                     PQMADi_DBG(printf("MDrv_PQ_GetMADiFromGrule_OSDBW_Ver2: DDR2 non-mirror\n"));
                     u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_On_DDR2_Main);
                     _MDrv_PQ_LoadOSD_BWTable(pInstance, eWindow, u16PQ_NRIdx);
                 }
            }
#endif
#endif
        }
        else
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"ASSERT!!!");
            PQ_ASSERT(0);
        }
    }
    else
    {
        UNUSED(pInstance);
        UNUSED(enOSD_BW_Type);
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[PQ] Sub Window not support OSD BW Table\n");
    }
}
#endif

#if PQ_GRULE_FILM_MODE_ENABLE
static void _MDrv_PQ_LoadFilmModeTable(void* pInstance, PQ_WIN eWindow, MS_U16 u16PQ_FilmModeIdx)
{
    if(eWindow == PQ_MAIN_WINDOW)
    {
        MS_U16 u16Index =0, u16IPIdx = 0, u16TabIdx = 0;
        MS_U16 u16GroupNum = 0;
        MS_U16 u16IPNum = 0;

        if(MHal_PQ_Support_GroupIPBIN())
        {
            MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,PQ_GRule_FILM_MODE_Main,PQ_BIN_STD_MAIN ,&u16GroupNum, &u16IPNum ,&stPQBinHeaderInfo[PQ_BIN_STD_MAIN]);
        }
        else
        {
            u16GroupNum = PQ_GRULE_FILM_MODE_NUM_Main;
            u16IPNum = PQ_GRULE_FILM_MODE_IP_NUM_Main;
        }
        if(u16PQ_FilmModeIdx > u16GroupNum)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",u16PQ_FilmModeIdx,(u16GroupNum-1));
            PQ_ASSERT(0);
            return;
        }
        for(u16Index = 0; u16Index < u16IPNum; u16Index++)
        {
            u16IPIdx = MDrv_PQ_GetGRule_IPIndex_U2(pInstance, eWindow, PQ_GRule_FILM_MODE_Main, u16Index);
            if(u16PQ_FilmModeIdx == u16GroupNum)  // see it as default
            {
                u16TabIdx = MDrv_PQ_GetTableIndex_U2(pInstance,eWindow, u16TabIdx);
            }
            else
            {
                u16TabIdx = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_FILM_MODE_Main, u16PQ_FilmModeIdx, u16Index);
            }
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[FM]SRC: %u, FM: %u, FMIPIdx:%u, IPIdx:%u, u16TabIdx:%u\n",
                               _u16PQSrcType[eWindow], u16PQ_FilmModeIdx, u16Index, u16IPIdx, u16TabIdx);
            MDrv_PQ_LoadTable_U2(pInstance, eWindow, u16TabIdx, u16IPIdx);
        }
    }
    else
    {
        UNUSED(pInstance);
        UNUSED(u16PQ_FilmModeIdx);
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[PQ] Sub Window not support Flim mode Table\n");
    }
}
#endif


void MDrv_PQ_LoadFilmModeTable_U2(void* pInstance,PQ_WIN eWindow, PQ_FILM_MODE_FUNCTION_TYPE enFilmModeType)
{
    if(eWindow == PQ_MAIN_WINDOW)
    {
#if PQ_GRULE_FILM_MODE_ENABLE
        MS_U16 u16PQ_FilmModeIdx;

#ifdef MSOS_TYPE_LINUX_KERNEL
        _eFilmModeType[eWindow] = enFilmModeType;
#endif
        if(enFilmModeType == PQ_FilmMode_OFF)
        {
            u16PQ_FilmModeIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_FILM_MODE_Main, PQ_GRule_FILM_MODE_Off_Main);
            _MDrv_PQ_LoadFilmModeTable(pInstance, eWindow, u16PQ_FilmModeIdx);
        }
        else if(enFilmModeType == PQ_FilmMode_ON)
        {
            u16PQ_FilmModeIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_FILM_MODE_Main, PQ_GRule_FILM_MODE_On_Main);
            _MDrv_PQ_LoadFilmModeTable(pInstance, eWindow, u16PQ_FilmModeIdx);
        }
        else
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",enFilmModeType,(PQ_FilmMode_NUM-1));
            PQ_ASSERT(0);
        }
#endif
    }
    else
    {
        UNUSED(pInstance);
        UNUSED(enFilmModeType);
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[PQ] Sub Window not support Flim mode Table\n");
    }


}
void SYMBOL_WEAK MDrv_PQ_LoadFilmModeTable(PQ_WIN eWindow, PQ_FILM_MODE_FUNCTION_TYPE enFilmModeType)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return ;
    }

    stPQ_LoadFilmModeTable PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.enFilmModeType = enFilmModeType;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_LOAD_FILMMODE_TABLE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}

#if PQ_GRULE_DYNAMIC_CONTRAST_ENABLE
static void _MDrv_PQ_DynamicContrastTable(void* pInstance, PQ_WIN eWindow, MS_U16 u16PQ_DynContrIdx)
{
    PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Window[%u] u16PQ_DynContrIdx is %u\n",eWindow,u16PQ_DynContrIdx);
    if(eWindow == PQ_MAIN_WINDOW)
    {
        MS_U16 u16Index=0, u16IPIdx = 0, u16TabIdx = 0;
        MS_U16 u16GroupNum = 0;
        MS_U16 u16IPNum = 0;

        if(MHal_PQ_Support_GroupIPBIN())
        {
            MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,PQ_GRule_DYNAMIC_CONTRAST_Main,PQ_BIN_STD_MAIN ,&u16GroupNum, &u16IPNum ,&stPQBinHeaderInfo[PQ_BIN_STD_MAIN]);
        }
        else
        {
            u16GroupNum = PQ_GRULE_DYNAMIC_CONTRAST_NUM_Main;
            u16IPNum = PQ_GRULE_DYNAMIC_CONTRAST_IP_NUM_Main;
        }
        if(u16PQ_DynContrIdx > u16GroupNum)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",u16PQ_DynContrIdx,(u16GroupNum-1));
            PQ_ASSERT(0);
            return;
        }
        for(u16Index = 0; u16Index < u16IPNum; u16Index++)
        {
            u16IPIdx = MDrv_PQ_GetGRule_IPIndex_U2(pInstance, eWindow, PQ_GRule_DYNAMIC_CONTRAST_Main, u16Index);
#if PQ_DLC_CTL_FOR_MVC4KX1K
            if((_gIsMVC4kx1k == TRUE) && (u16IPIdx == PQ_IP_VIP_DLC_Main))
            {
                PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"[Grule-DynamicContrast] cannot load DLC table for MVC4kx1k\n");
                continue;
            }
#endif
            if(u16PQ_DynContrIdx == u16GroupNum)  // see it as default
            {
                u16TabIdx = MDrv_PQ_GetTableIndex_U2(pInstance,eWindow, u16TabIdx);
            }
            else
            {
                u16TabIdx = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_DYNAMIC_CONTRAST_Main, u16PQ_DynContrIdx, u16Index);
            }
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[DC]SRC: %u, DC: %u, DCIPIdx:%u, IPIdx:%u, u16TabIdx:%u\n",
                               _u16PQSrcType[eWindow], u16PQ_DynContrIdx, u16Index, u16IPIdx, u16TabIdx);
            MDrv_PQ_LoadTable_U2(pInstance, eWindow, u16TabIdx, u16IPIdx);
        }
    }
    else
    {
        UNUSED(pInstance);
        UNUSED(u16PQ_DynContrIdx);
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[PQ] Sub Window not support Dynamic Contrast Table\n");
    }
}
#endif

void MDrv_PQ_LoadDynamicContrastTable_U2(void* pInstance,PQ_WIN eWindow, PQ_DYNAMIC_CONTRAST_FUNCTION_TYPE enDynamicContrastType)
{
    PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Window[%u] enDynamicContrastType is %u\n",eWindow,enDynamicContrastType);
    if(eWindow == PQ_MAIN_WINDOW)
    {
#if ((ENABLE_PQ_BIN_TMO==1) && (PQ_SWDR_VR==1))
    if(  (PQ_DynContr_OFF == MDrv_PQ_GetDLCModeStatus(eWindow))
        &&   (E_PQ_SWDR_OFF == MDrv_PQ_GetSWDRModeStatus(eWindow)) )
    {
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Set MDrv_PQ_LoadSWDRModeGRuleTable SWDR & DLC OFF\n");
        MDrv_PQ_LoadSWDRModeGRuleTable(eWindow, E_PQ_SWDR_DLC_OFF);
    }
#endif

#if PQ_GRULE_DYNAMIC_CONTRAST_ENABLE
        MS_U16 u16PQ_DynContrIdx;

#ifdef MSOS_TYPE_LINUX_KERNEL
        _eDynamicContrastType[eWindow] = enDynamicContrastType;
#endif
        if(enDynamicContrastType == PQ_DynContr_OFF)
        {
            u16PQ_DynContrIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_DYNAMIC_CONTRAST_Main, PQ_GRule_DYNAMIC_CONTRAST_Off_Main);
            _MDrv_PQ_DynamicContrastTable(pInstance, eWindow, u16PQ_DynContrIdx);
        }
        else if(enDynamicContrastType == PQ_DynContr_ON)
        {
            u16PQ_DynContrIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_DYNAMIC_CONTRAST_Main, PQ_GRule_DYNAMIC_CONTRAST_On_Main);
            _MDrv_PQ_DynamicContrastTable(pInstance, eWindow, u16PQ_DynContrIdx);
        }
        else
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",enDynamicContrastType,(PQ_DynContr_NUM-1));
            PQ_ASSERT(0);
        }
#endif
    }
    else
    {
        UNUSED(pInstance);
        UNUSED(enDynamicContrastType);
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[PQ] Sub Window not support Dynamic Contrast Table\n");
    }

}
void SYMBOL_WEAK MDrv_PQ_LoadDynamicContrastTable(PQ_WIN eWindow, PQ_DYNAMIC_CONTRAST_FUNCTION_TYPE enDynamicContrastType)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return ;
    }

    stPQ_LoadDynamicContrastTable PQArgs;
    PQArgs.eWindow =eWindow;
    PQArgs.enDynamicContrastType = enDynamicContrastType;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_LOAD_DYNAMIC_CONTRAST_TABLE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}

MS_BOOL MDrv_PQ_SetDLCModeStatus_U2(void* pInstance, PQ_WIN enWindow , PQ_DYNAMIC_CONTRAST_FUNCTION_TYPE enDynamicContrastType)
{
    if (enWindow >= PQ_MAX_WINDOW)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Unsupport Window[%u]\n",enWindow);
        return FALSE;
    }
    else
    {
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Window[%u] enDynamicContrastType is %u\n",enWindow,enDynamicContrastType);
        _enDLCModeOn[enWindow] = enDynamicContrastType;
        return TRUE;
    }
}

MS_BOOL SYMBOL_WEAK MDrv_PQ_SetDLCModeStatus(PQ_WIN eWindow, PQ_DYNAMIC_CONTRAST_FUNCTION_TYPE enDynamicContrastType)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_DLCModeStatus PQArgs;
    PQArgs.enWindow = eWindow;
    PQArgs.enDynamicContrastType= enDynamicContrastType;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SET_DLC_MODE_STATUS, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}

PQ_DYNAMIC_CONTRAST_FUNCTION_TYPE MDrv_PQ_GetDLCModeStatus_U2(void* pInstance, PQ_WIN enWindow)
{
    if (enWindow >= PQ_MAX_WINDOW)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Unsupport Window[%u]\n",enWindow);
        return PQ_DynContr_OFF;
    }
    else
    {
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Window[%u] _enDLCModeOn is %u\n",enWindow,_enDLCModeOn[enWindow]);
        return _enDLCModeOn[enWindow];
    }
}

PQ_DYNAMIC_CONTRAST_FUNCTION_TYPE SYMBOL_WEAK MDrv_PQ_GetDLCModeStatus(PQ_WIN eWindow)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return PQ_DynContr_NUM;
    }
    stPQ_DLCModeStatus PQArgs;
    PQArgs.enWindow = eWindow;
    PQArgs.enDynamicContrastType= PQ_DynContr_NUM;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_GET_DLC_MODE_STATUS, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return PQ_DynContr_NUM;
    }
    else
    {
        return PQArgs.enDynamicContrastType;
    }
}

#if PQ_GRULE_NR_ENABLE
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE || (ENABLE_PQ_CUSTOMER_BIN_SUB_GRULE && PQ_ENABLE_PIP)
static void _MDrv_PQ_LoadCustomerNRTable(void* pInstance, PQ_WIN eWindow, MS_U16 u16PQ_NRIdx)
{
    MS_U16 u16Index=0, u16IPIdx = 0, u16TabIdx = 0;
    MS_U16 u16GroupNum = 0;
    MS_U16 u16IPNum = 0;
    if(MHal_PQ_Support_GroupIPBIN())
    {
        MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,PQ_GRule_NR_Main_Color,PQ_BIN_CUSTOMER_MAIN ,&u16GroupNum, &u16IPNum ,&stPQBinHeaderInfo[PQ_BIN_CUSTOMER_MAIN]);
    }
    else
    {
        u16GroupNum = PQ_GRULE_NR_NUM_Main_Color;
        u16IPNum = PQ_GRULE_NR_IP_NUM_Main_Color;
    }
    // follow setgrulestatus, only load big pq or small pq, not both
    if ((eWindow == PQ_MAIN_WINDOW) && _bCustomerMainPQEn)
    {
        if(u16PQ_NRIdx > u16GroupNum)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",u16PQ_NRIdx,(u16GroupNum-1));
            PQ_ASSERT(0);
            return;
        }
        for(u16Index = 0; u16Index < u16IPNum; u16Index++)
        {
            u16IPIdx = MDrv_PQ_GetCustomerGRule_IPIndex(eWindow, PQ_GRule_NR_Main_Color, u16Index);
            if(u16PQ_NRIdx == u16GroupNum)
            {
                u16TabIdx = MDrv_PQ_GetCustomerTableIndex(eWindow, u16IPIdx);
            }
            else
            {
                u16TabIdx = MDrv_PQ_GetGRule_CustomerTableIndex(eWindow, PQ_GRule_NR_Main_Color, u16PQ_NRIdx, u16Index);
            }
            MDrv_PQ_LoadCustomerTable(eWindow, u16TabIdx, u16IPIdx);
        }
    }
#if (ENABLE_PQ_CUSTOMER_BIN_SUB_GRULE && PQ_ENABLE_PIP)
    else if ((eWindow == PQ_SUB_WINDOW) && _bCustomerSubPQEn)
    {
        u16GroupNum = PQ_GRULE_NR_NUM_Sub_Color;
        u16IPNum = PQ_GRULE_NR_IP_NUM_Sub_Color;
        if(MHal_PQ_Support_GroupIPBIN())
        {
            MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,PQ_GRule_NR_Sub_Color,PQ_BIN_CUSTOMER_SUB ,&u16GroupNum, &u16IPNum ,&stPQBinHeaderInfo[PQ_BIN_CUSTOMER_SUB]);
        }
        if(u16PQ_NRIdx > u16GroupNum)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",u16PQ_NRIdx,(u16GroupNum-1));
            PQ_ASSERT(0);
            return;
        }
        for(u16Index = 0; u16Index < u16IPNum; u16Index++)
        {
            u16IPIdx = MDrv_PQ_GetCustomerGRule_IPIndex(eWindow, PQ_GRule_NR_Sub_Color, u16Index);
            if(u16PQ_NRIdx == u16GroupNum)
            {
                u16TabIdx = MDrv_PQ_GetCustomerTableIndex(eWindow, u16IPIdx);
            }
            else
            {
                u16TabIdx = MDrv_PQ_GetGRule_CustomerTableIndex(eWindow, PQ_GRule_NR_Sub_Color, u16PQ_NRIdx, u16Index);
            }
            MDrv_PQ_LoadCustomerTable(eWindow, u16TabIdx, u16IPIdx);
        }
    }
#endif
    else
    {
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[NR] CUSTOMER PQ Not support case \n");
    }

}
#endif
#endif

#if PQ_GRULE_NR_ENABLE
static void _MDrv_PQ_LoadNRTable(void* pInstance, PQ_WIN eWindow, MS_U16 u16PQ_NRIdx)
{
    MS_U16 u16Index =0, u16IPIdx = 0, u16TabIdx = 0;
    ST_PQ_IPInfo stGRuleIPInfo;
    ST_PQ_IPInfo stUpdatedGRuleIPInfo;
    memset(&stGRuleIPInfo, 0, sizeof(ST_PQ_IPInfo));
    memset(&stUpdatedGRuleIPInfo, 0, sizeof(ST_PQ_IPInfo));
    stGRuleIPInfo.u16IPIdx = PQ_GRule_NR_Main;
    stGRuleIPInfo.u16GruleMaxIPNum = PQ_GRULE_NR_IP_NUM_Main;
    stGRuleIPInfo.u16GruleLevelMainNum = PQ_GRULE_NR_NUM_Main;
    stGRuleIPInfo.enPQEngineType = PQ_XC0_STD;
    MHal_PQ_RemappingGruleIP(pInstance, stGRuleIPInfo, &stUpdatedGRuleIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
    if(MHal_PQ_Support_GroupIPBIN())
    {
        if(stUpdatedGRuleIPInfo.enPQEngineType == PQ_XC0_STD)
        {
            MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,stUpdatedGRuleIPInfo.u16IPIdx,PQ_BIN_STD_MAIN ,&stUpdatedGRuleIPInfo.u16GruleLevelMainNum, &stUpdatedGRuleIPInfo.u16GruleMaxIPNum ,&stPQBinHeaderInfo[PQ_BIN_STD_MAIN]);
        }
        else
        {
            MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,stUpdatedGRuleIPInfo.u16IPIdx,PQ_BIN_EXT_MAIN ,&stUpdatedGRuleIPInfo.u16GruleLevelMainNum, &stUpdatedGRuleIPInfo.u16GruleMaxIPNum ,&stPQBinHeaderInfo[PQ_BIN_EXT_MAIN]);
        }
    }

#if(ENABLE_PQ_MLOAD)
    MDrv_PQ_Set_MLoadEn(eWindow, TRUE);
#endif

    // follow setgrulestatus, only load big pq or small pq, not both
    if (eWindow == PQ_MAIN_WINDOW)
    {
        {
            if(u16PQ_NRIdx > stUpdatedGRuleIPInfo.u16GruleLevelMainNum)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",u16PQ_NRIdx,(stUpdatedGRuleIPInfo.u16GruleLevelMainNum-1));
                PQ_ASSERT(0);
                return;
            }

            for(u16Index = 0; u16Index < stUpdatedGRuleIPInfo.u16GruleMaxIPNum; u16Index++)
            {
                u16IPIdx = MDrv_PQ_GetGRule_IPIndex_Ex_U2(pInstance, eWindow, stUpdatedGRuleIPInfo.u16IPIdx, u16Index, stUpdatedGRuleIPInfo.enPQEngineType);
                if(u16PQ_NRIdx == stUpdatedGRuleIPInfo.u16GruleLevelMainNum)  // see it as default
                {
                    u16TabIdx = MDrv_PQ_GetTableIndex_Ex_U2(pInstance,eWindow, u16IPIdx, stUpdatedGRuleIPInfo.enPQEngineType);
                }
                else
                {
                    u16TabIdx = MDrv_PQ_GetGRule_TableIndex_Ex(eWindow, stUpdatedGRuleIPInfo.u16IPIdx, u16PQ_NRIdx, u16Index, stUpdatedGRuleIPInfo.enPQEngineType);
                }
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[NR]SRC: %u, NR: %u, NRIPIdx:%u, IPIdx:%u, u16TabIdx:%u\n",
                               _u16PQSrcType[eWindow], u16PQ_NRIdx, u16Index, u16IPIdx, u16TabIdx);
                MDrv_PQ_LoadTable_Ex_U2(pInstance, eWindow, u16TabIdx, u16IPIdx, stUpdatedGRuleIPInfo.enPQEngineType);
            }
        }
    }
#if PQ_ENABLE_PIP
    else if (eWindow == PQ_SUB_WINDOW)
    {
        stGRuleIPInfo.u16IPIdx = MHal_PQ_Get_GRuleIPIndex(eWindow, E_PQ_GRULE_IP_NR);
        stGRuleIPInfo.u16GruleMaxIPNum = MHal_PQ_Get_GRuleIPNum(eWindow, E_PQ_GRULE_IP_NR);
        stGRuleIPInfo.u16GruleLevelMainNum = MHal_PQ_Get_GRuleNum(eWindow, E_PQ_GRULE_IP_NR);
        stGRuleIPInfo.enPQEngineType = PQ_XC0_STD;
        MHal_PQ_RemappingGruleIP(pInstance, stGRuleIPInfo, &stUpdatedGRuleIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
        if(MHal_PQ_Support_GroupIPBIN())
        {
            if(stUpdatedGRuleIPInfo.enPQEngineType == PQ_XC0_STD)
            {
                MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,stUpdatedGRuleIPInfo.u16IPIdx,PQ_BIN_STD_SUB ,&stUpdatedGRuleIPInfo.u16GruleLevelMainNum, &stUpdatedGRuleIPInfo.u16GruleMaxIPNum ,&stPQBinHeaderInfo[PQ_BIN_STD_SUB]);
            }
            else
            {
                MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,stUpdatedGRuleIPInfo.u16IPIdx,PQ_BIN_EXT_SUB ,&stUpdatedGRuleIPInfo.u16GruleLevelMainNum, &stUpdatedGRuleIPInfo.u16GruleMaxIPNum ,&stPQBinHeaderInfo[PQ_BIN_EXT_SUB]);
            }
        }

        if(u16PQ_NRIdx >= stUpdatedGRuleIPInfo.u16GruleLevelMainNum)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",u16PQ_NRIdx,(stUpdatedGRuleIPInfo.u16GruleLevelMainNum-1));
            PQ_ASSERT(0);
            return;
        }

        for(u16Index = 0; u16Index < stUpdatedGRuleIPInfo.u16GruleMaxIPNum; u16Index++)
        {
            u16IPIdx = MDrv_PQ_GetGRule_IPIndex_Ex_U2(pInstance, eWindow, stUpdatedGRuleIPInfo.u16IPIdx, u16Index, stUpdatedGRuleIPInfo.enPQEngineType);
            if(u16PQ_NRIdx == stUpdatedGRuleIPInfo.u16GruleLevelMainNum)  // see it as default
            {
                u16TabIdx = MDrv_PQ_GetTableIndex_Ex_U2(pInstance,eWindow, u16IPIdx, stUpdatedGRuleIPInfo.enPQEngineType);
            }
            else
            {
                u16TabIdx = MDrv_PQ_GetGRule_TableIndex_Ex(eWindow, stUpdatedGRuleIPInfo.u16IPIdx, u16PQ_NRIdx, u16Index, stUpdatedGRuleIPInfo.enPQEngineType);
            }
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[NR]SRC: %u, NR: %u, NRIPIdx:%u, IPIdx:%u, u16TabIdx:%u\n",
                               _u16PQSrcType[eWindow], u16PQ_NRIdx, u16Index, u16IPIdx, u16TabIdx);
            MDrv_PQ_LoadTable_Ex_U2(pInstance, eWindow, u16TabIdx, u16IPIdx, stUpdatedGRuleIPInfo.enPQEngineType);
        }
    }
#endif
    else
    {
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[NR] Not support case \n");
    }

#if(ENABLE_PQ_MLOAD)
    MDrv_PQ_Set_MLoadEn(eWindow, FALSE);
#endif
}
#endif

void MDrv_PQ_LoadNRTable_U2(void* pInstance,PQ_WIN eWindow, PQ_3D_NR_FUNCTION_TYPE en3DNRType)
{
#if PQ_GRULE_NR_ENABLE
    MS_U16 u16PQ_NRIdx = PQ_GRule_NR_Off_Main;
    MS_U16 u16GRuleType = PQ_GRule_NR_Main;
    MS_U16 u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Off_Main;
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
    MS_U16 u16CustomerPQ_NRIdx = PQ_GRule_NR_Off_Main;
    MS_U16 u16CustomerGRuleType = PQ_GRule_NR_Main_Color;
    MS_U16 u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Off_Main_Color;
#endif
    MS_U32 u32SupportZNR = 0;
    ST_PQ_IPInfo stGRuleIPInfo;
    ST_PQ_IPInfo stUpdatedGRuleIPInfo;
    memset(&stGRuleIPInfo, 0, sizeof(ST_PQ_IPInfo));
    memset(&stUpdatedGRuleIPInfo, 0, sizeof(ST_PQ_IPInfo));
    stGRuleIPInfo.u16IPIdx = PQ_GRule_NR_Main;
    stGRuleIPInfo.u16GruleLevelMain = PQ_GRule_NR_Off_Main;
    stGRuleIPInfo.u16GruleLevel = PQ_GRule_Lvl_NR_Off_Main;

    // FBL not support DNR but support ZNR if HW supported
    // NR off : FBL + HW not support ZNR
    MApi_XC_GetChipCaps(E_XC_SUPPORT_ZNR, &u32SupportZNR, sizeof(MS_U32));
    if(_MDrv_PQ_IsFBLMode(pInstance, eWindow) && (u32SupportZNR == 0))
    {
        en3DNRType = PQ_3D_NR_OFF;
    }

#ifdef MSOS_TYPE_LINUX_KERNEL
    _e3DNRType[eWindow] = en3DNRType;
#endif
    if (eWindow == PQ_MAIN_WINDOW)
    {
        u16GRuleType = PQ_GRule_NR_Main;

        if(en3DNRType == PQ_3D_NR_DEFAULT)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Default\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
            if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
            {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                u16CustomerPQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_Ex_U2(pInstance, eWindow, u16CustomerGRuleType, PQ_GRule_Lvl_NR_Low_3D_Main_Color,PQ_XC0_CUSTOMER);
#endif
                u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, u16GRuleType, PQ_GRule_Lvl_NR_Low_3D_Main);
            }
            else
#endif
            {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                u16CustomerPQ_NRIdx = PQ_GRULE_NR_NUM_Main_Color;
#endif
                u16PQ_NRIdx = PQ_GRULE_NR_NUM_Main;
            }
        }
        else
        {
            if(en3DNRType == PQ_3D_NR_OFF)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Off\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Off_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Off_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Off_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Off_Main;
                }
            }
            else if(en3DNRType == PQ_3D_NR_AUTO)
            {
                // Auto NR will be process in msAPI_DynamicNR_Handler(), hence we only need to pre-setup the PQ table.
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Auto\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Low_3D_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Low_3D_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Low_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Low_Main;
                }
            }
            else if(en3DNRType == PQ_3D_NR_LOW)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Low\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Low_3D_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Low_3D_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Low_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Low_Main;
                }
            }
            else if(en3DNRType == PQ_3D_NR_MID)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Mid\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Middle_3D_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Middle_3D_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Middle_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Middle_Main;
                }
            }
            else if(en3DNRType == PQ_3D_NR_HIGH)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"High\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_High_3D_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_High_3D_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_High_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_High_Main;
                }
            }
#if (PQ_ENABLE_MULTI_LEVEL_AUTO_NR == 1)
            else if(en3DNRType == PQ_3D_NR_AUTO_LOW_L)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"AUTO_LOW_L\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Low_3D_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Low_3D_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_Low_L_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_Low_L_Main;
                }
            }
            else if(en3DNRType == PQ_3D_NR_AUTO_LOW_M)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"AUTO_LOW_M\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Low_3D_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Low_3D_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_Low_M_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_Low_M_Main;
                }
            }
            else if(en3DNRType == PQ_3D_NR_AUTO_LOW_H)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"AUTO_LOW_H\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Low_3D_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Low_3D_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_Low_H_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_Low_H_Main;
                }
            }
            else if(en3DNRType == PQ_3D_NR_AUTO_MID_L)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"AUTO_MID_L\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Middle_3D_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Middle_3D_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_Middle_L_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_Middle_L_Main;
                }
            }
            else if(en3DNRType == PQ_3D_NR_AUTO_MID_M)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"AUTO_MID_M\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Middle_3D_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Middle_3D_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_Middle_M_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_Middle_M_Main;
                }
            }
            else if(en3DNRType == PQ_3D_NR_AUTO_MID_H)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"AUTO_MID_H\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Middle_3D_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Middle_3D_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_Middle_H_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_Middle_H_Main;
                }
            }
            else if(en3DNRType == PQ_3D_NR_AUTO_HIGH_L)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"AUTO_HIGH_L\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_High_3D_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_High_3D_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_High_L_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_High_L_Main;
                }
            }
            else if(en3DNRType == PQ_3D_NR_AUTO_HIGH_M)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"AUTO_HIGH_M\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_High_3D_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_High_3D_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_High_M_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_High_M_Main;
                }
            }
            else if(en3DNRType == PQ_3D_NR_AUTO_HIGH_H)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"AUTO_HIGH_H\n");
#if (PQ_ENABLE_3D_STRENGTHEN_NR == 1)
                if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_High_3D_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_High_3D_Main;
                }
                else
#endif
                {
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
                    u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_High_H_Main_Color;
#endif
                    u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Auto_High_H_Main;
                }
            }
#endif
            else
            {
                PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",en3DNRType,(PQ_3D_NR_NUM-1));
                PQ_ASSERT(FALSE);
            }
            // Third parameter of MDrv_PQ_GetGRule_LevelIndex should be level index, not group index.
            stGRuleIPInfo.u16GruleLevel = u16GRuleLevelIndex;
            MHal_PQ_RemappingGruleIP(pInstance, stGRuleIPInfo, &stUpdatedGRuleIPInfo, TRUE);
            u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_Ex_U2(pInstance, eWindow, u16GRuleType, stUpdatedGRuleIPInfo.u16GruleLevel, stUpdatedGRuleIPInfo.enPQEngineType);
            stGRuleIPInfo.u16GruleLevelMain = u16PQ_NRIdx;
            MHal_PQ_RemappingGruleIP(pInstance, stGRuleIPInfo, &stUpdatedGRuleIPInfo, TRUE);
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
            u16CustomerPQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_Ex_U2(pInstance, eWindow, u16CustomerGRuleType, u16CustomerGRuleLevelIndex, PQ_XC0_CUSTOMER);
#endif
        }
        _MDrv_PQ_LoadNRTable(pInstance, eWindow, stUpdatedGRuleIPInfo.u16GruleLevelMain);
#if ENABLE_PQ_CUSTOMER_BIN_MAIN_GRULE
        _MDrv_PQ_LoadCustomerNRTable(pInstance, eWindow, u16CustomerPQ_NRIdx);
#endif
    }
#if PQ_ENABLE_PIP
    else if (eWindow == PQ_SUB_WINDOW)
    {
        memset(&stGRuleIPInfo, 0, sizeof(ST_PQ_IPInfo));
        stGRuleIPInfo.u16IPIdx = PQ_GRule_NR_Sub;
        stGRuleIPInfo.u16GruleLevelMain = PQ_GRule_NR_Off_Sub;
        stGRuleIPInfo.u16GruleLevel = PQ_GRule_Lvl_NR_Off_Sub;
#if ENABLE_PQ_CUSTOMER_BIN_SUB_GRULE
        u16CustomerGRuleType = PQ_GRule_NR_Sub_Color;
#endif
        u16GRuleType = PQ_GRule_NR_Sub;

        if(en3DNRType == PQ_3D_NR_DEFAULT)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Default\n");
#if ENABLE_PQ_CUSTOMER_BIN_SUB_GRULE
            u16CustomerPQ_NRIdx = PQ_GRULE_NR_NUM_Sub_Color;
#endif
            u16PQ_NRIdx = PQ_GRULE_NR_NUM_Sub;
        }
        else
        {
            if(en3DNRType == PQ_3D_NR_OFF)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Off\n");
#if ENABLE_PQ_CUSTOMER_BIN_SUB_GRULE
                u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Off_Sub_Color;
#endif
                u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Off_Sub;
            }
            else if(en3DNRType == PQ_3D_NR_AUTO)
            {
                // Auto NR will be process in msAPI_DynamicNR_Handler(), hence we only need to pre-setup the PQ table.
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Auto\n");
#if ENABLE_PQ_CUSTOMER_BIN_SUB_GRULE
                u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Low_Sub_Color;
#endif
                u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Low_Sub;
            }
            else if(en3DNRType == PQ_3D_NR_LOW)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Low\n");
#if ENABLE_PQ_CUSTOMER_BIN_SUB_GRULE
                u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Low_Sub_Color;
#endif
                u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Low_Sub;
            }
            else if(en3DNRType == PQ_3D_NR_MID)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Mid\n");
#if ENABLE_PQ_CUSTOMER_BIN_SUB_GRULE
                u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_Middle_Sub_Color;
#endif
                u16GRuleLevelIndex = PQ_GRule_Lvl_NR_Middle_Sub;
            }
            else if(en3DNRType == PQ_3D_NR_HIGH)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"High\n");
#if ENABLE_PQ_CUSTOMER_BIN_SUB_GRULE
                u16CustomerGRuleLevelIndex = PQ_GRule_Lvl_NR_High_Sub_Color;
#endif
                u16GRuleLevelIndex = PQ_GRule_Lvl_NR_High_Sub;
            }
            else
            {
                PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",en3DNRType,(PQ_3D_NR_NUM-1));
                PQ_ASSERT(FALSE);
            }
            stGRuleIPInfo.u16GruleLevel = u16GRuleLevelIndex;
            MHal_PQ_RemappingGruleIP(pInstance, stGRuleIPInfo, &stUpdatedGRuleIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
            u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_Ex_U2(pInstance, eWindow, u16GRuleType, stUpdatedGRuleIPInfo.u16GruleLevel, stUpdatedGRuleIPInfo.enPQEngineType);
#if ENABLE_PQ_CUSTOMER_BIN_SUB_GRULE
            u16CustomerPQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_Ex_U2(pInstance, eWindow, u16CustomerGRuleType, u16CustomerGRuleLevelIndex,PQ_XC0_CUSTOMER);
#endif
        }
        _MDrv_PQ_LoadNRTable(pInstance, eWindow, u16PQ_NRIdx);
#if ENABLE_PQ_CUSTOMER_BIN_SUB_GRULE
        _MDrv_PQ_LoadCustomerNRTable(pInstance, eWindow, u16CustomerPQ_NRIdx);
#endif
    }
#endif
    else
    {
        UNUSED(u16PQ_NRIdx);
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Not support case \n");
    }
#endif
}
void SYMBOL_WEAK MDrv_PQ_LoadNRTable(PQ_WIN eWindow, PQ_3D_NR_FUNCTION_TYPE en3DNRType)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return ;
    }

    stPQ_LoadNRTable PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.en3DNRType = en3DNRType;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_LOAD_NR_TABLE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}

#if PQ_GRULE_MPEG_NR_ENABLE
static void _MDrv_PQ_LoadMPEGNRTable(void* pInstance, PQ_WIN eWindow, MS_U16 u16PQ_NRIdx)
{
    MS_U16 u16Index=0, u16IPIdx = 0, u16TabIdx = 0;
    MS_U16 u16GroupNum = 0;
    MS_U16 u16IPNum = 0;
    if(MHal_PQ_Support_GroupIPBIN())
    {
        MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,PQ_GRule_MPEG_NR_Main,PQ_BIN_STD_MAIN ,&u16GroupNum, &u16IPNum ,&stPQBinHeaderInfo[PQ_BIN_STD_MAIN]);
    }
    else
    {
        u16GroupNum = PQ_GRULE_MPEG_NR_NUM_Main;
        u16IPNum = PQ_GRULE_MPEG_NR_IP_NUM_Main;
    }
    if(u16PQ_NRIdx > u16GroupNum)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",u16PQ_NRIdx,(u16GroupNum-1));
        PQ_ASSERT(0);
        return;
    }
    for(u16Index = 0; u16Index < u16IPNum; u16Index++)
    {
        u16IPIdx = MDrv_PQ_GetGRule_IPIndex_U2(pInstance, eWindow, PQ_GRule_MPEG_NR_Main, u16Index);
        if(u16PQ_NRIdx == u16GroupNum)  // see it as default
        {
            u16TabIdx = MDrv_PQ_GetTableIndex_U2(pInstance,eWindow, u16IPIdx);
        }
        else
        {
            u16TabIdx = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_MPEG_NR_Main, u16PQ_NRIdx, u16Index);
        }
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[MPEGNR]SRC: %u, NR: %u, NRIPIdx:%u, IPIdx:%u, u16TabIdx:%u\n",
                           _u16PQSrcType[eWindow], u16PQ_NRIdx, u16Index, u16IPIdx, u16TabIdx);
        MDrv_PQ_LoadTable_U2(pInstance, eWindow, u16TabIdx, u16IPIdx);
    }

}
#endif

void MDrv_PQ_LoadMPEGNRTable_U2(void* pInstance,PQ_WIN eWindow, PQ_MPEG_NR_FUNCTION_TYPE enMPEGNRType)
{
    if(eWindow == PQ_MAIN_WINDOW)
    {
#if(PQ_GRULE_MPEG_NR_ENABLE)
        MS_U16 u16PQ_NRIdx;
        MS_U16 u16GroupNum = PQ_GRULE_MPEG_NR_NUM_Main;

#ifdef MSOS_TYPE_LINUX_KERNEL
        _eMPEGNRType[eWindow] = enMPEGNRType;
#endif
        if(enMPEGNRType == PQ_MPEG_NR_OFF)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Off\n");
            u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_MPEG_NR_Main, PQ_GRule_Lvl_MPEG_NR_Off_Main);
            _MDrv_PQ_LoadMPEGNRTable(pInstance, eWindow, u16PQ_NRIdx);
        }
        else if( enMPEGNRType == PQ_MPEG_NR_AUTO )
        {
            // Auto NR will be process in msAPI_DynamicNR_Handler(), hence we only need to pre-setup the PQ table.
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Auto\n");
            u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_MPEG_NR_Main, PQ_GRule_Lvl_MPEG_NR_Low_Main);
            _MDrv_PQ_LoadMPEGNRTable(pInstance, eWindow, u16PQ_NRIdx);
        }
        else if(enMPEGNRType == PQ_MPEG_NR_LOW)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Low\n");
            u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_MPEG_NR_Main, PQ_GRule_Lvl_MPEG_NR_Low_Main);
            _MDrv_PQ_LoadMPEGNRTable(pInstance, eWindow, u16PQ_NRIdx);
        }
        else if(enMPEGNRType == PQ_MPEG_NR_MID)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Mid\n");
            u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_MPEG_NR_Main, PQ_GRule_Lvl_MPEG_NR_Middle_Main);
            _MDrv_PQ_LoadMPEGNRTable(pInstance, eWindow, u16PQ_NRIdx);
        }
        else if(enMPEGNRType == PQ_MPEG_NR_HIGH)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"High\n");
            u16PQ_NRIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_MPEG_NR_Main, PQ_GRule_Lvl_MPEG_NR_High_Main);
            _MDrv_PQ_LoadMPEGNRTable(pInstance, eWindow, u16PQ_NRIdx);
        }
        else if(enMPEGNRType == PQ_MPEG_NR_DEFAULT)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Default\n");
            _MDrv_PQ_LoadMPEGNRTable(pInstance,eWindow, u16GroupNum);
        }
        else
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",enMPEGNRType,(PQ_MPEG_NR_NUM-1));
            PQ_ASSERT(0);
        }
#endif
    }
    else
    {
        UNUSED(enMPEGNRType);
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[PQ] Not Support Sub \n");
    }
}
void SYMBOL_WEAK MDrv_PQ_LoadMPEGNRTable(PQ_WIN eWindow, PQ_MPEG_NR_FUNCTION_TYPE enMPEGNRType)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return ;
    }

    stPQ_LoadMPEGNRTable PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.enMPEGNRType = enMPEGNRType;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_LOAD_MPEG_NR_TABLE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}

#if PQ_GRULE_ULTRAT_CLEAR_ENABLE
void _MDrv_PQ_Load_ULTRACLEAR_Table(void* pInstance, PQ_WIN eWindow, MS_U16 u16PQ_ULTRACLEAR_Idx)
{
    MS_U16 u16Index = 0, u16IPIdx = 0, u16TabIdx = 0;
    ST_PQ_IPInfo stGRuleIPInfo;
    ST_PQ_IPInfo stUpdatedGRuleIPInfo;
    memset(&stGRuleIPInfo, 0, sizeof(ST_PQ_IPInfo));
    memset(&stUpdatedGRuleIPInfo, 0, sizeof(ST_PQ_IPInfo));
    stGRuleIPInfo.u16IPIdx = PQ_GRule_ULTRAT_CLEAR_Main;
    stGRuleIPInfo.u16GruleMaxIPNum = PQ_GRULE_ULTRAT_CLEAR_IP_NUM_Main;
    stGRuleIPInfo.u16GruleLevelMainNum = PQ_GRULE_ULTRAT_CLEAR_NUM_Main;
    stGRuleIPInfo.enPQEngineType = PQ_XC0_STD;
    MHal_PQ_RemappingGruleIP(pInstance, stGRuleIPInfo, &stUpdatedGRuleIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
    if(u16PQ_ULTRACLEAR_Idx > stUpdatedGRuleIPInfo.u16GruleLevelMainNum)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",u16PQ_ULTRACLEAR_Idx,(stUpdatedGRuleIPInfo.u16GruleLevelMainNum-1));
        PQ_ASSERT(0);
        return;
    }
    if(MHal_PQ_Support_GroupIPBIN())
    {
        if(stUpdatedGRuleIPInfo.enPQEngineType == PQ_XC0_STD)
        {
            MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,stUpdatedGRuleIPInfo.u16IPIdx,PQ_BIN_STD_MAIN ,&stUpdatedGRuleIPInfo.u16GruleLevelMainNum, &stUpdatedGRuleIPInfo.u16GruleMaxIPNum ,&stPQBinHeaderInfo[PQ_BIN_STD_MAIN]);
        }
        else
        {
            MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,stUpdatedGRuleIPInfo.u16IPIdx,PQ_BIN_EXT_MAIN ,&stUpdatedGRuleIPInfo.u16GruleLevelMainNum, &stUpdatedGRuleIPInfo.u16GruleMaxIPNum ,&stPQBinHeaderInfo[PQ_BIN_EXT_MAIN]);
        }
    }
    for(u16Index = 0; u16Index < stUpdatedGRuleIPInfo.u16GruleMaxIPNum; u16Index++)
    {
        u16IPIdx = MDrv_PQ_GetGRule_IPIndex_Ex_U2(pInstance, eWindow, stUpdatedGRuleIPInfo.u16IPIdx, u16Index, stUpdatedGRuleIPInfo.enPQEngineType);
#if PQ_LCE_CTL_FOR_MVC4KX1K
        if((_gIsMVC4kx1k == TRUE) && (u16IPIdx == PQ_IP_VIP_LCE_Main))
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"[Grule-ULTRACLEAR] cannot load LCE table for MVC4kx1k\n");
            continue;
        }
#endif

        if(u16PQ_ULTRACLEAR_Idx == stUpdatedGRuleIPInfo.u16GruleLevelMainNum)  // see it as default
        {
            u16TabIdx = MDrv_PQ_GetTableIndex_Ex_U2(pInstance,eWindow, u16IPIdx, stUpdatedGRuleIPInfo.enPQEngineType);
        }
        else
        {
            u16TabIdx = MDrv_PQ_GetGRule_TableIndex_Ex(eWindow, stUpdatedGRuleIPInfo.u16IPIdx, u16PQ_ULTRACLEAR_Idx, u16Index, stUpdatedGRuleIPInfo.enPQEngineType);
        }

        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[UC]SRC: %u, UC: %u, UCIPIdx:%u, IPIdx:%u, u8TabIdx:%u\n",
                           _u16PQSrcType[eWindow], u16PQ_ULTRACLEAR_Idx, u16Index, u16IPIdx, u16TabIdx);

        MDrv_PQ_LoadTable_Ex_U2(pInstance, eWindow, u16TabIdx, u16IPIdx, stUpdatedGRuleIPInfo.enPQEngineType);
    }
}
#endif

void MDrv_PQ_Load_ULTRACLEAR_Table_U2(void* pInstance,PQ_WIN eWindow, PQ_FEATURE_SWITCH_TYPE enCtrlType)
{
    MS_U16 u16PQ_TableIdx = 0;
#if PQ_GRULE_ULTRAT_CLEAR_ENABLE
    ST_PQ_IPInfo stGRuleIPInfo;
    ST_PQ_IPInfo stUpdatedGRuleIPInfo;
    memset(&stGRuleIPInfo, 0, sizeof(ST_PQ_IPInfo));
    memset(&stUpdatedGRuleIPInfo, 0, sizeof(ST_PQ_IPInfo));
    stGRuleIPInfo.u16IPIdx = PQ_GRule_ULTRAT_CLEAR_Main;

#ifdef MSOS_TYPE_LINUX_KERNEL
    _eCtrType[eWindow] = enCtrlType;
#endif
    if(enCtrlType == PQ_FEATURE_SWITCH_ON)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"On\n");
        stGRuleIPInfo.u16GruleLevel = PQ_GRule_Lvl_ULTRAT_CLEAR_On_Main;
        MHal_PQ_RemappingGruleIP(pInstance, stGRuleIPInfo, &stUpdatedGRuleIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
        u16PQ_TableIdx = MDrv_PQ_GetGRule_LevelIndex_Ex_U2(pInstance, eWindow, stUpdatedGRuleIPInfo.u16IPIdx, stUpdatedGRuleIPInfo.u16GruleLevel, stUpdatedGRuleIPInfo.enPQEngineType);
        _MDrv_PQ_Load_ULTRACLEAR_Table(pInstance, eWindow, u16PQ_TableIdx);
    }
    else
    {
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Off\n");
        stGRuleIPInfo.u16GruleLevel = PQ_GRule_Lvl_ULTRAT_CLEAR_Off_Main;
        MHal_PQ_RemappingGruleIP(pInstance, stGRuleIPInfo, &stUpdatedGRuleIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
        u16PQ_TableIdx = MDrv_PQ_GetGRule_LevelIndex_Ex_U2(pInstance, eWindow, stUpdatedGRuleIPInfo.u16IPIdx, stUpdatedGRuleIPInfo.u16GruleLevel, stUpdatedGRuleIPInfo.enPQEngineType);
        _MDrv_PQ_Load_ULTRACLEAR_Table(pInstance, eWindow, u16PQ_TableIdx);
    }
#else
    UNUSED(u16PQ_TableIdx);
    UNUSED(eWindow);
    UNUSED(enCtrlType);

#endif
}
void SYMBOL_WEAK MDrv_PQ_Load_ULTRACLEAR_Table(PQ_WIN eWindow, PQ_FEATURE_SWITCH_TYPE enCtrlType)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return ;
    }

    stPQ_Load_ULTRACLEAR_Table PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.enCtrlType = enCtrlType;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_LOAD_ULTRACLEAR_TABLE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}

void MDrv_PQ_Load_HDR_Table_U2(void *pInstance,PQ_WIN eWindow, PQ_HDR_MODE enHdrMode)
{
#if PQ_GRULE_HDR_ENABLE
#ifdef MSOS_TYPE_LINUX_KERNEL
    _eHdrMode[eWindow] = enHdrMode;
#endif
    if (enHdrMode == PQ_HDR_ON)
    {
        if((MS_U16)PQ_GRule_HDR_Main < (MS_U16)E_GRULE_NUM)
        {
            MDrv_PQ_SetGRuleStatus_U2(pInstance,eWindow, PQ_GRule_HDR_Main, PQ_GRule_HDR_On_Main);
        }
    }
#else
    UNUSED(eWindow);
    UNUSED(enHdrMode);
#endif
}
void MDrv_PQ_Load_HDR_Table(PQ_WIN eWindow, PQ_HDR_MODE enHdrMode)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return ;
    }

    stPQ_Load_HDR_Table PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.enHdrMode = enHdrMode;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_LOAD_HDR_TABLE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}

void MDrv_PQ_Load_XVYCC_Table_U2(void* pInstance,PQ_WIN eWindow, PQ_XVYCC_TYPE enXvyccType)
{
#ifdef MSOS_TYPE_LINUX_KERNEL
    _eXvyccType[eWindow] = enXvyccType;
#endif
#ifdef PQ_CFD_INFO
    if (eWindow == PQ_MAIN_WINDOW)
    {
        ST_PQ_CFD_LINEAR_RGB stCfdLinearRgb;
        memset(&stCfdLinearRgb, 0, sizeof(ST_PQ_CFD_LINEAR_RGB));
        stCfdLinearRgb.u32Version = PQ_CFD_LINEAR_RGB_VERSION;
        stCfdLinearRgb.u16Length = sizeof(ST_PQ_CFD_LINEAR_RGB);
        stCfdLinearRgb.u8Win = eWindow;

        if(enXvyccType == PQ_XVYCC_NORMAL)
        {
            stCfdLinearRgb.bEnable = TRUE;
        }
        else if(enXvyccType == PQ_XVYCC_ON_XVYCC)
        {
            stCfdLinearRgb.bEnable = TRUE;
        }
        else if(enXvyccType == PQ_XVYCC_ON_SRGB)
        {
            stCfdLinearRgb.bEnable = FALSE;
        }

        MDrv_PQ_SendCfd(E_PQ_CFD_CTRL_SET_LINEAR_RGB, &stCfdLinearRgb, sizeof(ST_PQ_CFD_LINEAR_RGB));
    }
#else
#if PQ_GRULE_XVYCC_ENABLE
    if (!QM_IsSourceMultiMedia(MDrv_PQ_GetInputSourceType(eWindow)))
    {
        if(enXvyccType == PQ_XVYCC_NORMAL)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Normal\n");
            MDrv_PQ_SetGRuleStatus(eWindow, PQ_GRule_XVYCC_Main, PQ_GRule_XVYCC_Normal_Main);//PQ_GRule_XVYCC_Normal_Main
        }
        else if(enXvyccType == PQ_XVYCC_ON_XVYCC)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"On xcYCC\n");
            MDrv_PQ_SetGRuleStatus(eWindow, PQ_GRule_XVYCC_Main, PQ_GRule_XVYCC_On_xvYCC_Main);//PQ_GRule_XVYCC_On_xvYCC_Main
        }
        else if(enXvyccType == PQ_XVYCC_ON_SRGB)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"On sRGB\n");
            MDrv_PQ_SetGRuleStatus(eWindow, PQ_GRule_XVYCC_Main, PQ_GRule_XVYCC_On_sRGB_Main);//PQ_GRule_XVYCC_On_sRGB_Main
        }
        else
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",enXvyccType,(PQ_XVYCC_NUM-1));
            PQ_ASSERT(0);
        }
    }
#else
    UNUSED(eWindow);
    UNUSED(enXvyccType);
#endif
#endif
}
void SYMBOL_WEAK MDrv_PQ_Load_XVYCC_Table(PQ_WIN eWindow, PQ_XVYCC_TYPE enXvyccType)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return ;
    }

    stPQ_Load_XVYCC_Table PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.enXvyccType = enXvyccType;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_LOAD_XVYCC_TABLE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}

MS_BOOL MDrv_PQ_Set_CustomerIp_Parameter_U2(void* pInstance, PQ_WIN eWindow, EN_PQ_XC_CUSTOMER_IP enCustomerIp, MS_U8 *pu8data, MS_U16 u16Size)
{
    MS_BOOL bManual = FALSE;
    MS_U32 u32AddressOffset = 0;
    MS_U16 u16ParameterSize = 0;
    MS_U16 u16Count = 0;

    if((MDrv_PQBin_VR_Read2Byte((MS_U32)u32IPModeAddress[eWindow][enCustomerIp])) & u8IPModeAddressMask[eWindow][enCustomerIp])
    {
        bManual = TRUE;
    }
    else
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Customer IP is not set as customer mode\n");
        return FALSE;
    }

    u32AddressOffset = MDrv_PQBin_VR_Read4Byte((MS_U32)u32IPParameterAddress[eWindow][enCustomerIp]);
    u16ParameterSize = MDrv_PQBin_VR_Read2Byte((MS_U32)u32IPParameterSize[eWindow][enCustomerIp]);

    if(u16Size > u16ParameterSize)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Customer IP Setting size is lager than max length\n");
        return FALSE;
    }

    for(u16Count=0; u16Count<u16Size; u16Count++)
    {
        MDrv_PQBin_VR_WriteByte((MS_U32)(u32AddressOffset+u16Count), *(pu8data + u16Count));
    }

    if(bManual == TRUE)
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}


MS_BOOL SYMBOL_WEAK MDrv_PQ_Set_CustomerIp_Parameter(PQ_WIN enWindow, EN_PQ_XC_CUSTOMER_IP enCustomerIp, MS_U8 *pu8data, MS_U16 u16Size)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    ST_PQ_CUSTOMER_SETTING stCustomerSetting;
    stCustomerSetting.enWindow = enWindow;
    stCustomerSetting.enCustomerIp = enCustomerIp;
    stCustomerSetting.pu8data = pu8data;
    stCustomerSetting.u16Size = u16Size;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SET_CUSTOMER_IP_PARAMETER, (void*)&stCustomerSetting) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return stCustomerSetting.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_GRULE_Get_Support_Status_U2(void* pInstance,PQ_SUPPORTED_TYPE enType)
{
    MS_BOOL bStatus = FALSE;
    switch(enType)
    {
        case E_PQ_SUPPORTED_FILM:
            if(PQ_GRULE_FILM_MODE_ENABLE)
                bStatus = TRUE;
            break;
        case E_PQ_SUPPORTED_NR:
            if(PQ_GRULE_NR_ENABLE)
                bStatus = TRUE;
            break;
        case E_PQ_SUPPORTED_MPEG_NR:
            if(PQ_GRULE_MPEG_NR_ENABLE)
                bStatus = TRUE;
            break;
        case E_PQ_SUPPORTED_BLACK_LEVEL:
            bStatus = TRUE;
            break;
        case E_PQ_SUPPORTED_ULTRA_CLEAR:
            if(PQ_GRULE_ULTRAT_CLEAR_ENABLE)
                bStatus = TRUE;
            break;
        case E_PQ_SUPPORTED_HDR:
            if(PQ_GRULE_HDR_ENABLE )
                bStatus = TRUE;
            break;
        default:
            break;
    }

    return bStatus;

}
MS_BOOL SYMBOL_WEAK MDrv_PQ_GRULE_Get_Support_Status(PQ_SUPPORTED_TYPE enType)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_GRULE_Get_Support_Status PQArgs;
    PQArgs.enType = enType;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_GRULE_GET_SUPPORT_STATUS, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

#ifdef PQ_GRULE_FB_LEVEL_SWITCH_ENABLE
#if PQ_GRULE_FB_LEVEL_SWITCH_ENABLE
static MS_BOOL _MDrv_PQ_GetMADiFromFbLevelSwitchGrule(PQ_WIN eWindow,
                                           MS_U16 *pu16TabIdx_MADi,
                                           MS_U16 *pu16TabIdx_MADi_Motion)
{
    if(eWindow == PQ_MAIN_WINDOW)
    {
        MS_U16 u16GRuleLevelIndex = 0;
        MS_U16 u16PQ_FBLIdx = 0;
        if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
        {
            u16GRuleLevelIndex = PQ_GRule_Lvl_FB_LEVEL_SWITCH_On_Main;
            u16PQ_FBLIdx = MDrv_PQ_GetGRule_LevelIndex(eWindow, PQ_GRule_FB_LEVEL_SWITCH_Main, u16GRuleLevelIndex);
            *pu16TabIdx_MADi = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_FB_LEVEL_SWITCH_Main, u16PQ_FBLIdx, 0); // only MADi ip
            if(PQ_GRULE_FB_LEVEL_SWITCH_IP_NUM_Main > 1)
            {
                *pu16TabIdx_MADi_Motion = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_FB_LEVEL_SWITCH_Main, u16PQ_FBLIdx, 1); // Add MADi_Motion ip
            }
        }
        else
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Non-3D,get MADI return false! \n");
            return FALSE;
        }
    }
    else
    {
        // TODO: Should sub window need to consider the FB Level Switch ??
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[PQ] Not Support Sub \n");
    }

    return TRUE;
}
#endif//#if PQ_GRULE_FB_LEVEL_SWITCH_ENABLE
#endif//#ifdef PQ_GRULE_FB_LEVEL_SWITCH_ENABLE

//////////////////////////////////////////////////////////////////
// Load MADi/444To422/422To444 table
//
// parameter:
//    [IN]  u8PQTabType
//          bMemFmt422: TRUE  - 422
//                      FALSE - 444
//          bFBL:       TRUE  - framebuffer-less mode
//                      FALSE - framebuffer mode
//    [OUT] u8BitsPerPixel
//                      bits per pixel for decided memory format
//
// return:  deinterlace (MADi) mode
//
PQ_DEINTERLACE_MODE MDrv_PQ_SetMemFormat_U2(void* pInstance,PQ_WIN eWindow, MS_BOOL bMemFmt422, MS_BOOL bFBL, MS_U8 *pu8BitsPerPixel)
{
    MS_U16 u16TabIdx_MemFormat = 0;
    MS_U16 u16TabIdx_MADi = 0;
    MS_U16 u16TabIdx_MADi_Motion=0xFFFF;
    MS_U16 u16TabIdx_444To422 = 0;
    MS_U16 u16TabIdx_422To444 = 0;
    PQ_DEINTERLACE_MODE eDeInterlaceMode = PQ_DEINT_OFF;
    MS_U8 u8FrameCount = 4;
    MS_BOOL bIsUseMload = FALSE;
    MS_U8 u8CmpBitPerPixel = 0;
    ST_PQ_IPInfo stIPInfo;
    ST_PQ_IPInfo stUpdatedIPInfo;
    MS_U32 u32SupportZNR = 0;
    MS_U32 u32SupportABF = 0;
    ST_PQ_GET_MADI_VR_INFO stPQMADiInfo;
    memset(&stIPInfo, 0, sizeof(ST_PQ_IPInfo));
    memset(&stUpdatedIPInfo, 0, sizeof(ST_PQ_IPInfo));
    memset(&stPQMADiInfo, 0, sizeof(ST_PQ_GET_MADI_VR_INFO));

    if(eWindow == PQ_MAIN_WINDOW)
    {
        MApi_XC_Set_OPWriteOffEnable(ENABLE, MAIN_WINDOW); //default
    }
    else
    {
        PQ_LEVEL_PRINTF(PQ_DBG_MADI, "No need to enable OP write with sub window, it would change main window setting \n");
    }

    PQ_LEVEL_PRINTF(PQ_DBG_MADI,"eWindows = %u\n",eWindow);

    // if MADi mode change from 25 <=> 27, cropping base address need to be recalculated.
#if PQ_GRULE_OSD_BW_ENABLE
    if(((_stMode_Info[eWindow].u16input_hsize >= 1280) && (_stMode_Info[eWindow].u16input_vsize >= 720)) &&
            (_bOSD_On))
    {
        MDrv_PQ_GetMADiFromOSDBWGrule(eWindow, &u16TabIdx_MADi, &u16TabIdx_MADi_Motion);
    }
    else
#endif
    {
#ifdef PQ_GRULE_FB_LEVEL_SWITCH_ENABLE
#if PQ_GRULE_FB_LEVEL_SWITCH_ENABLE
        if(MApi_XC_Get_3D_Output_Mode() != E_XC_3D_OUTPUT_MODE_NONE)
        {
            _MDrv_PQ_GetMADiFromFbLevelSwitchGrule(eWindow, &u16TabIdx_MADi, &u16TabIdx_MADi_Motion);
        }
        else
#endif//#if PQ_GRULE_FB_LEVEL_SWITCH_ENABLE
#endif//#ifdef PQ_GRULE_FB_LEVEL_SWITCH_ENABLE
        {
            MDrv_PQ_GetMADiInGeneral_U2(pInstance, eWindow, &u16TabIdx_MADi, &u16TabIdx_MADi_Motion);
        }
#if PQ_GRULE_OSD_BW_ENABLE
        MDrv_PQ_Patch2Rto4RForFieldPackingMode_U2(pInstance, eWindow, u16TabIdx_MADi);
#endif
    }
    MDrv_PQ_GetMemFmtInGeneral_U2(pInstance, eWindow, bMemFmt422, &u16TabIdx_MemFormat, &u16TabIdx_444To422, &u16TabIdx_422To444);

    PQ_LEVEL_PRINTF(PQ_DBG_MADI,"eWindow = %u, u16TabIdx_MADi = %u\n",eWindow,u16TabIdx_MADi);
    PQ_LEVEL_PRINTF(PQ_DBG_MADI,"eWindow = %u, u16TabIdx_444To422 = %u\n",eWindow,u16TabIdx_444To422);
    PQ_LEVEL_PRINTF(PQ_DBG_MADI,"eWindow = %u, u16TabIdx_422To444 = %u\n",eWindow,u16TabIdx_422To444);
    PQ_LEVEL_PRINTF(PQ_DBG_MADI,"eWindow = %u, Mem FMT is %s\n",eWindow,bMemFmt422?("422"):("444"));
    PQ_LEVEL_PRINTF(PQ_DBG_MADI,"eWindow = %u, u16TabIdx_MemFormat = %u\n",eWindow,u16TabIdx_MemFormat);

    if(MHal_PQ_IsSupportMADiVR() == TRUE)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_MADI,"MADI VR Path\n");
#if (PQ_SUPPORT_MADI_VR)
        ST_PQ_GET_MADI_VR_INFO stPQGetMADiVRInfo;
        stPQGetMADiVRInfo.u32Version = ST_PQ_GET_MADI_VR_INFO_VERSION;
        stPQGetMADiVRInfo.u32Length= sizeof(ST_PQ_GET_MADI_VR_INFO);
        stPQGetMADiVRInfo.enWindow = eWindow;
        stPQGetMADiVRInfo.bMemFmt422 =bMemFmt422;
        stPQGetMADiVRInfo.pu8BitsPerPixel = pu8BitsPerPixel;
        stPQGetMADiVRInfo.peDeInterlaceMode = &eDeInterlaceMode;
        stPQGetMADiVRInfo.pu8FrameCount = &u8FrameCount;
        stPQGetMADiVRInfo.pu8CmpBitsPerPixel = &u8CmpBitPerPixel;
        stPQGetMADiVRInfo.u16IPIdx = PQ_IP_MADi_VR_Main_Ex;
        MDrv_PQ_GetBPPInfoFromMADiVR(&stPQGetMADiVRInfo);
#endif
    }
    else
    {
        PQ_LEVEL_PRINTF(PQ_DBG_MADI,"MADI INFO Path\n");
        MDrv_PQ_GetBPPInfoFromMADi_U2(
                           pInstance,
                           eWindow,
                           bMemFmt422,
                           u16TabIdx_MADi,
                           u16TabIdx_MemFormat,
                           pu8BitsPerPixel,
                           &eDeInterlaceMode,
                           &u8FrameCount);
        u8CmpBitPerPixel = MDrv_PQ_Get420CmpBitPerPixel();
    }
    PQ_LEVEL_PRINTF(PQ_DBG_MADI,"BitPerPixel =%d, DIMode =%x\n",*pu8BitsPerPixel, eDeInterlaceMode);

    _gbMemfmt422[eWindow] = bMemFmt422;
    _gu16SetMemfmt_Madi[eWindow] = u16TabIdx_MADi;
    _gu16SetMemfmt_Madi_Motion[eWindow] = u16TabIdx_MADi_Motion;

    ST_PQ_SET_VR_INFO stPQSetVRInfo;
    memset(&stPQSetVRInfo,0,sizeof(ST_PQ_SET_VR_INFO));
    stPQSetVRInfo.u32Version = ST_PQ_SET_VR_INFO_VERSION;
    stPQSetVRInfo.u32Length = sizeof(ST_PQ_SET_VR_INFO);
    stPQSetVRInfo.enVRInfoType = E_PQ_VR_INFO_MADI_INDEX;
    stPQSetVRInfo.enWindow= eWindow;
    stPQSetVRInfo.pValue= &_gu16SetMemfmt_Madi[eWindow];
    if(MDrv_PQ_SetPQInfoToVR(stPQSetVRInfo) == FALSE)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"MDrv_PQ_SetPQInfoToVR Fail\n");
    }

    MDrv_PQ_ChangeMemConfigFor3D_U2(pInstance, eWindow, bMemFmt422, &u16TabIdx_MemFormat, &u16TabIdx_444To422, &u16TabIdx_422To444,
                                    pu8BitsPerPixel, &u16TabIdx_MADi_Motion, &u16TabIdx_MADi);

    if (TRUE == MApi_XC_IsBlackVideoEnable((SCALER_WIN)eWindow))
    {
        bIsUseMload = FALSE;
    }
    else
    {
        bIsUseMload = TRUE;
    }

    if(eWindow == PQ_MAIN_WINDOW)
    {
#if(ENABLE_PQ_MLOAD)
        MDrv_PQ_Set_MLoadEn(eWindow, bIsUseMload);
#endif
        MDrv_PQ_LoadTable_U2(pInstance, PQ_MAIN_WINDOW, u16TabIdx_MemFormat, PQ_IP_MemFormat_Main);

        stIPInfo.u16IPIdx = PQ_IP_MADi_Main;
        stIPInfo.enPQEngineType = PQ_XC0_STD;
        MHal_PQ_RemappingIP(pInstance, stIPInfo, &stUpdatedIPInfo, TRUE);
        MDrv_PQ_LoadTable_Ex_U2(pInstance, eWindow, u16TabIdx_MADi, stUpdatedIPInfo.u16IPIdx, stUpdatedIPInfo.enPQEngineType);
#if PQ_GRULE_OSD_BW_ENABLE
        if(0xFFFF != u16TabIdx_MADi_Motion)
        {
            stIPInfo.u16IPIdx = PQ_IP_MADi_Motion_Main;
            stIPInfo.enPQEngineType = PQ_XC0_STD;
            MHal_PQ_RemappingIP(pInstance, stIPInfo, &stUpdatedIPInfo,TRUE);
            MDrv_PQ_LoadTable_Ex_U2(pInstance, eWindow, u16TabIdx_MADi_Motion, stUpdatedIPInfo.u16IPIdx, stUpdatedIPInfo.enPQEngineType);
        }
#endif
        MDrv_PQ_LoadTable_U2(pInstance, eWindow, u16TabIdx_444To422, PQ_IP_444To422_Main);
        MDrv_PQ_LoadTable_U2(pInstance, eWindow, u16TabIdx_422To444, PQ_IP_422To444_Main);

        MApi_XC_GetChipCaps(E_XC_SUPPORT_ZNR, &u32SupportZNR, sizeof(MS_U32));
        MApi_XC_GetChipCaps(E_XC_SUPPORT_ABF, &u32SupportABF, sizeof(MS_U32));

        PQ_LEVEL_PRINTF(PQ_DBG_MADI,"ZNR %s Support\n",(u32SupportZNR)?("is"):("not"));
        PQ_LEVEL_PRINTF(PQ_DBG_MADI,"ABF %s Support\n",(u32SupportABF)?("is"):("not"));

        if((u32SupportZNR!=0) && (u32SupportABF!=0))
        {
            stPQMADiInfo.u32Version = ST_PQ_GET_MADI_VR_INFO_VERSION;
            stPQMADiInfo.u32Length= sizeof(ST_PQ_GET_MADI_VR_INFO);
            stPQMADiInfo.enWindow = eWindow;
            stPQMADiInfo.bMemFmt422 =bMemFmt422;
            stPQMADiInfo.pu8BitsPerPixel = pu8BitsPerPixel;
            stPQMADiInfo.peDeInterlaceMode = &eDeInterlaceMode;
            stPQMADiInfo.pu8FrameCount = &u8FrameCount;
            stPQMADiInfo.pu8CmpBitsPerPixel = &u8CmpBitPerPixel;
            if(MDrv_PQ_LoadControlPathTable(&stPQMADiInfo) == FALSE)
            {
                PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Load ZNR path setting fail\n");
            }
        }
#if(ENABLE_PQ_MLOAD)
        MDrv_PQ_Set_MLoadEn(eWindow, FALSE);
#endif
        MHal_PQ_SetBitPerPixelForCmp(pu8BitsPerPixel, u8CmpBitPerPixel, TRUE);
    }
#if PQ_ENABLE_PIP
    else
    {
#if(ENABLE_PQ_MLOAD)
        MDrv_PQ_Set_MLoadEn(eWindow, bIsUseMload);
#endif
        MDrv_PQ_LoadTable_U2(pInstance, eWindow, u16TabIdx_MemFormat, MHal_PQ_Get_IPIndex(eWindow, E_PQ_IP_MEMFORMAT));

        stIPInfo.u16IPIdx = MHal_PQ_Get_IPIndex(eWindow, E_PQ_IP_MADI);
        stIPInfo.enPQEngineType = PQ_XC0_STD;
        MHal_PQ_RemappingIP(pInstance, stIPInfo, &stUpdatedIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
        MDrv_PQ_LoadTable_Ex_U2(pInstance, eWindow, u16TabIdx_MADi, stUpdatedIPInfo.u16IPIdx, stUpdatedIPInfo.enPQEngineType);

#if PQ_GRULE_OSD_BW_ENABLE
        if(0xFFFF != u16TabIdx_MADi_Motion)
        {
            stIPInfo.u16IPIdx = MHal_PQ_Get_IPIndex(eWindow, E_PQ_IP_MADI_MOTION);
            stIPInfo.enPQEngineType = PQ_XC0_STD;
            MHal_PQ_RemappingIP(pInstance, stIPInfo, &stUpdatedIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
            MDrv_PQ_LoadTable_Ex_U2(pInstance, eWindow, u16TabIdx_MADi_Motion, stUpdatedIPInfo.u16IPIdx, stUpdatedIPInfo.enPQEngineType);
        }
#endif
        MDrv_PQ_LoadTable_U2(pInstance, eWindow, u16TabIdx_444To422, MHal_PQ_Get_IPIndex(eWindow, E_PQ_IP_444TO422));
        MDrv_PQ_LoadTable_U2(pInstance, eWindow, u16TabIdx_422To444, MHal_PQ_Get_IPIndex(eWindow, E_PQ_IP_422TO444));

#if(ENABLE_PQ_MLOAD)
        MDrv_PQ_Set_MLoadEn(eWindow, FALSE);
#endif

        //R W bank mapping mode patch for Qmap hasn't this item for sub
        if(_stMode_Info[eWindow].bInterlace)
        {
            MApi_XC_W2BYTEMSK(REG_SC_BK12_47_L, 0x4000 , 0xE000 );
        }
        else
        {
            MApi_XC_W2BYTEMSK(REG_SC_BK12_47_L, 0x2000 , 0xE000 );
        }
    }
#endif
#if (PQ_XRULE_DB_ENABLE == 1)
    MDrv_PQ_Set_DBRule(eWindow, u16TabIdx_MADi);
#endif

    MDrv_PQ_ForceBPPForDynamicMemFmt_U2(pInstance, eWindow, bMemFmt422, pu8BitsPerPixel);
    MDrv_PQ_SuggestFrameNum_U2(pInstance, eWindow, u16TabIdx_MADi, u8FrameCount);

    if(_bDS_En)
    {
        _u16RW_Method = Hal_PQ_get_rw_method(pInstance,eWindow == PQ_MAIN_WINDOW ? TRUE : FALSE);
        Hal_PQ_set_rw_method(pInstance,eWindow == PQ_MAIN_WINDOW ? TRUE : FALSE, 0x4000);
    }

    _bRWNumIsReset[eWindow] = TRUE;

    return eDeInterlaceMode;
}
PQ_DEINTERLACE_MODE SYMBOL_WEAK MDrv_PQ_SetMemFormat(PQ_WIN eWindow, MS_BOOL bMemFmt422, MS_BOOL bFBL, MS_U8 *pu8BitsPerPixel)
{
    if (pu32PQInst == NULL)
    {
        if(UtopiaOpen(MODULE_PQ , &pu32PQInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"UtopiaOpen PQ failed\n");
            return PQ_DEINT_OFF;
        }
    }
    stPQ_SetMemFormat PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.bMemFmt422 = bMemFmt422;
    PQArgs.bFBL = bFBL;
    PQArgs.pu8BitsPerPixel = pu8BitsPerPixel;
    PQArgs.bReturnValue = PQ_DEINT_OFF;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SET_MEMFORMAT, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return PQ_DEINT_OFF;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

void MDrv_PQ_ReduceBW_ForOSD_U2(void* pInstance,PQ_WIN eWindow, MS_BOOL bOSD_On)
{
#if PQ_GRULE_OSD_BW_ENABLE
    MS_U8 u8BitPerPixel = 0;
{
    if((_stMode_Info[eWindow].u16input_hsize >= 1280) && (_stMode_Info[eWindow].u16input_vsize >= 720))
    {
        PQ_LEVEL_PRINTF(PQ_DBG_BW,"ReduceBW_ForOSD %s\n",(bOSD_On)?("YES"):("NO"));

        _bOSD_On = bOSD_On;
        bSetFrameCount = FALSE;

        MDrv_PQ_SetMemFormat(
            eWindow,
            _gbMemfmt422[eWindow],
            _stMode_Info[eWindow].bFBL,
            &u8BitPerPixel);
        bSetFrameCount = TRUE;

    }
}
#else
    UNUSED(eWindow);
    UNUSED(bOSD_On);
#endif

    return;
}
void SYMBOL_WEAK MDrv_PQ_ReduceBW_ForOSD(PQ_WIN eWindow, MS_BOOL bOSD_On)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return ;
    }

    stPQ_ReduceBW_ForOSD PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.bOSD_On = bOSD_On;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_REDUCEBW_ForOSD, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}

#if PQ_GRULE_PTP_ENABLE
static void _MDrv_PQ_LoadPTPTable(void* pInstance, PQ_WIN eWindow, MS_U16 u16PQ_PTP_Idx)
{
    MS_U16 u16Index=0, u16IPIdx=0, u16TabIdx=0;
    MS_U16 u16GroupNum = 0;
    MS_U16 u16IPNum = 0;
    if(MHal_PQ_Support_GroupIPBIN())
    {
        MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,PQ_GRule_PTP_Main,PQ_BIN_STD_MAIN ,&u16GroupNum, &u16IPNum ,&stPQBinHeaderInfo[PQ_BIN_STD_MAIN]);
    }
    else
    {
        u16GroupNum = PQ_GRULE_PTP_NUM_Main;
        u16IPNum = PQ_GRULE_PTP_IP_NUM_Main;
    }

    if(eWindow == PQ_SUB_WINDOW)
    {
        return;
    }

    if (u16PQ_PTP_Idx > u16GroupNum)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",u16PQ_PTP_Idx,(u16GroupNum-1));
        PQ_ASSERT(0);
        return;
    }
    for(u16Index = 0; u16Index < u16IPNum; u16Index++)
    {
        u16IPIdx = MDrv_PQ_GetGRule_IPIndex_U2(pInstance, eWindow, PQ_GRule_PTP_Main, u16Index);
        if (u16PQ_PTP_Idx == u16GroupNum) // see it as default
        {
            u16TabIdx = MDrv_PQ_GetTableIndex_U2(pInstance,eWindow, u16IPIdx);
        }
        else
        {
            u16TabIdx = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_PTP_Main, u16PQ_PTP_Idx, u16Index);
        }
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[PTP]SRC: %u, u16PQ_PTP_Idx: %u, PIPIPIdx:%u, IPIdx:%u, u8TabIdx:%u\n",
            _u16PQSrcType[eWindow], u16PQ_PTP_Idx, u16Index, u16IPIdx, u16TabIdx);

        MDrv_PQ_LoadTable_U2(pInstance, eWindow, u16TabIdx, u16IPIdx);
    }
}
#endif

void MDrv_PQ_LoadPTPTable_U2(void* pInstance,PQ_WIN eWindow, PQ_PTP_FUNCTION_TYPE enPTP_Type)
{
#if PQ_GRULE_PTP_ENABLE
    MS_U16 u16PQ_PTPIdx;

    if(eWindow == PQ_SUB_WINDOW)
    {
        return;
    }
#ifdef MSOS_TYPE_LINUX_KERNEL
    _ePTPType[eWindow] = enPTP_Type;
#endif
     if( enPTP_Type == PQ_PTP_PTP )
     {
         PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"PTP\n");
         u16PQ_PTPIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_PTP_Main, PQ_GRule_Lvl_PTP_On_Main);
         _MDrv_PQ_LoadPTPTable(pInstance, eWindow, u16PQ_PTPIdx);
#if (PQ_4K2K_P2P_H_OFFSET_LIMITIOM == 1)
         // 4k2k case, p2p should patch offset to 1, by designer
         if((QM_GetInputHSize(eWindow) == 3840) && (QM_GetInputVSize(eWindow) == 2160))
         {
            MApi_XC_W2BYTEMSK(REG_SC_BK20_1C_L, 0x01, 0xFF);
             //MDrv_PQ_LoadTable_U2(pInstance, eWindow, PQ_IP_VIP_Peaking_ON_Voff_Main, PQ_IP_VIP_Peaking_Main);
         }
#endif
     }
     else
     {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",enPTP_Type,(PQ_PTP_NUM-1));
        PQ_ASSERT(0);
     }
#else
    UNUSED(eWindow);
    UNUSED(enPTP_Type);
#endif

}
void SYMBOL_WEAK MDrv_PQ_LoadPTPTable(PQ_WIN eWindow, PQ_PTP_FUNCTION_TYPE enPTP_Type)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return ;
    }

    stPQ_LoadPTPTable PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.enPTP_Type = enPTP_Type;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_LOAD_PTP_TABLE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}

typedef struct {
  MS_U8 *pQuality_Map_Aray;
#if (ENABLE_PQ_EX)
  MS_U8 *pQuality_Map_Aray_Ex;
#endif
  MS_U8 *pGRule_Level[E_GRULE_NUM];
} QMAP_TBL_INIT_INFO;

#define QMAP_TABLE_PANEL_NUMBER 3 // 1920, 1366 , 4K2K
#if PQ_ENABLE_PIP
#define QMAP_TABLE_DISPLAY_NUMBER PQ_DISPLAY_POP+1
#else
#define QMAP_TABLE_DISPLAY_NUMBER PQ_DISPLAY_ONE+1
#endif
QMAP_TBL_INIT_INFO QmapTblInitInfo_Main[QMAP_TABLE_PANEL_NUMBER][QMAP_TABLE_DISPLAY_NUMBER] = {
    { // 1920
        { // ONE
            (void*)QMAP_1920_Main,
#if (ENABLE_PQ_EX)
            (void*)QMAP_1920_Main_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_1920_NR_Main,
#endif
#if (PQ_GRULE_OSD_BW_ENABLE == 1)
                (void*)MST_GRule_1920_OSD_BW_Main,
#endif
#if (PQ_GRULE_MPEG_NR_ENABLE)
                (void*)MST_GRule_1920_MPEG_NR_Main,
#endif
#if (PQ_GRULE_FILM_MODE_ENABLE)
                (void*)MST_GRule_1920_FILM_MODE_Main,
#endif
#if (PQ_GRULE_DYNAMIC_CONTRAST_ENABLE)
                (void*)MST_GRule_1920_DYNAMIC_CONTRAST_Main,
#endif
#if (PQ_GRULE_DDR_SELECT_ENABLE == 1)
                (void*)MST_GRule_1920_DDR_SELECT_Main,
#endif
#if (PQ_GRULE_ULTRAT_CLEAR_ENABLE)
                (void*)MST_GRule_1920_ULTRAT_CLEAR_Main,
#endif
#if (PQ_GRULE_PTP_ENABLE == 1)
                (void*)MST_GRule_1920_PTP_Main,
#endif
#if (PQ_GRULE_XVYCC_ENABLE == 1 )
                (void*)MST_GRule_1920_XVYCC_Main,
#endif
#if (PQ_GRULE_GAME_MODE_ENABLE == 1)
                (void*)MST_GRule_1920_GAME_MODE_Main,
#endif
#if (PQ_GRULE_DS_PARAMETERS_ENABLE == 1)
                (void*)MST_GRule_1920_DS_PARAMETERS_Main,
#endif
#if (PQ_GRULE_HDR_ENABLE == 1)
                (void*)MST_GRule_1920_HDR_Main,
#endif
            }
        },
#if PQ_ENABLE_PIP
#if (PQ_ENABLE_PIP_POP_MAIN)
        { // PIP
            (void*)QMAP_1920_PIP_Main,
#if (ENABLE_PQ_EX)
            (void*)QMAP_1920_PIP_Main_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_1920_PIP_NR_Main,
#endif
#if (PQ_GRULE_OSD_BW_ENABLE == 1)
                (void*)MST_GRule_1920_PIP_OSD_BW_Main,
#endif
#if (PQ_GRULE_MPEG_NR_ENABLE)
                (void*)MST_GRule_1920_PIP_MPEG_NR_Main,
#endif
#if (PQ_GRULE_FILM_MODE_ENABLE)
                (void*)MST_GRule_1920_PIP_FILM_MODE_Main,
#endif
#if (PQ_GRULE_DYNAMIC_CONTRAST_ENABLE)
                (void*)MST_GRule_1920_PIP_DYNAMIC_CONTRAST_Main,
#endif
#if (PQ_GRULE_DDR_SELECT_ENABLE == 1)
                (void*)MST_GRule_1920_PIP_DDR_SELECT_Main,
#endif
#if (PQ_GRULE_ULTRAT_CLEAR_ENABLE)
                (void*)MST_GRule_1920_PIP_ULTRAT_CLEAR_Main,
#endif
#if (PQ_GRULE_PTP_ENABLE == 1)
                (void*)MST_GRule_1920_PIP_PTP_Main,
#endif
#if (PQ_GRULE_XVYCC_ENABLE == 1 )
                (void*)MST_GRule_1920_PIP_XVYCC_Main,
#endif
#if (PQ_GRULE_GAME_MODE_ENABLE == 1)
                (void*)MST_GRule_1920_PIP_GAME_MODE_Main,
#endif
#if (PQ_GRULE_DS_PARAMETERS_ENABLE == 1)
                (void*)MST_GRule_1920_PIP_DS_PARAMETERS_Main,
#endif
#if (PQ_GRULE_HDR_ENABLE == 1)
                (void*)MST_GRule_1920_PIP_HDR_Main,
#endif
            }
        },
        { // POP
            (void*)QMAP_1920_POP_Main,
#if (ENABLE_PQ_EX)
            (void*)QMAP_1920_POP_Main_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_1920_POP_NR_Main,
#endif
#if (PQ_GRULE_OSD_BW_ENABLE == 1)
                (void*)MST_GRule_1920_POP_OSD_BW_Main,
#endif
#if (PQ_GRULE_MPEG_NR_ENABLE)
                (void*)MST_GRule_1920_POP_MPEG_NR_Main,
#endif
#if (PQ_GRULE_FILM_MODE_ENABLE)
                (void*)MST_GRule_1920_POP_FILM_MODE_Main,
#endif
#if (PQ_GRULE_DYNAMIC_CONTRAST_ENABLE)
                (void*)MST_GRule_1920_POP_DYNAMIC_CONTRAST_Main,
#endif
#if (PQ_GRULE_DDR_SELECT_ENABLE == 1)
                (void*)MST_GRule_1920_POP_DDR_SELECT_Main,
#endif
#if (PQ_GRULE_ULTRAT_CLEAR_ENABLE)
                (void*)MST_GRule_1920_POP_ULTRAT_CLEAR_Main,
#endif
#if (PQ_GRULE_PTP_ENABLE == 1)
                (void*)MST_GRule_1920_POP_PTP_Main,
#endif
#if (PQ_GRULE_XVYCC_ENABLE == 1 )
                (void*)MST_GRule_1920_POP_XVYCC_Main,
#endif
#if (PQ_GRULE_GAME_MODE_ENABLE == 1)
                (void*)MST_GRule_1920_POP_GAME_MODE_Main,
#endif
#if (PQ_GRULE_DS_PARAMETERS_ENABLE == 1)
                (void*)MST_GRule_1920_POP_DS_PARAMETERS_Main,
#endif
#if (PQ_GRULE_HDR_ENABLE == 1)
                (void*)MST_GRule_1920_POP_HDR_Main,
#endif
            }
        },
#endif
#endif
    },
    { // 1366
        { // ONE
            (void*)QMAP_1366_Main,
#if (ENABLE_PQ_EX)
            (void*)QMAP_1366_Main_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_1366_NR_Main,
#endif
#if (PQ_GRULE_OSD_BW_ENABLE == 1)
                (void*)MST_GRule_1366_OSD_BW_Main,
#endif
#if (PQ_GRULE_MPEG_NR_ENABLE)
                (void*)MST_GRule_1366_MPEG_NR_Main,
#endif
#if (PQ_GRULE_FILM_MODE_ENABLE)
                (void*)MST_GRule_1366_FILM_MODE_Main,
#endif
#if (PQ_GRULE_DYNAMIC_CONTRAST_ENABLE)
                (void*)MST_GRule_1366_DYNAMIC_CONTRAST_Main,
#endif
#if (PQ_GRULE_DDR_SELECT_ENABLE == 1)
                (void*)MST_GRule_1366_DDR_SELECT_Main,
#endif
#if (PQ_GRULE_ULTRAT_CLEAR_ENABLE)
                (void*)MST_GRule_1366_ULTRAT_CLEAR_Main,
#endif
#if (PQ_GRULE_PTP_ENABLE == 1)
                (void*)MST_GRule_1366_PTP_Main,
#endif
#if (PQ_GRULE_XVYCC_ENABLE == 1 )
                (void*)MST_GRule_1366_XVYCC_Main,
#endif
#if (PQ_GRULE_GAME_MODE_ENABLE == 1)
                (void*)MST_GRule_1366_GAME_MODE_Main,
#endif
#if (PQ_GRULE_DS_PARAMETERS_ENABLE == 1)
                (void*)MST_GRule_1366_DS_PARAMETERS_Main,
#endif
#if (PQ_GRULE_HDR_ENABLE == 1)
                (void*)MST_GRule_1366_HDR_Main,
#endif
            }
        },
#if PQ_ENABLE_PIP
#if (PQ_ENABLE_PIP_POP_MAIN)
        { // PIP
            (void*)QMAP_1366_PIP_Main,
#if (ENABLE_PQ_EX)
            (void*)QMAP_1366_PIP_Main_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_1366_PIP_NR_Main,
#endif
#if (PQ_GRULE_OSD_BW_ENABLE == 1)
                (void*)MST_GRule_1366_PIP_OSD_BW_Main,
#endif
#if (PQ_GRULE_MPEG_NR_ENABLE)
                (void*)MST_GRule_1366_PIP_MPEG_NR_Main,
#endif
#if (PQ_GRULE_FILM_MODE_ENABLE)
                (void*)MST_GRule_1366_PIP_FILM_MODE_Main,
#endif
#if (PQ_GRULE_DYNAMIC_CONTRAST_ENABLE)
                (void*)MST_GRule_1366_PIP_DYNAMIC_CONTRAST_Main,
#endif
#if (PQ_GRULE_DDR_SELECT_ENABLE == 1)
                (void*)MST_GRule_1366_PIP_DDR_SELECT_Main,
#endif
#if (PQ_GRULE_ULTRAT_CLEAR_ENABLE)
                (void*)MST_GRule_1366_PIP_ULTRAT_CLEAR_Main,
#endif
#if (PQ_GRULE_PTP_ENABLE == 1)
                (void*)MST_GRule_1366_PIP_PTP_Main,
#endif
#if (PQ_GRULE_XVYCC_ENABLE == 1 )
                (void*)MST_GRule_1366_PIP_XVYCC_Main,
#endif
#if (PQ_GRULE_GAME_MODE_ENABLE == 1)
                (void*)MST_GRule_1366_PIP_GAME_MODE_Main,
#endif
#if (PQ_GRULE_DS_PARAMETERS_ENABLE == 1)
                (void*)MST_GRule_1366_PIP_DS_PARAMETERS_Main,
#endif
#if (PQ_GRULE_HDR_ENABLE == 1)
                (void*)MST_GRule_1366_PIP_HDR_Main,
#endif
            }
        },
        { // POP
            (void*)QMAP_1366_POP_Main,
#if (ENABLE_PQ_EX)
            (void*)QMAP_1366_POP_Main_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_1366_POP_NR_Main,
#endif
#if (PQ_GRULE_OSD_BW_ENABLE == 1)
                (void*)MST_GRule_1366_POP_OSD_BW_Main,
#endif
#if (PQ_GRULE_MPEG_NR_ENABLE)
                (void*)MST_GRule_1366_POP_MPEG_NR_Main,
#endif
#if (PQ_GRULE_FILM_MODE_ENABLE)
                (void*)MST_GRule_1366_POP_FILM_MODE_Main,
#endif
#if (PQ_GRULE_DYNAMIC_CONTRAST_ENABLE)
                (void*)MST_GRule_1366_POP_DYNAMIC_CONTRAST_Main,
#endif
#if (PQ_GRULE_DDR_SELECT_ENABLE == 1)
                (void*)MST_GRule_1366_POP_DDR_SELECT_Main,
#endif
#if (PQ_GRULE_ULTRAT_CLEAR_ENABLE)
                (void*)MST_GRule_1366_POP_ULTRAT_CLEAR_Main,
#endif
#if (PQ_GRULE_PTP_ENABLE == 1)
                (void*)MST_GRule_1366_POP_PTP_Main,
#endif
#if (PQ_GRULE_XVYCC_ENABLE == 1 )
                (void*)MST_GRule_1366_POP_XVYCC_Main,
#endif
#if (PQ_GRULE_GAME_MODE_ENABLE == 1)
                (void*)MST_GRule_1366_POP_GAME_MODE_Main,
#endif
#if (PQ_GRULE_DS_PARAMETERS_ENABLE == 1)
                (void*)MST_GRule_1366_POP_DS_PARAMETERS_Main,
#endif
#if (PQ_GRULE_HDR_ENABLE == 1)
                (void*)MST_GRule_1366_POP_HDR_Main,
#endif
            }
        },
#endif
#endif
    },
#if PQ_SUPPORT_HDMI_4K2K_P2P
    { // 4k2k
            { // ONE
                (void*)QMAP_4K2K_Main,
#if (ENABLE_PQ_EX)
                (void*)QMAP_4K2K_Main_Ex,
#endif
                {
#if (PQ_GRULE_NR_ENABLE)
                    (void*)MST_GRule_4K2K_NR_Main,
#endif
#if (PQ_GRULE_OSD_BW_ENABLE == 1)
                    (void*)MST_GRule_4K2K_OSD_BW_Main,
#endif
#if (PQ_GRULE_MPEG_NR_ENABLE)
                    (void*)MST_GRule_4K2K_MPEG_NR_Main,
#endif
#if (PQ_GRULE_FILM_MODE_ENABLE)
                    (void*)MST_GRule_4K2K_FILM_MODE_Main,
#endif
#if (PQ_GRULE_DYNAMIC_CONTRAST_ENABLE)
                    (void*)MST_GRule_4K2K_DYNAMIC_CONTRAST_Main,
#endif
#if (PQ_GRULE_DDR_SELECT_ENABLE == 1)
                    (void*)MST_GRule_4K2K_DDR_SELECT_Main,
#endif
#if (PQ_GRULE_ULTRAT_CLEAR_ENABLE)
                    (void*)MST_GRule_4K2K_ULTRAT_CLEAR_Main,
#endif
#if (PQ_GRULE_PTP_ENABLE == 1)
                    (void*)MST_GRule_4K2K_PTP_Main,
#endif
#if (PQ_GRULE_XVYCC_ENABLE == 1 )
                    (void*)MST_GRule_4K2K_XVYCC_Main,
#endif
#if (PQ_GRULE_GAME_MODE_ENABLE == 1)
                    (void*)MST_GRule_4K2K_GAME_MODE_Main,
#endif
#if (PQ_GRULE_DS_PARAMETERS_ENABLE == 1)
                    (void*)MST_GRule_4K2K_DS_PARAMETERS_Main,
#endif
#if (PQ_GRULE_HDR_ENABLE == 1)
                    (void*)MST_GRule_4K2K_HDR_Main,
#endif
                }
            },
#if PQ_ENABLE_PIP
#if (PQ_ENABLE_PIP_POP_MAIN)
            { // PIP
                (void*)QMAP_4K2K_PIP_Main,
#if (ENABLE_PQ_EX)
                (void*)QMAP_4K2K_PIP_Main_Ex,
#endif
                {
#if (PQ_GRULE_NR_ENABLE)
                    (void*)MST_GRule_4K2K_PIP_NR_Main,
#endif
#if (PQ_GRULE_OSD_BW_ENABLE == 1)
                    (void*)MST_GRule_4K2K_PIP_OSD_BW_Main,
#endif
#if (PQ_GRULE_MPEG_NR_ENABLE)
                    (void*)MST_GRule_4K2K_PIP_MPEG_NR_Main,
#endif
#if (PQ_GRULE_FILM_MODE_ENABLE)
                    (void*)MST_GRule_4K2K_PIP_FILM_MODE_Main,
#endif
#if (PQ_GRULE_DYNAMIC_CONTRAST_ENABLE)
                    (void*)MST_GRule_4K2K_PIP_DYNAMIC_CONTRAST_Main,
#endif
#if (PQ_GRULE_DDR_SELECT_ENABLE == 1)
                    (void*)MST_GRule_4K2K_PIP_DDR_SELECT_Main,
#endif
#if (PQ_GRULE_ULTRAT_CLEAR_ENABLE)
                    (void*)MST_GRule_4K2K_PIP_ULTRAT_CLEAR_Main,
#endif
#if (PQ_GRULE_PTP_ENABLE == 1)
                    (void*)MST_GRule_4K2K_PIP_PTP_Main,
#endif
#if (PQ_GRULE_XVYCC_ENABLE == 1 )
                    (void*)MST_GRule_4K2K_PIP_XVYCC_Main,
#endif
#if (PQ_GRULE_GAME_MODE_ENABLE == 1)
                    (void*)MST_GRule_4K2K_PIP_GAME_MODE_Main,
#endif
#if (PQ_GRULE_DS_PARAMETERS_ENABLE == 1)
                    (void*)MST_GRule_4K2K_PIP_DS_PARAMETERS_Main,
#endif
#if (PQ_GRULE_HDR_ENABLE == 1)
                    (void*)MST_GRule_4K2K_PIP_HDR_Main,
#endif
                }
            },
            { // POP
                (void*)QMAP_4K2K_POP_Main,
#if (ENABLE_PQ_EX)
                (void*)QMAP_4K2K_POP_Main_Ex,
#endif
                {
#if (PQ_GRULE_NR_ENABLE)
                    (void*)MST_GRule_4K2K_POP_NR_Main,
#endif
#if (PQ_GRULE_OSD_BW_ENABLE == 1)
                    (void*)MST_GRule_4K2K_POP_OSD_BW_Main,
#endif
#if (PQ_GRULE_MPEG_NR_ENABLE)
                    (void*)MST_GRule_4K2K_POP_MPEG_NR_Main,
#endif
#if (PQ_GRULE_FILM_MODE_ENABLE)
                    (void*)MST_GRule_4K2K_POP_FILM_MODE_Main,
#endif
#if (PQ_GRULE_DYNAMIC_CONTRAST_ENABLE)
                    (void*)MST_GRule_4K2K_POP_DYNAMIC_CONTRAST_Main,
#endif
#if (PQ_GRULE_DDR_SELECT_ENABLE == 1)
                    (void*)MST_GRule_4K2K_POP_DDR_SELECT_Main,
#endif
#if (PQ_GRULE_ULTRAT_CLEAR_ENABLE)
                    (void*)MST_GRule_4K2K_POP_ULTRAT_CLEAR_Main,
#endif
#if (PQ_GRULE_PTP_ENABLE == 1)
                    (void*)MST_GRule_4K2K_POP_PTP_Main,
#endif
#if (PQ_GRULE_XVYCC_ENABLE == 1 )
                    (void*)MST_GRule_4K2K_POP_XVYCC_Main,
#endif
#if (PQ_GRULE_GAME_MODE_ENABLE == 1)
                    (void*)MST_GRule_4K2K_POP_GAME_MODE_Main,
#endif
#if (PQ_GRULE_DS_PARAMETERS_ENABLE == 1)
                    (void*)MST_GRule_4K2K_POP_DS_PARAMETERS_Main,
#endif
#if (PQ_GRULE_HDR_ENABLE == 1)
                    (void*)MST_GRule_4K2K_POP_HDR_Main,
#endif
                }
            },
#endif
#endif
    },
#endif
};

#if PQ_ENABLE_PIP
QMAP_TBL_INIT_INFO QmapTblInitInfo_Sub[QMAP_TABLE_PANEL_NUMBER][QMAP_TABLE_DISPLAY_NUMBER] = {
    { // 1920
        { // ONE
            (void*)QMAP_1920_Sub,
#if (ENABLE_PQ_EX)
            (void*)QMAP_1920_Sub_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_1920_NR_Sub,
#endif
            }
        },
#if (PQ_ENABLE_PIP_POP_SUB)
        { // PIP
            (void*)QMAP_1920_PIP_Sub,
#if (ENABLE_PQ_EX)
            (void*)QMAP_1920_PIP_Sub_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_1920_PIP_NR_Sub,
#endif
            }
        },
        { // POP
            (void*)QMAP_1920_POP_Sub,
#if (ENABLE_PQ_EX)
            (void*)QMAP_1920_POP_Sub_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_1920_POP_NR_Sub,
#endif
            }
        },
#endif
    },
    { // 1366
        { // ONE
            (void*)QMAP_1366_Sub,
#if (ENABLE_PQ_EX)
            (void*)QMAP_1366_Sub_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_1366_NR_Sub,
#endif
            }
        },
#if (PQ_ENABLE_PIP_POP_SUB)
        { // PIP
            (void*)QMAP_1366_PIP_Sub,
#if (ENABLE_PQ_EX)
            (void*)QMAP_1366_PIP_Sub_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_1366_PIP_NR_Sub,
#endif
            }
        },
        { // POP
            (void*)QMAP_1366_POP_Sub,
#if (ENABLE_PQ_EX)
            (void*)QMAP_1366_POP_Sub_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_1366_POP_NR_Sub,
#endif
            }
        },
#endif
    },
#if PQ_SUPPORT_HDMI_4K2K_P2P
    { // 4K2K
        { // ONE
            (void*)QMAP_4K2K_Sub,
#if (ENABLE_PQ_EX)
            (void*)QMAP_4K2K_Sub_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_4K2K_NR_Sub,
#endif
            }
        },
#if(PQ_ENABLE_PIP_POP_SUB)
        { // PIP
            (void*)QMAP_4K2K_PIP_Sub,
#if (ENABLE_PQ_EX)
            (void*)QMAP_4K2K_PIP_Sub_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_4K2K_PIP_NR_Sub,
#endif
            }
        },
        { // POP
            (void*)QMAP_4K2K_POP_Sub,
#if (ENABLE_PQ_EX)
            (void*)QMAP_4K2K_POP_Sub_Ex,
#endif
            {
#if (PQ_GRULE_NR_ENABLE)
                (void*)MST_GRule_4K2K_POP_NR_Sub,
#endif
            }
        },
#endif
    },
#endif
};
#endif

static MS_U8 _MDrv_PQ_Get_PanelIndexByDisplayWidth(MS_U16 u16DisplayWidth)
{
    MS_U8 u8PanelIndex = 0;

    switch(u16DisplayWidth)
    {
        case 1366:
            u8PanelIndex = PQ_BIN_PNLTYPE_1366;
            break;
        case 3840:
            u8PanelIndex = PQ_BIN_PNLTYPE_4K2K;
            break;
        case 1920:
        default:
            u8PanelIndex = PQ_BIN_PNLTYPE_1920;
            break;
    }
    return u8PanelIndex;
}

static MS_BOOL _MDrv_PQ_Set_DisplayType_Main(void *pInstance,MS_U16 u16DisplayWidth, PQ_DISPLAY_TYPE enDisplaType, MS_BOOL bSkipCommTable)
{
#if (PQ_ENABLE_PIP_POP_MAIN)
    MS_U8 u8PanelIndex = 0;
    PQTABLE_INFO PQTableInfo;
    PQTABLE_INFO PQTableInfoEx;

    memset(&PQTableInfo, 0, sizeof(PQTABLE_INFO));
    memset(&PQTableInfoEx, 0, sizeof(PQTABLE_INFO));

    u8PanelIndex = _MDrv_PQ_Get_PanelIndexByDisplayWidth(u16DisplayWidth);

    PQTableInfo.pQuality_Map_Aray = (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pQuality_Map_Aray;
#if (PQ_GRULE_NR_ENABLE)
    PQTableInfo.pGRule_Level[E_GRULE_NR] =
        (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pGRule_Level[E_GRULE_NR];
#endif
#if (PQ_GRULE_MPEG_NR_ENABLE)
    PQTableInfo.pGRule_Level[E_GRULE_MPEG_NR] =
        (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pGRule_Level[E_GRULE_MPEG_NR];
#endif
#if (PQ_GRULE_FILM_MODE_ENABLE)
    PQTableInfo.pGRule_Level[E_GRULE_FilmMode] =
        (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pGRule_Level[E_GRULE_FilmMode];
#endif
#if (PQ_GRULE_DYNAMIC_CONTRAST_ENABLE)
    PQTableInfo.pGRule_Level[E_GRULE_DynContr] =
        (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pGRule_Level[E_GRULE_DynContr];
#endif
#if (PQ_GRULE_ULTRAT_CLEAR_ENABLE)
    PQTableInfo.pGRule_Level[E_GRULE_ULTRACLEAR] =
        (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pGRule_Level[E_GRULE_ULTRACLEAR];
#endif
#if (PQ_GRULE_DDR_SELECT_ENABLE == 1)
    PQTableInfo.pGRule_Level[E_GRULE_DDR_SELECT] =
        (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pGRule_Level[E_GRULE_DDR_SELECT];
#endif
#if (PQ_GRULE_OSD_BW_ENABLE == 1)
    PQTableInfo.pGRule_Level[E_GRULE_OSD_BW] =
        (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pGRule_Level[E_GRULE_OSD_BW];
#endif
#if (PQ_GRULE_PTP_ENABLE == 1)
    PQTableInfo.pGRule_Level[E_GRULE_PTP] =
        (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pGRule_Level[E_GRULE_PTP];
#endif
#if (PQ_GRULE_XVYCC_ENABLE == 1 )
    PQTableInfo.pGRule_Level[E_GRULE_XVYCC] =
        (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pGRule_Level[E_GRULE_XVYCC];
#endif
#if (PQ_GRULE_GAME_MODE_ENABLE == 1)
    PQTableInfo.pGRule_Level[E_GRULE_GAME_MODE] =
        (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pGRule_Level[E_GRULE_GAME_MODE];
#endif
#if (PQ_GRULE_DS_PARAMETERS_ENABLE == 1)
    PQTableInfo.pGRule_Level[E_GRULE_DS_PARAMETERS] =
        (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pGRule_Level[E_GRULE_DS_PARAMETERS];
#endif
#if (PQ_GRULE_HDR_ENABLE == 1)
    PQTableInfo.pGRule_Level[E_GRule_HDR_Main] =
        (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pGRule_Level[E_GRule_HDR_Main];
#endif


    // table config parameter
    PQTableInfo.u8PQ_InputType_Num = QM_INPUTTYPE_NUM_Main;
    PQTableInfo.u16PQ_IP_Num = PQ_IP_NUM_Main;
    PQTableInfo.pIPTAB_Info = (void*)PQ_IPTAB_INFO_Main;
    PQTableInfo.pSkipRuleIP = (void*)MST_SkipRule_IP_Main;

    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_HSD] = PQ_HSDRule_IP_NUM_Main;
    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_VSD] = PQ_VSDRule_IP_NUM_Main;
    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_HSP] = PQ_HSPRule_IP_NUM_Main;
    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_VSP] = PQ_VSPRule_IP_NUM_Main;
#if defined(PQ_XRULE_CSC_ENABLE) && (PQ_XRULE_CSC_ENABLE==1)
    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_CSC] = PQ_CSCRule_IP_NUM_Main;
#endif
#if (PQ_XRULE_DB_ENABLE == 1)
    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_DB_NTSC] = PQ_DBRule_NTSC_IP_NUM_Main;
    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_DB_PAL]  = PQ_DBRule_PAL_IP_NUM_Main;
#endif

    PQTableInfo.pXRule_IP_Index[E_XRULE_HSD] = (void*)MST_HSDRule_IP_Index_Main;
    PQTableInfo.pXRule_IP_Index[E_XRULE_VSD] = (void*)MST_VSDRule_IP_Index_Main;
    PQTableInfo.pXRule_IP_Index[E_XRULE_HSP] = (void*)MST_HSPRule_IP_Index_Main;
    PQTableInfo.pXRule_IP_Index[E_XRULE_VSP] = (void*)MST_VSPRule_IP_Index_Main;
#if defined(PQ_XRULE_CSC_ENABLE) && (PQ_XRULE_CSC_ENABLE==1)
    PQTableInfo.pXRule_IP_Index[E_XRULE_CSC] = (void*)MST_CSCRule_IP_Index_Main;
#endif
#if (PQ_XRULE_DB_ENABLE == 1)
    PQTableInfo.pXRule_IP_Index[E_XRULE_DB_NTSC] = (void*)MST_DBRule_NTSC_IP_Index_Main;
    PQTableInfo.pXRule_IP_Index[E_XRULE_DB_PAL]  = (void*)MST_DBRule_PAL_IP_Index_Main;
#endif

    PQTableInfo.pXRule_Array[E_XRULE_HSD] = (void*)MST_HSDRule_Array_Main;
    PQTableInfo.pXRule_Array[E_XRULE_VSD] = (void*)MST_VSDRule_Array_Main;
    PQTableInfo.pXRule_Array[E_XRULE_HSP] = (void*)MST_HSPRule_Array_Main;
    PQTableInfo.pXRule_Array[E_XRULE_VSP] = (void*)MST_VSPRule_Array_Main;
#if defined(PQ_XRULE_CSC_ENABLE) && (PQ_XRULE_CSC_ENABLE==1)
    PQTableInfo.pXRule_Array[E_XRULE_CSC] = (void*)MST_CSCRule_Array_Main;
#endif
#if (PQ_XRULE_DB_ENABLE == 1)
    PQTableInfo.pXRule_Array[E_XRULE_DB_NTSC] = (void*)MST_DBRule_NTSC_Array_Main;
    PQTableInfo.pXRule_Array[E_XRULE_DB_PAL]  = (void*)MST_DBRule_PAL_Array_Main;
#endif

    PQTableInfo.u8PQ_GRule_Num[E_GRULE_NR] = PQ_GRULE_NR_NUM_Main;
    PQTableInfo.u8PQ_GRule_IPNum[E_GRULE_NR] = PQ_GRULE_NR_IP_NUM_Main;
    PQTableInfo.pGRule_IP_Index[E_GRULE_NR] = (void*)MST_GRule_NR_IP_Index_Main;
    PQTableInfo.pGRule_Array[E_GRULE_NR] = (void*)MST_GRule_NR_Main;
#if (PQ_GRULE_MPEG_NR_ENABLE)
    PQTableInfo.u8PQ_GRule_Num[E_GRULE_MPEG_NR] = PQ_GRULE_MPEG_NR_NUM_Main;
    PQTableInfo.u8PQ_GRule_IPNum[E_GRULE_MPEG_NR] = PQ_GRULE_MPEG_NR_IP_NUM_Main;
    PQTableInfo.pGRule_IP_Index[E_GRULE_MPEG_NR] = (void*)MST_GRule_MPEG_NR_IP_Index_Main;
    PQTableInfo.pGRule_Array[E_GRULE_MPEG_NR] = (void*)MST_GRule_MPEG_NR_Main;
#endif

#if (PQ_GRULE_FILM_MODE_ENABLE)
    PQTableInfo.u8PQ_GRule_Num[E_GRULE_FilmMode] = PQ_GRULE_FILM_MODE_NUM_Main;
    PQTableInfo.u8PQ_GRule_IPNum[E_GRULE_FilmMode] = PQ_GRULE_FILM_MODE_IP_NUM_Main;
    PQTableInfo.pGRule_IP_Index[E_GRULE_FilmMode] = (void*)MST_GRule_FILM_MODE_IP_Index_Main;
    PQTableInfo.pGRule_Array[E_GRULE_FilmMode] = (void*)MST_GRule_FILM_MODE_Main;
#endif

#if (PQ_GRULE_DYNAMIC_CONTRAST_ENABLE)
    PQTableInfo.u8PQ_GRule_Num[E_GRULE_DynContr] = PQ_GRULE_DYNAMIC_CONTRAST_NUM_Main;
    PQTableInfo.u8PQ_GRule_IPNum[E_GRULE_DynContr] = PQ_GRULE_DYNAMIC_CONTRAST_IP_NUM_Main;
    PQTableInfo.pGRule_IP_Index[E_GRULE_DynContr] = (void*)MST_GRule_DYNAMIC_CONTRAST_IP_Index_Main;
    PQTableInfo.pGRule_Array[E_GRULE_DynContr] = (void*)MST_GRule_DYNAMIC_CONTRAST_Main;
#endif

#if (PQ_GRULE_ULTRAT_CLEAR_ENABLE)
    PQTableInfo.u8PQ_GRule_Num[E_GRULE_ULTRACLEAR] = PQ_GRULE_ULTRAT_CLEAR_NUM_Main;
    PQTableInfo.u8PQ_GRule_IPNum[E_GRULE_ULTRACLEAR] = PQ_GRULE_ULTRAT_CLEAR_IP_NUM_Main;
    PQTableInfo.pGRule_IP_Index[E_GRULE_ULTRACLEAR] = (void*)MST_GRule_ULTRAT_CLEAR_IP_Index_Main;
    PQTableInfo.pGRule_Array[E_GRULE_ULTRACLEAR] = (void*)MST_GRule_ULTRAT_CLEAR_Main;
#endif

#if (PQ_GRULE_DDR_SELECT_ENABLE == 1)
    PQTableInfo.u8PQ_GRule_Num[E_GRULE_DDR_SELECT] = PQ_GRULE_DDR_SELECT_NUM_Main;
    PQTableInfo.u8PQ_GRule_IPNum[E_GRULE_DDR_SELECT] = PQ_GRULE_DDR_SELECT_IP_NUM_Main;
    PQTableInfo.pGRule_IP_Index[E_GRULE_DDR_SELECT] = (void*)MST_GRule_DDR_SELECT_IP_Index_Main;
    PQTableInfo.pGRule_Array[E_GRULE_DDR_SELECT] = (void*)MST_GRule_DDR_SELECT_Main;
#endif

#if (PQ_GRULE_OSD_BW_ENABLE == 1)
    PQTableInfo.u8PQ_GRule_Num[E_GRULE_OSD_BW] = PQ_GRULE_OSD_BW_NUM_Main;
    PQTableInfo.u8PQ_GRule_IPNum[E_GRULE_OSD_BW] = PQ_GRULE_OSD_BW_IP_NUM_Main;
    PQTableInfo.pGRule_IP_Index[E_GRULE_OSD_BW] = (void*)MST_GRule_OSD_BW_IP_Index_Main;
    PQTableInfo.pGRule_Array[E_GRULE_OSD_BW] = (void*)MST_GRule_OSD_BW_Main;
#endif

#if (PQ_GRULE_PTP_ENABLE == 1)
    PQTableInfo.u8PQ_GRule_Num[E_GRULE_PTP] = PQ_GRULE_PTP_NUM_Main;
    PQTableInfo.u8PQ_GRule_IPNum[E_GRULE_PTP] = PQ_GRULE_PTP_IP_NUM_Main;
    PQTableInfo.pGRule_IP_Index[E_GRULE_PTP] = (void*)MST_GRule_PTP_IP_Index_Main;
    PQTableInfo.pGRule_Array[E_GRULE_PTP] = (void*)MST_GRule_PTP_Main;
#endif

#if (PQ_GRULE_XVYCC_ENABLE == 1 )
    PQTableInfo.u8PQ_GRule_Num[E_GRULE_XVYCC] = PQ_GRULE_XVYCC_NUM_Main;
    PQTableInfo.u8PQ_GRule_IPNum[E_GRULE_XVYCC] = PQ_GRULE_XVYCC_IP_NUM_Main;
    PQTableInfo.pGRule_IP_Index[E_GRULE_XVYCC] = (void*)MST_GRule_XVYCC_IP_Index_Main;
    PQTableInfo.pGRule_Array[E_GRULE_XVYCC] = (void*)MST_GRule_XVYCC_Main;
#endif

#if (PQ_GRULE_GAME_MODE_ENABLE == 1)
    PQTableInfo.u8PQ_GRule_Num[E_GRULE_GAME_MODE] = PQ_GRULE_GAME_MODE_NUM_Main;
    PQTableInfo.u8PQ_GRule_IPNum[E_GRULE_GAME_MODE] = PQ_GRULE_GAME_MODE_IP_NUM_Main;
    PQTableInfo.pGRule_IP_Index[E_GRULE_GAME_MODE] = (void*)MST_GRule_GAME_MODE_IP_Index_Main;
    PQTableInfo.pGRule_Array[E_GRULE_GAME_MODE] = (void*)MST_GRule_GAME_MODE_Main;
#endif
#if (PQ_GRULE_DS_PARAMETERS_ENABLE == 1)
    PQTableInfo.u8PQ_GRule_Num[E_GRULE_DS_PARAMETERS] = PQ_GRULE_DS_PARAMETERS_NUM_Main;
    PQTableInfo.u8PQ_GRule_IPNum[E_GRULE_DS_PARAMETERS] = PQ_GRULE_DS_PARAMETERS_IP_NUM_Main;
    PQTableInfo.pGRule_IP_Index[E_GRULE_DS_PARAMETERS] = (void*)MST_GRule_DS_PARAMETERS_IP_Index_Main;
    PQTableInfo.pGRule_Array[E_GRULE_DS_PARAMETERS] = (void*)MST_GRule_DS_PARAMETERS_Main;
#endif
#if (PQ_GRULE_HDR_ENABLE == 1)
    PQTableInfo.u8PQ_GRule_Num[E_GRule_HDR_Main] = PQ_GRULE_HDR_NUM_Main;
    PQTableInfo.u8PQ_GRule_IPNum[E_GRule_HDR_Main] = PQ_GRULE_HDR_IP_NUM_Main;
    PQTableInfo.pGRule_IP_Index[E_GRule_HDR_Main] = (void*)MST_GRule_HDR_IP_Index_Main;
    PQTableInfo.pGRule_Array[E_GRule_HDR_Main] = (void*)MST_GRule_HDR_Main;
#endif

    MDrv_PQ_AddTable_(MAIN,pInstance, &PQTableInfo);
    if(!bSkipCommTable)
    {
        MDrv_PQ_LoadCommTable_(MAIN,pInstance);
    }

#if (ENABLE_PQ_EX)
    // table config parameter
    PQTableInfoEx = PQTableInfo;

    PQTableInfoEx.u8PQ_InputType_Num = QM_INPUTTYPE_NUM_Main_Ex;
    PQTableInfoEx.u16PQ_IP_Num = PQ_IP_NUM_Main_Ex;
    PQTableInfoEx.pIPTAB_Info = (void*)PQ_IPTAB_INFO_Main_Ex;
    PQTableInfoEx.pSkipRuleIP = (void*)MST_SkipRule_IP_Main_Ex;

    PQTableInfoEx.pQuality_Map_Aray =
        (void*)QmapTblInitInfo_Main[u8PanelIndex][enDisplaType].pQuality_Map_Aray_Ex;

    MDrv_PQ_AddTable_(MAINEX,pInstance, &PQTableInfoEx);
    if(!bSkipCommTable)
    {
        MDrv_PQ_LoadCommTable_(MAINEX,pInstance);
    }
    if((MS_U16)QM_INPUTTYPE_NUM_Main != (MS_U16)QM_INPUTTYPE_NUM_Main_Ex)
    {
        //printf("PQ INPUTTYPE NUM MISMATCH: MAIN != EX");
        //PQ_ASSERT(0);
    }
#endif
#else
    UNUSED(pInstance);
    UNUSED(u16DisplayWidth);
    UNUSED(enDisplaType);
    UNUSED(bSkipCommTable);
#endif
    return TRUE;
}

static MS_BOOL _MDrv_PQ_Set_DisplayType_Sub(void *pInstance,MS_U16 u16DisplayWidth, PQ_DISPLAY_TYPE enDisplaType, MS_BOOL bSkipCommTable)
{
#if PQ_ENABLE_PIP
#if PQ_ENABLE_PIP_POP_SUB
    MS_U8 u8PanelIndex = 0;

    PQTABLE_INFO PQTableInfo;
    PQTABLE_INFO PQTableInfoEx;

    memset(&PQTableInfo, 0, sizeof(PQTABLE_INFO));
    memset(&PQTableInfoEx, 0, sizeof(PQTABLE_INFO));

    u8PanelIndex = _MDrv_PQ_Get_PanelIndexByDisplayWidth(u16DisplayWidth);

    PQTableInfo.pQuality_Map_Aray =
        (void*)QmapTblInitInfo_Sub[u8PanelIndex][enDisplaType].pQuality_Map_Aray;
#if (PQ_GRULE_NR_ENABLE)
    PQTableInfo.pGRule_Level[E_GRULE_NR] =
        (void*)QmapTblInitInfo_Sub[u8PanelIndex][enDisplaType].pGRule_Level[E_GRULE_NR];

#endif

    // table config parameter
    PQTableInfo.u8PQ_InputType_Num = QM_INPUTTYPE_NUM_Sub;
    PQTableInfo.u16PQ_IP_Num = PQ_IP_NUM_Sub;
    PQTableInfo.pIPTAB_Info = (void*)PQ_IPTAB_INFO_Sub;
    PQTableInfo.pSkipRuleIP = (void*)MST_SkipRule_IP_Sub;

    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_HSD] = PQ_HSDRule_IP_NUM_Sub;
    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_VSD] = PQ_VSDRule_IP_NUM_Sub;
    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_HSP] = PQ_HSPRule_IP_NUM_Sub;
    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_VSP] = PQ_VSPRule_IP_NUM_Sub;
#if defined(PQ_XRULE_CSC_ENABLE) && (PQ_XRULE_CSC_ENABLE==1)
    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_CSC] = PQ_CSCRule_IP_NUM_Sub;
#endif
#if (PQ_XRULE_DB_ENABLE == 1)
    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_DB_NTSC] = PQ_DBRule_NTSC_IP_NUM_Sub;
    PQTableInfo.u8PQ_XRule_IP_Num[E_XRULE_DB_PAL] = PQ_DBRule_PAL_IP_NUM_Sub;
#endif

    PQTableInfo.pXRule_IP_Index[E_XRULE_HSD] = (void*)MST_HSDRule_IP_Index_Sub;
    PQTableInfo.pXRule_IP_Index[E_XRULE_VSD] = (void*)MST_VSDRule_IP_Index_Sub;
    PQTableInfo.pXRule_IP_Index[E_XRULE_HSP] = (void*)MST_HSPRule_IP_Index_Sub;
    PQTableInfo.pXRule_IP_Index[E_XRULE_VSP] = (void*)MST_VSPRule_IP_Index_Sub;
#if defined(PQ_XRULE_CSC_ENABLE) && (PQ_XRULE_CSC_ENABLE==1)
    PQTableInfo.pXRule_IP_Index[E_XRULE_CSC] = (void*)MST_CSCRule_IP_Index_Sub;
#endif
#if (PQ_XRULE_DB_ENABLE == 1)
    PQTableInfo.pXRule_IP_Index[E_XRULE_DB_NTSC] = (void*)MST_DBRule_NTSC_IP_Index_Sub;
    PQTableInfo.pXRule_IP_Index[E_XRULE_DB_PAL]  = (void*)MST_DBRule_PAL_IP_Index_Sub;
#endif

    PQTableInfo.pXRule_Array[E_XRULE_HSD] = (void*)MST_HSDRule_Array_Sub;
    PQTableInfo.pXRule_Array[E_XRULE_VSD] = (void*)MST_VSDRule_Array_Sub;
    PQTableInfo.pXRule_Array[E_XRULE_HSP] = (void*)MST_HSPRule_Array_Sub;
    PQTableInfo.pXRule_Array[E_XRULE_VSP] = (void*)MST_VSPRule_Array_Sub;
#if defined(PQ_XRULE_CSC_ENABLE) && (PQ_XRULE_CSC_ENABLE==1)
    PQTableInfo.pXRule_Array[E_XRULE_CSC] = (void*)MST_CSCRule_Array_Sub;
#endif
#if (PQ_XRULE_DB_ENABLE == 1)
    PQTableInfo.pXRule_Array[E_XRULE_DB_NTSC] = (void*)MST_DBRule_NTSC_Array_Sub;
    PQTableInfo.pXRule_Array[E_XRULE_DB_PAL]  = (void*)MST_DBRule_PAL_Array_Sub;
#endif

    PQTableInfo.u8PQ_GRule_Num[E_GRULE_NR] = PQ_GRULE_NR_NUM_Sub;
    PQTableInfo.u8PQ_GRule_IPNum[E_GRULE_NR] = PQ_GRULE_NR_IP_NUM_Sub;
    PQTableInfo.pGRule_IP_Index[E_GRULE_NR] = (void*)MST_GRule_NR_IP_Index_Sub;
    PQTableInfo.pGRule_Array[E_GRULE_NR] = (void*)MST_GRule_NR_Sub;

    MDrv_PQ_AddTable_(SUB,pInstance, &PQTableInfo);
    if(!bSkipCommTable)
    {
        MDrv_PQ_LoadCommTable_(SUB,pInstance);
    }

#if (ENABLE_PQ_EX)
    // table config parameter
    PQTableInfoEx = PQTableInfo;

    PQTableInfoEx.u8PQ_InputType_Num = QM_INPUTTYPE_NUM_Sub_Ex;
    PQTableInfoEx.u16PQ_IP_Num = PQ_IP_NUM_Sub_Ex;
    PQTableInfoEx.pIPTAB_Info = (void*)PQ_IPTAB_INFO_Sub_Ex;
    PQTableInfoEx.pSkipRuleIP = (void*)MST_SkipRule_IP_Sub_Ex;

    PQTableInfoEx.pQuality_Map_Aray =
        (void*)QmapTblInitInfo_Sub[u8PanelIndex][enDisplaType].pQuality_Map_Aray_Ex;

    MDrv_PQ_AddTable_(SUBEX,pInstance, &PQTableInfoEx);
    if(!bSkipCommTable)
    {
        MDrv_PQ_LoadCommTable_(SUBEX,pInstance);
    }
#endif
#endif
#endif
    return TRUE;
}

void MDrv_PQ_Init_DisplayType_U2(void* pInstance,MS_U16 u16DisplayWidth, PQ_DISPLAY_TYPE enDisplaType)
{
    PQ_LEVEL_PRINTF(PQ_DBG_INFO, "enDisplaType=%u, u16DisplayWidth=%u\n", enDisplaType, u16DisplayWidth);
    if(gbPQBinEnable)
    {
        MDrv_PQBin_SetPanelID(pInstance,_MDrv_PQ_Get_PanelIndexByDisplayWidth(u16DisplayWidth));
        MDrv_PQBin_SetDisplayType(pInstance,enDisplaType == PQ_DISPLAY_ONE ? PQ_BIN_DISPLAY_ONE :
                                  enDisplaType == PQ_DISPLAY_PIP ? PQ_BIN_DISPLAY_PIP :
                                  PQ_BIN_DISPLAY_POP);
    }
    else
    {
        MS_BOOL bSkipCommTable = PQ_SKIPCOMMTB_ENABLE;

        _MDrv_PQ_Set_DisplayType_Sub(pInstance,u16DisplayWidth, enDisplaType, bSkipCommTable);
        _MDrv_PQ_Set_DisplayType_Main(pInstance,u16DisplayWidth, enDisplaType, bSkipCommTable);
        gu16DisplayWidth = u16DisplayWidth;
    }
    MDrv_PQBin_GeneralSetPanelIdx(pInstance,PQ_BIN_TMO,(MS_U16)_MDrv_PQ_Get_PanelIndexByDisplayWidth(u16DisplayWidth));
#if (PQ_ENABLE_PIP)
    genDisplayType = PQ_DISPLAY_ONE;
#endif
}
void SYMBOL_WEAK MDrv_PQ_Init_DisplayType(MS_U16 u16DisplayWidth, PQ_DISPLAY_TYPE enDisplaType)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return ;
    }

    stPQ_Init_DisplayType PQArgs;
    PQArgs.u16DisplayWidth = u16DisplayWidth;
    PQArgs.enDisplaType = enDisplaType;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_INIT_DISPLAY_TYPE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}

void MDrv_PQ_Set_DisplayType_U2(void* pInstance,MS_U16 u16DisplayWidth, PQ_DISPLAY_TYPE enDisplaType)
{
    if(enDisplaType != PQ_DISPLAY_ONE)
    {
        _gbSubWin_En = TRUE;
    }
    else
    {
        _gbSubWin_En = FALSE;
    }

    _enPQDisplayType = enDisplaType;

    // QMAP(one, pip, pop) should be the same.
    // we need to handle the differnce between one/pip/pop by Grule, not by summary page.
    // because Qmap is complicatedly related with VD, ADC sampling. It's not simply dumping table.
    // eg. single-->pop, we will load 1920_pop page, but VD won't be re-set again according to
    // new VD sampling setting in Pop Page. So, conflict.
    {
        enDisplaType = PQ_DISPLAY_ONE;
    }

#if (PQ_ENABLE_PIP)
    PQ_LEVEL_PRINTF(PQ_DBG_INFO, "enDisplaType=%u, u16DisplayWidth=%u\n", enDisplaType, u16DisplayWidth);
    if(gbPQBinEnable)
    {
        MDrv_PQBin_SetPanelID(pInstance,_MDrv_PQ_Get_PanelIndexByDisplayWidth(u16DisplayWidth));
        MDrv_PQBin_SetDisplayType(pInstance,PQ_BIN_DISPLAY_ONE);
    }
    else
    {
        MS_BOOL bSkipCommTable = TRUE;

        if((genDisplayType != enDisplaType) || (gu16DisplayWidth != u16DisplayWidth))
        {
            _MDrv_PQ_Set_DisplayType_Sub(pInstance,u16DisplayWidth, enDisplaType, bSkipCommTable);
            _MDrv_PQ_Set_DisplayType_Main(pInstance,u16DisplayWidth, enDisplaType, bSkipCommTable);
            genDisplayType = enDisplaType;
            gu16DisplayWidth = u16DisplayWidth;
        }
    }
    MDrv_PQBin_GeneralSetPanelIdx(pInstance,PQ_BIN_TMO,(MS_U16)_MDrv_PQ_Get_PanelIndexByDisplayWidth(u16DisplayWidth));
#else
    if(gbPQBinEnable)
    {
        UNUSED(u16DisplayWidth);
        UNUSED(enDisplaType);
    }
    else
    {
        MS_BOOL bSkipCommTable = TRUE;

        if((gu16DisplayWidth != u16DisplayWidth))
        {
            _MDrv_PQ_Set_DisplayType_Main(pInstance,u16DisplayWidth, enDisplaType, bSkipCommTable);
            gu16DisplayWidth = u16DisplayWidth;
        }
    }
#endif
}
void SYMBOL_WEAK MDrv_PQ_Set_DisplayType(MS_U16 u16DisplayWidth, PQ_DISPLAY_TYPE enDisplaType)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return ;
    }

    stPQ_Set_DisplayType PQArgs;
    PQArgs.u16DisplayWidth = u16DisplayWidth;
    PQArgs.enDisplaType = enDisplaType;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SET_DISPLAY_TYPE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}

void SYMBOL_WEAK MDrv_PQDS_Update_PanelID(void *pInstance, MS_U16 u16DisplayWidth)
{
    if(u16DisplayWidth <= 1366)
    {
       MDrv_PQBin_SetPanelID(pInstance,_MDrv_PQ_Get_PanelIndexByDisplayWidth(1366));
    }
    else if (u16DisplayWidth == 1920)
    {
        MDrv_PQBin_SetPanelID(pInstance,_MDrv_PQ_Get_PanelIndexByDisplayWidth(1920));
    }
    else if (u16DisplayWidth == 3840)
    {
        MDrv_PQBin_SetPanelID(pInstance,_MDrv_PQ_Get_PanelIndexByDisplayWidth(3840));
    }
    else
    {
        MDrv_PQBin_SetPanelID(pInstance,_MDrv_PQ_Get_PanelIndexByDisplayWidth(1920));
    }

}

MS_BOOL MDrv_PQ_GetMADiFromOSDBWGrule_U2(void* pInstance,PQ_WIN eWindow,
                                           MS_U16 *pu16TabIdx_MADi,
                                           MS_U16 *pu16TabIdx_MADi_Motion)
{
#if PQ_GRULE_OSD_BW_ENABLE
    MS_U16 u16PQ_OSDBWIdx = 0;

    if(eWindow == PQ_MAIN_WINDOW)
    {
    #if (PQ_OSD_BW_VER == 1)
        #if PQ_GRULE_DDR_SELECT_ENABLE
        {
            if(bw_info.u32Miu1MemSize ==0) // 1 DDR
            {
                u16PQ_OSDBWIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_1DDR_On_Main);
                *pu16TabIdx_MADi = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_OSD_BW_Main, u16PQ_OSDBWIdx, 0); // only MADi ip
            }
            else // 2 DDR
            {
                u16PQ_OSDBWIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_2DDR_On_Main);
                *pu16TabIdx_MADi = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_OSD_BW_Main, u16PQ_OSDBWIdx, 0); // only MADi ip
            }
        }
        #else //DDR select disable
        {
            u16PQ_OSDBWIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_On_Main);
            *pu16TabIdx_MADi = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_OSD_BW_Main, u16PQ_OSDBWIdx, 0); // only MADi ip
        }
        #endif
    #elif (PQ_OSD_BW_VER == 2)
        #if PQ_GRULE_DDR_SELECT_ENABLE
        if(bw_info.bDDR2 == FALSE) // DDR 3
        {
             if(MApi_XC_GetMirrorModeTypeEx(MAIN_WINDOW)  != MIRROR_NORMAL)
             {
                 PQMADi_DBG(printf("MDrv_PQ_GetMADiFromGrule_OSDBW_Ver2: DDR3 mirror\n"));
                 u16PQ_OSDBWIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_On_DDR3_Mirror_Main);
                 *pu16TabIdx_MADi = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_OSD_BW_Main, u16PQ_OSDBWIdx, 0); // only MADi ip
             }
             else
             {
                 PQMADi_DBG(printf("MDrv_PQ_GetMADiFromGrule_OSDBW_Ver2: DDR3 non-mirror\n"));
                 u16PQ_OSDBWIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_On_DDR3_Main);
                 *pu16TabIdx_MADi = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_OSD_BW_Main, u16PQ_OSDBWIdx, 0); // only MADi ip
             }
        }
        else // DDR 2
        {
             if(MApi_XC_GetMirrorModeTypeEx(MAIN_WINDOW)  != MIRROR_NORMAL)
             {
                 PQMADi_DBG(printf("MDrv_PQ_GetMADiFromGrule_OSDBW_Ver2: DDR2 mirror\n"));
                 u16PQ_OSDBWIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_On_DDR2_Mirror_Main);
                 *pu16TabIdx_MADi = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_OSD_BW_Main, u16PQ_OSDBWIdx, 0); // only MADi ip
             }
             else
             {
                 PQMADi_DBG(printf("MDrv_PQ_GetMADiFromGrule_OSDBW_Ver2: DDR2 non-mirror\n"));
                 u16PQ_OSDBWIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_OSD_BW_Main, PQ_GRule_Lvl_OSD_BW_On_DDR2_Main);
                 *pu16TabIdx_MADi = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_OSD_BW_Main, u16PQ_OSDBWIdx, 0); // only MADi ip
             }
        }
        #endif
    #endif
    #if (PQ_GRULE_OSD_BW_IP_NUM_Main > 1)
        *pu16TabIdx_MADi_Motion = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_OSD_BW_Main, u16PQ_OSDBWIdx, 1); // Add MADi_Motion ip
    #else
        UNUSED(pu16TabIdx_MADi_Motion);
    #endif
    }
    else
    {
        // TODO: Should sub window need to consider the OSD BW ??
    }
#else
    UNUSED(eWindow);
    UNUSED(pu16TabIdx_MADi_Motion);
    UNUSED(pu16TabIdx_MADi);
#endif

    return TRUE;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_GetMADiFromOSDBWGrule(PQ_WIN eWindow,
                                           MS_U16 *pu16TabIdx_MADi,
                                           MS_U16 *pu16TabIdx_MADi_Motion)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_GetMADiFromOSDBWGrule PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.pu16TabIdx_MADi = pu16TabIdx_MADi;
    PQArgs.pu16TabIdx_MADi_Motion = pu16TabIdx_MADi_Motion;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_GET_MADI_FROM_OSDBW_GRULE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_GetMADiInGeneral_U2(void* pInstance,PQ_WIN eWindow, MS_U16 *pu16TabIdx_MADi, MS_U16 *pu16TabIdx_MADi_Motion)
{
    UNUSED(pu16TabIdx_MADi_Motion);
    UNUSED(pu16TabIdx_MADi);
#if PQ_GRULE_DDR_SELECT_ENABLE
    if(eWindow == PQ_MAIN_WINDOW)
    {
         MS_U16 u16PQ_DDRSELIdx = 0;
#if (PQ_DDR_SELECT_VER == 1)
         if(bw_info.u32Miu1MemSize==0) // 1 DDR
         {
              PQ_LEVEL_PRINTF(PQ_DBG_MADI,"GetMADiInGeneral: 1 DDR\n");
              u16PQ_DDRSELIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_DDR_SELECT_Main, PQ_GRule_Lvl_DDR_SELECT_1DDR_Main);
         }
         else // 2 DDR
         {
              PQ_LEVEL_PRINTF(PQ_DBG_MADI,"GetMADiInGeneral: 2 DDR \n");
              u16PQ_DDRSELIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_DDR_SELECT_Main, PQ_GRule_Lvl_DDR_SELECT_2DDR_Main);
         }
         *pu16TabIdx_MADi = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_DDR_SELECT_Main, u16PQ_DDRSELIdx, 0); // only MADi ip
#elif (PQ_DDR_SELECT_VER == 2)
        if(bw_info.bDDR2 == FALSE) // DDR 3
        {
             if(MApi_XC_GetMirrorModeTypeEx(MAIN_WINDOW)  != MIRROR_NORMAL)
             {
                 PQ_LEVEL_PRINTF(PQ_DBG_MADI,"GetDDRMirrorSelectInfo: DDR3 mirror\n");
                 u16PQ_DDRSELIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_DDR_SELECT_Main, PQ_GRule_Lvl_DDR_SELECT_DDR3_Mirror_Main);
             }
             else
             {
                 PQ_LEVEL_PRINTF(PQ_DBG_MADI,"GetDDRMirrorSelectInfo: DDR3 non-mirror\n");
                 u16PQ_DDRSELIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_DDR_SELECT_Main, PQ_GRule_Lvl_DDR_SELECT_DDR3_Main);
             }
        }
        else // DDR 2
        {
             if(MApi_XC_GetMirrorModeTypeEx(MAIN_WINDOW)  != MIRROR_NORMAL)
             {
                 PQ_LEVEL_PRINTF(PQ_DBG_MADI,"GetDDRMirrorSelectInfo: DDR2 mirror\n");
                 u16PQ_DDRSELIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_DDR_SELECT_Main, PQ_GRule_Lvl_DDR_SELECT_DDR2_Mirror_Main);
             }
             else
             {
                 PQ_LEVEL_PRINTF(PQ_DBG_MADI,"GetDDRMirrorSelectInfo: DDR2 non-mirror\n");
                 u16PQ_DDRSELIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_DDR_SELECT_Main, PQ_GRule_Lvl_DDR_SELECT_DDR2_Main);
             }
        }
        *pu16TabIdx_MADi = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_DDR_SELECT_Main, u16PQ_DDRSELIdx, 0);
        *pu16TabIdx_MADi_Motion = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_DDR_SELECT_Main, u16PQ_DDRSELIdx, 1);
#endif
    }
    else
    {
#if (ENABLE_LITE_SN == 0)
        ST_PQ_IPInfo stIPInfo;
        ST_PQ_IPInfo stUpdatedIPInfo;
        memset(&stIPInfo, 0, sizeof(ST_PQ_IPInfo));
        memset(&stUpdatedIPInfo, 0, sizeof(ST_PQ_IPInfo));
        stIPInfo.u16IPIdx = PQ_IP_MADi_Sub;
        stIPInfo.enPQEngineType = PQ_XC0_STD;
        MHal_PQ_RemappingIP(pInstance, stIPInfo, &stUpdatedIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
         *pu16TabIdx_MADi = MDrv_PQ_GetTableIndex_Ex_U2(pInstance,eWindow, stUpdatedIPInfo.u16IPIdx, stUpdatedIPInfo.enPQEngineType);
#endif
    }
#else //DDR select disable
    ST_PQ_IPInfo stIPInfo;
    ST_PQ_IPInfo stUpdatedIPInfo;
    memset(&stIPInfo, 0, sizeof(ST_PQ_IPInfo));
    memset(&stUpdatedIPInfo, 0, sizeof(ST_PQ_IPInfo));
    if(eWindow == PQ_MAIN_WINDOW)
    {
        stIPInfo.u16IPIdx = PQ_IP_MADi_Main;
        stIPInfo.enPQEngineType = PQ_XC0_STD;
        MHal_PQ_RemappingIP(pInstance, stIPInfo, &stUpdatedIPInfo, TRUE);
        *pu16TabIdx_MADi = MDrv_PQ_GetTableIndex_Ex_U2(pInstance,eWindow, stUpdatedIPInfo.u16IPIdx, stUpdatedIPInfo.enPQEngineType);
#if PQ_GRULE_OSD_BW_ENABLE
        stIPInfo.u16IPIdx = PQ_IP_MADi_Motion_Main;
        stIPInfo.enPQEngineType = PQ_XC0_STD;
        MHal_PQ_RemappingIP(pInstance, stIPInfo, &stUpdatedIPInfo, TRUE);
        *pu16TabIdx_MADi_Motion = MDrv_PQ_GetTableIndex_Ex_U2(pInstance,eWindow, stUpdatedIPInfo.u16IPIdx, stUpdatedIPInfo.enPQEngineType); //y MADi_motion ip
#endif
    }
#if PQ_ENABLE_PIP
    else
    {
        stIPInfo.u16IPIdx = MHal_PQ_Get_IPIndex(eWindow, E_PQ_IP_MADI);
        stIPInfo.enPQEngineType = PQ_XC0_STD;
        MHal_PQ_RemappingIP(pInstance, stIPInfo, &stUpdatedIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
        *pu16TabIdx_MADi = MDrv_PQ_GetTableIndex_Ex_U2(pInstance,eWindow, stUpdatedIPInfo.u16IPIdx,stUpdatedIPInfo.enPQEngineType);

#if PQ_GRULE_OSD_BW_ENABLE
        stIPInfo.u16IPIdx = MHal_PQ_Get_IPIndex(eWindow, E_PQ_IP_MADI_MOTION);
        stIPInfo.enPQEngineType = PQ_XC0_STD;
        MHal_PQ_RemappingIP(pInstance, stIPInfo, &stUpdatedIPInfo, (eWindow == PQ_MAIN_WINDOW)?TRUE:FALSE);
        *pu16TabIdx_MADi_Motion = MDrv_PQ_GetTableIndex_Ex_U2(pInstance,eWindow, stUpdatedIPInfo.u16IPIdx,stUpdatedIPInfo.enPQEngineType); // MADi_motion ip
#endif
    }
#endif
     //printf("$$[%s]:%d, %s, u16TabIdx_MADi=%u\n", __FUNCTION__, __LINE__, eWindow?"SUB":"MAIN", u16TabIdx_MADi);

#endif

#if PQ_GRULE_SLZ_ENABLE
     MS_U16 u16PQ_SLZIdx = 0;
     MS_BOOL bSeamlessZappingEnable;

     if(MApi_XC_GetSeamlessZappingStatus(eWindow, &bSeamlessZappingEnable) == E_APIXC_RET_OK)
     {
        if(bSeamlessZappingEnable)
        {
            if(eWindow == PQ_MAIN_WINDOW)
            {
                 u16PQ_SLZIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_SLZ_Main, PQ_GRule_Lvl_SLZ_On_Main);
                 PQ_LEVEL_PRINTF(PQ_DBG_MADI,"GetMADiInGeneral: Main LSZ =%u\n",u16PQ_SLZIdx);
                 *pu16TabIdx_MADi        = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_SLZ_Main, u16PQ_SLZIdx, 0); //y MADi ip
                 *pu16TabIdx_MADi_Motion = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_SLZ_Main, u16PQ_SLZIdx, 1); //y MADi_motion ip
            }
#if PQ_ENABLE_PIP
            else
            {
                 u16PQ_SLZIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow, PQ_GRule_SLZ_Sub, PQ_GRule_Lvl_SLZ_On_Sub);
                 PQ_LEVEL_PRINTF(PQ_DBG_MADI,"GetMADiInGeneral: Sub LSZ =%u\n",u16PQ_SLZIdx);
                 *pu16TabIdx_MADi        = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_SLZ_Sub, u16PQ_SLZIdx, 0); // MADi ip
                 *pu16TabIdx_MADi_Motion = MDrv_PQ_GetGRule_TableIndex(eWindow, PQ_GRule_SLZ_Sub, u16PQ_SLZIdx, 1); // MADi_motion ip
            }
#endif
        }
        else
        {
            //it's not slz case
        }
     }
     else
     {
         PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"MApi_XC_GetStatusEx () version is incorrect at %s, the code's purpose is not fulfilled.\n",__FILE__);
     }
#else
    UNUSED(pu16TabIdx_MADi_Motion);

#endif

    return TRUE;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_GetMADiInGeneral(PQ_WIN eWindow, MS_U16 *pu16TabIdx_MADi, MS_U16 *pu16TabIdx_MADi_Motion)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_GetMADiInGeneral PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.pu16TabIdx_MADi = pu16TabIdx_MADi;
    PQArgs.pu16TabIdx_MADi_Motion = pu16TabIdx_MADi_Motion;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_GET_MADI_IN_GENERAL, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_Check_PointToPoint_Condition_U2(void* pInstance,XC_SETWIN_INFO *pstXC_SetWin_Info,PQ_WIN eWindow)
{
    UNUSED(eWindow);
    MS_BOOL bRet = FALSE;

#if PQ_GRULE_PTP_ENABLE
    if(pstXC_SetWin_Info == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"pstXC_SetWin_Info == NULL\n");
        return FALSE;
    }
    // HDMI RGB, HDMI YUV444, DVI, VGA.
    // all in progressive mode
    PQ_LEVEL_PRINTF(PQ_DBG_P2P,"----HDMI source=%u, HDMIPacket=%u, RGB=%u, YUV444=%u, VGA=%u, interlace=%u\n",
                                                                                                            (IsSrcTypeHDMI(pstXC_SetWin_Info->enInputSourceType)),
                                                                                                            (_stHDMI_Info[eWindow].bIsHDMI == TRUE),
                                                                                                            (QM_HDMIPC_COLORRGB(PQ_MAIN_WINDOW)),
                                                                                                            (QM_HDMIPC_COLORYUV444(PQ_MAIN_WINDOW)),
                                                                                                            (IsSrcTypeVga(pstXC_SetWin_Info->enInputSourceType)),
                                                                                                            (pstXC_SetWin_Info->bInterlace)
                                                                                                            );
    //at this time, the PQ input source has not been inited. so we use XC_SETWIN_INFO to check
    //we cannot do the PTP when timing size is bigger than panel size
    if((((IsSrcTypeHDMI(pstXC_SetWin_Info->enInputSourceType)) && (_stHDMI_Info[eWindow].bIsHDMI == TRUE) && (QM_HDMIPC_COLORRGB(PQ_MAIN_WINDOW))) ||
         ((IsSrcTypeHDMI(pstXC_SetWin_Info->enInputSourceType)) && (_stHDMI_Info[eWindow].bIsHDMI == TRUE) && (QM_HDMIPC_COLORYUV444(PQ_MAIN_WINDOW))) ||
         ((IsSrcTypeHDMI(pstXC_SetWin_Info->enInputSourceType)) && (_stHDMI_Info[eWindow].bIsHDMI == FALSE) && (QM_HDMIPC_COLORYUV444(PQ_MAIN_WINDOW))) ||
         ((IsSrcTypeHDMI(pstXC_SetWin_Info->enInputSourceType)) && (_stHDMI_Info[eWindow].bIsHDMI == FALSE) && (QM_HDMIPC_COLORRGB(PQ_MAIN_WINDOW))) ||
         (IsSrcTypeVga(pstXC_SetWin_Info->enInputSourceType))) &&
         (!pstXC_SetWin_Info->bInterlace) &&
         ((g_IPanel.Width() >= pstXC_SetWin_Info->stCropWin.width) && (g_IPanel.Height() >= pstXC_SetWin_Info->stCropWin.height) &&
           (eWindow == PQ_MAIN_WINDOW))
         )
    {
        bRet = TRUE;
    }
#else
    UNUSED(pstXC_SetWin_Info);
#endif
    PQ_LEVEL_PRINTF(PQ_DBG_P2P,"Check Point To Point Condition %u\n",bRet);
    return bRet;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_Check_PointToPoint_Condition(XC_SETWIN_INFO *pstXC_SetWin_Info,PQ_WIN eWindow)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_Check_PointToPoint_Condition PQArgs;
    PQArgs.pstXC_SetWin_Info = pstXC_SetWin_Info;
    PQArgs.eWindow = eWindow;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_CHECK_POINT2POINT_CONDITION, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_SetPostCCSOnOff_U2(void* pInstance,PQ_WIN eWindow, MS_BOOL bEnable)
{
#if(PQ_SUPPORT_POSTCCS == 1)
    if (eWindow >= PQ_MAX_WINDOW)
        return FALSE;

    if (bEnable)
    {
        MS_U16 u16TabIdx =0;
        u16TabIdx = MDrv_PQ_GetTableIndex_U2(pInstance,eWindow, PQ_IP_PostCCS_Main);
        #if(ENABLE_PQ_MLOAD)
            MDrv_PQ_Set_MLoadEn(eWindow, TRUE);
        #endif
            MDrv_PQ_LoadTable_U2(pInstance, eWindow, u16TabIdx, PQ_IP_PostCCS_Main);
        #if(ENABLE_PQ_MLOAD)
            MDrv_PQ_Set_MLoadEn(eWindow, FALSE);
        #endif
    }
    else
    {
        #if(ENABLE_PQ_MLOAD)
            MDrv_PQ_Set_MLoadEn(eWindow, TRUE);
        #endif
            MDrv_PQ_LoadTable_U2(pInstance, eWindow, PQ_IP_PostCCS_OFF_Main, PQ_IP_PostCCS_Main);
        #if(ENABLE_PQ_MLOAD)
            MDrv_PQ_Set_MLoadEn(eWindow, FALSE);
        #endif
    }
#endif

    return TRUE;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_SetPostCCSOnOff(PQ_WIN eWindow, MS_BOOL bEnable)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_SetPostCCSOnOff PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.bEnable = bEnable;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SET_POSTCCS_ONOFF, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

void MDrv_PQ_AdaptiveTuning_U2(void* pInstance)
{
    Hal_PQ_AdaptiveTuning(pInstance);
}
void SYMBOL_WEAK MDrv_PQ_AdaptiveTuning(void)
{
    if (pu32PQInst == NULL)
    {
        if(UtopiaOpen(MODULE_PQ , &pu32PQInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"UtopiaOpen PQ failed\n");
            return ;
        }
    }

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_ADAPTIVE_TUNING, NULL) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}
#ifdef UFO_XC_PQ_SUPPORT_SWDRIVING_MULTI_DEVICES
void SYMBOL_WEAK MDrv_PQ_EX_AdaptiveTuning(PQ_DEVICE_ID *pDeviceId)
{
    if (pDeviceId->u32Id == 1)
    {
        //need add a PQ_device_1 instance
        return ;
    }

    if (pu32PQInst == NULL)
    {
        if(UtopiaOpen(MODULE_PQ , &pu32PQInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"UtopiaOpen PQ failed\n");
            return ;
        }
    }

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_ADAPTIVE_TUNING, NULL) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}
#endif

void MDrv_PQ_AdaptiveTuningByClient_U2(void* pInstance, PQ_ADAPTIVE_TUNING_CLIENT enClient)
{
    switch(enClient)
    {
        case PQ_ADAPTIVE_TUNING_CLIENT_SCALER:
            Hal_PQ_AdaptiveTuning(pInstance);
            break;
        default:
            break;
    }
}
void SYMBOL_WEAK MDrv_PQ_AdaptiveTuningByClient(PQ_ADAPTIVE_TUNING_CLIENT enClient)
{
    if (pu32PQInst == NULL)
    {
        if(UtopiaOpen(MODULE_PQ , &pu32PQInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"UtopiaOpen PQ failed\n");
            return ;
        }
    }

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_ADAPTIVE_TUNING_BY_CLIENT, NULL) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}


void MDrv_PQ_FilmMode_AnyCandence_Enable_U2(void* pInstance,MS_BOOL bEnable)
{
    Hal_PQ_FilmMode_AnyCandence_Enable(pInstance,bEnable);
}
void SYMBOL_WEAK MDrv_PQ_FilmMode_AnyCandence_Enable(MS_BOOL bEnable)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return ;
    }

    stPQ_FilmMode_AnyCandence_Enable PQArgs;
    PQArgs.bEnable = bEnable;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_FILMMODE_ANYCANDENCE_ENABLE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return ;
    }
    else
    {
        return ;
    }
}

MS_BOOL MDrv_PQ_SetH264_OnOff_U2(void* pInstance,MS_BOOL bEn)
{
    _gIsH264 = bEn;
    return TRUE;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_SetH264_OnOff(MS_BOOL bEn)
{
    if (pu32PQInst == NULL)
    {
        if(UtopiaOpen(MODULE_PQ , &pu32PQInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"UtopiaOpen PQ failed\n");
            return FALSE;
        }
    }

    stPQ_SetH264_OnOff PQArgs;
    PQArgs.bEn = bEn;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SETH264_ONOFF, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_SetG3D_OnOff_U2(void* pInstance,MS_BOOL bEn)
{
    _gbIsG3D = bEn;
    return TRUE;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_SetG3D_OnOff(MS_BOOL bEn)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_SetG3D_OnOff PQArgs;
    PQArgs.bEn = bEn;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SETG3D_ONOFF, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_SetMVC4kx1k_OnOff_U2(void* pInstance,MS_BOOL bEn)
{
    _gIsMVC4kx1k = bEn;
    return TRUE;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_SetMVC4kx1k_OnOff(MS_BOOL bEn)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_SetMVC4kx1k_OnOff PQArgs;
    PQArgs.bEn = bEn;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SETMVC4KX1K_ONOFF, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_SetNetworkMM_OnOff_U2(void* pInstance,MS_BOOL bEn)
{
    _gIsNetworkMM = bEn;
    return TRUE;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_SetNetworkMM_OnOff(MS_BOOL bEn)
{
    if (pu32PQInst == NULL)
    {
        if(UtopiaOpen(MODULE_PQ , &pu32PQInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"UtopiaOpen PQ failed\n");
            return FALSE;
        }
    }

    stPQ_SetNetworkMM_OnOff PQArgs;
    PQArgs.bEn = bEn;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SET_NETWORKMM_ONOFF, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_SetMM_OnOff_U2(void* pInstance,MS_BOOL bEn)
{
    _gIsMMplayer = bEn;
    return TRUE;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_SetMM_OnOff(MS_BOOL bEn)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_SetMM_OnOff PQArgs;
    PQArgs.bEn = bEn;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SETMM_ONOFF, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_SetRmvb_OnOff_U2(void* pInstance,MS_BOOL bEn, PQ_WIN ePQWindow)
{
    _gIsRmvb[ePQWindow] = bEn;
    return TRUE;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_SetRmvb_OnOff(MS_BOOL bEn, PQ_WIN ePQWindow)
{
    if (pu32PQInst == NULL)
    {
        if(UtopiaOpen(MODULE_PQ , &pu32PQInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"UtopiaOpen PQ failed\n");
            return FALSE;
        }
    }

    stPQ_SetRmvb_OnOff PQArgs;
    PQArgs.bEn = bEn;
    PQArgs.ePQWindow = ePQWindow;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SET_RMVB_ONOFF, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_Set1KTravelingEnable_U2(void* pInstance,MS_BOOL bEn)
{
    _gIs1KTraveling = bEn;
    return TRUE;
}

MS_BOOL MDrv_PQ_Set1KTravelingEnable(MS_BOOL bEn)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_Set1KTravelingEnable PQArgs;
    PQArgs.bEn = bEn;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SET_1KTRAVELINGENABLE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_SetVIPBypass_OnOff_U2(void* pInstance,MS_BOOL bEnable, PQ_WIN eWindow)
{
    if (eWindow == PQ_MAIN_WINDOW)
    {
#if PQ_VIP_CTL
#if(ENABLE_PQ_MLOAD)
        MDrv_PQ_Set_MLoadEn(eWindow, TRUE);
#endif
        if(bEnable)
        {
#if PQ_VIP_OFF_MINUS16
            if(MDrv_PQ_IsForceVideoInputMode_U2(pInstance, PQ_MAIN_WINDOW) == TRUE
               || MApi_XC_IsYUVSpace(MAIN_WINDOW) == TRUE)
            {
                MDrv_PQ_LoadTable_U2(pInstance, PQ_MAIN_WINDOW, PQ_IP_VIP_OFF_Minus16_Main, PQ_IP_VIP_Main);
            }
            else
            {
                MDrv_PQ_LoadTable_U2(pInstance, PQ_MAIN_WINDOW, PQ_IP_VIP_OFF_Main, PQ_IP_VIP_Main);
            }
#else
            MDrv_PQ_LoadTable_U2(pInstance, PQ_MAIN_WINDOW, PQ_IP_VIP_OFF_Main, PQ_IP_VIP_Main);
#endif
        }
        else
        {
            MDrv_PQ_LoadTable_U2(pInstance, PQ_MAIN_WINDOW, PQ_IP_VIP_ON_Main, PQ_IP_VIP_Main);
        }
#if(ENABLE_PQ_MLOAD)
        MDrv_PQ_Set_MLoadEn(eWindow, FALSE);
#endif
#endif
    }
    else if (eWindow == PQ_SUB_WINDOW)
    {
        //none
    }
    else
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Invalid window type, please check ! \n");
        return FALSE;
    }

    return TRUE;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_SetVIPBypass_OnOff(MS_BOOL bEnable, PQ_WIN eWindow)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_SetVIPBypass_OnOff PQArgs;
    PQArgs.bEnable = bEnable;
    PQArgs.eWindow = eWindow;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SET_VIPBYPASS_ONOFF, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_SetPeaking_OnOff_U2(void* pInstance,MS_BOOL bEnable, PQ_WIN eWindow)
{
    if (eWindow == PQ_MAIN_WINDOW)
    {
        MApi_XC_W2BYTEMSK(REG_SC_BK19_10_L, bEnable, 0x0001);
    }
    else if (eWindow == PQ_SUB_WINDOW)
    {
        MApi_XC_W2BYTEMSK(REG_SC_BK19_14_L, bEnable, 0x0001);
    }
    else
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Invalid window type, please check ! \n");
        return FALSE;
    }
    return TRUE;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_SetPeaking_OnOff(MS_BOOL bEnable, PQ_WIN eWindow)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_SetPeaking_OnOff PQArgs;
    PQArgs.bEnable = bEnable;
    PQArgs.eWindow = eWindow;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SET_PEAKING_ONOFF, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_SetFakeOutEnable_U2(void* pInstance,MS_BOOL bEnable)
{
    return Hal_PQ_SetFakeOutEnable(pInstance,bEnable);
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_SetFakeOutEnable(MS_BOOL bEnable)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_SetFakeOutEnable PQArgs;
    PQArgs.bEnable = bEnable;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_SET_FAKE_OUT_ENABLE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

MS_BOOL MDrv_PQ_SetBinInfo(MS_U32 PQBIN_Size, char *PQBin_Path, PQ_BIN_TYPE enPQBinType)
{
    if(enPQBinType>= MAX_PQ_BIN_NUM)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"enPQBinType >= MAX_PQ_BIN_NUM\n");
        return FALSE;
    }
    if(PQBin_Path == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"PQBin_Path == NULL\n");
        return FALSE;
    }
    if(strlen(PQBin_Path) > PQ_FILE_NAME_LENGTH)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"PQBin_Path Len Overflow Size %tu\n",(ptrdiff_t)strlen(PQBin_Path));
        return FALSE;
    }

     switch(enPQBinType)
    {
        case PQ_BIN_STD_MAIN:
        {
            MITestBinInfo[PQ_BIN_STD_MAIN].u32MIPQBIN_Size = PQBIN_Size;
            strncpy(MITestBinInfo[PQ_BIN_STD_MAIN].MIPQBin_Path,PQBin_Path,strlen(PQBin_Path));
            break;
        }
#if (PQ_ENABLE_PIP ==1)
        case PQ_BIN_STD_SUB:
        {
            MITestBinInfo[PQ_BIN_STD_SUB].u32MIPQBIN_Size = PQBIN_Size;
            strncpy(MITestBinInfo[PQ_BIN_STD_SUB].MIPQBin_Path,PQBin_Path,strlen(PQBin_Path));
            break;
        }
#endif
        case PQ_BIN_EXT_MAIN:
        {
            MITestBinInfo[PQ_BIN_EXT_MAIN].u32MIPQBIN_Size = PQBIN_Size;
            strncpy(MITestBinInfo[PQ_BIN_EXT_MAIN].MIPQBin_Path,PQBin_Path,strlen(PQBin_Path));
            break;
        }
#if (PQ_ENABLE_PIP ==1)
        case PQ_BIN_EXT_SUB:
        {
            MITestBinInfo[PQ_BIN_EXT_SUB].u32MIPQBIN_Size = PQBIN_Size;
            strncpy(MITestBinInfo[PQ_BIN_EXT_SUB].MIPQBin_Path,PQBin_Path,strlen(PQBin_Path));
            break;
        }
#endif
        case PQ_BIN_CUSTOMER_MAIN:
        {
            MITestBinInfo[PQ_BIN_CUSTOMER_MAIN].u32MIPQBIN_Size = PQBIN_Size;
            strncpy(MITestBinInfo[PQ_BIN_CUSTOMER_MAIN].MIPQBin_Path,PQBin_Path,strlen(PQBin_Path));
            break;
        }
#if ((PQ_ENABLE_PIP ==1) && ENABLE_PQ_BIN_CF)
        case PQ_BIN_CUSTOMER_SUB:
        {
            MITestBinInfo[PQ_BIN_CUSTOMER_SUB].u32MIPQBIN_Size = PQBIN_Size;
            strncpy(MITestBinInfo[PQ_BIN_CUSTOMER_SUB].MIPQBin_Path,PQBin_Path,strlen(PQBin_Path));
            break;
        }
#endif
         case PQ_BIN_UFSC:
        {
            MITestBinInfo[PQ_BIN_UFSC].u32MIPQBIN_Size = PQBIN_Size;
            strncpy(MITestBinInfo[PQ_BIN_UFSC].MIPQBin_Path,PQBin_Path,strlen(PQBin_Path));
            break;
        }
#if (ENABLE_PQ_BIN_CF == 1)
        case PQ_BIN_CF_MAIN:
        {
            MITestBinInfo[PQ_BIN_CF_MAIN].u32MIPQBIN_Size = PQBIN_Size;
            strncpy(MITestBinInfo[PQ_BIN_CF_MAIN].MIPQBin_Path,PQBin_Path,strlen(PQBin_Path));
            break;
        }
#if (PQ_ENABLE_PIP ==1)
        case PQ_BIN_CF_SUB:
        {
            MITestBinInfo[PQ_BIN_CF_SUB].u32MIPQBIN_Size = PQBIN_Size;
            strncpy(MITestBinInfo[PQ_BIN_CF_SUB].MIPQBin_Path,PQBin_Path,strlen(PQBin_Path));
            break;
        }
#endif
#endif
        case PQ_BIN_TMO:
        {
            MITestBinInfo[PQ_BIN_TMO].u32MIPQBIN_Size = PQBIN_Size;
            strncpy(MITestBinInfo[PQ_BIN_TMO].MIPQBin_Path,PQBin_Path,strlen(PQBin_Path));
            break;
        }
#if (ENABLE_PQ_BIN_HSY)
        case PQ_BIN_HSY:
        {
            MITestBinInfo[PQ_BIN_HSY].u32MIPQBIN_Size = PQBIN_Size;
            strncpy(MITestBinInfo[PQ_BIN_HSY].MIPQBin_Path,PQBin_Path,strlen(PQBin_Path));
            break;
        }
#endif
        default:
        {
            PQ_LEVEL_PRINTF(PQ_DBG_INFO,"enPQBinType do not Support\n");
            return FALSE;
        }
    }
    PQ_LEVEL_PRINTF(PQ_DBG_INFO,"PQBIN_Size = %u PQBIN_Path = %s\n",MITestBinInfo[enPQBinType].u32MIPQBIN_Size,MITestBinInfo[enPQBinType].MIPQBin_Path);
    return TRUE;
}

#ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT
static MS_BOOL _MDrv_Grule_MITestCase(MS_U8 u8window ,MDBCMD_CMDLINE_PARAMETER* paraCmdLine,MS_U16 u16GRuleType,MS_U16 u16GRuleLevelIndex)
{
    MS_BOOL bReturn = FALSE;

    if(paraCmdLine == NULL)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"paraCmdLine == NULL\n");
        return bReturn;
    }

    if(u16GRuleType > E_PQ_GRULEMAX)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"PQGruleTest_MDrv_Grule_MITestCase u16GRuleType overflow\n");
        return bReturn;
    }
    else
    {
        switch(u16GRuleType)
        {
            case E_PQ_SWDRMODEGRULE:
            {
                if(u16GRuleLevelIndex >E_PQ_SWDR_DLC_OFF)
                {
                    MdbPrint(paraCmdLine->u64ReqHdl,"PQGruleTest_SWDRMODEGRULE u16GRuleLevelIndex overflow\n");
                    bReturn = FALSE;
                }
                else
                {
                    bReturn = MDrv_PQ_LoadSWDRModeGRuleTable((PQ_WIN)u8window,u16GRuleLevelIndex);
                }
                break;
            }
            case E_PQ_TMOMODEGRULE:
            {
                MS_U16 u16Height = QM_GetInputHSize(u8window);
                MS_U16 u16Width = QM_GetInputVSize(u8window);
                if(u16GRuleLevelIndex >E_PQ_HDR_HLG_LOW)
                {
                    MdbPrint(paraCmdLine->u64ReqHdl,"PQGruleTest_TMOMODEGRULE u16GRuleLevelIndex overflow\n");
                    bReturn = FALSE;
                }
                else
                {
                    bReturn = MDrv_PQ_LoadTMOModeGRuleTable((PQ_WIN)u8window,u16GRuleLevelIndex,u16Width,u16Height);
                }
                break;
            }
            case E_PQ_UCDMODEGRULE:
            {
                ST_PQ_UCD_LEVEL stPQUCDLevel;
                memset(&stPQUCDLevel, 0, sizeof(ST_PQ_UCD_LEVEL));
                stPQUCDLevel.u32Version = ST_UCD_LEVEL_VERSION;
                stPQUCDLevel.u32Length =  sizeof(ST_PQ_UCD_LEVEL);
                stPQUCDLevel.enUCDLevel = u16GRuleLevelIndex;
                if(u16GRuleLevelIndex >E_PQ_UCD_HIGH)
                {
                    MdbPrint(paraCmdLine->u64ReqHdl,"PQGruleTest_UCDMODEGRULE u16GRuleLevelIndex overflow\n");
                    bReturn = FALSE;
                }
                else
                {
                    bReturn = MDrv_PQ_LoadUCDModeGRuleTable((PQ_WIN)u8window, &stPQUCDLevel); //version len LevelIndex
                }
                break;
            }
            case E_PQ_ENABLEHDRMODE:
            {
                if(u16GRuleLevelIndex >E_PQ_HDR_HLG_LOW)
                {
                    MdbPrint(paraCmdLine->u64ReqHdl,"PQGruleTest_UCDMODEGRULE u16GRuleLevelIndex overflow\n");
                    bReturn = FALSE;
                }
                else
                {
                    bReturn = MDrv_PQ_EnableHDRMode((PQ_WIN)u8window ,u16GRuleLevelIndex);
                }
                break;
            }
            case E_PQ_ENABLEGAMEMODE:
            {
                void *pInstance=NULL;
                pInstance = UtopiaModuleGetLocalInstantList(MODULE_XC, pInstance);
                switch(u16GRuleLevelIndex)
                {
                    case PQ_GAMEMODE_GRULE_INDEX_ON:
                    {
                        MdbPrint(paraCmdLine->u64ReqHdl,"PQGruleTest_ENABLEGAMEMODE Enable game mode \n");
                        bReturn = MDrv_PQ_SetGameMode((PQ_WIN)u8window,TRUE);
                        break;
                    }
                    case PQ_GAMEMODE_GRULE_INDEX_OFF:
                    {
                        MdbPrint(paraCmdLine->u64ReqHdl,"PQGruleTest_ENABLEGAMEMODE Bypass game mode \n");
                        bReturn = MDrv_PQ_SetGameMode((PQ_WIN)u8window,FALSE);
                        break;
                    }
                    case PQ_GAMEMODE_GRULE_INDEX_LVL0:
                    {
                        MdbPrint(paraCmdLine->u64ReqHdl,"PQGruleTest_GAMEMODE load game mode grule lvl0 \n");
                        bReturn = MDrv_PQ_LoadGameModeGrule(pInstance,(PQ_WIN)u8window ,PQ_GAMEMODE_GRULE_LVL0);
                        break;
                    }
                    case PQ_GAMEMODE_GRULE_INDEX_LVL1:
                    {
                        MdbPrint(paraCmdLine->u64ReqHdl,"PQGruleTest_GAMEMODE load game mode grule lvl1 \n");
                        bReturn = MDrv_PQ_LoadGameModeGrule(pInstance,(PQ_WIN)u8window ,PQ_GAMEMODE_GRULE_LVL1);
                        break;
                    }
                    default:
                    {
                        MdbPrint(paraCmdLine->u64ReqHdl,"PQGruleTest_ENABLEGAMEMODE u16GRuleLevelIndex wrong pls check(0->ON,1->OFF,3->lvl0,4->lvl1)\n");
                        bReturn = FALSE;
                        break;
                    }
                }
                break;
            }
            default:
            {
                bReturn = FALSE;
                break;
            }
        }
    }
    return bReturn;
}

static MS_BOOL _MDrv_PQMdbIoctl_EchoCmd(void *pInstance, MDBCMD_CMDLINE_PARAMETER *paraCmdLine)
{
    static MS_U16 u16Debuglevel = 0;
    MS_BOOL bEnable = FALSE;
    char pch[] = " =\n\r";
    char *pcCmdLine = paraCmdLine->pcCmdLine;
    char* psep;

    ST_PQ_Delay_Info stdelayinfo;
    EN_PQ_DelayTime_Type ePQDelayTime = E_PQ_Delay_DisplayWithPQ;
    EN_PQ_TEST_STATUS enHSYTestResult = E_PQ_TEST_FAIL;
    MS_U16 u16TempPQDbgSwitch = 0;
    memset(&stdelayinfo,0,sizeof(ST_PQ_Delay_Info));
    psep = strsep(&pcCmdLine,pch);
    if(strcmp("DebugLevel", psep) == 0) //DebugLevel
    {
        MS_U16 u16TmpDebuglevel = 0;

        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ERROR", psep) == 0)//Error
        {
            u16TmpDebuglevel = PQ_DBG_ERROR;
        }
        else if(strcmp("INF", psep) == 0)//Info
        {
            u16TmpDebuglevel = PQ_DBG_PQTAB | PQ_DBG_INFO | PQ_DBG_P2P;
        }
        else if(strcmp("GRULE", psep) == 0)//Grule info
        {
            u16TmpDebuglevel = PQ_DBG_GRULE;
        }
        else if(strcmp("XRULE", psep) == 0)//Xrule info
        {
            u16TmpDebuglevel = PQ_DBG_SRULE;
        }
        else if(strcmp("MADI", psep) == 0)//MADI
        {
            u16TmpDebuglevel = PQ_DBG_MADI;
        }
        else if(strcmp("ALL", psep) == 0)
        {
            u16TmpDebuglevel = PQ_DBG_ALL;
        }
        else if(strcmp("OFF", psep) == 0)
        {
            u16TmpDebuglevel = PQ_DBG_OFF;
        }
        else if(strcmp("HSY", psep) == 0)
        {
            u16TmpDebuglevel = PQ_DBG_HSY;
        }
        else if(strcmp("HVSP", psep) == 0)
        {
            u16TmpDebuglevel = PQ_DBG_HVSP;
        }
        else if(strcmp("DELAYTIME", psep) == 0)
        {
            u16TmpDebuglevel = PQ_DBG_DELAYTIME;
        }
        else if(strcmp("CSC", psep) == 0)
        {
            u16TmpDebuglevel = PQ_DBG_CSCRULE;
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Enter Wrong Cmd\n");
        }
        if(u16TmpDebuglevel == PQ_DBG_OFF)
        {
            u16Debuglevel = u16TmpDebuglevel;
        }
        else
        {
            u16Debuglevel |= u16TmpDebuglevel;
        }
        MdbPrint(paraCmdLine->u64ReqHdl,"MDrv_PQ_SetDbgLevel DebugLevel=%d\n",u16Debuglevel);
        MDrv_PQ_SetDbgLevel(u16Debuglevel);
        return TRUE;
    }
    else if(strcmp("PQGruleTest", psep) == 0)// Grule
    {
        MdbPrint(paraCmdLine->u64ReqHdl, "------------------- MTK PQ Grule --------------------\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo GRuleType=3 window=0 leLevelIndex=0\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "GRuleType : 0 SWDRModeGRule ex: echo  PQGruleTest=0 window=0/1 leLevelIndex=0~5 \n");
        MdbPrint(paraCmdLine->u64ReqHdl, "GRuleType : 1 TMOModeGRule ex: echo  PQGruleTest=1 window=0/1 leLevelIndex=0~14\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "GRuleType : 2 UCDModeGRule ex: echo  PQGruleTest=2 window=0/1  leLevelIndex=0~4 \n");
        MdbPrint(paraCmdLine->u64ReqHdl, "GRuleType : 3 EnableHDRMode ex: echo  PQGruleTest=3 window=0/1 leLevelIndex=0~14 \n");
        MdbPrint(paraCmdLine->u64ReqHdl, "GRuleType : 4 EnableGAMEMode ex: echo  PQGruleTest=4 window=0/1 leLevelIndex=0~1(on/off),3~4(Lvl0/Lvl1) \n");


        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        MS_U16 u16GRuleType = (MS_U16)atoi(psep);

        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        MS_U8 u8window = (MS_U8)atoi(psep);

        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        MS_U16 u16GRuleLevelIndex = (MS_U16)atoi(psep);

        if(_MDrv_Grule_MITestCase(u8window,paraCmdLine,u16GRuleType,u16GRuleLevelIndex))
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "PQGruleTest Success\n");
            return TRUE;
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "PQGruleTest Fail\n");
            return FALSE;
        }
    }
    else if (strcmp("LoadBinTest", psep) == 0)//Load Bin test
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if (strcmp("MAIN", psep) == 0)
        {
            psep = strsep(&pcCmdLine,pch);
            if (psep == NULL)
            {
                return FALSE;
            }
            if (strcmp("On", psep) == 0)
            {
                bEnable = TRUE;
            }
            else
            {
                bEnable = FALSE;
            }

            if (bEnable)
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_STD_MAIN, TRUE);
            }
            else
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_STD_MAIN, FALSE);
            }
        }
        else if (strcmp("MAIN_EX", psep) == 0)
        {
            psep = strsep(&pcCmdLine,pch);
            if (psep == NULL)
            {
                return FALSE;
            }
            if (strcmp("On", psep) == 0)
            {
                bEnable = TRUE;
            }
            else
            {
                bEnable = FALSE;
            }

            if (bEnable)
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_EXT_MAIN, TRUE);
            }
            else
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_EXT_MAIN, FALSE);
            }
        }
        else if (strcmp("MAIN_COLOR", psep) == 0)
        {
            psep = strsep(&pcCmdLine,pch);
            if (psep == NULL)
            {
                return FALSE;
            }
            if (strcmp("On", psep) == 0)
            {
                bEnable = TRUE;
            }
            else
            {
                bEnable = FALSE;
            }

            if (bEnable)
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_CUSTOMER_MAIN, TRUE);
            }
            else
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_CUSTOMER_MAIN, FALSE);
            }
        }
        else if (strcmp("UFSC", psep) == 0)
        {
            psep = strsep(&pcCmdLine,pch);
            if (psep == NULL)
            {
                return FALSE;
            }
            if (strcmp("On", psep) == 0)
            {
                bEnable = TRUE;
            }
            else
            {
                bEnable = FALSE;
            }

            if (bEnable)
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_UFSC, TRUE);
            }
            else
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_UFSC, FALSE);
            }
        }
        else if (strcmp("SUB", psep) == 0)
        {
            psep = strsep(&pcCmdLine,pch);
            if (psep == NULL)
            {
                return FALSE;
            }
            if (strcmp("On", psep) == 0)
            {
                bEnable = TRUE;
            }
            else
            {
                bEnable = FALSE;
            }

            if (bEnable)
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_STD_SUB, TRUE);
            }
            else
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_STD_SUB, FALSE);
            }
        }
        else if (strcmp("SUB_EX", psep) == 0)
        {
            psep = strsep(&pcCmdLine,pch);
            if (psep == NULL)
            {
                return FALSE;
            }
            if (strcmp("On", psep) == 0)
            {
                bEnable = TRUE;
            }
            else
            {
                bEnable = FALSE;
            }

            if (bEnable)
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_EXT_SUB, TRUE);
            }
            else
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_EXT_SUB, FALSE);
            }
        }
        else if (strcmp("SUB_COLOR", psep) == 0)
        {
            psep = strsep(&pcCmdLine,pch);
            if (psep == NULL)
            {
                return FALSE;
            }
            if (strcmp("On", psep) == 0)
            {
                bEnable = TRUE;
            }
            else
            {
                bEnable = FALSE;
            }

            if (bEnable)
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_CUSTOMER_SUB, TRUE);
            }
            else
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_CUSTOMER_SUB, FALSE);
            }
        }
        else if (strcmp("MAIN_TMO", psep) == 0)
        {
            psep = strsep(&pcCmdLine,pch);
            if (psep == NULL)
            {
                return FALSE;
            }
            if (strcmp("On", psep) == 0)
            {
                bEnable = TRUE;
            }
            else
            {
                bEnable = FALSE;
            }

            if (bEnable)
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_TMO, TRUE);
            }
            else
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_TMO, FALSE);
            }
        }
        else if (strcmp("HSY", psep) == 0)
        {
            psep = strsep(&pcCmdLine,pch);
            if (psep == NULL)
            {
                return FALSE;
            }
            if (strcmp("On", psep) == 0)
            {
                bEnable = TRUE;
            }
            else
            {
                bEnable = FALSE;
            }

            if (bEnable)
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_HSY, TRUE);
            }
            else
            {
                MDrv_PQ_ReplaceBin(pInstance, PQ_BIN_HSY, FALSE);
            }
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Enter Wrong Cmd\n");
            return FALSE;
        }
        return TRUE;
    }
    else if(strcmp("PQ_LoadDLCLevel", psep) == 0) //PQ_LoadDLCLevel
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }

        if(strcmp("Low", psep) == 0)
        {
            MDrv_PQ_LoadDLCLevelGRuleTable(PQ_MAIN_WINDOW, E_PQ_DLC_LOW);
        }
        else if(strcmp("Middle", psep) == 0)
        {
            MDrv_PQ_LoadDLCLevelGRuleTable(PQ_MAIN_WINDOW, E_PQ_DLC_MID);
        }
        else if(strcmp("High", psep) == 0)
        {
            MDrv_PQ_LoadDLCLevelGRuleTable(PQ_MAIN_WINDOW, E_PQ_DLC_HIGH);
        }
        else if(strcmp("Default", psep) == 0)
        {
            MDrv_PQ_LoadDLCLevelGRuleTable(PQ_MAIN_WINDOW, E_PQ_DLC_DEFAULT);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "PQ_LoadDLCLevel NOT SUPPORTED.\n");
        }
        return TRUE;
    }
    else if (strcmp("LoadPQBin", psep) == 0)// LoadPQBin
    {
        psep = strsep(&pcCmdLine,pch);
        if (psep == NULL)
        {
            return FALSE;
        }
        MS_U16 u16PQBinType = (MS_U16)atoi(psep);

        if (u16PQBinType < MAX_PQ_BIN_NUM)
        {
            if (MITestBinInfo[u16PQBinType].u32MIPQBIN_Size == 0)
            {
                MdbPrint(paraCmdLine->u64ReqHdl,"Not support [%X]\n", u16PQBinType);
            }
            else
            {
                MdbPrint(paraCmdLine->u64ReqHdl,"Support [%X]\n", u16PQBinType);
            }
            return TRUE;
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Not support [%X]\n", u16PQBinType);
            return FALSE;
        }
    }
    else if(strcmp("ProcfsLevel", psep) == 0) //Procfs to Set Level
    {
        EN_PQ_PROCFS_SEL enProcfs = E_PQ_PROCFS_SEL_ASSERT_PANIC;
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if (strcmp("DumpStack", psep) == 0)
        {
            enProcfs = E_PQ_ASSERT_SEL_ASSERT_DUMPSTACK;
        }
        else if (strcmp("Panic", psep) == 0)
        {
            enProcfs = E_PQ_PROCFS_SEL_ASSERT_PANIC;
        }

        MdbPrint(paraCmdLine->u64ReqHdl,"MDrv_PQ_SetProcfsLevel Select=%d\n",enProcfs);
        return MDrv_PQ_SetProcfsLevel(enProcfs);
    }
    else if(strcmp("PQ_FastPlayByMemc", psep) == 0) //PQ_FastPlayByMemc
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }

        if(strcmp("OFF", psep) == 0)
        {
            bEnable = FALSE;
        }
        else if(strcmp("ON", psep) == 0)
        {
            bEnable = TRUE;
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "PQ_FastPlayByMemc NOT SUPPORTED.\n");
            return FALSE;
        }

        return MDrv_PQ_SetFastPlaybyMemcDbg(bEnable);
    }
    else if(strcmp("PQ_LoadEdgeEnhancer", psep) == 0) //PQ_LoadEdgeEnhancer
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        ST_PQ_GENERAL_GRULE stPQGeneralGrule;
        stPQGeneralGrule.u32Version = ST_PQ_GENERAL_GRULE_VERSION;
        stPQGeneralGrule.u32Length = sizeof(ST_PQ_GENERAL_GRULE);
        stPQGeneralGrule.enWindow = PQ_MAIN_WINDOW;

        if(strcmp("OFF", psep) == 0)
        {
            stPQGeneralGrule.enGruleType = E_PQ_GRULE_EDGE_ENHANCER_OFF;
        }
        else if(strcmp("Low", psep) == 0)
        {
            stPQGeneralGrule.enGruleType = E_PQ_GRULE_EDGE_ENHANCER_LOW;
        }
        else if(strcmp("Middle", psep) == 0)
        {
            stPQGeneralGrule.enGruleType = E_PQ_GRULE_EDGE_ENHANCER_MID;
        }
        else if(strcmp("High", psep) == 0)
        {
            stPQGeneralGrule.enGruleType = E_PQ_GRULE_EDGE_ENHANCER_HIGH;
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "PQ_LoadEdgeEnhancer NOT SUPPORTED.\n");
            return FALSE;
        }
        return MDrv_PQ_General_GruleTable(&stPQGeneralGrule);
    }
    else if(strcmp("PQ_LoadABFLevel", psep) == 0) //PQ_LoadABFLevel
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        ST_PQ_GENERAL_GRULE stPQGeneralGrule;
        stPQGeneralGrule.u32Version = ST_PQ_GENERAL_GRULE_VERSION;
        stPQGeneralGrule.u32Length = sizeof(ST_PQ_GENERAL_GRULE);
        stPQGeneralGrule.enWindow = PQ_MAIN_WINDOW;

        if(strcmp("OFF", psep) == 0)
        {
            stPQGeneralGrule.enGruleType = E_PQ_GRULE_ABF_OFF;
        }
        else if(strcmp("Low", psep) == 0)
        {
            stPQGeneralGrule.enGruleType = E_PQ_GRULE_ABF_LOW;
        }
        else if(strcmp("Middle", psep) == 0)
        {
            stPQGeneralGrule.enGruleType = E_PQ_GRULE_ABF_MID;
        }
        else if(strcmp("High", psep) == 0)
        {
            stPQGeneralGrule.enGruleType = E_PQ_GRULE_ABF_HIGH;
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "PQ_ABFLevel NOT SUPPORTED.\n");
            return FALSE;
        }
        return MDrv_PQ_General_GruleTable(&stPQGeneralGrule);
    }
    else if(strcmp("IsSupport_GroupIPBIN", psep) == 0)  // Check Support Get Grule's IP/Group Num from bin
    {
        if(MHal_PQ_Support_GroupIPBIN())
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "Support Get Grule's IP Num and Group Num from Bin File!\n");
            return TRUE;
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "Not Support Get Grule's IP Num and Group Num from Bin File!\n");
            return FALSE;
        }
    }
    else if(strcmp("PQ_LoadBWLE", psep) == 0) //PQ_LoadBWLE
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        ST_PQ_GENERAL_GRULE stPQGeneralGrule;
        memset(&stPQGeneralGrule, 0, sizeof(ST_PQ_GENERAL_GRULE));
        stPQGeneralGrule.u32Version = ST_PQ_GENERAL_GRULE_VERSION;
        stPQGeneralGrule.u32Length = sizeof(ST_PQ_GENERAL_GRULE);
        stPQGeneralGrule.enWindow = PQ_MAIN_WINDOW;

        if(strcmp("OFF", psep) == 0)
        {
            stPQGeneralGrule.enGruleType = E_PQ_GRULE_BWLE_OFF;
        }
        else if(strcmp("Low", psep) == 0)
        {
            stPQGeneralGrule.enGruleType = E_PQ_GRULE_BWLE_LOW;
        }
        else if(strcmp("Middle", psep) == 0)
        {
            stPQGeneralGrule.enGruleType = E_PQ_GRULE_BWLE_MID;
        }
        else if(strcmp("High", psep) == 0)
        {
            stPQGeneralGrule.enGruleType = E_PQ_GRULE_BWLE_HIGH;
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "PQ_LoadBWLE NOT SUPPORTED.\n");
            return FALSE;
        }
        return MDrv_PQ_General_GruleTable(&stPQGeneralGrule);
    }
    else if(strcmp("DNR", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_DNR, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_DNR, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "DNR NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("UCNR", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_UCNR, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_UCNR, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "UCNR NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("ZNR", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_ZNR, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_ZNR, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "ZNR NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("SPF", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_SPF, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_SPF, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "SPF NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("DBK", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_DBK, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_DBK, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "DBK NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("PQ_DMS", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_DMS, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_DMS, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "DMS_12_LINE NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("UCD", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_UCD, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_UCD, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "UCD NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("DLC", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_DLC, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_DLC, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "DLC NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("BWLE", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_BWLE, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_BWLE, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "BWLE NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("SWDR", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_SWDR, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_SWDR, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "SWDR NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("VIP_ALL_BYPASS", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_VIP_ALL_BYPASS, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_VIP_ALL_BYPASS, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "VIP_ALL_BY_PASS NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("HSY", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_HSY, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_HSY, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "HSY NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("COLORENG_CBCR_BYPASS", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_COLORENG_CBCR_BYPASS, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_COLORENG_CBCR_BYPASS, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "COLORENG_CBCR_BY_PASS NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("FCC", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_FCC, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_FCC, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "FCC NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("FWC", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_FWC, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_FWC, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "FWC NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("ABF", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_ABF, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_ABF, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "ABF NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("PRE_CTI", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_PRE_CTI, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_PRE_CTI, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "PRE_CTI NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("POST_CTI", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_POST_CTI, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_POST_CTI, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "POST_CTI NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("SHARPNESS", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_SHARPNESS, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_SHARPNESS, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "SHARPNESS NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("PQ_GAMMA", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_PQ_GAMMA, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_PQ_GAMMA, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "PQ_GAMMA NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("PANEL_GAMMA", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_PANEL_GAMMA, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_PANEL_GAMMA, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "PANEL_GAMMA NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("3D_RGB", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_3D_RGB, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_3D_RGB, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "3D_RGB NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
   else if(strcmp("RGB_GAIN", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_RGB_GAIN, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_RGB_GAIN, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "RGB_GAIN NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
   }
    else if(strcmp("LINEAR_RGB", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_LINEAR_RGB, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_LINEAR_RGB, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "LINEAR_RGB NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("PQ_DRIVER", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_PQ_DRIVER, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_PQ_DRIVER, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "DRIVER NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("SCALING_FILTER", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_SCALING_FILTER, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_SCALING_FILTER, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "SCALING_FILTER NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("BRIGHTNESS", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_BRIGHTNESS, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_BRIGHTNESS, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "BRIGHTNESS NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("RGB_CLIP", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_RGB_CLIP, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_RGB_CLIP, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "RGB_CLIP NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }
    else if(strcmp("MM_TYPE", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        MS_PQ_MuliMedia_Info stMSPQMuliMediaInfo;
        memset(&stMSPQMuliMediaInfo,0,sizeof(MS_PQ_MuliMedia_Info));
        if(strcmp("PHOTO", psep) == 0)
        {
            stMSPQMuliMediaInfo.eType = E_PQ_MULTIMEDIA_PHOTO;
        }
        else if(strcmp("MOVIE", psep) == 0)
        {
            stMSPQMuliMediaInfo.eType = E_PQ_MULTIMEDIA_MOVIE;
        }
        else if(strcmp("NETFLIX", psep) == 0)
        {
            stMSPQMuliMediaInfo.eType = E_PQ_MULTIMEDIA_AMAZON;
        }
        else if(strcmp("AMAZON", psep) == 0)
        {
            stMSPQMuliMediaInfo.eType = E_PQ_MULTIMEDIA_NETFLIX;
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "MM_TYPE NOT SUPPORTED.\n");
            return FALSE;
        }
        MDrv_PQ_Set_MultiMediaInfo(PQ_MAIN_WINDOW,&stMSPQMuliMediaInfo);
        MdbPrint(paraCmdLine->u64ReqHdl, "MM_TYPE = %d\n",_stMultiMedia_Info[PQ_MAIN_WINDOW].eType);
        return TRUE;
    }
    else if(strcmp("PQ_DELAY", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("FULL_PQ_DELAY", psep) == 0)
        {
            ePQDelayTime = E_PQ_Delay_DisplayWithPQ;
        }
        else if(strcmp("FIRST_PQ_DELAY", psep) == 0)
        {
            ePQDelayTime = E_PQ_Delay_FirstFrameOut;
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "NOT SUPPORTED.\n");
            return FALSE;
        }
        u16TempPQDbgSwitch = _u16PQDbgSwitch;
        _u16PQDbgSwitch = PQ_DBG_DELAYTIME;
        MDrv_PQ_GetVideoDelayTime_U2(pInstance,MAIN_WINDOW,ePQDelayTime,stdelayinfo);
        MDrv_PQ_SetDbgLevel(u16TempPQDbgSwitch);
        return TRUE;
    }
    else if(strcmp("PQ_DS", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("NO_BYPASS", psep) == 0)
        {
            _gu16PQDbgXRuleBypass = PQ_DS_NO_BYPASS;
        }
        else if(strcmp("BYPASS_MMDS", psep) == 0)
        {
            _gu16PQDbgXRuleBypass |= PQ_MMDS_XRULE_BYPASS;
        }
        else if(strcmp("BYPASS_SPF", psep) == 0)
        {
            _gu16PQDbgXRuleBypass |= PQ_SPF_XRULE_BYPASS;
        }
        else if(strcmp("BYPASS_HVSP", psep) == 0)
        {
            _gu16PQDbgXRuleBypass |= PQ_HVSP_XRULE_BYPASS;
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Enter Wrong Cmd\n");
        }
        MdbPrint(paraCmdLine->u64ReqHdl,"PQ_RuleByPass _u16PQDbgXRuleBypass=%d\n",_gu16PQDbgXRuleBypass);
        return TRUE;
    }
    else if(strcmp("YMY_TEST", psep) == 0)
    {
        if(_MDrv_PQ_openYMYTestCase())
        {
            Hal_PQ_TestAutodownload(SC_FILTER_Y_SRAM1, &enHSYTestResult);
            MdbPrint(paraCmdLine->u64ReqHdl,"PQ HVSP ADL Y_SRAM1 Test result        : %s\n",( E_PQ_TEST_PASS == enHSYTestResult) ? "PASS":"FAIL");
            enHSYTestResult = E_PQ_TEST_FAIL;
            Hal_PQ_TestAutodownload(SC_FILTER_Y_SRAM2, &enHSYTestResult);
            MdbPrint(paraCmdLine->u64ReqHdl,"PQ HVSP ADL Y_SRAM2 Test result        : %s\n",( E_PQ_TEST_PASS == enHSYTestResult) ? "PASS":"FAIL");
            enHSYTestResult = E_PQ_TEST_FAIL;
            Hal_PQ_TestAutodownload(SC_FILTER_C_SRAM1, &enHSYTestResult);
            MdbPrint(paraCmdLine->u64ReqHdl,"PQ HVSP ADL C_SRAM1 Test result        : %s\n",( E_PQ_TEST_PASS == enHSYTestResult) ? "PASS":"FAIL");
            enHSYTestResult = E_PQ_TEST_FAIL;
            Hal_PQ_TestAutodownload(SC_FILTER_C_SRAM2, &enHSYTestResult);
            MdbPrint(paraCmdLine->u64ReqHdl,"PQ HVSP ADL C_SRAM2 Test result        : %s\n",( E_PQ_TEST_PASS == enHSYTestResult) ? "PASS":"FAIL");
        }
        return TRUE;
    }
    else if(strcmp("HALF_PQ_DELAY", psep) == 0)
    {
        psep = strsep(&pcCmdLine,pch);
        if(psep == NULL)
        {
            return FALSE;
        }
        if(strcmp("ON", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_HALF_PQ_DELAY, TRUE);
        }
        else if(strcmp("OFF", psep) == 0)
        {
            bEnable = MHal_PQ_Function_Control(PQ_MAIN_WINDOW,E_PQ_HALF_PQ_DELAY, FALSE);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl, "HALF_PQ_DELAY NOT SUPPORTED.\n");
            return FALSE;
        }
        return bEnable;
    }

    else if(strcmp("help", psep) == 0) //help
    {
        MdbPrint(paraCmdLine->u64ReqHdl, "------------------- MTK PQ Grule --------------------\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo GRuleType=3 window=0 leLevelIndex=0\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "GRuleType : 0 SWDRModeGRule ex: echo  PQGruleTest=0 window=0/1 leLevelIndex=0~5 \n");
        MdbPrint(paraCmdLine->u64ReqHdl, "GRuleType : 1 TMOModeGRule ex: echo  PQGruleTest=1 window=0/1 leLevelIndex=0~14\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "GRuleType : 2 UCDModeGRule ex: echo  PQGruleTest=2 window=0/1  leLevelIndex=0~4 \n");
        MdbPrint(paraCmdLine->u64ReqHdl, "GRuleType : 3 EnableHDRMode ex: echo  PQGruleTest=3 window=0/1 leLevelIndex=0~14 \n");
        MdbPrint(paraCmdLine->u64ReqHdl, "GRuleType : 4 EnableGAMEMode ex: echo  PQGruleTest=4 window=0/1 leLevelIndex=0~2 \n");
        MdbPrint(paraCmdLine->u64ReqHdl, "------------------- PQ_LoadDLCLevel ------------------\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo PQ_LoadDLCLevel=Low > /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ_LoadDLCLevel=Low/Middle/High/Default\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "------------------- PQ_LoadEdgeEnhancer ------------------\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo PQ_LoadEdgeEnhancer=OFF> /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ_LoadEdgeEnhancer=OFF/Low/Middle/High\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "------------------- PQ_LoadABFLevel ------------------\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo PQ_LoadABFLevel=OFF> /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ_LoadABFLevel=OFF/Low/Middle/High\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "------------------- PQ_FastPlayByMemc ------------------\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo PQ_FastPlayByMemc=OFF> /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ_FastPlayByMemc=OFF/ON\n");

        MdbPrint(paraCmdLine->u64ReqHdl, "------------------- PQ_LoadBinTest  ------------------\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo LoadBinTest MAIN On > /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "Test    MAIN:     echo LoadBinTest MAIN On\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "Test    MAIN_EX:  echo LoadBinTest MAIN_EX On\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "Test    MAIN_TMO: echo LoadBinTest MAIN_TMO On\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "Recover MAIN:     echo LoadBinTest MAIN Off\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "Recover MAIN_EX:  echo LoadBinTest MAIN_EX Off\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "Recover MAIN_TMO: echo LoadBinTest MAIN_TMO Off\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "------------------- PQ_LoadPQBin  ------------------\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo LoadBinTest MAIN On > /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "MAIN:     echo LoadPQBin 0 \n");

        MdbPrint(paraCmdLine->u64ReqHdl, "--------------------- PQ Debug Log -------------------\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ Debug ERROR Log    : ex: echo DebugLevel=ERROR > /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ Debug INF Log      : ex: echo DebugLevel=INF > /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ Debug GRULE Log    : ex: echo DebugLevel=GRULE > /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ Debug XRULE Log    : ex: echo DebugLevel=XRULE > /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ Debug MADI Log     : ex: echo DebugLevel=MADI > /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ Debug ALL Log      : ex: echo DebugLevel=ALL > /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ Debug OFF Log      : ex: echo DebugLevel=OFF > /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ Debug HSY Log      : ex: echo DebugLevel=HSY > /proc/utopia_mdb/pq\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ Debug HVSP Log     : ex: echo DebugLevel=HVSP > /proc/utopia_mdb/pq\n");

        MdbPrint(paraCmdLine->u64ReqHdl, "--------------------- PQ Procfs Select -------------------\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ Procfs Assert Lvl  : ex: echo ProcfsLevel DumpStack > /proc/utopia_mdb/pq\n");

        MdbPrint(paraCmdLine->u64ReqHdl, "--------------------- PQ Get Grule Group/IP num from Bin -------------------\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo IsSupport_GroupIPBIN > /proc/utopia_mdb/pq\n");

        MdbPrint(paraCmdLine->u64ReqHdl, "------------------- PQ  Command --------------------\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "====================DNR====================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo DNR=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "DNR=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "===================UCNR==================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo UCNR=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "UCNR=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================ZNR====================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo ZNR=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ZNR=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================SPF======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo SPF=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "SPF=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "====================DBK====================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo DBK=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "DBK=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "===================PQ_DMS==================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo PQ_DMS=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ_DMS=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================UCD====================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo UCD=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "UCD=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================DLC======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo DLC=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "DLC=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "====================BWLE====================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo BWLE=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "BWLE=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "===================SWDR==================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo SWDR=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "SWDR=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================VIP_ALL_BYPASS====================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo VIP_ALL_BYPASS=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "VIP_ALL_BYPASS=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================COLORENG_CBCR_BYPASS======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo COLORENG_CBCR_BYPASS=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "COLORENG_CBCR_BYPASS=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "====================FCC====================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo FCC=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "FCC=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "===================FWC==================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo FWC=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "FWC=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================ABF====================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo ABF=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ABF=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================PRE_CTI======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo PRE_CTI=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PRE_CTI=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================POST_CTI======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo POST_CTI=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "POST_CTI=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "====================SHARPNESS====================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo SHARPNESS=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "SHARPNESS=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "===================PQ_GAMMA==================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo PQ_GAMMA=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ_GAMMA=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================PANEL_GAMMA====================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo PANEL_GAMMA=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PANEL_GAMMA=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================3D_RGB======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: 3D_RGB=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "3D_RGB=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "====================RGB_Gain====================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo RGB_GAIN=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "RGB_GAIN=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "===================LINEAR_RGB==================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo LINEAR_RGB=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "LINEAR_RGB=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================PQ_DRIVER====================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo PQ_DRIVER=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ_DRIVER=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================SCALING_FILTER======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo SCALING_FILTER=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "SCALING_FILTER=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================BRIGHTNESS======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo BRIGHTNESS=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "BRIGHTNESS=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================RGB_CLIP======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo RGB_CLIP=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "RGB_CLIP=ON/OFF\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================MM_TYPE======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo MM_TYPE=PHOTO\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "MM_TYPE=PHOTO/MOVIE/NETFLIX/AMAZON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================PQ_DELAY======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo PQ_DELAY=FULL_PQ_DELAY\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ_DELAY=FULL_PQ_DELAY/FIRST_PQ_DELAY\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================PQ_RULE_BYPASS======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo PQ_DS=NO_BYPASS\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "PQ_DS=NO_BYPASS/BYPASS_MMDS/BYPASS_SPF/BYPASS_HVSP\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================YMY_TEST======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo YMY_TEST\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "======================HALF_PQ_DELAY======================\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "ex: echo HALF_PQ_DELAY=ON\n");
        MdbPrint(paraCmdLine->u64ReqHdl, "HALF_PQ_DELAY=ON/OFF\n");
        return TRUE;
     }
     else
     {
        MdbPrint(paraCmdLine->u64ReqHdl, "Please Enter procfs echo command!! \n");
        return FALSE;
     }
}

MS_BOOL SYMBOL_WEAK MDrv_PQMdbIoctl_EchoCmd(MDBCMD_CMDLINE_PARAMETER *paraCmdLine)
{
    void *pInstance=NULL;
    pInstance = UtopiaModuleGetLocalInstantList(MODULE_XC, pInstance);

    return _MDrv_PQMdbIoctl_EchoCmd(pInstance, paraCmdLine);
}

static MS_BOOL _MDrv_PQ_openYMYTestCase(void)
{
    return OPEN_PQ_YMY_TEST_CASE;
}

void SYMBOL_WEAK MDrv_PQMdbIoctl_Cat(MDBCMD_GETINFO_PARAMETER *paraGetInfo)
{
    void *pInstance=NULL;
    MS_U8 pStrBinVersion[PQ_BIN_VERSION_LEN] = {0};
    const MS_U8* pu8NotSupportString = "Not support";
    MS_BOOL bIsSuccess = FALSE;
    MS_BOOL bIsSupportSub = PQ_ENABLE_PIP;
    MS_U32 u32SupportZNR = 0;
    ST_PQ_Delay_Info stdelayinfo;
    XC_ApiStatusEx stApiStatusEx;
    PQ_INPUT_SOURCE_TYPE u8InputSrc = PQ_INPUT_SOURCE_NONE;
    MS_PQ_VD_Sampling_Info stPQVDSamplingInfo;
    pInstance = UtopiaModuleGetLocalInstantList(MODULE_PQ, pInstance);

    memset(&stdelayinfo,0,sizeof(ST_PQ_Delay_Info));
    MdbPrint(paraGetInfo->u64ReqHdl,"----------------  MTK PQ Info -----------------\n");
    u8InputSrc = MDrv_PQ_GetInputSourceType(PQ_MAIN_WINDOW);
    memset(&stApiStatusEx, 0, sizeof(stApiStatusEx));
    stApiStatusEx.u16ApiStatusEX_Length = sizeof(XC_ApiStatusEx);
    stApiStatusEx.u32ApiStatusEx_Version = API_STATUS_EX_VERSION;
    MApi_XC_GetStatusEx(&stApiStatusEx, PQ_MAIN_WINDOW);
    MApi_XC_GetChipCaps(E_XC_SUPPORT_ZNR, &u32SupportZNR, sizeof(MS_U32));

    MdbPrint(paraGetInfo->u64ReqHdl,"Source resolution                  : %d_%d_%d_%c\n",QM_GetInputHSize(PQ_MAIN_WINDOW),QM_GetInputVSize(PQ_MAIN_WINDOW),QM_GetInputVFreq(PQ_MAIN_WINDOW),(QM_IsInterlaced(PQ_MAIN_WINDOW)==TRUE)?'I':'P');
    MdbPrint(paraGetInfo->u64ReqHdl,"Display window                     : %d_%d\n",QM_GetDispHSize(PQ_MAIN_WINDOW),QM_GetDispVSize(PQ_MAIN_WINDOW));
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Source type                     : %d\n", QM_InputSourceToIndex(pInstance, PQ_MAIN_WINDOW, u8InputSrc));
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main Panel index                : %d\n", MDrv_PQBin_GetPanelIdx(pInstance));
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main MADI index                 : %d\n", _gu16SetMemfmt_Madi[PQ_MAIN_WINDOW]);
    if(bIsSupportSub)
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub MADI index                  : %d\n",_gu16SetMemfmt_Madi[PQ_SUB_WINDOW]);
    }
    else
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub MADI index                  : Not support\n");
    }
    MdbPrint(paraGetInfo->u64ReqHdl,"TMO Qmap index                     : %d\n", QM_InputSourceToIndex_TMO(pInstance, PQ_MAIN_WINDOW, u8InputSrc));
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ TMO Panel index                 : %d\n", MDrv_PQBin_GeneralGetPanelIdx(pInstance,PQ_BIN_TMO));
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Game Mode Status                : %d\n", MDrv_PQ_GetGameMode_Status_U2(pInstance,PQ_MAIN_WINDOW));
    MdbPrint(paraGetInfo->u64ReqHdl,"Display Delay                      : %d\n", MDrv_PQ_GetVideoDelayTime_U2(pInstance,MAIN_WINDOW,E_PQ_Delay_DisplayWithPQ,stdelayinfo));
    MdbPrint(paraGetInfo->u64ReqHdl,"Frame Out Delay                    : %d\n", MDrv_PQ_GetVideoDelayTime_U2(pInstance,MAIN_WINDOW,E_PQ_Delay_FirstFrameOut,stdelayinfo));

    if(QM_IsSourceVGA(u8InputSrc))
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"Input source type              : VGA\n");
        MdbPrint(paraGetInfo->u64ReqHdl,"ForceRGBin Enable              : %s\n",stApiStatusEx.bForceRGBin?"Enable":"Disable");
    }
    else if(QM_IsSourceHDMI(u8InputSrc))
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"Input source type              : %s\n",_stHDMI_Info[PQ_MAIN_WINDOW].bIsHDMI?"HDMI":"DVI");
        MdbPrint(paraGetInfo->u64ReqHdl,"ForceRGBin Enable              : %s\n",stApiStatusEx.bForceRGBin?"Enable":"Disable");
        MdbPrint(paraGetInfo->u64ReqHdl,"PointToPoint status            : %s\n",MDrv_PQ_Get_PointToPoint(PQ_MAIN_WINDOW)?"Enable":"Disable");
        if(QM_HDMIPC_COLORRGB(PQ_MAIN_WINDOW))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"Color Format is RGB\n");
        }
        else if(QM_HDMIPC_COLORYUV422(PQ_MAIN_WINDOW))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"Color Format is YUV_422\n");
        }
        else if(QM_HDMIPC_COLORYUV444(PQ_MAIN_WINDOW))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"Color Format is YUV_444\n");
        }
        else if(QM_HDMIPC_COLORYUV420(PQ_MAIN_WINDOW))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"Color Format is YUV_420\n");
        }
        else
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"Color Format not set\n");
        }
    }
    else if(QM_IsSourceYPbPr(u8InputSrc))
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"Input source type              : YPBPR\n");
        MdbPrint(paraGetInfo->u64ReqHdl,"u8ModeIndex                    : %d\n",_u8ModeIndex[PQ_MAIN_WINDOW]);

    }
    else if(QM_IsSourceDTV(u8InputSrc))
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"Input source type              : DTV\n");
        MdbPrint(paraGetInfo->u64ReqHdl,"DynamicScaling                 : %s\n",MApi_XC_GetDynamicScalingStatus()?"Enable":"Disable");
        if(QM_IsDTV_MPEG2(PQ_MAIN_WINDOW))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"DTV Type is MPEG2\n");
        }
        else if(QM_IsDTV_H264(PQ_MAIN_WINDOW))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"DTV Type is H264\n");
        }
        else if(QM_IsDTV_IFRAME(PQ_MAIN_WINDOW))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"DTV Type is IFRAME\n");
        }
        else
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"DTV Type not set\n");
        }
    }
    else if(QM_IsSourceMultiMedia(u8InputSrc))
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"Input source type              : MM\n");
        MdbPrint(paraGetInfo->u64ReqHdl,"DynamicScaling                 : %s\n",MApi_XC_GetDynamicScalingStatus()?"Enable":"Disable");
        if(QM_IsMultiMediaMOVIE(PQ_MAIN_WINDOW))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"MM Type is MOVIE\n");
        }
        else if(QM_IsMultiMediaPHOTO(PQ_MAIN_WINDOW))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"MM Type is PHOTO\n");
        }
        else if(QM_IsMultiMediaNetflix(PQ_MAIN_WINDOW))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"MM Type is METFLIX\n");
        }
        else if(QM_IsMultiMediaAmazon(PQ_MAIN_WINDOW))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"MM Type is AMAZON\n");
        }
        else
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"MM Type is not set\n");
        }
    }
    else if(QM_IsSourceScart(u8InputSrc))
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"Input source type              : SCART\n");
        if(QM_IsSourceScartRGB(u8InputSrc,PQ_MAIN_WINDOW))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"Scart RGB\n");
        }
        else
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"Scart CVBS\n");
        }
    }
    else if(QM_IsSourceATV(u8InputSrc))
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"Input source type              : ATV\n");
        if(QM_ISATVStandard_PAL(PQ_MAIN_WINDOW))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"PAL\n");
        }
        else
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"NTSC\n");
        }
    }
    else if(QM_IsSourceSV(u8InputSrc))
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"Input source type              : SV\n");
    }
    else if(QM_IsSourceAV(u8InputSrc))
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"Input source type              : AV\n");
    }
    if(QM_IsSourceVD(u8InputSrc))
    {
        memset(&stPQVDSamplingInfo, 0, sizeof(MS_PQ_VD_Sampling_Info));
        MDrv_PQ_Get_VDSampling_Info(PQ_MAIN_WINDOW,u8InputSrc,QM_GetATVStandard(PQ_MAIN_WINDOW),&stPQVDSamplingInfo);
        if(stPQVDSamplingInfo.eType == PQ_VD_SAMPLING_ON)
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"u16Hstart                   : %d\n",stPQVDSamplingInfo.u16Hstart);
            MdbPrint(paraGetInfo->u64ReqHdl,"u16Vstart                   : %d\n",stPQVDSamplingInfo.u16Vstart);
            MdbPrint(paraGetInfo->u64ReqHdl,"u16Hsize                    : %d\n",stPQVDSamplingInfo.u16Hsize);
            MdbPrint(paraGetInfo->u64ReqHdl,"u16Vsize                    : %d\n",stPQVDSamplingInfo.u16Vsize);
            MdbPrint(paraGetInfo->u64ReqHdl,"u16Htt                      : %d\n",stPQVDSamplingInfo.u16Htt);
        }
    }

    MdbPrint(paraGetInfo->u64ReqHdl,"----------------  MTK PQ Status Info -----------------\n");
    MdbPrint(paraGetInfo->u64ReqHdl,"RW diff count                      : %d\n", (MApi_XC_R2BYTEMSK(REG_SC_BK12_07_L, 0xE000)>>13));
    MdbPrint(paraGetInfo->u64ReqHdl,"Frame count                        : %d\n", MApi_XC_R2BYTEMSK(REG_SC_BK12_19_L, 0x000F));
    MdbPrint(paraGetInfo->u64ReqHdl,"UCM RW diff count                  : %d\n", MHal_PQ_UCMFrameNum());
    MdbPrint(paraGetInfo->u64ReqHdl,"UCM Frame count                    : %d\n", MHal_PQ_UCMRWDiff());
    if(MHal_PQ_IsSupportMADiVR() == TRUE)
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"BitsPerPixel                   : %d\n", MDrv_PQ_VR_R2BYTEMSK(REG_BKF009_09_L,0x00FF));
        MdbPrint(paraGetInfo->u64ReqHdl,"CmpBitsPerPixel                : %d\n", MDrv_PQ_VR_R2BYTEMSK(REG_BKF009_0C_L,0xFF00)>>8);
        MdbPrint(paraGetInfo->u64ReqHdl,"DeInterlaceMode                : %d\n", MDrv_PQ_VR_R2BYTEMSK(REG_BKF009_09_L,0x0700)>>8);
        MdbPrint(paraGetInfo->u64ReqHdl,"FrameCount                     : %d\n", MDrv_PQ_VR_R2BYTEMSK(REG_BKF009_0A_L,0x00FF));
        MdbPrint(paraGetInfo->u64ReqHdl,"PQDelayCount                   : %d\n", MDrv_PQ_VR_R2BYTEMSK(REG_BKF009_0A_L,0xFF00)>>8);
        MdbPrint(paraGetInfo->u64ReqHdl,"FBLevel                        : %d\n", MDrv_PQ_VR_R2BYTEMSK(REG_BKF009_0B_L,0x0300)>>8);
        MdbPrint(paraGetInfo->u64ReqHdl,"OPWriteOffEnable               : %d\n", MDrv_PQ_VR_R2BYTEMSK(REG_BKF009_0C_L,0x1));
    }
    MdbPrint(paraGetInfo->u64ReqHdl,"MADI mode                          : 0x%x\n", MApi_XC_R2BYTE(REG_SC_BK12_01_L));
    MdbPrint(paraGetInfo->u64ReqHdl,"DMS                                : %s\n", (MApi_XC_R2BYTEMSK(REG_SC_BK20_10_L,BIT(4))==BIT(4))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"DNR status                         : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_DNR))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"UCNR status                        : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_UCNR))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"ZNR status                         : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_ZNR))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"SPF status                         : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_SPF))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"DBK status                         : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_DBK))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"DMS status                         : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_DMS))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"UCD status                         : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_UCD))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"DLC status                         : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_DLC))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"BWLE status                        : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_BWLE))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"SWDR status                        : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_SWDR))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"VIP ALL by pass                    : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_VIP_ALL_BYPASS))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"HSY status                         : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_HSY))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"ColorEng CbCr by pass              : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_COLORENG_CBCR_BYPASS))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"FCC status                         : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_FCC))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"FWC status                         : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_FWC))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"ABF status                         : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_ABF))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"Pre CTI status                     : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_PRE_CTI))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"Post CTI status                    : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_POST_CTI))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"Sharpness status                   : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_SHARPNESS))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Gamma status                    : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_PQ_GAMMA))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Gamma Max Value                 : (0x%x, 0x%x, 0x%x)\n", MApi_XC_R2BYTE(REG_SC_BK10_7D_L), MApi_XC_R2BYTE(REG_SC_BK10_7E_L), MApi_XC_R2BYTE(REG_SC_BK10_7F_L));
    MdbPrint(paraGetInfo->u64ReqHdl,"Panel Gamma status                 : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_PANEL_GAMMA))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"3D RGB status                      : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_3D_RGB))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"RGB Gain status                    : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_RGB_GAIN))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"LinearRGB status                   : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_LINEAR_RGB))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Driver status                   : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_PQ_DRIVER))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"Scaling filter status              : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_SCALING_FILTER))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"Brightness                         : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_BRIGHTNESS))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"RGB Clip                           : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_RGB_CLIP))?"ON":"OFF");
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ DS bypass                       : %d\n", _gu16PQDbgXRuleBypass);
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ DS bypass status List : 1.All Bit is 0:Bypass off  2.Bit(1):MMDS Xrule Bypass  3.Bit(2):SPF Xrule Bypass  4.Bit(3):HVSP Xrule Bypass\n");
    MdbPrint(paraGetInfo->u64ReqHdl,"1/2 PQ Delay                       : %s\n", (MHal_PQ_Get_Function_Control_Info(PQ_MAIN_WINDOW,E_PQ_HALF_PQ_DELAY))?"ON":"OFF");

    MdbPrint(paraGetInfo->u64ReqHdl,"----------------  MTK PQ Path Version -----------------\n");
    bIsSuccess = MDrv_PQ_General_GetVersion_U2(pInstance, pStrBinVersion, PQ_BIN_STD_MAIN ,PQ_MAIN_WINDOW);
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main bin version                : %s\n",(bIsSuccess)?pStrBinVersion:pu8NotSupportString);

    bIsSuccess = MDrv_PQ_General_GetVersion_U2(pInstance, pStrBinVersion,PQ_BIN_STD_SUB ,PQ_SUB_WINDOW);
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub bin version                 : %s\n",(bIsSuccess)?pStrBinVersion:pu8NotSupportString);

    bIsSuccess = MDrv_PQ_General_GetVersion_U2(pInstance, pStrBinVersion,PQ_BIN_EXT_MAIN ,PQ_MAIN_WINDOW);
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main_Ex bin version             : %s\n",(bIsSuccess)?pStrBinVersion:pu8NotSupportString);

    bIsSuccess = MDrv_PQ_General_GetVersion_U2(pInstance, pStrBinVersion,PQ_BIN_EXT_SUB ,PQ_SUB_WINDOW);
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub_Ex bin version              : %s\n",(bIsSuccess)?pStrBinVersion:pu8NotSupportString);

    bIsSuccess = MDrv_PQ_General_GetVersion_U2(pInstance, pStrBinVersion,PQ_BIN_CUSTOMER_MAIN ,PQ_MAIN_WINDOW);
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main_Color bin version          : %s\n",(bIsSuccess)?pStrBinVersion:pu8NotSupportString);

    bIsSuccess = MDrv_PQ_General_GetVersion_U2(pInstance, pStrBinVersion,PQ_BIN_CUSTOMER_SUB ,PQ_SUB_WINDOW);
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub_Color bin version           : %s\n",(bIsSuccess)?pStrBinVersion:pu8NotSupportString);

    bIsSuccess = MDrv_PQ_General_GetVersion_U2(pInstance, pStrBinVersion,PQ_BIN_UFSC ,PQ_MAIN_WINDOW);
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ UFSC bin version                : %s\n",(bIsSuccess)?pStrBinVersion:pu8NotSupportString);

    bIsSuccess = MDrv_PQ_General_GetVersion_U2(pInstance, pStrBinVersion,PQ_BIN_CF_MAIN ,PQ_MAIN_WINDOW);
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main_CF bin version             : %s\n",(bIsSuccess)?pStrBinVersion:pu8NotSupportString);

    bIsSuccess = MDrv_PQ_General_GetVersion_U2(pInstance, pStrBinVersion,PQ_BIN_CF_SUB ,PQ_SUB_WINDOW);
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub_CF bin version              : %s\n",(bIsSuccess)?pStrBinVersion:pu8NotSupportString);

    bIsSuccess = MDrv_PQ_General_GetVersion_U2(pInstance, pStrBinVersion,PQ_BIN_TMO ,PQ_MAIN_WINDOW);
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ TMO bin version                 : %s\n",(bIsSuccess)?pStrBinVersion:pu8NotSupportString);

    bIsSuccess = MDrv_PQ_General_GetVersion_U2(pInstance, pStrBinVersion,PQ_BIN_HSY ,PQ_MAIN_WINDOW);
    MdbPrint(paraGetInfo->u64ReqHdl,"PQ HSY bin version                 : %s\n",(bIsSuccess)?pStrBinVersion:pu8NotSupportString);

    MdbPrint(paraGetInfo->u64ReqHdl,"----------------  MTK PQ Path Size -----------------\n");
    if(MITestBinInfo[PQ_BIN_STD_MAIN].u32MIPQBIN_Size == 0)
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main bin Path       : %s                         \n",pu8NotSupportString);
    }
    else
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main bin Path       : %s\t\tSize : %u            \n",MITestBinInfo[PQ_BIN_STD_MAIN].MIPQBin_Path,MITestBinInfo[PQ_BIN_STD_MAIN].u32MIPQBIN_Size);
    }
    if(MITestBinInfo[PQ_BIN_STD_SUB].u32MIPQBIN_Size == 0)
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub bin Path        : %s                         \n",pu8NotSupportString);
    }
    else
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub bin Path        : %s\t\tSize : %u            \n",MITestBinInfo[PQ_BIN_STD_SUB].MIPQBin_Path,MITestBinInfo[PQ_BIN_STD_SUB].u32MIPQBIN_Size);
    }
    if(MITestBinInfo[PQ_BIN_EXT_MAIN].u32MIPQBIN_Size == 0)
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main_Ex bin Path    : %s                         \n",pu8NotSupportString);
    }
    else
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main_Ex bin Path    : %s\t\tSize : %u            \n",MITestBinInfo[PQ_BIN_EXT_MAIN].MIPQBin_Path,MITestBinInfo[PQ_BIN_EXT_MAIN].u32MIPQBIN_Size);
    }
    if(MITestBinInfo[PQ_BIN_EXT_SUB].u32MIPQBIN_Size == 0)
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub_Ex bin Path     : %s                         \n",pu8NotSupportString);
    }
    else
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub_Ex bin Path     : %s\t\tSize : %u            \n",MITestBinInfo[PQ_BIN_EXT_SUB].MIPQBin_Path,MITestBinInfo[PQ_BIN_EXT_SUB].u32MIPQBIN_Size);
    }
    if(MITestBinInfo[PQ_BIN_CUSTOMER_MAIN].u32MIPQBIN_Size == 0)
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main_Color bin Path : %s                         \n",pu8NotSupportString);
    }
    else
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main_Color bin Path : %s\t\tSize : %u            \n",MITestBinInfo[PQ_BIN_CUSTOMER_MAIN].MIPQBin_Path,MITestBinInfo[PQ_BIN_CUSTOMER_MAIN].u32MIPQBIN_Size);
    }
    if(MITestBinInfo[PQ_BIN_CUSTOMER_SUB].u32MIPQBIN_Size == 0)
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub_Color bin Path  : %s                         \n",pu8NotSupportString);
    }
    else
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub_Color bin Path  : %s\t\tSize : %u            \n",MITestBinInfo[PQ_BIN_CUSTOMER_SUB].MIPQBin_Path,MITestBinInfo[PQ_BIN_CUSTOMER_SUB].u32MIPQBIN_Size);
    }
    if(MITestBinInfo[PQ_BIN_UFSC].u32MIPQBIN_Size == 0)
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ UFSC bin Path       : %s                         \n",pu8NotSupportString);
    }
    else
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ UFSC bin Path       : %s\t\tSize : %u            \n",MITestBinInfo[PQ_BIN_UFSC].MIPQBin_Path,MITestBinInfo[PQ_BIN_UFSC].u32MIPQBIN_Size);
    }
    if(MITestBinInfo[PQ_BIN_CF_MAIN].u32MIPQBIN_Size == 0)
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main_CF bin Path    : %s                         \n",pu8NotSupportString);
    }
    else
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Main_CF bin Path    : %s\t\tSize : %u            \n",MITestBinInfo[PQ_BIN_CF_MAIN].MIPQBin_Path,MITestBinInfo[PQ_BIN_CF_MAIN].u32MIPQBIN_Size);
    }
    if(MITestBinInfo[PQ_BIN_CF_SUB].u32MIPQBIN_Size == 0)
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub_CF bin Path     : %s                         \n",pu8NotSupportString);
    }
    else
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ Sub_CF bin Path     : %s\t\tSize : %u            \n",MITestBinInfo[PQ_BIN_CF_SUB].MIPQBin_Path,MITestBinInfo[PQ_BIN_CF_SUB].u32MIPQBIN_Size);
    }
    if(MITestBinInfo[PQ_BIN_TMO].u32MIPQBIN_Size == 0)
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ TMO bin Path        : %s                         \n",pu8NotSupportString);
    }
    else
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ TMO bin Path        : %s\t\tSize : %u            \n",MITestBinInfo[PQ_BIN_TMO].MIPQBin_Path,MITestBinInfo[PQ_BIN_TMO].u32MIPQBIN_Size);
    }
    if(MITestBinInfo[PQ_BIN_HSY].u32MIPQBIN_Size == 0)
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ HSY bin Path        : %s                         \n",pu8NotSupportString);
    }
    else
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"PQ HSY bin Path        : %s\t\tSize : %u            \n",MITestBinInfo[PQ_BIN_HSY].MIPQBin_Path,MITestBinInfo[PQ_BIN_HSY].u32MIPQBIN_Size);
    }

    MdbPrint(paraGetInfo->u64ReqHdl,"----------------  MTK PQ DLC/SWDR -----------------\n");
    if(MDrv_PQ_VR_R2BYTEMSK(REG_SC_BK04_01_L,BIT(15))==BIT(15))
    {
        if(MDrv_PQ_VR_R2BYTEMSK(REG_SC_BK04_01_L,BIT(14))==BIT(14))
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"DLC/SWDR                : SWDR\n");
        }
        else
        {
            MdbPrint(paraGetInfo->u64ReqHdl,"DLC/SWDR                : DLC\n");
        }
    }
    else
    {
        MdbPrint(paraGetInfo->u64ReqHdl,"DLC/SWDR                : By pass mode\n");
    }
}

#endif

MS_BOOL MDrv_PQ_Get_FBLStatus_U2(void* pInstance, PQ_WIN eWindow, PQ_INPUT_SOURCE_TYPE enInputSourceType, MS_PQ_Mode_Info *pstPQModeInfo, MS_BOOL bDsEnable)
{
    MS_BOOL bFblEnable = FALSE;

    _gManualDsEnable = bDsEnable;
    MDrv_PQ_Set_ModeInfo(eWindow, enInputSourceType, pstPQModeInfo);
    _u16PQSrcType[eWindow] = QM_InputSourceToIndex(pInstance, eWindow, enInputSourceType);

    bFblEnable = MDrv_PQ_IsFBLMadi(pInstance, eWindow);

    _gManualDsEnable = FALSE;
    return bFblEnable;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_Get_FBLStatus(PQ_WIN eWindow, PQ_INPUT_SOURCE_TYPE enInputSourceType, MS_PQ_Mode_Info *pstPQModeInfo, MS_BOOL bDsEnable)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_GetFBLStatus PQArgs;
    PQArgs.eWindow = eWindow;
    PQArgs.enInputSourceType = enInputSourceType;
    PQArgs.pstPQModeInfo = pstPQModeInfo;
    PQArgs.bDsEnable = bDsEnable;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_GET_FBLSTATUS, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    else
    {
        return PQArgs.bReturnValue;
    }
}

static PQ_BIN_TYPE _MDrv_PQ_BinTypeMapping(PQ_WIN eWindow,PQ_ENGINE_TYPE enEngineType)
{
    PQ_BIN_TYPE enPQBinType = PQ_BIN_STD_MAIN;
    if (eWindow == PQ_MAIN_WINDOW)
    {
        switch(enEngineType)
        {
            case PQ_XC0_STD:
                return PQ_BIN_STD_MAIN;
            case PQ_XC0_EXT:
                return PQ_BIN_EXT_MAIN;
            case PQ_XC0_CUSTOMER:
                return PQ_BIN_CUSTOMER_MAIN;
            default:
                return enPQBinType;
        }
    }
    else if(eWindow == PQ_SUB_WINDOW)
    {
        switch(enEngineType)
        {
            case PQ_XC0_STD:
                return PQ_BIN_STD_SUB;
            case PQ_XC0_EXT:
                return PQ_BIN_EXT_SUB;
            case PQ_XC0_CUSTOMER:
                return PQ_BIN_CUSTOMER_SUB;
            default:
                return enPQBinType;
        }
    }
    else
    {
        return enPQBinType;
    }
}

static MS_U16 _MDrv_PQ_Get_GruleInfoTableNum(void)
{
    return (sizeof(g_stPQ_GruleINFO)/sizeof(g_stPQ_GruleINFO[0]));
}

static MS_BOOL _MDrv_PQ_Get_GruleInfo(EN_PQ_GRULE_TYPE enGruleType,ST_PQ_GRULE_INFO *pstPQ_GruleINFO)
{
    MS_U16 u16Count = 0;
    if(pstPQ_GruleINFO != NULL)
    {
        for(u16Count=0;u16Count<_MDrv_PQ_Get_GruleInfoTableNum();u16Count++)
        {
            if(g_stPQ_GruleINFO[u16Count].stPQGruleTable.enPQGruleType == enGruleType)
            {
                *pstPQ_GruleINFO = g_stPQ_GruleINFO[u16Count];
                return TRUE;
            }
        }
    }
    return FALSE;
}

static MS_BOOL _MDrv_PQ_General_GruleTable(void* pInstance, PQ_WIN eWindow,ST_PQ_GRULE_INFO *pstGrule)
{
    if(pstGrule == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"pstGrule = NULL\n");
        return FALSE;
    }

    ST_PQ_IPInfo stGRuleIPInfo;
    ST_PQ_IPInfo stUpdatedGRuleIPInfo;
    memset(&stGRuleIPInfo, 0, sizeof(ST_PQ_IPInfo));
    memset(&stUpdatedGRuleIPInfo, 0, sizeof(ST_PQ_IPInfo));
    MS_U16 u16PQlevelIdx = 0;
    MS_U16 u16Index=0, u16IPIdx = 0, u16TabIdx = 0;
    MS_U16 u16GroupNum = 0;
    MS_U16 u16IPNum = 0;
    PQ_BIN_TYPE enPQBinType = PQ_BIN_STD_MAIN;

    if(MHal_PQ_Support_GroupIPBIN())
    {
        enPQBinType = _MDrv_PQ_BinTypeMapping(eWindow,pstGrule->stPQGruleTable.enEngineType);
        MDrv_PQBin_GetGRule_GroupIPNum(pInstance,eWindow,MHal_PQ_Get_GRuleIPIndex(eWindow,pstGrule->stPQGruleTable.enGruleIP),enPQBinType ,&u16GroupNum, &u16IPNum ,&stPQBinHeaderInfo[enPQBinType]);
    }
    else
    {
        u16GroupNum = MHal_PQ_Get_GRuleNum(eWindow,pstGrule->stPQGruleTable.enGruleIP);
        u16IPNum = MHal_PQ_Get_GRuleIPNum(eWindow,pstGrule->stPQGruleTable.enGruleIP);
    }

    u16PQlevelIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow,MHal_PQ_Get_GRuleIPIndex(eWindow,pstGrule->stPQGruleTable.enGruleIP),pstGrule->stPQGruleTable.u16GRuleLevelIndex);

    if(u16PQlevelIdx > u16GroupNum)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"GRULE_INDEX_OVERFLOW_ERROR Level Index = %u, Max Level Index = %u",u16PQlevelIdx,(u16GroupNum-1));
        PQ_ASSERT(0);
        return FALSE;
    }

    for(u16Index = 0; u16Index < u16IPNum; u16Index++)
    {
        u16IPIdx = MDrv_PQ_GetGRule_IPIndex_U2(pInstance, eWindow, MHal_PQ_Get_GRuleIPIndex(eWindow,pstGrule->stPQGruleTable.enGruleIP), u16Index);

        if(u16PQlevelIdx == u16GroupNum)  // see it as default
        {
            u16TabIdx = MDrv_PQ_GetTableIndex_U2(pInstance,eWindow, u16TabIdx);
        }
        else
        {
            u16TabIdx = MDrv_PQ_GetGRule_TableIndex(eWindow, MHal_PQ_Get_GRuleIPIndex(eWindow,pstGrule->stPQGruleTable.enGruleIP), u16PQlevelIdx, u16Index);
        }
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[DC]SRC: %u, DC: %u, DCIPIdx:%u, IPIdx:%u, u16TabIdx:%u\n",
                           _u16PQSrcType[eWindow], u16PQlevelIdx, u16Index, u16IPIdx, u16TabIdx);
        MDrv_PQ_LoadTable_Ex_U2(pInstance, eWindow, u16TabIdx, u16IPIdx,pstGrule->stPQGruleTable.enEngineType);
    }

    stGRuleIPInfo.u16IPIdx= MHal_PQ_Get_GRuleIPIndex(eWindow,pstGrule->stPQGruleTable.enGruleIP);
    stGRuleIPInfo.u16GruleLevelMain = pstGrule->stPQGruleTable.u16GRuleLevelIndex;
    stGRuleIPInfo.enPQEngineType = pstGrule->stPQGruleTable.enEngineType;
    MHal_PQ_RemappingGruleIP(pInstance, stGRuleIPInfo, &stUpdatedGRuleIPInfo, TRUE);
    if(stUpdatedGRuleIPInfo.u16IPIdx !=  PQ_GRULE_LEVEL_NULL && stUpdatedGRuleIPInfo.enPQEngineType == PQ_XC0_EXT)
    {
        u16PQlevelIdx = MDrv_PQ_GetGRule_LevelIndex_U2(pInstance, eWindow,stUpdatedGRuleIPInfo.u16IPIdx,stUpdatedGRuleIPInfo.u16GruleLevelMain);
        for(u16Index = 0; u16Index < stUpdatedGRuleIPInfo.u16GruleMaxIPNum; u16Index++)
        {
            u16IPIdx = MDrv_PQ_GetGRule_IPIndex_Ex_U2(pInstance, eWindow, stUpdatedGRuleIPInfo.u16IPIdx, u16Index, stUpdatedGRuleIPInfo.enPQEngineType);

            if(u16PQlevelIdx == stUpdatedGRuleIPInfo.u16GruleLevelMainNum)  // see it as default
            {
                u16TabIdx = MDrv_PQ_GetTableIndex_Ex_U2(pInstance,eWindow, u16TabIdx, stUpdatedGRuleIPInfo.enPQEngineType);
            }
            else
            {
                u16TabIdx = MDrv_PQ_GetGRule_TableIndex_Ex(eWindow, stUpdatedGRuleIPInfo.u16IPIdx, u16PQlevelIdx, u16Index, stUpdatedGRuleIPInfo.enPQEngineType);
            }

            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"[DC][EX]SRC: %u, DC: %u, DCIPIdx:%u, IPIdx:%u, u16TabIdx:%u\n",
                               _u16PQSrcType[eWindow], u16PQlevelIdx, u16Index, u16IPIdx, u16TabIdx);
            MDrv_PQ_LoadTable_Ex_U2(pInstance, eWindow, u16TabIdx, u16IPIdx,stUpdatedGRuleIPInfo.enPQEngineType);
        }
    }

    return TRUE;
}
MS_BOOL MDrv_PQ_General_GruleTable_U2(void* pInstance,ST_PQ_GENERAL_GRULE* pstPQGeneralGrule)
{
    MS_U16 u16levelIndex = 0;
    MS_U16 u16Index=0, u16IPIdx = 0, u16TabIdx = 0;
    MS_U32 u32CopiedLength = 0;
    MS_BOOL bRet = FALSE;
    ST_PQ_GRULE_INFO stPQ_GruleINFO;
    ST_PQ_GENERAL_GRULE stPQ_GeneralGrule;
    memset(&stPQ_GruleINFO,0,sizeof(ST_PQ_GRULE_INFO));
    memset(&stPQ_GeneralGrule, 0, sizeof(ST_PQ_GENERAL_GRULE));

    u32CopiedLength = sizeof(ST_PQ_GENERAL_GRULE);

    VERSION_COMPATIBLE_CHECK(pstPQGeneralGrule, stPQ_GeneralGrule, u32CopiedLength, u32Version, u32Length, ST_PQ_GENERAL_GRULE_VERSION, FALSE);
    pstPQGeneralGrule->u32Version = ST_PQ_GENERAL_GRULE_VERSION; /*Return the actual version of the returned value for APP to use*/
    pstPQGeneralGrule->u32Length = u32CopiedLength; /*Return the actual length of the returned value for APP to know whick info is valid*/

    memcpy(&stPQ_GeneralGrule,pstPQGeneralGrule, u32CopiedLength);

    _MDrv_PQ_Get_GruleInfo(stPQ_GeneralGrule.enGruleType,&stPQ_GruleINFO);

    PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Window[%u] enGruleType[%u]\n",stPQ_GeneralGrule.enWindow,stPQ_GeneralGrule.enGruleType);

    if(stPQ_GruleINFO.stPQGruleTable.u16GRuleLevelIndex == PQ_GRULE_LEVEL_NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"enGruleType[%u] Unsupport\n",stPQ_GeneralGrule.enGruleType);
        return bRet;
    }
    if((stPQ_GeneralGrule.enWindow != stPQ_GruleINFO.stPQGruleTable.enSupportWindow) && (stPQ_GruleINFO.stPQGruleTable.enSupportWindow != PQ_MAX_WINDOW))
    {
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Unsupport window[%d]\n",stPQ_GeneralGrule.enWindow);
        return bRet;
    }

    if(stPQ_GruleINFO.pfnPQ_GRULE_FUNCTION != NULL)
    {
        bRet = stPQ_GruleINFO.pfnPQ_GRULE_FUNCTION(pInstance,stPQ_GeneralGrule.enWindow,&stPQ_GruleINFO.stPQGruleTable);

        if(bRet == FALSE)
        {
            PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"Grule callback function return False\n");
            return FALSE;
        }
    }

    if(stPQ_GruleINFO.stPQGruleTable.bIsSkipDumpTalbe == TRUE)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"SkipDumpTable\n");
        return TRUE;
    }

    bRet = _MDrv_PQ_General_GruleTable(pInstance,stPQ_GeneralGrule.enWindow,&stPQ_GruleINFO);

    PQ_LEVEL_PRINTF(PQ_DBG_GRULE,"%s\n",(bRet?("Success"):("Fail")));

    return bRet;
}
MS_BOOL SYMBOL_WEAK MDrv_PQ_General_GruleTable(ST_PQ_GENERAL_GRULE* pstPQGeneralGrule)
{
    if (pu32PQInst == NULL)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"No instance existed, please get an instance by calling MDrv_PQ_Init() first\n");
        return FALSE;
    }

    stPQ_General_GRule PQArgs;
    PQArgs.pstPQGeneralGrule = pstPQGeneralGrule;
    PQArgs.bReturnValue = FALSE;

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_LOAD_GENERAL_GRULE_TABLE, (void*)&PQArgs) != 0)
    {
        PQ_LEVEL_PRINTF(PQ_DBG_ERROR,"Obtain PQ engine fail\n");
        return FALSE;
    }
    return PQArgs.bReturnValue;
}

void MDrv_PQ_ResumeYCSram_U2(void* pInstance)
{
    Hal_PQ_ResumeYCSram(pInstance);
    MDrv_PQ_ResetFilterPara();
}

void MDrv_PQ_ResumeYCSram(void)
{
    if (pu32PQInst == NULL)
    {
        printf("[%s,%5d]No instance existed, please get an instance by calling MDrv_PQ_Init() first\n",__FUNCTION__,__LINE__);
        return;
    }

    if(UtopiaIoctl(pu32PQInst, E_PQ_CMD_RESUME_YC_SRAM, NULL) != 0)
    {
        printf("Obtain PQ engine fail: E_PQ_CMD_RESUME_YC_SRAM\n");
        return;
    }
    else
    {
        return;
    }
}

