/* 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$
 * $Date$
 * $RCSfile: osd_drvif.h,v $
 * $Revision$
 *
 *---------------------------------------------------------------------------*/

/** @file osd_drvif.h
 *  This header file declares public function prototypes of OSD.
 */

#ifndef OSD_DRVIF_H
#define OSD_DRVIF_H

/*lint -e717 -e572*/

/*
 e717 : do ... while(0)
 e572 : Excessive shift value (precision Integer shifted right by Integer)
 */

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

#include "x_lint.h"
LINT_EXT_HEADER_BEGIN
#include "x_typedef.h"
#include "x_assert.h"
#include "x_common.h"
#include "x_os.h"
#ifdef DRV_SUPPORT_EXTMJC
#include "extmjc_if.h"
#endif
LINT_EXT_HEADER_END

#define OSD_SUPPORT_DOUBLE_CHANNEL      (IS_IC_5893() || IS_IC_5895())


#define OSD_BASE_SCRN_VSTART_TOP    (0x2)
#define OSD_BASE_HSART_ADJ          (0xb)
#define OSD_BASE_HSART_ADJ_CSR      (0x90)
#define OSD_BASE_HS_EDGE            (0)
#define OSD_BASE_VS_EDGE            (1)
#define OSD_BASE_SYNC_SRC_SEL       (0)

#define OSD_MAX_WIDTH          (8192)
#define OSD_MAX_HEIGHT         (4096)

#define CURSOR_SUPPORT
#define OSD_BASE_INIT_FRC_HEADER
#define OSD_PLA5_SUPPORT

#define OSD_RESET_BASE_ZERO
#define OSD_CSR_H_ACTIVE_SUPPORT

#if defined(CC_MT5893) || defined(CC_MT5895)
#define OSD_CHECK_LEFT_PLANE(plane)     ((plane) <= OSD_PLANE_5 && (plane) != OSD_PLANE_4)
#define OSD_GET_RIGHT_PLANE(plane)      ((plane == OSD_PLANE_5) ? OSD_RT_PLANE_5 : (plane + 5))
#endif

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

#ifndef LG_OSD_PATH_TEST
#define  LG_OSD_PATH_TEST 0
#define  OSD_TRANS_CTRL 0
#endif

#define OSD_DMA_ALIGN_SIZE             63  // 64 byte alignment
#define OSD_INVALID_VALUE_U32          (0xFFFFFFFF)

#define OSD_BASE_REG                   OSD_BASE
#if defined(CC_MT5893)
#define OSD_RT_BASE                    (OSD_BASE + 0x20000)
#define OSD_RT_BASE_REG                OSD_RT_BASE
#endif
#if defined(CC_MT5895)
#define OSD_RT_BASE                    (OSD_BASE - 0x3000)
#define OSD_RT_BASE_REG                OSD_RT_BASE
#endif

#define OSD_CLOCK_BASE                 IO_ADDR(0xd000)
#define FSC_OSD_VSYNC_SEL              IO_ADDR(0x25350)
#define FSC_OSD_POST_SCALER_SET        IO_ADDR(0x5e350)
#define OSD_POST_SCALER_SET_H_REVERSE  IO_ADDR(0x5e344)

#if defined(CC_MT5886) || defined(CC_MT5863) || defined(CC_MT5893) || defined(CC_MT5895)
#define OSD_PIXEL_CONFIG_REG_OFFSET    0xf20
#define OSD_PIXEL_DATA_REG_OFFSET      0xf24
#endif

// skip update and reset register
#define OSD_BASE_SKIP                  2
#define OSD_BASE_REG_NUM               18
#define OSD_BASE_SKIP_START            11
#define OSD_BASE_SKIP_END              13

#define OSD_PLA1_REG                   (OSD_BASE_REG + 0x100)
#define OSD_PLA1_RGN_REG               (OSD_PLA1_REG + 0x40)
#define OSD_PLA2_REG                   (OSD_BASE_REG + 0x200)
#define OSD_PLA3_REG                   (OSD_BASE_REG + 0x300)
#define OSD_PLA1_REG_OFF               (0x100)
#define OSD_PLA2_REG_OFF               (0x200)
#define OSD_PLA3_REG_OFF               (0x300)
#define OSD_SC2_REG_OFF                (0x500)
#define OSD_SC3_REG_OFF                (0x600)
#define OSD_DEC_DELAY_MAX              (0x20)
#define OSD_PLA4_REG                   (OSD_BASE_REG + 0x900)
#define OSD_PLA5_REG                   (OSD_BASE_REG + 0x700)  //for cursor

#define OSD_3D_REG                     (OSD_BASE_REG + 0x80)
#define OSD_SC1_REG                    (OSD_BASE_REG + 0x400)
#define OSD_SC2_REG                    (OSD_BASE_REG + 0x500)
#define OSD_SC3_REG                    (OSD_BASE_REG + 0x600)
#define OSD_FIFO_MONITOR_REG           (OSD_BASE_REG + 0xFC)

#if defined(CC_MT5893) || defined(CC_MT5895)
#define OSD_RT_PLA1_REG                (OSD_RT_BASE_REG + 0x100)
#define OSD_RT_PLA2_REG                (OSD_RT_BASE_REG + 0x200)
#define OSD_RT_PLA3_REG                (OSD_RT_BASE_REG + 0x300)
#define OSD_RT_PLA5_REG                (OSD_RT_BASE_REG + 0x700)  //for cursor
#define OSD_RT_3D_REG                  (OSD_RT_BASE_REG + 0x80)
#define OSD_RT_SC1_REG                 (OSD_RT_BASE_REG + 0x400)
#define OSD_RT_SC2_REG                 (OSD_RT_BASE_REG + 0x500)
#define OSD_RT_SC3_REG                 (OSD_RT_BASE_REG + 0x600)
#endif

#if defined(CC_MT5886)
#define OSD_MMU_REG                    IO_ADDR(0x68300)
#elif defined(CC_MT5863)
#define OSD1_MMU_REG                    IO_ADDR(0x68600)
#define OSD2_MMU_REG                    IO_ADDR(0x68680)
#define OSD3_MMU_REG                    IO_ADDR(0x68700)
#endif

#define OSD_SC_REG_NUM                 9
#define OSD_SC_STEP_BIT                14
#define OSD_SC_STEP_BASE               0x4000

#define OSD_LPF_PARAM_NUM              3
#define OSD_DEFAULT_LPF_C1             -7
#define OSD_DEFAULT_LPF_C2             28
#define OSD_DEFAULT_LPF_C3             88
#define OSD_DEFAULT_LPF_C4             0
#define OSD_DEFAULT_LPF_C5             0

#define OSD_CSR_REG                    (OSD_BASE_REG + 0x700)

#define OSD_CSR_DATA_REG               (OSD_BASE_REG + 0x800)
#define OSD_CSR_DATA_SIZE              0x100
#define OSD_CSR_COLOR_REG              (OSD_CSR_REG + 0x4)
#ifdef OSD_CSR_H_ACTIVE_SUPPORT
#define OSD_CSR_HACTIVE_REG              (OSD_CSR_REG + 0x40)
#define OSD_CSR_POSITION                 (OSD_CSR_REG + 0x44)
#endif

#define OSD_READ32(offset)                  IO_READ32(OSD_BASE_REG,(offset))
#define OSD_WRITE32(offset, value)          IO_WRITE32(OSD_BASE_REG,(offset),(value))
#define OSD_READ32MSK(offset,mask)          IO_READ32MSK(OSD_BASE_REG,(offset),(mask))
#define OSD_WRITE32MSK(offset,value,mask)   IO_WRITE32MSK(OSD_BASE_REG,(offset),(value),(mask))
#if defined(CC_MT5893) || defined(CC_MT5895)
#define OSD_R_READ32(offset)                IO_READ32(OSD_RT_BASE_REG,(offset))
#define OSD_R_WRITE32(offset, value)        IO_WRITE32(OSD_RT_BASE_REG,(offset),(value))
#define OSD_R_READ32MSK(offset,mask)        IO_READ32MSK(OSD_RT_BASE_REG,(offset),(mask))
#define OSD_R_WRITE32MSK(offset,value,mask) IO_WRITE32MSK(OSD_RT_BASE_REG,(offset),(value),(mask))
#endif
#define OSD_CSR_REG_NUM                1

#define OSD_RGN_REG_NUM                8
#define OSD_PLA_REG_NUM                7
#define OSD_MMU_REG_NUM                14

#ifdef CC_MINI_DRIVER
#define OSD_MAX_NUM_RGN            20
#define OSD_MAX_NUM_RGN_LIST       10
#else
#define OSD_MAX_NUM_RGN            120
#define OSD_MAX_NUM_RGN_LIST       90
#endif
#define OSD_CK_REG                     IO_ADDR(0xd40c)
#define OSD_POCLK_REG                  IO_ADDR(0xd368)

#define OSD_DE_S_REG                   IO_ADDR(0x8094)
#define OSD_DE_S_OSD2_VAL               (0x91)
#define OSD_DE_S_OSD3_VAL               (0xd1)
#define OSD_FIFO_MONITOR_OFFSET         (0xFC)

#if defined(CC_MT5893) || defined(CC_MT5895)
#define SMI_CK_REG                      IO_ADDR(0xd250)
#define OVL_CK_SRC                      IO_ADDR(0xd4d0)
#define OSD_PLA_BURST8_OFFSET         (0x98)
#define OSD_PLA_BURST8_BIT            (12)
#define OSD_PLA_BURST8_FIFO_OFFSET    (0x98)
#define OSD_PLA_BURST8_FIFO_BIT       (13)
#if defined(CC_MT5895)
#define OSD_MIXER_OSTG1                 IO_ADDR(0x2006a30)
#define OSD_MIXER_OSTG2                 IO_ADDR(0x200aa30)
#else
#define OSD_MIXER_OSTG1                 IO_ADDR(0x27a30)
#define OSD_MIXER_OSTG2                 IO_ADDR(0x36a30)
#endif
#define OSD_MIXER_INDEX_ENABLE_MASK     (1<<8)
#define OSD_MIXER_INDEX_COUNTER_MASK    (0xFFFFFE00)
#define OSD_MIXER_INDEX_THD_MASK        (0xFF)
#define GFX_MIXER_OSTG1                 IO_ADDR(0x27a50)
#define GFX_MIXER_OSTG2                 IO_ADDR(0x36a50)
#endif

#define OSD_CK_XTAL                    0
#define OSD_CK_SYS                     0xf //648Mhz
#define OSD_CK_SYS_DIV2                6 //324Mhz
#define OSD_FMT_08                     (OSD_BASE_REG + 0x8)
#define YUV_OUTPUT                     (1 << 9)

#define OSD_FIELD_TOP                  1
#define OSD_FIELD_BOT                  0
#define OSD_FRAME_MODE                 2

#define OSD_INT_ENABLE_REG         (OSD_BASE_REG + 0x30)
#define OSD1_CFUD_IEN              (1 << 8)
#define OSD2_CFUD_IEN              (1 << 7)
#define OSD2_PFUD_IEN              (1 << 6)
#define OSD2_VUTO_IEN              (1 << 5)
#define OSD2_VDTO_IEN              (1 << 4)
#define OSD3_CFUD_IEN              (1 << 3)
#define OSD3_PFUD_IEN              (1 << 2)
#define OSD3_VUTO_IEN              (1 << 1)
#define OSD3_VDTO_IEN              (1 << 0)
#define OSD_INT_STATUS_REG         (OSD_BASE_REG + 0x34)
#define OSD_INT                    (1 << 16)
#define OSD1_CFUD_IID              (1 << 8)
#define OSD2_CFUD_IID              (1 << 7)
#define OSD2_PFUD_IID              (1 << 6)
#define OSD2_VUTO_IID              (1 << 5)
#define OSD2_VDTO_IID              (1 << 4)
#define OSD3_CFUD_IID              (1 << 3)
#define OSD3_PFUD_IID              (1 << 2)
#define OSD3_VUTO_IID              (1 << 1)
#define OSD3_VDTO_IID              (1 << 0)

#define OSD_CHECKSUM               (OSD_BASE_REG + 0x50)

#define OSD_SC_MAX_SRCWIDTH         4096
#if defined(CC_MT5893) || defined(CC_MT5895)
#define OSD_SC_MAX_SRCHEIGHT        2160
#else
#define OSD_SC_MAX_SRCHEIGHT        4320
#endif

#define OSD_INVALID_VALUE_U32       (0xFFFFFFFF)

#define OSD_DE_S_OSD2_VAL           (0x91)
#define OSD_DE_S_OSD3_VAL           (0xd1)
#define OSD_DE_ADJ_VAL              (0xc)

#define OSD_BASE_MONITOR            (0xfc)
#define UPDATE_TIMING_BIT           (1 << 23)
#define DISABLE_SW_UPDATE           (1<<5)

#ifdef CC_MT5863
#ifdef CONFIG_ARM64_64K_PAGES
#define VIRTUAL_ADDRESS_BASE 0xfffffc0000000000
#else
#define VIRTUAL_ADDRESS_BASE 0xffffff8000000000
#endif
#endif

#define OSD_TIMING_SRC_FSC          (0)
#define OSD_TIMING_SRC_PSC          (1)

#define OSD_EXTERNAL_MAX_PLANE      5

#define OSD_BASE_SYNC_EDGE_RISING             (0)
#define OSD_BASE_SYNC_EDGE_FALLING            (1)

//#define CC_CONFIG_OSD_SBS_PLANE1
//#define CC_CONFIG_OSD_SBS_PLANE2
//#define CC_CONFIG_OSD_SBS_PLANE3

//#define CC_CONFIG_OSD_TB_PLANE1
//#define CC_CONFIG_OSD_TB_PLANE2
//#define CC_CONFIG_OSD_TB_PLANE3

#define OSD_INTERNAL_MAX_PLANE      (OSD_SUPPORT_DOUBLE_CHANNEL ? (OSD_RT_PLANE_5 + 1) : (OSD_PLANE_5 + 1))

//-----------------------------------------------------------------------------
// Type definitions
//-----------------------------------------------------------------------------


/** OSD plane enum.
 */
typedef enum
{
    OSD_PLANE_1,
    OSD_PLANE_2,
    OSD_PLANE_3,
    OSD_PLANE_4,
    OSD_PLANE_5,
#if defined(CC_MT5893) || defined(CC_MT5895)
    OSD_RT_PLANE_1,
    OSD_RT_PLANE_2,
    OSD_RT_PLANE_3,
    OSD_RT_PLANE_5,
#endif
    OSD_PLANE_MAX_NUM
} OSD_PLANE_T;

typedef enum
{
    OSD_PLANE_RGN_LEFT,
    OSD_PLANE_RGN_RIGHT,
    OSD_PLANE_RGN_MAX
} OSD_PLANE_RGN_NUM;

typedef enum
{
    OSD_PLANE_RGN_STATE_FRONT = 0,
    OSD_PLANE_RGN_STATE_BACK = 1,
    OSD_PLANE_RGN_STATE_MAX
} OSD_PLANE_RGN_STATE;

/** OSD scaler enum.
 */
typedef enum
{
    OSD_SCALER_1,
    OSD_SCALER_2,
    OSD_SCALER_3,
#if defined(CC_MT5893) || defined(CC_MT5895)
    OSD_RT_SCALER_1,
    OSD_RT_SCALER_2,
    OSD_RT_SCALER_3,
#endif
    OSD_SCALER_MAX_NUM
} OSD_SCALER_T;

/** OSD function return code.
 */
typedef enum
{
    OSD_RET_OK,
    OSD_RET_INV_ARG,
    OSD_RET_OUT_OF_MEM,
    OSD_RET_OUT_OF_REGION,
    OSD_RET_OUT_OF_LIST,
    OSD_RET_UNINIT,
    OSD_RET_INV_PLANE,
    OSD_RET_INV_SCALER,
    OSD_RET_INV_REGION,
    OSD_RET_INV_BITMAP,
    OSD_RET_INV_LIST,
    OSD_RET_INV_DISPLAY_MODE,
    OSD_RET_NO_ATTACH_REGION,
    OSD_RET_REGION_COLLISION,
    OSD_RET_ERR_INTERNAL,
    OSD_RET_UNDEF_ERR
} OSD_RET_CODE_T;

typedef enum
{
    OSD_TIMING_POST_SCALER,
    OSD_TIMING_FRONT_SCALER,
    OSD_TIMING_GFX
}OSD_TIMING_SRC_T;

/** OSD color mode.
 */
typedef enum
{
    OSD_CM_YCBCR_CLUT2,
    OSD_CM_YCBCR_CLUT4,
    OSD_CM_YCBCR_CLUT8,
    OSD_CM_RESERVED_0,
    OSD_CM_CBYCRY422_DIRECT16,
    OSD_CM_YCBYCR422_DIRECT16,
    OSD_CM_AYCBCR8888_DIRECT32,
    OSD_CM_RESERVED_1,
    OSD_CM_RGB_CLUT2,
    OSD_CM_RGB_CLUT4,
    OSD_CM_RGB_CLUT8,
    OSD_CM_RGB565_DIRECT16,
    OSD_CM_ARGB1555_DIRECT16,
    OSD_CM_ARGB4444_DIRECT16,
    OSD_CM_ARGB8888_DIRECT32,
    OSD_CM_ALPHA_BIT
} OSD_COLOR_MODE_T;

/** OSD display mode. for FPGA emulation
 */
typedef enum
{
    OSD_DM_480I,
    OSD_DM_576I,
    OSD_DM_480P,
    OSD_DM_576P,
    OSD_DM_720P,
    OSD_DM_768P,
    OSD_DM_1080I,
    OSD_DM_1080P,
    OSD_DM_MAX_NUM
} OSD_DISPLAY_MODE_T;

/** OSD blending mode.
 */
typedef enum
{
    OSD_BM_NONE, OSD_BM_PIXEL, OSD_BM_REGION, OSD_BM_PLANE
} OSD_BLEND_MODE_T;

/** OSD region list cmd.
 */
typedef enum
{
    OSD_RGN_LIST_HEAD, OSD_RGN_LIST_TAIL, OSD_RGN_LIST_COUNT, OSD_LIST_FLAGS
} OSD_RGN_LIST_CMD_T;

/** OSD region cmd.
 */
typedef enum
{
    OSD_RGN_ALLOC,
    OSD_RGN_PREV,
    OSD_RGN_NEXT,
    OSD_RGN_FLAGS,
    OSD_RGN_POS_X,
    OSD_RGN_POS_Y,
    OSD_RGN_BMP_W,
    OSD_RGN_BMP_H,
    OSD_RGN_OUT_X,
    OSD_RGN_OUT_Y,
    OSD_RGN_DISP_W,
    OSD_RGN_DISP_H,
    OSD_RGN_OUT_W,
    OSD_RGN_OUT_H,
    OSD_RGN_COLORMODE,
    OSD_RGN_ALPHA,
    OSD_RGN_BMP_ADDR,
    OSD_RGN_BMP_PITCH,
    OSD_RGN_CLIP_V,
    OSD_RGN_CLIP_H,
    OSD_RGN_V_FLIP,
    OSD_RGN_H_MIRROR,
    OSD_RGN_PAL_LOAD,
    OSD_RGN_PAL_ADDR,
    OSD_RGN_PAL_LEN,
    OSD_RGN_STEP_V,
    OSD_RGN_STEP_H,
    OSD_RGN_COLOR_KEY,
    OSD_RGN_COLOR_KEY_EN,
    OSD_RGN_MIX_SEL,
    OSD_RGN_BIG_ENDIAN,
    OSD_RGN_ALPHA_SEL,
    OSD_RGN_YR_SEL,
    OSD_RGN_UG_SEL,
    OSD_RGN_VB_SEL,
    OSD_RGN_NEXT_EN,
    OSD_RGN_NEXT_HDR_ADDR,
    OSD_RGN_DEC_MODE,
    OSD_RGN_DEC_LINE,
    OSD_RGN_DEC_EN,
    OSD_RGN_10BIT_EN
} OSD_RGN_CMD_T;

typedef enum
{
    OSD_FRCHD_FORMAT,
    OSD_FRCHD_PIXORDER,
    OSD_FRCHD_LRINDEX,
    OSD_FRCHD_BMPINDEX,
    OSD_FRCHD_FRAMENUM,
    OSD_FRCHD_PREFIX,
    OSD_FRCHD_BMPHEIGHT,
    OSD_FRCHD_BMPWIDTH,
    OSD_FRCHD_GLOBALALPHA,
    OSD_FRCHD_PIXELALPHAEN,
    OSD_FRCHD_GLOBALALPHAEN,
    OSD_FRCHD_ODPUPPER,
    OSD_FRCHD_DISPYOFF,
    OSD_FRCHD_DISPXOFF,
    OSD_FRCHD_DISPHEIGHT,
    OSD_FRCHD_DISPWIDTH
} OSD_FRCHEADER_CMD_T;

typedef enum _OSD_CPBLTY_E
{
    E_OSD_CPBLTY_NONE,
    E_OSD_CPBLTY_CMPRSS,
    E_OSD_CPBLTY_CMPRSS_PLANE,
    E_OSD_CPBLTY_SBS_PLANE,
    E_OSD_CPBLTY_3D_STATUS,
    E_OSD_CPBLTY_FLIP,
    E_OSD_CPBLTY_MIRROR,
    E_OSD_CPBLTY_MAX
} OSD_CPBLTY_E;

typedef enum _OSD_RGN_STATE_E
{
    OSD_RGN_STATE_IDLE,
    OSD_RGN_STATE_DISP,
    OSD_RGN_STATE_CMP_DISP,
    OSD_RGN_STATE_CMP,
    OSD_RGN_STATE_UNCMP,
    OSD_RGN_STATE_MAX
} OSD_RGN_STATE_E;


/** OSD base register bit-field type.
 */

typedef struct _OSD_CPBLTY
{
    UINT32 u4_cmprss;
    UINT32 u4_cmprss_plane[OSD_PLANE_MAX_NUM];
    UINT32 u4_sbs_plane[OSD_PLANE_MAX_NUM];
    UINT32 u4_3d_status[OSD_PLANE_MAX_NUM];
    UINT32 u4_flip;
    UINT32 u4_mirror;
} OSD_CPBLTY;

typedef struct _OSD_RGN_CREATE_T
{
    UINT32 *pu4Region;
    UINT32 u4BmpWidth;
    UINT32 u4BmpHeight;
    void *pvBitmap;
    UINT32 eColorMode;
    UINT32 u4BmpPitch;
    UINT32 u4DispX;
    UINT32 u4DispY;
    UINT32 u4DispW;
    UINT32 u4DispH;
    UINT32 u4Flip;
    UINT32 u4Mirror;
    UINT32 u4Dec;
} OSD_RGN_CREATE_T;

typedef struct _OSD_RGN_INFO_T
{
    UPTR   pu4Hdr_addr;
    UPTR   pu4Bmp_addr;
    UINT32 u4Src_x;
    UINT32 u4Src_y;
    UINT32 u4Src_w;
    UINT32 u4Src_h;
    UINT32 u4Dst_x;
    UINT32 u4Dst_y;
    UINT32 u4Dst_w;
    UINT32 u4Dst_h;
    UINT32 u4Disp_w;
    UINT32 u4Disp_h;
    UINT32 u4Clip_h;
    UINT32 u4Clip_v;
    UINT32 u4Hmirror;
    UINT32 u4Vflip;
    UINT32 u4ColorMode;
    UINT32 u4Pitch;
} OSD_RGN_INFO_T;

/** OSD region register bit-field type.
 */

typedef struct _OSD_RGN_FIELD_T
{
    /* DWORD - 000 */
    UINT32 u4NextOsdAddr : 28;
    UINT32 u4ColorMode : 4;
    /* DWORD - 004 */
    UINT32 u4DataAddr : 28;
    UINT32 fgColorKeyEn : 1;
    UINT32 : 1;
    UINT32 u4MixSel : 2;
    /* DWORD - 008 */
    UINT32 u4LineSize : 11;
    UINT32 : 5;
    UINT32 u4MixWeight : 8;
    UINT32 u4VbSel : 2;
    UINT32 u4UgSel : 2;
    UINT32 u4YrSel : 2;
    UINT32 u4AlphaSel : 2;
    /* DWORD - 00C */
    UINT32 : 20;
    UINT32 fg10bitOsdEn : 1;
    UINT32 : 1;
    UINT32 fgNewPalette : 1;
    UINT32 fgNextOsdEn : 1;
    UINT32 fgDecMode : 2;
    UINT32 u4PaletteLen : 2;
    UINT32 fgDecEn : 1;
    UINT32 fgDecLine : 1;
    UINT32 fgHMirror : 1;
    UINT32 fgVFlip : 1;
    /* DWORD - 010 */
    UINT32 u4PaletteAddr : 28;
    UINT32 : 4;
    /* DWORD - 014 */
    UINT32 u4HStep : 16;
    UINT32 u4VStep : 16;
    /* DWORD - 018 */
#ifdef CC_MT5863
    UINT32 u4DataAddrHigh: 7;
    UINT32 : 1;
    UINT32 u4PaletteAddrHigh: 7;
    UINT32 : 1;
    UINT32 u4NextOsdAddrHigh: 7;
    UINT32 : 9;
#else
    UINT32 : 32;
#endif
    /* DWORD - 01C */
    UINT32 u4ColorKey : 32;
    /* DWORD - 020 */
    UINT32 u4HClip : 13;
    UINT32 : 3;
    UINT32 u4VClip : 12;
    UINT32 : 4;
    /* DWORD - 024 */
    UINT32 u4Ihw : 13;
    UINT32 : 3;
    UINT32 u4Ivw : 12;
    UINT32 : 4;
    /* DWORD - 028 */
    UINT32 u4Ovw : 12;
    UINT32 : 4;
    UINT32 u4Ovs : 12;
    UINT32 : 4;
    /* DWORD - 02c */
    UINT32 u4Ohw : 13;
    UINT32 : 3;
    UINT32 u4Ohs : 13;
    UINT32 : 3;
    LINT_SUPPRESS_NEXT_EXPRESSION(950)
} __attribute__((packed)) OSD_RGN_FIELD_T;

typedef struct _OSD_BASE_FIELD_T
{
    /* DWORD - 000 */
    UINT32 fgUpdate : 1;
    UINT32 fgAlwaysUpdate : 1;
    UINT32 fgForceCLKEn : 1;
    UINT32 fgTveUpdate : 1;
    UINT32 fgOSD3FifoSel : 1;
    UINT32 fgForceSramOn : 1;
    UINT32 : 26;

    /* DWORD - 004 */
    UINT32 fgResetFsm : 1;
    UINT32 fgResetAll : 1;
    UINT32 fgFrameReset : 1; //1:Reset FSM for each frame
#if defined(CC_MT5893) || defined(CC_MT5895)
    UINT32 fgTopRShadowSel : 1; //1:use left shadow; 0:use right shadow
    UINT32 fgLarbReset : 1;
    UINT32 fgMclkFrameReset : 1;
    UINT32 fgOvlShareOsdScaler : 1;
    UINT32 fgOsd2LvdsSel : 1;
    UINT32 fgOsdMonSel : 1; //0:use left monitor; 1:use right monitor
    UINT32 fgOvlOsd3FifoRem : 7;
    UINT32 fgOvlOsd3FifoFullTh : 8;
    UINT32 fgOvlOsd3FifoEmpTh : 8;
#else
    UINT32 : 29;
#endif

    /* DWORD - 008 */
    UINT32 fgHsEdge : 1;
    UINT32 fgVsEdge : 1;
    UINT32 fgFldPol : 1;
    UINT32 fgPrgs : 1;
    UINT32 : 1;
    UINT32 fgIntTGen : 1;
    UINT32 fgChecksumEn : 1;
    UINT32 fgOSD12Ex : 1;
    UINT32 fgAutoPos : 1;
    UINT32 fgYuvOut : 1;
    UINT32 : 2;
    UINT32 fgSclChkSumSel : 2;
    UINT32 fgSyncSrcSel : 2;
    UINT32 fgTGenMethod : 1;
    UINT32 fgCMPREn : 1;
    UINT32 fgTVEEn : 1;
#if defined(CC_MT5895)
    UINT32 fgSrcTimingSel : 1;
#else
    UINT32 fgYCC709En : 1;
#endif
    UINT32 fgAlphaBackEn : 1;
    UINT32 fgABISTEn : 1;
    UINT32 : 1;
    UINT32 fgOSD2LvdsEn : 1;
    UINT32 fgTransferCtl : 2;
    UINT32 fgOSD1Switch : 2;
    UINT32 fgOSD2Switch : 2;
    UINT32 fgOSD3Switch : 2;

    /* DWORD - 00C */
    UINT32 u4Ovt : 14;
    UINT32 : 2;
    UINT32 u4Oht : 14;
    UINT32 : 2;

    /* DWORD - 010 */
    UINT32 u4VsWidth : 8;
    UINT32 u4HsWidth : 8;
    UINT32 u4ScrnHStartOsd1 : 15;
    UINT32 u4DelayAdj : 1;

    /* DWORD - 014 */
    UINT32 u4ScrnHStartOsd3 : 15;
    UINT32 u4Osd3DelayAdj: 1;
    UINT32 u4ScrnHStartOsd2 : 15;
    UINT32 u4Osd2DelayAdj: 1;

    /* DWORD - 018 */
    UINT32 : 16;
    UINT32 u4ScrnVStart : 14;
    UINT32 : 2;

    /* DWORD - 01C */
    UINT32 : 32;

    /* DWORD - 020 */
    UINT32 u4Osd1VStart : 14;
    UINT32 : 2;
    UINT32 u4Osd1HStart : 14;
    UINT32 : 2;

    /* DWORD - 024 */
    UINT32 u4Osd2VStart : 14;
    UINT32 : 2;
    UINT32 u4Osd2HStart : 14;
    UINT32 : 2;

    /* DWORD - 028 */
    UINT32 u4Osd3VStart : 14;
    UINT32 : 2;
    UINT32 u4Osd3HStart : 14;
    UINT32 : 2;

    /* DWORD - 02C */
    UINT32 : 32;
    /* DWORD - 030 */
    UINT32 : 32;
    /* DWORD - 034 */
    UINT32 : 32;
    /* DWORD - 038 */
    UINT32 : 16;
    UINT32 u4ScrnHStartCSR : 15;
    UINT32 u4CsrDelayAdj: 1;
    /* DWORD - 03C */
    UINT32 u4CsrVStart : 14;
    UINT32 : 2;
    UINT32 u4CsrHStart : 14;
    UINT32 : 2;
    /* DWORD - 040 */
    UINT32 : 32;
    /* DWORD - 044 */
    UINT32 : 32;
    /* DWORD - 048 */
    UINT32 u4VcntStrobe: 14;
    UINT32 : 2;
    UINT32 u4HcntStrobe: 14;
    UINT32 : 2;
    /* DWORD - 04c */
    UINT32 u4VcntStatus: 14;
    UINT32 : 2;
    UINT32 u4HcntStatus: 14;
    UINT32 : 2;

    LINT_SUPPRESS_NEXT_EXPRESSION(950)
} __attribute__((packed)) OSD_BASE_FIELD_T;

typedef struct _OSD_3D_BASE_FIELD_T
{
    /* DWORD - 080 */
    UINT32 fgOsd2LShiftEn : 1;
    UINT32 fgOsd2LShiftInv : 1;
    UINT32 fgPlaneSwitchEn : 1;
    UINT32 fgPlaneSwitchInv : 1;
    UINT32 fgTgenLREn : 1;
    UINT32 fgTgenLLRREn : 1;
    UINT32 fgTgenLRDly : 1;
    UINT32 fgTgenLRInv : 1;
    UINT32 fgShutterShiftEn : 1;
    UINT32 : 1;
    UINT32 fgOsd1LShiftEn : 1;
    UINT32 fgOsd1LShiftInv : 1;
    UINT32 fgOsd3LShiftEn : 1;
    UINT32 fgOsd3LShiftInv : 1;
    UINT32 fgCsrLShiftEn : 1;
    UINT32 fgCsrLShiftInv : 1;
    UINT32 fgTwoChEn : 1;
    UINT32 fgTwoMaskDummy : 1;
    UINT32 : 5;
    UINT32 fgShutterLRFlag : 1;
    UINT32 : 8;

    /* DWORD - 084 */
    UINT32 fgOsd1ShiftValue : 8;
    UINT32 fgOsd2ShiftValue : 8;
    UINT32 fgOsd3ShiftValue : 8;
    UINT32 fgCsrShiftValue : 8;

    LINT_SUPPRESS_NEXT_EXPRESSION(950)
} __attribute__((packed)) OSD_3D_BASE_FIELD_T;

/** OSD plane register bit-field type.
 */
#ifdef CC_MT5863
typedef struct _OSD_PLA_FIELD_T
{
    /* DWORD - 000 */
    UINT32 fgEn : 1;
    UINT32 : 1;
    UINT32 fgFakeHdr : 1;
    UINT32 fgPrngEn : 1;
    UINT32 : 1;
    UINT32 : 1;
    UINT32 : 1;
    UINT32 fgPrngMode : 1;
    UINT32 fgAEdgeDetEn : 1;
    UINT32 fgCLKeySel : 1;
    UINT32 fgEnableMatrix: 1;
    UINT32 fgFastMute : 1;
    UINT32 fgPremulEn : 1;

    UINT32 fgShutter : 1;
    UINT32 fgFSMProtDis: 1; //FSM protection disable, not shown in register map, when 1, OSD HW would set initial state to begin
    UINT32 fgEnHwRstDec : 1;
    UINT32 : 4;
    UINT32 fgEnNewFastMute : 1;
    UINT32 fgEnHdrIrq : 1;
    UINT32 fgClrHdrIrq : 1;
    UINT32 : 1;
    UINT32 u4HeaderAddrHigh : 3;
    UINT32 : 1;
    UINT32 u4RightHeaderAddrHigh : 3;
    UINT32 fgHdrIrqStatus : 1;

    /* DWORD - 004 */
    UINT32 u4HeaderAddr : 32;

    /* DWORD - 008 */
    UINT32 u4Blending : 8;
    UINT32 u4Fading : 8;
    UINT32 fgHFilter : 1;
    UINT32 fgColor_Exp_sel : 1;
    UINT32 : 14;

    /* DWORD - 00c */
    UINT32 u4ContReqLmt : 4;
    UINT32 u4FifoSize : 4;
    UINT32 u4VacTh : 4;
    UINT32 u4PauseCnt : 4;
    UINT32 u4ContReqLmt0 : 4;
    UINT32 fgBurstDis : 1;
    UINT32 : 1;
    UINT32 : 1;
    UINT32 : 1;
    UINT32 LarbReqEn : 1;
    UINT32 : 1;
    UINT32 : 1;
    UINT32 : 1;
    UINT32 LarbTim : 4;

    /* DWORD - 010 */
    UINT32 : 24;
    UINT32 u4RealHeaderAddrHigh : 3;
    UINT32 : 5;

    /* DWORD - 014 */
    UINT32 u4RealHeaderAddr : 32;
    /* DWORD - 018 */
    UINT32 u4RightHeaderAddr : 32;
    /* DWORD - 01C */
    UINT32 : 32;
    /* DWORD - 020 */
    OSD_RGN_FIELD_T t_rgn;

    LINT_SUPPRESS_NEXT_EXPRESSION(950)
} __attribute__((packed)) OSD_PLA_FIELD_T;
#else
typedef struct _OSD_PLA_FIELD_T
{
    /* DWORD - 000 */
    UINT32 fgEn : 1;
    UINT32 : 1;
    UINT32 fgFakeHdr : 1;
    UINT32 fgPrngEn : 1;
    UINT32 : 1;
    UINT32 : 1;
    UINT32 : 1;
    UINT32 fgPrngMode : 1;
    UINT32 fgAEdgeDetEn : 1;
    UINT32 fgCLKeySel : 1;
    UINT32 fgEnableMatrix: 1;
    UINT32 fgFastMute : 1;
    UINT32 fgPremulEn : 1;

    UINT32 fgShutter : 1;
    UINT32 fgFSMProtDis: 1; //FSM protection disable, not shown in register map, when 1, OSD HW would set initial state to begin
    UINT32 fgEnHwRstDec : 1;
    UINT32 : 4;
    UINT32 fgEnNewFastMute : 1;
    UINT32 fgEnHdrIrq : 1;
    UINT32 fgClrHdrIrq : 1;
    UINT32 : 1;
    UINT32 fgHdrIrqStatus : 1;
    UINT32 : 7;

    /* DWORD - 004 */
    UINT32 u4HeaderAddr : 28; //5363 address 25bits
    UINT32 : 4;

    /* DWORD - 008 */
    UINT32 u4Blending : 8;
    UINT32 u4Fading : 8;
    UINT32 fgHFilter : 1;
    UINT32 fgColor_Exp_sel : 1;
    UINT32 : 2;
    UINT32 fgLSBAlpha: 1;  //alpha select for 10bit osd (0:alpha is [31:30] 1:alpha is [1:0]), only used in osd plane3
    UINT32 : 11;

    /* DWORD - 00c */
    UINT32 u4ContReqLmt : 4;
    UINT32 u4FifoSize : 4;
    UINT32 u4VacTh : 4;
    UINT32 u4PauseCnt : 4;
    UINT32 u4ContReqLmt0 : 4;
    UINT32 fgBurstDis : 1;
    UINT32 : 1;
    UINT32 : 1;
    UINT32 : 1;
    UINT32 LarbReqEn : 1;
    UINT32 : 1;
    UINT32 : 1;
    UINT32 : 1;
    UINT32 LarbTim : 4;

    /* DWORD - 010 */
    UINT32 : 32;

    /* DWORD - 014 */
    UINT32 u4RealHeaderAddr : 28; //5363 address 25bits
    UINT32 : 4;
    /* DWORD - 018 */
    UINT32 u4RightHeaderAddr : 28;
    UINT32 : 4;
    /* DWORD - 01C */
    UINT32 : 32;
    /* DWORD - 020 */
    OSD_RGN_FIELD_T t_rgn;

    LINT_SUPPRESS_NEXT_EXPRESSION(950)
} __attribute__((packed)) OSD_PLA_FIELD_T;
#endif

/** OSD scaler register bit-field type.
 */
typedef struct _OSD_SC_FIELD_T
{
    /* DWORD - 000 */
    UINT32 : 2;
    UINT32 fgVuscEn : 1;
    UINT32 fgVdscEn : 1;
    UINT32 fgHuscEn : 1;
    UINT32 fgHdscEn : 1;
    UINT32 fgScLpfEn: 1;
    UINT32 fgScEn : 1;
    UINT32 : 8;
    UINT32 fgScPtEn : 1;
    UINT32 : 2;
    UINT32 fgAlphaCountEn : 1;
    UINT32 : 12;

    /* DWORD - 004 */
    UINT32 u4SrcVSize : 14;
    UINT32 : 2;
    UINT32 u4SrcHSize : 13;
    UINT32 : 3;

    /* DWORD - 008 */
    UINT32 u4DstVSize : 14;
    UINT32 : 2;
    UINT32 u4DstHSize : 14;
    UINT32 : 2;

    /* DWORD - 00C */
    UINT32 u4VscHSize : 14;
    UINT32 : 18;

    /* DWORD - 010 */
    UINT32 u4HdscStep : 14;
    UINT32 : 2;
    UINT32 u4HdscOfst : 14;
    UINT32 : 2;

    /* DWORD - 014 */
    UINT32 u4HuscStep : 14;
    UINT32 : 2;
    UINT32 u4HuscOfst : 14;
    UINT32 : 2;

    /* DWORD - 018 */
    UINT32 u4VscOfstBot : 14;
    UINT32 : 2;
    UINT32 u4VscOfstTop : 14;
    UINT32 : 2;

    /* DWORD - 01C */
    UINT32 u4VscStep : 14;
    UINT32 : 18;

    /* DWORD - 020 */
    UINT32 u4ScLpfC3 : 7;
    UINT32 : 1;
    UINT32 u4ScLpfC2 : 7;
    UINT32 : 1;
    UINT32 u4ScLpfC1 : 6;
    UINT32 : 10;

    /* DWORD - 024 */
    UINT32 : 32;

    /* DWORD - 028 */
    UINT32 : 32;

    /* DWORD - 02c */
    UINT32 : 32;

    /* DWORD - 030 */
    UINT32 u4AEdgeDetTh: 7;
    UINT32 fgAEdgeDetEnNear: 1;
    UINT32 fgAEdgeDetEnSetRGB: 1;
    UINT32 : 23;
    LINT_SUPPRESS_NEXT_EXPRESSION(950)
} __attribute__((packed)) OSD_SC_FIELD_T;

/** OSD cursor register bit-field type.
 */
#ifdef CURSOR_SUPPORT
typedef struct _OSD_CSR_FIELD_T
{
    /* DWORD - 000 */
#ifdef OSD_CSR_H_ACTIVE_SUPPORT //20101129
    UINT32 u4VStart : 11;
    UINT32 : 1;
    UINT32 u4HStart : 11;
    UINT32 : 1;
#else
    UINT32 : 24;
#endif

    UINT32 fgV2x : 1;
    UINT32 fgH2x : 1;
    UINT32 fgEn : 1;
    UINT32 : 1;
    UINT32 fgH4Bit : 1;
    UINT32 fgV4Bit : 1;
    UINT32 : 2;
    LINT_SUPPRESS_NEXT_EXPRESSION(950)
} __attribute__((packed)) OSD_CSR_FIELD_T;
#endif

typedef struct _OSD_FRC_HEADER_FIELD_T
{
    /* DWORD - 000 */
    UINT32 fgFormat : 4; //[0000]ARGB6888;[0001]AYUV6888;[0101]AYUV8888;[0100]ARGB8888
    UINT32 fgPixelOrder : 4; //[0001]AGBR/AUVY;[0010]BGRA/VUYA;[0001]ABGR/AVUY;[0000]ARGB/AYUV
    UINT32 : 2;
    UINT32 fgLR : 1; //1:R,0:L
    UINT32 fg3DBmp : 1; //1:3D ; 0:2D
    UINT32 : 4;
    UINT32 fgOSDFramenum : 4;
    UINT32 fgOSDPrefix : 4; //[1010]valid osd;[0000]valid osd end
    UINT32 : 8;

    /* DWORD - 001 */
    UINT32 fgBmpHeight : 13;
    UINT32 : 3;
    UINT32 fgBmpWidth : 13;
    UINT32 : 3;

    /* DWORD - 002 */
    UINT32 fgGlobalAlpha : 8;
    UINT32 : 4;
    UINT32 fgPixelAlphaEn : 1;
    UINT32 fgGlobalAlphaEn : 1;
    UINT32 : 1;
    UINT32 fgOsdUpper : 1; //[1]:osd over vedio;[0]:osd under vedio
    UINT32 : 16;

    /* DWORD - 003 */
    UINT32 : 32;

    /* DWORD - 004 */
    UINT32 fgDispYOFF : 13;
    UINT32 : 3;
    UINT32 fgDispXOFF : 13;
    UINT32 : 3;

    /* DWORD - 005 */
    UINT32 fgDispHeight : 13;
    UINT32 : 3;
    UINT32 fgDispWidth : 13;
    UINT32 : 3;

    LINT_SUPPRESS_NEXT_EXPRESSION(950)
} __attribute__((packed)) OSD_FRC_HEADER_FIELD_T;

#if defined(CC_MT5886)
typedef struct _OSD_MMU_FIELD_T
{
    /* DWORD - 000 */
    UINT32 fgIOMMUEn : 1;
    UINT32 : 31;

    /* DWORD - 004 */
    UINT32 u4TableIdx : 32;

    /* DWORD - 008 */
    UINT32 fgA0MMUEn : 1;
    UINT32 u4A0MID : 3;
    UINT32 fgA0Prefetch : 1;
    UINT32 fgA02DPrefetch : 1;
    UINT32 fgA0PrefetchDir : 1;
    UINT32 : 9;
    UINT32 fgA1MMUEn : 1;
    UINT32 u4A1MID : 3;
    UINT32 fgA1Prefetch : 1;
    UINT32 fgA12DPrefetch : 1;
    UINT32 fgA1PrefetchDir : 1;
    UINT32 : 9;

    /* DWORD - 00C */
    UINT32 fgA2MMUEn : 1;
    UINT32 u4A2MID : 3;
    UINT32 fgA2Prefetch : 1;
    UINT32 fgA22DPrefetch : 1;
    UINT32 fgA2PrefetchDir : 1;
    UINT32 : 25;

    /* DWORD - 010 */
    UINT32 fg1MTIntClr : 1;
    UINT32 fg1MTIntEn : 1;
    UINT32 fg4KTIntClr : 1;
    UINT32 fg4KTIntEn : 1;
    UINT32 : 28;

    /* DWORD - 014 */
    UINT32 : 32;
    /* DWORD - 018 */
    UINT32 : 32;
    /* DWORD - 01C */
    UINT32 : 32;
    /* DWORD - 020 */
    UINT32 : 32;
    /* DWORD - 024 */
    UINT32 : 32;
    /* DWORD - 02C */
    UINT32 : 32;
    /* DWORD - 030 */
    UINT32 : 32;
    /* DWORD - 034 */
    UINT32 : 32;
    LINT_SUPPRESS_NEXT_EXPRESSION(950)
} __attribute__((packed)) OSD_MMU_FIELD_T;

#elif defined(CC_MT5863)
typedef struct _OSD_MMU_FIELD_T
{
    /* DWORD - 000 */
    UINT32 fgIOMMUEn : 1;
    UINT32 : 7;
    UINT32 u4MMUMode : 2;
    UINT32 : 22;

    /* DWORD - 004 */
    UINT32 u4TableIdx : 32;

    /* DWORD - 008 */
    UINT32 fgA0MMUEn : 1;
    UINT32 u4A0MID : 3;
    UINT32 fgA0Prefetch : 1;
    UINT32 fgA02DPrefetch : 1;
    UINT32 fgA0PrefetchDir : 1;
    UINT32 : 25;

    /* DWORD - 00C */
    UINT32 : 32;

    /* DWORD - 010 */
    UINT32 fg1GTIntClr : 1;
    UINT32 fg1GTIntEn : 1;
    UINT32 fg1MTIntClr : 1;
    UINT32 fg1MTIntEn : 1;
    UINT32 fg4KTIntClr : 1;
    UINT32 fg4KTIntEn : 1;
    UINT32 : 26;

    /* DWORD - 014 */
    UINT32 : 32;
    /* DWORD - 018 */
    UINT32 : 32;
    /* DWORD - 01C */
    UINT32 : 32;
    /* DWORD - 020 */
    UINT32 : 32;
    /* DWORD - 024 */
    UINT32 : 32;
    /* DWORD - 02C */
    UINT32 : 32;
    /* DWORD - 030 */
    UINT32 : 32;
    /* DWORD - 034 */
    UINT32 : 32;
    LINT_SUPPRESS_NEXT_EXPRESSION(950)
} __attribute__((packed)) OSD_MMU_FIELD_T;
#endif
/** OSD base register union type.
 */
/*lint -save -e960 */
typedef union _OSD_BASE_UNION_T
{
    UINT32 au4Reg[OSD_BASE_REG_NUM];
    OSD_BASE_FIELD_T rField;
} OSD_BASE_UNION_T;
/*lint -restore */

/** OSD plane register union type.
 */
/*lint -save -e960 */
typedef union _OSD_PLA_UNION_T
{
    UINT32 au4Reg[OSD_PLA_REG_NUM];
    OSD_PLA_FIELD_T rField;
} OSD_PLA_UNION_T;
/*lint -restore */
/* 3D related register */

typedef union _OSD_3D_UNION_T
{
    UINT32 au4Reg[2];
    OSD_3D_BASE_FIELD_T rField;
} OSD_3D_UNION_T;

/** OSD plane scaler union type.
 */
/*lint -save -e960 */
typedef union _OSD_SC_UNION_T
{
    UINT32 au4Reg[OSD_SC_REG_NUM];
    OSD_SC_FIELD_T rField;
} OSD_SC_UNION_T;
/*lint -restore */

/** OSD region register union type.
 */
/*lint -save -e960 */
typedef union _OSD_RGN_UNION_T
{
    UINT32 au4Reg[OSD_RGN_REG_NUM];
    OSD_RGN_FIELD_T rField;
} OSD_RGN_UNION_T;
/*lint -restore */

/** OSD cursor register union type.
 */
/*lint -save -e960 */
#ifdef CURSOR_SUPPORT
typedef union _OSD_CSR_UNION_T
{
    UINT32 au4Reg[OSD_CSR_REG_NUM];
    OSD_CSR_FIELD_T rField;
} OSD_CSR_UNION_T;
#endif
/*lint -restore */

#if defined(CC_MT5886) || defined(CC_MT5863)
typedef union _OSD_MMU_UNION_T
{
    UINT32 au4Reg[OSD_MMU_REG_NUM];
    OSD_MMU_FIELD_T rField;
} OSD_MMU_UNION_T;
#endif
// this struct is uesd to create palette
typedef struct _OSD_ARGB_T
{
    UINT8 u1Alpha;
    UINT8 u1Red;
    UINT8 u1Green;
    UINT8 u1Blue;
} OSD_ARGB_T;

typedef union _OSD_FRC_HEADER_UNION_T
{
    UINT32 au4Reg[6];
    OSD_FRC_HEADER_FIELD_T rField;
} OSD_FRC_HEADER_UNION_T;

typedef struct _OSD_SCALER_DATA_T
{
    UINT32 u4SrcWidth;
    UINT32 u4SrcHeight;
    UINT32 u4DstWidth;
    UINT32 u4DstHeight;
} OSD_SCALER_DATA_T;

typedef enum
{
    OSD_LL_NONE,
    OSD_LL_ERROR,
    OSD_LL_WARNING,
    OSD_LL_INFO,
    OSD_LL_DEBUG,
    OSD_LL_VERBOSE
} OSD_LOG_LEVEL;

#ifdef INCLUDE_LEGACY_DMA
/** OSD operation mode.
 */
typedef enum
{
    OSD_OP_NORMAL, OSD_OP_DMA, OSD_OP_GFX
} OSD_OP_MODE_T;
#endif

#if defined(CC_MT5886) || defined(CC_MT5863)
typedef enum
{
    OSD_MMU_AGENT_MID0,
    OSD_MMU_AGENT_MID1,
    OSD_MMU_AGENT_MID2
} OSD_MMU_AGENT_MID;
#endif

//-----------------------------------------------------------------------------
// Macro definitions
//-----------------------------------------------------------------------------

#define PARAM(IDX) (UINT32)StrToInt(szArgv[IDX+1])

#define OSD_DMA_ALIGN(X) (((X) + OSD_DMA_ALIGN_SIZE) & (~OSD_DMA_ALIGN_SIZE))
#define OSD_PALETTE_SIZE 1024

#define OSD_CHECK_NULL(X) \
    do \
    { \
        if ((X) == NULL) \
        { \
            return -(INT32)OSD_RET_INV_ARG; \
        } \
    } while (0)

#define OSD_VERIFY_PLANE(X) \
    do \
    { \
        if ((UINT32)(X) >= (UINT32)OSD_PLANE_MAX_NUM) \
        { \
            return -(INT32)OSD_RET_INV_PLANE; \
        } \
    } while (0)

#if defined(CC_MT5893) || defined(CC_MT5895)
#define OSD_VERIFY_PLANE_INTERNAL(X) \
    do \
    { \
        if ((UINT32)(X) >= (UINT32)OSD_PLANE_MAX_NUM) \
        { \
            return -(INT32)OSD_RET_INV_PLANE; \
        } \
    } while (0)

#define OSD_VERIFY_PLANE_EXTERNAL(X) \
    do \
    { \
        if ((UINT32)(X) >= (UINT32)OSD_RT_PLANE_1) \
        { \
            return -(INT32)OSD_RET_INV_PLANE; \
        } \
    } while (0)

#define OSD_CHECK_L2R_PLANE(plane) ((plane) <= OSD_PLANE_5 && (plane) != OSD_PLANE_4)
#define OSD_GET_L2R_PLANE(plane)   (((plane) == OSD_PLANE_5) ? OSD_RT_PLANE_5 : (plane) + 5)

#endif

#define OSD_VERIFY_SCALER(X) \
    do \
    { \
        if ((UINT32)(X) >= (UINT32)OSD_SCALER_MAX_NUM) \
        { \
            return -(INT32)OSD_RET_INV_SCALER; \
        } \
    } while (0)

#define OSD_VERIFY_REGION(X) \
    do \
    { \
        if ((UINT32)(X) >= (UINT32)OSD_MAX_NUM_RGN) \
        { \
            return -(INT32)OSD_RET_INV_REGION; \
        } \
    } while (0)

#define OSD_VERIFY_RGNLIST(X) \
    do \
    { \
        if ((UINT32)(X) >= (UINT32)OSD_MAX_NUM_RGN_LIST) \
        { \
            return -(INT32)OSD_RET_INV_LIST; \
        } \
    } while (0)

#define OSD_VERIFY_DISPLAY_MODE(X) \
    do \
    { \
        if ((UINT32)(X) >= (UINT32)OSD_DM_MAX_NUM) \
        { \
            return -(INT32)OSD_RET_INV_DISPLAY_MODE; \
        } \
    } while (0)


#define IGNORE_RET(X) \
    do \
    { \
        INT32 i4Ignore; \
        i4Ignore = (INT32)(X); \
        UNUSED(i4Ignore); \
    } while (0)

#define OSD_GET_LPF_SIGN_NUM(NUM, SIGN, DST) \
    do { \
        if ((NUM) > (SIGN)) \
        { \
            (DST) = (SIGN) - (NUM); \
        } \
        else \
        { \
            (DST) = (NUM); \
        } \
    } while (0)

#define OSD_SET_LPF_SIGN_NUM(NUM, SIGN, SRC) \
    do { \
        if (SRC < 0) \
        { \
            (NUM) = (UINT16)((SIGN) - SRC); \
        } \
        else \
        { \
            (NUM) = (UINT16)SRC; \
        } \
        if ((NUM) >= ((SIGN) << 1)) \
        { \
            return -(INT32)OSD_RET_INV_ARG; \
        } \
    } while (0)

#define OSD_BYTE_PER_PIXEL(CM, BPP) \
    do \
    { \
        switch ((CM)) \
        { \
        case OSD_CM_CBYCRY422_DIRECT16: \
        case OSD_CM_YCBYCR422_DIRECT16: \
        case OSD_CM_RGB565_DIRECT16: \
        case OSD_CM_ARGB1555_DIRECT16: \
        case OSD_CM_ARGB4444_DIRECT16: \
            (BPP) = 2; \
            break; \
        case OSD_CM_AYCBCR8888_DIRECT32: \
        case OSD_CM_ARGB8888_DIRECT32: \
            (BPP) = 4; \
            break; \
        default: \
            (BPP) = 1; \
        } \
    } while (0)

#define OSD_PIXEL_PER_BYTE(CM, PIXEL, MASK, BIT) \
            do \
            { \
                switch ((CM)) \
                { \
                case OSD_CM_YCBCR_CLUT2: \
                case OSD_CM_RGB_CLUT2: \
                    (PIXEL) = 4; \
                    (MASK) = 0x3; \
                    (BIT)  = 2; \
                    break; \
                case OSD_CM_YCBCR_CLUT4: \
                case OSD_CM_RGB_CLUT4: \
                    (PIXEL) = 2; \
                    (MASK) = 0xf; \
                    (BIT)  = 4; \
                    break; \
                default: \
                    (PIXEL) = 1; \
                    (MASK) = 0xff; \
                    (BIT)  = 8; \
                } \
            } while (0)

#define OSD_GET_PITCH_SIZE(CM, WIDTH, SIZE) \
    do \
    { \
        switch ((CM)) \
        { \
        case OSD_CM_CBYCRY422_DIRECT16: \
        case OSD_CM_YCBYCR422_DIRECT16: \
        case OSD_CM_RGB565_DIRECT16: \
        case OSD_CM_ARGB1555_DIRECT16: \
        case OSD_CM_ARGB4444_DIRECT16: \
            (SIZE) = (WIDTH) * 2; \
            break; \
        case OSD_CM_AYCBCR8888_DIRECT32: \
        case OSD_CM_ARGB8888_DIRECT32: \
            (SIZE) = (WIDTH) * 4; \
            break; \
        case OSD_CM_YCBCR_CLUT8: \
        case OSD_CM_RGB_CLUT8: \
            (SIZE) = (WIDTH); \
            break; \
        case OSD_CM_YCBCR_CLUT4: \
        case OSD_CM_RGB_CLUT4: \
            (SIZE) = (WIDTH) >> 1; \
            break; \
        case OSD_CM_YCBCR_CLUT2: \
        case OSD_CM_RGB_CLUT2: \
            (SIZE) = (WIDTH) >> 2; \
            break; \
        default: \
            ASSERT(0); \
        } \
    } while (0)


#define OSD_DMA_PLANE                       (OSD_PLANE_2)


//-----------------------------------------------------------------------------
// Public functions
//-----------------------------------------------------------------------------

/** osd global initialization function
 *  @param  void
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_Init(void);
EXTERN INT32 OSD_ReInit(void);

EXTERN INT32 OSD_Reset(void);

EXTERN INT32 OSD_SwInit(void);

EXTERN INT32 OSD_SwReset(void);
EXTERN void _OSD_AlwaysUpdateReg(BOOL fgEnable);
EXTERN void OSD_SetLogLevel(UINT32 level);
EXTERN UINT32 OSD_GetLogLevel(void);

EXTERN void OSD_InitVsync(void);
EXTERN UINT64 OSD_WaitVsync(void);
EXTERN VOID OSD_EnableHwVsync(BOOL fgEnabled);
EXTERN void OSD_UpdateReg(void);
EXTERN void OSD_TimingNfy(void);

EXTERN INT32 OSD_BASE_SetDisplayMode(UINT32 u4DisplayMode);

EXTERN INT32 OSD_BASE_SetPlaneSwitchOrder(UINT32 u4TopPlane, UINT32 u4MidPlane,
                                          UINT32 u4BotPlane);
EXTERN INT32 OSD_BASE_GetPlaneSwitchOrder(UINT32 *u4TopPlane, UINT32 *u4MidPlane,
                                          UINT32 *u4BotPlane);
/** set osd plane position
 *  @param  u4Plane plane id
 *  @param  u4X x position
 *  @param  u4Y y position
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_BASE_SetOsdPosition(UINT32 u4Plane, UINT32 u4X, UINT32 u4Y);

/** get osd plane position
 *  @param  u4Plane plane id
 *  @param  pu4X x position pointer
 *  @param  pu4Y y position pointer
 *  @retval OSD_RET_OK success
 */
EXTERN INT32
OSD_BASE_GetOsdPosition(UINT32 u4Plane, UINT32 *pu4X, UINT32 *pu4Y);

EXTERN INT32 OSD_BASE_SetClock(UINT32 u4Clock);
EXTERN VOID OSD_BASE_SetPoclk(BOOL fgEnable);
EXTERN INT32 OSD_BASE_SetYuvOutput(BOOL fgYuvOutput);
EXTERN void OSD_BASE_Dump(void);

EXTERN INT32 OSD_BASE_SetLineShift(UINT32 u4Enable, UINT32 u4Shift);
EXTERN INT32 OSD_Base_SetHStart(void);
EXTERN INT32 OSD_Base_GetOffset(UINT32 *pu4H, UINT32 *pu4V);
EXTERN void OSD_BASE_SwitchResolution(void);
EXTERN VOID OSD_BASE_AutoAlignPosition(VOID);

EXTERN INT32 OSD_BASE_SetPlaneLineShift(UINT32 u4Plane, BOOL fgEnable,
                                        INT32 i4Value);

EXTERN INT32 OSD_BASE_GetHTotalPixel(UINT32 *pu4Value);

EXTERN UINT32 OSD_BASE_GetDisplayWidth(VOID);
EXTERN UINT32 OSD_BASE_GetDisplayHeight(VOID);

EXTERN INT32 OSD_SetTVEOut(BOOL fgEnable);
EXTERN INT32 OSD_ShowLogo(void);

EXTERN VOID OSD_PLA_InitAll(VOID);
EXTERN VOID OSD_PLA_SwResetAll(VOID);
EXTERN INT32 OSD_PLA_Reset(UINT32 u4Plane);
EXTERN INT32 OSD_PLA_SwReset(UINT32 u4Plane);

EXTERN VOID OSD_PLA_SetAvailable(UINT32 u4Plane, BOOL fgVailable);
EXTERN BOOL OSD_PLA_GetAllPanelAvailable(VOID);
EXTERN INT32 OSD_PLA_CacheRngList(UINT32 u4Plane, UINT32 u4RgnList);
EXTERN INT32 OSD_PLA_CacheScaler(UINT32 u4Scaler, UINT32 u4SrcWidth, UINT32 u4SrcHeight,
                                 UINT32 u4DstWidth, UINT32 u4DstHeight);
EXTERN BOOL OSD_PLA_GetSCCacheState(UINT32 u4Plane);
EXTERN BOOL OSD_PLA_GetFlipCacheState(UINT32 u4Plane);
EXTERN BOOL OSD_PLA_GetEnableCacheState(UINT32 u4Plane);


/** enable/disable osd plane, it will also disable scaler when disable plane
 *  @param  u4Plane plane id
 *  @param  fgEnable enable=TRUE/disable=FALSE
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_PLA_Enable(UINT32 u4Plane, BOOL fgEnable);

/** attach a specific list to osd plane
 *  @param  u4Plane plane id
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_PLA_FlipTo(UINT32 u4Plane, UINT32 u4RgnList);

EXTERN INT32 OSD_PLA_FlipToNone(UINT32 u4Plane);
EXTERN INT32 OSD_PLA_Reflip(UINT32 u4RgnList);

/** get osd plane alpha level
 *  @param  u4Plane plane id
 *  @param  pu1BlendLevel aplha level pointer
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_PLA_GetBlendLevel(UINT32 u4Plane, UINT8 *pu1BlendLevel);

/** set osd plane alpha level
 *  @param  u4Plane plane id
 *  @param  u1BlendLevel aplha level(0~255)
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_PLA_SetBlendLevel(UINT32 u4Plane, UINT8 u1BlendLevel);

/** get osd plane fading value
 *  @param  u4Plane plane id
 *  @param  pu1Fading fading value pointer
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_PLA_GetFading(UINT32 u4Plane, UINT8 *pu1Fading);

/** set osd plane fading value
 *  @param  u4Plane plane id
 *  @param  u1Fading fading value
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_PLA_SetFading(UINT32 u4Plane, UINT8 u1Fading);

EXTERN INT32 OSD_PLA_SetHFilter(UINT32 u4Plane, BOOL fgEnable);
EXTERN INT32 OSD_PLA_SetFifo(UINT32 u4Plane, BOOL fgFastReq, UINT8 u1ExVacThr,
                             UINT8 u1VacThr, UINT8 u1FullThr);
EXTERN INT32 OSD_PLA_SetGlobeEnable(UINT32 u4Plane, BOOL fgGlobeEnable);
EXTERN INT32 OSD_PLA_SetFastMute(UINT32 u4Plane, UINT32 u4Mute);
EXTERN INT32 OSD_PLA_GetFastMute(UINT32 u4Plane, UINT32 *pu4Mute);

/** dump osd debug info
 *  @param  u4Plane osd plane
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_PLA_Dump(UINT32 u4Plane);
EXTERN INT32 OSD_PLA_DisableLoaderLogo(UINT32 u4Plane);
EXTERN UINT32 OSD_PLANE_TO_SCALER(UINT32 u4Plane);

/** get the first region id of osd plane
 *  @param  u4Plane osd plane
 *  @retval region id, -1 is no region
 */
EXTERN INT32 OSD_PLA_GetFirstRegion(UINT32 u4Plane);
EXTERN INT32 _OSD_PLA_Get_Hw_RealHeaderAddr(UINT32 u4Plane,
                                            volatile UPTR *pupValue);
EXTERN INT32 _OSD_PLA_Get_Hw_RealBmpAddr(UINT32 u4Plane, UPTR *pu4Value);
EXTERN INT32 _OSD_PLA_Get_Hw_RealClipH(UINT32 u4Plane, UINT32 *pu4Value);

EXTERN UINT32 OSD_PLA_GetRgnPlane(INT32 i4FirstRegion);

EXTERN INT32 OSD_PLA_GetFirstRegionList(UINT32 u4Plane);
EXTERN INT32 OSD_PLA_GetEnable(UINT32 u4Plane, BOOL *pfgEnable);

/** get the first region address of osd plane
 *  @param  u4Plane osd plane
 *  @retval region address, 0 is no region
 */
EXTERN UPTR OSD_PLA_GetFirstRegionAddress(UINT32 u4Plane);

EXTERN INT32 OSD_PLA_GetAllRegion(UINT32 u4Plane, UINT32 *u4Rgn1,
                                  UINT32 *u4Rgn2);
EXTERN INT32 OSD_PLA_GetSrcContentRegion(UINT32 u4Plane, UINT32 *u4Rgn1,
                                         UINT32 *u4Rgn2);
EXTERN INT32 OSD_PLA_GetSrcContentSize(UINT32 u4Plane, UINT32 *pu4Width,
                                       UINT32 *pu4Height);

EXTERN UINT32 OSD_PLA_GetHStart(UINT32 u4Plane);
EXTERN UINT32 OSD_PLA_GetVStart(UINT32 u4Plane);



#if 0
EXTERN INT32 OSD_PLA_Set3DAddress(UINT32 u4Plane, UINT32 u4L_Address, UINT32 u4R_Address);
EXTERN INT32 OSD_Vsync_3DUpdateLR(UINT32 u4L_R);
#endif
EXTERN INT32 OSD_Set3DMode(UINT8 u1Mode);

EXTERN INT32 OSD_RGN_LIST_Set(UINT32 u4RgnList, INT32 i4Cmd, UINT32 u4Value);
EXTERN INT32 OSD_RGN_LIST_Get(UINT32 u4RgnList, INT32 i4Cmd, UINT32 *pu4Value);

/** create an osd list
 *  @param pu4RgnList list id pointer
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_RGN_LIST_Create(UINT32 *pu4RgnList);

/** delete an osd list
 *  @param  u4RgnList list id
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_RGN_LIST_Delete(UINT32 u4RgnList);

/** get first region id of list
 *  @param  u4RgnList list id
 *  @param  pi4HeadRegion region id pointer
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_RGN_LIST_GetHead(UINT32 u4RgnList, INT32 *phHeadRegion);

EXTERN INT32 OSD_RGN_LIST_GetNext(UINT32 u4RgnList, INT32 hRgnCurr,
                                  INT32 *phRgnNext);
EXTERN INT32 OSD_RGN_LIST_DetachAll(UINT32 u4RgnList);
EXTERN INT32 OSD_RGN_LIST_GetCount(UINT32 u4RgnList, INT32 *pi4Count);

EXTERN INT32 OSD_RGN_LIST_Init(void);
EXTERN INT32 OSD_RGN_Init(void);
EXTERN INT32 OSD_RGN_LIST_SCALER_Init(void);
EXTERN INT32 OSD_RGN_LIST_LineScaler(UINT32 u4RgnList, UINT32 u4BmpWidth, UINT32 u4BmpHeight,
                                     void *pvBitmap, UINT32 eColorMode, UINT32 u4BmpPitch,
                                     UINT32 u4DispX, UINT32 u4DispY, UINT32 u4DispW, UINT32 u4DispH);
EXTERN INT32 OSD_RGN_SetColorOrder(UINT32 u4Region, UINT32 u4AOrder, UINT32 u4ROrder,
                                   UINT32 u4GOrder, UINT32 u4BOrder);
/** get osd region attribute
 *  @param  u4Region region id
 *  @param  i4Cmd attribute name, refer to OSD_RGN_CMD_T
 *  @param  pu4Value attribute value pointer
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_RGN_Get(UINT32 u4Region, INT32 i4Cmd, UINT32 *pu4Value);
EXTERN INT32 OSD_RGN_GetAddress(UINT32 u4Region, INT32 i4Cmd, UPTR *pupValue);
#if defined(CC_OSD1_M4U_IOVA_SUPPORT) || defined(CC_OSD2_M4U_IOVA_SUPPORT) || defined(CC_OSD3_M4U_IOVA_SUPPORT)
EXTERN INT32 OSD_RGN_SetCpuAddr(UINT32 u4Region, VOID *ppvCpuAddr);
EXTERN INT32 OSD_RGN_GetCpuAddr(UINT32 u4Region, VOID **ppvCpuAddr);
#endif

EXTERN INT32 OSD_RGN_Set(UINT32 u4Region, INT32 i4Cmd, UINT32 u4Value);
EXTERN INT32 OSD_RGN_SetAddress(UINT32 u4Region, INT32 i4Cmd, UPTR upValue);

EXTERN INT32 OSD_RGN_Copy(UINT32 u4DstRgn, UINT32 u4SrcRgn);


/** create an osd region
 *  @param  pu4Region region id pointer
 *  @param  u4BmpWidth source bitmap width
 *  @param  u4BmpHeight source bitmap height
 *  @param  pvBitmap source bitmap address, MUST align with 16bytes
 *  @param  eColorMode, region color mode, refer to OSD_COLOR_MODE_T
 *  @param  u4BmpPitch, bytes per line, MUST align with 16bytes
 *  @param  u4DispX, region x position
 *  @param  u4DispY, region y position
 *  @param  u4DispW, output width
 *  @param  u4DispH, output height

 *  @retval OSD_RET_OK success
 *  @retval OSD_RET_INV_ARG invalid argument
 */
EXTERN INT32 OSD_RGN_Create(UINT32 *pu4Region, UINT32 u4BmpWidth,
                            UINT32 u4BmpHeight, void *pvBitmap, UINT32 eColorMode,
                            UINT32 u4BmpPitch, UINT32 u4DispX, UINT32 u4DispY, UINT32 u4DispW,
                            UINT32 u4DispH);

/** delete an osd region
 *  @param  u4Region region id
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_RGN_Delete(UINT32 u4Region);

EXTERN INT32 OSD_RGN_AttachTail(UINT32 u4Region, UINT32 u4RgnList);

/** attach region to list
 *  @param  u4Region region id
 *  @param  u4RgnList list id
 *  @retval OSD_RET_OK success
 *  @retval OSD_RET_INV_LIST invalid list
 */
EXTERN INT32 OSD_RGN_Insert(UINT32 u4Region, UINT32 u4RgnList);

/** dettach region from list
 *  @param  u4Region region id
 *  @param  u4RgnList list id
 *  @retval OSD_RET_OK success
 *  @retval OSD_RET_INV_REGION invalid region
 */
EXTERN INT32 OSD_RGN_Detach(UINT32 u4Region, UINT32 u4RgnList);

EXTERN INT32 OSD_RGN_SetDisplayWidth(UINT32 u4Region, UINT32 u4Width);
EXTERN INT32 OSD_RGN_SetDisplayHeight(UINT32 u4Region, UINT32 u4Height);
EXTERN INT32 OSD_RGN_SetBigEndian(UINT32 u4Region, BOOL fgBE);
EXTERN INT32 OSD_RGN_Dump(UINT32 u4Region);

//add for setting/getting the region list used by linux frame buffer
EXTERN INT32 OSD_Set_FrameBuffer_RGN_LIST(UINT32 u4RgnList);
EXTERN INT32 OSD_Get_FrameBuffer_RGN_LIST(UINT32 *pu4Value);

//add for getting the region resolution used by linux frame buffer
EXTERN INT32 OSD_Get_FrameBuffer_Resolution(UINT32 *pu4Width, UINT32 *pu4Height);

EXTERN INT32 OSD_RGN_GetOriginalY(UINT32 u4Region, UINT32 *pu4Value);
EXTERN INT32 OSD_RGN_GetOriginalX(UINT32 u4Region, UINT32 *pu4Value);
EXTERN INT32 OSD_RGN_MirrorFlipUpdate(UINT32 u4Region, BOOL updateMirror, BOOL updateFlip);
EXTERN UINT32 OSD_RGN_TO_PLANE(UINT32 u4Region);
#ifndef CC_MTK_LOADER
EXTERN INT32 OSD_RGN_GetVirtBmpAddr(UINT32 u4Region, UPTR *upAddr, UINT32 *u4Size);
#endif

/** cinfugure osd scaler
 *  @param  u4Scaler scaler id(only OSD_SCALER_2)
 *  @param  fgEnable enable=TRUE/disable=FALSE
 *  @param  u4SrcWidth osd input width
 *  @param  u4SrcHeight osd input height
 *  @param  u4DstWidth osd output width
 *  @param  u4DstHeight osd output height
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_SC_Scale(UINT32 u4Scaler, UINT32 u4Enable, UINT32 u4SrcWidth,
                          UINT32 u4SrcHeight, UINT32 u4DstWidth, UINT32 u4DstHeight);
EXTERN INT32 OSD_SC_DoScale(UINT32 u4Scaler, UINT32 u4Enable, UINT32 u4SrcWidth,
                          UINT32 u4SrcHeight, UINT32 u4DstWidth, UINT32 u4DstHeight);
EXTERN INT32 OSD_SC_Init(UINT32 u4Scaler);
EXTERN VOID OSD_SC_InitAll(VOID);
EXTERN VOID OSD_SC_SwResetAll(VOID);

#if !(defined NDEBUG) || defined(__MODEL_slt__)
EXTERN INT32 OSD_SC_HDown(UINT32 u4Scaler, UINT32 u4SrcWidth, UINT32 u4Step);
EXTERN INT32 OSD_SC_HUp(UINT32 u4Scaler, UINT32 u4SrcWidth, UINT32 u4Step);
EXTERN INT32 OSD_SC_VDown(UINT32 u4Scaler, UINT32 u4SrcHeight, UINT32 u4Step);
EXTERN INT32 OSD_SC_VUp(UINT32 u4Scaler, UINT32 u4SrcHeight, UINT32 u4Step);
#endif

/** get osd scaler infomation
 *  @param  u4Scaler scaler id(only OSD_SCALER_2)
 *  @param  pu4Enable enable pointer
 *  @param  pu4SrcW osd input width pointer
 *  @param  pu4SrcH osd input height pointer
 *  @param  pu4DstW osd output width pointer
 *  @param  pu4DstH osd output height pointer
 *  @param  pu4Is16Bpp don't care
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_SC_GetScalerInfo(UINT32 u4Scaler, UINT32 *pu4Enable,
                                  UINT32 *pu4SrcW, UINT32 *pu4SrcH, UINT32 *pu4DstW, UINT32 *pu4DstH,
                                  UINT32 *pu4Is16Bpp);

EXTERN INT32 OSD_SC_SetLpfInfo(UINT32 u4Scaler, UINT32 u4Enable, INT16 i2C1,
                               INT16 i2C2, INT16 i2C3, INT16 i2C4, INT16 i2C5);

/** enable low pass filter
 *  @param  u4Scaler scaler id(only OSD_SCALER_2)
 *  @param  fgEnable enable=TRUE/disable=FALSE
 *  @retval OSD_RET_OK success
 */
EXTERN INT32 OSD_SC_SetLpf(UINT32 u4Scaler, UINT32 u4Enable);

EXTERN INT32 OSD_SC_GetLpfInfo(UINT32 u4Scaler, UINT32 *pu4Enable,
                               INT16 *pi2C1, INT16 *pi2C2, INT16 *pi2C3, INT16 *pi2C4, INT16 *pi2C5);
EXTERN void OSD_SC_UpdateDstSize(UINT32 u4Scaler);
EXTERN INT32 OSD_SC_SetSramConfiguration(UINT32 u4Mode);
EXTERN INT32 OSD_SC_GetSramConfiguration(void);
EXTERN INT32 OSD_SC_Dump(UINT32 u4Scaler);
EXTERN INT32 OSD_SC_SetRegion(UINT32 u4Scaler, INT32 i4Region);

EXTERN void OSD_DrawVLine(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                          UINT32 u4ColorMode, UINT8 u1Alpha);
EXTERN void OSD_DrawHLine(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                          UINT32 u4ColorMode);
EXTERN void OSD_DrawBorder(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                           UINT32 u4ColorMode);
EXTERN void OSD_DrawColorbar(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                             UINT32 u4ColorMode, UINT8 u1Alpha);
EXTERN void OSD_DrawSlt(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                        UINT32 u4ColorMode);
EXTERN void OSD_DrawRamp(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                         UINT32 u4ColorMode, UINT8 u1Alpha, BOOL fgPremultipled);
EXTERN void OSD_DrawMute(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                         UINT32 u4ColorMode, UINT32 u4MuteColor);
EXTERN void OSD_CreatePaleTable(OSD_ARGB_T *prPaleTable, UINT32 u4ColorMode);
EXTERN void OSD_DrawColor(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                          UINT32 u4ColorMode, UINT32 u4Color);
EXTERN void OSD_DrawColorbar2(UINT8 *pu1Canvas, UINT32 u4Width,
                              UINT32 u4Height, UINT32 u4ColorMode);
EXTERN void OSD_DrawPattern0(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                             UINT32 u4ColorMode, UINT32 u4BgColor);
EXTERN void OSD_DrawPattern1(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                             UINT32 u4ColorMode, UINT32 u4Pattern);
EXTERN void OSD_DrawPattern2(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                             UINT32 u4ColorMode, UINT32 u4Pattern);
EXTERN void OSD_DrawPattern3(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                             UINT32 u4ColorMode, UINT32 u4Pattern, UINT32 u4BgColor);
EXTERN void OSD_DrawPattern4(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                             UINT32 u4ColorMode, UINT32 u4Pattern);
EXTERN void OSD_DrawPattern5(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                             UINT32 u4ColorMode);
EXTERN void OSD_DrawPattern6(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                             UINT32 u4ColorMode);
EXTERN void OSD_DrawPattern7(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                             UINT32 u4ColorMode);
EXTERN void OSD_DrawPattern8(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                             UINT32 u4ColorMode, UINT32 uPattern);
EXTERN void OSD_DrawPattern9(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                             UINT32 u4ColorMode);
EXTERN void OSD_DrawPattern10(UINT8 *pu1Canvas, UINT32 u4Width,
                              UINT32 u4Height, UINT32 u4ColorMode);

EXTERN void OSD_DrawPattern11(UINT8 *pu1Canvas, UINT32 u4Width,
                              UINT32 u4Height, UINT32 u4ColorMode);
EXTERN void OSD_DrawPattern12(UINT8 *pu1Canvas, UINT32 u4Width,
                              UINT32 u4Height, UINT32 u4ColorMode);
EXTERN void OSD_DrawPattern13(UINT8 *pu1Canvas, UINT32 u4Width,
                              UINT32 u4Height, UINT32 u4ColorMode);
EXTERN void
OSD_DrawPattern14(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                  UINT32 u4ColorMode, UINT32 u4Pattern, UINT32 u4BgColor);
EXTERN void OSD_DrawPattern15(UINT8 *pu1Canvas, UINT32 u4Width,
                              UINT32 u4Height, UINT32 u4ColorMode);
EXTERN void OSD_DrawPattern16(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                              UINT32 u4ColorMode);
void OSD_DrawPixLinePattern0(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                             UINT32 u4R, UINT32 u4G, UINT32 u4B);
EXTERN void OSD_DrawPixLinePattern1(UINT8 *pu1Canvas, UINT32 u4Width,
                                    UINT32 u4Height, UINT32 u4R, UINT32 u4G, UINT32 u4B);
EXTERN void OSD_DrawPixLinePattern2(UINT8 *pu1Canvas, UINT32 u4Width,
                                    UINT32 u4Height, UINT32 u4R, UINT32 u4G, UINT32 u4B);
EXTERN void OSD_DrawPixLinePattern3(UINT8 *pu1Canvas, UINT32 u4Width,
                                    UINT32 u4Height, UINT32 u4R, UINT32 u4G, UINT32 u4B);
EXTERN void OSD_DrawPixLinePattern4(UINT8 *pu1Canvas, UINT32 u4Width,
                                    UINT32 u4Height, UINT32 u4R, UINT32 u4G, UINT32 u4B);
EXTERN void OSD_DrawPixLinePattern5(UINT8 *pu1Canvas, UINT32 u4Width,
                                    UINT32 u4Height, UINT32 u4R, UINT32 u4G, UINT32 u4B);
EXTERN void OSD_DrawPixLinePattern6(UINT8 *pu1Canvas, UINT32 u4Width,
                                    UINT32 u4Height, UINT32 u4R, UINT32 u4G, UINT32 u4B);
EXTERN void OSD_DrawPixLinePattern7(UINT8 *pu1Canvas, UINT32 u4Width,
                                    UINT32 u4Height, UINT32 u4R, UINT32 u4G, UINT32 u4B);
EXTERN void OSD_DrawPixLinePattern8(UINT8 *pu1Canvas, UINT32 u4Width,
                                    UINT32 u4Height, UINT32 u4R, UINT32 u4G, UINT32 u4B);
EXTERN void OSD_DrawPixLinePattern9(UINT8 *pu1Canvas, UINT32 u4Width,
                                    UINT32 u4Height, UINT32 u4R, UINT32 u4G, UINT32 u4B);

EXTERN void OSD_LockFlipTo(void);
EXTERN void OSD_UnLockFlipTo(void);

EXTERN void OSD_LockLogoDisplaying(void);
EXTERN void OSD_UnLockLogoDisplaying(void);
EXTERN VOID OSD_BASE_GetPanelSize(UINT32 *u4Width, UINT32 *u4Height);
EXTERN void OSD_DrawPatternL92(UINT8 *pu1Canvas, UINT32 u4Width,
                               UINT32 u4Height, UINT32 u4ColorMode, UINT8 ui1_grid_width,
                               UINT8 ui1_grid_heigh, UINT32 u4BgColor);

EXTERN void OSD_DrawPatternGomi(UINT8 *pu1Canvas, UINT32 u4Width,
                                UINT32 u4Height, UINT32 u4ColorMode, UINT32 u4BgColor, UINT8 ui1_mode);
EXTERN void OSD_DrawPatternCrosstalk(UINT8 *pu1Canvas, UINT32 u4Width,
                                     UINT32 u4Height, UINT32 u4ColorMode, UINT32 u4BgColor);
EXTERN void OSD_DrawPatternFlicker(UINT8 *pu1Canvas, UINT32 u4Width,
                                   UINT32 u4Height, UINT32 u4ColorMode, UINT32 u4BgColor);
EXTERN void OSD_DrawPatternFlicker1(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                                    UINT32 u4ColorMode, UINT32 u4BgColor);
EXTERN void OSD_DrawPatternFlicker2(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                                    UINT32 u4ColorMode, UINT32 u4BgColor);
EXTERN void OSD_DrawPatternFlicker3(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                                    UINT32 u4ColorMode, UINT32 u4BgColor);
EXTERN void OSD_DrawPatternStripe1(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                                   UINT32 u4ColorMode);
EXTERN void OSD_DrawPatternStripe2(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                                   UINT32 u4ColorMode);
EXTERN void OSD_DrawPatternStripe3(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                                   UINT32 u4ColorMode);

EXTERN UINT32 OSD_ColormodeToBpp(OSD_COLOR_MODE_T cm);

#ifdef INCLUDE_LEGACY_DMA
EXTERN void OSD_DMA_Init(void);

EXTERN void OSD_DMA_SetMode(OSD_OP_MODE_T eMode);

EXTERN void OSD_DMA_SetTarget(UINT32 *au4TargetAddr);

EXTERN INT32 OSD_DMA_TransferRegion(UINT32 u4Plane);

EXTERN INT32 OSD_DMA_WriteRegister(UINT32 u4Reg, UINT32 u4Value,
                                   BOOL fg8bitData, UINT32 u4Parity);

EXTERN INT32 OSD_DMA_Copy(UPTR u4DstAddress, UPTR u4SrcAddress,
                          USIZE u4Size);

EXTERN void OSD_DMA_OnOutputVsync(void);

EXTERN void OSD_DMA_SetUpdatePeriod(UINT32 u4DmaUpdatePeriod);

EXTERN void OSD_DMA_Dump(void);

EXTERN OSD_OP_MODE_T OSD_DMA_GetMode(void);

EXTERN void OSD_DMA_EnableI2C(BOOL fgEnable);

EXTERN void OSD_DMA_AfterPaletteUpdate(UINT32 u4PaletteId,
                                       UPTR u4PaletteAddress);

EXTERN INT32 OSD_DMA_Check_Plane(UINT32 u4_plane);
EXTERN INT32 OSD_DMA_Set8281(UPTR u4addr, UINT32 u4value);
#endif


//Add for Set DRAM parameters
EXTERN void OSD_PLA_SetContReqLmt(UINT32 u4Plane, UINT32 u4Value);
EXTERN void OSD_PLA_SetFifoSize(UINT32 u4Plane, UINT32 u4Value);
EXTERN void OSD_PLA_SetVacTh(UINT32 u4Plane, UINT32 u4Value);
EXTERN void OSD_PLA_SetPauseCnt(UINT32 u4Plane, UINT32 u4Value);
EXTERN void OSD_PLA_SetContReqLmt0(UINT32 u4Plane, UINT32 u4Value);


EXTERN BOOL OSD_GetUnderflowStatus(void);

EXTERN void OSD_ClearUnderflowStatus(void);

//For OSD scroll
EXTERN INT32 OSD_Vsync_UpdateScroll(void);
EXTERN INT32 OSD_RGN_SetScrollInfo(UINT32 u4Rgn, UPTR u4BaseAddress,
                                   UINT32 u4Pitch, UINT32 u4Step);
EXTERN INT32 OSD_SetScrollMode(UINT8 u1Mode);
EXTERN INT32 OSD_BASE_Get3DOsd2LShiftEn(UINT32 *pu4Value);
EXTERN INT32 OSD_BASE_Get3DOsdShiftEn(UINT32 OSD_Plane, UINT32 *pu4Value);
EXTERN void OSD_PLA_WaitStable(UINT32 u4_plane);


typedef enum
{
    OSD_3D_NONE,
    OSD_3D_SBSHALF_PR,
    OSD_3D_TPANDBT_PR,
    OSD_3D_SBSHALF_SG,
    OSD_3D_TPANDBT_SG,
    OSD_3D_MAX
} OSD_3D_MODE_T;


#ifdef SYS_3D_SUPPORT

#ifndef CC_MTK_LOADER
extern INT32 OSD_PLA_Set3DFlip(UINT32 u4Plane, OSD_3D_MODE_T e3DMode, UINT32 u4Shift,
                               UINT32 u4BmpWidth, UINT32 u4BmpHeight, UINT32 u4BmpPitch,
                               UPTR u4BmpAddr, UINT32 eColorMode);

EXTERN INT32 OSD_PLA_Set3DBlit(UINT32 u4Plane, OSD_3D_MODE_T e3DMode, UINT32 u4Shift,
                               UINT32 u4BmpWidth, UINT32 u4BmpHeight, UINT32 u4BmpPitch,
                               UPTR u4DstAddr, UINT32 eColorMode, UINT32 u4SrcAddr);

EXTERN INT32 OSD_PLA_Redraw3D(OSD_3D_MODE_T e3DMode);
#endif

EXTERN void OSD_SC_ForceSize(BOOL fgForceSize);

#endif

EXTERN UINT32 OSD_Base_GetVsyncTime(void);

#ifndef CC_MTK_LOADER

#ifdef OSD_DSC_PDP

EXTERN INT32 OSD_PLA_DsBlit(UPTR u4SrcAddr, UINT32 u4SrcX, UINT32 u4SrcY, UINT32 u4SrcWidth,
                            UINT32 u4SrcHeight, UINT32 u4SrcPitch,
                            UPTR u4DstAddr, UINT32 u4DstX, UINT32 u4DstY, UINT32 u4DstWidth, UINT32 u4DstHeight,
                            UINT32 u4DstpPitch, UINT32 eColorMode);
#endif
#endif

EXTERN INT32 OSD_PLA_Set3DMode(UINT32 u4Plane, UINT8 u1Mode);
EXTERN INT32 OSD_PLA_Set3DRegion(UINT32 u4Plane, UINT32 u4LeftRgn,
                                 UINT32 u4RightRgn);
EXTERN BOOL OSD_BASE_Get_3DOSD2PLsEn(void);
EXTERN void OSD_BASE_Set_3DOSD2PLsEn(BOOL u4Enable);
EXTERN INT32 OSD_3D_SetOsd2LShiftEn(UINT32 u4Value);
EXTERN INT32 OSD_3D_SetOsd1LShiftEn(UINT32 u4Value);
EXTERN INT32 OSD_3D_SetOsd3LShiftEn(UINT32 u4Value);
EXTERN BOOL OSD_BASE_IsDisplaying(void);
EXTERN void vSetOsdFlipMirror(BOOL fgMirrorEn, BOOL fgFlipEn);
EXTERN INT32 OSD_3D_SetPlaneSwitch(UINT32 u4Enable);
#ifdef CC_ANDROID_3D_UI_SUPPORT


EXTERN UINT32 OSD_PLA_SetUIMode(UINT32 u4Mode, UINT32 u4WIdth, UINT32 u4Height);
EXTERN INT32 OSD_PLA_Set3DSwitchRegion(UINT32 u4LeftRgn, UINT32 u4RightRgn);
EXTERN INT32 OSD_PLA_Set3DSwitchRgnAddr(UINT32 u4LeftRgn, UINT32 u4RightRgn, UINT32 u4LeftAddr,
                                        UINT32 u4RightAddr);
EXTERN INT32 OSD_PLA_DsBlit(UPTR u4SrcAddr, UINT32 u4SrcX, UINT32 u4SrcY,
                            UINT32 u4SrcWidth, UINT32 u4SrcHeight, UINT32 u4SrcPitch,
                            UPTR u4DstAddr, UINT32 u4DstX, UINT32 u4DstY,
                            UINT32 u4DstWidth, UINT32 u4DstHeight, UINT32 u4DstpPitch, UINT32 eColorMode);

#endif

EXTERN UINT32 OSD_BASE_GetTranBuf_Current(void);
EXTERN UINT32 OSD_BASE_GetTranBuf_Back(void);
EXTERN INT32 OSD_BASE_SetFRCHeader(UINT32 u4SetCMD, UINT32 u4Value);
EXTERN INT32 OSD_BASE_SetTransferCtl(UINT32 u4Enable);
EXTERN INT32 OSD_BASE_GetTransferCtl(UINT32 *u4Enable);
EXTERN INT32 OSD_BASE_TransferTo(UPTR u4SrcAddr, UPTR u4DstAddr);
EXTERN INT32 OSD_BASE_COPY_FRCHeader(UPTR u4DstAddr);
EXTERN INT32 OSD_BASE_InitFRCHeader(void);
EXTERN INT32 OSD_BASE_GetFRCHeader(UINT32 u4SetCMD, UINT32 *u4Value);
EXTERN INT32 OSD_BASE_TransferTo_SYNC_Header(UINT32 u4Region);
EXTERN UINT32 _OSD_BASE_Get_SHUTTER_LR_FLAG(void);
EXTERN INT32 _OSD_RGN_GetRegionId(UPTR u4RegionAdress , UINT32 *pu4RegionId);

EXTERN UINT32 OSD_GetCpblty(UINT32 u4_type, UINT32 u4_idx);
EXTERN INT32 OSD_SetCpblty(UINT32 u4_type, UINT32 u4_idx, UINT32 u4_val);
EXTERN void  OSD_InitCpblty(void);

EXTERN void OSD_PLA_WaitStable(UINT32 u4_plane);
EXTERN INT32 OSD_PLA_SetPremulEn(UINT32 u4Plane, UINT32 u4Value);
EXTERN INT32 OSD_PLA_GetPremulEn(UINT32 u4Plane, UINT32 *pu4Value);
EXTERN INT32 OSD_BASE_SetScrnHStart(UINT32 u4_plane, UINT32 u4_value);
EXTERN INT32 OSD_BASE_SetScrnVStart(UINT32 u4_value);
EXTERN INT32 OSD_BASE_UpdateHwReg(void);

#if defined(LINUX_TURNKEY_SOLUTION) && !defined(OSD_INDEPENDENT_VERIFY)
EXTERN INT32 fb_osd_reupdate_bmp_addr(UINT32 u4_plane);
#endif
EXTERN INT32 OSD_SetFb3DCfg(UINT32 u4_plane, UINT32 u4_3d_mode, UINT32 u4_sync);

EXTERN void OSD_Reset_UnderFlow(void);
EXTERN UINT32 OSD_Base_Check_Abnormal_Status(void);
EXTERN void OSD_Reset_FSM_Step1(void);
EXTERN void OSD_Reset_FSM_Step2(void);
EXTERN void OSD_Base_Check_Underflow_Action(void);
EXTERN void OSD_Base_Reg_Isr(void);
EXTERN void OSD_Base_UnderFlow_Isr_Action(void);
EXTERN void OSD_Base_Check_Underflow_Isr_Action(void);
EXTERN void OSD_Set_Dbg_Info(UINT32 u4_idx, UINT32 u4_val);
EXTERN UINT32 OSD_Get_Dbg_Info(UINT32 u4_idx);
EXTERN UINT32 OSD_PLA_Get_Dec(UINT32 u4Plane);
EXTERN INT32 OSD_PLA_Get_En(UINT32 u4Plane);
EXTERN void OSD_PLA_Chg_Clock_Action(UINT32 u4_enable);
EXTERN VOID OSD_PLA_SetCropEnable(BOOL fgEnable);

EXTERN UINT32 OSD_SC_GetPlane(UINT32 u4_scaler);
EXTERN INT32 OSD_PLA_LineScalerShow(UINT32 u4Plane, UPTR u4BufferAddr, UINT32 u4SrcWidth,
                                    UINT32 u4SrcHeight, UINT32 u4SrcPitch, UINT32 u4DstX, UINT32 u4DstY,
                                    UINT32 u4DstWidth, UINT32 u4DstHeight, UINT32 u4ColorMode);

EXTERN BOOL OSD_BASE_SonyIsDisplaying(void);

EXTERN UINT32 OSD_PLA_GetScaler(UINT32 u4Plane);
EXTERN INT32 OSD_BASE_AdjustPlanePosition(UINT32 u4TopPlane, UINT32 u4MidPlane,
                                          UINT32 u4BotPlane, INT32 i4Position, UINT32 delay);
EXTERN void OSD_DrawSonyPattern(UINT8 *pu1Canvas, UINT32 u4Width, UINT32 u4Height,
                                UINT32 u4ColorMode, UINT32 u4BgColor);
EXTERN INT32 OSD_PLA_Get_Hw_RealBmpAddr(UINT32 u4Plane, UPTR *pupValue);
#ifdef CC_FASTBOOT_DRIVER_LOGO
EXTERN INT32 OSD_SetFastLogoPlane(void);
#endif
EXTERN INT32 OSD_Base_AdjustOSDPosition(INT32 i4Adjust);
EXTERN INT32 OSD_Base_AdjustOSDVPosition(INT32 i4Adjust);

EXTERN BOOL OSD_Base_Init_Status(void);

#ifdef CC_CONFIG_OSD_SBS
EXTERN INT32 OSD_PLA_Set3DDFB(UINT32 u4Plane, UINT32 e3DMode, UINT32 u4Shift,
                              UINT32 u4BmpWidth, UINT32 u4BmpHeight, UINT32 u4BmpPitch,
                              UPTR u4DstAddr, UINT32 eColorMode, UINT32 u4SrcAddr);
#endif

#if defined(__KERNEL__) && !defined(CC_UBOOT) && !defined(CONFIG_TV_DRV_VFY)
EXTERN UINT32 fb_osd_get_buffer_mode(UINT32 u4_plane);
EXTERN UINT32 fb_osd_get_dfb_addr(void);
EXTERN UINT32 fb_osd_get_dfb_size(void);
EXTERN UINT32 fb_osd_get_fb_addr(void);
EXTERN UINT32 fb_osd_get_fb_size(void);
#endif

UINT32 OSD_BASE_GetPlaneDisplayRatio(UINT32 u4Plane, UPTR u4ScalerBaseAddr);
VOID OSD_BASE_GetDisplayRatio(UINT32 *pu4Plane1Ratio, UINT32 *pu4Plane2Ratio,
                              UINT32 *pu4Plane3Ratio);

EXTERN void OSD_PLA_SetMatrixEnable(BOOL fgEnable);
EXTERN void OSD_PLA_SetMatrixAndOffset(const UINT16 *pwMatrix);
EXTERN UINT32 OSD_PLA_GetBaseAddr(UINT32 u4Plane);
#if defined(__KERNEL__) && !defined(CC_UBOOT) && !defined(CONFIG_TV_DRV_VFY)
EXTERN INT32 OSD_PLA_DumpBitmap(UINT32 plane, const CHAR *filePath);
EXTERN INT32 OSD_PLA_DumpInBitmap(UINT32 plane, const CHAR *filePath);
EXTERN VOID OSD_PLA_DumpTask(UINT32 u4Region);
EXTERN INT32 OSD_PLA_DumpTaskStart(UINT32 u4Plane, const CHAR *sDir, UINT32 u4Amount, UINT32 u4Period);
#endif

BOOL OSD_Base_Suspend_Status(void);
BOOL OSD_Get_ResumeStatus(void);
void OSD_Clear_ResumeStatus(void);
#if defined(CC_MT5886) || defined(CC_MT5863)
VOID OSD_MMU_Init(VOID);
INT32 OSD_MMU_Enable(UINT32 u4Plane, BOOL fgEnable);
INT32 OSD_MMU_GetEnable(UINT32 u4Plane, BOOL *fgEnable);
void OSD_MMU_ApplyEnable(void);
#elif defined(CC_MT5893) || defined(CC_MT5895)
INT32 OSD_M4U_Enable(UINT32 u4Plane, BOOL fgEnable);
INT32 OSD_M4U_GetEnable(UINT32 u4Plane, BOOL *fgEnable);
#endif

#if defined(CC_MT5893) || defined(CC_MT5895)
EXTERN INT32 OSD_BASE_SetOvlDLModeEnable(BOOL enable);
EXTERN UINT32 OSD_PLA_GetBaseReg(UINT32 u4Plane);
EXTERN INT32 OSD_PLA_SetBurst8Enable(UINT32 u4Plane, BOOL enable);
EXTERN INT32 OSD_PLA_SetBurst8FifoEnable(UINT32 u4Plane, BOOL enable);
EXTERN BOOL OSD_IsOstg2Display(void);
EXTERN BOOL OSD_IsDualOstgDisplay(void);
EXTERN INT32 OSD_PLA_DualOstgFlipTo(UINT32 u4Plane, INT32 region);
EXTERN void OSD_PLA_InitialInternalRgnList(void);
EXTERN UINT32 OSD_PLA_GetCurrentInternalRgnList(UINT32 u4Plane);
EXTERN VOID OSD_SetCropingSize(INT32 i4Width);
EXTERN BOOL OSD_PLA_GetCropEnable(VOID);


#endif

EXTERN void OSD_PLA_SetUltraEn(UINT32 u4Plane, UINT32 u4Enable);
EXTERN void OSD_PLA_SetUltraThdValue(UINT32 u4Plane, UINT8 u1ThdLow, UINT8 u1ThdHigh);
EXTERN void OSD_PLA_SetPreUltraThdValue(UINT32 u4Plane, UINT8 u1ThdValue);
EXTERN INT32 _OSD_PLA_SetHwReg(UINT32 u4Plane);

EXTERN void OSD_EXP_BypassEnable(UINT32 u4Plane, UINT32 u4BypEnable);
EXTERN void OSD_EXP_BypassApply(void);

#ifndef CC_MTK_LOADER
#ifdef CC_LOADER_LOGO_LONG_TIME
#define CHECK_OSD_INIT()    \
    do \
    { \
        if (!OSD_Base_Init_Status()) \
        { \
            OSD_SwInit(); \
        } \
    } while(0)

#else
#define CHECK_OSD_INIT()    \
    do \
    { \
        if (!OSD_Base_Init_Status()) \
        { \
            OSD_Init(); \
        } \
    } while(0)

#endif
#else
#define CHECK_OSD_INIT()
#endif

#endif //OSD_DRVIF_H

