00001 /* 00002 buz - Iomega Buz driver 00003 00004 Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de> 00005 00006 based on 00007 00008 buz.0.0.3 Copyright (C) 1998 Dave Perks <dperks@ibm.net> 00009 00010 and 00011 00012 bttv - Bt848 frame grabber driver 00013 Copyright (C) 1996,97 Ralph Metzler (rjkm@thp.uni-koeln.de) 00014 00015 This program is free software; you can redistribute it and/or modify 00016 it under the terms of the GNU General Public License as published by 00017 the Free Software Foundation; either version 2 of the License, or 00018 (at your option) any later version. 00019 00020 This program is distributed in the hope that it will be useful, 00021 but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 GNU General Public License for more details. 00024 00025 You should have received a copy of the GNU General Public License 00026 along with this program; if not, write to the Free Software 00027 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00028 */ 00029 00030 #ifndef _BUZ_H_ 00031 #define _BUZ_H_ 00032 00033 /* The Buz only supports a maximum width of 720, but some V4L 00034 applications (e.g. xawtv are more happy with 768). 00035 If XAWTV_HACK is defined, we try to fake a device with bigger width */ 00036 00037 //#define XAWTV_HACK 00038 00039 //#ifdef XAWTV_HACK 00040 //#define BUZ_MAX_WIDTH 768 /* never display more than 768 pixels */ 00041 #define BUZ_MAX_WIDTH (tvnorms[btv->params.norm].Wa) 00042 //#else 00043 //#define BUZ_MAX_WIDTH 720 /* never display more than 720 pixels */ 00044 //#endif 00045 //#define BUZ_MAX_HEIGHT 576 /* never display more than 576 rows */ 00046 #define BUZ_MAX_HEIGHT (tvnorms[btv->params.norm].Ha) 00047 #define BUZ_MIN_WIDTH 32 /* never display less than 32 pixels */ 00048 #define BUZ_MIN_HEIGHT 24 /* never display less than 24 rows */ 00049 00050 struct buz_requestbuffers 00051 { 00052 unsigned long count; /* Number of buffers for MJPEG grabbing */ 00053 unsigned long size; /* Size PER BUFFER in bytes */ 00054 }; 00055 00056 struct buz_sync 00057 { 00058 unsigned long frame; /* number of buffer that has been free'd */ 00059 unsigned long length; /* number of code bytes in buffer (capture only) */ 00060 unsigned long seq; /* frame sequence number */ 00061 struct timeval timestamp; /* timestamp */ 00062 }; 00063 00064 struct buz_status 00065 { 00066 int input; /* Input channel, has to be set prior to BUZIOC_G_STATUS */ 00067 int signal; /* Returned: 1 if valid video signal detected */ 00068 int norm; /* Returned: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */ 00069 int color; /* Returned: 1 if color signal detected */ 00070 }; 00071 00072 struct buz_params 00073 { 00074 00075 /* The following parameters can only be queried */ 00076 00077 int major_version; /* Major version number of driver */ 00078 int minor_version; /* Minor version number of driver */ 00079 00080 /* Main control parameters */ 00081 00082 int input; /* Input channel: 0 = Composite, 1 = S-VHS */ 00083 int norm; /* Norm: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */ 00084 int decimation; /* decimation of captured video, 00085 enlargement of video played back. 00086 Valid values are 1, 2, 4 or 0. 00087 0 is a special value where the user 00088 has full control over video scaling */ 00089 00090 /* The following parameters only have to be set if decimation==0, 00091 for other values of decimation they provide the data how the image is captured */ 00092 00093 int HorDcm; /* Horizontal decimation: 1, 2 or 4 */ 00094 int VerDcm; /* Vertical decimation: 1 or 2 */ 00095 int TmpDcm; /* Temporal decimation: 1 or 2, 00096 if TmpDcm==2 in capture every second frame is dropped, 00097 in playback every frame is played twice */ 00098 int field_per_buff; /* Number of fields per buffer: 1 or 2 */ 00099 int img_x; /* start of image in x direction */ 00100 int img_y; /* start of image in y direction */ 00101 int img_width; /* image width BEFORE decimation, 00102 must be a multiple of HorDcm*16 */ 00103 int img_height; /* image height BEFORE decimation, 00104 must be a multiple of VerDcm*8 */ 00105 00106 /* --- End of parameters for decimation==0 only --- */ 00107 00108 /* JPEG control parameters */ 00109 00110 int quality; /* Measure for quality of compressed images. 00111 Scales linearly with the size of the compressed images. 00112 Must be beetween 0 and 100, 100 is a compression 00113 ratio of 1:4 */ 00114 00115 int odd_even; /* Which field should come first ??? */ 00116 00117 int APPn; /* Number of APP segment to be written, must be 0..15 */ 00118 int APP_len; /* Length of data in JPEG APPn segment */ 00119 char APP_data[60]; /* Data in the JPEG APPn segment. */ 00120 00121 int COM_len; /* Length of data in JPEG COM segment */ 00122 char COM_data[60]; /* Data in JPEG COM segment */ 00123 00124 unsigned long jpeg_markers; /* Which markers should go into the JPEG output. 00125 Unless you exactly know what you do, leave them untouched. 00126 Inluding less markers will make the resulting code 00127 smaller, but there will be fewer aplications 00128 which can read it. 00129 The presence of the APP and COM marker is 00130 influenced by APP0_len and COM_len ONLY! */ 00131 #define JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */ 00132 #define JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */ 00133 #define JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */ 00134 #define JPEG_MARKER_COM (1<<6) /* Comment segment */ 00135 #define JPEG_MARKER_APP (1<<7) /* App segment, driver will allways use APP0 */ 00136 00137 int VFIFO_FB; /* Flag for enabling Video Fifo Feedback. 00138 If this flag is turned on and JPEG decompressing 00139 is going to the screen, the decompress process 00140 is stopped every time the Video Fifo is full. 00141 This enables a smooth decompress to the screen 00142 but the video output signal will get scrambled */ 00143 00144 /* Misc */ 00145 00146 char reserved[312]; /* Makes 512 bytes for this structure */ 00147 }; 00148 00149 /* 00150 Private IOCTL to set up for displaying MJPEG 00151 */ 00152 #define BUZIOC_G_PARAMS _IOR ('v', BASE_VIDIOCPRIVATE+0, struct buz_params) 00153 #define BUZIOC_S_PARAMS _IOWR('v', BASE_VIDIOCPRIVATE+1, struct buz_params) 00154 #define BUZIOC_REQBUFS _IOWR('v', BASE_VIDIOCPRIVATE+2, struct buz_requestbuffers) 00155 #define BUZIOC_QBUF_CAPT _IOW ('v', BASE_VIDIOCPRIVATE+3, int) 00156 #define BUZIOC_QBUF_PLAY _IOW ('v', BASE_VIDIOCPRIVATE+4, int) 00157 #define BUZIOC_SYNC _IOR ('v', BASE_VIDIOCPRIVATE+5, struct buz_sync) 00158 #define BUZIOC_G_STATUS _IOWR('v', BASE_VIDIOCPRIVATE+6, struct buz_status) 00159 00160 00161 #ifdef __KERNEL__ 00162 00163 #define BUZ_NUM_STAT_COM 4 00164 #define BUZ_MASK_STAT_COM 3 00165 00166 #define BUZ_MAX_FRAME 256 /* Must be a power of 2 */ 00167 #define BUZ_MASK_FRAME 255 /* Must be BUZ_MAX_FRAME-1 */ 00168 00169 #if VIDEO_MAX_FRAME <= 32 00170 # define V4L_MAX_FRAME 32 00171 #elif VIDEO_MAX_FRAME <= 64 00172 # define V4L_MAX_FRAME 64 00173 #else 00174 # error "Too many video frame buffers to handle" 00175 #endif 00176 #define V4L_MASK_FRAME (V4L_MAX_FRAME - 1) 00177 00178 00179 #include "zr36057.h" 00180 00181 enum buz_codec_mode 00182 { 00183 BUZ_MODE_IDLE, /* nothing going on */ 00184 BUZ_MODE_MOTION_COMPRESS, /* grabbing frames */ 00185 BUZ_MODE_MOTION_DECOMPRESS, /* playing frames */ 00186 BUZ_MODE_STILL_COMPRESS, /* still frame conversion */ 00187 BUZ_MODE_STILL_DECOMPRESS /* still frame conversion */ 00188 }; 00189 00190 enum buz_buffer_state 00191 { 00192 BUZ_STATE_USER, /* buffer is owned by application */ 00193 BUZ_STATE_PEND, /* buffer is queued in pend[] ready to feed to I/O */ 00194 BUZ_STATE_DMA, /* buffer is queued in dma[] for I/O */ 00195 BUZ_STATE_DONE /* buffer is ready to return to application */ 00196 }; 00197 00198 struct buz_gbuffer 00199 { 00200 u32 * frag_tab; /* addresses of frag table */ 00201 u32 frag_tab_bus; /* same value cached to save time in ISR */ 00202 enum buz_buffer_state state; /* non-zero if corresponding buffer is in use in grab queue */ 00203 struct buz_sync bs; /* DONE: info to return to application */ 00204 }; 00205 00206 struct v4l_gbuffer 00207 { 00208 char * fbuffer; /* virtual address of frame buffer */ 00209 unsigned long fbuffer_phys; /* physical address of frame buffer */ 00210 unsigned long fbuffer_bus; /* bus address of frame buffer */ 00211 enum buz_buffer_state state; /* state: unused/pending/done */ 00212 }; 00213 00214 struct buz 00215 { 00216 struct video_device video_dev; 00217 struct i2c_bus i2c; 00218 00219 int initialized; /* flag if buz has been correctly initalized */ 00220 int user; /* number of current users (0 or 1) */ 00221 00222 unsigned short id; /* number of this device */ 00223 char name[32]; /* name of this device */ 00224 struct pci_dev *pci_dev; /* PCI device */ 00225 unsigned char revision; /* revision of zr36057 */ 00226 unsigned int zr36057_adr; /* bus address of IO mem returned by PCI BIOS */ 00227 unsigned char *zr36057_mem; /* pointer to mapped IO memory */ 00228 00229 int map_mjpeg_buffers; /* Flag which bufferset will map by next mmap() */ 00230 00231 spinlock_t lock; /* Spinlock */ 00232 00233 /* Video for Linux parameters */ 00234 00235 struct video_picture picture; /* Current picture params */ 00236 struct video_buffer buffer; /* Current buffer params */ 00237 struct video_window window; /* Current window params */ 00238 int buffer_set, window_set; /* Flags if the above structures are set */ 00239 int video_interlace; /* Image on screen is interlaced */ 00240 00241 u32 *overlay_mask; 00242 00243 struct wait_queue * v4l_capq; /* wait here for grab to finish */ 00244 00245 int v4l_overlay_active; /* Overlay grab is activated */ 00246 int v4l_memgrab_active; /* Memory grab is activated */ 00247 00248 int v4l_grab_frame; /* Frame number being currently grabbed */ 00249 #define NO_GRAB_ACTIVE (-1) 00250 int v4l_grab_seq; /* Number of frames grabbed */ 00251 int gwidth; /* Width of current memory capture */ 00252 int gheight; /* Height of current memory capture */ 00253 int gformat; /* Format of ... */ 00254 int gbpl; /* byte per line of ... */ 00255 00256 /* V4L grab queue of frames pending */ 00257 00258 unsigned v4l_pend_head; 00259 unsigned v4l_pend_tail; 00260 int v4l_pend[V4L_MAX_FRAME]; 00261 00262 struct v4l_gbuffer v4l_gbuf[VIDEO_MAX_FRAME]; /* V4L buffers' info */ 00263 00264 /* Buz MJPEG parameters */ 00265 00266 unsigned long jpg_nbufs; /* Number of buffers */ 00267 unsigned long jpg_bufsize; /* Size of mjpeg buffers in bytes */ 00268 int jpg_buffers_allocated; /* Flag if buffers are allocated */ 00269 int need_contiguous; /* Flag if contiguous buffers are needed */ 00270 00271 enum buz_codec_mode codec_mode; /* status of codec */ 00272 struct buz_params params; /* structure with a lot of things to play with */ 00273 00274 struct wait_queue * jpg_capq; /* wait here for grab to finish */ 00275 00276 /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */ 00277 /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */ 00278 /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */ 00279 unsigned long jpg_que_head; /* Index where to put next buffer which is queued */ 00280 unsigned long jpg_dma_head; /* Index of next buffer which goes into stat_com */ 00281 unsigned long jpg_dma_tail; /* Index of last buffer in stat_com */ 00282 unsigned long jpg_que_tail; /* Index of last buffer in queue */ 00283 unsigned long jpg_seq_num; /* count of frames since grab/play started */ 00284 00285 /* zr36057's code buffer table */ 00286 u32 * stat_com; /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */ 00287 00288 /* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */ 00289 int jpg_pend[BUZ_MAX_FRAME]; 00290 00291 /* array indexed by frame number */ 00292 struct buz_gbuffer jpg_gbuf[BUZ_MAX_FRAME]; /* MJPEG buffers' info */ 00293 00294 /* Additional stuff for testing */ 00295 #ifdef CONFIG_PROC_FS 00296 00297 struct proc_dir_entry *buz_proc; 00298 00299 #endif 00300 int testing; 00301 int jpeg_error; 00302 int intr_counter_GIRQ1; 00303 int intr_counter_GIRQ0; 00304 int intr_counter_CodRepIRQ; 00305 int intr_counter_JPEGRepIRQ; 00306 int field_counter; 00307 int IRQ1_in; 00308 int IRQ1_out; 00309 int JPEG_in; 00310 int JPEG_out; 00311 int JPEG_0; 00312 int JPEG_1; 00313 int JPEG_missed; 00314 int JPEG_max_missed; 00315 int JPEG_min_missed; 00316 00317 u32 last_isr; 00318 unsigned long frame_num; 00319 00320 struct wait_queue *test_q; 00321 }; 00322 00323 #endif 00324 00325 /*The following should be done in more portable way. It depends on define 00326 of _ALPHA_BUZ in the Makefile.*/ 00327 00328 #ifdef _ALPHA_BUZ 00329 #define btwrite(dat,adr) writel((dat),(char *) (btv->zr36057_adr+(adr))) 00330 #define btread(adr) readl(btv->zr36057_adr+(adr)) 00331 #else 00332 #define btwrite(dat,adr) writel((dat), (char *) (btv->zr36057_mem+(adr))) 00333 #define btread(adr) readl(btv->zr36057_mem+(adr)) 00334 #endif 00335 00336 #define btand(dat,adr) btwrite((dat) & btread(adr), adr) 00337 #define btor(dat,adr) btwrite((dat) | btread(adr), adr) 00338 #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr) 00339 00340 #define I2C_TSA5522 0xc2 00341 #define I2C_TDA9850 0xb6 00342 #define I2C_HAUPEE 0xa0 00343 #define I2C_STBEE 0xae 00344 #define I2C_SAA7111 0x48 00345 #define I2C_SAA7110 0x9c 00346 #define I2C_SAA7185 0x88 00347 //#define I2C_ADV7175 0xd4 00348 #define I2C_ADV7175 0x54 00349 00350 #define TDA9850_CON1 0x04 00351 #define TDA9850_CON2 0x05 00352 #define TDA9850_CON3 0x06 00353 #define TDA9850_CON4 0x07 00354 #define TDA9850_ALI1 0x08 00355 #define TDA9850_ALI2 0x09 00356 #define TDA9850_ALI3 0x0a 00357 00358 #endif
1.4.4