/*
 * Copyright 2010 Trident Microsystems (Far East) Ltd. All rights reserved.
 * All prior copyright rights in this work and the accompanying software
 * products transferred to Trident Microsystems (Far East) Ltd. by written
 * agreement.
 */
/*****************************************************************************/
/* Copyright (c) 2010 NXP B.V.  All rights are 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 NXP 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      */
/* OWNER 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.                                                                   */
/*                                                                           */
/*****************************************************************************/
/**
    @file           phStbDraw.h
    @brief          Linux kernel module for 2D graphics hardware accelleration

    @b  Component:  phStbDraw

*//*

Rev Date        Author      Comments
--------------------------------------------------------------------------------
  1 20060925    neill       Port from STB810 original
  2 20070904    neill       Add hardware version ioctl
  3 20080207    batelaan    Update file copyright/license text
  4 20081111    steel       add stretch blit.
  5 20090106    neill       add triangle fill and rectangle draw.
  6 20090120    batelaan    Update file copyright/license text
  7 20090123    steel       add cache flushing
*/

#ifndef __PHSTBDRAW_H__
#define __PHSTBDRAW_H__

#include <asm/types.h>

#include <ph833xCore.h>

#define PNXDRAW_HEADER_SETUP_DESTINATION     0x01
#define PNXDRAW_HEADER_SETUP_SOURCE          0x02
#define PNXDRAW_HEADER_SETUP_KEY             0x03
#define PNXDRAW_HEADER_EXECUTE_FILL          0x11
#define PNXDRAW_HEADER_EXECUTE_BLIT          0x12
#define PNXDRAW_HEADER_EXECUTE_BLIT_BLEND    0x13
#define PNXDRAW_HEADER_EXECUTE_STRETCH_BLIT  0x14
#define PNXDRAW_HEADER_EXECUTE_TRIANGLE      0x15
#define PNXDRAW_HEADER_EXECUTE_RECTANGLE     0x16

/**
 * Shift X and Y into correct locations for the drawing engine registers
 */
#define PNXDRAW_XY(x,y) (x) | ((y) << 16)

#define PNXDRAW_X(value) ((value)&0xFFFF)
#define PNXDRAW_Y(value) ((value)>>16)

/**
 * Shift Width and Height into correct locations for the drawing engine
 * registers
 */
#define PNXDRAW_WH(w,h) (w) | ((h) << 16)

#define PNXDRAW_W(value) ((value)&0xFFFF)
#define PNXDRAW_H(value) ((value)>>16)

typedef volatile struct {
     __u32                    addr;
     __u32                    stride;
     __u32                    psize;
} PNXDrawSetupDestination_t;


typedef volatile struct {
     __u32                    addr;
     __u32                    stride;
} PNXDrawSetupSource_t;


typedef volatile struct {
     __u32                    cccolor;
     __u32                    transmask;
} PNXDrawSetupKey_t;


typedef volatile struct {
     __u32                    bltctl;
     __u32                    color;

     __u32                    xy;
     __u32                    size;
} PNXDrawExecuteFill_t;


typedef volatile struct {
     __u32                    bltctl;

     __u32                    srcxy;
     __u32                    dstxy;
     __u32                    size;
} PNXDrawExecuteBlit_t;

typedef volatile struct {
     __u32                    bltctl;
     __u32                    color;

     __u32                    xy[3];
} PNXDrawExecuteTriangle_t;

typedef volatile struct {
     __u32                    bltctl;
     __u32                    color;

     __u32                    xy;
     __u32                    size;
} PNXDrawExecuteRectangle_t;

typedef volatile struct {
     __u32                    bltctl;

     __u32                    color;

     __u32                    srcxy;
     __u32                    dstxy;
     __u32                    size;
} PNXDrawExecuteBlitBlend_t;

typedef volatile struct {
     __u32                    bltctl;

     __u32                    color;
     __u32                    srcxy;
     __u32                    dstxy;
     __u32                    srcsize;
     __u32                    dstsize;
} PNXDrawExecuteStretchBlit_t;


typedef volatile struct {
     __u32                    header;
     union {
         PNXDrawSetupDestination_t   dest;
         PNXDrawSetupSource_t        source;
         PNXDrawSetupKey_t           key;

         PNXDrawExecuteFill_t        fill;
         PNXDrawExecuteRectangle_t   rectangle;
         PNXDrawExecuteTriangle_t    triangle;
         PNXDrawExecuteBlit_t        blit;
         PNXDrawExecuteBlitBlend_t   blit_blend;
         PNXDrawExecuteStretchBlit_t stretch_blit;
     } data;
} PNXDrawPacket_t;

typedef volatile struct {
     __u32                    addr;
     __u32                    size;
} PNXDrawCacheFlush_t;


/** Packet Processing is inactive */
#define PNXDRAW_STATE_INACTIVE 0x00000000
/** Packets are being processed */
#define PNXDRAW_STATE_ACTIVE   0x00000001

/** Maximum number of packets in the ring buffer */
#define PNXDRAW_NUM_PACKETS   (130)

typedef volatile struct {
    /** State of packet processing operations */
    __u32           state;

    /** Next packet to be read by the device  */
    __u32           readIndex;
    /** Next packet to be written by the user */
    __u32           writeIndex;

    PNXDrawPacket_t packets[PNXDRAW_NUM_PACKETS];
} PNXDrawSharedArea_t;

/** Size of the ring buffer data */
#define PNXDRAW_SHARED_SIZE    sizeof(PNXDrawSharedArea_t)
/** Page aligned size of the ring buffer */
#define PNXDRAW_SHARED_SIZE_PA PAGE_ALIGN(PNXDRAW_SHARED_SIZE)

/* IOCTLs that can be performed on the draw device */

/**
 * Reset the drawing engine and the packet ring buffer
 */
#define PNXDRAW_IOCTL_RESET        _IO( 'D', 0)

/**
 * Continue/Start processing packets from the ring buffer.
 */
#define PNXDRAW_IOCTL_CONTINUE     _IO( 'D', 1)

/**
 * Wait until the drawing engine is idle.
 */
#define PNXDRAW_IOCTL_WAITIDLE     _IO( 'D', 2)

/**
 * Get the hardware version.
 */
#define PNXDRAW_IOCTL_GET_HW_VERSION _IOR( 'D', 3, ph833xCore_hwVersion *)

/**
 * Wait until the drawing engine is idle, then invalidate the cache
 */
#define PNXDRAW_IOCTL_CACHE_FLUSH    _IOW( 'D', 4, PNXDrawCacheFlush_t *)

#endif

