1 /* SPDX-License-Identifier: GPL-2.0-or-later */
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>
16 #include <linux/types.h>
17 #include <linux/wait.h>
18 #include <linux/i2c.h>
19 #include <linux/i2c-algo-bit.h>
20 #include <linux/pci.h>
21 #include <linux/input.h>
22 #include <linux/mutex.h>
23 #include <linux/scatterlist.h>
24 #include <linux/device.h>
26 #include <media/v4l2-common.h>
27 #include <media/v4l2-ctrls.h>
28 #include <media/v4l2-fh.h>
29 #include <media/videobuf-dma-sg.h>
30 #include <media/tveeprom.h>
31 #include <media/rc-core.h>
32 #include <media/i2c/ir-kbd-i2c.h>
33 #include <media/drv-intf/tea575x.h>
37 #include "btcx-risc.h"
41 #define FORMAT_FLAGS_DITHER 0x01
42 #define FORMAT_FLAGS_PACKED 0x02
43 #define FORMAT_FLAGS_PLANAR 0x04
44 #define FORMAT_FLAGS_RAW 0x08
45 #define FORMAT_FLAGS_CrCb 0x10
47 #define RISC_SLOT_O_VBI 4
48 #define RISC_SLOT_O_FIELD 6
49 #define RISC_SLOT_E_VBI 10
50 #define RISC_SLOT_E_FIELD 12
51 #define RISC_SLOT_LOOP 14
53 #define RESOURCE_OVERLAY 1
54 #define RESOURCE_VIDEO_STREAM 2
55 #define RESOURCE_VBI 4
56 #define RESOURCE_VIDEO_READ 8
63 /* Min. value in VDELAY register. */
65 /* Even to get Cb first, odd for Cr. */
66 #define MAX_HDELAY (0x3FF & -2)
67 /* Limits scaled width, which must be a multiple of 4. */
68 #define MAX_HACTIVE (0x3FF & -4)
71 V4L2_STD_PAL | V4L2_STD_PAL_N | \
72 V4L2_STD_PAL_Nc | V4L2_STD_SECAM | \
73 V4L2_STD_NTSC | V4L2_STD_PAL_M | \
75 /* ---------------------------------------------------------- */
81 u16 swidth, sheight; /* scaled standard width, height */
83 u8 adelay, bdelay, iform;
85 u16 hdelayx1, hactivex1;
90 /* ITU-R frame line number of the first VBI line we can
91 capture, of the first and second field. The last possible line
92 is determined by cropcap.bounds. */
94 /* Horizontally this counts fCLKx1 samples following the leading
95 edge of the horizontal sync pulse, vertically ITU-R frame line
96 numbers of the first field times two (2, 4, 6, ... 524 or 624). */
97 struct v4l2_cropcap cropcap;
99 extern const struct bttv_tvnorm bttv_tvnorms[];
103 int fourcc; /* video4linux 2 */
104 int btformat; /* BT848_COLOR_FMT_* */
105 int btswap; /* BT848_COLOR_CTL_* */
106 int depth; /* bit/pixel */
108 int hshift,vshift; /* for planar modes */
114 struct timer_list timer;
119 /* Usual gpio signalling */
129 bool rc5_gpio; /* Is RC5 legacy GPIO enabled? */
130 u32 last_bit; /* last raw bit seen */
131 u32 code; /* raw code under construction */
132 ktime_t base_time; /* time of last seen code */
133 bool active; /* building raw code */
137 /* ---------------------------------------------------------- */
139 struct bttv_geometry {
141 u16 width,hscale,hdelay;
142 u16 sheight,vscale,vdelay,vtotal;
146 /* common v4l buffer stuff -- must be first */
147 struct videobuf_buffer vb;
150 const struct bttv_format *fmt;
154 struct bttv_geometry geo;
155 struct btcx_riscmem top;
156 struct btcx_riscmem bottom;
157 struct v4l2_rect crop;
158 unsigned int vbi_skip[2];
159 unsigned int vbi_count[2];
162 struct bttv_buffer_set {
163 struct bttv_buffer *top; /* top field buffer */
164 struct bttv_buffer *bottom; /* bottom field buffer */
165 unsigned int top_irq;
166 unsigned int frame_irq;
169 struct bttv_overlay {
172 enum v4l2_field field;
173 struct v4l2_clip *clips;
178 struct bttv_vbi_fmt {
179 struct v4l2_vbi_format fmt;
181 /* fmt.start[] and count[] refer to this video standard. */
182 const struct bttv_tvnorm *tvnorm;
184 /* Earliest possible start of video capturing with this
185 v4l2_vbi_format, in struct bttv_crop.rect units. */
190 void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm);
193 /* A cropping rectangle in struct bttv_tvnorm.cropcap units. */
194 struct v4l2_rect rect;
196 /* Scaled image size limits with this crop rect. Divide
197 max_height, but not min_height, by two when capturing
198 single fields. See also bttv_crop_reset() and
199 bttv_crop_adjust() in bttv-driver.c. */
200 __s32 min_scaled_width;
201 __s32 min_scaled_height;
202 __s32 max_scaled_width;
203 __s32 max_scaled_height;
207 /* This must be the first field in this struct */
212 enum v4l2_buf_type type;
215 struct videobuf_queue cap;
216 const struct bttv_format *fmt;
221 const struct bttv_format *ovfmt;
222 struct bttv_overlay ov;
224 /* Application called VIDIOC_S_SELECTION. */
228 struct videobuf_queue vbi;
229 /* Current VBI capture window as seen through this fh (cannot
230 be global for compatibility with earlier drivers). Protected
231 by struct bttv.lock and struct bttv_fh.vbi.lock. */
232 struct bttv_vbi_fmt vbi_fmt;
235 /* ---------------------------------------------------------- */
238 /* risc code generators - capture */
239 int bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
240 struct scatterlist *sglist,
241 unsigned int offset, unsigned int bpl,
242 unsigned int pitch, unsigned int skip_lines,
243 unsigned int store_lines);
245 /* control dma register + risc main loop */
246 void bttv_set_dma(struct bttv *btv, int override);
247 int bttv_risc_init_main(struct bttv *btv);
248 int bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
251 /* capture buffer handling */
252 int bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf);
253 int bttv_buffer_activate_video(struct bttv *btv,
254 struct bttv_buffer_set *set);
255 int bttv_buffer_activate_vbi(struct bttv *btv,
256 struct bttv_buffer *vbi);
257 void bttv_dma_free(struct videobuf_queue *q, struct bttv *btv,
258 struct bttv_buffer *buf);
260 /* overlay handling */
261 int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
262 const struct bttv_format *fmt,
263 struct bttv_buffer *buf);
266 /* ---------------------------------------------------------- */
269 int bttv_try_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
270 int bttv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
271 int bttv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
273 extern const struct videobuf_queue_ops bttv_vbi_qops;
275 /* ---------------------------------------------------------- */
278 extern struct bus_type bttv_sub_bus_type;
279 int bttv_sub_add_device(struct bttv_core *core, char *name);
280 int bttv_sub_del_devices(struct bttv_core *core);
282 /* ---------------------------------------------------------- */
285 extern int no_overlay;
287 /* ---------------------------------------------------------- */
290 extern void init_bttv_i2c_ir(struct bttv *btv);
292 /* ---------------------------------------------------------- */
294 extern int init_bttv_i2c(struct bttv *btv);
295 extern int fini_bttv_i2c(struct bttv *btv);
297 /* ---------------------------------------------------------- */
301 extern unsigned int bttv_verbose;
302 extern unsigned int bttv_debug;
303 extern unsigned int bttv_gpio;
304 extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
306 #define dprintk(fmt, ...) \
308 if (bttv_debug >= 1) \
309 pr_debug(fmt, ##__VA_ARGS__); \
311 #define dprintk_cont(fmt, ...) \
313 if (bttv_debug >= 1) \
314 pr_cont(fmt, ##__VA_ARGS__); \
316 #define d2printk(fmt, ...) \
318 if (bttv_debug >= 2) \
319 printk(fmt, ##__VA_ARGS__); \
322 #define BTTV_MAX_FBUF 0x208000
323 #define BTTV_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
324 #define BTTV_FREE_IDLE msecs_to_jiffies(1000) /* one second */
327 struct bttv_pll_info {
328 unsigned int pll_ifreq; /* PLL input frequency */
329 unsigned int pll_ofreq; /* PLL output frequency */
330 unsigned int pll_crystal; /* Crystal used for input */
331 unsigned int pll_current; /* Currently programmed ofreq */
334 /* for gpio-connected remote control */
336 struct input_dev *dev;
343 struct bttv_suspend_state {
348 struct bttv_buffer_set video;
349 struct bttv_buffer *vbi;
352 struct bttv_tea575x_gpio {
353 u8 data, clk, wren, most;
359 /* pci device config */
361 unsigned char revision;
362 unsigned char __iomem *bt848_mmio; /* pointer to mmio */
364 /* card configuration info */
365 unsigned int cardid; /* pci subsystem id (bt878 based ones) */
366 unsigned int tuner_type; /* tuner chip type */
367 unsigned int tda9887_conf;
368 unsigned int svhs, dig;
369 unsigned int has_saa6588:1;
370 struct bttv_pll_info pll;
376 /* old gpio interface */
379 void (*volume_gpio)(struct bttv *btv, __u16 volume);
380 void (*audio_mode_gpio)(struct bttv *btv, struct v4l2_tuner *tuner, int set);
382 /* new gpio interface */
383 spinlock_t gpio_lock;
386 struct i2c_algo_bit_data i2c_algo;
387 struct i2c_client i2c_client;
388 int i2c_state, i2c_rc;
390 wait_queue_head_t i2c_queue;
391 struct v4l2_subdev *sd_msp34xx;
392 struct v4l2_subdev *sd_tvaudio;
393 struct v4l2_subdev *sd_tda7432;
395 /* video4linux (1) */
396 struct video_device video_dev;
397 struct video_device radio_dev;
398 struct video_device vbi_dev;
401 struct v4l2_ctrl_handler ctrl_handler;
402 struct v4l2_ctrl_handler radio_ctrl_handler;
404 /* infrared remote */
406 struct bttv_ir *remote;
408 /* I2C remote data */
409 struct IR_i2c_init_data init_data;
418 unsigned int audio_input;
420 unsigned long tv_freq;
423 int hue, contrast, bright, saturation;
424 struct v4l2_framebuffer fbuf;
425 unsigned int field_count;
427 /* various options */
433 /* radio data/state */
437 int radio_uses_msp_demodulator;
438 unsigned long radio_freq;
440 /* miro/pinnacle + Aimslab VHX
441 philips matchbox (tea5757 radio tuner) support */
443 struct bttv_tea575x_gpio tea_gpio;
444 struct snd_tea575x tea;
446 /* ISA stuff (Terratec Active Radio Upgrade) */
451 /* switch status for multi-controller cards */
454 /* risc memory management data
455 - must acquire s_lock before changing these
456 - only the irq handler is supported to touch top + bottom + vcurr */
457 struct btcx_riscmem main;
458 struct bttv_buffer *screen; /* overlay */
459 struct list_head capture; /* video capture queue */
460 struct list_head vcapture; /* vbi capture queue */
461 struct bttv_buffer_set curr; /* active buffers */
462 struct bttv_buffer *cvbi; /* active vbi buffer */
466 unsigned long cap_ctl;
467 unsigned long dma_on;
468 struct timer_list timeout;
469 struct bttv_suspend_state state;
473 unsigned int framedrop;
474 unsigned int irq_total;
480 /* used to make dvb-bt8xx autoloadable */
481 struct work_struct request_module_wk;
483 /* Default (0) and current (1) video capturing and overlay
484 cropping parameters in bttv_tvnorm.cropcap units. Protected
486 struct bttv_crop crop[2];
488 /* Earliest possible start of video capturing in
489 bttv_tvnorm.cropcap line units. Set by check_alloc_btres()
490 and free_btres(). Protected by bttv.lock. */
493 /* Latest possible end of VBI capturing (= crop[x].rect.top when
494 VIDEO_RESOURCES are locked). Set by check_alloc_btres()
495 and free_btres(). Protected by bttv.lock. */
499 static inline struct bttv *to_bttv(struct v4l2_device *v4l2_dev)
501 return container_of(v4l2_dev, struct bttv, c.v4l2_dev);
506 extern unsigned int bttv_num;
507 extern struct bttv *bttvs[BTTV_MAX];
509 static inline unsigned int bttv_muxsel(const struct bttv *btv,
512 return (bttv_tvcards[btv->c.type].muxsel >> (input * 2)) & 3;
517 #define btwrite(dat,adr) writel((dat), btv->bt848_mmio+(adr))
518 #define btread(adr) readl(btv->bt848_mmio+(adr))
520 #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
521 #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
522 #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
524 #endif /* _BTTVP_H_ */