2 bttv - Bt848 frame grabber driver
4 Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
5 & Marcus Metzler (mocm@thp.uni-koeln.de)
6 (c) 1999,2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/version.h>
24 #include <linux/module.h>
25 #include <linux/delay.h>
26 #include <linux/errno.h>
28 #include <linux/kernel.h>
29 #include <linux/major.h>
30 #include <linux/malloc.h>
32 #include <linux/poll.h>
33 #include <linux/pci.h>
34 #include <linux/signal.h>
36 #include <linux/ioport.h>
37 #include <asm/pgtable.h>
39 #include <linux/sched.h>
40 #include <asm/segment.h>
41 #include <linux/types.h>
42 #include <linux/wrapper.h>
43 #include <linux/interrupt.h>
44 #include <linux/kmod.h>
45 #include <linux/vmalloc.h>
46 #include <linux/init.h>
51 #define DEBUG(x) /* Debug driver */
52 #define MIN(a,b) (((a)>(b))?(b):(a))
53 #define MAX(a,b) (((a)>(b))?(a):(b))
55 static void bt848_set_risc_jmps(struct bttv
*btv
, int state
);
57 int bttv_num
; /* number of Bt848s in use */
58 struct bttv bttvs
[BTTV_MAX
];
60 /* configuration variables */
61 #if defined(__sparc__) || defined(__powerpc__) || defined(__hppa__)
62 static unsigned int bigendian
=1;
64 static unsigned int bigendian
=0;
66 static unsigned int radio
[BTTV_MAX
];
67 static unsigned int fieldnr
= 0;
68 static unsigned int irq_debug
= 0;
69 static unsigned int gbuffers
= 2;
70 static unsigned int gbufsize
= BTTV_MAX_FBUF
;
71 static unsigned int combfilter
= 0;
72 unsigned int bttv_debug
= 0;
73 unsigned int bttv_verbose
= 1;
74 unsigned int bttv_gpio
= 0;
77 MODULE_PARM(radio
,"1-4i");
78 MODULE_PARM_DESC(radio
,"The TV card supports radio, default is 0 (no)");
79 MODULE_PARM(bigendian
,"i");
80 MODULE_PARM_DESC(bigendian
,"byte order of the framebuffer, default is native endian");
81 MODULE_PARM(fieldnr
,"i");
82 MODULE_PARM_DESC(fieldnr
,"count fields, default is 0 (no)");
83 MODULE_PARM(bttv_verbose
,"i");
84 MODULE_PARM_DESC(bttv_verbose
,"verbose startup messages, default is 1 (yes)");
85 MODULE_PARM(bttv_gpio
,"i");
86 MODULE_PARM_DESC(bttv_gpio
,"log gpio changes, default is 0 (no)");
87 MODULE_PARM(bttv_debug
,"i");
88 MODULE_PARM_DESC(bttv_debug
,"debug messages, default is 0 (no)");
89 MODULE_PARM(irq_debug
,"i");
90 MODULE_PARM_DESC(irq_debug
,"irq handler debug messages, default is 0 (no)");
91 MODULE_PARM(gbuffers
,"i");
92 MODULE_PARM_DESC(gbuffers
,"number of capture buffers, default is 2 (64 max)");
93 MODULE_PARM(gbufsize
,"i");
94 MODULE_PARM_DESC(gbufsize
,"size of the capture buffers, default is 0x208000");
95 MODULE_PARM(combfilter
,"i");
97 MODULE_DESCRIPTION("bttv - v4l driver module for bt848/878 based cards");
98 MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr");
102 static int __init
p_radio(char *str
) { return bttv_parse(str
,BTTV_MAX
,radio
); }
103 __setup("bttv.radio=", p_radio
);
106 #define I2C_TIMING (0x7<<4)
109 #define I2C_SET(CTRL,DATA) \
110 { btwrite((CTRL<<1)|(DATA), BT848_I2C); udelay(I2C_DELAY); }
111 #define I2C_GET() (btread(BT848_I2C)&1)
113 #define BURSTOFFSET 76
114 #define BTTV_ERRORS 5
117 /*******************************/
118 /* Memory management functions */
119 /*******************************/
121 #define MDEBUG(x) do { } while(0) /* Debug memory management */
123 /* [DaveM] I've recoded most of this so that:
124 * 1) It's easier to tell what is happening
125 * 2) It's more portable, especially for translating things
126 * out of vmalloc mapped areas in the kernel.
127 * 3) Less unnecessary translations happen.
129 * The code used to assume that the kernel vmalloc mappings
130 * existed in the page tables of every process, this is simply
131 * not guarenteed. We now use pgd_offset_k which is the
132 * defined way to get at the kernel page tables.
135 /* Given PGD from the address space's page table, return the kernel
136 * virtual mapping of the physical memory mapped at ADR.
138 static inline unsigned long uvirt_to_kva(pgd_t
*pgd
, unsigned long adr
)
140 unsigned long ret
= 0UL;
144 if (!pgd_none(*pgd
)) {
145 pmd
= pmd_offset(pgd
, adr
);
146 if (!pmd_none(*pmd
)) {
147 ptep
= pte_offset(pmd
, adr
);
149 if(pte_present(pte
)) {
150 ret
= (unsigned long) page_address(pte_page(pte
));
151 ret
|= (adr
& (PAGE_SIZE
- 1));
156 MDEBUG(printk("uv2kva(%lx-->%lx)", adr
, ret
));
160 static inline unsigned long uvirt_to_bus(unsigned long adr
)
162 unsigned long kva
, ret
;
164 kva
= uvirt_to_kva(pgd_offset(current
->mm
, adr
), adr
);
165 ret
= virt_to_bus((void *)kva
);
166 MDEBUG(printk("uv2b(%lx-->%lx)", adr
, ret
));
170 static inline unsigned long kvirt_to_bus(unsigned long adr
)
172 unsigned long va
, kva
, ret
;
174 va
= VMALLOC_VMADDR(adr
);
175 kva
= uvirt_to_kva(pgd_offset_k(va
), va
);
176 ret
= virt_to_bus((void *)kva
);
177 MDEBUG(printk("kv2b(%lx-->%lx)", adr
, ret
));
181 /* Here we want the physical address of the memory.
182 * This is used when initializing the contents of the
183 * area and marking the pages as reserved.
185 static inline unsigned long kvirt_to_pa(unsigned long adr
)
187 unsigned long va
, kva
, ret
;
189 va
= VMALLOC_VMADDR(adr
);
190 kva
= uvirt_to_kva(pgd_offset_k(va
), va
);
192 MDEBUG(printk("kv2pa(%lx-->%lx)", adr
, ret
));
196 static void * rvmalloc(signed long size
)
199 unsigned long adr
, page
;
201 mem
=vmalloc_32(size
);
204 memset(mem
, 0, size
); /* Clear the ram out, no junk to the user */
205 adr
=(unsigned long) mem
;
208 page
= kvirt_to_pa(adr
);
209 mem_map_reserve(virt_to_page(__va(page
)));
217 static void rvfree(void * mem
, signed long size
)
219 unsigned long adr
, page
;
223 adr
=(unsigned long) mem
;
226 page
= kvirt_to_pa(adr
);
227 mem_map_unreserve(virt_to_page(__va(page
)));
238 * Create the giant waste of buffer space we need for now
239 * until we get DMA to user space sorted out (probably 2.3.x)
241 * We only create this as and when someone uses mmap
244 static int fbuffer_alloc(struct bttv
*btv
)
247 btv
->fbuffer
=(unsigned char *) rvmalloc(gbuffers
*gbufsize
);
249 printk(KERN_ERR
"bttv%d: Double alloc of fbuffer!\n",
257 /* init + register i2c algo-bit adapter */
258 static int __devinit
init_bttv_i2c(struct bttv
*btv
)
260 memcpy(&btv
->i2c_adap
, &bttv_i2c_adap_template
, sizeof(struct i2c_adapter
));
261 memcpy(&btv
->i2c_algo
, &bttv_i2c_algo_template
, sizeof(struct i2c_algo_bit_data
));
262 memcpy(&btv
->i2c_client
, &bttv_i2c_client_template
, sizeof(struct i2c_client
));
264 sprintf(btv
->i2c_adap
.name
+strlen(btv
->i2c_adap
.name
),
266 btv
->i2c_algo
.data
= btv
;
267 btv
->i2c_adap
.data
= btv
;
268 btv
->i2c_adap
.algo_data
= &btv
->i2c_algo
;
269 btv
->i2c_client
.adapter
= &btv
->i2c_adap
;
271 bttv_bit_setscl(btv
,1);
272 bttv_bit_setsda(btv
,1);
274 btv
->i2c_rc
= i2c_bit_add_bus(&btv
->i2c_adap
);
279 /* ----------------------------------------------------------------------- */
281 void bttv_gpio_tracking(struct bttv
*btv
, char *comment
)
283 unsigned int outbits
, data
;
284 outbits
= btread(BT848_GPIO_OUT_EN
);
285 data
= btread(BT848_GPIO_DATA
);
286 printk(KERN_DEBUG
"bttv%d: gpio: en=%08x, out=%08x in=%08x [%s]\n",
287 btv
->nr
,outbits
,data
& outbits
, data
& ~outbits
, comment
);
290 static char *audio_modes
[] = { "audio: tuner", "audio: radio", "audio: extern",
291 "audio: intern", "audio: off" };
293 static void audio(struct bttv
*btv
, int mode
, int no_irq_context
)
295 btaor(bttv_tvcards
[btv
->type
].gpiomask
, ~bttv_tvcards
[btv
->type
].gpiomask
,
301 btv
->audio
|=AUDIO_MUTE
;
304 btv
->audio
&=~AUDIO_MUTE
;
314 btv
->audio
&=AUDIO_MUTE
;
318 /* if audio mute or not in H-lock, turn audio off */
319 if ((btv
->audio
&AUDIO_MUTE
))
321 if ((mode
== AUDIO_TUNER
) && (btv
->radio
))
323 btaor(bttv_tvcards
[btv
->type
].audiomux
[mode
],
324 ~bttv_tvcards
[btv
->type
].gpiomask
, BT848_GPIO_DATA
);
326 bttv_gpio_tracking(btv
,audio_modes
[mode
]);
328 bttv_call_i2c_clients(btv
,AUDC_SET_INPUT
,&(mode
));
332 extern inline void bt848_dma(struct bttv
*btv
, uint state
)
335 btor(3, BT848_GPIO_DMA_CTL
);
337 btand(~3, BT848_GPIO_DMA_CTL
);
341 /* If Bt848a or Bt849, use PLL for PAL/SECAM and crystal for NTSC*/
343 /* Frequency = (F_input / PLL_X) * PLL_I.PLL_F/PLL_C
344 PLL_X = Reference pre-divider (0=1, 1=2)
345 PLL_C = Post divider (0=6, 1=4)
346 PLL_I = Integer input
347 PLL_F = Fractional input
349 F_input = 28.636363 MHz:
350 PAL (CLKx2 = 35.46895 MHz): PLL_X = 1, PLL_I = 0x0E, PLL_F = 0xDCF9, PLL_C = 0
353 static void set_pll_freq(struct bttv
*btv
, unsigned int fin
, unsigned int fout
)
355 unsigned char fl
, fh
, fi
;
357 /* prevent overflows */
370 /*printk("0x%02x 0x%02x 0x%02x\n", fi, fh, fl);*/
371 btwrite(fl
, BT848_PLL_F_LO
);
372 btwrite(fh
, BT848_PLL_F_HI
);
373 btwrite(fi
|BT848_PLL_X
, BT848_PLL_XCI
);
376 static int set_pll(struct bttv
*btv
)
381 if (!btv
->pll
.pll_crystal
)
384 if (btv
->pll
.pll_ifreq
== btv
->pll
.pll_ofreq
) {
386 if (btv
->pll
.pll_current
== 0) {
387 /* printk ("bttv%d: PLL: is off\n",btv->nr); */
391 printk ("bttv%d: PLL: switching off\n",btv
->nr
);
392 btwrite(0x00,BT848_TGCTRL
);
393 btwrite(0x00,BT848_PLL_XCI
);
394 btv
->pll
.pll_current
= 0;
398 if (btv
->pll
.pll_ofreq
== btv
->pll
.pll_current
) {
399 /* printk("bttv%d: PLL: no change required\n",btv->nr); */
404 printk("bttv%d: PLL: %d => %d ... ",btv
->nr
,
405 btv
->pll
.pll_ifreq
, btv
->pll
.pll_ofreq
);
407 set_pll_freq(btv
, btv
->pll
.pll_ifreq
, btv
->pll
.pll_ofreq
);
409 /* Let other people run while the PLL stabilizes */
410 tv
=jiffies
+HZ
/10; /* .1 seconds */
415 while(time_before(jiffies
,tv
));
417 for (i
=0; i
<100; i
++)
419 if ((btread(BT848_DSTATUS
)&BT848_DSTATUS_PLOCK
))
420 btwrite(0,BT848_DSTATUS
);
423 btwrite(0x08,BT848_TGCTRL
);
424 btv
->pll
.pll_current
= btv
->pll
.pll_ofreq
;
431 btv
->pll
.pll_current
= 0;
437 static void bt848_muxsel(struct bttv
*btv
, unsigned int input
)
440 #if 0 /* seems no card uses this ... */
441 btaor(bttv_tvcards
[btv
->type
].gpiomask2
,~bttv_tvcards
[btv
->type
].gpiomask2
,
445 /* This seems to get rid of some synchronization problems */
446 btand(~(3<<5), BT848_IFORM
);
449 input
%= bttv_tvcards
[btv
->type
].video_inputs
;
450 if (input
==bttv_tvcards
[btv
->type
].svhs
)
452 btor(BT848_CONTROL_COMP
, BT848_E_CONTROL
);
453 btor(BT848_CONTROL_COMP
, BT848_O_CONTROL
);
457 btand(~BT848_CONTROL_COMP
, BT848_E_CONTROL
);
458 btand(~BT848_CONTROL_COMP
, BT848_O_CONTROL
);
460 btaor((bttv_tvcards
[btv
->type
].muxsel
[input
&7]&3)<<5, ~(3<<5), BT848_IFORM
);
461 audio(btv
, (input
!=bttv_tvcards
[btv
->type
].tuner
) ?
462 AUDIO_EXTERN
: AUDIO_TUNER
, 1);
464 #if 0 /* seems no card uses this ... */
465 btaor(bttv_tvcards
[btv
->type
].muxsel
[input
]>>4,
466 ~bttv_tvcards
[btv
->type
].gpiomask2
, BT848_GPIO_DATA
);
468 bttv_gpio_tracking(btv
,"muxsel");
476 u16 swidth
, sheight
; /* scaled standard width, height */
478 u8 adelay
, bdelay
, iform
;
480 u16 hdelayx1
, hactivex1
;
485 static struct tvnorm tvnorms
[] = {
487 /* max. active video is actually 922, but 924 is divisible by 4 and 3! */
488 /* actually, max active PAL with HSCALE=0 is 948, NTSC is 768 - nil */
490 924, 576, 1135, 0x7f, 0x72, (BT848_IFORM_PAL_BDGHI
|BT848_IFORM_XT1
),
491 1135, 186, 924, 0x20, 255},
495 768, 480, 910, 0x68, 0x5d, (BT848_IFORM_NTSC
|BT848_IFORM_XT0
),
496 910, 128, 910, 0x1a, 144},
500 768, 576, 1135, 0x7f, 0xb0, (BT848_IFORM_SECAM
|BT848_IFORM_XT1
),
501 944, 186, 922, 0x20, 255},
505 924, 576, 1135, 0x7f, 0xb0, (BT848_IFORM_SECAM
|BT848_IFORM_XT1
),
506 1135, 186, 922, 0x20, 255},
510 640, 576, 910, 0x68, 0x5d, (BT848_IFORM_PAL_NC
|BT848_IFORM_XT0
),
511 780, 130, 734, 0x1a, 144},
514 640, 480, 910, 0x68, 0x5d, (BT848_IFORM_PAL_M
|BT848_IFORM_XT0
),
515 780, 135, 754, 0x1a, 144},
518 768, 576, 1135, 0x7f, 0x72, (BT848_IFORM_PAL_N
|BT848_IFORM_XT1
),
519 944, 186, 922, 0x20, 144},
522 640, 480, 910, 0x68, 0x5d, (BT848_IFORM_NTSC_J
|BT848_IFORM_XT0
),
523 780, 135, 754, 0x16, 144},
525 #define TVNORMS (sizeof(tvnorms)/sizeof(tvnorm))
528 /* RISC command to write one VBI data line */
529 #define VBI_RISC BT848_RISC_WRITE|VBI_SPL|BT848_RISC_EOL|BT848_RISC_SOL
531 static void make_vbitab(struct bttv
*btv
)
534 unsigned int *po
=(unsigned int *) btv
->vbi_odd
;
535 unsigned int *pe
=(unsigned int *) btv
->vbi_even
;
538 printk("bttv%d: vbi1: po=%08lx pe=%08lx\n",
539 btv
->nr
,virt_to_bus(po
), virt_to_bus(pe
));
541 *(po
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
); *(po
++)=0;
544 *(po
++)=cpu_to_le32(VBI_RISC
);
545 *(po
++)=cpu_to_le32(kvirt_to_bus((unsigned long)btv
->vbibuf
+i
*2048));
547 *(po
++)=cpu_to_le32(BT848_RISC_JUMP
);
548 *(po
++)=cpu_to_le32(virt_to_bus(btv
->risc_jmp
+4));
550 *(pe
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
); *(pe
++)=0;
551 for (i
=16; i
<32; i
++)
553 *(pe
++)=cpu_to_le32(VBI_RISC
);
554 *(pe
++)=cpu_to_le32(kvirt_to_bus((unsigned long)btv
->vbibuf
+i
*2048));
556 *(pe
++)=cpu_to_le32(BT848_RISC_JUMP
|BT848_RISC_IRQ
|(0x01<<16));
557 *(pe
++)=cpu_to_le32(virt_to_bus(btv
->risc_jmp
+10));
560 printk("bttv%d: vbi2: po=%08lx pe=%08lx\n",
561 btv
->nr
,virt_to_bus(po
), virt_to_bus(pe
));
564 static int fmtbppx2
[16] = {
565 8, 6, 4, 4, 4, 3, 2, 2, 4, 3, 0, 0, 0, 0, 2, 0
568 static int palette2fmt
[] = {
571 BT848_COLOR_FMT_RGB8
,
572 BT848_COLOR_FMT_RGB16
,
573 BT848_COLOR_FMT_RGB24
,
574 BT848_COLOR_FMT_RGB32
,
575 BT848_COLOR_FMT_RGB15
,
576 BT848_COLOR_FMT_YUY2
,
577 BT848_COLOR_FMT_BtYUV
,
582 BT848_COLOR_FMT_YCrCb422
,
583 BT848_COLOR_FMT_YCrCb411
,
584 BT848_COLOR_FMT_YCrCb422
,
585 BT848_COLOR_FMT_YCrCb411
,
587 #define PALETTEFMT_MAX (sizeof(palette2fmt)/sizeof(int))
589 static int make_rawrisctab(struct bttv
*btv
, unsigned int *ro
,
590 unsigned int *re
, unsigned int *vbuf
)
593 unsigned long bpl
=1024; /* bytes per line */
594 unsigned long vadr
=(unsigned long) vbuf
;
596 *(ro
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
597 *(ro
++)=cpu_to_le32(0);
598 *(re
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
599 *(re
++)=cpu_to_le32(0);
601 /* In PAL 650 blocks of 256 DWORDs are sampled, but only if VDELAY
602 is 2 and without separate VBI grabbing.
603 We'll have to handle this inside the IRQ handler ... */
605 for (line
=0; line
< 640; line
++)
607 *(ro
++)=cpu_to_le32(BT848_RISC_WRITE
|bpl
|BT848_RISC_SOL
|BT848_RISC_EOL
);
608 *(ro
++)=cpu_to_le32(kvirt_to_bus(vadr
));
609 *(re
++)=cpu_to_le32(BT848_RISC_WRITE
|bpl
|BT848_RISC_SOL
|BT848_RISC_EOL
);
610 *(re
++)=cpu_to_le32(kvirt_to_bus(vadr
+gbufsize
/2));
614 *(ro
++)=cpu_to_le32(BT848_RISC_JUMP
);
615 *(ro
++)=cpu_to_le32(btv
->bus_vbi_even
);
616 *(re
++)=cpu_to_le32(BT848_RISC_JUMP
|BT848_RISC_IRQ
|(2<<16));
617 *(re
++)=cpu_to_le32(btv
->bus_vbi_odd
);
622 static int make_prisctab(struct bttv
*btv
, unsigned int *ro
,
624 unsigned int *vbuf
, unsigned short width
,
625 unsigned short height
, unsigned short fmt
)
627 unsigned long line
, lmask
;
628 unsigned long bl
, blcr
, blcb
, rcmd
;
632 unsigned long cbadr
, cradr
;
633 unsigned long vadr
=(unsigned long) vbuf
;
637 printk("bttv%d: prisc1: ro=%08lx re=%08lx\n",
638 btv
->nr
,virt_to_bus(ro
), virt_to_bus(re
));
642 case VIDEO_PALETTE_YUV422P
:
643 csize
=(width
*height
)>>1;
648 case VIDEO_PALETTE_YUV411P
:
649 csize
=(width
*height
)>>2;
654 case VIDEO_PALETTE_YUV420P
:
655 csize
=(width
*height
)>>2;
660 case VIDEO_PALETTE_YUV410P
:
661 csize
=(width
*height
)>>4;
669 cbadr
=vadr
+(width
*height
);
671 inter
= (height
>tvnorms
[btv
->win
.norm
].sheight
/2) ? 1 : 0;
673 *(ro
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM3
);
675 *(re
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM3
);
678 for (line
=0; line
< (height
<<(1^inter
)); line
++)
683 cbadr
=vadr
+(width
*height
);
687 rp
= (line
&1) ? &re
: &ro
;
689 rp
= (line
>=height
) ? &ro
: &re
;
693 rcmd
=BT848_RISC_WRITE1S23
|BT848_RISC_SOL
;
695 rcmd
=BT848_RISC_WRITE123
|BT848_RISC_SOL
;
700 bl
=PAGE_SIZE
-((PAGE_SIZE
-1)&vadr
);
701 blcr
=(PAGE_SIZE
-((PAGE_SIZE
-1)&cradr
))<<shift
;
702 blcb
=(PAGE_SIZE
-((PAGE_SIZE
-1)&cbadr
))<<shift
;
703 bl
=(blcr
<bl
) ? blcr
: bl
;
704 bl
=(blcb
<bl
) ? blcb
: bl
;
705 bl
=(bl
>todo
) ? todo
: bl
;
708 /* bl now containts the longest row that can be written */
710 if(!todo
) rcmd
|=BT848_RISC_EOL
; /* if this is the last EOL */
712 *((*rp
)++)=cpu_to_le32(rcmd
|bl
);
713 *((*rp
)++)=cpu_to_le32(blcb
|(blcr
<<16));
714 *((*rp
)++)=cpu_to_le32(kvirt_to_bus(vadr
));
716 if((rcmd
&(15<<28))==BT848_RISC_WRITE123
)
718 *((*rp
)++)=(kvirt_to_bus(cbadr
));
720 *((*rp
)++)=cpu_to_le32(kvirt_to_bus(cradr
));
724 rcmd
&=~BT848_RISC_SOL
; /* only the first has SOL */
728 *(ro
++)=cpu_to_le32(BT848_RISC_JUMP
);
729 *(ro
++)=cpu_to_le32(btv
->bus_vbi_even
);
730 *(re
++)=cpu_to_le32(BT848_RISC_JUMP
|BT848_RISC_IRQ
|(2<<16));
731 *(re
++)=cpu_to_le32(btv
->bus_vbi_odd
);
734 printk("bttv%d: prisc2: ro=%08lx re=%08lx\n",
735 btv
->nr
,virt_to_bus(ro
), virt_to_bus(re
));
740 static int make_vrisctab(struct bttv
*btv
, unsigned int *ro
,
742 unsigned int *vbuf
, unsigned short width
,
743 unsigned short height
, unsigned short palette
)
746 unsigned long bpl
; /* bytes per line */
751 unsigned long vadr
=(unsigned long) vbuf
;
753 if (palette
==VIDEO_PALETTE_RAW
)
754 return make_rawrisctab(btv
, ro
, re
, vbuf
);
755 if (palette
>=VIDEO_PALETTE_PLANAR
)
756 return make_prisctab(btv
, ro
, re
, vbuf
, width
, height
, palette
);
759 printk("bttv%d: vrisc1: ro=%08lx re=%08lx\n",
760 btv
->nr
,virt_to_bus(ro
), virt_to_bus(re
));
762 inter
= (height
>tvnorms
[btv
->win
.norm
].sheight
/2) ? 1 : 0;
763 bpl
=width
*fmtbppx2
[palette2fmt
[palette
]&0xf]/2;
765 *(ro
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
766 *(ro
++)=cpu_to_le32(0);
767 *(re
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
768 *(re
++)=cpu_to_le32(0);
770 for (line
=0; line
< (height
<<(1^inter
)); line
++)
773 rp
= (line
&1) ? &re
: &ro
;
775 rp
= (line
>=height
) ? &ro
: &re
;
777 bl
=PAGE_SIZE
-((PAGE_SIZE
-1)&vadr
);
780 *((*rp
)++)=cpu_to_le32(BT848_RISC_WRITE
|BT848_RISC_SOL
|
782 *((*rp
)++)=cpu_to_le32(kvirt_to_bus(vadr
));
788 *((*rp
)++)=cpu_to_le32(BT848_RISC_WRITE
|BT848_RISC_SOL
|bl
);
789 *((*rp
)++)=cpu_to_le32(kvirt_to_bus(vadr
));
792 while (todo
>PAGE_SIZE
)
794 *((*rp
)++)=cpu_to_le32(BT848_RISC_WRITE
|PAGE_SIZE
);
795 *((*rp
)++)=cpu_to_le32(kvirt_to_bus(vadr
));
799 *((*rp
)++)=cpu_to_le32(BT848_RISC_WRITE
|BT848_RISC_EOL
|todo
);
800 *((*rp
)++)=cpu_to_le32(kvirt_to_bus(vadr
));
805 *(ro
++)=cpu_to_le32(BT848_RISC_JUMP
);
806 *(ro
++)=cpu_to_le32(btv
->bus_vbi_even
);
807 *(re
++)=cpu_to_le32(BT848_RISC_JUMP
|BT848_RISC_IRQ
|(2<<16));
808 *(re
++)=cpu_to_le32(btv
->bus_vbi_odd
);
811 printk("bttv%d: vrisc2: ro=%08lx re=%08lx\n",
812 btv
->nr
,virt_to_bus(ro
), virt_to_bus(re
));
817 static unsigned char lmaskt
[8] =
818 { 0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80};
819 static unsigned char rmaskt
[8] =
820 { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
822 static void clip_draw_rectangle(unsigned char *clipmap
, int x
, int y
, int w
, int h
)
824 unsigned char lmask
, rmask
, *p
;
829 printk("bttv clip: %dx%d+%d+%d\n",w
,h
,x
,y
);
831 /* bitmap is fixed width, 128 bytes (1024 pixels represented) */
842 if (w
< 0 || h
< 0) /* catch bad clips */
844 /* out of range data should just fall through */
854 rmask
=rmaskt
[(x
+w
-1)&7];
859 for (i
=0; i
<h
; i
++, p
+=128)
862 memset(p
+1, 0xff, W
);
866 for (i
=0; i
<h
; i
++, p
+=128)
872 for (i
=0; i
<h
; i
++, p
+=128)
879 static void make_clip_tab(struct bttv
*btv
, struct video_clip
*cr
, int ncr
)
881 int i
, line
, x
, y
, bpl
, width
, height
, inter
, maxw
;
882 unsigned int bpp
, dx
, sx
, **rp
, *ro
, *re
, flags
, len
;
884 unsigned char *clipmap
, *clipline
, cbit
, lastbit
, outofmem
;
886 /* take care: bpp != btv->win.bpp is allowed here */
887 bpp
= fmtbppx2
[btv
->win
.color_fmt
&0xf]/2;
889 adr
=btv
->win
.vidadr
+ btv
->win
.x
* btv
->win
.bpp
+ btv
->win
.y
* bpl
;
890 inter
=(btv
->win
.interlace
&1)^1;
891 width
=btv
->win
.width
;
892 height
=btv
->win
.height
;
894 printk("bttv%d: clip1: pal=%d size=%dx%d, bpl=%d bpp=%d\n",
895 btv
->nr
,btv
->picture
.palette
,width
,height
,bpl
,bpp
);
897 width
= 1023; /* sanity check */
899 height
= 625; /* sanity check */
900 ro
=btv
->risc_scr_odd
;
901 re
=btv
->risc_scr_even
;
904 printk("bttv%d: clip: ro=%08lx re=%08lx\n",
905 btv
->nr
,virt_to_bus(ro
), virt_to_bus(re
));
907 if ((clipmap
=vmalloc(VIDEO_CLIPMAP_SIZE
))==NULL
) {
908 /* can't clip, don't generate any risc code */
909 *(ro
++)=cpu_to_le32(BT848_RISC_JUMP
);
910 *(ro
++)=cpu_to_le32(btv
->bus_vbi_even
);
911 *(re
++)=cpu_to_le32(BT848_RISC_JUMP
);
912 *(re
++)=cpu_to_le32(btv
->bus_vbi_odd
);
914 if (ncr
< 0) { /* bitmap was pased */
915 memcpy(clipmap
, (unsigned char *)cr
, VIDEO_CLIPMAP_SIZE
);
916 } else { /* convert rectangular clips to a bitmap */
917 memset(clipmap
, 0, VIDEO_CLIPMAP_SIZE
); /* clear map */
918 for (i
=0; i
<ncr
; i
++)
919 clip_draw_rectangle(clipmap
, cr
[i
].x
, cr
[i
].y
,
920 cr
[i
].width
, cr
[i
].height
);
922 /* clip against viewing window AND screen
923 so we do not have to rely on the user program
925 maxw
= (bpl
- btv
->win
.x
* btv
->win
.bpp
) / bpp
;
926 clip_draw_rectangle(clipmap
, (width
> maxw
) ? maxw
: width
,
928 clip_draw_rectangle(clipmap
,0,(btv
->win
.y
+height
>btv
->win
.sheight
) ?
929 (btv
->win
.sheight
-btv
->win
.y
) : height
,1024,768);
931 clip_draw_rectangle(clipmap
, 0, 0, -(btv
->win
.x
), 768);
933 clip_draw_rectangle(clipmap
, 0, 0, 1024, -(btv
->win
.y
));
935 *(ro
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
936 *(ro
++)=cpu_to_le32(0);
937 *(re
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
938 *(re
++)=cpu_to_le32(0);
940 /* translate bitmap to risc code */
941 for (line
=outofmem
=0; line
< (height
<<inter
) && !outofmem
; line
++)
944 rp
= (line
&1) ? &re
: &ro
;
945 clipline
= clipmap
+ (y
<<7); /* running pointers ... */
946 lastbit
= *clipline
& 1;
947 for(x
=dx
=0,sx
=0; x
<=width
&& !outofmem
;) {
949 /* check bytes not bits if we can ... */
951 while (0xff==*clipline
&& x
<width
-8) {
957 while (0x00==*clipline
&& x
<width
-8) {
964 cbit
= *clipline
& (1<<(x
&7));
965 if (x
< width
&& !lastbit
== !cbit
) {
968 /* generate the dma controller code */
970 flags
= ((bpp
==4) ? BT848_RISC_BYTE3
: 0);
971 flags
|= ((!sx
) ? BT848_RISC_SOL
: 0);
972 flags
|= ((sx
+ dx
== width
) ? BT848_RISC_EOL
: 0);
974 *((*rp
)++)=cpu_to_le32(BT848_RISC_WRITE
|flags
|len
);
975 *((*rp
)++)=cpu_to_le32(adr
+ bpp
* sx
);
977 *((*rp
)++)=cpu_to_le32(BT848_RISC_SKIP
|flags
|len
);
982 if (ro
- btv
->risc_scr_odd
>(RISCMEM_LEN
>>3) - 16)
984 if (re
- btv
->risc_scr_even
>(RISCMEM_LEN
>>3) - 16)
991 if ((!inter
)||(line
&1))
996 /* outofmem flag relies on the following code to discard extra data */
997 *(ro
++)=cpu_to_le32(BT848_RISC_JUMP
);
998 *(ro
++)=cpu_to_le32(btv
->bus_vbi_even
);
999 *(re
++)=cpu_to_le32(BT848_RISC_JUMP
);
1000 *(re
++)=cpu_to_le32(btv
->bus_vbi_odd
);
1003 printk("bttv%d: clip2: pal=%d size=%dx%d, bpl=%d bpp=%d\n",
1004 btv
->nr
,btv
->picture
.palette
,width
,height
,bpl
,bpp
);
1008 * Set the registers for the size we have specified. Don't bother
1009 * trying to understand this without the BT848 manual in front of
1012 * PS: The manual is free for download in .pdf format from
1013 * www.brooktree.com - nicely done those folks.
1016 static inline void bt848_set_eogeo(struct bttv
*btv
, struct tvnorm
*tvn
,
1017 int odd
, int width
, int height
)
1023 int inter
= (height
>tvn
->sheight
/2) ? 0 : 1;
1024 int off
= odd
? 0x80 : 0x00;
1026 xsf
= (width
*tvn
->scaledtwidth
)/tvn
->swidth
;
1027 hscale
= ((tvn
->totalwidth
*4096UL)/xsf
-4096);
1028 hdelay
= tvn
->hdelayx1
;
1029 hdelay
= (hdelay
*width
)/tvn
->swidth
;
1031 sr
=((tvn
->sheight
>>inter
)*512)/height
-512;
1032 vscale
=(0x10000UL
-sr
)&0x1fff;
1033 crop
=((width
>>8)&0x03)|((hdelay
>>6)&0x0c)|
1034 ((tvn
->sheight
>>4)&0x30)|((tvn
->vdelay
>>2)&0xc0);
1035 vscale
|= inter
? (BT848_VSCALE_INT
<<8) : 0;
1038 /* Some people say interpolation looks bad ... */
1039 vtc
= (width
< 193) ? 2 : ((width
< 385) ? 1 : 0);
1041 btor(BT848_VSCALE_COMB
, BT848_E_VSCALE_HI
+off
);
1043 btand(~BT848_VSCALE_COMB
, BT848_E_VSCALE_HI
+off
);
1046 btand(~BT848_VSCALE_COMB
, BT848_E_VSCALE_HI
+off
);
1049 btwrite(vtc
, BT848_E_VTC
+off
);
1050 btwrite(hscale
>>8, BT848_E_HSCALE_HI
+off
);
1051 btwrite(hscale
&0xff, BT848_E_HSCALE_LO
+off
);
1052 btaor((vscale
>>8), 0xe0, BT848_E_VSCALE_HI
+off
);
1053 btwrite(vscale
&0xff, BT848_E_VSCALE_LO
+off
);
1054 btwrite(width
&0xff, BT848_E_HACTIVE_LO
+off
);
1055 btwrite(hdelay
&0xff, BT848_E_HDELAY_LO
+off
);
1056 btwrite(tvn
->sheight
&0xff, BT848_E_VACTIVE_LO
+off
);
1057 btwrite(tvn
->vdelay
&0xff, BT848_E_VDELAY_LO
+off
);
1058 btwrite(crop
, BT848_E_CROP
+off
);
1062 static void bt848_set_geo(struct bttv
*btv
,
1065 u16 ewidth
, eheight
, owidth
, oheight
;
1069 tvn
=&tvnorms
[btv
->win
.norm
];
1071 btwrite(tvn
->adelay
, BT848_ADELAY
);
1072 btwrite(tvn
->bdelay
, BT848_BDELAY
);
1073 btaor(tvn
->iform
,~(BT848_IFORM_NORM
|BT848_IFORM_XTBOTH
), BT848_IFORM
);
1074 btwrite(tvn
->vbipack
, BT848_VBI_PACK_SIZE
);
1075 btwrite(1, BT848_VBI_PACK_DEL
);
1077 btv
->pll
.pll_ofreq
= tvn
->Fsc
;
1081 btv
->win
.interlace
= (btv
->win
.height
>tvn
->sheight
/2) ? 1 : 0;
1083 if (0 == btv
->risc_cap_odd
&&
1084 0 == btv
->risc_cap_even
) {
1086 owidth
= btv
->win
.width
;
1087 oheight
= btv
->win
.height
;
1088 ewidth
= btv
->win
.width
;
1089 eheight
= btv
->win
.height
;
1090 format
= btv
->win
.color_fmt
;
1091 bswap
= btv
->fb_color_ctl
;
1092 } else if (-1 != btv
->gq_grab
&&
1093 0 == btv
->risc_cap_odd
&&
1094 !btv
->win
.interlace
&&
1096 /* odd field -> overlay, even field -> capture */
1097 owidth
= btv
->win
.width
;
1098 oheight
= btv
->win
.height
;
1099 ewidth
= btv
->gbuf
[btv
->gq_grab
].width
;
1100 eheight
= btv
->gbuf
[btv
->gq_grab
].height
;
1101 format
= (btv
->win
.color_fmt
& 0xf0) |
1102 (btv
->gbuf
[btv
->gq_grab
].fmt
& 0x0f);
1103 bswap
= btv
->fb_color_ctl
& 0x0a;
1106 owidth
= btv
->gbuf
[btv
->gq_grab
].width
;
1107 oheight
= btv
->gbuf
[btv
->gq_grab
].height
;
1108 ewidth
= btv
->gbuf
[btv
->gq_grab
].width
;
1109 eheight
= btv
->gbuf
[btv
->gq_grab
].height
;
1110 format
= btv
->gbuf
[btv
->gq_grab
].fmt
;
1114 /* program odd + even fields */
1115 bt848_set_eogeo(btv
, tvn
, 1, owidth
, oheight
);
1116 bt848_set_eogeo(btv
, tvn
, 0, ewidth
, eheight
);
1118 btwrite(format
, BT848_COLOR_FMT
);
1119 btwrite(bswap
| BT848_COLOR_CTL_GAMMA
, BT848_COLOR_CTL
);
1123 static int bpp2fmt
[4] = {
1124 BT848_COLOR_FMT_RGB8
, BT848_COLOR_FMT_RGB16
,
1125 BT848_COLOR_FMT_RGB24
, BT848_COLOR_FMT_RGB32
1128 static void bt848_set_winsize(struct bttv
*btv
)
1130 unsigned short format
;
1132 if (btv
->picture
.palette
> 0 && btv
->picture
.palette
<= VIDEO_PALETTE_YUV422
) {
1133 /* format set by VIDIOCSPICT */
1134 format
= palette2fmt
[btv
->picture
.palette
];
1136 /* use default for the given color depth */
1137 format
= (btv
->win
.depth
==15) ? BT848_COLOR_FMT_RGB15
:
1138 bpp2fmt
[(btv
->win
.bpp
-1)&3];
1140 btv
->win
.color_fmt
= format
;
1142 format
== BT848_COLOR_FMT_RGB32
) {
1144 BT848_COLOR_CTL_WSWAP_ODD
|
1145 BT848_COLOR_CTL_WSWAP_EVEN
|
1146 BT848_COLOR_CTL_BSWAP_ODD
|
1147 BT848_COLOR_CTL_BSWAP_EVEN
;
1148 } else if (bigendian
&&
1149 (format
== BT848_COLOR_FMT_RGB16
||
1150 format
== BT848_COLOR_FMT_RGB15
)) {
1152 BT848_COLOR_CTL_BSWAP_ODD
|
1153 BT848_COLOR_CTL_BSWAP_EVEN
;
1155 btv
->fb_color_ctl
= 0;
1158 /* RGB8 seems to be a 9x5x5 GRB color cube starting at
1159 * color 16. Why the h... can't they even mention this in the
1160 * data sheet? [AC - because it's a standard format so I guess
1161 * it never occurred to them]
1162 * Enable dithering in this mode.
1165 if (format
==BT848_COLOR_FMT_RGB8
)
1166 btand(~BT848_CAP_CTL_DITH_FRAME
, BT848_CAP_CTL
);
1168 btor(BT848_CAP_CTL_DITH_FRAME
, BT848_CAP_CTL
);
1170 bt848_set_geo(btv
,1);
1174 * Grab into virtual memory.
1177 static int vgrab(struct bttv
*btv
, struct video_mmap
*mp
)
1179 unsigned int *ro
, *re
;
1181 unsigned long flags
;
1183 if(btv
->fbuffer
==NULL
)
1185 if(fbuffer_alloc(btv
))
1189 if(mp
->frame
>= gbuffers
|| mp
->frame
< 0)
1191 if(btv
->gbuf
[mp
->frame
].stat
!= GBUFFER_UNUSED
)
1194 if(mp
->height
< 32 || mp
->width
< 32)
1196 if (mp
->format
>= PALETTEFMT_MAX
)
1199 if (mp
->height
*mp
->width
*fmtbppx2
[palette2fmt
[mp
->format
]&0x0f]/2
1202 if(-1 == palette2fmt
[mp
->format
])
1206 * Ok load up the BT848
1209 vbuf
=(unsigned int *)(btv
->fbuffer
+gbufsize
*mp
->frame
);
1210 ro
=btv
->gbuf
[mp
->frame
].risc
;
1212 make_vrisctab(btv
, ro
, re
, vbuf
, mp
->width
, mp
->height
, mp
->format
);
1215 printk("bttv%d: cap vgrab: queue %d (%d:%dx%d)\n",
1216 btv
->nr
,mp
->frame
,mp
->format
,mp
->width
,mp
->height
);
1217 spin_lock_irqsave(&btv
->s_lock
, flags
);
1218 btv
->gbuf
[mp
->frame
].stat
= GBUFFER_GRABBING
;
1219 btv
->gbuf
[mp
->frame
].fmt
= palette2fmt
[mp
->format
];
1220 btv
->gbuf
[mp
->frame
].width
= mp
->width
;
1221 btv
->gbuf
[mp
->frame
].height
= mp
->height
;
1222 btv
->gbuf
[mp
->frame
].ro
= virt_to_bus(ro
);
1223 btv
->gbuf
[mp
->frame
].re
= virt_to_bus(re
);
1226 if (mp
->height
<= tvnorms
[btv
->win
.norm
].sheight
/2 &&
1227 mp
->format
!= VIDEO_PALETTE_RAW
)
1228 btv
->gbuf
[mp
->frame
].ro
= 0;
1231 if (-1 == btv
->gq_grab
&& btv
->gq_in
== btv
->gq_out
) {
1233 btv
->risc_jmp
[12]=cpu_to_le32(BT848_RISC_JUMP
|(0x8<<16)|BT848_RISC_IRQ
);
1235 btv
->gqueue
[btv
->gq_in
++] = mp
->frame
;
1236 btv
->gq_in
= btv
->gq_in
% MAX_GBUFFERS
;
1238 btor(3, BT848_CAP_CTL
);
1239 btor(3, BT848_GPIO_DMA_CTL
);
1240 spin_unlock_irqrestore(&btv
->s_lock
, flags
);
1244 static long bttv_write(struct video_device
*v
, const char *buf
, unsigned long count
, int nonblock
)
1249 static long bttv_read(struct video_device
*v
, char *buf
, unsigned long count
, int nonblock
)
1251 struct bttv
*btv
= (struct bttv
*)v
;
1253 DECLARE_WAITQUEUE(wait
, current
);
1255 /* BROKEN: RETURNS VBI WHEN IT SHOULD RETURN GRABBED VIDEO FRAME */
1257 while (todo
&& todo
>(q
=VBIBUF_SIZE
-btv
->vbip
))
1259 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, q
))
1264 add_wait_queue(&btv
->vbiq
, &wait
);
1265 current
->state
= TASK_INTERRUPTIBLE
;
1266 if (todo
&& q
==VBIBUF_SIZE
-btv
->vbip
)
1270 remove_wait_queue(&btv
->vbiq
, &wait
);
1271 current
->state
= TASK_RUNNING
;
1273 return -EWOULDBLOCK
;
1277 if(signal_pending(current
))
1279 remove_wait_queue(&btv
->vbiq
, &wait
);
1280 current
->state
= TASK_RUNNING
;
1288 remove_wait_queue(&btv
->vbiq
, &wait
);
1289 current
->state
= TASK_RUNNING
;
1293 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, todo
))
1300 static inline void burst(int on
)
1302 tvnorms
[0].scaledtwidth
= 1135 - (on
?BURSTOFFSET
-2:0);
1303 tvnorms
[0].hdelayx1
= 186 - (on
?BURSTOFFSET
:0);
1304 tvnorms
[2].scaledtwidth
= 1135 - (on
?BURSTOFFSET
-2:0);
1305 tvnorms
[2].hdelayx1
= 186 - (on
?BURSTOFFSET
:0);
1309 * called from irq handler on fatal errors. Takes the grabber chip
1310 * offline, flag it needs a reinitialization (which can't be done
1311 * from irq context) and wake up all sleeping proccesses. They would
1312 * block forever else. We also need someone who actually does the
1313 * reinitialization from process context...
1315 static void bt848_offline(struct bttv
*btv
)
1318 spin_lock(&btv
->s_lock
);
1320 /* cancel all outstanding grab requests */
1324 for (i
= 0; i
< gbuffers
; i
++)
1325 if (btv
->gbuf
[i
].stat
== GBUFFER_GRABBING
)
1326 btv
->gbuf
[i
].stat
= GBUFFER_ERROR
;
1328 /* disable screen overlay and DMA */
1329 btv
->risc_cap_odd
= 0;
1330 btv
->risc_cap_even
= 0;
1331 bt848_set_risc_jmps(btv
,0);
1333 /* flag the chip needs a restart */
1334 btv
->needs_restart
= 1;
1335 spin_unlock(&btv
->s_lock
);
1337 wake_up_interruptible(&btv
->vbiq
);
1338 wake_up_interruptible(&btv
->capq
);
1341 static void bt848_restart(struct bttv
*btv
)
1343 unsigned long irq_flags
;
1346 printk("bttv%d: resetting chip\n",btv
->nr
);
1347 btwrite(0xfffffUL
, BT848_INT_STAT
);
1348 btand(~15, BT848_GPIO_DMA_CTL
);
1349 btwrite(0, BT848_SRESET
);
1350 btwrite(virt_to_bus(btv
->risc_jmp
+2),
1351 BT848_RISC_STRT_ADD
);
1353 /* enforce pll reprogramming */
1354 btv
->pll
.pll_current
= 0;
1357 spin_lock_irqsave(&btv
->s_lock
, irq_flags
);
1359 btv
->needs_restart
= 0;
1360 bt848_set_geo(btv
,0);
1361 bt848_set_risc_jmps(btv
,-1);
1362 spin_unlock_irqrestore(&btv
->s_lock
, irq_flags
);
1366 * Open a bttv card. Right now the flags stuff is just playing
1369 static int bttv_open(struct video_device
*dev
, int flags
)
1371 struct bttv
*btv
= (struct bttv
*)dev
;
1376 printk("bttv%d: open called\n",btv
->nr
);
1383 btv
->fbuffer
=(unsigned char *) rvmalloc(gbuffers
*gbufsize
);
1391 for (i
= 0; i
< gbuffers
; i
++)
1392 btv
->gbuf
[i
].stat
= GBUFFER_UNUSED
;
1394 if (btv
->needs_restart
)
1408 static void bttv_close(struct video_device
*dev
)
1410 struct bttv
*btv
=(struct bttv
*)dev
;
1411 unsigned long irq_flags
;
1415 spin_lock_irqsave(&btv
->s_lock
, irq_flags
);
1417 btv
->risc_cap_odd
= 0;
1418 btv
->risc_cap_even
= 0;
1419 bt848_set_risc_jmps(btv
,-1);
1420 spin_unlock_irqrestore(&btv
->s_lock
, irq_flags
);
1423 * A word of warning. At this point the chip
1424 * is still capturing because its FIFO hasn't emptied
1425 * and the DMA control operations are posted PCI
1429 btread(BT848_I2C
); /* This fixes the PCI posting delay */
1431 if (-1 != btv
->gq_grab
) {
1433 * This is sucky but right now I can't find a good way to
1434 * be sure its safe to free the buffer. We wait 5-6 fields
1435 * which is more than sufficient to be sure.
1437 current
->state
= TASK_UNINTERRUPTIBLE
;
1438 schedule_timeout(HZ
/10); /* Wait 1/10th of a second */
1442 * We have allowed it to drain.
1446 rvfree((void *) btv
->fbuffer
, gbuffers
*gbufsize
);
1453 /***********************************/
1454 /* ioctls and supporting functions */
1455 /***********************************/
1457 extern inline void bt848_bright(struct bttv
*btv
, uint bright
)
1459 btwrite(bright
&0xff, BT848_BRIGHT
);
1462 extern inline void bt848_hue(struct bttv
*btv
, uint hue
)
1464 btwrite(hue
&0xff, BT848_HUE
);
1467 extern inline void bt848_contrast(struct bttv
*btv
, uint cont
)
1469 unsigned int conthi
;
1472 btwrite(cont
&0xff, BT848_CONTRAST_LO
);
1473 btaor(conthi
, ~4, BT848_E_CONTROL
);
1474 btaor(conthi
, ~4, BT848_O_CONTROL
);
1477 extern inline void bt848_sat_u(struct bttv
*btv
, unsigned long data
)
1482 btwrite(data
&0xff, BT848_SAT_U_LO
);
1483 btaor(datahi
, ~2, BT848_E_CONTROL
);
1484 btaor(datahi
, ~2, BT848_O_CONTROL
);
1487 static inline void bt848_sat_v(struct bttv
*btv
, unsigned long data
)
1492 btwrite(data
&0xff, BT848_SAT_V_LO
);
1493 btaor(datahi
, ~1, BT848_E_CONTROL
);
1494 btaor(datahi
, ~1, BT848_O_CONTROL
);
1502 static int bttv_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
1504 struct bttv
*btv
=(struct bttv
*)dev
;
1505 unsigned long irq_flags
;
1509 printk("bttv%d: ioctl 0x%x\n",btv
->nr
,cmd
);
1514 struct video_capability b
;
1515 strcpy(b
.name
,btv
->video_dev
.name
);
1516 b
.type
= VID_TYPE_CAPTURE
|
1517 ((bttv_tvcards
[btv
->type
].tuner
!= -1) ? VID_TYPE_TUNER
: 0) |
1522 b
.channels
= bttv_tvcards
[btv
->type
].video_inputs
;
1523 b
.audios
= bttv_tvcards
[btv
->type
].audio_inputs
;
1524 b
.maxwidth
= tvnorms
[btv
->win
.norm
].swidth
;
1525 b
.maxheight
= tvnorms
[btv
->win
.norm
].sheight
;
1528 if(copy_to_user(arg
,&b
,sizeof(b
)))
1534 struct video_channel v
;
1535 if(copy_from_user(&v
, arg
,sizeof(v
)))
1537 v
.flags
=VIDEO_VC_AUDIO
;
1539 v
.type
=VIDEO_TYPE_CAMERA
;
1540 v
.norm
= btv
->win
.norm
;
1541 if (v
.channel
>=bttv_tvcards
[btv
->type
].video_inputs
)
1543 if(v
.channel
==bttv_tvcards
[btv
->type
].tuner
)
1545 strcpy(v
.name
,"Television");
1546 v
.flags
|=VIDEO_VC_TUNER
;
1547 v
.type
=VIDEO_TYPE_TV
;
1550 else if(v
.channel
==bttv_tvcards
[btv
->type
].svhs
)
1551 strcpy(v
.name
,"S-Video");
1553 sprintf(v
.name
,"Composite%d",v
.channel
);
1555 if(copy_to_user(arg
,&v
,sizeof(v
)))
1560 * Each channel has 1 tuner
1564 struct video_channel v
;
1565 if(copy_from_user(&v
, arg
,sizeof(v
)))
1568 if (v
.channel
>bttv_tvcards
[btv
->type
].video_inputs
)
1570 if (v
.norm
> (sizeof(tvnorms
)/sizeof(*tvnorms
)))
1573 bttv_call_i2c_clients(btv
,cmd
,&v
);
1575 bt848_muxsel(btv
, v
.channel
);
1576 btv
->channel
=v
.channel
;
1577 if (btv
->win
.norm
!= v
.norm
) {
1578 btv
->win
.norm
= v
.norm
;
1580 spin_lock_irqsave(&btv
->s_lock
, irq_flags
);
1581 bt848_set_winsize(btv
);
1582 spin_unlock_irqrestore(&btv
->s_lock
, irq_flags
);
1589 struct video_tuner v
;
1590 if(copy_from_user(&v
,arg
,sizeof(v
))!=0)
1592 if(v
.tuner
||btv
->channel
) /* Only tuner 0 */
1594 strcpy(v
.name
, "Television");
1596 v
.rangehigh
=0xFFFFFFFF;
1597 v
.flags
=VIDEO_TUNER_PAL
|VIDEO_TUNER_NTSC
|VIDEO_TUNER_SECAM
;
1598 v
.mode
= btv
->win
.norm
;
1599 v
.signal
= (btread(BT848_DSTATUS
)&BT848_DSTATUS_HLOC
) ? 0xFFFF : 0;
1600 bttv_call_i2c_clients(btv
,cmd
,&v
);
1601 if(copy_to_user(arg
,&v
,sizeof(v
)))
1605 /* We have but one tuner */
1608 struct video_tuner v
;
1609 if(copy_from_user(&v
, arg
, sizeof(v
)))
1611 /* Only one channel has a tuner */
1612 if(v
.tuner
!=bttv_tvcards
[btv
->type
].tuner
)
1615 if(v
.mode
!=VIDEO_MODE_PAL
&&v
.mode
!=VIDEO_MODE_NTSC
1616 &&v
.mode
!=VIDEO_MODE_SECAM
)
1618 bttv_call_i2c_clients(btv
,cmd
,&v
);
1619 if (btv
->win
.norm
!= v
.mode
) {
1620 btv
->win
.norm
= v
.mode
;
1624 spin_lock_irqsave(&btv
->s_lock
, irq_flags
);
1625 bt848_set_winsize(btv
);
1626 spin_unlock_irqrestore(&btv
->s_lock
, irq_flags
);
1633 struct video_picture p
=btv
->picture
;
1634 if(copy_to_user(arg
, &p
, sizeof(p
)))
1640 struct video_picture p
;
1641 if(copy_from_user(&p
, arg
,sizeof(p
)))
1643 if (p
.palette
> PALETTEFMT_MAX
)
1646 /* We want -128 to 127 we get 0-65535 */
1647 bt848_bright(btv
, (p
.brightness
>>8)-128);
1648 /* 0-511 for the colour */
1649 bt848_sat_u(btv
, p
.colour
>>7);
1650 bt848_sat_v(btv
, ((p
.colour
>>7)*201L)/237);
1652 bt848_hue(btv
, (p
.hue
>>8)-128);
1654 bt848_contrast(btv
, p
.contrast
>>7);
1661 struct video_window vw
;
1662 struct video_clip
*vcp
= NULL
;
1664 if(copy_from_user(&vw
,arg
,sizeof(vw
)))
1668 if(vw
.flags
|| vw
.width
< 16 || vw
.height
< 16)
1670 spin_lock_irqsave(&btv
->s_lock
, irq_flags
);
1672 bt848_set_risc_jmps(btv
,-1);
1673 spin_unlock_irqrestore(&btv
->s_lock
, irq_flags
);
1677 if (btv
->win
.bpp
< 4)
1678 { /* adjust and align writes */
1679 vw
.x
= (vw
.x
+ 3) & ~3;
1682 if (btv
->needs_restart
)
1686 btv
->win
.width
=vw
.width
;
1687 btv
->win
.height
=vw
.height
;
1689 spin_lock_irqsave(&btv
->s_lock
, irq_flags
);
1690 bt848_set_risc_jmps(btv
,0);
1691 bt848_set_winsize(btv
);
1692 spin_unlock_irqrestore(&btv
->s_lock
, irq_flags
);
1697 if(vw
.clipcount
<0) {
1698 if((vcp
=vmalloc(VIDEO_CLIPMAP_SIZE
))==NULL
) {
1702 if(copy_from_user(vcp
, vw
.clips
,
1703 VIDEO_CLIPMAP_SIZE
)) {
1708 } else if (vw
.clipcount
) {
1709 if((vcp
=vmalloc(sizeof(struct video_clip
)*
1710 (vw
.clipcount
))) == NULL
) {
1714 if(copy_from_user(vcp
,vw
.clips
,
1715 sizeof(struct video_clip
)*
1722 make_clip_tab(btv
, vcp
, vw
.clipcount
);
1723 if (vw
.clipcount
!= 0)
1725 spin_lock_irqsave(&btv
->s_lock
, irq_flags
);
1726 bt848_set_risc_jmps(btv
,-1);
1727 spin_unlock_irqrestore(&btv
->s_lock
, irq_flags
);
1733 struct video_window vw
;
1734 /* Oh for a COBOL move corresponding .. */
1737 vw
.width
=btv
->win
.width
;
1738 vw
.height
=btv
->win
.height
;
1741 if(btv
->win
.interlace
)
1742 vw
.flags
|=VIDEO_WINDOW_INTERLACE
;
1743 if(copy_to_user(arg
,&vw
,sizeof(vw
)))
1750 if(copy_from_user(&v
, arg
,sizeof(v
)))
1752 if(btv
->win
.vidadr
== 0)
1754 if (btv
->win
.width
==0 || btv
->win
.height
==0)
1756 spin_lock_irqsave(&btv
->s_lock
, irq_flags
);
1757 if (v
== 1 && btv
->win
.vidadr
!= 0)
1761 bt848_set_risc_jmps(btv
,-1);
1762 spin_unlock_irqrestore(&btv
->s_lock
, irq_flags
);
1767 struct video_buffer v
;
1768 v
.base
=(void *)btv
->win
.vidadr
;
1769 v
.height
=btv
->win
.sheight
;
1770 v
.width
=btv
->win
.swidth
;
1771 v
.depth
=btv
->win
.depth
;
1772 v
.bytesperline
=btv
->win
.bpl
;
1773 if(copy_to_user(arg
, &v
,sizeof(v
)))
1780 struct video_buffer v
;
1781 if(!capable(CAP_SYS_ADMIN
) &&
1782 !capable(CAP_SYS_RAWIO
))
1784 if(copy_from_user(&v
, arg
,sizeof(v
)))
1786 if(v
.depth
!=8 && v
.depth
!=15 && v
.depth
!=16 &&
1787 v
.depth
!=24 && v
.depth
!=32 && v
.width
> 16 &&
1788 v
.height
> 16 && v
.bytesperline
> 16)
1792 btv
->win
.vidadr
=(unsigned long)v
.base
;
1793 btv
->win
.sheight
=v
.height
;
1794 btv
->win
.swidth
=v
.width
;
1795 btv
->win
.bpp
=((v
.depth
+7)&0x38)/8;
1796 btv
->win
.depth
=v
.depth
;
1797 btv
->win
.bpl
=v
.bytesperline
;
1799 /* set sefault color format */
1800 switch (btv
->win
.bpp
) {
1801 case 8: btv
->picture
.palette
= VIDEO_PALETTE_HI240
; break;
1802 case 15: btv
->picture
.palette
= VIDEO_PALETTE_RGB555
; break;
1803 case 16: btv
->picture
.palette
= VIDEO_PALETTE_RGB565
; break;
1804 case 24: btv
->picture
.palette
= VIDEO_PALETTE_RGB24
; break;
1805 case 32: btv
->picture
.palette
= VIDEO_PALETTE_RGB32
; break;
1809 printk("Display at %p is %d by %d, bytedepth %d, bpl %d\n",
1810 v
.base
, v
.width
,v
.height
, btv
->win
.bpp
, btv
->win
.bpl
);
1811 spin_lock_irqsave(&btv
->s_lock
, irq_flags
);
1812 bt848_set_winsize(btv
);
1813 spin_unlock_irqrestore(&btv
->s_lock
, irq_flags
);
1819 /* Will be handled higher up .. */
1824 unsigned long v
=btv
->win
.freq
;
1825 if(copy_to_user(arg
,&v
,sizeof(v
)))
1832 if(copy_from_user(&v
, arg
, sizeof(v
)))
1835 bttv_call_i2c_clients(btv
,cmd
,&v
);
1837 if (btv
->type
== BTTV_MIROPRO
&& btv
->radio
)
1838 tea5757_set_freq(btv
,v
);
1845 struct video_audio v
;
1848 v
.flags
&=~(VIDEO_AUDIO_MUTE
|VIDEO_AUDIO_MUTABLE
);
1849 v
.flags
|=VIDEO_AUDIO_MUTABLE
;
1850 strcpy(v
.name
,"TV");
1852 v
.mode
= VIDEO_SOUND_MONO
;
1853 bttv_call_i2c_clients(btv
,cmd
,&v
);
1855 /* card specific hooks */
1856 if (bttv_tvcards
[btv
->type
].audio_hook
)
1857 bttv_tvcards
[btv
->type
].audio_hook(btv
,&v
,0);
1859 if(copy_to_user(arg
,&v
,sizeof(v
)))
1865 struct video_audio v
;
1867 if(copy_from_user(&v
,arg
, sizeof(v
)))
1870 if(v
.flags
&VIDEO_AUDIO_MUTE
)
1871 audio(btv
, AUDIO_MUTE
, 1);
1872 /* One audio source per tuner -- huh? <GA> */
1873 if(v
.audio
<0 || v
.audio
>= bttv_tvcards
[btv
->type
].audio_inputs
) {
1877 /* bt848_muxsel(btv,v.audio); */
1878 if(!(v
.flags
&VIDEO_AUDIO_MUTE
))
1879 audio(btv
, AUDIO_UNMUTE
, 1);
1881 bttv_call_i2c_clients(btv
,cmd
,&v
);
1883 /* card specific hooks */
1884 if (bttv_tvcards
[btv
->type
].audio_hook
)
1885 bttv_tvcards
[btv
->type
].audio_hook(btv
,&v
,0);
1894 DECLARE_WAITQUEUE(wait
, current
);
1896 if(copy_from_user((void *)&i
,arg
,sizeof(int)))
1898 if (i
< 0 || i
>= gbuffers
)
1900 switch (btv
->gbuf
[i
].stat
) {
1901 case GBUFFER_UNUSED
:
1904 case GBUFFER_GRABBING
:
1905 add_wait_queue(&btv
->capq
, &wait
);
1906 current
->state
= TASK_INTERRUPTIBLE
;
1907 while(btv
->gbuf
[i
].stat
==GBUFFER_GRABBING
) {
1909 printk("bttv%d: cap sync: sleep on %d\n",btv
->nr
,i
);
1911 if(signal_pending(current
)) {
1912 remove_wait_queue(&btv
->capq
, &wait
);
1913 current
->state
= TASK_RUNNING
;
1917 remove_wait_queue(&btv
->capq
, &wait
);
1918 current
->state
= TASK_RUNNING
;
1922 ret
= (btv
->gbuf
[i
].stat
== GBUFFER_ERROR
) ? -EIO
: 0;
1924 printk("bttv%d: cap sync: buffer %d, retval %d\n",btv
->nr
,i
,ret
);
1925 btv
->gbuf
[i
].stat
= GBUFFER_UNUSED
;
1927 if (btv
->needs_restart
) {
1936 if(copy_to_user((void *) arg
, (void *) &btv
->last_field
,
1937 sizeof(btv
->last_field
)))
1942 struct bttv_pll_info p
;
1943 if(!capable(CAP_SYS_ADMIN
))
1945 if(copy_from_user(&p
, (void *) arg
, sizeof(btv
->pll
)))
1948 btv
->pll
.pll_ifreq
= p
.pll_ifreq
;
1949 btv
->pll
.pll_ofreq
= p
.pll_ofreq
;
1950 btv
->pll
.pll_crystal
= p
.pll_crystal
;
1955 case VIDIOCMCAPTURE
:
1957 struct video_mmap vm
;
1959 if(copy_from_user((void *) &vm
, (void *) arg
, sizeof(vm
)))
1962 ret
= vgrab(btv
, &vm
);
1969 struct video_mbuf vm
;
1970 memset(&vm
, 0 , sizeof(vm
));
1971 vm
.size
=gbufsize
*gbuffers
;
1973 for (i
= 0; i
< gbuffers
; i
++)
1974 vm
.offsets
[i
]=i
*gbufsize
;
1975 if(copy_to_user((void *)arg
, (void *)&vm
, sizeof(vm
)))
1982 struct video_unit vu
;
1983 vu
.video
=btv
->video_dev
.minor
;
1984 vu
.vbi
=btv
->vbi_dev
.minor
;
1985 if(btv
->radio_dev
.minor
!=-1)
1986 vu
.radio
=btv
->radio_dev
.minor
;
1988 vu
.radio
=VIDEO_NO_UNIT
;
1989 vu
.audio
=VIDEO_NO_UNIT
;
1990 vu
.teletext
=VIDEO_NO_UNIT
;
1991 if(copy_to_user((void *)arg
, (void *)&vu
, sizeof(vu
)))
2002 case BTTV_BURST_OFF
:
2010 return BTTV_VERSION_CODE
;
2015 /* return picture;*/
2020 return -ENOIOCTLCMD
;
2026 * This maps the vmalloced and reserved fbuffer to user space.
2029 * - PAGE_READONLY should suffice!?
2030 * - remap_page_range is kind of inefficient for page by page remapping.
2031 * But e.g. pte_alloc() does not work in modules ... :-(
2034 static int do_bttv_mmap(struct bttv
*btv
, const char *adr
, unsigned long size
)
2036 unsigned long start
=(unsigned long) adr
;
2037 unsigned long page
,pos
;
2039 if (size
>gbuffers
*gbufsize
)
2041 if (!btv
->fbuffer
) {
2042 if(fbuffer_alloc(btv
))
2045 pos
=(unsigned long) btv
->fbuffer
;
2047 page
= kvirt_to_pa(pos
);
2048 if (remap_page_range(start
, page
, PAGE_SIZE
, PAGE_SHARED
))
2057 static int bttv_mmap(struct video_device
*dev
, const char *adr
, unsigned long size
)
2059 struct bttv
*btv
=(struct bttv
*)dev
;
2063 r
=do_bttv_mmap(btv
, adr
, size
);
2069 static struct video_device bttv_template
=
2072 type
: VID_TYPE_TUNER
|VID_TYPE_CAPTURE
|VID_TYPE_OVERLAY
|VID_TYPE_TELETEXT
,
2073 hardware
: VID_HARDWARE_BT848
,
2084 static long vbi_read(struct video_device
*v
, char *buf
, unsigned long count
,
2087 struct bttv
*btv
=(struct bttv
*)(v
-2);
2089 DECLARE_WAITQUEUE(wait
, current
);
2092 while (todo
&& todo
>(q
=VBIBUF_SIZE
-btv
->vbip
))
2094 if (btv
->needs_restart
) {
2099 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, q
))
2104 add_wait_queue(&btv
->vbiq
, &wait
);
2105 current
->state
= TASK_INTERRUPTIBLE
;
2106 if (todo
&& q
==VBIBUF_SIZE
-btv
->vbip
)
2110 remove_wait_queue(&btv
->vbiq
, &wait
);
2111 current
->state
= TASK_RUNNING
;
2113 return -EWOULDBLOCK
;
2117 if(signal_pending(current
))
2119 remove_wait_queue(&btv
->vbiq
, &wait
);
2120 current
->state
= TASK_RUNNING
;
2127 remove_wait_queue(&btv
->vbiq
, &wait
);
2128 current
->state
= TASK_RUNNING
;
2132 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, todo
))
2139 static unsigned int vbi_poll(struct video_device
*dev
, struct file
*file
,
2142 struct bttv
*btv
=(struct bttv
*)(dev
-2);
2143 unsigned int mask
= 0;
2145 poll_wait(file
, &btv
->vbiq
, wait
);
2147 if (btv
->vbip
< VBIBUF_SIZE
)
2148 mask
|= (POLLIN
| POLLRDNORM
);
2153 static int vbi_open(struct video_device
*dev
, int flags
)
2155 struct bttv
*btv
=(struct bttv
*)(dev
-2);
2156 unsigned long irq_flags
;
2160 if (btv
->needs_restart
)
2163 btv
->vbip
=VBIBUF_SIZE
;
2164 spin_lock_irqsave(&btv
->s_lock
, irq_flags
);
2166 bt848_set_risc_jmps(btv
,-1);
2167 spin_unlock_irqrestore(&btv
->s_lock
, irq_flags
);
2173 static void vbi_close(struct video_device
*dev
)
2175 struct bttv
*btv
=(struct bttv
*)(dev
-2);
2176 unsigned long irq_flags
;
2178 spin_lock_irqsave(&btv
->s_lock
, irq_flags
);
2180 bt848_set_risc_jmps(btv
,-1);
2181 spin_unlock_irqrestore(&btv
->s_lock
, irq_flags
);
2185 static int vbi_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
2187 struct bttv
*btv
=(struct bttv
*)dev
;
2192 struct video_capability b
;
2193 strcpy(b
.name
,btv
->vbi_dev
.name
);
2194 b
.type
= ((bttv_tvcards
[btv
->type
].tuner
!= -1) ? VID_TYPE_TUNER
: 0) |
2202 if(copy_to_user(arg
,&b
,sizeof(b
)))
2209 return bttv_ioctl(dev
,cmd
,arg
);
2211 /* make alevt happy :-) */
2218 static struct video_device vbi_template
=
2221 type
: VID_TYPE_CAPTURE
|VID_TYPE_TELETEXT
,
2222 hardware
: VID_HARDWARE_BT848
,
2233 static int radio_open(struct video_device
*dev
, int flags
)
2235 struct bttv
*btv
= (struct bttv
*)(dev
-1);
2246 bttv_call_i2c_clients(btv
,VIDIOCSFREQ
,&v
);
2247 bttv_call_i2c_clients(btv
,AUDC_SET_RADIO
,&btv
->tuner_type
);
2248 bt848_muxsel(btv
,0);
2259 static void radio_close(struct video_device
*dev
)
2261 struct bttv
*btv
=(struct bttv
*)(dev
-1);
2270 static long radio_read(struct video_device
*v
, char *buf
, unsigned long count
, int nonblock
)
2275 static int radio_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
2277 struct bttv
*btv
=(struct bttv
*)(dev
-1);
2281 struct video_capability v
;
2282 strcpy(v
.name
,btv
->video_dev
.name
);
2283 v
.type
= VID_TYPE_TUNER
;
2286 /* No we don't do pictures */
2291 if (copy_to_user(arg
, &v
, sizeof(v
)))
2298 struct video_tuner v
;
2299 if(copy_from_user(&v
,arg
,sizeof(v
))!=0)
2301 if(v
.tuner
||btv
->channel
) /* Only tuner 0 */
2303 strcpy(v
.name
, "Radio");
2304 v
.rangelow
=(int)(76*16); /* jp: 76.0MHz - 89.9MHz */
2305 v
.rangehigh
=(int)(108*16); /* eu: 87.5MHz - 108.0MHz */
2306 v
.flags
= 0; /* XXX */
2307 v
.mode
= 0; /* XXX */
2308 bttv_call_i2c_clients(btv
,cmd
,&v
);
2309 if(copy_to_user(arg
,&v
,sizeof(v
)))
2315 struct video_tuner v
;
2316 if(copy_from_user(&v
, arg
, sizeof(v
)))
2318 /* Only channel 0 has a tuner */
2319 if(v
.tuner
!=0 || btv
->channel
)
2321 /* XXX anything to do ??? */
2328 bttv_ioctl((struct video_device
*)btv
,cmd
,arg
);
2331 return -ENOIOCTLCMD
;
2336 static struct video_device radio_template
=
2339 type
: VID_TYPE_TUNER
,
2340 hardware
: VID_HARDWARE_BT848
,
2343 read
: radio_read
, /* just returns -EINVAL */
2344 write
: bttv_write
, /* just returns -EINVAL */
2350 static void bt848_set_risc_jmps(struct bttv
*btv
, int flags
)
2362 printk("bttv%d: set_risc_jmp %08lx:",
2363 btv
->nr
,virt_to_bus(btv
->risc_jmp
));
2365 /* Sync to start of odd field */
2366 btv
->risc_jmp
[0]=cpu_to_le32(BT848_RISC_SYNC
|BT848_RISC_RESYNC
2367 |BT848_FIFO_STATUS_VRE
);
2368 btv
->risc_jmp
[1]=cpu_to_le32(0);
2370 /* Jump to odd vbi sub */
2371 btv
->risc_jmp
[2]=cpu_to_le32(BT848_RISC_JUMP
|(0xd<<20));
2374 printk(" ev=%08lx",virt_to_bus(btv
->vbi_odd
));
2375 btv
->risc_jmp
[3]=cpu_to_le32(virt_to_bus(btv
->vbi_odd
));
2378 printk(" -----------");
2379 btv
->risc_jmp
[3]=cpu_to_le32(virt_to_bus(btv
->risc_jmp
+4));
2382 /* Jump to odd sub */
2383 btv
->risc_jmp
[4]=cpu_to_le32(BT848_RISC_JUMP
|(0xe<<20));
2384 if (0 != btv
->risc_cap_odd
) {
2386 printk(" e%d=%08x",btv
->gq_grab
,btv
->risc_cap_odd
);
2388 btv
->risc_jmp
[5]=cpu_to_le32(btv
->risc_cap_odd
);
2389 } else if ((flags
&2) &&
2390 (!btv
->win
.interlace
|| 0 == btv
->risc_cap_even
)) {
2392 printk(" eo=%08lx",virt_to_bus(btv
->risc_scr_odd
));
2393 btv
->risc_jmp
[5]=cpu_to_le32(virt_to_bus(btv
->risc_scr_odd
));
2396 printk(" -----------");
2397 btv
->risc_jmp
[5]=cpu_to_le32(virt_to_bus(btv
->risc_jmp
+6));
2401 /* Sync to start of even field */
2402 btv
->risc_jmp
[6]=cpu_to_le32(BT848_RISC_SYNC
|BT848_RISC_RESYNC
2403 |BT848_FIFO_STATUS_VRO
);
2404 btv
->risc_jmp
[7]=cpu_to_le32(0);
2406 /* Jump to even vbi sub */
2407 btv
->risc_jmp
[8]=cpu_to_le32(BT848_RISC_JUMP
);
2410 printk(" ov=%08lx",virt_to_bus(btv
->vbi_even
));
2411 btv
->risc_jmp
[9]=cpu_to_le32(virt_to_bus(btv
->vbi_even
));
2414 printk(" -----------");
2415 btv
->risc_jmp
[9]=cpu_to_le32(virt_to_bus(btv
->risc_jmp
+10));
2418 /* Jump to even sub */
2419 btv
->risc_jmp
[10]=cpu_to_le32(BT848_RISC_JUMP
|(8<<20));
2420 if (0 != btv
->risc_cap_even
) {
2422 printk(" o%d=%08x",btv
->gq_grab
,btv
->risc_cap_even
);
2424 btv
->risc_jmp
[11]=cpu_to_le32(btv
->risc_cap_even
);
2425 } else if ((flags
&1) &&
2426 btv
->win
.interlace
) {
2428 printk(" oo=%08lx",virt_to_bus(btv
->risc_scr_even
));
2429 btv
->risc_jmp
[11]=cpu_to_le32(virt_to_bus(btv
->risc_scr_even
));
2432 printk(" -----------");
2433 btv
->risc_jmp
[11]=cpu_to_le32(virt_to_bus(btv
->risc_jmp
+12));
2436 if (btv
->gq_start
) {
2437 btv
->risc_jmp
[12]=cpu_to_le32(BT848_RISC_JUMP
|(0x8<<16)|BT848_RISC_IRQ
);
2439 btv
->risc_jmp
[12]=cpu_to_le32(BT848_RISC_JUMP
);
2441 btv
->risc_jmp
[13]=cpu_to_le32(virt_to_bus(btv
->risc_jmp
));
2443 /* enable cpaturing and DMA */
2445 printk(" flags=0x%x dma=%s\n",
2446 flags
,(flags
&0x0f) ? "on" : "off");
2447 btaor(flags
, ~0x0f, BT848_CAP_CTL
);
2454 static int __devinit
init_video_dev(struct bttv
*btv
)
2456 audio(btv
, AUDIO_MUTE
, 1);
2458 if(video_register_device(&btv
->video_dev
,VFL_TYPE_GRABBER
)<0)
2460 if(video_register_device(&btv
->vbi_dev
,VFL_TYPE_VBI
)<0)
2462 video_unregister_device(&btv
->video_dev
);
2467 if(video_register_device(&btv
->radio_dev
, VFL_TYPE_RADIO
)<0)
2469 video_unregister_device(&btv
->vbi_dev
);
2470 video_unregister_device(&btv
->video_dev
);
2477 static int __devinit
init_bt848(struct bttv
*btv
)
2480 unsigned long irq_flags
;
2483 init_MUTEX(&btv
->lock
);
2485 /* dump current state of the gpio registers before changing them,
2486 * might help to make a new card work */
2488 bttv_gpio_tracking(btv
,"init #1");
2490 /* reset the bt848 */
2491 btwrite(0, BT848_SRESET
);
2492 DEBUG(printk(KERN_DEBUG
"bttv%d: bt848_mem: 0x%lx\n", btv
->nr
, (unsigned long) btv
->bt848_mem
));
2494 /* not registered yet */
2495 btv
->video_dev
.minor
= -1;
2496 btv
->radio_dev
.minor
= -1;
2497 btv
->vbi_dev
.minor
= -1;
2499 /* default setup for max. PAL size in a 1024xXXX hicolor framebuffer */
2500 btv
->win
.norm
=0; /* change this to 1 for NTSC, 2 for SECAM */
2501 btv
->win
.interlace
=1;
2504 btv
->win
.width
=768; /* 640 */
2505 btv
->win
.height
=576; /* 480 */
2508 btv
->win
.color_fmt
=BT848_COLOR_FMT_RGB16
;
2509 btv
->win
.bpl
=1024*btv
->win
.bpp
;
2510 btv
->win
.swidth
=1024;
2511 btv
->win
.sheight
=768;
2516 btv
->risc_scr_odd
=0;
2517 btv
->risc_scr_even
=0;
2518 btv
->risc_cap_odd
=0;
2519 btv
->risc_cap_even
=0;
2522 btv
->field
=btv
->last_field
=0;
2525 btv
->needs_restart
=0;
2527 if (!(btv
->risc_scr_odd
=(unsigned int *) kmalloc(RISCMEM_LEN
/2, GFP_KERNEL
)))
2529 if (!(btv
->risc_scr_even
=(unsigned int *) kmalloc(RISCMEM_LEN
/2, GFP_KERNEL
)))
2531 if (!(btv
->risc_jmp
=(unsigned int *) kmalloc(2048, GFP_KERNEL
)))
2533 btv
->vbi_odd
=btv
->risc_jmp
+16;
2534 btv
->vbi_even
=btv
->vbi_odd
+256;
2535 btv
->bus_vbi_odd
=virt_to_bus(btv
->risc_jmp
+12);
2536 btv
->bus_vbi_even
=virt_to_bus(btv
->risc_jmp
+6);
2538 btwrite(virt_to_bus(btv
->risc_jmp
+2), BT848_RISC_STRT_ADD
);
2539 btv
->vbibuf
=(unsigned char *) vmalloc_32(VBIBUF_SIZE
);
2542 if (!(btv
->gbuf
= kmalloc(sizeof(struct bttv_gbuf
)*gbuffers
,GFP_KERNEL
)))
2544 for (j
= 0; j
< gbuffers
; j
++) {
2545 if (!(btv
->gbuf
[j
].risc
= kmalloc(16384,GFP_KERNEL
)))
2549 memset(btv
->vbibuf
, 0, VBIBUF_SIZE
); /* We don't want to return random
2550 memory to the user */
2554 bt848_muxsel(btv
, 1);
2555 bt848_set_winsize(btv
);
2557 /* btwrite(0, BT848_TDEC); */
2558 btwrite(0x10, BT848_COLOR_CTL
);
2559 btwrite(0x00, BT848_CAP_CTL
);
2560 /* set planar and packed mode trigger points and */
2561 /* set rising edge of inverted GPINTR pin as irq trigger */
2562 btwrite(BT848_GPIO_DMA_CTL_PKTP_32
|
2563 BT848_GPIO_DMA_CTL_PLTP1_16
|
2564 BT848_GPIO_DMA_CTL_PLTP23_16
|
2565 BT848_GPIO_DMA_CTL_GPINTC
|
2566 BT848_GPIO_DMA_CTL_GPINTI
,
2567 BT848_GPIO_DMA_CTL
);
2569 /* select direct input */
2570 btwrite(0x00, BT848_GPIO_REG_INP
);
2571 btwrite(0x00, BT848_GPIO_OUT_EN
);
2573 bttv_gpio_tracking(btv
,"init #2");
2575 btwrite(BT848_IFORM_MUX1
| BT848_IFORM_XTAUTO
| BT848_IFORM_AUTO
,
2578 btwrite(0xd8, BT848_CONTRAST_LO
);
2579 bt848_bright(btv
, 0x10);
2581 btwrite(0x20, BT848_E_VSCALE_HI
);
2582 btwrite(0x20, BT848_O_VSCALE_HI
);
2583 btwrite(/*BT848_ADC_SYNC_T|*/
2584 BT848_ADC_RESERVED
|BT848_ADC_CRUSH
, BT848_ADC
);
2586 btwrite(BT848_CONTROL_LDEC
, BT848_E_CONTROL
);
2587 btwrite(BT848_CONTROL_LDEC
, BT848_O_CONTROL
);
2589 btv
->picture
.colour
=254<<7;
2590 btv
->picture
.brightness
=128<<8;
2591 btv
->picture
.hue
=128<<8;
2592 btv
->picture
.contrast
=0xd8<<7;
2594 btwrite(0x00, BT848_E_SCLOOP
);
2595 btwrite(0x00, BT848_O_SCLOOP
);
2597 /* clear interrupt status */
2598 btwrite(0xfffffUL
, BT848_INT_STAT
);
2600 /* set interrupt mask */
2601 btwrite(btv
->triton1
|
2602 /*BT848_INT_PABORT|BT848_INT_RIPERR|BT848_INT_PPERR|
2603 BT848_INT_FDSR|BT848_INT_FTRGT|BT848_INT_FBUS|*/
2604 (fieldnr
? BT848_INT_VSYNC
: 0)|
2607 BT848_INT_RISCI
|BT848_INT_OCERR
|BT848_INT_VPRES
|
2608 BT848_INT_FMTCHG
|BT848_INT_HLOCK
,
2612 spin_lock_irqsave(&btv
->s_lock
, irq_flags
);
2613 bt848_set_risc_jmps(btv
,-1);
2614 spin_unlock_irqrestore(&btv
->s_lock
, irq_flags
);
2616 /* needs to be done before i2c is registered */
2617 if (btv
->type
== BTTV_HAUPPAUGE
|| btv
->type
== BTTV_HAUPPAUGE878
)
2618 bttv_hauppauge_boot_msp34xx(btv
);
2624 /* some card-specific stuff (needs working i2c) */
2625 bttv_init_card(btv
);
2628 * Now add the template and register the device unit.
2630 init_video_dev(btv
);
2635 /* ----------------------------------------------------------------------- */
2637 static char *irq_name
[] = { "FMTCHG", "VSYNC", "HSYNC", "OFLOW", "HLOCK",
2638 "VPRES", "6", "7", "I2CDONE", "GPINT", "10",
2639 "RISCI", "FBUS", "FTRGT", "FDSR", "PPERR",
2640 "RIPERR", "PABORT", "OCERR", "SCERR" };
2642 static void bttv_irq(int irq
, void *dev_id
, struct pt_regs
* regs
)
2649 btv
=(struct bttv
*)dev_id
;
2653 /* get/clear interrupt status bits */
2654 stat
=btread(BT848_INT_STAT
);
2655 astat
=stat
&btread(BT848_INT_MASK
);
2658 btwrite(stat
,BT848_INT_STAT
);
2660 /* get device status bits */
2661 dstat
=btread(BT848_DSTATUS
);
2665 printk(KERN_DEBUG
"bttv%d: irq loop=%d risc=%x, bits:",
2666 btv
->nr
, count
, stat
>>28);
2667 for (i
= 0; i
< (sizeof(irq_name
)/sizeof(char*)); i
++) {
2668 if (stat
& (1 << i
))
2669 printk(" %s",irq_name
[i
]);
2670 if (astat
& (1 << i
))
2673 if (stat
& BT848_INT_HLOCK
)
2674 printk(" HLOC => %s", (dstat
& BT848_DSTATUS_HLOC
)
2676 if (stat
& BT848_INT_VPRES
)
2677 printk(" PRES => %s", (dstat
& BT848_DSTATUS_PRES
)
2679 if (stat
& BT848_INT_FMTCHG
)
2680 printk(" NUML => %s", (dstat
& BT848_DSTATUS_PRES
)
2685 if (astat
&BT848_INT_GPINT
)
2686 wake_up_interruptible(&btv
->gpioq
);
2688 if (astat
&BT848_INT_VSYNC
)
2691 if (astat
&(BT848_INT_SCERR
|BT848_INT_OCERR
)) {
2693 printk("bttv%d: irq:%s%s risc_count=%08x\n",
2695 (astat
&BT848_INT_SCERR
) ? " SCERR" : "",
2696 (astat
&BT848_INT_OCERR
) ? " OCERR" : "",
2697 btread(BT848_RISC_COUNT
));
2699 if (btv
->errors
< BTTV_ERRORS
) {
2700 spin_lock(&btv
->s_lock
);
2701 btand(~15, BT848_GPIO_DMA_CTL
);
2702 btwrite(virt_to_bus(btv
->risc_jmp
+2),
2703 BT848_RISC_STRT_ADD
);
2704 bt848_set_geo(btv
,0);
2705 bt848_set_risc_jmps(btv
,-1);
2706 spin_unlock(&btv
->s_lock
);
2709 printk("bttv%d: aiee: error loops\n",btv
->nr
);
2713 if (astat
&BT848_INT_RISCI
)
2716 printk("bttv%d: IRQ_RISCI\n",btv
->nr
);
2718 /* captured VBI frame */
2722 /* inc vbi frame count for detecting drops */
2723 (*(u32
*)&(btv
->vbibuf
[VBIBUF_SIZE
- 4]))++;
2724 wake_up_interruptible(&btv
->vbiq
);
2727 /* captured full frame */
2728 if (stat
&(2<<28) && btv
->gq_grab
!= -1)
2730 btv
->last_field
=btv
->field
;
2732 printk("bttv%d: cap irq: done %d\n",btv
->nr
,btv
->gq_grab
);
2733 do_gettimeofday(&btv
->gbuf
[btv
->gq_grab
].tv
);
2734 spin_lock(&btv
->s_lock
);
2735 btv
->gbuf
[btv
->gq_grab
].stat
= GBUFFER_DONE
;
2737 if (btv
->gq_in
!= btv
->gq_out
)
2739 btv
->gq_grab
= btv
->gqueue
[btv
->gq_out
++];
2740 btv
->gq_out
= btv
->gq_out
% MAX_GBUFFERS
;
2742 printk("bttv%d: cap irq: capture %d\n",btv
->nr
,btv
->gq_grab
);
2743 btv
->risc_cap_odd
= btv
->gbuf
[btv
->gq_grab
].ro
;
2744 btv
->risc_cap_even
= btv
->gbuf
[btv
->gq_grab
].re
;
2745 bt848_set_risc_jmps(btv
,-1);
2746 bt848_set_geo(btv
,0);
2747 btwrite(BT848_COLOR_CTL_GAMMA
,
2750 btv
->risc_cap_odd
= 0;
2751 btv
->risc_cap_even
= 0;
2752 bt848_set_risc_jmps(btv
,-1);
2753 bt848_set_geo(btv
,0);
2754 btwrite(btv
->fb_color_ctl
| BT848_COLOR_CTL_GAMMA
,
2757 spin_unlock(&btv
->s_lock
);
2758 wake_up_interruptible(&btv
->capq
);
2763 spin_lock(&btv
->s_lock
);
2765 btv
->gq_grab
= btv
->gqueue
[btv
->gq_out
++];
2766 btv
->gq_out
= btv
->gq_out
% MAX_GBUFFERS
;
2768 printk("bttv%d: cap irq: capture %d [start]\n",btv
->nr
,btv
->gq_grab
);
2769 btv
->risc_cap_odd
= btv
->gbuf
[btv
->gq_grab
].ro
;
2770 btv
->risc_cap_even
= btv
->gbuf
[btv
->gq_grab
].re
;
2771 bt848_set_risc_jmps(btv
,-1);
2772 bt848_set_geo(btv
,0);
2773 btwrite(BT848_COLOR_CTL_GAMMA
,
2775 spin_unlock(&btv
->s_lock
);
2779 if (astat
&BT848_INT_HLOCK
) {
2780 if ((dstat
&BT848_DSTATUS_HLOC
) || (btv
->radio
))
2781 audio(btv
, AUDIO_ON
,0);
2783 audio(btv
, AUDIO_OFF
,0);
2788 btwrite(0, BT848_INT_MASK
);
2790 "bttv%d: IRQ lockup, cleared int mask\n", btv
->nr
);
2799 * Scan for a Bt848 card, request the irq and map the io memory
2802 static void __devexit
bttv_remove(struct pci_dev
*pci_dev
)
2806 struct bttv
*btv
= pci_get_drvdata(pci_dev
);
2809 printk("bttv%d: unloading\n",btv
->nr
);
2811 /* unregister i2c_bus */
2812 if (0 == btv
->i2c_rc
)
2813 i2c_bit_del_bus(&btv
->i2c_adap
);
2815 /* turn off all capturing, DMA and IRQs */
2816 btand(~15, BT848_GPIO_DMA_CTL
);
2818 /* first disable interrupts before unmapping the memory! */
2819 btwrite(0, BT848_INT_MASK
);
2820 btwrite(~0x0UL
,BT848_INT_STAT
);
2821 btwrite(0x0, BT848_GPIO_OUT_EN
);
2823 bttv_gpio_tracking(btv
,"cleanup");
2825 /* disable PCI bus-mastering */
2826 pci_read_config_byte(btv
->dev
, PCI_COMMAND
, &command
);
2827 /* Should this be &=~ ?? */
2828 command
&=~PCI_COMMAND_MASTER
;
2829 pci_write_config_byte(btv
->dev
, PCI_COMMAND
, command
);
2831 /* unmap and free memory */
2832 for (j
= 0; j
< gbuffers
; j
++)
2833 if (btv
->gbuf
[j
].risc
)
2834 kfree(btv
->gbuf
[j
].risc
);
2836 kfree((void *) btv
->gbuf
);
2838 if (btv
->risc_scr_odd
)
2839 kfree((void *) btv
->risc_scr_odd
);
2841 if (btv
->risc_scr_even
)
2842 kfree((void *) btv
->risc_scr_even
);
2844 DEBUG(printk(KERN_DEBUG
"free: risc_jmp: 0x%p.\n", btv
->risc_jmp
));
2846 kfree((void *) btv
->risc_jmp
);
2848 DEBUG(printk(KERN_DEBUG
"bt848_vbibuf: 0x%p.\n", btv
->vbibuf
));
2850 vfree((void *) btv
->vbibuf
);
2852 free_irq(btv
->irq
,btv
);
2853 DEBUG(printk(KERN_DEBUG
"bt848_mem: 0x%p.\n", btv
->bt848_mem
));
2855 iounmap(btv
->bt848_mem
);
2857 if(btv
->video_dev
.minor
!=-1)
2858 video_unregister_device(&btv
->video_dev
);
2859 if(btv
->vbi_dev
.minor
!=-1)
2860 video_unregister_device(&btv
->vbi_dev
);
2861 if (radio
[btv
->nr
] && btv
->radio_dev
.minor
!= -1)
2862 video_unregister_device(&btv
->radio_dev
);
2864 release_mem_region(pci_resource_start(btv
->dev
,0),
2865 pci_resource_len(btv
->dev
,0));
2866 /* wake up any waiting processes
2867 because shutdown flag is set, no new processes (in this queue)
2871 wake_up(&btv
->gpioq
);
2873 pci_set_drvdata(pci_dev
, NULL
);
2878 static int __devinit
bttv_probe(struct pci_dev
*dev
, const struct pci_device_id
*pci_id
)
2883 #if defined(__powerpc__)
2887 printk(KERN_INFO
"bttv: Bt8xx card found (%d).\n", bttv_num
);
2889 btv
=&bttvs
[bttv_num
];
2892 btv
->bt848_mem
=NULL
;
2897 init_waitqueue_head(&btv
->vbiq
);
2898 init_waitqueue_head(&btv
->capq
);
2899 btv
->vbip
=VBIBUF_SIZE
;
2900 btv
->s_lock
= SPIN_LOCK_UNLOCKED
;
2901 init_waitqueue_head(&btv
->gpioq
);
2904 memcpy(&btv
->video_dev
,&bttv_template
, sizeof(bttv_template
));
2905 memcpy(&btv
->vbi_dev
,&vbi_template
, sizeof(vbi_template
));
2906 memcpy(&btv
->radio_dev
,&radio_template
,sizeof(radio_template
));
2908 btv
->id
=dev
->device
;
2910 btv
->bt848_adr
=pci_resource_start(dev
,0);
2911 if (pci_enable_device(dev
))
2913 if (!request_mem_region(pci_resource_start(dev
,0),
2914 pci_resource_len(dev
,0),
2919 btv
->i2c_command
= 0x83;
2921 btv
->i2c_command
=(I2C_TIMING
| BT848_I2C_SCL
| BT848_I2C_SDA
);
2923 pci_read_config_byte(dev
, PCI_CLASS_REVISION
, &btv
->revision
);
2924 pci_read_config_byte(dev
, PCI_LATENCY_TIMER
, &lat
);
2925 printk(KERN_INFO
"bttv%d: Bt%d (rev %d) at %02x:%02x.%x, ",
2926 bttv_num
,btv
->id
, btv
->revision
, dev
->bus
->number
,
2927 PCI_SLOT(dev
->devfn
),PCI_FUNC(dev
->devfn
));
2928 printk("irq: %d, latency: %d, memory: 0x%lx\n",
2929 btv
->irq
, lat
, btv
->bt848_adr
);
2933 #if defined(__powerpc__)
2934 /* on OpenFirmware machines (PowerMac at least), PCI memory cycle */
2935 /* response on cards with no firmware is not enabled by OF */
2936 pci_read_config_dword(dev
, PCI_COMMAND
, &cmd
);
2937 cmd
= (cmd
| PCI_COMMAND_MEMORY
);
2938 pci_write_config_dword(dev
, PCI_COMMAND
, cmd
);
2942 btv
->bt848_mem
=(unsigned char *)btv
->bt848_adr
;
2944 btv
->bt848_mem
=ioremap(btv
->bt848_adr
, 0x1000);
2947 /* clear interrupt mask */
2948 btwrite(0, BT848_INT_MASK
);
2950 result
= request_irq(btv
->irq
, bttv_irq
,
2951 SA_SHIRQ
| SA_INTERRUPT
,"bttv",(void *)btv
);
2952 if (result
==-EINVAL
)
2954 printk(KERN_ERR
"bttv%d: Bad irq number or handler\n",
2960 printk(KERN_ERR
"bttv%d: IRQ %d busy, change your PnP config in BIOS\n",bttv_num
,btv
->irq
);
2966 if (0 != bttv_handle_chipset(btv
)) {
2971 pci_set_master(dev
);
2972 pci_set_drvdata(dev
,btv
);
2974 if(init_bt848(btv
) < 0) {
2983 free_irq(btv
->irq
,btv
);
2985 release_mem_region(pci_resource_start(btv
->dev
,0),
2986 pci_resource_len(btv
->dev
,0));
2990 static struct pci_device_id bttv_pci_tbl
[] __devinitdata
= {
2991 {PCI_VENDOR_ID_BROOKTREE
, PCI_DEVICE_ID_BT848
,
2992 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
2993 {PCI_VENDOR_ID_BROOKTREE
, PCI_DEVICE_ID_BT849
,
2994 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
2995 {PCI_VENDOR_ID_BROOKTREE
, PCI_DEVICE_ID_BT878
,
2996 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
2997 {PCI_VENDOR_ID_BROOKTREE
, PCI_DEVICE_ID_BT879
,
2998 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
3002 MODULE_DEVICE_TABLE(pci
, bttv_pci_tbl
);
3004 static struct pci_driver bttv_pci_driver
= {
3006 id_table
: bttv_pci_tbl
,
3008 remove
: bttv_remove
,
3011 int bttv_init_module(void)
3015 printk(KERN_INFO
"bttv: driver version %d.%d.%d loaded\n",
3016 (BTTV_VERSION_CODE
>> 16) & 0xff,
3017 (BTTV_VERSION_CODE
>> 8) & 0xff,
3018 BTTV_VERSION_CODE
& 0xff);
3019 if (gbuffers
< 2 || gbuffers
> MAX_GBUFFERS
)
3021 if (gbufsize
< 0 || gbufsize
> BTTV_MAX_FBUF
)
3022 gbufsize
= BTTV_MAX_FBUF
;
3024 printk(KERN_INFO
"bttv: using %d buffers with %dk (%dk total) for capture\n",
3025 gbuffers
,gbufsize
/1024,gbuffers
*gbufsize
/1024);
3027 bttv_check_chipset();
3029 return pci_module_init(&bttv_pci_driver
);
3032 void bttv_cleanup_module(void)
3034 pci_unregister_driver(&bttv_pci_driver
);
3038 module_init(bttv_init_module
);
3039 module_exit(bttv_cleanup_module
);