/*----------------------------------------------------------------------------*
 * No Warranty                                                                *
 * Except as may be otherwise agreed to in writing, no warranties of any      *
 * kind, whether express or implied, are given by MTK with respect to any MTK *
 * Deliverables or any use thereof, and MTK Deliverables are provided on an   *
 * "AS IS" basis.  MTK hereby expressly disclaims all such warranties,        *
 * including any implied warranties of merchantability, non-infringement and  *
 * fitness for a particular purpose and any warranties arising out of course  *
 * of performance, course of dealing or usage of trade.  Parties further      *
 * acknowledge that Company may, either presently and/or in the future,       *
 * instruct MTK to assist it in the development and the implementation, in    *
 * accordance with Company's designs, of certain softwares relating to        *
 * Company's product(s) (the "Services").  Except as may be otherwise agreed  *
 * to in writing, no warranties of any kind, whether express or implied, are  *
 * given by MTK with respect to the Services provided, and the Services are   *
 * provided on an "AS IS" basis.  Company further acknowledges that the       *
 * Services may contain errors, that testing is important and Company is      *
 * solely responsible for fully testing the Services and/or derivatives       *
 * thereof before they are used, sublicensed or distributed.  Should there be *
 * any third party action brought against MTK, arising out of or relating to  *
 * the Services, Company agree to fully indemnify and hold MTK harmless.      *
 * If the parties mutually agree to enter into or continue a business         *
 * relationship or other arrangement, the terms and conditions set forth      *
 * hereunder shall remain effective and, unless explicitly stated otherwise,  *
 * shall prevail in the event of a conflict in the terms in any agreements    *
 * entered into between the parties.                                          *
 *---------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
 * Copyright (c) 2005, MediaTek Inc.
 * All rights reserved.
 *
 * Unauthorized use, practice, perform, copy, distribution, reproduction,
 * or disclosure of this information in whole or in part is prohibited.
 *---------------------------------------------------------------------------
 *
 * $Author: dtvbm11 $
 * $Date: 2015/07/28 $
 * $RCSfile: imgrz_if.h,v $
 * $Revision: #1 $
 *
 *---------------------------------------------------------------------------*/

/** @file imgrz_if.h
 *  image resizer driver main interfaces
 *
 */

#ifndef IMGRZ_IF_H
#define IMGRZ_IF_H


//---------------------------------------------------------------------------
// Include files
//---------------------------------------------------------------------------


/*lint -save -e961 */
#include "x_common.h"
#include "x_typedef.h"
#include "x_timer.h"
#include "x_assert.h"
#include "x_os.h"
//#include "x_bim.h"
#include "x_clksrc.h"
#include "x_hal_5381.h"
#include "x_hal_926.h"
/*lint -restore */


//---------------------------------------------------------------------------
// Configurations
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
// Constant definitions
//---------------------------------------------------------------------------

/// String size
#define D_RZ_STR_SIZE           50

/// Software mode
#define D_RZ_HAVE_SW_MOD        (1 << (INT32)E_RZ_SW_MOD)

/// Hardware mode
#define D_RZ_HAVE_HW_MOD        (1 << (INT32)E_RZ_HW_MOD)

/// Align 16 bytes
#define D_RZ_ALIGN16(X) (((X) + 0xF) & (~0xF))	///< for scaler pitch alignment
#define D_RZ_ALIGN32(X) (((X) + 0x1F) & (~0x1F))
//---------------------------------------------------------------------------
// Type definitions
//---------------------------------------------------------------------------

//#define REMAP_HWRZID        ((u4Which >= IMGRZ_NUM) ? 0 : _rIdx2ImgrzHwIdTbl[u4Which])

#define REMAP_HWRZID   imgrz_map_hwid(u4Which)
#define E_FIRST_RESIZER     0
#if defined(CC_MT5890)
    #define IMGRZ_NUM   3
	#define IMGRZ4VDO_NUM	(IMGRZ_NUM - 1)
    #define E_SECND_RESIZER     1
    #define E_THIRD_RESIZER     2
    #define E_RZ_DEFAULT_ID 	E_SECND_RESIZER
#elif defined(CC_MT5891)
	#define IMGRZ_NUM	4	
	#define IMGRZ4VDO_NUM	(IMGRZ_NUM - 1)
    #define E_SECND_RESIZER     1
    #define E_THIRD_RESIZER     2
	#define E_FORTH_RESIZER		3
    #define E_RZ_DEFAULT_ID 	E_SECND_RESIZER	
#elif (defined(CC_MT5396) || defined(CC_MT5398)|| defined(CC_MT5399) || defined(CC_MT5882))
    #define IMGRZ_NUM   2
    #define IMGRZ4VDO_NUM	IMGRZ_NUM
    #define E_SECND_RESIZER     1
    #define E_RZ_DEFAULT_ID 	E_FIRST_RESIZER
#else
    #define E_SECND_RESIZER     0
    #define IMGRZ_NUM   1
    #define IMGRZ4VDO_NUM	IMGRZ_NUM
    #define E_RZ_DEFAULT_ID 	E_FIRST_RESIZER
#endif

/// Error types
typedef enum
{
    E_RZ_OK = 0,
    E_RZ_INV_ARG,
    E_RZ_OUT_OF_MEM,
    E_RZ_UNINIT,
    E_RZ_UNDEF_ERR
} E_RZ_ERR_CODE_T;

/// OSD input color mode (direct/index)
typedef enum
{
    E_RZ_OSD_IN_CM_INDEX  = 0,
    E_RZ_OSD_IN_CM_DIRECT = 1
} E_RZ_OSD_IN_CM_T;

/// OSD color mode (index)
typedef enum
{
    E_RZ_OSD_IDX_CM_2BPP   = 1,
    E_RZ_OSD_IDX_CM_4BPP   = 2,
    E_RZ_OSD_IDX_CM_8BPP   = 3
} E_RZ_OSD_IDX_CM_T;

/// OSD color mode (direct)
typedef enum
{
    E_RZ_OSD_DIR_CM_RGB565      = 0,
    E_RZ_OSD_DIR_CM_ARGB1555    = 1,
    E_RZ_OSD_DIR_CM_ARGB4444    = 2,
    E_RZ_OSD_DIR_CM_ARGB8888    = 3,
    E_RZ_OSD_DIR_CM_AYCbCr8888  = 3,
    E_RZ_OSD_DIR_CM_YCbYCr      = 4,
    E_RZ_OSD_DIR_CM_CbYCrY      = 5,
    E_RZ_OSD_DIR_CM_RGBA8888  = 6
} E_RZ_OSD_DIR_CM_T;

/// Scaling type for dealing with alpha change
typedef enum
{
    E_RZ_A_SCL_TYPE_GENERAL          = 0,
    E_RZ_A_SCL_TYPE_REFER_TO_LEFT    = 1,
    E_RZ_A_SCL_TYPE_REFER_TO_NEAREST = 2
} E_RZ_A_SCL_TYPE_T;

/// VDO output mode
typedef enum
{
    E_RZ_VDO_OUTMD_420 = 0,
    E_RZ_VDO_OUTMD_422 = 1,
    E_RZ_VDO_OUTMD_444 = 2
} E_RZ_VDO_OUTMD_T;

/// Inout type (video/jpeg/osd)
typedef enum
{
    E_RZ_INOUT_TYPE_VDOMD  = 0,
    E_RZ_INOUT_TYPE_JPGMD  = 1,
    E_RZ_INOUT_TYPE_OSDMD  = 2,
    E_RZ_INOUT_TYPE_OSDUI  = 3,
    E_RZ_INOUT_TYPE_VDOENCODE=4,
    E_RZ_INOUT_TYPE_VDORMRPR=5,
    E_RZ_INOUT_TYPE_VDOENCODE_V2=6,
    E_RZ_INOUT_TYPE_OSD_CSC =7,
} E_RZ_INOUT_TYPE_T;

/// Modules
typedef enum
{
    E_RZ_SW_MOD = 0,
    E_RZ_HW_MOD,
    E_RZ_MODULE_LAST
} E_RZ_MODULE_T;

typedef enum
{
	E_RZ_OSD_CSC_FORMAT_ARGB8888=0,
	E_RZ_OSD_CSC_FORMAT_AYUV8888=1
} E_RZ_CSC_FORMAT_T;

typedef enum
{
	E_RZ_VDO_BOTTOM_FILED=0,
	E_RZ_VDO_TOP_FILED=1
} E_RZ_VDO_FIELD_TYPE_T;

typedef enum
{
    E_RZ_OSD_ALCOM_MODE_CLEAR         = 0x0,
    E_RZ_OSD_ALCOM_MODE_DST_IN        = 0x1,
    E_RZ_OSD_ALCOM_MODE_DST_OUT       = 0x2,
    E_RZ_OSD_ALCOM_MODE_DST_OVER      = 0x3,
    E_RZ_OSD_ALCOM_MODE_SRC           = 0x4,
    E_RZ_OSD_ALCOM_MODE_SRC_IN        = 0x5,
    E_RZ_OSD_ALCOM_MODE_SRC_OUT       = 0x6,
    E_RZ_OSD_ALCOM_MODE_SRC_OVER      = 0x7,
    E_RZ_OSD_ALCOM_MODE_DST           = 0x8,
    E_RZ_OSD_ALCOM_MODE_SRC_ATOP      = 0x9,
    E_RZ_OSD_ALCOM_MODE_DST_ATOP      = 0xA,
    E_RZ_OSD_ALCOM_MODE_XOR           = 0xB,
    E_RZ_OSD_ALCOM_MODE_NONE          = 0xC,
    E_RZ_OSD_ALCOM_MODE_ADD           = 0xD
} E_RZ_OSD_ALCOM_MODE;

typedef enum {
	IMGRZ_DONE_OK=100,
	IMGRZ_DONE_TIMEOUT,
	IMGRZ_DONE_FAULT
}IMGRZ_DONE_TYPE;

/*cb run in irq context, pls return quickly*/
typedef int (*imgrz_done_cb) (unsigned int u4Which,
				IMGRZ_DONE_TYPE u4Type, void *data);
//---------------------------------------------------------------------------
// Macro definitions
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
// Inter-file functions
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
// Public functions
//---------------------------------------------------------------------------
extern UINT32 imgrz_map_hwid(UINT32 u4Which);
//---------------------------------------------------------------------------
//  IMGRZ_Init
//
/** Initialize gfx driver.
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_Init(void);
extern void IMGRZ_Init_Ex(UINT32 u4Which);


//---------------------------------------------------------------------------
//  IMGRZ_Reset
//
/** Reset engine.
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_Reset(void);
extern void IMGRZ_Reset_Ex(UINT32 u4Which);

//---------------------------------------------------------------------------
//  IMGRZ_Wait
//
/** Wait for flushing engine completely.
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_Wait(void);
extern void IMGRZ_Wait_Ex(UINT32 u4Which);


#if !defined(IMGRZ_RISC_MODE)
//---------------------------------------------------------------------------
//  IMGRZ_MwFlush
//
/** Flush cmdque and force engine to do operations (for MW use).
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_MwFlush_Ex(UINT32 u4Which);
#endif

//---------------------------------------------------------------------------
//  IMGRZ_Flush
//
/** Flush cmdque and force engine to do operations (for Drv use).
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_Flush(void);
extern void IMGRZ_Flush_Ex(UINT32 u4Which);


//---------------------------------------------------------------------------
//  IMGRZ_Lock
//
/** Take the imgrz resource.
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_Lock(void);
extern void IMGRZ_Lock_Ex(UINT32 u4Which);


//---------------------------------------------------------------------------
//  IMGRZ_TryLock
//
/** Try to take the imgrz resource.
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
//extern void IMGRZ_TryLock(UINT32 u4Which);


//---------------------------------------------------------------------------
//  IMGRZ_Unlock
//
/** Release the imgrz resource.
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_Unlock(void);
extern void IMGRZ_Unlock_Ex(UINT32 u4Which);


//---------------------------------------------------------------------------
//  IMGRZ_LockCmdque
//
/** Take the imgrz-cmdq resource.
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
//extern void IMGRZ_LockCmdque(UINT32 u4Which);


//---------------------------------------------------------------------------
//  IMGRZ_UnlockCmdque
//
/** Release the imgrz-cmdq resource.
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_UnlockCmdque(void);
//extern void IMGRZ_UnlockCmdque_Ex(UINT32 u4Which);


//---------------------------------------------------------------------------
//  IMGRZ_LockWaitIsr
//
/** Take the imgrz- waitIsr cmd resource.
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
//extern void IMGRZ_LockWaitIsr(UINT32 u4Which);

//---------------------------------------------------------------------------
//  IMGRZ_UnlockWaitIsr
//
/** Release the imgrz-waitIsr cmd resource.
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_UnlockWaitIsr(void);
//extern void IMGRZ_UnlockWaitIsr_Ex(UINT32 u4Which);

//---------------------------------------------------------------------------
//  IMGRZ_QueryHwIdle
//
/** Query engine status.
 *
 *  @retval 1   Idle
 *  @retval 0   Busy
 */
//---------------------------------------------------------------------------
//extern INT32 IMGRZ_QueryHwIdle(UINT32 u4Which);


//---------------------------------------------------------------------------
//  IMGRZ_SetNotify
//
/** Set notify function (for MW use).
 *
 *  @param  pfnNotifyFunc   The callback function pointer
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
//extern void IMGRZ_SetNotify(UINT32 u4Which, void (*pfnNotifyFunc)(UINT32));


//---------------------------------------------------------------------------
//  IMGRZ_ReInit
//
/** Re initial imgrz.
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_ReInit(void);
extern void IMGRZ_ReInit_Ex(UINT32 u4Which);


//---------------------------------------------------------------------------
//  IMGRZ_SetScaleOpt
//
/** Set scale option.
 *
 *  @param  eInOutType   Scale option
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_SetScaleOpt(E_RZ_INOUT_TYPE_T eInOutType);
extern void IMGRZ_SetScaleOpt_Ex(UINT32 u4Which, E_RZ_INOUT_TYPE_T eInOutType);


//---------------------------------------------------------------------------
//  IMGRZ_Scale
//
/** Execute scale operation.
 *
 *  @param  pvSclParam  scale parameters
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_Scale(void *pvSclParam);
extern void IMGRZ_Scale_Ex(UINT32 u4Which, void *pvSclParam);
extern void IMGRZ_Async_Ex(UINT32 u4Which, imgrz_done_cb fDoneCb, void *pvData);


//---------------------------------------------------------------------------
//  IMGRZ_GetScaleOpt
//
/** get scale option.
 *  @retval void
 */
//---------------------------------------------------------------------------
extern E_RZ_INOUT_TYPE_T IMGRZ_GetScaleOpt(void);
extern E_RZ_INOUT_TYPE_T IMGRZ_GetScaleOpt_Ex(UINT32 u4Which);


//---------------------------------------------------------------------------
//  IMGRZ_SetDigest
//
/** Set a video output frame to a thumbnail result
 *
 *  @param  pvSrc  source parameters
 *  @param  pvDst  distination parameters
 *  @param  fgOnePass FALSE: 2pass (only video scaling), TRUE: 1 pass (scaling and color conv)
 *  @param  u4WorkingBuf  working buffer address for 2 pass
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_SetDigest(void *pvSrc, void *pvDst, BOOL fgOnePass, UINT32 u4WorkingBuf, UINT32 u4Which);


//---------------------------------------------------------------------------
//  IMGRZ_Break
//
/** Save imgrz parameters for breaking
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_Break(void);
extern void IMGRZ_Break_Ex(UINT32 u4Which);

//---------------------------------------------------------------------------
//  IMGRZ_Resume
//
/** Resume the process of imgrz of jpg mcu row mode
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_Resume(void);
extern void IMGRZ_Resume_Ex(UINT32 u4Which);

//---------------------------------------------------------------------------
//  IMGRZ_OFF
//
/** disable clock of imgrz
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_OFF(void);
extern void IMGRZ_OFF_Ex(UINT32 u4Which);

//---------------------------------------------------------------------------
//  IMGRZ_OFF
//
/** disable clock of imgrz
 *
 *  @retval void
 */
//---------------------------------------------------------------------------
extern UINT32 IMGRZ_GetScaleLine(void);
extern UINT32 IMGRZ_GetScaleLine_Ex(UINT32 u4Which);


//---------------------------------------------------------------------------
//  IMGRZ_RegInfo
//
/** get imgrz register address and size for
 *  register dump
 *  @retval void
 */
//---------------------------------------------------------------------------
extern void IMGRZ_RegInfo(UINT32 u4Which, UINT32 *pu4Addr,UINT32 *pu4Size);

extern BOOL IMGRZ_CkgenOnOff(UINT32 u4Id, BOOL fgEnable);

extern void IMGRZ_AYUV_ARGB_Conv(UINT32  u4TgBase,UINT32 u4BufLen,UINT32 u4Width, UINT32 u4Height,
    UINT32 u4OffsetX,  UINT32 u4OffsetY, UINT32 u4MMUTableAddr, BOOL fgAYUV2ARGB);
extern void IMGRZ_AYUV_ARGB_Conv_Ex(UINT32 u4Which, UINT32  u4TgBase,UINT32 u4BufLen,UINT32 u4Width, UINT32 u4Height,
    UINT32 u4OffsetX,  UINT32 u4OffsetY, UINT32 u4MMUTableAddr, BOOL fgAYUV2ARGB);

extern void IMGRZ_DMA(UINT32 u4SrcAddr,UINT32 u4DstAddr, UINT32 u4Pitch,UINT32 u4Height, UINT32 u4MMUTableAddr);
extern void IMGRZ_DMA_Ex(UINT32 u4Which, UINT32 u4SrcAddr,UINT32 u4DstAddr, UINT32 u4Pitch,UINT32 u4Height, UINT32 u4MMUTableAddr);

#define OSD_CLR_MODE_CONV_OSD_4444    4
#define OSD_CLR_MODE_CONV_OSD_8888    3
#define OSD_CLR_MODE_CONV_OSD_565     0
//extern void IMGRZ_OSD_CLR_MODE_CONV(UINT32 u4Which, UINT32 u4SrcAddr,UINT32 u4DstAddr, UINT32 u4Pitch, UINT32 u4Height, UINT32 fromClrMode, UINT32 toClrMode,BOOL fgDoDither);

extern void IMGRZ_Cfg_MMU_IO(BOOL MMU_Read, BOOL MMU_Write);
extern void IMGRZ_Cfg_MMU_IO_Ex(UINT32 u4Which, BOOL MMU_Read, BOOL MMU_Write);
#if defined(CC_MT5890)
extern void IMGRZ_ReadSpecReg_Ex(UINT32 u4Which);
#endif
#if defined(CC_MT5890)|| defined(CC_MT5891) || defined(CC_MT5882)
extern void IMGRZ_DecompressUFO(void *pvSrc, UINT32 u4Which);
#endif

#endif // IMGRZ_IF_H



