linux/drivers/staging/go7007/go7007-priv.h
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2005-2006 Micronas USA Inc.
   3 *
   4 * This program is free software; you can redistribute it and/or modify
   5 * it under the terms of the GNU General Public License (Version 2) as
   6 * published by the Free Software Foundation.
   7 *
   8 * This program is distributed in the hope that it will be useful,
   9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11 * GNU General Public License for more details.
  12 *
  13 * You should have received a copy of the GNU General Public License
  14 * along with this program; if not, write to the Free Software Foundation,
  15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  16 */
  17
  18/*
  19 * This is the private include file for the go7007 driver.  It should not
  20 * be included by anybody but the driver itself, and especially not by
  21 * user-space applications.
  22 */
  23
  24struct go7007;
  25
  26/* IDs to activate board-specific support code */
  27#define GO7007_BOARDID_MATRIX_II        0
  28#define GO7007_BOARDID_MATRIX_RELOAD    1
  29#define GO7007_BOARDID_STAR_TREK        2
  30#define GO7007_BOARDID_PCI_VOYAGER      3
  31#define GO7007_BOARDID_XMEN             4
  32#define GO7007_BOARDID_XMEN_II          5
  33#define GO7007_BOARDID_XMEN_III         6
  34#define GO7007_BOARDID_MATRIX_REV       7
  35#define GO7007_BOARDID_PX_M402U         16
  36#define GO7007_BOARDID_PX_TV402U_ANY    17 /* need to check tuner model */
  37#define GO7007_BOARDID_PX_TV402U_NA     18 /* detected NTSC tuner */
  38#define GO7007_BOARDID_PX_TV402U_EU     19 /* detected PAL tuner */
  39#define GO7007_BOARDID_PX_TV402U_JP     20 /* detected NTSC-J tuner */
  40#define GO7007_BOARDID_LIFEVIEW_LR192   21 /* TV Walker Ultra */
  41#define GO7007_BOARDID_ENDURA           22
  42#define GO7007_BOARDID_ADLINK_MPG24     23
  43#define GO7007_BOARDID_SENSORAY_2250    24 /* Sensoray 2250/2251 */
  44
  45/* Various characteristics of each board */
  46#define GO7007_BOARD_HAS_AUDIO          (1<<0)
  47#define GO7007_BOARD_USE_ONBOARD_I2C    (1<<1)
  48#define GO7007_BOARD_HAS_TUNER          (1<<2)
  49
  50/* Characteristics of sensor devices */
  51#define GO7007_SENSOR_VALID_POLAR       (1<<0)
  52#define GO7007_SENSOR_HREF_POLAR        (1<<1)
  53#define GO7007_SENSOR_VREF_POLAR        (1<<2)
  54#define GO7007_SENSOR_FIELD_ID_POLAR    (1<<3)
  55#define GO7007_SENSOR_BIT_WIDTH         (1<<4)
  56#define GO7007_SENSOR_VALID_ENABLE      (1<<5)
  57#define GO7007_SENSOR_656               (1<<6)
  58#define GO7007_SENSOR_CONFIG_MASK       0x7f
  59#define GO7007_SENSOR_TV                (1<<7)
  60#define GO7007_SENSOR_VBI               (1<<8)
  61#define GO7007_SENSOR_SCALING           (1<<9)
  62
  63/* Characteristics of audio sensor devices */
  64#define GO7007_AUDIO_I2S_MODE_1         (1)
  65#define GO7007_AUDIO_I2S_MODE_2         (2)
  66#define GO7007_AUDIO_I2S_MODE_3         (3)
  67#define GO7007_AUDIO_BCLK_POLAR         (1<<2)
  68#define GO7007_AUDIO_WORD_14            (14<<4)
  69#define GO7007_AUDIO_WORD_16            (16<<4)
  70#define GO7007_AUDIO_ONE_CHANNEL        (1<<11)
  71#define GO7007_AUDIO_I2S_MASTER         (1<<16)
  72#define GO7007_AUDIO_OKI_MODE           (1<<17)
  73
  74struct go7007_board_info {
  75        char *firmware;
  76        unsigned int flags;
  77        int hpi_buffer_cap;
  78        unsigned int sensor_flags;
  79        int sensor_width;
  80        int sensor_height;
  81        int sensor_framerate;
  82        int sensor_h_offset;
  83        int sensor_v_offset;
  84        unsigned int audio_flags;
  85        int audio_rate;
  86        int audio_bclk_div;
  87        int audio_main_div;
  88        int num_i2c_devs;
  89        struct {
  90                const char *type;
  91                int id;
  92                int addr;
  93        } i2c_devs[4];
  94        int num_inputs;
  95        struct {
  96                int video_input;
  97                int audio_input;
  98                char *name;
  99        } inputs[4];
 100};
 101
 102struct go7007_hpi_ops {
 103        int (*interface_reset)(struct go7007 *go);
 104        int (*write_interrupt)(struct go7007 *go, int addr, int data);
 105        int (*read_interrupt)(struct go7007 *go);
 106        int (*stream_start)(struct go7007 *go);
 107        int (*stream_stop)(struct go7007 *go);
 108        int (*send_firmware)(struct go7007 *go, u8 *data, int len);
 109        int (*send_command)(struct go7007 *go, unsigned int cmd, void *arg);
 110};
 111
 112/* The video buffer size must be a multiple of PAGE_SIZE */
 113#define GO7007_BUF_PAGES        (128 * 1024 / PAGE_SIZE)
 114#define GO7007_BUF_SIZE         (GO7007_BUF_PAGES << PAGE_SHIFT)
 115
 116struct go7007_buffer {
 117        struct go7007 *go; /* Reverse reference for VMA ops */
 118        int index; /* Reverse reference for DQBUF */
 119        enum { BUF_STATE_IDLE, BUF_STATE_QUEUED, BUF_STATE_DONE } state;
 120        u32 seq;
 121        struct timeval timestamp;
 122        struct list_head stream;
 123        struct page *pages[GO7007_BUF_PAGES + 1]; /* extra for straddling */
 124        unsigned long user_addr;
 125        unsigned int page_count;
 126        unsigned int offset;
 127        unsigned int bytesused;
 128        unsigned int frame_offset;
 129        u32 modet_active;
 130        int mapped;
 131};
 132
 133struct go7007_file {
 134        struct go7007 *go;
 135        struct mutex lock;
 136        int buf_count;
 137        struct go7007_buffer *bufs;
 138};
 139
 140#define GO7007_FORMAT_MJPEG     0
 141#define GO7007_FORMAT_MPEG4     1
 142#define GO7007_FORMAT_MPEG1     2
 143#define GO7007_FORMAT_MPEG2     3
 144#define GO7007_FORMAT_H263      4
 145
 146#define GO7007_RATIO_1_1        0
 147#define GO7007_RATIO_4_3        1
 148#define GO7007_RATIO_16_9       2
 149
 150enum go7007_parser_state {
 151        STATE_DATA,
 152        STATE_00,
 153        STATE_00_00,
 154        STATE_00_00_01,
 155        STATE_FF,
 156        STATE_VBI_LEN_A,
 157        STATE_VBI_LEN_B,
 158        STATE_MODET_MAP,
 159        STATE_UNPARSED,
 160};
 161
 162struct go7007 {
 163        struct device *dev;
 164        struct go7007_board_info *board_info;
 165        unsigned int board_id;
 166        int tuner_type;
 167        int channel_number; /* for multi-channel boards like Adlink PCI-MPG24 */
 168        char name[64];
 169        struct video_device *video_dev;
 170        int ref_count;
 171        enum { STATUS_INIT, STATUS_ONLINE, STATUS_SHUTDOWN } status;
 172        spinlock_t spinlock;
 173        struct mutex hw_lock;
 174        int streaming;
 175        int in_use;
 176        int audio_enabled;
 177
 178        /* Video input */
 179        int input;
 180        enum { GO7007_STD_NTSC, GO7007_STD_PAL, GO7007_STD_OTHER } standard;
 181        int sensor_framerate;
 182        int width;
 183        int height;
 184        int encoder_h_offset;
 185        int encoder_v_offset;
 186        unsigned int encoder_h_halve:1;
 187        unsigned int encoder_v_halve:1;
 188        unsigned int encoder_subsample:1;
 189
 190        /* Encoder config */
 191        int format;
 192        int bitrate;
 193        int fps_scale;
 194        int pali;
 195        int aspect_ratio;
 196        int gop_size;
 197        unsigned int ipb:1;
 198        unsigned int closed_gop:1;
 199        unsigned int repeat_seqhead:1;
 200        unsigned int seq_header_enable:1;
 201        unsigned int gop_header_enable:1;
 202        unsigned int dvd_mode:1;
 203        unsigned int interlace_coding:1;
 204
 205        /* Motion detection */
 206        unsigned int modet_enable:1;
 207        struct {
 208                unsigned int enable:1;
 209                int pixel_threshold;
 210                int motion_threshold;
 211                int mb_threshold;
 212        } modet[4];
 213        unsigned char modet_map[1624];
 214        unsigned char active_map[216];
 215
 216        /* Video streaming */
 217        struct go7007_buffer *active_buf;
 218        enum go7007_parser_state state;
 219        int parse_length;
 220        u16 modet_word;
 221        int seen_frame;
 222        u32 next_seq;
 223        struct list_head stream;
 224        wait_queue_head_t frame_waitq;
 225
 226        /* Audio streaming */
 227        void (*audio_deliver)(struct go7007 *go, u8 *buf, int length);
 228        void *snd_context;
 229
 230        /* I2C */
 231        int i2c_adapter_online;
 232        struct i2c_adapter i2c_adapter;
 233
 234        /* HPI driver */
 235        struct go7007_hpi_ops *hpi_ops;
 236        void *hpi_context;
 237        int interrupt_available;
 238        wait_queue_head_t interrupt_waitq;
 239        unsigned short interrupt_value;
 240        unsigned short interrupt_data;
 241};
 242
 243/* All of these must be called with the hpi_lock mutex held! */
 244#define go7007_interface_reset(go) \
 245                        ((go)->hpi_ops->interface_reset(go))
 246#define go7007_write_interrupt(go, x, y) \
 247                        ((go)->hpi_ops->write_interrupt)((go), (x), (y))
 248#define go7007_stream_start(go) \
 249                        ((go)->hpi_ops->stream_start(go))
 250#define go7007_stream_stop(go) \
 251                        ((go)->hpi_ops->stream_stop(go))
 252#define go7007_send_firmware(go, x, y) \
 253                        ((go)->hpi_ops->send_firmware)((go), (x), (y))
 254#define go7007_write_addr(go, x, y) \
 255                        ((go)->hpi_ops->write_interrupt)((go), (x)|0x8000, (y))
 256
 257/* go7007-driver.c */
 258int go7007_read_addr(struct go7007 *go, u16 addr, u16 *data);
 259int go7007_read_interrupt(struct go7007 *go, u16 *value, u16 *data);
 260int go7007_boot_encoder(struct go7007 *go, int init_i2c);
 261int go7007_reset_encoder(struct go7007 *go);
 262int go7007_register_encoder(struct go7007 *go);
 263int go7007_start_encoder(struct go7007 *go);
 264void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length);
 265struct go7007 *go7007_alloc(struct go7007_board_info *board,
 266                                        struct device *dev);
 267void go7007_remove(struct go7007 *go);
 268
 269/* go7007-fw.c */
 270int go7007_construct_fw_image(struct go7007 *go, u8 **fw, int *fwlen);
 271
 272/* go7007-i2c.c */
 273int go7007_i2c_init(struct go7007 *go);
 274int go7007_i2c_remove(struct go7007 *go);
 275
 276/* go7007-v4l2.c */
 277int go7007_v4l2_init(struct go7007 *go);
 278void go7007_v4l2_remove(struct go7007 *go);
 279
 280/* snd-go7007.c */
 281int go7007_snd_init(struct go7007 *go);
 282int go7007_snd_remove(struct go7007 *go);
 283