/* 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.
 *
 *****************************************************************************/

  /*************************************************************************
 *
 * Filename:
 * ---------
 *   $Workfile: drv_predown.h $
 *
 * Project:
 * --------
 *
 *
 * Description:
 * ------------
 *
 *
 * Author:
 * -------
 *
 *
 * Last changed:
 * -------------
 * $Author: peng.liu $
 *
 * $Date: 2015/06/30 $
 *
 * $Revision: #2 $
*************************************************************************/
#ifndef _DRV_PREDOWN_H_
#define _DRV_PREDOWN_H_
#include "general.h"
#include "video_def.h"
#include "vdp_if.h"
#include "vdo_rm.h"

//Wukong can fix this issue by set mib register 
//MIB_FULL_DATA_RATE = 0 : 324M
// MAIN_HCEN_ACT_AT_SYNC = 1 do not down H blank
// MAIN_VCEN_ACT_AT_SYNC = 0 down v blank

typedef struct
{
    UINT8 bPDSModeChanged;
    VRM_INFO_T pdsIn;
    VRM_INFO_T pdsOut;
    UINT8  fgPredsFirEn;
    UINT8  u1PredsFirDlySel;
    UINT8  u1PredsFirInputDlySel;
    
    UINT32 u4PdsFirHDSFactorIntg;
    UINT32 u4PdsFirHDSFactorFrac;
    UINT32 u4PdsFirHDeltaPhaseIntg;
    UINT32 u4PdsFirHDeltaPhaseFrac;
    UINT8  u4PdsFirHDeltaPhaseSign;
    UINT8  fgPDSInterlace;
    UINT32 u4ForcedHPDS;
    UINT32 u4ForcedVPDS;
    UINT32 u4HPDSFactor;
    UINT32 u4VPDSFactor;
    UINT32 u4VPDSPhase;
    UINT32 u4VPDSPhaseBottom;
    UINT32 u4VPDSPhaseBottomEn;
    UINT32 u4MddiFifoMin;                   //Pscan line buffer or fifo minimum limit (Query from Pscan)
    UINT32 u4MddiFifoMax;                   //Pscan line buffer or fifo maximum limit (Query from Pscan)    
    UINT32 u4InputWidth;			        //input width(pixel based)
    UINT32 u4InputHeight;                   //input height(pixel based)
    UINT32 u4OutputWidth;                   //output Width(pixel based)
    UINT32 u4OutputHeight;	                //output Height(pixel based)    
    UINT32 u43DMode;                        //3D mode
    UINT8 u1PredownBlank;
#if defined(CC_MT5861)
	UINT8  fg10bitBypass;
#endif
}PREDOWN_INFO_T;


#define PDS_WRITE_FLD(reg,value,fld) vIO32WriteFldAlign(reg, value, fld)
#define PDS_READ_FLD(reg,fld) IO32ReadFldAlign(reg,fld)
#define getPDSInfo(bPath) (&_pdsInfo[bPath==SV_VP_TNR?SV_VP_PIP+1:bPath])

EXTERN PREDOWN_INFO_T _pdsInfo[VDP_MAX_NS + 1];

void vPDSSwInit(UINT8 bPath);
void vPDSHwInit(UINT8 bPath);
void vPDSImportEn(UINT8 bPath, UINT8 bOnOff);
void vPDSImportTrigger(UINT8 bPath);
UINT32 u4PDSUpdatePDSWidth(UINT8 bPath);
UINT32 u4PDSUpdatePDSHeight(UINT8 bPath);

#if 0
void vPDSUpdateHPDSInfo(UINT8 bPath);
void vPDSUpdateVPDSInfo(UINT8 bPath);
#endif

UINT32 u4PDSGetHPDSFactor(UINT8 bPath);
UINT32 u4PDSGetVPDSFactor(UINT8 bPath);
void vPDSSetHPDSFactor(UINT8 bPath, UINT32 factor);
void vPDSSetVPDSFactor(UINT8 bPath, UINT32 factor);
//void vPDSUpdateVInitPhaseReg(UINT8 bPath, UINT8 bIsFSInterlace , UINT8 bIsLeftEye , UINT8 bIsBottomField);
void vPDSUpdateMddiFifo(UINT8 bPath);
void _vPDSUpdateDispPrm(UINT8 bPath);
void vPDSLoop(UINT8 bPath);
void vPDSSetModeChanged(UINT8 bPath);

void vPDSSetHPSFactorReg(UINT32 u4VdpId, UINT32 u4Factor);
void vPDSSetVPSFactorReg(UINT32 u4VdpId, UINT32 u4Factor);
UINT32 u4PDSGetHPSFactorReg(UINT8 bPath);
UINT32 u4PDSGetVPSFactorReg(UINT8 bPath);
void vPDSSetInputResolutionReg(UINT32 u4VdpId, UINT32 u4InW, UINT32 u4InH);
void vPDSSetOutputResolutionReg(UINT32 u4VdpId, UINT32 u4InW, UINT32 u4InH);
void vPDSSetVCenActAtSync(UINT8 bPath, UINT8 value);

UINT32 u4PDSGetHActive(UINT8 bPath, UINT8 bInOut);
UINT32 u4PDSGetHTotal(UINT8 bPath, UINT8 bInOut);
UINT32 u4PDSGetVActive(UINT8 bPath, UINT8 bInOut);
UINT32 u4PDSGetVTotal(UINT8 bPath, UINT8 bInOut);

void vPds4k1k(UINT8);
BOOL bDrvPDSIsSetResDone(UINT8 u1VdpId, SET_RES_STATUS_TYPE_E eStatusType);
void vDrvPDSClrSetRes(UINT8 u1VdpId, SET_RES_STATUS_TYPE_E eStatusType);
void vDrvPDSInOutStatusDump(UINT8 bPath);

#if defined(CC_MT5861)
void vDrvPDSPIPByPass10Bit(UINT8 bOnOff);
void _vPDSHybridModeBypass(UINT8 bPath);
#endif

#endif
