//<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>
///////////////////////////////////////////////////////////////////////////////////////////////////
///
/// file    drvXC_HDMI_if_v2.c
/// @author MStar Semiconductor Inc.
/// @brief  HDMI Rx driver Function
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef MSOS_TYPE_NUTTX
#ifndef _API_HDMI_RX_V2_C_
#define _API_HDMI_RX_V2_C_

//-------------------------------------------------------------------------------------------------
//  Include Files
//-------------------------------------------------------------------------------------------------
#include "MsCommon.h"
#ifdef MSOS_TYPE_LINUX_KERNEL
#include <linux/string.h>
#else
#include "string.h"
#endif
#include "utopia.h"
#include "utopia_dapi.h"
#include "drvXC_IOPort.h"
#include "apiXC.h"
#include "apiXC_Adc.h"
#include "apiXC_Auto.h"
#include "apiXC_ModeParse.h"
#include "drv_sc_display.h"
#include "drv_sc_isr.h"
#include "apiXC_PCMonitor.h"
#include "drvXC_HDMI_if.h"
#include "mhal_xc_chip_config.h"
#include "mvideo_context.h"
#if (LD_ENABLE==1)
#include "mdrv_ld.h"
#include "mdrv_ldalgo.h"
#endif
#include "mdrv_sc_3d.h"
#include "drv_sc_menuload.h"
#include "drv_sc_ip.h"
#include "drvXC_ADC_Internal.h"
#include "mhal_sc.h"
#if FRC_INSIDE
#include "mdrv_frc.h"
#include "mhal_frc.h"
#endif
#include "XC_private.h"
#include "apiXC_v2.h"
#include "drvXC_HDMI_if_v2.h"
#include "apiHDMIRx_private.h"

//-------------------------------------------------------------------------------------------------
//  Local Defines
//-------------------------------------------------------------------------------------------------
#if(defined(CONFIG_MLOG))
#include "ULog.h"

#define MAPI_HDMIRX_MSG_INFO(format, args...)       ULOGI("HDMIRX", format, ##args)
#define MAPI_HDMIRX_MSG_WARNING(format, args...)    ULOGW("HDMIRX", format, ##args)
#define MAPI_HDMIRX_MSG_DEBUG(format, args...)      ULOGD("HDMIRX", format, ##args)
#define MAPI_HDMIRX_MSG_ERROR(format, args...)      ULOGE("HDMIRX", format, ##args)
#define MAPI_HDMIRX_MSG_FATAL(format, args...)      ULOGF("HDMIRX", format, ##args)

#else
#define MAPI_HDMIRX_MSG_INFO(format, args...)       printf(format, ##args)
#define MAPI_HDMIRX_MSG_WARNING(format, args...)    printf(format, ##args)
#define MAPI_HDMIRX_MSG_DEBUG(format, args...)      printf(format, ##args)
#define MAPI_HDMIRX_MSG_ERROR(format, args...)      printf(format, ##args)
#define MAPI_HDMIRX_MSG_FATAL(format, args...)      printf(format, ##args)

#endif

//-------------------------------------------------------------------------------------------------
//  Local Structures
//-------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
//  Global Variables
//-------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
//  Local Variables
//-------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
//  Local Functions
//-------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
//  Global Functions
//-------------------------------------------------------------------------------------------------

//**************************************************************************
//  [Function Name]:
//                  HDMI_IF_Initialize()
//  [Description]
//
//  [Arguments]:
//
//  [Return]:
//
//**************************************************************************
void HDMI_IF_Initialize(XC_INSTANCE_PRIVATE* psXCInstPri, const void* const pAttribute)
{
    psXCInstPri->fpHDMI_Func_Caps =     MDrv_HDMI_Func_Caps_U2;
    psXCInstPri->fpHDMI_init =     MDrv_HDMI_init_U2;
    psXCInstPri->fpHDMI_Exit =     MDrv_HDMI_Exit_U2;
    psXCInstPri->fpHDMI_pullhpd =     MDrv_HDMI_pullhpd_U2;
    psXCInstPri->fpHDMI_Packet_Received =     MDrv_HDMI_Packet_Received_U2;
    psXCInstPri->fpHDMI_Set_EQ =     MDrv_HDMI_Set_EQ_U2;
    psXCInstPri->fpHDMI_Set_EQ_To_Port = MDrv_HDMI_Set_EQ_To_Port_U2;
    psXCInstPri->fpHDMI_Audio_MUTE_Enable =     MDrv_HDMI_Audio_MUTE_Enable_U2;
    psXCInstPri->fpHDMI_Audio_Status_Clear =     MDrv_HDMI_Audio_Status_Clear_U2;
    psXCInstPri->fpHDMI_Get_TMDS_freq     =     MDrv_HDMI_GetTMDSFreq_U2;
    psXCInstPri->fpHDMI_Get_PollingStatus =     MDrv_HDMI_Get_PollingStatus_U2;
    psXCInstPri->fpHDMI_IsHDMI_Mode =     MDrv_HDMI_IsHDMI_Mode_U2;
    psXCInstPri->fpDVI_ChannelPhaseStatus =     MDrv_DVI_ChannelPhaseStatus_U2;
    psXCInstPri->fpDVI_SoftwareReset =     MDrv_DVI_SoftwareReset_U2;
    psXCInstPri->fpdvi_reset =     mdrv_dvi_reset_U2;
    psXCInstPri->fpDVI_ClkPullLow =     MDrv_DVI_ClkPullLow_U2;
    psXCInstPri->fpHDMI_SetForClockLessThan70Mhz =     MDrv_HDMI_SetForClockLessThan70Mhz_U2;
    psXCInstPri->fpHDMI_dvi_adjust =     MDrv_HDMI_dvi_adjust_U2;
    psXCInstPri->fpHDMI_SetUpdatePhaseLineCount =     MDrv_HDMI_SetUpdatePhaseLineCount_U2;
    psXCInstPri->fpHDCP_Enable =     MDrv_HDCP_Enable_U2;
    psXCInstPri->fpHDMI_SetHdcpEnable = MDrv_HDMI_SetHdcpEnable_U2;
    psXCInstPri->fpHDCP_ClearStatus =     MDrv_HDCP_ClearStatus_U2;
    psXCInstPri->fpHDCP_initproductionkey =     MDrv_HDCP_initproductionkey_U2;
    psXCInstPri->fpHDCP_GetStatus =     MDrv_HDCP_GetStatus_U2;
    psXCInstPri->fpHDCP_Vsync_end_en =     MDrv_HDCP_Vsync_end_en_U2;
    psXCInstPri->fpHDMI_audio_output =     MDrv_HDMI_audio_output_U2;
    psXCInstPri->fpHDMI_GetLibVer =     MDrv_HDMI_GetLibVer_U2;
    psXCInstPri->fpHDMI_GetInfo =     MDrv_HDMI_GetInfo_U2;
    psXCInstPri->fpHDMI_GetStatus =     MDrv_HDMI_GetStatus_U2;
    psXCInstPri->fpHDMI_READ_DDCRAM =   MDrv_HDMI_READ_DDCRAM_U2;
    psXCInstPri->fpHDMI_PROG_DDCRAM = MDrv_HDMI_PROG_DDCRAM_U2;
    psXCInstPri->fpHDMI_ARC_PINControl =     MDrv_HDMI_ARC_PINControl_U2;
    psXCInstPri->fpDVI_Software_Reset =     MDrv_DVI_Software_Reset_U2;
    psXCInstPri->fpHDMI_Set_PowerState =    MDrv_HDMI_SetPowerState_U2;
    psXCInstPri->fpHDMI_dvi_hf_adjust =     MDrv_DVI_HF_adjust_U2;
    psXCInstPri->fpHDMI_checkhdmi20_setting = MDrv_HDMI_CheckHDMI20_Setting_U2;
    psXCInstPri->fpHDMI_Set5VDetectGPIOSelect = MDrv_HDMI_Set5VDetectGPIOSelect_U2;
    psXCInstPri->fpHDMI_GetDEStableStatus=     MDrv_HDMI_GetDEStableStatus_U2;
    psXCInstPri->fpHDMI_Ctrl = MDrv_HDMI_Ctrl_U2;
    return;
}

//**************************************************************************
//  [Function Name]:
//                  _HDMI_IF_Ioctl()
//  [Description]
//
//  [Arguments]:
//
//  [Return]:
//
//**************************************************************************
MS_U32 _HDMI_IF_Ioctl(void * pInstance, MS_U32 u32Cmd, void * pArgs)
{
    //void* pModule = NULL;
    //void* pResource = NULL;
    MS_U32 u32Return = UTOPIA_STATUS_FAIL;
    XC_INSTANCE_PRIVATE* psXCInstPri = NULL;

    //UtopiaInstanceGetModule(pInstance, &pModule);

    if(UtopiaInstanceGetPrivate(pInstance, (void*)&psXCInstPri)!=UTOPIA_STATUS_SUCCESS)
    {
        MAPI_HDMIRX_MSG_ERROR("[%s,%5d] Instance Get Private failed\n",__FUNCTION__,__LINE__);
    }

    switch(u32Cmd)
    {
        case E_XC_HDMI_IF_CMD_FUNC_CAPS:
            {
                if(psXCInstPri->fpHDMI_Func_Caps != NULL)
                {
                    pstHDMI_FUNC_CAPS pXCArgs = (pstHDMI_FUNC_CAPS) pArgs;
                    pXCArgs->u16ReturnValue = psXCInstPri->fpHDMI_Func_Caps(pInstance);

                    u32Return = UTOPIA_STATUS_SUCCESS;
                }
                break;
            }

        case E_XC_HDMI_IF_CMD_INIT:
            {
                pstHDMI_INITIAL_SETTING pXCArgs = (pstHDMI_INITIAL_SETTING)pArgs;

                pXCArgs->stInitialTable = psXCInstPri->fpHDMI_init(pInstance);
#if PIP_PATCH_USING_SC1_MAIN_AS_SC0_SUB
                //FIX ME: other hdmi interface may assess global vars,maybe should add device1 flow
                CHECK_DEVICE1_INSTANCE();
                pXCArgs->stInitialTable = psXCInstPri->fpHDMI_init(g_pDevice1Instance);
#endif
                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_EXIT:
            {
                psXCInstPri->fpHDMI_Exit(pInstance);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_PULLHPD:
            {
                pstHDMI_PULLHPD pXCArgs = (pstHDMI_PULLHPD) pArgs;
                psXCInstPri->fpHDMI_pullhpd(pInstance, pXCArgs->bHighLow,
                                                       pXCArgs->enInputPortType,
                                                       pXCArgs->bInverse);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_PACKET_RECEIVED:
            {
                pstHDMI_PACKET_RECEIVED pXCArgs = (pstHDMI_PACKET_RECEIVED) pArgs;
                psXCInstPri->fpHDMI_Packet_Received(pInstance, pXCArgs->ucHDMIInfoSource, pXCArgs->bEnable, pXCArgs->ulPacketStatus);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_SET_EQ:
            {
                pstHDMI_SET_EQ pXCArgs = (pstHDMI_SET_EQ) pArgs;
                psXCInstPri->fpHDMI_Set_EQ(pInstance, pXCArgs->enEq, pXCArgs->u8EQValue);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_SET_EQ_TO_PORT:
            {
                pstHDMI_SET_EQ_TO_PORT pXCArgs = (pstHDMI_SET_EQ_TO_PORT) pArgs;
                pXCArgs->bReturnValue = psXCInstPri->fpHDMI_Set_EQ_To_Port(pInstance, pXCArgs->enEq, pXCArgs->u8EQValue, pXCArgs->enInputPortType);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_AUDIO_MUTE_ENABLE:
            {
                pstHDMI_AUDIO_MUTE_ENABLE pXCArgs = (pstHDMI_AUDIO_MUTE_ENABLE) pArgs;
                psXCInstPri->fpHDMI_Audio_MUTE_Enable(pInstance, pXCArgs->u16MuteEvent,
                                                                 pXCArgs->u16MuteMask);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_AUDIO_STATUS_CLEAR:
            {
                psXCInstPri->fpHDMI_Audio_Status_Clear(pInstance);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_GET_TMDS_FREQ:
            {
                pstHDMI_GET_TMDS_FREQ pXCArgs = (pstHDMI_GET_TMDS_FREQ) pArgs;
                pXCArgs->u8ReturnValue = psXCInstPri->fpHDMI_Get_TMDS_freq(pInstance);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_GET_POLLINGSTATUS:
            {
                pstHDMI_GET_POLLINGSTATUS pXCArgs = (pstHDMI_GET_POLLINGSTATUS) pArgs;
                psXCInstPri->fpHDMI_Get_PollingStatus(pInstance, pXCArgs->pStatus);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_ISHDMI_MODE:
            {
                pstHDMI_ISHDMI_MODE pXCArgs = (pstHDMI_ISHDMI_MODE) pArgs;
                pXCArgs->bReturnValue = psXCInstPri->fpHDMI_IsHDMI_Mode(pInstance);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_DVI_IF_CMD_CHANNELPHASESTATUS:
            {
                pstDVI_CHANNELPHASESTATUS pXCArgs = (pstDVI_CHANNELPHASESTATUS) pArgs;
                pXCArgs->u16ReturnValue = psXCInstPri->fpDVI_ChannelPhaseStatus(pInstance, pXCArgs->u8Channel);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_DVI_IF_CMD_SOFTWARERESET:
            {
                pstDVI_SOFTWARERESET pXCArgs = (pstDVI_SOFTWARERESET) pArgs;
                psXCInstPri->fpDVI_SoftwareReset(pInstance, pXCArgs->u16Reset);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_DVI_IF_CMD_RESET:
            {
                psXCInstPri->fpdvi_reset(pInstance);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_DVI_IF_CMD_CLKPULLLOW:
            {
                pstDVI_CLKPULLLOW pXCArgs = (pstDVI_CLKPULLLOW) pArgs;
                psXCInstPri->fpDVI_ClkPullLow(pInstance,
                                              pXCArgs->bPullLow,
                                              pXCArgs->enInputPortType);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_SETFORCLOCKLESSTHAN70MHZ:
            {
                pstHDMI_SETFORCLOCKLESSTHAN70MHZ pXCArgs = (pstHDMI_SETFORCLOCKLESSTHAN70MHZ) pArgs;
                pXCArgs->bReturnValue = psXCInstPri->fpHDMI_SetForClockLessThan70Mhz(pInstance, pXCArgs->enInputPortType);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_DVI_ADJUST:
            {
                pstHDMI_DVI_ADJUST pXCArgs = (pstHDMI_DVI_ADJUST) pArgs;
                psXCInstPri->fpHDMI_dvi_adjust(pInstance, pXCArgs->bClockLessThan70MHz);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_SETUPDATEPHASELINECOUNT:
            {
                pstHDMI_SETUPDATEPHASELINECOUNT pXCArgs = (pstHDMI_SETUPDATEPHASELINECOUNT) pArgs;
                psXCInstPri->fpHDMI_SetUpdatePhaseLineCount(pInstance, pXCArgs->enInputSourceType);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDCP_IF_CMD_ENABLE:
            {
                pstHDCP_ENABLE pXCArgs = (pstHDCP_ENABLE) pArgs;
                psXCInstPri->fpHDCP_Enable(pInstance, pXCArgs->bEnable);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_SET_HDCP_ENABLE:
            {
                pstHDMI_SET_HDCPENABLE pXCArgs = (pstHDMI_SET_HDCPENABLE) pArgs;
                pXCArgs->bReturnValue = psXCInstPri->fpHDMI_SetHdcpEnable(pInstance, pXCArgs->enInputPortType, pXCArgs->bEnable);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDCP_IF_CMD_CLEARSTATUS:
            {
                psXCInstPri->fpHDCP_ClearStatus(pInstance);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDCP_IF_CMD_INITPRODUCTIONKEY:
            {
                pstHDCP_INITPRODUCTIONKEY pXCArgs = (pstHDCP_INITPRODUCTIONKEY) pArgs;
                psXCInstPri->fpHDCP_initproductionkey(pInstance, pXCArgs->pu8HdcpKeyData);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDCP_IF_CMD_GETSTATUS:
            {
                pstHDCP_GETSTATUS pXCArgs = (pstHDCP_GETSTATUS)pArgs;
                pXCArgs->usHDCPStatus = psXCInstPri->fpHDCP_GetStatus(pInstance);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDCP_IF_CMD_VSYNC_END_EN:
            {
                pstHDCP_VSYNC_END_EN pXCArgs = (pstHDCP_VSYNC_END_EN) pArgs;
                psXCInstPri->fpHDCP_Vsync_end_en(pInstance, pXCArgs->bStable);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_AUDIO_OUTPUT:
            {
                pstHDMI_AUDIO_OUTPUT pXCArgs = (pstHDMI_AUDIO_OUTPUT) pArgs;
                psXCInstPri->fpHDMI_audio_output(pInstance, pXCArgs->bEnable);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_GETLIBVER:
            {
                pstHDMI_GETLIBVER pXCArgs = (pstHDMI_GETLIBVER) pArgs;
                pXCArgs->eReturnValue = psXCInstPri->fpHDMI_GetLibVer(pInstance, pXCArgs->ppVersion);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_GETINFO:
            {
                pstHDMI_GETINFO pXCArgs = (pstHDMI_GETINFO) pArgs;
                pXCArgs->eReturnValue = psXCInstPri->fpHDMI_GetInfo(pInstance, pXCArgs->pInfo);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_GETSTATUS:
            {
                pstHDMI_GETSTATUS pXCArgs = (pstHDMI_GETSTATUS) pArgs;
                pXCArgs->eReturnValue = psXCInstPri->fpHDMI_GetStatus(pInstance, pXCArgs->pStatus);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_READ_DDCRAM:
            {
                pstHDMI_READ_DDCRAM pXCArgs = (pstHDMI_READ_DDCRAM) pArgs;
                psXCInstPri->fpHDMI_READ_DDCRAM(pInstance, pXCArgs->pstDDCRam_Info, pXCArgs->u32SizeOfInfo);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_PROG_DDCRAM:
            {
                pstHDMI_PROG_DDCRAM pXCArgs = (pstHDMI_PROG_DDCRAM) pArgs;
                psXCInstPri->fpHDMI_PROG_DDCRAM(pInstance, pXCArgs->pstDDCRam_Info, pXCArgs->u32SizeOfInfo);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_ARC_PINCONTROL:
            {
                pstHDMI_ARC_PINCONTROL pXCArgs = (pstHDMI_ARC_PINCONTROL) pArgs;
                psXCInstPri->fpHDMI_ARC_PINControl(pInstance,
                                                   pXCArgs->enInputPortType,
                                                   pXCArgs->bEnable,
                                                   pXCArgs->bDrivingHigh);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_DVI_SOFTWARE_RESET:
            {
                pstDVI_SOFTWARE_RESET pXCArgs = (pstDVI_SOFTWARE_RESET) pArgs;
                psXCInstPri->fpDVI_Software_Reset(pInstance,
                                                  pXCArgs->enInputPortType,
                                                  pXCArgs->u16Reset);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_SET_POWERSTATE:
            {
                pstHDMI_SET_POWERSTATE pXCArgs = (pstHDMI_SET_POWERSTATE) pArgs;
                pXCArgs->u32ReturnValue = psXCInstPri->fpHDMI_Set_PowerState(pInstance, pXCArgs->enPowerState);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_DVI_HF_ADJUST:
            {
                psXCInstPri->fpHDMI_dvi_hf_adjust(pInstance);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_CHECK_HDMI20_SETTING:
            {
                pstHDMI_CHECK_HDMI20_SETTING pXCArgs = (pstHDMI_CHECK_HDMI20_SETTING) pArgs;
                pXCArgs->bReturnValue = psXCInstPri->fpHDMI_checkhdmi20_setting(pInstance, pXCArgs->enInputPortType);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_SET_5V_DETECT_GPIO_SELECT:
            {
                pstHDMI_SET_5V_DETECT_GPIO_SELECT pXCArgs = (pstHDMI_SET_5V_DETECT_GPIO_SELECT) pArgs;
                psXCInstPri->fpHDMI_Set5VDetectGPIOSelect(pInstance, pXCArgs->ul5VDetectGPIOSelect);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_GET_DE_STABLE_STATUS:
            {
                pstHDMI_GET_DE_STABLE_STATUS pXCArgs = (pstHDMI_GET_DE_STABLE_STATUS) pArgs;
                pXCArgs->bStatus = psXCInstPri->fpHDMI_GetDEStableStatus(pInstance, pXCArgs->enInputPortType);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_CTRL:
            {
                pstHDMI_CONTROL pXCArgs = (pstHDMI_CONTROL)pArgs;
                pXCArgs->bRet = psXCInstPri->fpHDMI_Ctrl(pInstance, pXCArgs->ucHDMIInfoSource, pXCArgs->u32Cmd, pXCArgs->pBuf, pXCArgs->u32BufSize);

                u32Return = UTOPIA_STATUS_SUCCESS;
                break;
            }

        case E_XC_HDMI_IF_CMD_NONE:
        case E_XC_HDMI_IF_CMD_MAX:
        default:
            {
                MAPI_HDMIRX_MSG_WARNING("Command %td is not existed\n",(ptrdiff_t)u32Cmd);
                u32Return = UTOPIA_STATUS_ERR_INVALID_HANDLE;
                break;
            }
    }

    return u32Return;
}

//**************************************************************************
//  [Function Name]:
//                  HDMIRxOpen()
//  [Description]
//
//  [Arguments]:
//
//  [Return]:
//
//**************************************************************************
MS_U32 HDMIRxOpen(void** ppInstance, const void* const pAttribute)
{
    HDMI_RX_INSTANT_PRIVATE *psHDMIRxInstPri = NULL;

    //UTOPIA_TRACE(MS_UTOPIA_DB_LEVEL_TRACE,printf("enter %s %d\n",__FUNCTION__,__LINE__));
    // instance is allocated here, also can allocate private for internal use, ex, BDMA_INSTANT_PRIVATE
    UtopiaInstanceCreate(sizeof(HDMI_RX_INSTANT_PRIVATE), ppInstance);
    // setup func in private and assign the calling func in func ptr in instance private
    UtopiaInstanceGetPrivate(*ppInstance, (void**)&psHDMIRxInstPri);

    psHDMIRxInstPri->fpHDMIRxInitial = (IOCTL_HDMIRX_INITIAL)mdrv_HDMI_InitialSetting;
    psHDMIRxInstPri->fpHDMIRxStablePolling = (IOCTL_HDMIRX_STABLE_POLLING)mdrv_HDMI_StablePolling;
    psHDMIRxInstPri->fpHDMIRxGetSourceVersion = (IOCTL_HDMIRX_GET_SOURCE_VERSION)mdrv_HDMI_GetSourceVersion;
    psHDMIRxInstPri->fpHDMIRxCheckHDCPState = (IOCTL_HDMIRX_CHECK_HDCP_STATE)mdrv_HDMI_CheckHDCPState;
    psHDMIRxInstPri->fpHDMIRxCheckHDCPENCState = (IOCTL_HDMIRX_CHECK_HDCP_ENC_STATE)mdrv_HDMI_CheckHDCPENCState;
    psHDMIRxInstPri->fpHDMIRxCheckHDCP14KeyVaild = (IOCTL_HDMIRX_CHECK_HDCP14_KEY_VAILD)mdrv_HDMI_CheckHDCP14KeyVaild;
    psHDMIRxInstPri->fpHDMIRxGetHDCP14KeyVaildFlag = (IOCTL_HDMIRX_GET_HDCP14_KEY_VAILD_FLAG)mdrv_HDMI_GetHDCP14KeyVaildFlag;
    psHDMIRxInstPri->fpHDMIRxSetHPDInvertFlag = (IOCTL_HDMIRX_SET_HPD_INVERT_FLAG)mdrv_HDMI_SetHPDInvertFlag;
    psHDMIRxInstPri->fpHDMIRxGetPacketReceive = (IOCTL_HDMIRX_GET_PACKET_RECEIVE)mdrv_HDMI_GetPacketReceiveStatus;
    psHDMIRxInstPri->fpHDMIRxGetHDRInfoFrame = (IOCTL_HDMIRX_GET_HDR_INFO_FRAME)mdrv_HDMI_GetHDRInfoFrame;
    psHDMIRxInstPri->fpHDMIRxDataRtermControl = (IOCTL_HDMIRX_DATA_RTERM_CONTROL)mdrv_HDMI_DataRtermControl;
    psHDMIRxInstPri->fpHDMIRxGetHDCPStatus = (IOCTL_HDMIRX_GET_HDCP_STATUS)mdrv_HDMI_GetHDCPStatusPort;
    psHDMIRxInstPri->fpHDMIRxGetSCDCValue = (IOCTL_HDMIRX_GET_SCDC_VALUE)mdrv_HDMI_GetSCDCValue;
    psHDMIRxInstPri->fpHDMIRxGetTMDSRatesKHz = (IOCTL_HDMIRX_GET_TMDS_RATES_KHZ)mdrv_HDMI_GetTMDSRatesKHz;
    psHDMIRxInstPri->fpHDMIRxGetSCDCCableDetect = (IOCTL_HDMIRX_GET_SCDC_CABLE_DETECT)mdrv_HDMI_GetSCDCCableDetect;
    psHDMIRxInstPri->fpHDMIRxGetSourceSelect = (IOCTL_HDMIRX_GET_SOURCE_SELECT)mdrv_HDMI_GetSourceSelect;
    psHDMIRxInstPri->fpHDMIRxGetPacketStatus = (IOCTL_HDMIRX_GET_PACKET_STATUS)mdrv_HDMI_GetPacketStatus;
    psHDMIRxInstPri->fpHDMIRxGetPacketContent = (IOCTL_HDMIRX_GET_PACKET_CONTENT)mdrv_HDMI_GetPacketContent;
    psHDMIRxInstPri->fpHDMIRxCreatePath = (IOCTL_HDMIRX_CREATE_PATH)mdrv_HDMI_CreatePath;
    psHDMIRxInstPri->fpHDMIRxGetGCPacketInfo = (IOCTL_HDMIRX_GET_GC_PACKET_INFO)mdrv_HDMI_GetGCPacketInfo;
    psHDMIRxInstPri->fpHDMIRxErrorStatusUpdate = (IOCTL_HDMIRX_ERROR_STATUS_UPDATE)mdrv_HDMI_ErrorStatusUpdate;
    psHDMIRxInstPri->fpHDMIRxAudioContentProtectInfo = (IOCTL_HDMIRX_AUDIO_CONTENT_PROTECT_INFO)mdrv_HDMI_AudioContentProtectInfo;
    psHDMIRxInstPri->fpHDMIRxGetMIDInfoValue = (IOCTL_HDMIRX_GET_MID_INFO_VALUE)mdrv_HDMI_GetMIDInfoValue;
    psHDMIRxInstPri->fpHDMIRxGetPacketValue = (IOCTL_HDMIRX_GET_PACKET_VALUE)mdrv_HDMI_GetPacketValue;
    psHDMIRxInstPri->fpHDMIRxAudioChannelStatus = (IOCTL_HDMIRX_AUDIO_CHANNEL_STATUS)mdrv_HDMI_AudioChannelStatus;
    psHDMIRxInstPri->fpHDMIRxGetColorFormat = (IOCTL_HDMIRX_GET_COLOR_FORMAT)mdrv_HDMI_GetColorFormat;
    psHDMIRxInstPri->fpHDMIRxGetColorRange = (IOCTL_HDMIRX_GET_COLOR_RANGE)mdrv_HDMI_GetColorRange;
    psHDMIRxInstPri->fpHDMIRxGetAspectRatio = (IOCTL_HDMIRX_GET_ASPECT_RATIO)mdrv_HDMI_GetAspectRatio;
    psHDMIRxInstPri->fpHDMIRxGetActiveFormatAspectRatio = (IOCTL_HDMIRX_GET_ACTIVE_FORMAT_ASPECT_RATIO)mdrv_HDMI_GetActiveFormatAspectRatio;
    psHDMIRxInstPri->fpHDMIRxGetContentType = (IOCTL_HDMIRX_GET_CONTENT_TYPE)mdrv_HDMI_GetContentType;
    psHDMIRxInstPri->fpHDMIRxGetPixelRepetition = (IOCTL_HDMIRX_GET_PIXEL_REPETITION)mdrv_HDMI_GetPixelRepetition;
    psHDMIRxInstPri->fpHDMIRxGetAVIInfoFrameVersion = (IOCTL_HDMIRX_GET_AVI_INFOFRAME_VERSION)mdrv_HDMI_GetAVIInfoFrameVersion;
    psHDMIRxInstPri->fpHDMIRxGetActiveInformationPresent = (IOCTL_HDMIRX_GET_ACTIVE_INFORMATION_PRESENT)mdrv_HDMI_GetActiveInformationPresent;
    psHDMIRxInstPri->fpHDMIRxGetColormetry = (IOCTL_HDMIRX_GET_COLORIMETRY)mdrv_HDMI_GetColormetry;
    psHDMIRxInstPri->fpHDMIRxCheckVSPacket4K2K = (IOCTL_HDMIRX_CHECK_VS_PACKET_4K2K)mdrv_HDMI_CheckVSPacket4K2K;
    psHDMIRxInstPri->fpHDMIRx3Dor4K2KProcess = (IOCTL_HDMIRX_3D_4K2K_PROCESS)mdrv_HDMI_3Dor4K2KProcess;
    psHDMIRxInstPri->fpHDMIRxGetAdditionalFormat = (IOCTL_HDMIRX_GET_ADDITIONAL_FORMAT)mdrv_HDMI_GetVSAdditionalFormat;
    psHDMIRxInstPri->fpHDMIRxGetVS3DStructure = (IOCTL_HDMIRX_GET_3D_STRUCTURE)mdrv_HDMI_GetVS3DStructure;
    psHDMIRxInstPri->fpHDMIRxGetVS3DExtendData = (IOCTL_HDMIRX_GET_3D_EXTEND_DATA)mdrv_HDMI_GetVS3DExtendData;
    psHDMIRxInstPri->fpHDMIRxGetVS3DMetaField = (IOCTL_HDMIRX_GET_3D_META_FIELD)mdrv_HDMI_GetVS3DMetaField;
    psHDMIRxInstPri->fpHDMIRxGetVSVICCode = (IOCTL_HDMIRX_GET_VS_VIC_CODE)mdrv_HDMI_GetVSVICCode;
    psHDMIRxInstPri->fpHDMIRxGetVS4K2KVICCode = (IOCTL_HDMIRX_GET_VS_4K2K_VIC_CODE)mdrv_HDMI_GetVS4K2KVICCode;
    psHDMIRxInstPri->fpHDMIRxDVIMuxSwitch = (IOCTL_HDMIRX_DVI_MUX_SWITCH)mdrv_HDMI_DVIMuxSwitch;
    psHDMIRxInstPri->fpHDMIRxAverageScalingDown = (IOCTL_HDMIRX_AVERAGE_SCALING_DOWN)mdrv_HDMI_AverageScalingDown;
    psHDMIRxInstPri->fpHDMIRxGetTimingInfo = (IOCTL_HDMIRX_GET_TIMING_INFO)mdrv_HDMI_GetTimingInfo;
    psHDMIRxInstPri->fpHDMIRxPacketReset = (IOCTL_HDMIRX_PACKET_RESET)mdrv_HDMI_PacketReset;
    psHDMIRxInstPri->fpHDMIRxGetHDCPAuthVersion = (IOCTL_HDMIRX_GET_HDCP_AUTHVERSION)mdrv_HDCP_GetAuthVersion;
    psHDMIRxInstPri->fpHDMIRxGetISRC1HeaderInfo = (IOCTL_HDMIRX_GET_ISRC1_HEADERINFO)mdrv_HDMI_GetISRC1HeaderInfo;
    psHDMIRxInstPri->fpHDMIRxForcePowerDownPort = (IOCTL_HDMIRX_FORCE_POWER_DOWN_PORT)mdrv_HDMI_ForcePowerDownPort;
    /*************************** HDCP Repeater ***************************/
    psHDMIRxInstPri->fpHDMIRxWriteX74 = (IOCTL_HDMIRX_WRITE_X74)mdrv_HDCP_WriteX74;
    psHDMIRxInstPri->fpHDMIRxReadX74 = (IOCTL_HDMIRX_READ_X74)mdrv_HDCP_ReadX74;
    psHDMIRxInstPri->fpHDMIRxSetRepeater = (IOCTL_HDMIRX_SET_REPEATER)mdrv_HDCP_SetRepeater;
    psHDMIRxInstPri->fpHDMIRxSetBstatus = (IOCTL_HDMIRX_SET_BSTATUS)mdrv_HDCP_SetBstatus;
    psHDMIRxInstPri->fpHDMIRxSetHDMIMode = (IOCTL_HDMIRX_SET_HDMI_MODE)mdrv_HDCP_SetHDMIMode;
    psHDMIRxInstPri->fpHDMIRxGetInterruptStatus = (IOCTL_HDMIRX_GET_INTERRUPT_STATUS)mdrv_HDCP_GetInterruptStatus;
    psHDMIRxInstPri->fpHDMIRxWriteKSVList = (IOCTL_HDMIRX_WRITE_KSV_LIST)mdrv_HDCP_WriteKSVList;
    psHDMIRxInstPri->fpHDMIRxSetVPrime = (IOCTL_HDMIRX_SET_VPRIME)mdrv_HDCP_SetVPrime;
    /*************************** HDCP Repeater ***************************/
    psHDMIRxInstPri->fpHDMIRxFillCipherKey = (IOCTL_HDMIRX_FILL_CIPHER_KEY)mdrv_HDCP22_FillCipherKey;
    psHDMIRxInstPri->fpHDMIRxPortInit = (IOCTL_HDMIRX_PORT_INIT)mdrv_HDCP22_PortInit;
    psHDMIRxInstPri->fpHDMIRxPollingReadDone = (IOCTL_HDMIRX_POLLING_READ_DONE)mdrv_HDCP22_PollingReadDone;
    psHDMIRxInstPri->fpHDMIRxEnableCipher = (IOCTL_HDMIRX_ENABLE_CIPHER)mdrv_HDCP22_EnableCipher;
    psHDMIRxInstPri->fpHDMIRxSendMessage = (IOCTL_HDMIRX_SEND_MESSAGE)mdrv_HDCP22_SendMessage;
    psHDMIRxInstPri->fpHDMIRxHDCP22Handler = (IOCTL_HDMIRX_HDCP22_HANDER)mdrv_HDCP22_Handler;
    psHDMIRxInstPri->fpHDMIRxHDCP22WaitEvent = (IOCTL_HDMIRX_HDCP22_WAIT_EVENT)mdrv_HDCP22_WaitEvent;
    psHDMIRxInstPri->fpHDMIRxHDCP22SetEvent = (IOCTL_HDMIRX_HDCP22_SET_EVENT)mdrv_HDCP22_SetEvent;
    /*************************** HDCP STR Loadkey ***************************/
    psHDMIRxInstPri->fpHdcp14RxInitResumeCBFunc = (IOCTL_HDMIRX_HDCP14_InitResumeCBFunc)mdrv_HDCP14_InitResumeCBFunc;
    psHDMIRxInstPri->fpHdcp22RxInitResumeCBFunc = (IOCTL_HDMIRX_HDCP22_InitResumeCBFunc)mdrv_HDCP22_InitResumeCBFunc;
    psHDMIRxInstPri->fpHdcp14RxInitSuspendCBFunc = (IOCTL_HDMIRX_HDCP14_InitSuspendCBFunc)mdrv_HDCP14_InitSuspendCBFunc;
    psHDMIRxInstPri->fpHdcp22RxInitSuspendCBFunc = (IOCTL_HDMIRX_HDCP22_InitSuspendCBFunc)mdrv_HDCP22_InitSuspendCBFunc;
    /*************************** HDCP SVP ***************************/
    psHDMIRxInstPri->fpHdcp14RxInitSVPLockCBFunc = (IOCTL_HDMIRX_HDCP14_InitSVPLockCBFunc)mdrv_HDCP14_InitSVPLockCBFunc;
    psHDMIRxInstPri->fpHdcp14RxInitAccessWriteProtectedCBFunc = (IOCTL_HDMIRX_HDCP14_InitAccessWriteProtectedCBFunc)mdrv_HDCP14_InitAccessWriteProtectedCBFunc;
    psHDMIRxInstPri->fpHDMIAVIInfoframeInfo = (IOCTL_HDMI_AVI_INFOFRAME_INFO)mdrv_HDMI_avi_infoframe_info;
    psHDMIRxInstPri->fpHDMIAVIInfoframePort = (IOCTL_HDMI_AVIINFOFRAMEPORT)mdrv_HDMI_AVIInfoframePort;
    psHDMIRxInstPri->fpHDMIAudioCpDataInfo = (IOCTL_HDMI_AUDIO_CP_DATA_INFO)mdrv_HDMI_audio_cp_data_info;
    psHDMIRxInstPri->fpHDMIRxGetCRCValue = (IOCTL_HDMIRX_GET_CRC_VALUE)mdrv_HDMI_GetCRCValue;
    psHDMIRxInstPri->fpHDMIRxSetHotplugDelay = (IOCTL_HDMIRX_SET_HPD_DELAY)mdrv_HDMI_SetHotplugDelay;
    psHDMIRxInstPri->fpHDMIGetHDMIStatus = (IOCTL_HDMIRX_GET_HDMI_STATUS)mdrv_HDMI_GetHDMI_Status;
    psHDMIRxInstPri->fpHdmiRxClockStableStatus = (IOCTL_HDMIRX_CLOCKSTABLE_STATUS)mdrv_HDMI_ClockStableStatus;
    psHDMIRxInstPri->fpHdmiRxGetPipelineMode = (IOCTL_HDMIRX_PIPELINE_MODE)mdrv_HDMI_GetPipeLineMode;
    psHDMIRxInstPri->fpHdmiRxGet_HW_Ability = (IOCTL_HDMIRX_GET_HW_ABILITY)mdrv_HDMI_Get_HW_Ability;
    return UTOPIA_STATUS_SUCCESS;
}

//**************************************************************************
//  [Function Name]:
//                  HDMIRxIoctl()
//  [Description]
//
//  [Arguments]:
//
//  [Return]:
//
//**************************************************************************
MS_U32 HDMIRxIoctl(void* pInstance, MS_U32 u32Cmd, void* pArgs)
{
    void* pModule = NULL;
    MS_U32 ulReturnValue = UTOPIA_STATUS_SUCCESS;
    HDMI_RX_INSTANT_PRIVATE* psHDMIRxInstPri = NULL;

    UtopiaInstanceGetModule(pInstance, &pModule);
    UtopiaInstanceGetPrivate(pInstance, (void**)&psHDMIRxInstPri);

    switch(u32Cmd)
    {
        case MAPI_CMD_HDMIRX_INITIAL:
            {
                pstHDMI_INITIAL_SETTING pHDMIRxArgs = (pstHDMI_INITIAL_SETTING)pArgs;
                pHDMIRxArgs->bCreateHDCPTaskFlag = psHDMIRxInstPri->fpHDMIRxInitial(pInstance, pHDMIRxArgs->stInitialTable);
            }
            break;

        case MAPI_CMD_HDMIRX_STABLE_POLLING:
            psHDMIRxInstPri->fpHDMIRxStablePolling(pInstance);
            break;

        case MAPI_CMD_HDMIRX_GET_SOURCE_VERSION:
            {
                pstHDMI_GET_SOURCE_VERSION pHDMIRxArgs = (pstHDMI_GET_SOURCE_VERSION)pArgs;
                pHDMIRxArgs->ucSourceVersion = psHDMIRxInstPri->fpHDMIRxGetSourceVersion(pInstance, pHDMIRxArgs->enInputPortType);
            }
            break;

        case MAPI_CMD_HDMIRX_CHECK_HDCP_STATE:
            {
                pstHDMI_CHECK_HDCP_STATE pHDMIRxArgs = (pstHDMI_CHECK_HDCP_STATE)pArgs;
                pHDMIRxArgs->ucHDCPState = psHDMIRxInstPri->fpHDMIRxCheckHDCPState(pInstance, pHDMIRxArgs->enInputPortType);
            }
            break;

        case MAPI_CMD_HDMIRX_CHECK_HDCP_ENC_STATE:
            {
                pstHDMI_CHECK_HDCP_ENC_STATE pHDMIRxArgs = (pstHDMI_CHECK_HDCP_ENC_STATE)pArgs;
                pHDMIRxArgs->ucHDCPENCState = psHDMIRxInstPri->fpHDMIRxCheckHDCPENCState(pInstance, pHDMIRxArgs->enInputPortType);
            }
            break;

        case MAPI_CMD_HDMIRX_CHECK_HDCP14_KEY:
            {
                pstHDCP_INITPRODUCTIONKEY pHDMIRxArgs = (pstHDCP_INITPRODUCTIONKEY)pArgs;
                psHDMIRxInstPri->fpHDMIRxCheckHDCP14KeyVaild(pInstance, pHDMIRxArgs->pu8HdcpKeyData);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_HDCP14_KEY_VAILD:
            {
                pstHDMI_GET_HDCP14_KEY_VAILD pHDMIRxArgs = (pstHDMI_GET_HDCP14_KEY_VAILD)pArgs;
                pHDMIRxArgs->bHDCP14KeyVaildFlag = psHDMIRxInstPri->fpHDMIRxGetHDCP14KeyVaildFlag(pInstance);
            }
            break;

        case MAPI_CMD_HDMIRX_SET_HPD_INVERT_FLAG:
            {
                pstHDMI_SET_HPD_INVERT_FLAG pHDMIRxArgs = (pstHDMI_SET_HPD_INVERT_FLAG)pArgs;
                pHDMIRxArgs->bInverse = psHDMIRxInstPri->fpHDMIRxSetHPDInvertFlag(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->bInverse);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_PACKET_RECEIVE:
            {
                pstHDMI_PACKET_RECEIVED pHDMIRxArgs = (pstHDMI_PACKET_RECEIVED)pArgs;
                pHDMIRxArgs->ulPacketStatus = psHDMIRxInstPri->fpHDMIRxGetPacketReceive(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        /*************************** HDCP Repeater ***************************/
        case MAPI_CMD_HDMIRX_WRITE_X74:
            {
                pstHDCP_WRITE_X74 pHDMIRxArgs = (pstHDCP_WRITE_X74)pArgs;
                psHDMIRxInstPri->fpHDMIRxWriteX74(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->ucOffset, pHDMIRxArgs->ucData);
            }
            break;

        case MAPI_CMD_HDMIRX_READ_X74:
            {
                pstHDCP_READ_X74 pHDMIRxArgs = (pstHDCP_READ_X74)pArgs;
                pHDMIRxArgs->ucRetData = psHDMIRxInstPri->fpHDMIRxReadX74(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->ucOffset);
            }
            break;

        case MAPI_CMD_HDMIRX_SET_REPEATER:
            {
                pstHDCP_SET_REPEATER pHDMIRxArgs = (pstHDCP_SET_REPEATER)pArgs;
                psHDMIRxInstPri->fpHDMIRxSetRepeater(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->bIsRepeater);
            }
            break;

        case MAPI_CMD_HDMIRX_SET_BSTATUS:
            {
                pstHDCP_SET_BSTATUS pHDMIRxArgs = (pstHDCP_SET_BSTATUS)pArgs;
                psHDMIRxInstPri->fpHDMIRxSetBstatus(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->usBstatus);
            }
            break;

        case MAPI_CMD_HDMIRX_SET_HDMI_MODE:
            {
                pstHDCP_SET_HDMI_MODE pHDMIRxArgs = (pstHDCP_SET_HDMI_MODE)pArgs;
                psHDMIRxInstPri->fpHDMIRxSetHDMIMode(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->bHDMIMode);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_INTERRUPT_STATUS:
            {
                pstHDCP_GET_INTERRUPT_STATUS pHDMIRxArgs = (pstHDCP_GET_INTERRUPT_STATUS)pArgs;
                pHDMIRxArgs->ucRetIntStatus = psHDMIRxInstPri->fpHDMIRxGetInterruptStatus(pInstance, pHDMIRxArgs->enInputPortType);
            }
            break;

        case MAPI_CMD_HDMIRX_WRITE_KSV_LIST:
            {
                pstHDCP_WRITE_KSV_LIST pHDMIRxArgs = (pstHDCP_WRITE_KSV_LIST)pArgs;
                psHDMIRxInstPri->fpHDMIRxWriteKSVList(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->pucKSV, pHDMIRxArgs->ulLen);
            }
            break;

        case MAPI_CMD_HDMIRX_SET_VPRIME:
            {
                pstHDCP_SET_VPRIME pHDMIRxArgs = (pstHDCP_SET_VPRIME)pArgs;
                psHDMIRxInstPri->fpHDMIRxSetVPrime(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->pucVPrime);
            }
            break;
        /*************************** HDCP Repeater ***************************/

        case MAPI_CMD_HDMIRX_HDCP22_FILL_CIPHER_KEY:
            {
                pstHDCP22_FILL_CIPHER_KEY pHDMIRxArgs = (pstHDCP22_FILL_CIPHER_KEY)pArgs;
                psHDMIRxInstPri->fpHDMIRxFillCipherKey(pInstance, pHDMIRxArgs->ucPortIdx, pHDMIRxArgs->pucRiv, pHDMIRxArgs->pucSessionKey);
            }
            break;

        case MAPI_CMD_HDMIRX_HDCP22_PORT_INIT:
            {
                pstHDCP22_PORT_INIT pHDMIRxArgs = (pstHDCP22_PORT_INIT)pArgs;
                psHDMIRxInstPri->fpHDMIRxPortInit(pInstance, pHDMIRxArgs->ucPortIdx);
            }
            break;

        case MAPI_CMD_HDMIRX_HDCP22_POLLING_READ_DONE:
            {
                pstHDCP22_POLLING_READ_DONE pHDMIRxArgs = (pstHDCP22_POLLING_READ_DONE)pArgs;
                pHDMIRxArgs->bReturnValue = psHDMIRxInstPri->fpHDMIRxPollingReadDone(pInstance, pHDMIRxArgs->ucPortIdx);
            }
            break;

        case MAPI_CMD_HDMIRX_HDCP22_ENABLE_CIPHER:
            {
                pstHDCP22_ENABLE_CIPHER pHDMIRxArgs = (pstHDCP22_ENABLE_CIPHER)pArgs;
                psHDMIRxInstPri->fpHDMIRxEnableCipher(pInstance, pHDMIRxArgs->ucPortType, pHDMIRxArgs->ucPortIdx, pHDMIRxArgs->bIsEnable);
            }
            break;

        case MAPI_CMD_HDMIRX_HDCP22_SEND_MESSAGE:
            {
                pstHDCP22_SEND_MESSAGE pHDMIRxArgs = (pstHDCP22_SEND_MESSAGE)pArgs;
                psHDMIRxInstPri->fpHDMIRxSendMessage(pInstance, pHDMIRxArgs->ucPortType, pHDMIRxArgs->ucPortIdx, pHDMIRxArgs->pucData, pHDMIRxArgs->dwDataLen, pHDMIRxArgs->pDummy);
            }
            break;

        case MAPI_CMD_HDMIRX_HDCP22_HANDLER:
            {
                pstHDCP22_HANDLER pHDMIRxArgs = (pstHDCP22_HANDLER)pArgs;
                pHDMIRxArgs->bHdcp22RecvMsgFlag = psHDMIRxInstPri->fpHDMIRxHDCP22Handler(pInstance, pHDMIRxArgs->ucPortIdx, &pHDMIRxArgs->ucHdcp22PortType, pHDMIRxArgs->pucHdcp22MsgData, &pHDMIRxArgs->ucHdcp22MsgLen, pHDMIRxArgs->bIRQModeFlag);
            }
            break;

        case MAPI_CMD_HDMIRX_HDCP22_WAIT_EVENT:
            {
                pstHDCP22_WAIT_EVENT pHDMIRxArgs = (pstHDCP22_WAIT_EVENT)pArgs;
                pHDMIRxArgs->ucHDCPWriteDoneIndex = psHDMIRxInstPri->fpHDMIRxHDCP22WaitEvent(pInstance);
            }
            break;

        case MAPI_CMD_HDMIRX_HDCP22_SET_EVENT:
            {
                pstHDCP22_SET_EVENT pHDMIRxArgs = (pstHDCP22_SET_EVENT)pArgs;
                psHDMIRxInstPri->fpHDMIRxHDCP22SetEvent(pInstance, pHDMIRxArgs->usHDCPEventIndex);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_HDR_INFO_FRAME:
            {
                pstHDMI_GET_HDR_INFOFRAME pHDMIRxArgs = (pstHDMI_GET_HDR_INFOFRAME)pArgs;
                pHDMIRxArgs->bHDRReceiveFlag = psHDMIRxInstPri->fpHDMIRxGetHDRInfoFrame(pInstance, pHDMIRxArgs->ucHDMIInfoSource, pHDMIRxArgs->pusHDRInfoFrame);
            }
            break;

        case MAPI_CMD_HDMIRX_DATA_RTERM_CONTROL:
            {
                pstHDMI_DATA_RTERM_CONTROL pHDMIRxArgs = (pstHDMI_DATA_RTERM_CONTROL)pArgs;
                psHDMIRxInstPri->fpHDMIRxDataRtermControl(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->bDataRtermEnable, pHDMIRxArgs->bCheckInitFlag);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_HDCP_STATUS:
            {
                pstHDMI_GET_HDCP_STATUS pHDMIRxArgs = (pstHDMI_GET_HDCP_STATUS)pArgs;
                pHDMIRxArgs->usHDCPStatus = psHDMIRxInstPri->fpHDMIRxGetHDCPStatus(pInstance, pHDMIRxArgs->enInputPortType);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_SCDC_VALUE:
            {
                pstHDMI_GET_SCDC_VALUE pHDMIRxArgs = (pstHDMI_GET_SCDC_VALUE)pArgs;
                pHDMIRxArgs->ucRetData = psHDMIRxInstPri->fpHDMIRxGetSCDCValue(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->ucOffset);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_TMDS_RATES_KHZ:
            {
                pstHDMI_GET_TMDS_RATES_KHZ pHDMIRxArgs = (pstHDMI_GET_TMDS_RATES_KHZ)pArgs;
                pHDMIRxArgs->ulRetRates = psHDMIRxInstPri->fpHDMIRxGetTMDSRatesKHz(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->enType);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_SCDC_CABLE_DETECT:
            {
                pstHDMI_GET_SCDC_CABLE_DETECT pHDMIRxArgs = (pstHDMI_GET_SCDC_CABLE_DETECT)pArgs;
                pHDMIRxArgs->bCableDetectFlag = psHDMIRxInstPri->fpHDMIRxGetSCDCCableDetect(pInstance, pHDMIRxArgs->enInputPortType);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_SOURCE_SELECT:
            {
                pstHDMI_GET_SOURCE_SELECT pHDMIRxArgs = (pstHDMI_GET_SOURCE_SELECT)pArgs;
                pHDMIRxArgs->u8HDMIInfoSource = psHDMIRxInstPri->fpHDMIRxGetSourceSelect(pInstance, pHDMIRxArgs->enInputPortType);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_PACKET_STATUS:
            {
                pstHDMI_GET_PACKET_STATUS pHDMIRxArgs = (pstHDMI_GET_PACKET_STATUS)pArgs;
                pHDMIRxArgs->u32PacketStatus = psHDMIRxInstPri->fpHDMIRxGetPacketStatus(pInstance, pHDMIRxArgs->enInputPortType);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_PACKET_CONTENT:
            {
                pstHDMI_GET_PACKET_CONTENT pHDMIRxArgs = (pstHDMI_GET_PACKET_CONTENT)pArgs;
                pHDMIRxArgs->bGetContentFlag = psHDMIRxInstPri->fpHDMIRxGetPacketContent(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->enPacketType, pHDMIRxArgs->u8PacketLength, pHDMIRxArgs->u8PacketContent);
            }
            break;

        case MAPI_CMD_HDMIRX_FORCE_POWER_DOWN_PORT:
            {
                pstHDMI_FORCE_POWER_DOWN_PORT pHDMIRxArgs = (pstHDMI_FORCE_POWER_DOWN_PORT)pArgs;
                psHDMIRxInstPri->fpHDMIRxForcePowerDownPort(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->bPowerDown);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_MULTIVS_PACKET_CONTENT:
            {
                pstHDMI_GET_MULTIVS_PACKET_CONTENT pHDMIRxArgs = (pstHDMI_GET_MULTIVS_PACKET_CONTENT)pArgs;
                pHDMIRxArgs->bGetContentFlag = psHDMIRxInstPri->fpHDMIRxGetPacketContent(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->enPacketType, pHDMIRxArgs->u8PacketLength, pHDMIRxArgs->u8PacketContent);
            }
            break;

        case MAPI_CMD_HDMIRX_CREATE_PATH:
            {
                pstHDMI_CREATE_PATH pHDMIRxArgs = (pstHDMI_CREATE_PATH)pArgs;
                psHDMIRxInstPri->fpHDMIRxCreatePath(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->u8HDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_GC_PACKET_INFO:
            {
                pstHDMI_GC_INFO pHDMIRxArgs = (pstHDMI_GC_INFO)pArgs;
                pHDMIRxArgs->u16ReturnValue = psHDMIRxInstPri->fpHDMIRxGetGCPacketInfo(pInstance, pHDMIRxArgs->gcontrol, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_ERROR_STATUS_UPDATE:
            {
                pstHDMI_ERR_STATUS_UPDATE pHDMIRxArgs = (pstHDMI_ERR_STATUS_UPDATE)pArgs;
                pHDMIRxArgs->u8ReturnValue = psHDMIRxInstPri->fpHDMIRxErrorStatusUpdate(pInstance, pHDMIRxArgs->ucHDMIInfoSource, pHDMIRxArgs->u8value, pHDMIRxArgs->bread, pHDMIRxArgs->bNewPathFlag);
            }
            break;

        case MAPI_CMD_HDMIRX_AUDIO_CONTENT_PROTECT_INFO:
            {
                pstHDMI_AUDIO_CP_HDR_INFO pHDMIRxArgs = (pstHDMI_AUDIO_CP_HDR_INFO)pArgs;
                pHDMIRxArgs->u8ReturnValue = psHDMIRxInstPri->fpHDMIRxAudioContentProtectInfo(pInstance, pHDMIRxArgs->ucHDMIInfoSource, pHDMIRxArgs->bNewPathFlag);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_MID_INFO_VALUE:
            {
                pstHDMI_GET_MID_INFO pHDMIRxArgs = (pstHDMI_GET_MID_INFO)pArgs;
                psHDMIRxInstPri->fpHDMIRxGetMIDInfoValue(pInstance, pHDMIRxArgs->ucHDMIInfoSource, pHDMIRxArgs->pu8ManufactorData);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_PACKET_VALUE:
            {
                pstHDMI_GET_PACKET_VALUE pHDMIRxArgs = (pstHDMI_GET_PACKET_VALUE)pArgs;
                pHDMIRxArgs->bReturnValue = psHDMIRxInstPri->fpHDMIRxGetPacketValue(pInstance, pHDMIRxArgs->ucHDMIInfoSource, pHDMIRxArgs->u8state, pHDMIRxArgs->u8byte_idx, pHDMIRxArgs->pValue);
            }
            break;

        case MAPI_CMD_HDMIRX_AUDIO_CHANNEL_STATUS:
            {
                pstHDMI_AUDIO_CHANNEL_STATUS pHDMIRxArgs = (pstHDMI_AUDIO_CHANNEL_STATUS)pArgs;
                pHDMIRxArgs->u8ReturnValue = psHDMIRxInstPri->fpHDMIRxAudioChannelStatus(pInstance, pHDMIRxArgs->ucHDMIInfoSource, pHDMIRxArgs->u8byte);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_COLOR_FORMAT:
            {
                pstHDMI_GET_COLORFORMAT pHDMIRxArgs = (pstHDMI_GET_COLORFORMAT)pArgs;
                pHDMIRxArgs->eReturnValue = psHDMIRxInstPri->fpHDMIRxGetColorFormat(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_COLOR_RANGE:
            {
                pstHDMI_GET_COLORRANGE pHDMIRxArgs = (pstHDMI_GET_COLORRANGE)pArgs;
                pHDMIRxArgs->eReturnValue = psHDMIRxInstPri->fpHDMIRxGetColorRange(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_ASPECT_RATIO:
            {
                pstHDMI_GET_ASPECTRATIO pHDMIRxArgs = (pstHDMI_GET_ASPECTRATIO)pArgs;
                pHDMIRxArgs->eReturnValue = psHDMIRxInstPri->fpHDMIRxGetAspectRatio(pInstance, pHDMIRxArgs->ucHDMIInfoSource, pHDMIRxArgs->bEn_PAR, pHDMIRxArgs->bEn_AFAR);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_ACTIVE_FORMAT_ASPECT_RATIO:
            {
                pstHDMI_GET_ACTIVEFORMAT_ASPECTRATIO pHDMIRxArgs = (pstHDMI_GET_ACTIVEFORMAT_ASPECTRATIO)pArgs;
                pHDMIRxArgs->eReturnValue = psHDMIRxInstPri->fpHDMIRxGetActiveFormatAspectRatio(pInstance, pHDMIRxArgs->ucHDMIInfoSource, pHDMIRxArgs->bEn_AFAR);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_CONTENT_TYPE:
            {
                pstHDMI_GET_CONTENT_TYPE pHDMIRxArgs = (pstHDMI_GET_CONTENT_TYPE)pArgs;
                pHDMIRxArgs->enReturnValue = psHDMIRxInstPri->fpHDMIRxGetContentType(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_PIXEL_REPETITION:
            {
                pstHDMI_GET_PIXEL_REPETITION pHDMIRxArgs = (pstHDMI_GET_PIXEL_REPETITION)pArgs;
                pHDMIRxArgs->u8ReturnValue = psHDMIRxInstPri->fpHDMIRxGetPixelRepetition(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_AVI_INFOFRAME_VERSION:
            {
                pstHDMI_GET_AVIINFOFRAMEVER pHDMIRxArgs = (pstHDMI_GET_AVIINFOFRAMEVER)pArgs;
                pHDMIRxArgs->eReturnValue = psHDMIRxInstPri->fpHDMIRxGetAVIInfoFrameVersion(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_ACTIVE_INFORMATION_PRESENT:
            {
                pstHDMI_GET_AVIIINFO_ACTIVEINFOPRESENT pHDMIRxArgs = (pstHDMI_GET_AVIIINFO_ACTIVEINFOPRESENT)pArgs;
                pHDMIRxArgs->bReturnValue = psHDMIRxInstPri->fpHDMIRxGetActiveInformationPresent(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_COLORMETRY:
            {
                pstHDMI_GET_EXT_COLORIMETRY pHDMIRxArgs = (pstHDMI_GET_EXT_COLORIMETRY)pArgs;
                pHDMIRxArgs->enReturnValue = psHDMIRxInstPri->fpHDMIRxGetColormetry(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_CHECK_VS_PACKET_4K2K:
            {
                pstHDMI_CHECK_4K2K pHDMIRxArgs = (pstHDMI_CHECK_4K2K)pArgs;
                pHDMIRxArgs->bReturnValue = psHDMIRxInstPri->fpHDMIRxCheckVSPacket4K2K(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_3D_4K2K_PROCESS:
            {
                pstHDMI_3D_4K2K_PROCESS pHDMIRxArgs = (pstHDMI_3D_4K2K_PROCESS)pArgs;
                psHDMIRxInstPri->fpHDMIRx3Dor4K2KProcess(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_ADDITIONAL_FORMAT:
            {
                pstHDMI_CHECK_ADDITIONAL_FORMAT pHDMIRxArgs = (pstHDMI_CHECK_ADDITIONAL_FORMAT)pArgs;
                pHDMIRxArgs->eReturnValue = psHDMIRxInstPri->fpHDMIRxGetAdditionalFormat(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_3D_STRUCTURE:
            {
                pstHDMI_GET_3D_STRUCTURE pHDMIRxArgs = (pstHDMI_GET_3D_STRUCTURE)pArgs;
                pHDMIRxArgs->eReturnValue = psHDMIRxInstPri->fpHDMIRxGetVS3DStructure(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_3D_EXTEND_DATA:
            {
                pstHDMI_GET_3D_EXT_DATA pHDMIRxArgs = (pstHDMI_GET_3D_EXT_DATA)pArgs;
                pHDMIRxArgs->eReturnValue = psHDMIRxInstPri->fpHDMIRxGetVS3DExtendData(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_3D_META_FIELD:
            {
                pstHDMI_GET_3D_META_FIELD pHDMIRxArgs = (pstHDMI_GET_3D_META_FIELD)pArgs;
                psHDMIRxInstPri->fpHDMIRxGetVS3DMetaField(pInstance, pHDMIRxArgs->ucHDMIInfoSource, pHDMIRxArgs->pdata);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_VS_VIC_CODE:
            {
                pstHDMI_GET_VIC_CODE pHDMIRxArgs = (pstHDMI_GET_VIC_CODE)pArgs;
                pHDMIRxArgs->u8ReturnValue = psHDMIRxInstPri->fpHDMIRxGetVSVICCode(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_VS_4K2K_VIC_CODE:
            {
                pstHDMI_GET_4KX2K_VIC_CODE pHDMIRxArgs = (pstHDMI_GET_4KX2K_VIC_CODE)pArgs;
                pHDMIRxArgs->eReturnValue = psHDMIRxInstPri->fpHDMIRxGetVS4K2KVICCode(pInstance, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_DVI_MUX_SWITCH:
            {
                pstDVI_SWITCHSRC pHDMIRxArgs = (pstDVI_SWITCHSRC)pArgs;
                psHDMIRxInstPri->fpHDMIRxDVIMuxSwitch(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->ucHDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_AVERAGE_SCALING_DOWN:
            {
                pstHDMI_AVG_SCALERINGDOWN pHDMIRxArgs = (pstHDMI_AVG_SCALERINGDOWN)pArgs;
                psHDMIRxInstPri->fpHDMIRxAverageScalingDown(pInstance, pHDMIRxArgs->ucHDMIInfoSource, pHDMIRxArgs->bTrue);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_TIMING_INFO:
            {
                pstHDMI_GET_DATA_INFO pHDMIRxArgs = (pstHDMI_GET_DATA_INFO)pArgs;
                pHDMIRxArgs->usReturnValue = psHDMIRxInstPri->fpHDMIRxGetTimingInfo(pInstance, pHDMIRxArgs->enInfo, pHDMIRxArgs->ucHDMIInfoSource, pHDMIRxArgs->bNewPathFlag);
            }
            break;

        case MAPI_CMD_HDMIRX_PACKET_RESET:
            {
                pstHDMI_PKT_RESET pHDMIRxArgs = (pstHDMI_PKT_RESET)pArgs;
                psHDMIRxInstPri->fpHDMIRxPacketReset(pInstance, pHDMIRxArgs->breset, pHDMIRxArgs->u8HDMIInfoSource);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_HDCP_AUTHVERSION:
            {
                pstHDMI_HDCP_AUTHVERSION pHDMIRxArgs = (pstHDMI_HDCP_AUTHVERSION)pArgs;
                pHDMIRxArgs->enHDCPAuthVersion = psHDMIRxInstPri->fpHDMIRxGetHDCPAuthVersion(pInstance, pHDMIRxArgs->enInputPortType);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_ISRC1_HEADER_INFO:
            {
                pstHDMI_AUDIO_CP_HDR_INFO pHDMIRxArgs = (pstHDMI_AUDIO_CP_HDR_INFO)pArgs;
                pHDMIRxArgs->u8ReturnValue = psHDMIRxInstPri->fpHDMIRxGetISRC1HeaderInfo(pInstance, pHDMIRxArgs->ucHDMIInfoSource, pHDMIRxArgs->bNewPathFlag);
            }
            break;

        case MAPI_CMD_HDCP14_INITRESUMECBFUNC:
            {
                pstHDCP14RXRESUME pHDMIRxArgs = (pstHDCP14RXRESUME)pArgs;
                psHDMIRxInstPri->fpHdcp14RxInitResumeCBFunc(pInstance, pHDMIRxArgs->fpHdcp14RxResumeCBFunc, pHDMIRxArgs->pContext);
            }
            break;

        case MAPI_CMD_HDCP22_INITRESUMECBFUNC:
            {
                pstHDCP22RXRESUME pHDMIRxArgs = (pstHDCP22RXRESUME)pArgs;
                psHDMIRxInstPri->fpHdcp22RxInitResumeCBFunc(pInstance, pHDMIRxArgs->fpHdcp22RxResumeCBFunc, pHDMIRxArgs->pContext);
            }
            break;

        case MAPI_CMD_HDCP14_INITSUSPENDCBFUNC:
            {
                pstHDCP14RXSUSPEND pHDMIRxArgs = (pstHDCP14RXSUSPEND)pArgs;
                psHDMIRxInstPri->fpHdcp14RxInitSuspendCBFunc(pInstance, pHDMIRxArgs->fpHdcp14RxSuspendCBFunc, pHDMIRxArgs->pContext);
            }
            break;

        case MAPI_CMD_HDCP14_INITACCESSWRITEPROTECTEDREGCBFUNC:
            {
                pstHDCP14RX_ACCESS_WRITE_PROTECTED_REG pHDMIRxArgs = (pstHDCP14RX_ACCESS_WRITE_PROTECTED_REG)pArgs;
                psHDMIRxInstPri->fpHdcp14RxInitAccessWriteProtectedCBFunc(pInstance, pHDMIRxArgs->fpHdcp14RxAccessWriteProtectedRegCBFunc, pHDMIRxArgs->pContext);
            }
            break;

        case MAPI_CMD_HDCP22_INITSUSPENDCBFUNC:
            {
                pstHDCP22RXSUSPEND pHDMIRxArgs = (pstHDCP22RXSUSPEND)pArgs;
                psHDMIRxInstPri->fpHdcp22RxInitSuspendCBFunc(pInstance, pHDMIRxArgs->fpHdcp22RxSuspendCBFunc, pHDMIRxArgs->pContext);
            }
            break;
        case MAPI_CMD_HDCP14_INITSVPLOCKCBFUNC:
            {
                pstHDCP14SVPLOCK pHDMIRxArgs = (pstHDCP14SVPLOCK)pArgs;
                psHDMIRxInstPri->fpHdcp14RxInitSVPLockCBFunc(pInstance, pHDMIRxArgs->fpHdcp14RxSVPLockCBFunc, pHDMIRxArgs->pContext);
            }
            break;

        case MAPI_CMD_HDMI_AVI_INFOFRAME_INFO:
            {
                pstHDMI_AVI_INFOFRAME_INFO pHDMIRxArgs = (pstHDMI_AVI_INFOFRAME_INFO)pArgs;
                pHDMIRxArgs->u8ReturnValue = psHDMIRxInstPri->fpHDMIAVIInfoframeInfo(pInstance, pHDMIRxArgs->u8byte);
            }
            break;

        case MAPI_CMD_HDMI_AVIINFOFRAMEPORT:
            {
                pstHDMI_AVIINFOFRAMEPORT pHDMIRxArgs = (pstHDMI_AVIINFOFRAMEPORT)pArgs;
                pHDMIRxArgs->u8ReturnValue = psHDMIRxInstPri->fpHDMIAVIInfoframePort(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->u8byte);
            }
            break;

        case MAPI_CMD_HDMI_AUDIO_CP_DATA_INFO:
            {
                pstHDMI_AUDIO_CP_DATA_INFO pHDMIRxArgs = (pstHDMI_AUDIO_CP_DATA_INFO)pArgs;
                pHDMIRxArgs->u8ReturnValue = psHDMIRxInstPri->fpHDMIAudioCpDataInfo(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->u8byte);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_CRC_VALUE:
            {
                pstHDMI_GET_CRC_VALUE pHDMIRxArgs = (pstHDMI_GET_CRC_VALUE)pArgs;
                pHDMIRxArgs->bIsValid = psHDMIRxInstPri->fpHDMIRxGetCRCValue(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->u8Channel, pHDMIRxArgs->u16CRCVal);
            }
            break;

        case MAPI_CMD_HDMIRX_SET_HPD_DELAY:
            {
                pstHDMI_SET_HPD_DELAY pHDMIRxArgs = (pstHDMI_SET_HPD_DELAY)pArgs;
                psHDMIRxInstPri->fpHDMIRxSetHotplugDelay(pInstance, pHDMIRxArgs->u8HotplugDelay);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_HDMI_STATUS:
            {
                pstHDMI_GET_HDMI_STATUS pHDMIRxArgs = (pstHDMI_GET_HDMI_STATUS)pArgs;
                pHDMIRxArgs->u16Ret = psHDMIRxInstPri->fpHDMIGetHDMIStatus(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->enInfoType, pHDMIRxArgs->u8Param);
            }
            break;

        case MAPI_CMD_HDMIRX_CLOCKSTABLE_STATUS:
            {
                pstHDMI_GET_CLOCKSTABLE_STATUS pHDMIRxArgs = (pstHDMI_GET_CLOCKSTABLE_STATUS)pArgs;
                pHDMIRxArgs->bClockStableStatus = psHDMIRxInstPri->fpHdmiRxClockStableStatus(pInstance, pHDMIRxArgs->enInputPortType);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_PIPELINE_MODE:
            {
                pstHDMI_PIPELINE_MODE pHDMIRxArgs = (pstHDMI_PIPELINE_MODE)pArgs;
                pHDMIRxArgs->enPipeLineMode = psHDMIRxInstPri->fpHdmiRxGetPipelineMode(pInstance);
            }
            break;

        case MAPI_CMD_HDMIRX_GET_HW_ABILITY:
            {
                pstHDMI_HW_ABILITY pHDMIRxArgs = (pstHDMI_HW_ABILITY)pArgs;
                pHDMIRxArgs->u32Result = psHDMIRxInstPri->fpHdmiRxGet_HW_Ability(pInstance, pHDMIRxArgs->enInputPortType, pHDMIRxArgs->enWhichAbility);
            }
            break;

        default:
            ulReturnValue = UTOPIA_STATUS_FAIL;
            break;
    };

    return ulReturnValue;
}

//**************************************************************************
//  [Function Name]:
//                  HDMIRxClose()
//  [Description]
//
//  [Arguments]:
//
//  [Return]:
//
//**************************************************************************
MS_U32 HDMIRxClose(void* pInstance)
{
    UtopiaInstanceDelete(pInstance);

    return TRUE;
}

//**************************************************************************
//  [Function Name]:
//                  HDMIRxSTR()
//  [Description]
//
//  [Arguments]:
//
//  [Return]:
//
//**************************************************************************
MS_U32 HDMIRxSTR(MS_U32 ulPowerState, void* pModule)
{
    MS_U32 ulReturnValue = UTOPIA_STATUS_FAIL;

    if(mdrv_HDMI_STREventProc(pModule, (EN_POWER_MODE)ulPowerState) == UTOPIA_STATUS_SUCCESS)
    {
        ulReturnValue = UTOPIA_STATUS_SUCCESS;
    }

    return ulReturnValue;
}

#ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT
//**************************************************************************
//  [Function Name]:
//                  HDMIRxMdbIoctl()
//  [Description]
//
//  [Arguments]:
//
//  [Return]:
//
//**************************************************************************
MS_U32 HDMIRxMdbIoctl(MS_U32 cmd, const void* const pArgs)
{
    void* pInstance = NULL;
    MS_U32 ulReturnValue = UTOPIA_STATUS_FAIL;
    MDBCMD_CMDLINE_PARAMETER *paraCmdLine;
    MDBCMD_GETINFO_PARAMETER *paraGetInfo;

    pInstance = UtopiaModuleGetLocalInstantList(MODULE_HDMIRX, pInstance);

    if(pInstance != NULL)
    {
        switch(cmd)
        {
            case MDBCMD_CMDLINE:
                paraCmdLine = (MDBCMD_CMDLINE_PARAMETER *)pArgs;
                MdbPrint(paraCmdLine->u64ReqHdl,"u32CmdSize: %d\n", paraCmdLine->u32CmdSize);
                mdrv_HDMI_MDCMDEchoCommand(pInstance, paraCmdLine->u64ReqHdl, paraCmdLine->pcCmdLine);
                paraCmdLine->result = MDBRESULT_SUCCESS_FIN;
                break;

            case MDBCMD_GETINFO:
                paraGetInfo = (MDBCMD_GETINFO_PARAMETER *)pArgs;
                mdrv_HDMI_MDCMDGetInfo(pInstance, paraGetInfo->u64ReqHdl);
                paraGetInfo->result = MDBRESULT_SUCCESS_FIN;
                break;

            default:
                paraGetInfo = (MDBCMD_GETINFO_PARAMETER *)pArgs;
                MdbPrint(paraGetInfo->u64ReqHdl,"unknown cmd\n", __LINE__);
                break;
        };

        ulReturnValue = UTOPIA_STATUS_SUCCESS;
    }

    return ulReturnValue;
}
#endif

//**************************************************************************
//  [Function Name]:
//                  HDMIRXRegisterToUtopia()
//  [Description]
//
//  [Arguments]:
//
//  [Return]:
//
//**************************************************************************
void HDMIRXRegisterToUtopia(FUtopiaOpen ModuleType)
{
    void* pUtopiaModule = NULL;
    void* psResource = NULL;

    // 1. deal with module
    UtopiaModuleCreate(MODULE_HDMIRX, 0, &pUtopiaModule);
    UtopiaModuleRegister(pUtopiaModule);
    // register func for module, after register here, then ap call UtopiaOpen/UtopiaIoctl/UtopiaClose can call to these registered standard func
    UtopiaModuleSetupFunctionPtr(pUtopiaModule, (FUtopiaOpen)HDMIRxOpen, (FUtopiaClose)HDMIRxClose, (FUtopiaIOctl)HDMIRxIoctl);

#if(defined(MSOS_TYPE_LINUX_KERNEL))
    UtopiaModuleSetupSTRFunctionPtr(pUtopiaModule, (FUtopiaSTR)HDMIRxSTR);
#endif

#ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT
    UtopiaModuleRegisterMdbNode("HDMIRX", (FUtopiaMdbIoctl)HDMIRxMdbIoctl);
#endif

    // 2. deal with resource
    // start func to add res, call once will create 2 access in resource. Also can declare BDMA_POOL_ID_BDMA1 for another channel depend on driver owner.
    UtopiaModuleAddResourceStart(pUtopiaModule, HDMI_RX_POOL);
    // resource can alloc private for internal use, ex, BDMA_RESOURCE_PRIVATE
    UtopiaResourceCreate("HDMIRX", sizeof(HDMI_RX_RESOURCE_PRIVATE), &psResource);
    // func to reg res
    UtopiaResourceRegister(pUtopiaModule, psResource, HDMI_RX_POOL);

    UtopiaModuleAddResourceEnd(pUtopiaModule, HDMI_RX_POOL);
}

//**************************************************************************
//  [Function Name]:
//                  HDMIEARCOpen()
//  [Description]
//
//  [Arguments]:
//
//  [Return]:
//
//**************************************************************************
MS_U32 HDMIEARCOpen(void** ppInstance, const void* const pAttribute)
{
    HDMI_EARC_INSTANT_PRIVATE *psHDMIEARCInstPri = NULL;

    //UTOPIA_TRACE(MS_UTOPIA_DB_LEVEL_TRACE,printf("enter %s %d\n",__FUNCTION__,__LINE__));
    // instance is allocated here, also can allocate private for internal use, ex, BDMA_INSTANT_PRIVATE
    UtopiaInstanceCreate(sizeof(HDMI_EARC_INSTANT_PRIVATE), ppInstance);
    // setup func in private and assign the calling func in func ptr in instance private
    UtopiaInstanceGetPrivate(*ppInstance, (void**)&psHDMIEARCInstPri);

    psHDMIEARCInstPri->fpHDMIEARCInitialSetting = (IOCTL_HDMIEARC_INITIAL_SETTING)mdrv_EARC_Init;
    psHDMIEARCInstPri->fpHDMIEARCGetConnectStatus = (IOCTL_HDMIEARC_GET_CONNECT_STATUS)mdrv_EARC_Get_Connect_Status;
    psHDMIEARCInstPri->fpHDMIEARCGetCapabilityInfo = (IOCTL_HDMIEARC_GET_CAPABILITY_INFO)mdrv_EARC_Get_Capability_Info;
    psHDMIEARCInstPri->fpHDMIEARCGetLatencyInfo = (IOCTL_HDMIEARC_GET_LATENCY_INFO)mdrv_EARC_Get_Latency_Info;
    psHDMIEARCInstPri->fpHDMIEARCSetATOPSettingAUPLL = (IOCTL_HDMIEARC_SET_ATOPSETTING_AUPLL)mdrv_EARC_Set_ATOPSetting_AUPLL;
    psHDMIEARCInstPri->fpHDMIEARCSetAudioOutputStream = (IOCTL_HDMIEARC_SET_AUDIO_OUTPUT_STREAM)mdrv_EARC_Set_AudioOutputStream;
    psHDMIEARCInstPri->fpHDMIEARCSetSupportMode = (IOCTL_HDMIEARC_SET_SUPPORT_MODE)mdrv_EARC_Set_SupportMode;
    psHDMIEARCInstPri->fpHDMIEARCGetChipCapability = (IOCTL_HDMIEARC_GET_CHIP_CAPABILITY)mdrv_EARC_Get_ChipCapability;
    psHDMIEARCInstPri->fpHDMIEARCOutputPortSelect = (IOCTL_HDMIEARC_OUTPUT_PORT_SELECT)mdrv_EARC_OutputPortSelect;

    return UTOPIA_STATUS_SUCCESS;
}

//**************************************************************************
//  [Function Name]:
//                  HDMIEARCIoctl()
//  [Description]
//
//  [Arguments]:
//
//  [Return]:
//
//**************************************************************************
MS_U32 HDMIEARCIoctl(void* pInstance, MS_U32 u32Cmd, void* pArgs)
{
    void* pModule = NULL;
    MS_U32 ulReturnValue = UTOPIA_STATUS_SUCCESS;
    HDMI_EARC_INSTANT_PRIVATE* psHDMIEARCInstPri = NULL;

    UtopiaInstanceGetModule(pInstance, &pModule);
    UtopiaInstanceGetPrivate(pInstance, (void**)&psHDMIEARCInstPri);

    switch(u32Cmd)
    {
        case MAPI_CMD_HDMIEARC_INITIAL_SETTING:
            {
                pstEARC_INITIAL_SETTING pHDMIEARCArgs = (pstEARC_INITIAL_SETTING)pArgs;
                pHDMIEARCArgs->bReDoneFlag = psHDMIEARCInstPri->fpHDMIEARCInitialSetting(pInstance);
            }
            break;

        case MAPI_CMD_HDMIEARC_GET_CONNECT_STATUS:
            {
                pstEARC_GET_CONNECT_STATUS pHDMIEARCArgs = (pstEARC_GET_CONNECT_STATUS)pArgs;
                pHDMIEARCArgs->u8EARCConnectStatus = psHDMIEARCInstPri->fpHDMIEARCGetConnectStatus(pInstance);
            }
            break;

        case MAPI_CMD_HDMIEARC_GET_CAPABILITY_INFO:
            {
                pstEARC_GET_CAPABILITY_INFO pHDMIEARCArgs = (pstEARC_GET_CAPABILITY_INFO)pArgs;
                psHDMIEARCInstPri->fpHDMIEARCGetCapabilityInfo(pInstance, &pHDMIEARCArgs->stCapabilityInfo);
            }
            break;

        case MAPI_CMD_HDMIEARC_GET_LATENCY_INFO:
            {
                pstEARC_GET_LATENCY_INFO pHDMIEARCArgs = (pstEARC_GET_LATENCY_INFO)pArgs;
                psHDMIEARCInstPri->fpHDMIEARCGetLatencyInfo(pInstance, &pHDMIEARCArgs->stEARCLatencyInfo);
            }
            break;

        case MAPI_CMD_HDMIEARC_SET_ATOPSETTING_AUPLL:
            {
                pstEARC_SET_ATOPSETTING_AUPLL pHDMIEARCArgs = (pstEARC_SET_ATOPSETTING_AUPLL)pArgs;
                psHDMIEARCInstPri->fpHDMIEARCSetATOPSettingAUPLL(pInstance, &pHDMIEARCArgs->stAudioInfo);
            }
            break;

        case MAPI_CMD_HDMIEARC_SET_AUDIO_OUTPUT_STREAM:
            {
                pstEARC_SET_AUDIO_OUTPUT_STREAM pHDMIEARCArgs = (pstEARC_SET_AUDIO_OUTPUT_STREAM)pArgs;
                psHDMIEARCInstPri->fpHDMIEARCSetAudioOutputStream(pInstance, pHDMIEARCArgs->bEnableFlag);
            }
            break;

        case MAPI_CMD_HDMIEARC_SET_SUPPORT_MODE:
            {
                pstEARC_SET_SUPPORT_MODE pHDMIEARCArgs = (pstEARC_SET_SUPPORT_MODE)pArgs;
                psHDMIEARCInstPri->fpHDMIEARCSetSupportMode(pInstance, pHDMIEARCArgs->enSupportMode);
            }
            break;

        case MAPI_CMD_HDMIEARC_GET_CHIPCAPABILITY:
            {
                pstEARC_GET_CHIP_CAPABILITY pHDMIEARCArgs = (pstEARC_GET_CHIP_CAPABILITY)pArgs;
                pHDMIEARCArgs->u8ChipCapability = psHDMIEARCInstPri->fpHDMIEARCGetChipCapability(pInstance);
            }
            break;

        case MAPI_CMD_HDMIEARC_OUTPUT_PORT_SELECT:
            {
                pstEARC_OUTPUT_PORT_SELECT pHDMIEARCArgs = (pstEARC_OUTPUT_PORT_SELECT)pArgs;
                psHDMIEARCInstPri->fpHDMIEARCOutputPortSelect(pInstance, pHDMIEARCArgs->enInputPortType, pHDMIEARCArgs->bEnable5VDetectInvert, pHDMIEARCArgs->bEnableHPDInvert);
            }
            break;

        default:
            break;
    }

    return ulReturnValue;
}

//**************************************************************************
//  [Function Name]:
//                  HDMIEARCClose()
//  [Description]
//
//  [Arguments]:
//
//  [Return]:
//
//**************************************************************************
MS_U32 HDMIEARCClose(void* pInstance)
{
    UtopiaInstanceDelete(pInstance);

    return TRUE;
}

//**************************************************************************
//  [Function Name]:
//                  HDMIEARCSTR()
//  [Description]
//
//  [Arguments]:
//
//  [Return]:
//
//**************************************************************************
MS_U32 HDMIEARCSTR(MS_U32 ulPowerState, void* pModule)
{
    MS_U32 ulReturnValue = UTOPIA_STATUS_FAIL;

    if(mdrv_EARC_STREventProc(pModule, (EN_POWER_MODE)ulPowerState) == UTOPIA_STATUS_SUCCESS)
    {
        ulReturnValue = UTOPIA_STATUS_SUCCESS;
    }

    return ulReturnValue;
}

//**************************************************************************
//  [Function Name]:
//                  HDMIEARCRegisterToUtopia()
//  [Description]
//
//  [Arguments]:
//
//  [Return]:
//
//**************************************************************************
void HDMIEARCRegisterToUtopia(FUtopiaOpen ModuleType)
{
    void* pUtopiaModule = NULL;
    void* psResource = NULL;

    // 1. deal with module
    UtopiaModuleCreate(MODULE_HDMIEARC, 0, &pUtopiaModule);
    UtopiaModuleRegister(pUtopiaModule);
    // register func for module, after register here, then ap call UtopiaOpen/UtopiaIoctl/UtopiaClose can call to these registered standard func
    UtopiaModuleSetupFunctionPtr(pUtopiaModule, (FUtopiaOpen)HDMIEARCOpen, (FUtopiaClose)HDMIEARCClose, (FUtopiaIOctl)HDMIEARCIoctl);

#if(defined(MSOS_TYPE_LINUX_KERNEL))
    UtopiaModuleSetupSTRFunctionPtr(pUtopiaModule, (FUtopiaSTR)HDMIEARCSTR);
#endif

#ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT
    //UtopiaModuleRegisterMdbNode("HDMIEARC", (FUtopiaMdbIoctl)HDMIEARCMdbIoctl);
#endif

    // 2. deal with resource
    // start func to add res, call once will create 2 access in resource. Also can declare BDMA_POOL_ID_BDMA1 for another channel depend on driver owner.
    UtopiaModuleAddResourceStart(pUtopiaModule, HDMI_EARC_POOL);
    // resource can alloc private for internal use, ex, BDMA_RESOURCE_PRIVATE
    UtopiaResourceCreate("HDMIEARC", sizeof(HDMI_EARCTX_RESOURCE_PRIVATE), &psResource);
    // func to reg res
    UtopiaResourceRegister(pUtopiaModule, psResource, HDMI_EARC_POOL);

    UtopiaModuleAddResourceEnd(pUtopiaModule, HDMI_EARC_POOL);
}

#endif // _API_HDMI_RX_V2_C_
#endif

