/*
 *
 * Copyright (C) 2012, Samsung Electronics Co., Ltd.
 *
 * TUI HAL header file
 */

#ifndef TUIHAL_H_
#define TUIHAL_H_

#include <tee_internal_api.h>

/**
 * Driver fatal error codes.
 */
#define E_TUI_HAL_BAD_PARAMETERS  ((TEE_Result) 2) /**< Bad parameters */
#define E_TUI_HAL_BUSY            ((TEE_Result) 3) /**< Error peripheral is Busy */
#define E_TUI_HAL_IO              ((TEE_Result) 4) /**< IO error */
#define E_TUI_HAL_NO_MEMORY       ((TEE_Result) 5) /**< Error no memory available */
#define E_TUI_HAL_MAP             ((TEE_Result) 6) /**< Error no memory available */

#define DISP_IOCTL_SET_FB         0x10
#define DISP_IOCTL_RELEASE_FB     0x11
#define DISP_IOCTL_GET_INFO       0x12
#define DISP_IOCTL_UPDATE         0x13
#define TOUCH_IOCTL_CANCEL_READ   0x10
#define TOUCH_IOCTL_SET_INFO      0x11
#define TOUCH_IOCTL_SET_TIMEOUT   0x12
#define TOUCH_IOCTL_GET_DATA      0x13
#define TOUCH_WAIT_TIMEOUT_MS     10000

#define MT_INFO_MAX_EVENT         10

#define TSP_TYPE_SLSI             0x00
#define TSP_TYPE_ILITEK           0x01
#define TSP_TYPE_NOVATEK          0x02
#define TSP_TYPE_MELFAS           0x03
#define TSP_TYPE_STM              0x04
#define TSP_TYPE_ZINITIX          0x05
#define TSP_TYPE_SNAPTICS         0x06
#define TSP_TYPE_GOODIX           0x07
#define TSP_TYPE_FOCALTECH        0x08
#define TSP_TYPE_HIMAX            0x09

#define STUI_DISPLAY_INFO_SIZE    10

/////////////////////////////////////////////////////
/////////              Board                /////////
/////////////////////////////////////////////////////

/* Initialize board info */
TEE_Result tuiHalBoardInit(void);

/////////////////////////////////////////////////////
/////////              Touch                /////////
/////////////////////////////////////////////////////

enum tui_ts_event
{
    tui_ts_release = 0,
    tui_ts_press   = 1,
    tui_ts_update  = 2,
};

typedef struct touch_info
{
    uint8_t   n_finger;
    uint8_t   ev_type;
    uint16_t  x;
    uint16_t  y;
} __attribute__ ((packed)) touch_info_t;

typedef struct mt_touch_info
{
    uint8_t      num;
    touch_info_t buf[MT_INFO_MAX_EVENT];
} __attribute__ ((packed)) mt_touch_info_t;

typedef struct
{
    uint32_t    width;
    uint32_t    height;
} drTouchInfo_t, *drTouchInfo_ptr;

TEE_Result tuiHalTouchGetInfo(drTouchInfo_ptr touchSize);
TEE_Result tuiHalTouchOpen(uint32_t width, uint32_t heiht, uint32_t touch_type);
TEE_Result tuiHalTouchClose(void);
TEE_Result tuiHalTouchProcess(void);


///////////////////////////////////////////////////////
//////////         FRAMEBUFFER               //////////
///////////////////////////////////////////////////////

typedef struct
{
    uint32_t width;            /* IN  */
    uint32_t height;           /* IN  */
    uint64_t physicalFb;       /* IN  */
    uint64_t physicalFbLen;    /* IN  */
    uint64_t virtualFb;        /* OUT */
    uint64_t physicalWb;       /* IN  */
    uint64_t physicalWbLen;    /* IN  */
    uint64_t virtualWb;        /* OUT */
    uint64_t physicaldisp;     /* IN  */
    uint64_t physicaldispLen;  /* IN  */
    uint64_t lcd_info[STUI_DISPLAY_INFO_SIZE]; /* IN  */
    uint32_t displayIf;        /* IN  */
} tuiDisplayBuffer_t;


///////////////////////////////////////////////////////
//////////           DISPLAY                 //////////
///////////////////////////////////////////////////////

typedef struct
{
    uint32_t grayscaleBitsDepth;  /* Available grayscale depth */
    uint32_t redBitsDepth;        /* Available Red bit depth */
    uint32_t greenBitsDepth;      /* Available Green bit depth */
    uint32_t blueBitsDepth;       /* Available Blue bit depth */
    uint32_t width;               /* LCD Width in pixels */
    uint32_t height;              /* LCD Height in pixels */
    uint32_t wDensity;            /* Width in pixels per inch */
    uint32_t hDensity;            /* Height in pixels per inch */
    uint32_t lcdOrientation;      /* Physical LCD orientation: 0 - portrait, 1 - landscape */
    uint32_t bpp;                 /* Bits per pixel */
} tuiScreenInfo_t, *tuiScreenInfo_ptr;

typedef struct
{
    uint32_t cmd_size;
    tuiDisplayBuffer_t fb;
} ioctl_fbset_t;

typedef struct
{
    uint32_t cmd_size;
    tuiScreenInfo_t info;
} ioctl_getinfo_t;

typedef struct
{
    uint32_t cmd_size;
    uint32_t fb_index;
} ioctl_update_t;

typedef struct
{
    uint32_t cmd_size;
    uint32_t width;
    uint32_t height;
    uint32_t touch_type;
} ioctl_range_t;

/* Protect display controller */
TEE_Result tuiHalDisplayProtectController(void);

/* Unprotect display controller */
TEE_Result tuiHalDisplayUnprotectController(void);

/* Protect display framebuffer */
TEE_Result tuiHalDisplayProtectFramebuffer(void);

/* Unprotect display framebuffer */
TEE_Result tuiHalDisplayUnprotectFramebuffer(void);

/* Map the video controller registers into the driver address space */
TEE_Result tuiHalDisplayMapController(void);

/* Unmap the video controller registers from the driver address space */
TEE_Result tuiHalDisplayUnMapController(void);

/*
 *  Protect display controller and TUI frame buffer
 *  Configure display controller registers
 *  Map TUI frame buffer to driver's memory
 */
TEE_Result tuiHalDisplayInitialize(tuiDisplayBuffer_t *fb);

/* Reset display config and unmap frame buffer */
TEE_Result tuiHalDisplayUninitialize(void);


///////////////////////////////////////////////////////
//////////         WORKBUFFER                //////////
///////////////////////////////////////////////////////

void *tuiHalWBGetVaddr(void);
unsigned int tuiHalWBGetSize(void);

#endif /* TUIHAL_H_ */
