1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef _BTTVP_H_
14#define _BTTVP_H_
15
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>
25#include <asm/io.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>
34
35#include "bt848.h"
36#include "bttv.h"
37#include "btcx-risc.h"
38
39#ifdef __KERNEL__
40
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
46
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
52
53#define RESOURCE_OVERLAY 1
54#define RESOURCE_VIDEO_STREAM 2
55#define RESOURCE_VBI 4
56#define RESOURCE_VIDEO_READ 8
57
58#define RAW_LINES 640
59#define RAW_BPL 1024
60
61#define UNSET (-1U)
62
63
64#define MIN_VDELAY 2
65
66#define MAX_HDELAY (0x3FF & -2)
67
68#define MAX_HACTIVE (0x3FF & -4)
69
70#define BTTV_NORMS (\
71 V4L2_STD_PAL | V4L2_STD_PAL_N | \
72 V4L2_STD_PAL_Nc | V4L2_STD_SECAM | \
73 V4L2_STD_NTSC | V4L2_STD_PAL_M | \
74 V4L2_STD_PAL_60)
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
91
92
93 u16 vbistart[2];
94
95
96
97 struct v4l2_cropcap cropcap;
98};
99extern const struct bttv_tvnorm bttv_tvnorms[];
100
101struct bttv_format {
102 char *name;
103 int fourcc;
104 int btformat;
105 int btswap;
106 int depth;
107 int flags;
108 int hshift,vshift;
109};
110
111struct bttv_ir {
112 struct rc_dev *dev;
113 struct bttv *btv;
114 struct timer_list timer;
115
116 char name[32];
117 char phys[32];
118
119
120 u32 mask_keycode;
121 u32 mask_keydown;
122 u32 mask_keyup;
123 u32 polling;
124 u32 last_gpio;
125 int shift_by;
126 int rc5_remote_gap;
127
128
129 bool rc5_gpio;
130 u32 last_bit;
131 u32 code;
132 ktime_t base_time;
133 bool active;
134};
135
136
137
138
139struct bttv_geometry {
140 u8 vtc,crop,comb;
141 u16 width,hscale,hdelay;
142 u16 sheight,vscale,vdelay,vtotal;
143};
144
145struct bttv_buffer {
146
147 struct videobuf_buffer vb;
148
149
150 const struct bttv_format *fmt;
151 unsigned int tvnorm;
152 int btformat;
153 int btswap;
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];
160};
161
162struct bttv_buffer_set {
163 struct bttv_buffer *top;
164 struct bttv_buffer *bottom;
165 unsigned int top_irq;
166 unsigned int frame_irq;
167};
168
169struct bttv_overlay {
170 unsigned int tvnorm;
171 struct v4l2_rect w;
172 enum v4l2_field field;
173 struct v4l2_clip *clips;
174 int nclips;
175 int setup_ok;
176};
177
178struct bttv_vbi_fmt {
179 struct v4l2_vbi_format fmt;
180
181
182 const struct bttv_tvnorm *tvnorm;
183
184
185
186 __s32 end;
187};
188
189
190void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm);
191
192struct bttv_crop {
193
194 struct v4l2_rect rect;
195
196
197
198
199
200 __s32 min_scaled_width;
201 __s32 min_scaled_height;
202 __s32 max_scaled_width;
203 __s32 max_scaled_height;
204};
205
206struct bttv_fh {
207
208 struct v4l2_fh fh;
209
210 struct bttv *btv;
211 int resources;
212 enum v4l2_buf_type type;
213
214
215 struct videobuf_queue cap;
216 const struct bttv_format *fmt;
217 int width;
218 int height;
219
220
221 const struct bttv_format *ovfmt;
222 struct bttv_overlay ov;
223
224
225 int do_crop;
226
227
228 struct videobuf_queue vbi;
229
230
231
232 struct bttv_vbi_fmt vbi_fmt;
233};
234
235
236
237
238
239int 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);
244
245
246void bttv_set_dma(struct bttv *btv, int override);
247int bttv_risc_init_main(struct bttv *btv);
248int bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
249 int irqflags);
250
251
252int bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf);
253int bttv_buffer_activate_video(struct bttv *btv,
254 struct bttv_buffer_set *set);
255int bttv_buffer_activate_vbi(struct bttv *btv,
256 struct bttv_buffer *vbi);
257void bttv_dma_free(struct videobuf_queue *q, struct bttv *btv,
258 struct bttv_buffer *buf);
259
260
261int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
262 const struct bttv_format *fmt,
263 struct bttv_buffer *buf);
264
265
266
267
268
269int bttv_try_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
270int bttv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
271int bttv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
272
273extern const struct videobuf_queue_ops bttv_vbi_qops;
274
275
276
277
278extern struct bus_type bttv_sub_bus_type;
279int bttv_sub_add_device(struct bttv_core *core, char *name);
280int bttv_sub_del_devices(struct bttv_core *core);
281
282
283
284
285extern int no_overlay;
286
287
288
289
290extern void init_bttv_i2c_ir(struct bttv *btv);
291
292
293
294extern int init_bttv_i2c(struct bttv *btv);
295extern int fini_bttv_i2c(struct bttv *btv);
296
297
298
299
300
301extern unsigned int bttv_verbose;
302extern unsigned int bttv_debug;
303extern unsigned int bttv_gpio;
304extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
305
306#define dprintk(fmt, ...) \
307do { \
308 if (bttv_debug >= 1) \
309 pr_debug(fmt, ##__VA_ARGS__); \
310} while (0)
311#define dprintk_cont(fmt, ...) \
312do { \
313 if (bttv_debug >= 1) \
314 pr_cont(fmt, ##__VA_ARGS__); \
315} while (0)
316#define d2printk(fmt, ...) \
317do { \
318 if (bttv_debug >= 2) \
319 printk(fmt, ##__VA_ARGS__); \
320} while (0)
321
322#define BTTV_MAX_FBUF 0x208000
323#define BTTV_TIMEOUT msecs_to_jiffies(500)
324#define BTTV_FREE_IDLE msecs_to_jiffies(1000)
325
326
327struct bttv_pll_info {
328 unsigned int pll_ifreq;
329 unsigned int pll_ofreq;
330 unsigned int pll_crystal;
331 unsigned int pll_current;
332};
333
334
335struct bttv_input {
336 struct input_dev *dev;
337 char name[32];
338 char phys[32];
339 u32 mask_keycode;
340 u32 mask_keydown;
341};
342
343struct bttv_suspend_state {
344 u32 gpio_enable;
345 u32 gpio_data;
346 int disabled;
347 int loop_irq;
348 struct bttv_buffer_set video;
349 struct bttv_buffer *vbi;
350};
351
352struct bttv_tea575x_gpio {
353 u8 data, clk, wren, most;
354};
355
356struct bttv {
357 struct bttv_core c;
358
359
360 unsigned short id;
361 unsigned char revision;
362 unsigned char __iomem *bt848_mmio;
363
364
365 unsigned int cardid;
366 unsigned int tuner_type;
367 unsigned int tda9887_conf;
368 unsigned int svhs, dig;
369 unsigned int has_saa6588:1;
370 struct bttv_pll_info pll;
371 int triton1;
372 int gpioirq;
373
374 int use_i2c_hw;
375
376
377 int shutdown;
378
379 void (*volume_gpio)(struct bttv *btv, __u16 volume);
380 void (*audio_mode_gpio)(struct bttv *btv, struct v4l2_tuner *tuner, int set);
381
382
383 spinlock_t gpio_lock;
384
385
386 struct i2c_algo_bit_data i2c_algo;
387 struct i2c_client i2c_client;
388 int i2c_state, i2c_rc;
389 int i2c_done;
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;
394
395
396 struct video_device video_dev;
397 struct video_device radio_dev;
398 struct video_device vbi_dev;
399
400
401 struct v4l2_ctrl_handler ctrl_handler;
402 struct v4l2_ctrl_handler radio_ctrl_handler;
403
404
405 int has_remote;
406 struct bttv_ir *remote;
407
408
409 struct IR_i2c_init_data init_data;
410
411
412 spinlock_t s_lock;
413 struct mutex lock;
414 int resources;
415
416
417 unsigned int input;
418 unsigned int audio_input;
419 unsigned int mute;
420 unsigned long tv_freq;
421 unsigned int tvnorm;
422 v4l2_std_id std;
423 int hue, contrast, bright, saturation;
424 struct v4l2_framebuffer fbuf;
425 unsigned int field_count;
426
427
428 int opt_combfilter;
429 int opt_automute;
430 int opt_vcr_hack;
431 int opt_uv_ratio;
432
433
434 int has_radio;
435 int has_radio_tuner;
436 int radio_user;
437 int radio_uses_msp_demodulator;
438 unsigned long radio_freq;
439
440
441
442 int has_tea575x;
443 struct bttv_tea575x_gpio tea_gpio;
444 struct snd_tea575x tea;
445
446
447 int mbox_ior;
448 int mbox_iow;
449 int mbox_csel;
450
451
452 char sw_status[4];
453
454
455
456
457 struct btcx_riscmem main;
458 struct bttv_buffer *screen;
459 struct list_head capture;
460 struct list_head vcapture;
461 struct bttv_buffer_set curr;
462 struct bttv_buffer *cvbi;
463 int loop_irq;
464 int new_input;
465
466 unsigned long cap_ctl;
467 unsigned long dma_on;
468 struct timer_list timeout;
469 struct bttv_suspend_state state;
470
471
472 unsigned int errors;
473 unsigned int framedrop;
474 unsigned int irq_total;
475 unsigned int irq_me;
476
477 unsigned int users;
478 struct bttv_fh init;
479
480
481 struct work_struct request_module_wk;
482
483
484
485
486 struct bttv_crop crop[2];
487
488
489
490
491 __s32 vbi_end;
492
493
494
495
496 __s32 crop_start;
497};
498
499static inline struct bttv *to_bttv(struct v4l2_device *v4l2_dev)
500{
501 return container_of(v4l2_dev, struct bttv, c.v4l2_dev);
502}
503
504
505#define BTTV_MAX 32
506extern unsigned int bttv_num;
507extern struct bttv *bttvs[BTTV_MAX];
508
509static inline unsigned int bttv_muxsel(const struct bttv *btv,
510 unsigned int input)
511{
512 return (bttv_tvcards[btv->c.type].muxsel >> (input * 2)) & 3;
513}
514
515#endif
516
517#define btwrite(dat,adr) writel((dat), btv->bt848_mmio+(adr))
518#define btread(adr) readl(btv->bt848_mmio+(adr))
519
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)
523
524#endif
525