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

/*-----------------------------------------------------------------------------
 *
 * $Author: dtvbm11 $
 * $Date: 2015/11/10 $
 * $RCSfile: drv_async.h,v $
 * $Revision: #1 $
 *
 *---------------------------------------------------------------------------*/

/*
 *
 * THIS HEAFER FILE SHOULD ONLY INCLUDED BY DRV_TDTC.C
 * OTHER MODULE SHOULD USE drv_tdtv_drvif.h
 *
 */

#include "drv_tdtv_drvif.h"

#ifndef _DRV_TDTV_H
#define _DRV_TDTV_H

#define AUTO_ONLY_START E_TDTV_DECODER_INPUT_FS_I
#define AUTO_ONLY_END   E_TDTV_DECODER_INPUT_FP_P

#define TD_TBL_UNPACK_DEC(x)      ((((*(pu8VdoPathProcCfg+((UINT32)x)))>>(TD_TBL_POS_DEC))&TD_MSK(DEC_W)))
#define TD_TBL_UNPACK_DQC(x)      ((((*(pu8VdoPathProcCfg+((UINT32)x)))>>(TD_TBL_POS_DQC))&TD_MSK(DQC_W)))

//#define TD_TBL_UNPACK_TTT(x)      ((((*(pu8VdoPathProcCfg+((UINT32)x)))>>(TD_TBL_POS_TTT))&TD_MSK(TTT_W)))
#define TD_TBL_UNPACK_TTT(path,x)      ((path)==SV_VP_MAIN? \
    (((*(pu8VdoPathProcCfg+((UINT32)x)))>>(TD_TBL_POS_TTT))&TD_MSK(TTT_W)): \
    ((u8VdoPathProc322Cfg[x])>>TD_TBL_POS_TTT)&TD_MSK(TTT_W))

#define TD_TBL_UNPACK_MIB(x)      ((((*(pu8VdoPathProcCfg+((UINT32)x)))>>(TD_TBL_POS_MIB))&TD_MSK(MIB_W)))
//#define TD_TBL_UNPACK_SCL(x)      ((((*(pu8VdoPathProcCfg+((UINT32)x)))>>(TD_TBL_POS_SCL))&TD_MSK(SCL_W)))

#define TD_TBL_UNPACK_SCL(path,x)      ((path)==SV_VP_MAIN? \
    (((*(pu8VdoPathProcCfg+((UINT32)x)))>>(TD_TBL_POS_SCL))&TD_MSK(SCL_W)): \
    ((u8VdoPathProc322Cfg[x])>>TD_TBL_POS_SCL)&TD_MSK(SCL_W))


#define TD_TBL_UNPACK_TTD(x)      ((((*(pu8VdoPathProcCfg+((UINT32)x)))>>(TD_TBL_POS_TTD))&TD_MSK(TTD_W)))
#define TD_TBL_UNPACK_MJC(x)      ((((*(pu8VdoPathProcCfg+((UINT32)x)))>>(TD_TBL_POS_MJC))&TD_MSK(MJC_W)))

#define TDTV_TBL_CFG() do{ \
    pu8VdoPathProcCfg=(E_TDTV_UI_3D_2_2D_OFF != eDrvTDTVGet3D22D(SV_VP_MAIN)) ? \
        u8VdoPathProc322Cfg : u8VdoPathProcCfg; \
        }while(0)


//Indivisual Module COnfiguration
typedef struct{
    UINT32 DEC[NUM_OF_DECOER];
    UINT32 DQC;
    UINT32 TTT;//2D to 3D
    UINT32 DI;
    UINT32 SC;
    UINT32 MJC;
    UINT32 TTD;
    S_TDTV_OSD_CONFIG OSD;
    S_TDTV_OSTG_CONFIG OSTG;
}S_TDTVVdoCfg;

#define TD_2ENUM_TO_INT(DecOut,DecIn) (((UINT32)(DecOut)<<16)|((UINT32)(DecIn)))

#define PANEL_CLK_H (148500000)
#define PANEL_CLK_L (74250000)

#define NUM_OF_PATH (SV_VP_PIP+1)

#define TTD_MODE_CHANGE_CB(module)   do{if(TDTVCallback[(module)]!=NULL) TDTVCallback[(module)](NULL);}while(0)


E_TDTV_UI_3D_2_2D eDrvTDTVGet3D22D(UINT32 u4Path);

void vDrvTDTVMiscInit(void);
void vDrvTDTVMiscCfg(void);
void vPrintfMIBSCStatus(void);
UINT8 u1DrvTDTVCurIs3DMode(void);
E_TDTV_UI_3D_PACKING u1DrvTDTVGetCur3DMode(void);


/**
 * @brief : Is Using Dual MIB Engine to procssing Frame Packing Interlace Src?
 * @retval: TRUE / FALSE
 */

UINT32 u4DrvTDTVIsDualFPI(void);

/**
 * @brief : Query Function for 3D Photo cropping info
 * @retval: IS 3D photo or not
 */
UINT32 u4DrvTDTVIs3DPhoto(TDTV_3D_CROP_INTO_T* prCropInfo);

/**
 * @brief : Trigger TDTV Cfg Check
 * @retval: NONO
 */
VOID vDrvTDTVTriggerCfgCheck(void);

#endif
