2 $Id: bttvp.h,v 1.12 2004/10/25 11:26:36 kraxel Exp $
4 bttv - Bt848 frame grabber driver
6 bttv's *private* header file -- nobody other than bttv itself
7 should ever include this file.
9 (c) 2000-2002 Gerd Knorr <kraxel@bytesex.org>
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <linux/version.h>
30 #define BTTV_VERSION_CODE KERNEL_VERSION(0,9,15)
32 #include <linux/types.h>
33 #include <linux/wait.h>
34 #include <linux/i2c.h>
35 #include <linux/i2c-algo-bit.h>
36 #include <linux/videodev.h>
37 #include <linux/pci.h>
38 #include <linux/input.h>
39 #include <asm/scatterlist.h>
42 #include <linux/device.h>
43 #include <media/video-buf.h>
44 #include <media/audiochip.h>
45 #include <media/tuner.h>
46 #include <media/ir-common.h>
50 #include "btcx-risc.h"
54 #define FORMAT_FLAGS_DITHER 0x01
55 #define FORMAT_FLAGS_PACKED 0x02
56 #define FORMAT_FLAGS_PLANAR 0x04
57 #define FORMAT_FLAGS_RAW 0x08
58 #define FORMAT_FLAGS_CrCb 0x10
60 #define RISC_SLOT_O_VBI 4
61 #define RISC_SLOT_O_FIELD 6
62 #define RISC_SLOT_E_VBI 10
63 #define RISC_SLOT_E_FIELD 12
64 #define RISC_SLOT_LOOP 14
66 #define RESOURCE_OVERLAY 1
67 #define RESOURCE_VIDEO 2
68 #define RESOURCE_VBI 4
75 /* ---------------------------------------------------------- */
81 u16 swidth, sheight; /* scaled standard width, height */
83 u8 adelay, bdelay, iform;
85 u16 hdelayx1, hactivex1;
91 extern const struct bttv_tvnorm bttv_tvnorms[];
92 extern const unsigned int BTTV_TVNORMS;
96 int palette; /* video4linux 1 */
97 int fourcc; /* video4linux 2 */
98 int btformat; /* BT848_COLOR_FMT_* */
99 int btswap; /* BT848_COLOR_CTL_* */
100 int depth; /* bit/pixel */
102 int hshift,vshift; /* for planar modes */
104 extern const struct bttv_format bttv_formats[];
105 extern const unsigned int BTTV_FORMATS;
107 /* ---------------------------------------------------------- */
109 struct bttv_geometry {
111 u16 width,hscale,hdelay;
112 u16 sheight,vscale,vdelay,vtotal;
116 /* common v4l buffer stuff -- must be first */
117 struct videobuf_buffer vb;
120 const struct bttv_format *fmt;
124 struct bttv_geometry geo;
125 struct btcx_riscmem top;
126 struct btcx_riscmem bottom;
129 struct bttv_buffer_set {
130 struct bttv_buffer *top; /* top field buffer */
131 struct bttv_buffer *bottom; /* bottom field buffer */
132 unsigned int top_irq;
133 unsigned int frame_irq;
136 struct bttv_overlay {
139 enum v4l2_field field;
140 struct v4l2_clip *clips;
148 #ifdef VIDIOC_G_PRIORITY
149 enum v4l2_priority prio;
151 enum v4l2_buf_type type;
154 struct videobuf_queue cap;
155 const struct bttv_format *fmt;
159 /* current settings */
160 const struct bttv_format *ovfmt;
161 struct bttv_overlay ov;
164 struct videobuf_queue vbi;
168 /* ---------------------------------------------------------- */
171 /* risc code generators - capture */
172 int bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
173 struct scatterlist *sglist,
174 unsigned int offset, unsigned int bpl,
175 unsigned int pitch, unsigned int lines);
176 int bttv_risc_planar(struct bttv *btv, struct btcx_riscmem *risc,
177 struct scatterlist *sglist,
178 unsigned int yoffset, unsigned int ybpl,
179 unsigned int ypadding, unsigned int ylines,
180 unsigned int uoffset, unsigned int voffset,
181 unsigned int hshift, unsigned int vshift,
182 unsigned int cpadding);
183 int bttv_risc_overlay(struct bttv *btv, struct btcx_riscmem *risc,
184 const struct bttv_format *fmt,
185 struct bttv_overlay *ov,
186 int skip_top, int skip_bottom);
188 /* calculate / apply geometry settings */
189 void bttv_calc_geo(struct bttv *btv, struct bttv_geometry *geo,
190 int width, int height, int interleaved, int norm);
191 void bttv_apply_geo(struct bttv *btv, struct bttv_geometry *geo, int top);
193 /* control dma register + risc main loop */
194 void bttv_set_dma(struct bttv *btv, int override);
195 int bttv_risc_init_main(struct bttv *btv);
196 int bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
199 /* capture buffer handling */
200 int bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf);
201 int bttv_buffer_activate_video(struct bttv *btv,
202 struct bttv_buffer_set *set);
203 int bttv_buffer_activate_vbi(struct bttv *btv,
204 struct bttv_buffer *vbi);
205 void bttv_dma_free(struct bttv *btv, struct bttv_buffer *buf);
207 /* overlay handling */
208 int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
209 const struct bttv_format *fmt,
210 struct bttv_buffer *buf);
213 /* ---------------------------------------------------------- */
216 void bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_format *f);
217 void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_format *f);
218 void bttv_vbi_setlines(struct bttv_fh *fh, struct bttv *btv, int lines);
220 extern struct videobuf_queue_ops bttv_vbi_qops;
222 /* ---------------------------------------------------------- */
226 extern struct bus_type bttv_sub_bus_type;
227 int bttv_sub_add_device(struct bttv_core *core, char *name);
228 int bttv_sub_del_devices(struct bttv_core *core);
229 void bttv_gpio_irq(struct bttv_core *core);
230 void bttv_i2c_info(struct bttv_core *core, struct i2c_client *client, int attach);
233 /* ---------------------------------------------------------- */
237 extern unsigned int bttv_verbose;
238 extern unsigned int bttv_debug;
239 extern unsigned int bttv_gpio;
240 extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
241 extern int init_bttv_i2c(struct bttv *btv);
242 extern int fini_bttv_i2c(struct bttv *btv);
243 extern int pvr_boot(struct bttv *btv);
245 extern int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg);
246 extern void bttv_reinit_bt848(struct bttv *btv);
247 extern void bttv_field_count(struct bttv *btv);
249 #define vprintk if (bttv_verbose) printk
250 #define dprintk if (bttv_debug >= 1) printk
251 #define d2printk if (bttv_debug >= 2) printk
255 extern unsigned int bttv_num;
256 extern struct bttv bttvs[BTTV_MAX];
258 #define BTTV_MAX_FBUF 0x208000
259 #define VBIBUF_SIZE (2048*VBI_MAXLINES*2)
260 #define BTTV_TIMEOUT (HZ/2) /* 0.5 seconds */
261 #define BTTV_FREE_IDLE (HZ) /* one second */
264 struct bttv_pll_info {
265 unsigned int pll_ifreq; /* PLL input frequency */
266 unsigned int pll_ofreq; /* PLL output frequency */
267 unsigned int pll_crystal; /* Crystal used for input */
268 unsigned int pll_current; /* Currently programmed ofreq */
271 /* for gpio-connected remote control */
273 struct input_dev dev;
274 struct ir_input_state ir;
281 struct bttv_suspend_state {
286 struct bttv_buffer_set video;
287 struct bttv_buffer *vbi;
293 /* pci device config */
295 unsigned char revision;
296 unsigned char __iomem *bt848_mmio; /* pointer to mmio */
298 /* card configuration info */
299 unsigned int cardid; /* pci subsystem id (bt878 based ones) */
300 unsigned int tuner_type; /* tuner chip type */
301 unsigned int pinnacle_id;
303 struct bttv_pll_info pll;
308 /* old gpio interface */
309 wait_queue_head_t gpioq;
311 void (*audio_hook)(struct bttv *btv, struct video_audio *v, int set);
313 /* new gpio interface */
314 spinlock_t gpio_lock;
317 struct i2c_algo_bit_data i2c_algo;
318 struct i2c_client i2c_client;
319 int i2c_state, i2c_rc;
321 wait_queue_head_t i2c_queue;
323 /* video4linux (1) */
324 struct video_device *video_dev;
325 struct video_device *radio_dev;
326 struct video_device *vbi_dev;
328 /* infrared remote */
330 struct bttv_input *remote;
334 struct semaphore lock;
336 struct semaphore reslock;
337 #ifdef VIDIOC_G_PRIORITY
338 struct v4l2_prio_state prio;
345 int tvnorm,hue,contrast,bright,saturation;
346 struct v4l2_framebuffer fbuf;
347 unsigned int field_count;
349 /* various options */
356 int opt_whitecrush_upper;
357 int opt_whitecrush_lower;
359 /* radio data/state */
363 /* miro/pinnacle + Aimslab VHX
364 philips matchbox (tea5757 radio tuner) support */
372 /* ISA stuff (Terratec Active Radio Upgrade) */
377 /* risc memory management data
378 - must aquire s_lock before changing these
379 - only the irq handler is supported to touch top + bottom + vcurr */
380 struct btcx_riscmem main;
381 struct bttv_buffer *screen; /* overlay */
382 struct list_head capture; /* video capture queue */
383 struct list_head vcapture; /* vbi capture queue */
384 struct bttv_buffer_set curr; /* active buffers */
385 struct bttv_buffer *cvbi; /* active vbi buffer */
389 unsigned long cap_ctl;
390 unsigned long dma_on;
391 struct timer_list timeout;
392 struct bttv_suspend_state state;
396 unsigned int framedrop;
397 unsigned int irq_total;
405 #define BTTV_VERSION _IOR('v' , BASE_VIDIOCPRIVATE+6, int)
406 #define BTTV_VBISIZE _IOR('v' , BASE_VIDIOCPRIVATE+8, int)
410 #define btwrite(dat,adr) writel((dat), btv->bt848_mmio+(adr))
411 #define btread(adr) readl(btv->bt848_mmio+(adr))
413 #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
414 #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
415 #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
417 #endif /* _BTTVP_H_ */