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

#ifndef FB_MT53XX_H
#define FB_MT53XX_H

#define FB_INIT_BY_AP 1
#define FB_DBG 0
#define FB_PROF 0

#if FB_PROF
#undef FB_DBG
#define FB_DBG 1
#endif

#define FBIO_RECTFILL 0x4620
#define FBIO_COPYAREA 0x4621
#define FBIO_IMAGEBLIT 0x4622
#define FBIO_REGISTERBUFFER 0x4623
#define FBIO_UNREGISTERBUFFER 0x4624
#define FBIO_RECTFILLROP 0x4625
#define FBIO_COPYAREAROP 0x4626
#define FBIO_SET 0x4627
#define FBIO_PALETTE 0x4628
#define FBIO_GETIMAGEBUFFER 0x4629
#define FBIO_IMAGEBLITROP 0x462A
#define FBIO_FONTRENDER 0x462B
#define FBIO_SETBLITOPT 0x462c
//new function
#define FBIO_DRAWLINE 0x462D
#define FBIO_DRAWLINEROP 0x462E
#define FBIO_DRAWRECT 0x462F
#define FBIO_DRAWRECTROP 0x4632
#define FBIO_DRAWTEXT 0x4631
// For DirectFB user mode cmdque
#define FBIO_GFX_FLUSH 0x4640
#define FBIO_GFX_WAIT 0x4641

// For get /set plane order array to sync with m/w
#define FBIO_GET_PLANE_ORDER_ARRAY 0x4642
#define FBIO_SET_PLANE_ORDER_ARRAY 0x4643
#define FBIO_SET_OSD_PLANE_ORDER_ARRAY 0x4644
#define FBIO_GET 0x4645

// For DirectFB & FB share lock
#define FBIO_GFX_LOCK 0x4646
#define FBIO_GFX_UNLOCK 0x4647

#if FB_INIT_BY_AP
#define FBIO_INIT 0x4630
#endif
#if FB_DBG
#define FBIO_GETTIME 0x4630
#endif

#define MT53FB_SET_X 0
#define MT53FB_SET_Y 1
#define MT53FB_SET_W 2
#define MT53FB_SET_H 3
#define MT53FB_SET_VIRT_W 4
#define MT53FB_SET_VIRT_H 5	
#define MT53FB_SET_OFFSET_X 6
#define MT53FB_SET_OFFSET_Y 7
#define MT53FB_SET_BPP 8
#define MT53FB_SET_CM 9
#define MT53FB_SET_VISIBLE 10
#define MT53FB_SET_BASE 11
#define MT53FB_SET_PITCH 12
#define MT53FB_SET_ORDER 13
#define MT53FB_SET_OPACITY 14
#define MT53FB_SET_MIXSEL 15
#define MT53FB_SET_COLORKEYEN 16
#define MT53FB_SET_COLORKEY 17
#define MT53FB_SET_PLANE_ID 18


#define MT53FB_SET_MASK_X (1u << MT53FB_SET_X)
#define MT53FB_SET_MASK_Y (1u << MT53FB_SET_Y)
#define MT53FB_SET_MASK_W (1u << MT53FB_SET_W)
#define MT53FB_SET_MASK_H (1u << MT53FB_SET_H)
#define MT53FB_SET_MASK_VIRT_W (1u << MT53FB_SET_VIRT_W)
#define MT53FB_SET_MASK_VIRT_H (1u << MT53FB_SET_VIRT_H)
#define MT53FB_SET_MASK_OFFSET_X (1u << MT53FB_SET_OFFSET_X)
#define MT53FB_SET_MASK_OFFSET_Y (1u << MT53FB_SET_OFFSET_Y)
#define MT53FB_SET_MASK_BPP (1u << MT53FB_SET_BPP)
#define MT53FB_SET_MASK_CM (1u << MT53FB_SET_CM)
#define MT53FB_SET_MASK_VISIBLE (1u << MT53FB_SET_VISIBLE)
#define MT53FB_SET_MASK_BASE (1u << MT53FB_SET_BASE)
#define MT53FB_SET_MASK_PITCH (1u << MT53FB_SET_PITCH)
#define MT53FB_SET_MASK_ORDER (1u << MT53FB_SET_ORDER)
#define MT53FB_SET_MASK_OPACITY (1u << MT53FB_SET_OPACITY)
#define MT53FB_SET_MASK_MIXSEL (1u << MT53FB_SET_MIXSEL)
#define MT53FB_SET_MASK_COLORKEY (1u << MT53FB_SET_COLORKEY)
#define MT53FB_SET_MASK_COLORKEYEN (1u << MT53FB_SET_COLORKEYEN)
#define MT53FB_SET_MASK_PLANE_ID (1u << MT53FB_SET_PLANE_ID)

#define MT53FB_GET_PANEL_SIZE 0


//new feature
struct mt53fb_DrawLine
{
    unsigned short u2X1;
    unsigned short u2Y1;
    unsigned short u2X2;
    unsigned short u2Y2;
    unsigned short u2DstPitch;
    unsigned int            u4color;
    unsigned char* pu1DstBaseAddr;
    unsigned int             u4Bpp;
};

struct mt53fb_DrawLineRop
{
    unsigned short u2X1;
    unsigned short u2Y1;
    unsigned short u2X2;
    unsigned short u2Y2;
    unsigned short u2DstPitch;
    unsigned int   u4color;
    unsigned int   u4Rop;
    unsigned short u2Alpha;
    unsigned char* pu1DstBaseAddr;
    unsigned int             u4Bpp;
};

struct mt53fb_DrawRect {
    unsigned short                  u2DstX;
    unsigned short                  u2DstY;
    unsigned short                  u2DstPitch;
    // Rectangular's width and height
    unsigned short                  u2Width;
    unsigned short                  u2Height;
    // Destiniation paper
    unsigned char*                  pu1DstBaseAddr;
    // Color
    unsigned int	        	                u4Color;
    unsigned int			                    u4Bpp;
    unsigned int                            u4BoarderWidth;
};

struct mt53fb_DrawRectRop {
    unsigned short                  u2DstX;
    unsigned short                  u2DstY;
    unsigned short                  u2DstPitch;
    // Rectangular's width and height
    unsigned short                  u2Width;
    unsigned short                  u2Height;
    // Destiniation paper
    unsigned char*                  pu1DstBaseAddr;
    // Color
    unsigned int                             u4Color; 
    unsigned int			                    u4Alpha;    
    unsigned int 			                u4Rop;
    unsigned int			                    u4Bpp;    
    unsigned int                             u4BoarderWidth;
};

struct mt53fb_DrawText {
    unsigned short u2X;
    unsigned short u2Y;
    unsigned short u2Width;
    unsigned short u2Height;
    unsigned short u2DstPitch;
    unsigned char*          pTextArray;
    unsigned char*  pu1DstBaseAddr;
    unsigned int   u4Color;
    unsigned int   u4Alpha;
    unsigned int   u4Bpp;
};



//end new feature

struct mt53fb_imagebuffer
{
    unsigned int u4Size;
    unsigned int u4VirtAddr;
    unsigned int u4PhyAddr;
};

struct mt53fb_imageblit
{
    unsigned short       u2SrcX;
    unsigned short       u2SrcY;
    unsigned short       u2SrcPitch;
    unsigned short                  u2DstX;
    unsigned short                  u2DstY;
    unsigned short                  u2DstPitch;
    // Blitting area's width and height
    unsigned short                  u2Width;
    unsigned short                  u2Height;
    // Source paper
    unsigned char*                  pu1SrcBaseAddr;
    // Destination paper
    unsigned char*                  pu1DstBaseAddr;

    int			i4SrcBpp;   
    int			i4DstBpp;     
    
};

struct mt53fb_imageblitrop
{
    unsigned short                  u2SrcX;
    unsigned short                  u2SrcY;
    unsigned short                  u2SrcPitch;
    unsigned short                  u2DstX;
    unsigned short                  u2DstY;
    unsigned short                  u2DstPitch;
    // Blitting area's width and height
    unsigned short                  u2Width;
    unsigned short                  u2Height;
    // Source paper
    unsigned char*                  pu1SrcBaseAddr;
    // Destination paper
    unsigned char*                  pu1DstBaseAddr;
        
    int					 i4Alpha;
    int					 i4Rop;   
    
    int			i4SrcBpp;   
    int			i4DstBpp;      
    
    
};

struct mt53fb_fillrect {
    unsigned short                  u2DstX;
    unsigned short                  u2DstY;
    unsigned short                  u2DstPitch;
    // Rectangular's width and height
    unsigned short                  u2Width;
    unsigned short                  u2Height;
    // Destiniation paper
    unsigned char*                  pu1DstBaseAddr;
    // Color
    int			                  i4Color;

    int			i4Bpp;
    
};

struct mt53fb_fillrectrop {
    unsigned short                  u2DstX;
    unsigned short                  u2DstY;
    unsigned short                  u2DstPitch;
    // Rectangular's width and height
    unsigned short                  u2Width;
    unsigned short                  u2Height;
    // Destiniation paper
    unsigned char*                  pu1DstBaseAddr;
    // Color
    int                     i4Color;
       
    int			 i4Alpha;    
    int 		i4Rop;
   
    int			i4Bpp; 
};

struct mt53fb_copyarearop 
{
	unsigned int dx;
	unsigned int dy;
	unsigned int width;
	unsigned int height;
	unsigned int sx;
	unsigned int sy;
	unsigned int rop;	
	unsigned int alpha;
};

struct mt53fb_setting 
{
    unsigned int u4Pitch;
    unsigned int u1CM;	
    unsigned int u2X;
    unsigned int u2Y;
    unsigned int u2W;
    unsigned int u2H;   
    unsigned int u2OffsetX;
    unsigned int u2OffsetY;    
    unsigned int fgVisible;
    unsigned int u4Base;
    unsigned int u4Order;    
    unsigned int u4Opacity;        
    unsigned int u4MixSel;       
    unsigned int u4ColorKey;
    unsigned int u4ColorKeyEn;
    unsigned int u4OsdPlaneID;        
};   

struct mt53fb_set 
{
    struct mt53fb_setting rSetting;
    unsigned int mask;
};

struct mt53fb_get 
{
    unsigned int get_type;
    unsigned int get_size;
    unsigned int *get_data;
};

struct mt53fb_palette
{
    unsigned int plane_id;
    unsigned int palette[256];
};

typedef enum
{
    E_GFXLIB_SRC_X_ERR = 1000,
    E_GFXLIB_SRC_Y_ERR,
    E_GFXLIB_DST_X_ERR,
    E_GFXLIB_DST_Y_ERR,
    E_GFXLIB_WIDTH_ERR,
    E_GFXLIB_HEIGHT_ERR,
    E_GFXLIB_SRC_PITCH_ERR,
    E_GFXLIB_DST_PITCH_ERR,
    E_GFXLIB_SRC_ADDR_ERR,
    E_GFXLIB_DST_ADDR_ERR,
    E_GFXLIB_ROP_ERR,
    E_GFXLIB_PALE_ADDR_ERR,
    
    E_GFXLIB_SET_X_ERR,
    E_GFXLIB_SET_Y_ERR,
    E_GFXLIB_SET_WIDTH_ERR,
    E_GFXLIB_SET_HEIGHT_ERR,
    E_GFXLIB_SET_PITCH_ERR,
    E_GFXLIB_SET_BPP_ERR,    
    E_GFXLIB_SET_ADDR_ERR,
    E_GFXLIB_SET_COLORMODE_ERR,
    E_GFXLIB_SET_ENABLE_ERR,

    E_GFXLIB_ERR_MAX
} E_GFXLIB_T;

#endif /*__MT53_FB__*/
