1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#ifndef _BTTVP_H_
27#define _BTTVP_H_
28
29#include <linux/version.h>
30#define BTTV_VERSION_CODE KERNEL_VERSION(0,9,15)
31
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>
40#include <asm/io.h>
41
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>
47
48#include "bt848.h"
49#include "bttv.h"
50#include "btcx-risc.h"
51
52#ifdef __KERNEL__
53
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
59
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
65
66#define RESOURCE_OVERLAY 1
67#define RESOURCE_VIDEO 2
68#define RESOURCE_VBI 4
69
70#define RAW_LINES 640
71#define RAW_BPL 1024
72
73#define UNSET (-1U)
74
75
76
77struct bttv_tvnorm {
78 int v4l2_id;
79 char *name;
80 u32 Fsc;
81 u16 swidth, sheight;
82 u16 totalwidth;
83 u8 adelay, bdelay, iform;
84 u32 scaledtwidth;
85 u16 hdelayx1, hactivex1;
86 u16 vdelay;
87 u8 vbipack;
88 u16 vtotal;
89 int sram;
90};
91extern const struct bttv_tvnorm bttv_tvnorms[];
92extern const unsigned int BTTV_TVNORMS;
93
94struct bttv_format {
95 char *name;
96 int palette;
97 int fourcc;
98 int btformat;
99 int btswap;
100 int depth;
101 int flags;
102 int hshift,vshift;
103};
104extern const struct bttv_format bttv_formats[];
105extern const unsigned int BTTV_FORMATS;
106
107
108
109struct bttv_geometry {
110 u8 vtc,crop,comb;
111 u16 width,hscale,hdelay;
112 u16 sheight,vscale,vdelay,vtotal;
113};
114
115struct bttv_buffer {
116
117 struct videobuf_buffer vb;
118
119
120 const struct bttv_format *fmt;
121 int tvnorm;
122 int btformat;
123 int btswap;
124 struct bttv_geometry geo;
125 struct btcx_riscmem top;
126 struct btcx_riscmem bottom;
127};
128
129struct bttv_buffer_set {
130 struct bttv_buffer *top;
131 struct bttv_buffer *bottom;
132 unsigned int top_irq;
133 unsigned int frame_irq;
134};
135
136struct bttv_overlay {
137 int tvnorm;
138 struct v4l2_rect w;
139 enum v4l2_field field;
140 struct v4l2_clip *clips;
141 int nclips;
142 int setup_ok;
143};
144
145struct bttv_fh {
146 struct bttv *btv;
147 int resources;
148#ifdef VIDIOC_G_PRIORITY
149 enum v4l2_priority prio;
150#endif
151 enum v4l2_buf_type type;
152
153
154 struct videobuf_queue cap;
155 const struct bttv_format *fmt;
156 int width;
157 int height;
158
159
160 const struct bttv_format *ovfmt;
161 struct bttv_overlay ov;
162
163
164 struct videobuf_queue vbi;
165 int lines;
166};
167
168
169
170
171
172int 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);
176int 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);
183int 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);
187
188
189void bttv_calc_geo(struct bttv *btv, struct bttv_geometry *geo,
190 int width, int height, int interleaved, int norm);
191void bttv_apply_geo(struct bttv *btv, struct bttv_geometry *geo, int top);
192
193
194void bttv_set_dma(struct bttv *btv, int override);
195int bttv_risc_init_main(struct bttv *btv);
196int bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
197 int irqflags);
198
199
200int bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf);
201int bttv_buffer_activate_video(struct bttv *btv,
202 struct bttv_buffer_set *set);
203int bttv_buffer_activate_vbi(struct bttv *btv,
204 struct bttv_buffer *vbi);
205void bttv_dma_free(struct bttv *btv, struct bttv_buffer *buf);
206
207
208int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
209 const struct bttv_format *fmt,
210 struct bttv_buffer *buf);
211
212
213
214
215
216void bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_format *f);
217void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_format *f);
218void bttv_vbi_setlines(struct bttv_fh *fh, struct bttv *btv, int lines);
219
220extern struct videobuf_queue_ops bttv_vbi_qops;
221
222
223
224
225
226extern struct bus_type bttv_sub_bus_type;
227int bttv_sub_add_device(struct bttv_core *core, char *name);
228int bttv_sub_del_devices(struct bttv_core *core);
229void bttv_gpio_irq(struct bttv_core *core);
230void bttv_i2c_info(struct bttv_core *core, struct i2c_client *client, int attach);
231
232
233
234
235
236
237extern unsigned int bttv_verbose;
238extern unsigned int bttv_debug;
239extern unsigned int bttv_gpio;
240extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
241extern int init_bttv_i2c(struct bttv *btv);
242extern int fini_bttv_i2c(struct bttv *btv);
243extern int pvr_boot(struct bttv *btv);
244
245extern int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg);
246extern void bttv_reinit_bt848(struct bttv *btv);
247extern void bttv_field_count(struct bttv *btv);
248
249#define vprintk if (bttv_verbose) printk
250#define dprintk if (bttv_debug >= 1) printk
251#define d2printk if (bttv_debug >= 2) printk
252
253
254#define BTTV_MAX 16
255extern unsigned int bttv_num;
256extern struct bttv bttvs[BTTV_MAX];
257
258#define BTTV_MAX_FBUF 0x208000
259#define VBIBUF_SIZE (2048*VBI_MAXLINES*2)
260#define BTTV_TIMEOUT (HZ/2)
261#define BTTV_FREE_IDLE (HZ)
262
263
264struct bttv_pll_info {
265 unsigned int pll_ifreq;
266 unsigned int pll_ofreq;
267 unsigned int pll_crystal;
268 unsigned int pll_current;
269};
270
271
272struct bttv_input {
273 struct input_dev dev;
274 struct ir_input_state ir;
275 char name[32];
276 char phys[32];
277 u32 mask_keycode;
278 u32 mask_keydown;
279};
280
281struct bttv_suspend_state {
282 u32 gpio_enable;
283 u32 gpio_data;
284 int disabled;
285 int loop_irq;
286 struct bttv_buffer_set video;
287 struct bttv_buffer *vbi;
288};
289
290struct bttv {
291 struct bttv_core c;
292
293
294 unsigned short id;
295 unsigned char revision;
296 unsigned char __iomem *bt848_mmio;
297
298
299 unsigned int cardid;
300 unsigned int tuner_type;
301 unsigned int pinnacle_id;
302 unsigned int svhs;
303 struct bttv_pll_info pll;
304 int triton1;
305 int gpioirq;
306 int use_i2c_hw;
307
308
309 wait_queue_head_t gpioq;
310 int shutdown;
311 void (*audio_hook)(struct bttv *btv, struct video_audio *v, int set);
312
313
314 spinlock_t gpio_lock;
315
316
317 struct i2c_algo_bit_data i2c_algo;
318 struct i2c_client i2c_client;
319 int i2c_state, i2c_rc;
320 int i2c_done;
321 wait_queue_head_t i2c_queue;
322
323
324 struct video_device *video_dev;
325 struct video_device *radio_dev;
326 struct video_device *vbi_dev;
327
328
329 int has_remote;
330 struct bttv_input *remote;
331
332
333 spinlock_t s_lock;
334 struct semaphore lock;
335 int resources;
336 struct semaphore reslock;
337#ifdef VIDIOC_G_PRIORITY
338 struct v4l2_prio_state prio;
339#endif
340
341
342 unsigned int input;
343 unsigned int audio;
344 unsigned long freq;
345 int tvnorm,hue,contrast,bright,saturation;
346 struct v4l2_framebuffer fbuf;
347 unsigned int field_count;
348
349
350 int opt_combfilter;
351 int opt_lumafilter;
352 int opt_automute;
353 int opt_chroma_agc;
354 int opt_adc_crush;
355 int opt_vcr_hack;
356 int opt_whitecrush_upper;
357 int opt_whitecrush_lower;
358
359
360 int has_radio;
361 int radio_user;
362
363
364
365 int has_matchbox;
366 int mbox_we;
367 int mbox_data;
368 int mbox_clk;
369 int mbox_most;
370 int mbox_mask;
371
372
373 int mbox_ior;
374 int mbox_iow;
375 int mbox_csel;
376
377
378
379
380 struct btcx_riscmem main;
381 struct bttv_buffer *screen;
382 struct list_head capture;
383 struct list_head vcapture;
384 struct bttv_buffer_set curr;
385 struct bttv_buffer *cvbi;
386 int loop_irq;
387 int new_input;
388
389 unsigned long cap_ctl;
390 unsigned long dma_on;
391 struct timer_list timeout;
392 struct bttv_suspend_state state;
393
394
395 unsigned int errors;
396 unsigned int framedrop;
397 unsigned int irq_total;
398 unsigned int irq_me;
399
400 unsigned int users;
401 struct bttv_fh init;
402};
403
404
405#define BTTV_VERSION _IOR('v' , BASE_VIDIOCPRIVATE+6, int)
406#define BTTV_VBISIZE _IOR('v' , BASE_VIDIOCPRIVATE+8, int)
407
408#endif
409
410#define btwrite(dat,adr) writel((dat), btv->bt848_mmio+(adr))
411#define btread(adr) readl(btv->bt848_mmio+(adr))
412
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)
416
417#endif
418
419
420
421
422
423
424