/* Attempt at defining the ioctls used in the Hauppauge MVP Linux drivers
 * Use at your own risk
 * this is a work in progress - it's likely the definitions are confused and just plain wrong
 * Bob the Builder May 2004
 */


#ifndef _STBx25xx_H
#define _STBx25xx_H
#include <sys/ioctl.h>
#include <stdint.h>
#include <linux/fb.h>



typedef enum {
	        AUDIO_SOURCE_DEMUX, /* Select the demux as the main source */
	        AUDIO_SOURCE_MEMORY /* Select internal memory as the main source */
} audio_stream_source_t;

typedef enum {
	        AUDIO_STOPPED,      /* Device is stopped */
	        AUDIO_PLAYING,      /* Device is currently playing */
	        AUDIO_PAUSED        /* Device is paused */
} audio_play_state_t;


// needs clarification /testing
struct vid_regs {
   unsigned char dummy[44];
};

// needs clarification /testing
typedef struct {
 uint64_t stc;
 uint64_t pts;
} sync_data_t;

typedef struct {
	int arg;
	int a;
	int b;
	int c;
	int d;
	int e;
	int f;
} set_display_t;

typedef struct {
	unsigned long handle;
	unsigned long x;
	unsigned long y;
	unsigned long w;
	unsigned long h;
	unsigned long colour;
} osd_fillblt_t;

typedef struct {
	unsigned long handle1;
	unsigned long x;
	unsigned long y;
	unsigned long w;
	unsigned long h;
	unsigned long handle2;
	unsigned long x1;
	unsigned long y1;
	unsigned long w1;
	unsigned long h1;
	unsigned long colour1;
} osd_blend_t;

typedef struct {
	unsigned long handle;
	unsigned long x;
	unsigned long y;
	unsigned long w;
	unsigned long h;
	unsigned long colour1;
	unsigned long colour2;
	unsigned long colour3;
	unsigned long colour4;
	unsigned long colour5;
	unsigned long colour6;
	unsigned long colour7;
	unsigned char c[2];
} osd_afillblt_t;

typedef struct { // 41 bytes
	unsigned long dst_handle;
	unsigned long dst_x;
	unsigned long dst_y;
	unsigned long dst_w;
	unsigned long dst_h;
	unsigned long src_handle;
	unsigned long src_x;
	unsigned long src_y;
	unsigned long u1;
	unsigned long u2;
	unsigned char u3;
} osd_bitblt_t;

unsigned long r1;

typedef struct {
	unsigned long handle;
	unsigned long left;
	unsigned long top;
	unsigned long right;
	unsigned long bottom;
} osd_clip_rec_t;

typedef struct {
	unsigned int channels;
	unsigned int bits;
	unsigned int samples;
	unsigned int signage;
	unsigned int endian;
} mixer_t;

// needs clarification /testing
typedef struct {
	int nleft;
	int state;
} vid_state_regs_t;

// needs clarification /testing
typedef struct {
	int parm1;
	int parm2;
} vid_sync_parms_t;

// needs clarification /testing
typedef struct {
	int parm1;
	int parm2;
} aud_sync_parms_t;

// needs clarification /testing
typedef struct {
	int w;
	int h;
	int scale;
	int x1;
	int y1;
	int x2;
	int y2;
	int x3;
	int y3;
	int x4;
	int y4;
} vid_pos_regs_t;

// needs clarification /testing
typedef struct {
	int aud_ctl0;
	int aud_ctl1;
	int aud_ctl2;
} aud_ctl_regs_t;

// needs clarification /testing
typedef struct {
	int denc0_cr1;
	int denc1_cr1;
	int dencmux;
	int vid_disp_mode;
} vid_ctl_regs_t;

/*
 * The following describes the TV layout (I think)
 */
typedef struct {  //size should be 0x18 
   unsigned long handle; // Surface gHandle
   unsigned long width;  // Surface Width
   unsigned long height; // Surface Height
   unsigned long flags; 
   unsigned long u0; // 
   unsigned long depth; // number of subplanes
} stbgfx_win_t;

/*
 * The following describes a drawing surface
 */
typedef struct {  //size should be 0x18 
   unsigned long handle; // Surface gHandle
   unsigned long width;  // Surface Width
   unsigned long height; // Surface Height
   unsigned long flags; // need detail somehow  
   unsigned long u0; //  not really sure yet
   unsigned long depth; // number of subplanes , probably wrong ?
} stbgfx_sfc_t;

/*
 * The following describes the layout of /dev/stbgfx so that it can be
 * properly mmap'd (I think)
 */
typedef struct {
    unsigned long unknown;
    unsigned long win_unknown;
    unsigned long addr;
    unsigned long size;
    unsigned long unknown2;
    unsigned long width;
    unsigned long height;
    unsigned long unknown3;
    unsigned long unknown4;
    unsigned long width2;
    unsigned long unknown5;
    unsigned long unknown6;
} stbgfx_map_item_t;

typedef struct {
       stbgfx_map_item_t map[3];
       unsigned long other[2];
} stbgfx_map_t;

/*
 * The following describes the STBGFX display size (I think) 0x1d bytes ?
 */
typedef struct {
  unsigned long handle;
  unsigned long unknown[4];
  unsigned long width;
  unsigned long height;
  char unknown2;
} stbgfx_display_t;


/*
 * ioctl commands for the adec_mpg, vdec_dev, and stbgfx devices
 *
 * The names are educated guesses, so they may need to change...
 */

/* Audio decoder */
#define AV_SET_AUD_STOP         _IOW('a',1,int)
#define AV_SET_AUD_PLAY         _IOW('a',2,int)
#define AV_SET_AUD_PAUSE        _IOW('a',3,int)
#define AV_SET_AUD_CONTINUE     _IOW('a',4,int)
#define AV_SET_AUD_SRC          _IOW('a',5,int) // 0 or 1 valid , maybe 0xffff as well
#define AV_SET_AUD_MUTE         _IOW('a',6,int)
#define AV_SET_AUD_SYNC         _IOW('a',7,int)
#define AV_SET_AUD_BYPASS       _IOW('a',8,int) // not in this driver ?
#define AV_SET_AUD_CHANNEL      _IOW('a',9,int)  // What is this ???
#define AV_SET_AUD_GET_STATUS   _IOR('a',10,int)
#define AV_SET_AUD_VOLUME       _IOW('a',13,int)
						// either audio device or mixer device
#define AV_GET_AUD_VOLUME       _IOR('a',14,int)
#define AV_SET_AUD_STREAMTYPE   _IOW('a',15,int) // NOT mixer device - only audio device
						// 0,1,2,3 valid
#define AV_SET_AUD_FORMAT       _IOW('a',16,mixer_t *) // for mixer device
						// or for pcm device
						// mpeg or PCM 0,1,2,3 ?
#define AV_GET_AUD_SYNC	        _IOR('a',21,sync_data_t *)
#define AV_SET_AUD_STC	        _IOW('a',22,uint64_t *)
#define AV_SET_AUD_ENABLE_SYNC  _IOW('a',23,int) //aud_sync_parms_t *) set sync master ?
#define AV_SET_AUD_DISABLE_SYNC _IOW('a',24,aud_sync_parms_t *)
#define AV_RESET_AUD_END_STREAM _IOW('a',25,int)
#define AV_RESET_AUD_BUF        _IOW('a',26,int)
#define AV_SET_AUD_DAC_CLK      _IOW('a',27,int)
#define AV_DUMP_AUD_REGS        _IOW('a',28,aud_ctl_regs_t *)

/* Video Decoder */
#define AV_SET_VID_PLAY         _IOW('v',22,int)
#define AV_SET_VID_FREEZE       _IOW('v',23,int)
#define AV_SET_VID_RESUME       _IOW('v',24,int)
#define AV_SET_VID_SRC          _IOW('v',25,int)
#define AV_SET_VID_FB           _IOW('v',26,int)
#define AV_GET_VID_STATE        _IOR('v',27,vid_state_regs_t *)
#define AV_SET_VID_PAUSE        _IOW('v',28,int)
#define AV_SET_VID_FFWD         _IOW('v',29,int)
#define AV_SET_VID_SLOMO        _IOW('v',30,int)
#define AV_SET_VID_BLANK        _IOW('v',32,int)
#define AV_SET_VID_POSITION     _IOW('v',36,vid_pos_regs_t *) // set the position of the video on screen 11 ints ?
#define AV_SET_VID_SCALE_ON     _IOW('v',37,int)
#define AV_SET_VID_SCALE_OFF    _IOW('v',38,int)
#define AV_GET_VID_SYNC		_IOR('v',39,int)
#define AV_SET_VID_STC	        _IOW('v',40,uint64_t *)
#define AV_SET_VID_RATIO        _IOW('v',41,int)
#define AV_SET_VID_ENABLE_SYNC  _IOW('v',42,int) //vid_sync_parms_t *) 
#define AV_SET_VID_DISABLE_SYNC _IOW('v',43,int) //vid_sync_parms_t *)
#define AV_SET_VID_DISP_FMT     _IOW('v',45,int) // 0 or 1
#define AV_RESET_VID_BUF        _IOW('v',51,int)
#define AV_SET_VID_OUTPUT       _IOW('v',57,int)
#define AV_SET_VID_MODE         _IOW('v',58,int) // set display mode
#define AV_DUMP_VID_REGS        _IOW('v',61,struct vid_regs)
#define AV_SET_VID_COLOURBAR    _IOW('v',62,int)
#define AV_SET_DENC             _IOW('v',63,int)
#define AV_CHK_SCART            _IOW('v',64,int *)

/* Screen Device */
#define AV_GET_VID_INFO         _IOR('s',44,int)

/* Infra Red Receiver */
#define IR_SET_LED              _IOW('i',21,int)

/* Frame Buffer */
#define GFX_FB_SFC_ALLOC        _IOWR(0xfb,1,int *) //create surface 0x18 bytes ptr
#define GFX_FB_SFC_FREE         _IOWR(0xfb,2,int *) //free surface 0x18 bytes ptr
#define GFX_FB_SFC_MAP          _IOWR(0xfb,3,int *) //lock surface 0x04 bytes ptr
#define GFX_FB_SFC_UNMAP        _IOWR(0xfb,4,int *) //unlock surface 0x04 bytes ptr
#define GFX_FB_SET_PAL_1        _IOWR(0xfb,5,int *)
#define GFX_FB_SET_PAL_2        _IOW(0xfb,6,int *)
#define GFX_FB_SFC_GET_SHARE    _IO(0xfb,7) // get shared
#define GFX_FB_SFC_SET_SHARE    _IOW(0xfb,8,int)
#define GFX_FB_OSD_CUR_SETATTR  _IOW(0xfb,9,int *) // 12 bytes ?	
#define GFX_FB_SFC_ATTACH       _IOW(0xfb,11,int *) //attach surface
#define GFX_FB_SFC_DETACH       _IOW(0xfb,12,int *) //detach surface
#define GFX_FB_SFC_GETDISP      _IOWR(0xfb,13,int *) //get surface display parm
#define GFX_FB_SFC_SETDISP      _IOW(0xfb,14,int *)  //set surface display parm 0x1d bytes
#define GFX_FB_OSD_CUR_MOVE_1   _IOW(0xfb,15,int *) // 8 bytes ?
#define GFX_FB_OSD_CUR_MOVE_2   _IOW(0xfb,16,int)
#define GFX_FB_SET_SCR_INFO     _IOW(0xfb,18,int *) //set screen info ,16bytes
#define GFX_FB_SET_DISP_CTRL    _IOW(0xfb,21,int *) // 8 bytes
#define GFX_FB_GET_DISP_CTRL    _IOWR(0xfb,22,int *) // 8 bytes
#define GFX_FB_SET_VIS_DEV_CTL	_IOW(0xfb,23,int *) // 12 bytes
#define GFX_FB_GET_VIS_DEV_CTL	_IOWR(0xfb,24,int *) //12 bytes
#define GFX_FB_OSD_BITBLT	_IOW(0xfb,51,osd_bitblt_t *) // structure 41 bytes ,
#define GFX_FB_OSD_FILLBLT	_IOW(0xfb,53,osd_fillblt_t *) // structure 24 bytes ,
#define GFX_FB_OSD_ADVFILLBLT	_IOW(0xfb,54,osd_afillblt_t *) // structure 50 bytes
#define GFX_FB_OSD_BLEND	_IOW(0xfb,55,int *) // structure 44 bytes
#define GFX_FB_OSD_ADVBLEND	_IOW(0xfb,56,int *) // structure 56 bytes
#define GFX_FB_OSD_RESIZE	_IOW(0xfb,58,int *) // 0x2A bytes , 
#define GFX_FB_ENGINE_WAIT	_IOW(0xfb,60,int)
#define GFX_FB_RESET_ENGINE	_IO(0xfb,61)
#define GFX_FB_SET_ENGINE_MODE	_IOW(0xfb,62,int)
#define GFX_FB_GET_ENGINE_MODE	_IO (0xfb,63)
#define GFX_FB_GET_SFC_INFO	_IOWR(0xfb,64,int *) // get surface info ?? 0x98 bytes , 38 unsigned longs
#define GFX_FB_SET_SFC_CLIP_REC	_IOWR(0xfb,65,int *) //20bytes
#define GFX_FB_OSD_COLOURKEY	_IOW(0xfb,67,int *) // 0x38 bytes
#define GFX_FB_GET_SFC_PSEUDO	_IOWR(0xfb,68,int *) //20bytes , not implemented

#endif

