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 IDEBUG(x) /* Debug interrupt handler */
53 #define MIN(a,b) (((a)>(b))?(b):(a))
54 #define MAX(a,b) (((a)>(b))?(a):(b))
57 /* Anybody who uses more than four? */
59 static void bt848_set_risc_jmps(struct bttv
*btv
, int state
);
61 static int bttv_num
; /* number of Bt848s in use */
62 static struct bttv bttvs
[BTTV_MAX
];
66 MODULE_PARM(triton1
,"i");
67 MODULE_PARM(remap
,"1-4i");
68 MODULE_PARM(radio
,"1-4i");
69 MODULE_PARM(card
,"1-4i");
70 MODULE_PARM(pll
,"1-4i");
71 MODULE_PARM(bigendian
,"i");
72 MODULE_PARM(fieldnr
,"i");
73 MODULE_PARM(verbose
,"i");
74 MODULE_PARM(debug
,"i");
75 MODULE_PARM(autoload
,"i");
76 MODULE_PARM(gbuffers
,"i");
77 MODULE_PARM(gbufsize
,"i");
79 EXPORT_SYMBOL(bttv_get_id
);
80 EXPORT_SYMBOL(bttv_gpio_enable
);
81 EXPORT_SYMBOL(bttv_read_gpio
);
82 EXPORT_SYMBOL(bttv_write_gpio
);
83 EXPORT_SYMBOL(bttv_get_gpio_queue
);
85 MODULE_DESCRIPTION("bttv - v4l driver module for bt848/878 based cards");
86 MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr");
88 #if defined(__sparc__) || defined(__powerpc__)
89 static unsigned int bigendian
=1;
91 static unsigned int bigendian
=0;
94 static unsigned long remap
[BTTV_MAX
];
95 static unsigned int radio
[BTTV_MAX
];
96 static unsigned int card
[BTTV_MAX
] = { 0, 0, 0, 0 };
97 static unsigned int pll
[BTTV_MAX
] = { -1, -1, -1, -1};
98 static unsigned int fieldnr
= 0;
99 static unsigned int verbose
= 1;
100 static unsigned int debug
= 0;
101 static unsigned int gbuffers
= 2;
102 static unsigned int gbufsize
= BTTV_MAX_FBUF
;
104 static unsigned int autoload
= 1;
106 static unsigned int autoload
= 0;
110 #define I2C_TIMING (0x7<<4)
113 #define I2C_SET(CTRL,DATA) \
114 { btwrite((CTRL<<1)|(DATA), BT848_I2C); udelay(I2C_DELAY); }
115 #define I2C_GET() (btread(BT848_I2C)&1)
117 #define BURSTOFFSET 76
118 #define BTTV_ERRORS 5
121 /* ----------------------------------------------------------------------- */
122 /* Exported functions - for other modules which want to access the */
123 /* gpio ports (IR for example) */
124 /* see bttv.h for comments */
126 int bttv_get_id(unsigned int card
)
128 if (card
>= bttv_num
) {
131 return bttvs
[card
].type
;
134 int bttv_gpio_enable(unsigned int card
, unsigned long mask
, unsigned long data
)
138 if (card
>= bttv_num
) {
143 btaor(data
, ~mask
, BT848_GPIO_OUT_EN
);
147 int bttv_read_gpio(unsigned int card
, unsigned long *data
)
151 if (card
>= bttv_num
) {
161 /* prior setting BT848_GPIO_REG_INP is (probably) not needed
162 because we set direct input on init */
163 *data
= btread(BT848_GPIO_DATA
);
167 int bttv_write_gpio(unsigned int card
, unsigned long mask
, unsigned long data
)
171 if (card
>= bttv_num
) {
177 /* prior setting BT848_GPIO_REG_INP is (probably) not needed
178 because direct input is set on init */
179 btaor(data
& mask
, ~mask
, BT848_GPIO_DATA
);
183 WAIT_QUEUE
* bttv_get_gpio_queue(unsigned int card
)
187 if (card
>= bttv_num
) {
192 if (bttvs
[card
].shutdown
) {
198 /*******************************/
199 /* Memory management functions */
200 /*******************************/
202 #define MDEBUG(x) do { } while(0) /* Debug memory management */
204 /* [DaveM] I've recoded most of this so that:
205 * 1) It's easier to tell what is happening
206 * 2) It's more portable, especially for translating things
207 * out of vmalloc mapped areas in the kernel.
208 * 3) Less unnecessary translations happen.
210 * The code used to assume that the kernel vmalloc mappings
211 * existed in the page tables of every process, this is simply
212 * not guarenteed. We now use pgd_offset_k which is the
213 * defined way to get at the kernel page tables.
216 /* Given PGD from the address space's page table, return the kernel
217 * virtual mapping of the physical memory mapped at ADR.
219 static inline unsigned long uvirt_to_kva(pgd_t
*pgd
, unsigned long adr
)
221 unsigned long ret
= 0UL;
225 if (!pgd_none(*pgd
)) {
226 pmd
= pmd_offset(pgd
, adr
);
227 if (!pmd_none(*pmd
)) {
228 ptep
= pte_offset(pmd
, adr
);
231 ret
= (page_address(pte_page(pte
))|(adr
&(PAGE_SIZE
-1)));
234 MDEBUG(printk("uv2kva(%lx-->%lx)", adr
, ret
));
238 static inline unsigned long uvirt_to_bus(unsigned long adr
)
240 unsigned long kva
, ret
;
242 kva
= uvirt_to_kva(pgd_offset(current
->mm
, adr
), adr
);
243 ret
= virt_to_bus((void *)kva
);
244 MDEBUG(printk("uv2b(%lx-->%lx)", adr
, ret
));
248 static inline unsigned long kvirt_to_bus(unsigned long adr
)
250 unsigned long va
, kva
, ret
;
252 va
= VMALLOC_VMADDR(adr
);
253 kva
= uvirt_to_kva(pgd_offset_k(va
), va
);
254 ret
= virt_to_bus((void *)kva
);
255 MDEBUG(printk("kv2b(%lx-->%lx)", adr
, ret
));
259 /* Here we want the physical address of the memory.
260 * This is used when initializing the contents of the
261 * area and marking the pages as reserved.
263 static inline unsigned long kvirt_to_pa(unsigned long adr
)
265 unsigned long va
, kva
, ret
;
267 va
= VMALLOC_VMADDR(adr
);
268 kva
= uvirt_to_kva(pgd_offset_k(va
), va
);
270 MDEBUG(printk("kv2pa(%lx-->%lx)", adr
, ret
));
274 static void * rvmalloc(signed long size
)
277 unsigned long adr
, page
;
282 memset(mem
, 0, size
); /* Clear the ram out, no junk to the user */
283 adr
=(unsigned long) mem
;
286 page
= kvirt_to_pa(adr
);
287 mem_map_reserve(MAP_NR(__va(page
)));
295 static void rvfree(void * mem
, signed long size
)
297 unsigned long adr
, page
;
301 adr
=(unsigned long) mem
;
304 page
= kvirt_to_pa(adr
);
305 mem_map_unreserve(MAP_NR(__va(page
)));
316 * Create the giant waste of buffer space we need for now
317 * until we get DMA to user space sorted out (probably 2.3.x)
319 * We only create this as and when someone uses mmap
322 static int fbuffer_alloc(struct bttv
*btv
)
325 btv
->fbuffer
=(unsigned char *) rvmalloc(gbuffers
*gbufsize
);
327 printk(KERN_ERR
"bttv%d: Double alloc of fbuffer!\n",
335 /* ----------------------------------------------------------------------- */
338 static void bttv_bit_setscl(void *data
, int state
)
340 struct bttv
*btv
= (struct bttv
*)data
;
343 btv
->i2c_state
|= 0x02;
345 btv
->i2c_state
&= ~0x02;
346 btwrite(btv
->i2c_state
, BT848_I2C
);
350 static void bttv_bit_setsda(void *data
, int state
)
352 struct bttv
*btv
= (struct bttv
*)data
;
355 btv
->i2c_state
|= 0x01;
357 btv
->i2c_state
&= ~0x01;
358 btwrite(btv
->i2c_state
, BT848_I2C
);
362 static int bttv_bit_getscl(void *data
)
364 struct bttv
*btv
= (struct bttv
*)data
;
367 state
= btread(BT848_I2C
) & 0x02 ? 1 : 0;
371 static int bttv_bit_getsda(void *data
)
373 struct bttv
*btv
= (struct bttv
*)data
;
376 state
= btread(BT848_I2C
) & 0x01;
380 static void bttv_inc_use(struct i2c_adapter
*adap
)
385 static void bttv_dec_use(struct i2c_adapter
*adap
)
390 static void call_i2c_clients(struct bttv
*btv
, unsigned int cmd
, void *arg
)
394 for (i
= 0; i
< I2C_CLIENTS_MAX
; i
++) {
395 if (NULL
== btv
->i2c_clients
[i
])
397 if (NULL
== btv
->i2c_clients
[i
]->driver
->command
)
399 btv
->i2c_clients
[i
]->driver
->command(
400 btv
->i2c_clients
[i
],cmd
,arg
);
404 static int attach_inform(struct i2c_client
*client
)
406 struct bttv
*btv
= (struct bttv
*)client
->adapter
->data
;
409 for (i
= 0; i
< I2C_CLIENTS_MAX
; i
++) {
410 if (btv
->i2c_clients
[i
] == NULL
||
411 btv
->i2c_clients
[i
]->driver
->id
== client
->driver
->id
) {
412 btv
->i2c_clients
[i
] = client
;
416 if (btv
->tuner_type
!= -1)
417 call_i2c_clients(btv
,TUNER_SET_TYPE
,&btv
->tuner_type
);
419 printk("bttv%d: i2c attach [%s]\n",btv
->nr
,client
->name
);
423 static int detach_inform(struct i2c_client
*client
)
425 struct bttv
*btv
= (struct bttv
*)client
->adapter
->data
;
429 printk("bttv%d: i2c detach [%s]\n",btv
->nr
,client
->name
);
430 for (i
= 0; i
< I2C_CLIENTS_MAX
; i
++) {
431 if (NULL
!= btv
->i2c_clients
[i
] &&
432 btv
->i2c_clients
[i
]->driver
->id
== client
->driver
->id
) {
433 btv
->i2c_clients
[i
] = NULL
;
440 static struct i2c_algo_bit_data i2c_algo_template
= {
449 static struct i2c_adapter i2c_adap_template
= {
461 static struct i2c_client i2c_client_template
= {
470 static int __init
init_bttv_i2c(struct bttv
*btv
)
472 /* i2c bit_adapter */
473 memcpy(&btv
->i2c_adap
, &i2c_adap_template
, sizeof(struct i2c_adapter
));
474 memcpy(&btv
->i2c_algo
, &i2c_algo_template
, sizeof(struct i2c_algo_bit_data
));
475 memcpy(&btv
->i2c_client
, &i2c_client_template
, sizeof(struct i2c_client
));
477 sprintf(btv
->i2c_adap
.name
+strlen(btv
->i2c_adap
.name
),
479 btv
->i2c_algo
.data
= btv
;
480 btv
->i2c_adap
.data
= btv
;
481 btv
->i2c_adap
.algo_data
= &btv
->i2c_algo
;
482 btv
->i2c_client
.adapter
= &btv
->i2c_adap
;
484 bttv_bit_setscl(btv
,1);
485 bttv_bit_setsda(btv
,1);
487 btv
->i2c_ok
= i2c_bit_add_bus(&btv
->i2c_adap
);
492 static int __init
I2CRead(struct bttv
*btv
, unsigned char addr
, char *probe_for
)
494 unsigned char buffer
= 0;
496 if (0 != btv
->i2c_ok
)
498 if (verbose
&& NULL
!= probe_for
)
499 printk(KERN_INFO
"bttv%d: i2c: checking for %s @ 0x%02x... ",
500 btv
->nr
,probe_for
,addr
);
501 btv
->i2c_client
.addr
= addr
>> 1;
502 if (1 != i2c_master_recv(&btv
->i2c_client
, &buffer
, 1)) {
503 if (NULL
!= probe_for
) {
505 printk("not found\n");
507 printk(KERN_WARNING
"bttv%d: i2c read 0x%x: error\n",
511 if (verbose
&& NULL
!= probe_for
)
517 static int __init
I2CWrite(struct bttv
*btv
, unsigned char addr
, unsigned char b1
,
518 unsigned char b2
, int both
)
520 unsigned char buffer
[2];
521 int bytes
= both
? 2 : 1;
523 if (0 != btv
->i2c_ok
)
525 btv
->i2c_client
.addr
= addr
>> 1;
528 if (bytes
!= i2c_master_send(&btv
->i2c_client
, buffer
, bytes
))
534 static void __init
readee(struct bttv
*btv
, unsigned char *eedata
, int addr
)
538 if (I2CWrite(btv
, addr
, 0, -1, 0)<0) {
539 printk(KERN_WARNING
"bttv: readee error\n");
542 btv
->i2c_client
.addr
= addr
>> 1;
543 for (i
=0; i
<256; i
+=16) {
544 if (16 != i2c_master_recv(&btv
->i2c_client
,eedata
+i
,16)) {
545 printk(KERN_WARNING
"bttv: readee error\n");
552 /* ----------------------------------------------------------------------- */
553 /* some hauppauge specific stuff */
555 static unsigned char eeprom_data
[256];
556 static struct HAUPPAUGE_TUNER
561 hauppauge_tuner
[] __initdata
=
563 { TUNER_ABSENT
, "" },
564 { TUNER_ABSENT
, "External" },
565 { TUNER_ABSENT
, "Unspecified" },
566 { TUNER_ABSENT
, "Philips FI1216" },
567 { TUNER_PHILIPS_SECAM
, "Philips FI1216MF" },
568 { TUNER_PHILIPS_NTSC
, "Philips FI1236" },
569 { TUNER_ABSENT
, "Philips FI1246" },
570 { TUNER_ABSENT
, "Philips FI1256" },
571 { TUNER_PHILIPS_PAL
, "Philips FI1216 MK2" },
572 { TUNER_PHILIPS_SECAM
, "Philips FI1216MF MK2" },
573 { TUNER_PHILIPS_NTSC
, "Philips FI1236 MK2" },
574 { TUNER_PHILIPS_PAL_I
, "Philips FI1246 MK2" },
575 { TUNER_ABSENT
, "Philips FI1256 MK2" },
576 { TUNER_ABSENT
, "Temic 4032FY5" },
577 { TUNER_TEMIC_PAL
, "Temic 4002FH5" },
578 { TUNER_TEMIC_PAL_I
, "Temic 4062FY5" },
579 { TUNER_ABSENT
, "Philips FR1216 MK2" },
580 { TUNER_PHILIPS_SECAM
, "Philips FR1216MF MK2" },
581 { TUNER_PHILIPS_NTSC
, "Philips FR1236 MK2" },
582 { TUNER_PHILIPS_PAL_I
, "Philips FR1246 MK2" },
583 { TUNER_ABSENT
, "Philips FR1256 MK2" },
584 { TUNER_PHILIPS_PAL
, "Philips FM1216" },
585 { TUNER_ABSENT
, "Philips FM1216MF" },
586 { TUNER_PHILIPS_NTSC
, "Philips FM1236" },
587 { TUNER_PHILIPS_PAL_I
, "Philips FM1246" },
588 { TUNER_ABSENT
, "Philips FM1256" },
589 { TUNER_TEMIC_4036FY5_NTSC
, "Temic 4036FY5" },
590 { TUNER_ABSENT
, "Samsung TCPN9082D" },
591 { TUNER_ABSENT
, "Samsung TCPM9092P" },
592 { TUNER_TEMIC_PAL
, "Temic 4006FH5" },
593 { TUNER_ABSENT
, "Samsung TCPN9085D" },
594 { TUNER_ABSENT
, "Samsung TCPB9085P" },
595 { TUNER_ABSENT
, "Samsung TCPL9091P" },
596 { TUNER_ABSENT
, "Temic 4039FR5" },
597 { TUNER_ABSENT
, "Philips FQ1216 ME" },
598 { TUNER_TEMIC_PAL_I
, "Temic 4066FY5" },
599 { TUNER_ABSENT
, "Philips TD1536" },
600 { TUNER_ABSENT
, "Philips TD1536D" },
601 { TUNER_ABSENT
, "Philips FMR1236" },
602 { TUNER_ABSENT
, "Philips FI1256MP" },
603 { TUNER_ABSENT
, "Samsung TCPQ9091P" },
604 { TUNER_ABSENT
, "Temic 4006FN5" },
605 { TUNER_ABSENT
, "Temic 4009FR5" },
606 { TUNER_ABSENT
, "Temic 4046FM5" },
609 static void __init
hauppauge_eeprom(struct bttv
*btv
)
611 if (eeprom_data
[9] < sizeof(hauppauge_tuner
)/sizeof(struct HAUPPAUGE_TUNER
))
613 btv
->tuner_type
= hauppauge_tuner
[eeprom_data
[9]].id
;
615 printk("bttv%d: Hauppauge eeprom: tuner=%s (%d)\n",btv
->nr
,
616 hauppauge_tuner
[eeprom_data
[9]].name
,btv
->tuner_type
);
622 static void __init
hauppauge_boot_msp34xx(struct bttv
*btv
)
626 /* reset/enable the MSP on some Hauppauge cards */
627 /* Thanks to Kyösti Mälkki (kmalkki@cc.hut.fi)! */
628 btaor(32, ~32, BT848_GPIO_OUT_EN
);
629 btaor(0, ~32, BT848_GPIO_DATA
);
631 btaor(32, ~32, BT848_GPIO_DATA
);
634 printk("bttv%d: Hauppauge msp34xx: reset line init\n",btv
->nr
);
636 /* look if the msp3400 driver is already registered */
637 for (i
= 0; i
< I2C_CLIENTS_MAX
; i
++) {
638 if (btv
->i2c_clients
[i
] != NULL
&&
639 btv
->i2c_clients
[i
]->driver
->id
== I2C_DRIVERID_MSP3400
) {
644 /* if not: look for the chip ... */
645 if (I2CRead(btv
, I2C_MSP3400
, "MSP34xx")) {
646 /* ... if found re-register to trigger a i2c bus rescan, */
647 /* this time with the msp34xx chip activated */
648 i2c_bit_del_bus(&btv
->i2c_adap
);
649 i2c_bit_add_bus(&btv
->i2c_adap
);
654 /* Imagenation L-Model PXC200 Framegrabber */
655 /* This is basically the same procedure as
656 * used by Alessandro Rubini in his pxc200
657 * driver, but using BTTV functions */
658 static void __init
init_PXC200(struct bttv
*btv
)
660 static const int vals
[] = { 0x08, 0x09, 0x0a, 0x0b, 0x0d, 0x0d,
661 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
665 /* Initialise GPIO-connevted stuff */
666 btwrite(1<<13,BT848_GPIO_OUT_EN
); /* Reset pin only */
667 btwrite(0,BT848_GPIO_DATA
);
669 btwrite(1<<13,BT848_GPIO_DATA
);
670 /* GPIO inputs are pulled up, so no need to drive
671 * reset pin any longer */
672 btwrite(0,BT848_GPIO_OUT_EN
);
674 /* we could/should try and reset/control the AD pots? but
675 right now we simply turned off the crushing. Without
676 this the AGC drifts drifts
677 remember the EN is reverse logic -->
678 setting BT848_ADC_AGC_EN disable the AGC
679 tboult@eecs.lehigh.edu
681 btwrite(BT848_ADC_RESERVED
|BT848_ADC_AGC_EN
, BT848_ADC
);
683 /* Initialise MAX517 DAC */
684 printk(KERN_INFO
"Setting DAC reference voltage level ...\n");
685 I2CWrite(btv
,0x5E,0,0x80,1);
687 /* Initialise 12C508 PIC */
688 /* The I2CWrite and I2CRead commmands are actually to the
689 * same chips - but the R/W bit is included in the address
690 * argument so the numbers are different */
692 printk(KERN_INFO
"Initialising 12C508 PIC chip ...\n");
694 for (i
= 0; i
< sizeof(vals
)/sizeof(int); i
++) {
695 tmp
=I2CWrite(btv
,0x1E,vals
[i
],0,1);
696 printk(KERN_INFO
"I2C Write(0x08) = %i\nI2C Read () = %x\n\n",
697 tmp
,I2CRead(btv
,0x1F,NULL
));
699 printk(KERN_INFO
"PXC200 Initialised.\n");
702 /* ----------------------------------------------------------------------- */
708 } cards
[] __initdata
= {
709 { 0x00011002, BTTV_HAUPPAUGE878
, "ATI TV Wonder" },
710 { 0x00011461, BTTV_AVPHONE98
, "AVerMedia TVPhone98" },
711 { 0x00031461, BTTV_AVPHONE98
, "AVerMedia TVPhone98" },
712 { 0x00041461, BTTV_AVPHONE98
, "AVerMedia TVPhone98" },
713 { 0x10b42636, BTTV_HAUPPAUGE878
, "STB ???" },
714 { 0x1118153b, BTTV_TERRATVALUE
, "Terratec TV Value" },
715 { 0x1200bd11, BTTV_PINNACLERAVE
, "Pinnacle PCTV Rave" },
716 { 0x13eb0070, BTTV_HAUPPAUGE878
, "Hauppauge WinTV" },
717 { 0x14610002, BTTV_AVERMEDIA98
, "Avermedia TVCapture 98" },
718 { 0x18501851, BTTV_CHRONOS_VS2
, "Chronos Video Shuttle II" },
719 { 0x18521852, BTTV_TYPHOON_TVIEW
, "Typhoon TView TV/FM Tuner" },
720 { 0x263610b4, BTTV_STB2
, "STB TV PCI FM, P/N 6000704" },
721 { 0x3000144f, BTTV_MAGICTVIEW063
, "TView 99 (CPH063)" },
722 { 0x300014ff, BTTV_MAGICTVIEW061
, "TView 99 (CPH061)" },
723 { 0x3002144f, BTTV_MAGICTVIEW061
, "Askey Magic TView" },
724 { 0x300214ff, BTTV_PHOEBE_TVMAS
, "Phoebe TV Master" },
725 { 0x402010fc, 0 /* no tvcards entry yet */, "I-O Data Co. GV-BCV3/PCI" },
726 { 0x6606217d, BTTV_WINFAST2000
, "Leadtek WinFast TV 2000" },
739 u32 audiomux
[6]; /* Tuner, Radio, external, internal, mute, stereo */
740 u32 gpiomask2
; /* GPIO MUX mask */
742 /* look for these i2c audio chips */
757 static struct tvcard tvcards
[] =
760 { " *** UNKNOWN *** ",
761 3, 1, 0, 2, 0, { 2, 3, 1, 1}, { 0, 0, 0, 0, 0},0,
762 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
764 4, 1, 0, 2,15, { 2, 3, 1, 1}, { 2, 0, 0, 0,10},0,
765 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
767 4, 1, 0, 2, 7, { 2, 3, 1, 1}, { 0, 1, 2, 3, 4},0,
768 1,1,0,1,0,0,0,1, PLL_NONE
, -1 },
770 3, 1, 0, 2, 7, { 2, 3, 1, 1}, { 4, 0, 2, 3, 1},0,
771 0,1,1,1,1,0,0,1, PLL_NONE
, -1 },
774 3, 1, 0, -1, 7, { 2, 3, 1, 1}, { 0, 1, 2, 3, 4},0,
775 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
777 3, 1, 0, 2, 3, { 2, 3, 1, 1}, { 0, 1, 0, 1, 3},0,
778 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
779 { "AVerMedia TVPhone",
780 3, 1, 0, 3,15, { 2, 3, 1, 1}, {12, 4,11,11, 0},0,
781 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
782 { "MATRIX-Vision MV-Delta",
783 5, 1, -1, 3, 0, { 2, 3, 1, 0, 0},{0 }, 0,
784 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
788 3, 1, 0, 2, 0xc00, { 2, 3, 1, 1},
789 { 0, 0xc00, 0x800, 0x400, 0xc00, 0},0,
790 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
792 3, 1, 0, 2, 3, { 2, 3, 1, 1}, { 1, 1, 2, 3, 0},0,
793 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
794 { "Hauppauge new (bt878)",
795 4, 1, 0, 2, 7, { 2, 0, 1, 1}, { 0, 1, 2, 3, 4},0,
796 1,1,0,1,0,0,0,1, PLL_28
, -1 },
798 3, 1, 0, 2, 65551, { 2, 3, 1, 1}, {1,65537, 0, 0,10},0,
799 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
801 { "ADS Technologies Channel Surfer TV",
802 3, 1, 2, 2, 15, { 2, 3, 1, 1}, { 13, 14, 11, 7, 0, 0},0,
803 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
804 { "AVerMedia TVCapture 98",
805 3, 4, 0, 2, 15, { 2, 3, 1, 1}, { 13, 14, 11, 7, 0, 0},0,
806 1,1,1,1,0,0,0,1, PLL_28
, -1 },
808 3, 1, 0, 2, 7, { 2, 3, 1, 1}, { 0, 1, 2, 3, 4},0,
809 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
811 3, 1, 0, 2,15, { 2, 3, 1, 1}, {0 , 0, 1 , 0, 10},0,
812 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
815 { "Pixelview PlayTV (bt878)",
816 3, 1, 0, 2, 0x01fe00, { 2, 0, 1, 1},
817 { 0x01c000, 0, 0x018000, 0x014000, 0x002000, 0 },0,
818 1,1,1,1,0,0,0,1, PLL_28
, -1 },
819 { "Leadtek WinView 601",
820 3, 1, 0, 2, 0x8300f8, { 2, 3, 1, 1,0},
821 { 0x4fa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007},0,
822 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
823 { "AVEC Intercapture",
824 3, 2, 0, 2, 0, {2, 3, 1, 1}, {1, 0, 0, 0, 0},0,
825 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
826 { "LifeView FlyKit w/o Tuner",
827 3, 1, -1, -1, 0x8dff00, { 2, 3, 1, 1}, { 0 },0,
828 0,0,0,0,0,0,0,1, PLL_NONE
, -1 },
830 { "CEI Raffles Card",
831 3, 3, 0, 2, 0, {2, 3, 1, 1}, {0, 0, 0, 0 ,0},0,
832 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
833 { "Lucky Star Image World ConferenceTV",
834 3, 1, 0, 2, 0x00fffe07, { 2, 3, 1, 1}, { 131072, 1, 1638400, 3, 4},0,
835 1,1,1,1,0,0,0,1, PLL_28
, TUNER_PHILIPS_PAL_I
},
836 { "Phoebe Tv Master + FM",
837 3, 1, 0, 2, 0xc00, { 2, 3, 1, 1},{0, 1, 0x800, 0x400, 0xc00, 0},0,
838 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
839 { "Modular Technology MM205 PCTV, bt878",
840 2, 1, 0, -1, 7, { 2, 3 }, { 0, 0, 0, 0, 0 },0,
841 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
844 { "Askey/Typhoon/Anubis Magic TView CPH051/061 (bt878)",
845 3, 1, 0, 2, 0xe00, { 2, 3, 1, 1}, {0x400, 0x400, 0x400, 0x400, 0},0,
846 1,1,1,1,0,0,0,1, PLL_28
, -1 },
847 { "Terratec/Vobis TV-Boostar",
848 3, 1, 0, 2, 16777215 , { 2, 3, 1, 1}, { 131072, 1, 1638400, 3,4},0,
849 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
850 { "Newer Hauppauge WinCam (bt878)",
851 4, 1, 0, 3, 7, { 2, 0, 1, 1}, { 0, 1, 2, 3, 4},0,
852 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
853 { "MAXI TV Video PCI2",
854 3, 1, 0, 2, 0xffff, { 2, 3, 1, 1}, { 0, 1, 2, 3, 0xc00},0,
855 1,1,1,1,0,0,0,1, PLL_NONE
, TUNER_PHILIPS_SECAM
},
857 { "Terratec TerraTV+",
858 3, 1, 0, 2, 0x70000, { 2, 3, 1, 1},
859 { 0x20000, 0x30000, 0x00000, 0x10000, 0x40000},0,
860 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
861 { "Imagenation PXC200",
862 5, 1, -1, 4, 0, { 2, 3, 1, 0, 0}, { 0 }, 0,
863 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
865 3, 1, 0, 2, 0x8dff00, {2, 3, 1, 1},
866 { 0, 0x8dff00, 0x8df700, 0x8de700, 0x8dff00, 0 },0,
867 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
869 3, 1, 0, 2, 1, { 2, 3, 1, 1}, { 1, 0, 0, 0, 0 },0,
870 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
873 { "Intel Create and Share PCI",
874 4, 1, 0, 2, 7, { 2, 3, 1, 1}, { 4, 4, 4, 4, 4},0,
875 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
876 { "Terratec TerraTValue",
877 3, 1, 0, 2, 0xffff00, { 2, 3, 1, 1},
878 { 0x500, 0, 0x300, 0x900, 0x900},0,
879 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
880 { "Leadtek WinFast 2000",
881 3, 1, 0, 2, 0xfff000, { 2, 3, 1, 1,0},
882 { 0x621000,0x620100,0x621100,0x620000,0xE210000,0x620000},0,
883 1,1,1,1,1,0,0,1, PLL_28
, -1 },
884 { "Chronos Video Shuttle II",
885 3, 3, 0, 2, 0x1800, { 2, 3, 1, 1}, { 0, 0, 0x1000, 0x1000, 0x0800},0,
886 1,1,1,1,0,0,0,1, PLL_28
, -1 },
888 { "Typhoon TView TV/FM Tuner",
889 3, 3, 0, 2, 0x1800, { 2, 3, 1, 1}, { 0, 0x800, 0, 0, 0x1800, 0 },0,
890 1,1,1,1,0,0,0,1, PLL_28
, -1 },
891 { "PixelView PlayTV pro",
892 3, 1, 0, 2, 0xff, { 2, 3, 1, 1 },
893 { 0x21, 0x20, 0x24, 0x2c, 0x29, 0x29 }, 0,
894 0,0,0,0,0,0,0,1, PLL_28
, -1 },
896 3, 1, 0, 2, 0x551e00, { 2, 3, 1, 1},
897 { 0x551400, 0x551200, 0, 0, 0, 0x551200 }, 0,
898 1,1,1,1,0,0,0,1, PLL_28
, -1 },
899 { "Pinnacle PCTV Rave",
900 3, 1, 0, 2, 0x03000F, { 2, 3, 1, 1}, { 2, 0, 0, 0, 1},0,
901 1,1,1,1,0,0,0,1, PLL_NONE
, -1 },
905 3, 1, 0, 2, 7, { 2, 3, 1, 1}, { 4, 0, 2, 3, 1},0,
906 0,1,1,1,0,1,1,1, PLL_NONE
, -1 },
907 { "AVerMedia TVPhone 98",
908 3, 4, 0, 2, 4, { 2, 3, 1, 1}, { 13, 14, 11, 7, 0, 0},0,
909 1,1,1,1,0,0,0,1, PLL_28
, 5 },
910 { "ProVideo PV951", /* pic16c54 */
911 3, 1, 0, 2, 0, { 2, 3, 1, 1}, { 0, 0, 0, 0, 0},0,
912 0,0,0,0,0,0,0,0, PLL_28
, 1 },
914 #define TVCARDS (sizeof(tvcards)/sizeof(struct tvcard))
916 static void __init
dump_eeprom(struct bttv
*btv
,int addr
)
922 /* for debugging: dump eeprom to syslog */
923 printk(KERN_DEBUG
"bttv%d: dump eeprom @ 0x%02x\n",btv
->nr
,addr
);
924 for (i
= 0; i
< 256;) {
925 printk(KERN_DEBUG
" %02x:",i
);
927 printk(" %02x",eeprom_data
[i
++]);
933 static int __init
idcard_eeprom(struct bttv
*btv
)
938 id
= (eeprom_data
[252] << 24) |
939 (eeprom_data
[253] << 16) |
940 (eeprom_data
[254] << 8) |
942 if (id
== 0 || id
== 0xffffffff)
945 /* look for the card */
946 for (n
= -1, i
= 0; cards
[i
].id
!= 0; i
++)
947 if (cards
[i
].id
== id
)
952 printk(KERN_INFO
"bttv%d: id: %s (0x%08x)\n",
953 btv
->nr
,cards
[n
].name
,id
);
955 printk(KERN_INFO
"bttv%d: => card=%d (%s)\n",
956 btv
->nr
,cards
[n
].cardnr
,
957 tvcards
[cards
[n
].cardnr
].name
);
958 return cards
[n
].cardnr
;
961 printk(KERN_INFO
"bttv%d: id: unknown (0x%08x)\n",
963 printk(KERN_INFO
"please mail id, board name and "
964 "the correct card= insmod option to "
965 "kraxel@goldbach.in-berlin.de\n");
970 /* ----------------------------------------------------------------------- */
972 static void audio(struct bttv
*btv
, int mode
, int no_irq_context
)
974 btaor(tvcards
[btv
->type
].gpiomask
, ~tvcards
[btv
->type
].gpiomask
,
980 btv
->audio
|=AUDIO_MUTE
;
983 btv
->audio
&=~AUDIO_MUTE
;
993 btv
->audio
&=AUDIO_MUTE
;
997 /* if audio mute or not in H-lock, turn audio off */
998 if ((btv
->audio
&AUDIO_MUTE
))
1000 if ((mode
== AUDIO_TUNER
) && (btv
->radio
))
1002 btaor(tvcards
[btv
->type
].audiomux
[mode
],
1003 ~tvcards
[btv
->type
].gpiomask
, BT848_GPIO_DATA
);
1005 call_i2c_clients(btv
,AUDC_SET_INPUT
,&(mode
));
1009 extern inline void bt848_dma(struct bttv
*btv
, uint state
)
1012 btor(3, BT848_GPIO_DMA_CTL
);
1014 btand(~3, BT848_GPIO_DMA_CTL
);
1018 /* If Bt848a or Bt849, use PLL for PAL/SECAM and crystal for NTSC*/
1020 /* Frequency = (F_input / PLL_X) * PLL_I.PLL_F/PLL_C
1021 PLL_X = Reference pre-divider (0=1, 1=2)
1022 PLL_C = Post divider (0=6, 1=4)
1023 PLL_I = Integer input
1024 PLL_F = Fractional input
1026 F_input = 28.636363 MHz:
1027 PAL (CLKx2 = 35.46895 MHz): PLL_X = 1, PLL_I = 0x0E, PLL_F = 0xDCF9, PLL_C = 0
1030 static void set_pll_freq(struct bttv
*btv
, unsigned int fin
, unsigned int fout
)
1032 unsigned char fl
, fh
, fi
;
1034 /* prevent overflows */
1041 fout
=(fout
%fin
)*256;
1044 fout
=(fout
%fin
)*256;
1047 /*printk("0x%02x 0x%02x 0x%02x\n", fi, fh, fl);*/
1048 btwrite(fl
, BT848_PLL_F_LO
);
1049 btwrite(fh
, BT848_PLL_F_HI
);
1050 btwrite(fi
|BT848_PLL_X
, BT848_PLL_XCI
);
1053 static int set_pll(struct bttv
*btv
)
1058 if (!btv
->pll
.pll_crystal
)
1061 if (btv
->pll
.pll_ifreq
== btv
->pll
.pll_ofreq
) {
1063 if (btv
->pll
.pll_current
== 0) {
1064 /* printk ("bttv%d: PLL: is off\n",btv->nr); */
1067 printk ("bttv%d: PLL: switching off\n",btv
->nr
);
1068 btwrite(0x00,BT848_TGCTRL
);
1069 btwrite(0x00,BT848_PLL_XCI
);
1070 btv
->pll
.pll_current
= 0;
1074 if (btv
->pll
.pll_ofreq
== btv
->pll
.pll_current
) {
1075 /* printk("bttv%d: PLL: no change required\n",btv->nr); */
1080 printk("bttv%d: PLL: %d => %d ... ",btv
->nr
,
1081 btv
->pll
.pll_ifreq
, btv
->pll
.pll_ofreq
);
1083 set_pll_freq(btv
, btv
->pll
.pll_ifreq
, btv
->pll
.pll_ofreq
);
1085 /* Let other people run while the PLL stabilizes */
1086 tv
=jiffies
+HZ
/10; /* .1 seconds */
1091 while(time_before(jiffies
,tv
));
1093 for (i
=0; i
<100; i
++)
1095 if ((btread(BT848_DSTATUS
)&BT848_DSTATUS_PLOCK
))
1096 btwrite(0,BT848_DSTATUS
);
1099 btwrite(0x08,BT848_TGCTRL
);
1100 btv
->pll
.pll_current
= btv
->pll
.pll_ofreq
;
1107 btv
->pll
.pll_current
= 0;
1113 static void bt848_muxsel(struct bttv
*btv
, unsigned int input
)
1115 btaor(tvcards
[btv
->type
].gpiomask2
,~tvcards
[btv
->type
].gpiomask2
,
1118 /* This seems to get rid of some synchronization problems */
1119 btand(~(3<<5), BT848_IFORM
);
1123 input
%= tvcards
[btv
->type
].video_inputs
;
1124 if (input
==tvcards
[btv
->type
].svhs
)
1126 btor(BT848_CONTROL_COMP
, BT848_E_CONTROL
);
1127 btor(BT848_CONTROL_COMP
, BT848_O_CONTROL
);
1131 btand(~BT848_CONTROL_COMP
, BT848_E_CONTROL
);
1132 btand(~BT848_CONTROL_COMP
, BT848_O_CONTROL
);
1134 btaor((tvcards
[btv
->type
].muxsel
[input
&7]&3)<<5, ~(3<<5), BT848_IFORM
);
1135 audio(btv
, (input
!=tvcards
[btv
->type
].tuner
) ?
1136 AUDIO_EXTERN
: AUDIO_TUNER
, 1);
1137 btaor(tvcards
[btv
->type
].muxsel
[input
]>>4,
1138 ~tvcards
[btv
->type
].gpiomask2
, BT848_GPIO_DATA
);
1145 u16 swidth
, sheight
; /* scaled standard width, height */
1147 u8 adelay
, bdelay
, iform
;
1149 u16 hdelayx1
, hactivex1
;
1154 static struct tvnorm tvnorms
[] = {
1156 /* max. active video is actually 922, but 924 is divisible by 4 and 3! */
1157 /* actually, max active PAL with HSCALE=0 is 948, NTSC is 768 - nil */
1159 924, 576, 1135, 0x7f, 0x72, (BT848_IFORM_PAL_BDGHI
|BT848_IFORM_XT1
),
1160 1135, 186, 924, 0x20, 255},
1164 768, 480, 910, 0x68, 0x5d, (BT848_IFORM_NTSC
|BT848_IFORM_XT0
),
1165 910, 128, 910, 0x1a, 144},
1169 768, 576, 1135, 0x7f, 0xb0, (BT848_IFORM_SECAM
|BT848_IFORM_XT1
),
1170 944, 186, 922, 0x20, 255},
1174 924, 576, 1135, 0x7f, 0xb0, (BT848_IFORM_SECAM
|BT848_IFORM_XT1
),
1175 1135, 186, 922, 0x20, 255},
1179 640, 576, 910, 0x68, 0x5d, (BT848_IFORM_PAL_NC
|BT848_IFORM_XT0
),
1180 780, 130, 734, 0x1a, 144},
1183 640, 480, 910, 0x68, 0x5d, (BT848_IFORM_PAL_M
|BT848_IFORM_XT0
),
1184 780, 135, 754, 0x1a, 144},
1187 768, 576, 1135, 0x7f, 0x72, (BT848_IFORM_PAL_N
|BT848_IFORM_XT1
),
1188 944, 186, 922, 0x20, 144},
1191 640, 480, 910, 0x68, 0x5d, (BT848_IFORM_NTSC_J
|BT848_IFORM_XT0
),
1192 780, 135, 754, 0x16, 144},
1194 #define TVNORMS (sizeof(tvnorms)/sizeof(tvnorm))
1195 #define VBI_SPL 2044
1197 /* RISC command to write one VBI data line */
1198 #define VBI_RISC BT848_RISC_WRITE|VBI_SPL|BT848_RISC_EOL|BT848_RISC_SOL
1200 static void make_vbitab(struct bttv
*btv
)
1203 unsigned int *po
=(unsigned int *) btv
->vbi_odd
;
1204 unsigned int *pe
=(unsigned int *) btv
->vbi_even
;
1207 printk("bttv%d: vbi1: po=%08lx pe=%08lx\n",
1208 btv
->nr
,virt_to_bus(po
), virt_to_bus(pe
));
1210 *(po
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
); *(po
++)=0;
1211 for (i
=0; i
<16; i
++)
1213 *(po
++)=cpu_to_le32(VBI_RISC
);
1214 *(po
++)=cpu_to_le32(kvirt_to_bus((unsigned long)btv
->vbibuf
+i
*2048));
1216 *(po
++)=cpu_to_le32(BT848_RISC_JUMP
);
1217 *(po
++)=cpu_to_le32(virt_to_bus(btv
->risc_jmp
+4));
1219 *(pe
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
); *(pe
++)=0;
1220 for (i
=16; i
<32; i
++)
1222 *(pe
++)=cpu_to_le32(VBI_RISC
);
1223 *(pe
++)=cpu_to_le32(kvirt_to_bus((unsigned long)btv
->vbibuf
+i
*2048));
1225 *(pe
++)=cpu_to_le32(BT848_RISC_JUMP
|BT848_RISC_IRQ
|(0x01<<16));
1226 *(pe
++)=cpu_to_le32(virt_to_bus(btv
->risc_jmp
+10));
1229 printk("bttv%d: vbi2: po=%08lx pe=%08lx\n",
1230 btv
->nr
,virt_to_bus(po
), virt_to_bus(pe
));
1233 static int fmtbppx2
[16] = {
1234 8, 6, 4, 4, 4, 3, 2, 2, 4, 3, 0, 0, 0, 0, 2, 0
1237 static int palette2fmt
[] = {
1240 BT848_COLOR_FMT_RGB8
,
1241 BT848_COLOR_FMT_RGB16
,
1242 BT848_COLOR_FMT_RGB24
,
1243 BT848_COLOR_FMT_RGB32
,
1244 BT848_COLOR_FMT_RGB15
,
1245 BT848_COLOR_FMT_YUY2
,
1246 BT848_COLOR_FMT_BtYUV
,
1250 BT848_COLOR_FMT_RAW
,
1251 BT848_COLOR_FMT_YCrCb422
,
1252 BT848_COLOR_FMT_YCrCb411
,
1253 BT848_COLOR_FMT_YCrCb422
,
1254 BT848_COLOR_FMT_YCrCb411
,
1256 #define PALETTEFMT_MAX (sizeof(palette2fmt)/sizeof(int))
1258 static int make_rawrisctab(struct bttv
*btv
, unsigned int *ro
,
1259 unsigned int *re
, unsigned int *vbuf
)
1262 unsigned long bpl
=1024; /* bytes per line */
1263 unsigned long vadr
=(unsigned long) vbuf
;
1265 *(ro
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
1266 *(ro
++)=cpu_to_le32(0);
1267 *(re
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
1268 *(re
++)=cpu_to_le32(0);
1270 /* In PAL 650 blocks of 256 DWORDs are sampled, but only if VDELAY
1271 is 2 and without separate VBI grabbing.
1272 We'll have to handle this inside the IRQ handler ... */
1274 for (line
=0; line
< 640; line
++)
1276 *(ro
++)=cpu_to_le32(BT848_RISC_WRITE
|bpl
|BT848_RISC_SOL
|BT848_RISC_EOL
);
1277 *(ro
++)=cpu_to_le32(kvirt_to_bus(vadr
));
1278 *(re
++)=cpu_to_le32(BT848_RISC_WRITE
|bpl
|BT848_RISC_SOL
|BT848_RISC_EOL
);
1279 *(re
++)=cpu_to_le32(kvirt_to_bus(vadr
+gbufsize
/2));
1283 *(ro
++)=cpu_to_le32(BT848_RISC_JUMP
);
1284 *(ro
++)=cpu_to_le32(btv
->bus_vbi_even
);
1285 *(re
++)=cpu_to_le32(BT848_RISC_JUMP
|BT848_RISC_IRQ
|(2<<16));
1286 *(re
++)=cpu_to_le32(btv
->bus_vbi_odd
);
1291 static int make_prisctab(struct bttv
*btv
, unsigned int *ro
,
1293 unsigned int *vbuf
, unsigned short width
,
1294 unsigned short height
, unsigned short fmt
)
1296 unsigned long line
, lmask
;
1297 unsigned long bl
, blcr
, blcb
, rcmd
;
1301 unsigned long cbadr
, cradr
;
1302 unsigned long vadr
=(unsigned long) vbuf
;
1306 printk("bttv%d: prisc1: ro=%08lx re=%08lx\n",
1307 btv
->nr
,virt_to_bus(ro
), virt_to_bus(re
));
1311 case VIDEO_PALETTE_YUV422P
:
1312 csize
=(width
*height
)>>1;
1317 case VIDEO_PALETTE_YUV411P
:
1318 csize
=(width
*height
)>>2;
1323 case VIDEO_PALETTE_YUV420P
:
1324 csize
=(width
*height
)>>2;
1329 case VIDEO_PALETTE_YUV410P
:
1330 csize
=(width
*height
)>>4;
1338 cbadr
=vadr
+(width
*height
);
1340 inter
= (height
>tvnorms
[btv
->win
.norm
].sheight
/2) ? 1 : 0;
1342 *(ro
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM3
);
1344 *(re
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM3
);
1347 for (line
=0; line
< (height
<<(1^inter
)); line
++)
1352 cbadr
=vadr
+(width
*height
);
1356 rp
= (line
&1) ? &re
: &ro
;
1358 rp
= (line
>=height
) ? &ro
: &re
;
1362 rcmd
=BT848_RISC_WRITE1S23
|BT848_RISC_SOL
;
1364 rcmd
=BT848_RISC_WRITE123
|BT848_RISC_SOL
;
1369 bl
=PAGE_SIZE
-((PAGE_SIZE
-1)&vadr
);
1370 blcr
=(PAGE_SIZE
-((PAGE_SIZE
-1)&cradr
))<<shift
;
1371 blcb
=(PAGE_SIZE
-((PAGE_SIZE
-1)&cbadr
))<<shift
;
1372 bl
=(blcr
<bl
) ? blcr
: bl
;
1373 bl
=(blcb
<bl
) ? blcb
: bl
;
1374 bl
=(bl
>todo
) ? todo
: bl
;
1377 /* bl now containts the longest row that can be written */
1379 if(!todo
) rcmd
|=BT848_RISC_EOL
; /* if this is the last EOL */
1381 *((*rp
)++)=cpu_to_le32(rcmd
|bl
);
1382 *((*rp
)++)=cpu_to_le32(blcb
|(blcr
<<16));
1383 *((*rp
)++)=cpu_to_le32(kvirt_to_bus(vadr
));
1385 if((rcmd
&(15<<28))==BT848_RISC_WRITE123
)
1387 *((*rp
)++)=(kvirt_to_bus(cbadr
));
1389 *((*rp
)++)=cpu_to_le32(kvirt_to_bus(cradr
));
1393 rcmd
&=~BT848_RISC_SOL
; /* only the first has SOL */
1397 *(ro
++)=cpu_to_le32(BT848_RISC_JUMP
);
1398 *(ro
++)=cpu_to_le32(btv
->bus_vbi_even
);
1399 *(re
++)=cpu_to_le32(BT848_RISC_JUMP
|BT848_RISC_IRQ
|(2<<16));
1400 *(re
++)=cpu_to_le32(btv
->bus_vbi_odd
);
1403 printk("bttv%d: prisc2: ro=%08lx re=%08lx\n",
1404 btv
->nr
,virt_to_bus(ro
), virt_to_bus(re
));
1409 static int make_vrisctab(struct bttv
*btv
, unsigned int *ro
,
1411 unsigned int *vbuf
, unsigned short width
,
1412 unsigned short height
, unsigned short palette
)
1415 unsigned long bpl
; /* bytes per line */
1420 unsigned long vadr
=(unsigned long) vbuf
;
1422 if (palette
==VIDEO_PALETTE_RAW
)
1423 return make_rawrisctab(btv
, ro
, re
, vbuf
);
1424 if (palette
>=VIDEO_PALETTE_PLANAR
)
1425 return make_prisctab(btv
, ro
, re
, vbuf
, width
, height
, palette
);
1428 printk("bttv%d: vrisc1: ro=%08lx re=%08lx\n",
1429 btv
->nr
,virt_to_bus(ro
), virt_to_bus(re
));
1431 inter
= (height
>tvnorms
[btv
->win
.norm
].sheight
/2) ? 1 : 0;
1432 bpl
=width
*fmtbppx2
[palette2fmt
[palette
]&0xf]/2;
1434 *(ro
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
1435 *(ro
++)=cpu_to_le32(0);
1436 *(re
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
1437 *(re
++)=cpu_to_le32(0);
1439 for (line
=0; line
< (height
<<(1^inter
)); line
++)
1442 rp
= (line
&1) ? &re
: &ro
;
1444 rp
= (line
>=height
) ? &ro
: &re
;
1446 bl
=PAGE_SIZE
-((PAGE_SIZE
-1)&vadr
);
1449 *((*rp
)++)=cpu_to_le32(BT848_RISC_WRITE
|BT848_RISC_SOL
|
1450 BT848_RISC_EOL
|bpl
);
1451 *((*rp
)++)=cpu_to_le32(kvirt_to_bus(vadr
));
1457 *((*rp
)++)=cpu_to_le32(BT848_RISC_WRITE
|BT848_RISC_SOL
|bl
);
1458 *((*rp
)++)=cpu_to_le32(kvirt_to_bus(vadr
));
1461 while (todo
>PAGE_SIZE
)
1463 *((*rp
)++)=cpu_to_le32(BT848_RISC_WRITE
|PAGE_SIZE
);
1464 *((*rp
)++)=cpu_to_le32(kvirt_to_bus(vadr
));
1468 *((*rp
)++)=cpu_to_le32(BT848_RISC_WRITE
|BT848_RISC_EOL
|todo
);
1469 *((*rp
)++)=cpu_to_le32(kvirt_to_bus(vadr
));
1474 *(ro
++)=cpu_to_le32(BT848_RISC_JUMP
);
1475 *(ro
++)=cpu_to_le32(btv
->bus_vbi_even
);
1476 *(re
++)=cpu_to_le32(BT848_RISC_JUMP
|BT848_RISC_IRQ
|(2<<16));
1477 *(re
++)=cpu_to_le32(btv
->bus_vbi_odd
);
1480 printk("bttv%d: vrisc2: ro=%08lx re=%08lx\n",
1481 btv
->nr
,virt_to_bus(ro
), virt_to_bus(re
));
1486 static unsigned char lmaskt
[8] =
1487 { 0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80};
1488 static unsigned char rmaskt
[8] =
1489 { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
1491 static void clip_draw_rectangle(unsigned char *clipmap
, int x
, int y
, int w
, int h
)
1493 unsigned char lmask
, rmask
, *p
;
1498 printk("bttv clip: %dx%d+%d+%d\n",w
,h
,x
,y
);
1500 /* bitmap is fixed width, 128 bytes (1024 pixels represented) */
1511 if (w
< 0 || h
< 0) /* catch bad clips */
1513 /* out of range data should just fall through */
1523 rmask
=rmaskt
[(x
+w
-1)&7];
1528 for (i
=0; i
<h
; i
++, p
+=128)
1531 memset(p
+1, 0xff, W
);
1535 for (i
=0; i
<h
; i
++, p
+=128)
1541 for (i
=0; i
<h
; i
++, p
+=128)
1548 static void make_clip_tab(struct bttv
*btv
, struct video_clip
*cr
, int ncr
)
1550 int i
, line
, x
, y
, bpl
, width
, height
, inter
, maxw
;
1551 unsigned int bpp
, dx
, sx
, **rp
, *ro
, *re
, flags
, len
;
1553 unsigned char *clipmap
, *clipline
, cbit
, lastbit
, outofmem
;
1555 /* take care: bpp != btv->win.bpp is allowed here */
1556 bpp
= fmtbppx2
[btv
->win
.color_fmt
&0xf]/2;
1558 adr
=btv
->win
.vidadr
+ btv
->win
.x
* btv
->win
.bpp
+ btv
->win
.y
* bpl
;
1559 inter
=(btv
->win
.interlace
&1)^1;
1560 width
=btv
->win
.width
;
1561 height
=btv
->win
.height
;
1563 printk("bttv%d: clip1: pal=%d size=%dx%d, bpl=%d bpp=%d\n",
1564 btv
->nr
,btv
->picture
.palette
,width
,height
,bpl
,bpp
);
1566 width
= 1023; /* sanity check */
1568 height
= 625; /* sanity check */
1569 ro
=btv
->risc_scr_odd
;
1570 re
=btv
->risc_scr_even
;
1573 printk("bttv%d: clip: ro=%08lx re=%08lx\n",
1574 btv
->nr
,virt_to_bus(ro
), virt_to_bus(re
));
1576 if ((clipmap
=vmalloc(VIDEO_CLIPMAP_SIZE
))==NULL
) {
1577 /* can't clip, don't generate any risc code */
1578 *(ro
++)=cpu_to_le32(BT848_RISC_JUMP
);
1579 *(ro
++)=cpu_to_le32(btv
->bus_vbi_even
);
1580 *(re
++)=cpu_to_le32(BT848_RISC_JUMP
);
1581 *(re
++)=cpu_to_le32(btv
->bus_vbi_odd
);
1583 if (ncr
< 0) { /* bitmap was pased */
1584 memcpy(clipmap
, (unsigned char *)cr
, VIDEO_CLIPMAP_SIZE
);
1585 } else { /* convert rectangular clips to a bitmap */
1586 memset(clipmap
, 0, VIDEO_CLIPMAP_SIZE
); /* clear map */
1587 for (i
=0; i
<ncr
; i
++)
1588 clip_draw_rectangle(clipmap
, cr
[i
].x
, cr
[i
].y
,
1589 cr
[i
].width
, cr
[i
].height
);
1591 /* clip against viewing window AND screen
1592 so we do not have to rely on the user program
1594 maxw
= (bpl
- btv
->win
.x
* btv
->win
.bpp
) / bpp
;
1595 clip_draw_rectangle(clipmap
, (width
> maxw
) ? maxw
: width
,
1597 clip_draw_rectangle(clipmap
,0,(btv
->win
.y
+height
>btv
->win
.sheight
) ?
1598 (btv
->win
.sheight
-btv
->win
.y
) : height
,1024,768);
1600 clip_draw_rectangle(clipmap
, 0, 0, -(btv
->win
.x
), 768);
1602 clip_draw_rectangle(clipmap
, 0, 0, 1024, -(btv
->win
.y
));
1604 *(ro
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
1605 *(ro
++)=cpu_to_le32(0);
1606 *(re
++)=cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
1607 *(re
++)=cpu_to_le32(0);
1609 /* translate bitmap to risc code */
1610 for (line
=outofmem
=0; line
< (height
<<inter
) && !outofmem
; line
++)
1613 rp
= (line
&1) ? &re
: &ro
;
1614 clipline
= clipmap
+ (y
<<7); /* running pointers ... */
1615 lastbit
= *clipline
& 1;
1616 for(x
=dx
=0,sx
=0; x
<=width
&& !outofmem
;) {
1618 /* check bytes not bits if we can ... */
1620 while (0xff==*clipline
&& x
<width
-8) {
1626 while (0x00==*clipline
&& x
<width
-8) {
1633 cbit
= *clipline
& (1<<(x
&7));
1634 if (x
< width
&& !lastbit
== !cbit
) {
1637 /* generate the dma controller code */
1639 flags
= ((bpp
==4) ? BT848_RISC_BYTE3
: 0);
1640 flags
|= ((!sx
) ? BT848_RISC_SOL
: 0);
1641 flags
|= ((sx
+ dx
== width
) ? BT848_RISC_EOL
: 0);
1643 *((*rp
)++)=cpu_to_le32(BT848_RISC_WRITE
|flags
|len
);
1644 *((*rp
)++)=cpu_to_le32(adr
+ bpp
* sx
);
1646 *((*rp
)++)=cpu_to_le32(BT848_RISC_SKIP
|flags
|len
);
1651 if (ro
- btv
->risc_scr_odd
>RISCMEM_LEN
/2 - 16)
1653 if (re
- btv
->risc_scr_even
>RISCMEM_LEN
/2 - 16)
1660 if ((!inter
)||(line
&1))
1665 /* outofmem flag relies on the following code to discard extra data */
1666 *(ro
++)=cpu_to_le32(BT848_RISC_JUMP
);
1667 *(ro
++)=cpu_to_le32(btv
->bus_vbi_even
);
1668 *(re
++)=cpu_to_le32(BT848_RISC_JUMP
);
1669 *(re
++)=cpu_to_le32(btv
->bus_vbi_odd
);
1672 printk("bttv%d: clip2: pal=%d size=%dx%d, bpl=%d bpp=%d\n",
1673 btv
->nr
,btv
->picture
.palette
,width
,height
,bpl
,bpp
);
1677 * Set the registers for the size we have specified. Don't bother
1678 * trying to understand this without the BT848 manual in front of
1681 * PS: The manual is free for download in .pdf format from
1682 * www.brooktree.com - nicely done those folks.
1685 static inline void bt848_set_eogeo(struct bttv
*btv
, struct tvnorm
*tvn
,
1686 int odd
, int width
, int height
)
1692 int inter
= (height
>tvn
->sheight
/2) ? 0 : 1;
1693 int off
= odd
? 0x80 : 0x00;
1695 xsf
= (width
*tvn
->scaledtwidth
)/tvn
->swidth
;
1696 hscale
= ((tvn
->totalwidth
*4096UL)/xsf
-4096);
1697 hdelay
= tvn
->hdelayx1
;
1698 hdelay
= (hdelay
*width
)/tvn
->swidth
;
1700 sr
=((tvn
->sheight
>>inter
)*512)/height
-512;
1701 vscale
=(0x10000UL
-sr
)&0x1fff;
1702 crop
=((width
>>8)&0x03)|((hdelay
>>6)&0x0c)|
1703 ((tvn
->sheight
>>4)&0x30)|((tvn
->vdelay
>>2)&0xc0);
1704 vscale
|= inter
? (BT848_VSCALE_INT
<<8) : 0;
1707 /* Some people say interpolation looks bad ... */
1708 vtc
= (width
< 193) ? 2 : ((width
< 385) ? 1 : 0);
1710 btor(BT848_VSCALE_COMB
, BT848_E_VSCALE_HI
+off
);
1712 btand(~BT848_VSCALE_COMB
, BT848_E_VSCALE_HI
+off
);
1715 btand(~BT848_VSCALE_COMB
, BT848_E_VSCALE_HI
+off
);
1718 btwrite(vtc
, BT848_E_VTC
+off
);
1719 btwrite(hscale
>>8, BT848_E_HSCALE_HI
+off
);
1720 btwrite(hscale
&0xff, BT848_E_HSCALE_LO
+off
);
1721 btaor((vscale
>>8), 0xe0, BT848_E_VSCALE_HI
+off
);
1722 btwrite(vscale
&0xff, BT848_E_VSCALE_LO
+off
);
1723 btwrite(width
&0xff, BT848_E_HACTIVE_LO
+off
);
1724 btwrite(hdelay
&0xff, BT848_E_HDELAY_LO
+off
);
1725 btwrite(tvn
->sheight
&0xff, BT848_E_VACTIVE_LO
+off
);
1726 btwrite(tvn
->vdelay
&0xff, BT848_E_VDELAY_LO
+off
);
1727 btwrite(crop
, BT848_E_CROP
+off
);
1731 static void bt848_set_geo(struct bttv
*btv
,
1734 u16 ewidth
, eheight
, owidth
, oheight
;
1737 unsigned long flags
;
1739 spin_lock_irqsave(&btv
->s_lock
, flags
);
1741 tvn
=&tvnorms
[btv
->win
.norm
];
1743 btwrite(tvn
->adelay
, BT848_ADELAY
);
1744 btwrite(tvn
->bdelay
, BT848_BDELAY
);
1745 btaor(tvn
->iform
,~(BT848_IFORM_NORM
|BT848_IFORM_XTBOTH
), BT848_IFORM
);
1746 btwrite(tvn
->vbipack
, BT848_VBI_PACK_SIZE
);
1747 btwrite(1, BT848_VBI_PACK_DEL
);
1749 btv
->pll
.pll_ofreq
= tvn
->Fsc
;
1753 btv
->win
.interlace
= (btv
->win
.height
>tvn
->sheight
/2) ? 1 : 0;
1755 if (0 == btv
->risc_cap_odd
&&
1756 0 == btv
->risc_cap_even
) {
1758 owidth
= btv
->win
.width
;
1759 oheight
= btv
->win
.height
;
1760 ewidth
= btv
->win
.width
;
1761 eheight
= btv
->win
.height
;
1762 format
= btv
->win
.color_fmt
;
1763 bswap
= btv
->fb_color_ctl
;
1764 } else if (-1 != btv
->gq_grab
&&
1765 0 == btv
->risc_cap_odd
&&
1766 !btv
->win
.interlace
&&
1768 /* odd field -> overlay, even field -> capture */
1769 owidth
= btv
->win
.width
;
1770 oheight
= btv
->win
.height
;
1771 ewidth
= btv
->gbuf
[btv
->gq_grab
].width
;
1772 eheight
= btv
->gbuf
[btv
->gq_grab
].height
;
1773 format
= (btv
->win
.color_fmt
& 0xf0) |
1774 (btv
->gbuf
[btv
->gq_grab
].fmt
& 0x0f);
1775 bswap
= btv
->fb_color_ctl
& 0x0a;
1778 owidth
= btv
->gbuf
[btv
->gq_grab
].width
;
1779 oheight
= btv
->gbuf
[btv
->gq_grab
].height
;
1780 ewidth
= btv
->gbuf
[btv
->gq_grab
].width
;
1781 eheight
= btv
->gbuf
[btv
->gq_grab
].height
;
1782 format
= btv
->gbuf
[btv
->gq_grab
].fmt
;
1786 /* program odd + even fields */
1787 bt848_set_eogeo(btv
, tvn
, 1, owidth
, oheight
);
1788 bt848_set_eogeo(btv
, tvn
, 0, ewidth
, eheight
);
1790 btwrite(format
, BT848_COLOR_FMT
);
1791 btwrite(bswap
| BT848_COLOR_CTL_GAMMA
, BT848_COLOR_CTL
);
1793 spin_unlock_irqrestore(&btv
->s_lock
, flags
);
1797 static int bpp2fmt
[4] = {
1798 BT848_COLOR_FMT_RGB8
, BT848_COLOR_FMT_RGB16
,
1799 BT848_COLOR_FMT_RGB24
, BT848_COLOR_FMT_RGB32
1802 static void bt848_set_winsize(struct bttv
*btv
)
1804 unsigned short format
;
1806 if (btv
->picture
.palette
> 0 && btv
->picture
.palette
<= VIDEO_PALETTE_YUV422
) {
1807 /* format set by VIDIOCSPICT */
1808 format
= palette2fmt
[btv
->picture
.palette
];
1810 /* use default for the given color depth */
1811 format
= (btv
->win
.depth
==15) ? BT848_COLOR_FMT_RGB15
:
1812 bpp2fmt
[(btv
->win
.bpp
-1)&3];
1814 btv
->win
.color_fmt
= format
;
1816 format
== BT848_COLOR_FMT_RGB32
) {
1818 BT848_COLOR_CTL_WSWAP_ODD
|
1819 BT848_COLOR_CTL_WSWAP_EVEN
|
1820 BT848_COLOR_CTL_BSWAP_ODD
|
1821 BT848_COLOR_CTL_BSWAP_EVEN
;
1822 } else if (bigendian
&&
1823 (format
== BT848_COLOR_FMT_RGB16
||
1824 format
== BT848_COLOR_FMT_RGB15
)) {
1826 BT848_COLOR_CTL_BSWAP_ODD
|
1827 BT848_COLOR_CTL_BSWAP_EVEN
;
1829 btv
->fb_color_ctl
= 0;
1832 /* RGB8 seems to be a 9x5x5 GRB color cube starting at
1833 * color 16. Why the h... can't they even mention this in the
1834 * data sheet? [AC - because it's a standard format so I guess
1835 * it never occurred to them]
1836 * Enable dithering in this mode.
1839 if (format
==BT848_COLOR_FMT_RGB8
)
1840 btand(~BT848_CAP_CTL_DITH_FRAME
, BT848_CAP_CTL
);
1842 btor(BT848_CAP_CTL_DITH_FRAME
, BT848_CAP_CTL
);
1844 bt848_set_geo(btv
,1);
1849 * Grab into virtual memory.
1850 * Currently only does double buffering. Do we need more?
1853 static int vgrab(struct bttv
*btv
, struct video_mmap
*mp
)
1855 unsigned int *ro
, *re
;
1857 unsigned long flags
;
1859 if(btv
->fbuffer
==NULL
)
1861 if(fbuffer_alloc(btv
))
1865 if(mp
->frame
>= gbuffers
|| mp
->frame
< 0)
1867 if(btv
->gbuf
[mp
->frame
].stat
!= GBUFFER_UNUSED
)
1870 if(mp
->height
< 32 || mp
->width
< 32)
1872 if (mp
->format
>= PALETTEFMT_MAX
)
1875 if (mp
->height
*mp
->width
*fmtbppx2
[palette2fmt
[mp
->format
]&0x0f]/2
1878 if(-1 == palette2fmt
[mp
->format
])
1882 * Ok load up the BT848
1885 vbuf
=(unsigned int *)(btv
->fbuffer
+gbufsize
*mp
->frame
);
1886 ro
=btv
->gbuf
[mp
->frame
].risc
;
1888 make_vrisctab(btv
, ro
, re
, vbuf
, mp
->width
, mp
->height
, mp
->format
);
1891 printk("bttv%d: cap vgrab: queue %d (%d:%dx%d)\n",
1892 btv
->nr
,mp
->frame
,mp
->format
,mp
->width
,mp
->height
);
1893 spin_lock_irqsave(&btv
->s_lock
, flags
);
1894 btv
->gbuf
[mp
->frame
].stat
= GBUFFER_GRABBING
;
1895 btv
->gbuf
[mp
->frame
].fmt
= palette2fmt
[mp
->format
];
1896 btv
->gbuf
[mp
->frame
].width
= mp
->width
;
1897 btv
->gbuf
[mp
->frame
].height
= mp
->height
;
1898 btv
->gbuf
[mp
->frame
].ro
= virt_to_bus(ro
);
1899 btv
->gbuf
[mp
->frame
].re
= virt_to_bus(re
);
1902 if (mp
->height
<= tvnorms
[btv
->win
.norm
].sheight
/2 &&
1903 mp
->format
!= VIDEO_PALETTE_RAW
)
1904 btv
->gbuf
[mp
->frame
].ro
= 0;
1907 if (btv
->gq_in
== btv
->gq_out
) {
1909 btv
->risc_jmp
[12]=cpu_to_le32(BT848_RISC_JUMP
|(0x8<<16)|BT848_RISC_IRQ
);
1911 btv
->gqueue
[btv
->gq_in
++] = mp
->frame
;
1912 btv
->gq_in
= btv
->gq_in
% MAX_GBUFFERS
;
1914 spin_unlock_irqrestore(&btv
->s_lock
, flags
);
1915 btor(3, BT848_CAP_CTL
);
1916 btor(3, BT848_GPIO_DMA_CTL
);
1921 static long bttv_write(struct video_device
*v
, const char *buf
, unsigned long count
, int nonblock
)
1926 static long bttv_read(struct video_device
*v
, char *buf
, unsigned long count
, int nonblock
)
1928 struct bttv
*btv
= (struct bttv
*)v
;
1931 /* BROKEN: RETURNS VBI WHEN IT SHOULD RETURN GRABBED VIDEO FRAME */
1933 while (todo
&& todo
>(q
=VBIBUF_SIZE
-btv
->vbip
))
1935 unsigned long flags
;
1937 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, q
))
1942 spin_lock_irqsave(&btv
->s_lock
, flags
);
1943 if (todo
&& q
==VBIBUF_SIZE
-btv
->vbip
)
1947 spin_unlock_irqrestore(&btv
->s_lock
, flags
);
1949 return -EWOULDBLOCK
;
1952 spin_unlock_irqrestore(&btv
->s_lock
, flags
);
1953 interruptible_sleep_on(&btv
->vbiq
);
1954 if(signal_pending(current
))
1962 spin_unlock_irqrestore(&btv
->s_lock
, flags
);
1966 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, todo
))
1973 static inline void burst(int on
)
1975 tvnorms
[0].scaledtwidth
= 1135 - (on
?BURSTOFFSET
-2:0);
1976 tvnorms
[0].hdelayx1
= 186 - (on
?BURSTOFFSET
:0);
1977 tvnorms
[2].scaledtwidth
= 1135 - (on
?BURSTOFFSET
-2:0);
1978 tvnorms
[2].hdelayx1
= 186 - (on
?BURSTOFFSET
:0);
1981 static void bt848_restart(struct bttv
*btv
)
1984 printk("bttv%d: resetting chip\n",btv
->nr
);
1985 btwrite(~0x0UL
, BT848_INT_STAT
);
1986 btand(~15, BT848_GPIO_DMA_CTL
);
1987 btwrite(0, BT848_SRESET
);
1988 btwrite(virt_to_bus(btv
->risc_jmp
+2),
1989 BT848_RISC_STRT_ADD
);
1991 /* enforce pll reprogramming */
1992 btv
->pll
.pll_current
= 0;
1996 btv
->needs_restart
= 0;
1997 bt848_set_geo(btv
,0);
1998 bt848_set_risc_jmps(btv
,-1);
2002 * Open a bttv card. Right now the flags stuff is just playing
2005 static int bttv_open(struct video_device
*dev
, int flags
)
2007 struct bttv
*btv
= (struct bttv
*)dev
;
2017 btv
->fbuffer
=(unsigned char *) rvmalloc(gbuffers
*gbufsize
);
2025 for (i
= 0; i
< gbuffers
; i
++)
2026 btv
->gbuf
[i
].stat
= GBUFFER_UNUSED
;
2028 if (btv
->needs_restart
)
2042 static void bttv_close(struct video_device
*dev
)
2044 struct bttv
*btv
=(struct bttv
*)dev
;
2049 btv
->risc_cap_odd
= 0;
2050 btv
->risc_cap_even
= 0;
2051 bt848_set_risc_jmps(btv
,-1);
2054 * A word of warning. At this point the chip
2055 * is still capturing because its FIFO hasn't emptied
2056 * and the DMA control operations are posted PCI
2060 btread(BT848_I2C
); /* This fixes the PCI posting delay */
2062 if (-1 != btv
->gq_grab
) {
2064 * This is sucky but right now I can't find a good way to
2065 * be sure its safe to free the buffer. We wait 5-6 fields
2066 * which is more than sufficient to be sure.
2068 current
->state
= TASK_UNINTERRUPTIBLE
;
2069 schedule_timeout(HZ
/10); /* Wait 1/10th of a second */
2073 * We have allowed it to drain.
2077 rvfree((void *) btv
->fbuffer
, gbuffers
*gbufsize
);
2084 /***********************************/
2085 /* ioctls and supporting functions */
2086 /***********************************/
2088 extern inline void bt848_bright(struct bttv
*btv
, uint bright
)
2090 btwrite(bright
&0xff, BT848_BRIGHT
);
2093 extern inline void bt848_hue(struct bttv
*btv
, uint hue
)
2095 btwrite(hue
&0xff, BT848_HUE
);
2098 extern inline void bt848_contrast(struct bttv
*btv
, uint cont
)
2100 unsigned int conthi
;
2103 btwrite(cont
&0xff, BT848_CONTRAST_LO
);
2104 btaor(conthi
, ~4, BT848_E_CONTROL
);
2105 btaor(conthi
, ~4, BT848_O_CONTROL
);
2108 extern inline void bt848_sat_u(struct bttv
*btv
, unsigned long data
)
2113 btwrite(data
&0xff, BT848_SAT_U_LO
);
2114 btaor(datahi
, ~2, BT848_E_CONTROL
);
2115 btaor(datahi
, ~2, BT848_O_CONTROL
);
2118 static inline void bt848_sat_v(struct bttv
*btv
, unsigned long data
)
2123 btwrite(data
&0xff, BT848_SAT_V_LO
);
2124 btaor(datahi
, ~1, BT848_E_CONTROL
);
2125 btaor(datahi
, ~1, BT848_O_CONTROL
);
2133 static int bttv_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
2135 struct bttv
*btv
=(struct bttv
*)dev
;
2138 if (debug
) printk("bttv%d: ioctl 0x%x\n",btv
->nr
,cmd
);
2143 struct video_capability b
;
2144 strcpy(b
.name
,btv
->video_dev
.name
);
2145 b
.type
= VID_TYPE_CAPTURE
|
2146 ((tvcards
[btv
->type
].tuner
!= -1) ? VID_TYPE_TUNER
: 0) |
2151 b
.channels
= tvcards
[btv
->type
].video_inputs
;
2152 b
.audios
= tvcards
[btv
->type
].audio_inputs
;
2153 b
.maxwidth
= tvnorms
[btv
->win
.norm
].swidth
;
2154 b
.maxheight
= tvnorms
[btv
->win
.norm
].sheight
;
2157 if(copy_to_user(arg
,&b
,sizeof(b
)))
2163 struct video_channel v
;
2164 if(copy_from_user(&v
, arg
,sizeof(v
)))
2166 v
.flags
=VIDEO_VC_AUDIO
;
2168 v
.type
=VIDEO_TYPE_CAMERA
;
2169 v
.norm
= btv
->win
.norm
;
2170 if (v
.channel
>=tvcards
[btv
->type
].video_inputs
)
2172 if(v
.channel
==tvcards
[btv
->type
].tuner
)
2174 strcpy(v
.name
,"Television");
2175 v
.flags
|=VIDEO_VC_TUNER
;
2176 v
.type
=VIDEO_TYPE_TV
;
2179 else if(v
.channel
==tvcards
[btv
->type
].svhs
)
2180 strcpy(v
.name
,"S-Video");
2182 sprintf(v
.name
,"Composite%d",v
.channel
);
2184 if(copy_to_user(arg
,&v
,sizeof(v
)))
2189 * Each channel has 1 tuner
2193 struct video_channel v
;
2194 if(copy_from_user(&v
, arg
,sizeof(v
)))
2197 if (v
.channel
>tvcards
[btv
->type
].video_inputs
)
2199 if (v
.norm
> (sizeof(tvnorms
)/sizeof(*tvnorms
)))
2202 call_i2c_clients(btv
,cmd
,&v
);
2204 bt848_muxsel(btv
, v
.channel
);
2205 btv
->channel
=v
.channel
;
2206 if (btv
->win
.norm
!= v
.norm
) {
2207 btv
->win
.norm
= v
.norm
;
2209 bt848_set_winsize(btv
);
2216 struct video_tuner v
;
2217 if(copy_from_user(&v
,arg
,sizeof(v
))!=0)
2219 if(v
.tuner
||btv
->channel
) /* Only tuner 0 */
2221 strcpy(v
.name
, "Television");
2223 v
.rangehigh
=0xFFFFFFFF;
2224 v
.flags
=VIDEO_TUNER_PAL
|VIDEO_TUNER_NTSC
|VIDEO_TUNER_SECAM
;
2225 v
.mode
= btv
->win
.norm
;
2226 v
.signal
= (btread(BT848_DSTATUS
)&BT848_DSTATUS_HLOC
) ? 0xFFFF : 0;
2227 call_i2c_clients(btv
,cmd
,&v
);
2228 if(copy_to_user(arg
,&v
,sizeof(v
)))
2232 /* We have but one tuner */
2235 struct video_tuner v
;
2236 if(copy_from_user(&v
, arg
, sizeof(v
)))
2238 /* Only one channel has a tuner */
2239 if(v
.tuner
!=tvcards
[btv
->type
].tuner
)
2242 if(v
.mode
!=VIDEO_MODE_PAL
&&v
.mode
!=VIDEO_MODE_NTSC
2243 &&v
.mode
!=VIDEO_MODE_SECAM
)
2245 call_i2c_clients(btv
,cmd
,&v
);
2246 if (btv
->win
.norm
!= v
.mode
) {
2247 btv
->win
.norm
= v
.mode
;
2251 bt848_set_winsize(btv
);
2258 struct video_picture p
=btv
->picture
;
2259 if(copy_to_user(arg
, &p
, sizeof(p
)))
2265 struct video_picture p
;
2266 if(copy_from_user(&p
, arg
,sizeof(p
)))
2268 if (p
.palette
> PALETTEFMT_MAX
)
2271 /* We want -128 to 127 we get 0-65535 */
2272 bt848_bright(btv
, (p
.brightness
>>8)-128);
2273 /* 0-511 for the colour */
2274 bt848_sat_u(btv
, p
.colour
>>7);
2275 bt848_sat_v(btv
, ((p
.colour
>>7)*201L)/237);
2277 bt848_hue(btv
, (p
.hue
>>8)-128);
2279 bt848_contrast(btv
, p
.contrast
>>7);
2286 struct video_window vw
;
2287 struct video_clip
*vcp
= NULL
;
2289 if(copy_from_user(&vw
,arg
,sizeof(vw
)))
2292 if(vw
.flags
|| vw
.width
< 16 || vw
.height
< 16)
2296 bt848_set_risc_jmps(btv
,-1);
2300 if (btv
->win
.bpp
< 4)
2301 { /* adjust and align writes */
2302 vw
.x
= (vw
.x
+ 3) & ~3;
2306 if (btv
->needs_restart
)
2310 btv
->win
.width
=vw
.width
;
2311 btv
->win
.height
=vw
.height
;
2313 bt848_set_risc_jmps(btv
,0);
2315 bt848_set_winsize(btv
);
2321 if(vw
.clipcount
<0) {
2322 if((vcp
=vmalloc(VIDEO_CLIPMAP_SIZE
))==NULL
)
2324 if(copy_from_user(vcp
, vw
.clips
,
2325 VIDEO_CLIPMAP_SIZE
)) {
2329 } else if (vw
.clipcount
) {
2330 if((vcp
=vmalloc(sizeof(struct video_clip
)*
2331 (vw
.clipcount
))) == NULL
)
2333 if(copy_from_user(vcp
,vw
.clips
,
2334 sizeof(struct video_clip
)*
2341 make_clip_tab(btv
, vcp
, vw
.clipcount
);
2342 if (vw
.clipcount
!= 0)
2344 bt848_set_risc_jmps(btv
,-1);
2350 struct video_window vw
;
2351 /* Oh for a COBOL move corresponding .. */
2354 vw
.width
=btv
->win
.width
;
2355 vw
.height
=btv
->win
.height
;
2358 if(btv
->win
.interlace
)
2359 vw
.flags
|=VIDEO_WINDOW_INTERLACE
;
2360 if(copy_to_user(arg
,&vw
,sizeof(vw
)))
2367 if(copy_from_user(&v
, arg
,sizeof(v
)))
2369 if(btv
->win
.vidadr
== 0)
2371 if (btv
->win
.width
==0 || btv
->win
.height
==0)
2374 if (v
== 1 && btv
->win
.vidadr
!= 0)
2378 bt848_set_risc_jmps(btv
,-1);
2384 struct video_buffer v
;
2385 v
.base
=(void *)btv
->win
.vidadr
;
2386 v
.height
=btv
->win
.sheight
;
2387 v
.width
=btv
->win
.swidth
;
2388 v
.depth
=btv
->win
.depth
;
2389 v
.bytesperline
=btv
->win
.bpl
;
2390 if(copy_to_user(arg
, &v
,sizeof(v
)))
2397 struct video_buffer v
;
2398 if(!capable(CAP_SYS_ADMIN
) &&
2399 !capable(CAP_SYS_RAWIO
))
2401 if(copy_from_user(&v
, arg
,sizeof(v
)))
2403 if(v
.depth
!=8 && v
.depth
!=15 && v
.depth
!=16 &&
2404 v
.depth
!=24 && v
.depth
!=32 && v
.width
> 16 &&
2405 v
.height
> 16 && v
.bytesperline
> 16)
2409 btv
->win
.vidadr
=(unsigned long)v
.base
;
2410 btv
->win
.sheight
=v
.height
;
2411 btv
->win
.swidth
=v
.width
;
2412 btv
->win
.bpp
=((v
.depth
+7)&0x38)/8;
2413 btv
->win
.depth
=v
.depth
;
2414 btv
->win
.bpl
=v
.bytesperline
;
2416 /* set sefault color format */
2417 switch (btv
->win
.bpp
) {
2418 case 8: btv
->picture
.palette
= VIDEO_PALETTE_HI240
; break;
2419 case 15: btv
->picture
.palette
= VIDEO_PALETTE_RGB555
; break;
2420 case 16: btv
->picture
.palette
= VIDEO_PALETTE_RGB565
; break;
2421 case 24: btv
->picture
.palette
= VIDEO_PALETTE_RGB24
; break;
2422 case 32: btv
->picture
.palette
= VIDEO_PALETTE_RGB32
; break;
2426 printk("Display at %p is %d by %d, bytedepth %d, bpl %d\n",
2427 v
.base
, v
.width
,v
.height
, btv
->win
.bpp
, btv
->win
.bpl
);
2428 bt848_set_winsize(btv
);
2434 /* Will be handled higher up .. */
2439 unsigned long v
=btv
->win
.freq
;
2440 if(copy_to_user(arg
,&v
,sizeof(v
)))
2447 if(copy_from_user(&v
, arg
, sizeof(v
)))
2450 call_i2c_clients(btv
,cmd
,&v
);
2456 struct video_audio v
;
2459 v
.flags
&=~(VIDEO_AUDIO_MUTE
|VIDEO_AUDIO_MUTABLE
);
2460 v
.flags
|=VIDEO_AUDIO_MUTABLE
;
2461 strcpy(v
.name
,"TV");
2463 v
.mode
= VIDEO_SOUND_MONO
;
2464 call_i2c_clients(btv
,cmd
,&v
);
2466 if (btv
->type
== BTTV_TERRATV
) {
2467 v
.mode
= VIDEO_SOUND_MONO
;
2468 v
.mode
|= VIDEO_SOUND_STEREO
;
2469 v
.mode
|= VIDEO_SOUND_LANG1
|VIDEO_SOUND_LANG2
;
2471 } else if (btv
->audio_chip
== TDA9840
) {
2472 /* begin of Horrible Hack <grin@tolna.net> */
2473 v
.flags
|=VIDEO_AUDIO_VOLUME
;
2474 v
.mode
= VIDEO_SOUND_MONO
;
2475 v
.mode
|= VIDEO_SOUND_STEREO
;
2476 v
.mode
|= VIDEO_SOUND_LANG1
|VIDEO_SOUND_LANG2
;
2477 v
.volume
= 32768; /* fixme */
2481 if(copy_to_user(arg
,&v
,sizeof(v
)))
2487 struct video_audio v
;
2489 if(copy_from_user(&v
,arg
, sizeof(v
)))
2492 if(v
.flags
&VIDEO_AUDIO_MUTE
)
2493 audio(btv
, AUDIO_MUTE
, 1);
2494 /* One audio source per tuner -- huh? <GA> */
2495 if(v
.audio
<0 || v
.audio
>= tvcards
[btv
->type
].audio_inputs
) {
2499 /* bt848_muxsel(btv,v.audio); */
2500 if(!(v
.flags
&VIDEO_AUDIO_MUTE
))
2501 audio(btv
, AUDIO_UNMUTE
, 1);
2504 call_i2c_clients(btv
,cmd
,&v
);
2507 if (btv
->type
== BTTV_TERRATV
) {
2508 unsigned int con
= 0;
2509 btor(0x180000, BT848_GPIO_OUT_EN
);
2510 if (v
.mode
& VIDEO_SOUND_LANG2
)
2512 if (v
.mode
& VIDEO_SOUND_STEREO
)
2514 btaor(con
, ~0x180000, BT848_GPIO_DATA
);
2516 } else if (btv
->type
== BTTV_WINVIEW_601
) {
2517 /* PT2254A programming Jon Tombs, jon@gte.esi.us.es */
2518 int bits_out
, loops
, vol
, data
;
2520 /* 32 levels logarithmic */
2521 vol
= 32 - ((v
.volume
>>11));
2523 bits_out
= (PT2254_DBS_IN_2
>>(vol
%5));
2525 bits_out
|= (PT2254_DBS_IN_10
>>(vol
/5));
2526 bits_out
|= PT2254_L_CHANEL
| PT2254_R_CHANEL
;
2527 data
= btread(BT848_GPIO_DATA
);
2528 data
&= ~(WINVIEW_PT2254_CLK
| WINVIEW_PT2254_DATA
|
2529 WINVIEW_PT2254_STROBE
);
2530 for (loops
= 17; loops
>= 0 ; loops
--) {
2531 if (bits_out
& (1<<loops
))
2532 data
|= WINVIEW_PT2254_DATA
;
2534 data
&= ~WINVIEW_PT2254_DATA
;
2535 btwrite(data
, BT848_GPIO_DATA
);
2537 data
|= WINVIEW_PT2254_CLK
;
2538 btwrite(data
, BT848_GPIO_DATA
);
2540 data
&= ~WINVIEW_PT2254_CLK
;
2541 btwrite(data
, BT848_GPIO_DATA
);
2543 data
|= WINVIEW_PT2254_STROBE
;
2544 data
&= ~WINVIEW_PT2254_DATA
;
2545 btwrite(data
, BT848_GPIO_DATA
);
2547 data
&= ~WINVIEW_PT2254_STROBE
;
2548 btwrite(data
, BT848_GPIO_DATA
);
2557 if(copy_from_user((void *)&i
,arg
,sizeof(int)))
2559 if (i
< 0 || i
>= gbuffers
)
2561 switch (btv
->gbuf
[i
].stat
) {
2562 case GBUFFER_UNUSED
:
2565 case GBUFFER_GRABBING
:
2566 while(btv
->gbuf
[i
].stat
==GBUFFER_GRABBING
) {
2568 printk("bttv%d: cap sync: sleep on %d\n",btv
->nr
,i
);
2569 interruptible_sleep_on(&btv
->capq
);
2570 if(signal_pending(current
))
2576 ret
= (btv
->gbuf
[i
].stat
== GBUFFER_ERROR
) ? -EIO
: 0;
2578 printk("bttv%d: cap sync: buffer %d, retval %d\n",btv
->nr
,i
,ret
);
2579 btv
->gbuf
[i
].stat
= GBUFFER_UNUSED
;
2581 if (btv
->needs_restart
) {
2589 if(copy_to_user((void *) arg
, (void *) &btv
->last_field
,
2590 sizeof(btv
->last_field
)))
2595 struct bttv_pll_info p
;
2596 if(!capable(CAP_SYS_ADMIN
))
2598 if(copy_from_user(&p
, (void *) arg
, sizeof(btv
->pll
)))
2601 btv
->pll
.pll_ifreq
= p
.pll_ifreq
;
2602 btv
->pll
.pll_ofreq
= p
.pll_ofreq
;
2603 btv
->pll
.pll_crystal
= p
.pll_crystal
;
2609 case VIDIOCMCAPTURE
:
2611 struct video_mmap vm
;
2613 if(copy_from_user((void *) &vm
, (void *) arg
, sizeof(vm
)))
2616 ret
= vgrab(btv
, &vm
);
2623 struct video_mbuf vm
;
2624 memset(&vm
, 0 , sizeof(vm
));
2625 vm
.size
=gbufsize
*gbuffers
;
2627 for (i
= 0; i
< gbuffers
; i
++)
2628 vm
.offsets
[i
]=i
*gbufsize
;
2629 if(copy_to_user((void *)arg
, (void *)&vm
, sizeof(vm
)))
2636 struct video_unit vu
;
2637 vu
.video
=btv
->video_dev
.minor
;
2638 vu
.vbi
=btv
->vbi_dev
.minor
;
2639 if(btv
->radio_dev
.minor
!=-1)
2640 vu
.radio
=btv
->radio_dev
.minor
;
2642 vu
.radio
=VIDEO_NO_UNIT
;
2643 vu
.audio
=VIDEO_NO_UNIT
;
2644 vu
.teletext
=VIDEO_NO_UNIT
;
2645 if(copy_to_user((void *)arg
, (void *)&vu
, sizeof(vu
)))
2656 case BTTV_BURST_OFF
:
2664 return BTTV_VERSION_CODE
;
2669 /* return picture;*/
2674 return -ENOIOCTLCMD
;
2679 static int bttv_init_done(struct video_device
*dev
)
2685 * This maps the vmalloced and reserved fbuffer to user space.
2688 * - PAGE_READONLY should suffice!?
2689 * - remap_page_range is kind of inefficient for page by page remapping.
2690 * But e.g. pte_alloc() does not work in modules ... :-(
2693 static int do_bttv_mmap(struct bttv
*btv
, const char *adr
, unsigned long size
)
2695 unsigned long start
=(unsigned long) adr
;
2696 unsigned long page
,pos
;
2698 if (size
>gbuffers
*gbufsize
)
2700 if (!btv
->fbuffer
) {
2701 if(fbuffer_alloc(btv
))
2704 pos
=(unsigned long) btv
->fbuffer
;
2706 page
= kvirt_to_pa(pos
);
2707 if (remap_page_range(start
, page
, PAGE_SIZE
, PAGE_SHARED
))
2716 static int bttv_mmap(struct video_device
*dev
, const char *adr
, unsigned long size
)
2718 struct bttv
*btv
=(struct bttv
*)dev
;
2722 r
=do_bttv_mmap(btv
, adr
, size
);
2728 static struct video_device bttv_template
=
2731 VID_TYPE_TUNER
|VID_TYPE_CAPTURE
|VID_TYPE_OVERLAY
|VID_TYPE_TELETEXT
,
2747 static long vbi_read(struct video_device
*v
, char *buf
, unsigned long count
,
2750 struct bttv
*btv
=(struct bttv
*)(v
-2);
2754 while (todo
&& todo
>(q
=VBIBUF_SIZE
-btv
->vbip
))
2756 unsigned long flags
;
2758 if (btv
->needs_restart
) {
2763 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, q
))
2768 spin_lock_irqsave(&btv
->s_lock
, flags
);
2769 if (todo
&& q
==VBIBUF_SIZE
-btv
->vbip
)
2773 spin_unlock_irqrestore(&btv
->s_lock
, flags
);
2775 return -EWOULDBLOCK
;
2778 spin_unlock_irqrestore(&btv
->s_lock
, flags
);
2779 interruptible_sleep_on(&btv
->vbiq
);
2780 if(signal_pending(current
))
2788 spin_unlock_irqrestore(&btv
->s_lock
, flags
);
2792 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, todo
))
2799 static unsigned int vbi_poll(struct video_device
*dev
, struct file
*file
,
2802 struct bttv
*btv
=(struct bttv
*)(dev
-2);
2803 unsigned int mask
= 0;
2805 poll_wait(file
, &btv
->vbiq
, wait
);
2807 if (btv
->vbip
< VBIBUF_SIZE
)
2808 mask
|= (POLLIN
| POLLRDNORM
);
2813 static int vbi_open(struct video_device
*dev
, int flags
)
2815 struct bttv
*btv
=(struct bttv
*)(dev
-2);
2820 if (btv
->needs_restart
)
2822 btv
->vbip
=VBIBUF_SIZE
;
2824 bt848_set_risc_jmps(btv
,-1);
2830 static void vbi_close(struct video_device
*dev
)
2832 struct bttv
*btv
=(struct bttv
*)(dev
-2);
2836 bt848_set_risc_jmps(btv
,-1);
2842 static int vbi_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
2844 struct bttv
*btv
=(struct bttv
*)dev
;
2849 struct video_capability b
;
2850 strcpy(b
.name
,btv
->vbi_dev
.name
);
2851 b
.type
= ((tvcards
[btv
->type
].tuner
!= -1) ? VID_TYPE_TUNER
: 0) |
2859 if(copy_to_user(arg
,&b
,sizeof(b
)))
2865 return bttv_ioctl((struct video_device
*)btv
,cmd
,arg
);
2867 /* make alevt happy :-) */
2874 static struct video_device vbi_template
=
2877 VID_TYPE_CAPTURE
|VID_TYPE_TELETEXT
,
2885 NULL
, /* no mmap yet */
2893 static int radio_open(struct video_device
*dev
, int flags
)
2895 struct bttv
*btv
= (struct bttv
*)(dev
-1);
2906 call_i2c_clients(btv
,VIDIOCSFREQ
,&v
);
2907 call_i2c_clients(btv
,AUDC_SET_RADIO
,&btv
->tuner_type
);
2908 bt848_muxsel(btv
,0);
2919 static void radio_close(struct video_device
*dev
)
2921 struct bttv
*btv
=(struct bttv
*)(dev
-1);
2930 static long radio_read(struct video_device
*v
, char *buf
, unsigned long count
, int nonblock
)
2935 static int radio_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
2937 struct bttv
*btv
=(struct bttv
*)(dev
-1);
2941 struct video_capability v
;
2942 strcpy(v
.name
,btv
->video_dev
.name
);
2943 v
.type
= VID_TYPE_TUNER
;
2946 /* No we don't do pictures */
2951 if (copy_to_user(arg
, &v
, sizeof(v
)))
2958 struct video_tuner v
;
2959 if(copy_from_user(&v
,arg
,sizeof(v
))!=0)
2961 if(v
.tuner
||btv
->channel
) /* Only tuner 0 */
2963 strcpy(v
.name
, "Radio");
2964 v
.rangelow
=(int)(76*16); /* jp: 76.0MHz - 89.9MHz */
2965 v
.rangehigh
=(int)(108*16); /* eu: 87.5MHz - 108.0MHz */
2966 v
.flags
= 0; /* XXX */
2967 v
.mode
= 0; /* XXX */
2968 if(copy_to_user(arg
,&v
,sizeof(v
)))
2974 struct video_tuner v
;
2975 if(copy_from_user(&v
, arg
, sizeof(v
)))
2977 /* Only channel 0 has a tuner */
2978 if(v
.tuner
!=0 || btv
->channel
)
2980 /* XXX anything to do ??? */
2987 bttv_ioctl((struct video_device
*)btv
,cmd
,arg
);
2990 return -ENOIOCTLCMD
;
2995 static struct video_device radio_template
=
3002 radio_read
, /* just returns -EINVAL */
3003 bttv_write
, /* just returns -EINVAL */
3007 bttv_init_done
, /* just returns 0 */
3014 #define TRITON_PCON 0x50
3015 #define TRITON_BUS_CONCURRENCY (1<<0)
3016 #define TRITON_STREAMING (1<<1)
3017 #define TRITON_WRITE_BURST (1<<2)
3018 #define TRITON_PEER_CONCURRENCY (1<<3)
3021 static void __init
handle_chipset(void)
3023 struct pci_dev
*dev
= NULL
;
3025 /* Just in case some nut set this to something dangerous */
3027 triton1
=BT848_INT_ETBF
;
3029 while ((dev
= pci_find_device(PCI_VENDOR_ID_SI
, PCI_DEVICE_ID_SI_496
, dev
)))
3031 /* Beware the SiS 85C496 my friend - rev 49 don't work with a bttv */
3032 printk(KERN_WARNING
"BT848 and SIS 85C496 chipset don't always work together.\n");
3035 while ((dev
= pci_find_device(PCI_VENDOR_ID_INTEL
,
3036 PCI_DEVICE_ID_INTEL_82441
, dev
)))
3039 pci_read_config_byte(dev
, 0x53, &b
);
3040 DEBUG(printk(KERN_INFO
"bttv: Host bridge: 82441FX Natoma, "));
3041 DEBUG(printk("bufcon=0x%02x\n",b
));
3044 while ((dev
= pci_find_device(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82437
, dev
)))
3046 printk(KERN_INFO
"bttv: Host bridge 82437FX Triton PIIX\n");
3047 triton1
=BT848_INT_ETBF
;
3052 /* can tda9855.c handle this too maybe? */
3053 static void __init
init_tda9840(struct bttv
*btv
)
3056 I2CWrite(btv
, I2C_TDA9840
, TDA9840_SW
, 0x2a, 1); /* sound mode switching */
3058 10 - mono / averaged stereo
3067 /* Figure out card and tuner type */
3069 static void __init
idcard(struct bttv
*btv
)
3071 int type
,eeprom
= 0;
3073 btwrite(0, BT848_GPIO_OUT_EN
);
3074 DEBUG(printk(KERN_DEBUG
"bttv%d: GPIO: 0x%08x\n", btv
->nr
, btread(BT848_GPIO_DATA
)));
3076 /* Default the card to the user-selected one. */
3077 if (card
[btv
->nr
] >= 0 && card
[btv
->nr
] < TVCARDS
)
3078 btv
->type
=card
[btv
->nr
];
3080 /* If we were asked to auto-detect, then do so! */
3081 if (btv
->type
== BTTV_UNKNOWN
) {
3083 /* many bt878 cards have a eeprom @ 0xa0 => read ID
3084 and try to identify it */
3085 if (I2CRead(btv
, I2C_HAUPEE
, "eeprom") >= 0) {
3087 readee(btv
,eeprom_data
,0xa0);
3088 dump_eeprom(btv
,0xa0); /* DEBUG */
3089 type
= idcard_eeprom(btv
);
3092 } else if (btv
->id
<= 849) {
3093 /* for unknown bt848, assume old Hauppauge */
3094 btv
->type
=BTTV_HAUPPAUGE
;
3097 /* STB cards have a eeprom @ 0xae (old bt848) */
3098 } else if (I2CRead(btv
, I2C_STBEE
, "eeprom")>=0) {
3103 /* check for msp34xx */
3104 if (I2CRead(btv
, 0x80, "msp3400")>=0)
3105 btv
->type
= BTTV_MIROPRO
;
3107 btv
->type
= BTTV_MIRO
;
3111 /* print which board we have found */
3112 sprintf(btv
->video_dev
.name
,"BT%d%s(%.22s)",
3114 (btv
->id
==848 && btv
->revision
==0x12) ? "A" : "",
3115 tvcards
[btv
->type
].name
);
3116 printk(KERN_INFO
"bttv%d: model: %s\n",btv
->nr
,btv
->video_dev
.name
);
3119 /* board specific initialisations */
3120 if (btv
->type
== BTTV_MIRO
|| btv
->type
== BTTV_MIROPRO
) {
3121 /* auto detect tuner for MIRO cards */
3122 btv
->tuner_type
=((btread(BT848_GPIO_DATA
)>>10)-1)&7;
3124 if (btv
->type
== BTTV_HAUPPAUGE
|| btv
->type
== BTTV_HAUPPAUGE878
) {
3125 /* pick up some config infos from the eeprom */
3126 if (0xa0 != eeprom
) {
3128 readee(btv
,eeprom_data
,0xa0);
3130 hauppauge_eeprom(btv
);
3131 hauppauge_boot_msp34xx(btv
);
3133 if (btv
->type
== BTTV_PXC200
)
3137 /* pll configuration */
3138 if (!(btv
->id
==848 && btv
->revision
==0x11)) {
3139 /* defaults from card list */
3140 if (PLL_28
== tvcards
[btv
->type
].pll
) {
3141 btv
->pll
.pll_ifreq
=28636363;
3142 btv
->pll
.pll_crystal
=BT848_IFORM_XT0
;
3144 /* insmod options can override */
3145 switch (pll
[btv
->nr
]) {
3147 btv
->pll
.pll_crystal
= 0;
3148 btv
->pll
.pll_ifreq
= 0;
3149 btv
->pll
.pll_ofreq
= 0;
3151 case 1: /* 28 MHz */
3152 btv
->pll
.pll_ifreq
= 28636363;
3153 btv
->pll
.pll_ofreq
= 0;
3154 btv
->pll
.pll_crystal
=BT848_IFORM_XT0
;
3156 case 2: /* 35 MHz */
3157 btv
->pll
.pll_ifreq
= 35468950;
3158 btv
->pll
.pll_ofreq
= 0;
3159 btv
->pll
.pll_crystal
=BT848_IFORM_XT1
;
3165 /* tuner configuration */
3166 if (-1 != tvcards
[btv
->type
].tuner_type
)
3167 btv
->tuner_type
= tvcards
[btv
->type
].tuner_type
;
3168 if (btv
->tuner_type
!= -1)
3169 call_i2c_clients(btv
,TUNER_SET_TYPE
,&btv
->tuner_type
);
3171 /* try to detect audio/fader chips */
3172 if (tvcards
[btv
->type
].msp34xx
&&
3173 I2CRead(btv
, I2C_MSP3400
, "MSP34xx") >=0) {
3175 request_module("msp3400");
3178 if (tvcards
[btv
->type
].tda8425
&&
3179 I2CRead(btv
, I2C_TDA8425
, "TDA8425") >=0) {
3181 request_module("tda8425");
3184 if (tvcards
[btv
->type
].tda9840
&&
3185 I2CRead(btv
, I2C_TDA9840
, "TDA9840") >=0) {
3187 btv
->audio_chip
= TDA9840
;
3188 /* move this to a module too? */
3192 if (tvcards
[btv
->type
].tda985x
&&
3193 I2CRead(btv
, I2C_TDA9850
, "TDA985x") >=0) {
3195 request_module("tda985x");
3198 if (tvcards
[btv
->type
].tda9875
&&
3199 I2CRead(btv
, I2C_TDA9875
, "TDA9875") >=0) {
3201 request_module("tda9875");
3204 if (tvcards
[btv
->type
].tda7432
&&
3205 I2CRead(btv
, I2C_TDA7432
, "TDA7432") >=0) {
3207 request_module("tda7432");
3210 if (tvcards
[btv
->type
].tea63xx
) {
3212 request_module("tea6300");
3215 if (tvcards
[btv
->type
].tea64xx
) {
3217 request_module("tea6420");
3220 if (tvcards
[btv
->type
].tuner
!= -1) {
3222 request_module("tuner");
3225 audio(btv
, AUDIO_MUTE
, 1);
3229 static void bt848_set_risc_jmps(struct bttv
*btv
, int flags
)
3231 unsigned long irq_flags
;
3233 spin_lock_irqsave(&btv
->s_lock
, irq_flags
);
3244 if (debug
) printk("bttv%d: set_risc_jmp %08lx:",
3245 btv
->nr
,virt_to_bus(btv
->risc_jmp
));
3247 /* Sync to start of odd field */
3248 btv
->risc_jmp
[0]=cpu_to_le32(BT848_RISC_SYNC
|BT848_RISC_RESYNC
3249 |BT848_FIFO_STATUS_VRE
);
3250 btv
->risc_jmp
[1]=cpu_to_le32(0);
3252 /* Jump to odd vbi sub */
3253 btv
->risc_jmp
[2]=cpu_to_le32(BT848_RISC_JUMP
|(0xd<<20));
3255 if (debug
) printk(" ev=%08lx",virt_to_bus(btv
->vbi_odd
));
3256 btv
->risc_jmp
[3]=cpu_to_le32(virt_to_bus(btv
->vbi_odd
));
3258 if (debug
) printk(" -----------");
3259 btv
->risc_jmp
[3]=cpu_to_le32(virt_to_bus(btv
->risc_jmp
+4));
3262 /* Jump to odd sub */
3263 btv
->risc_jmp
[4]=cpu_to_le32(BT848_RISC_JUMP
|(0xe<<20));
3264 if (0 != btv
->risc_cap_odd
) {
3265 if (debug
) printk(" e%d=%08x",btv
->gq_grab
,btv
->risc_cap_odd
);
3267 btv
->risc_jmp
[5]=cpu_to_le32(btv
->risc_cap_odd
);
3268 } else if (flags
&2) {
3269 if (debug
) printk(" eo=%08lx",virt_to_bus(btv
->risc_scr_odd
));
3270 btv
->risc_jmp
[5]=cpu_to_le32(virt_to_bus(btv
->risc_scr_odd
));
3272 if (debug
) printk(" -----------");
3273 btv
->risc_jmp
[5]=cpu_to_le32(virt_to_bus(btv
->risc_jmp
+6));
3277 /* Sync to start of even field */
3278 btv
->risc_jmp
[6]=cpu_to_le32(BT848_RISC_SYNC
|BT848_RISC_RESYNC
3279 |BT848_FIFO_STATUS_VRO
);
3280 btv
->risc_jmp
[7]=cpu_to_le32(0);
3282 /* Jump to even vbi sub */
3283 btv
->risc_jmp
[8]=cpu_to_le32(BT848_RISC_JUMP
);
3285 if (debug
) printk(" ov=%08lx",virt_to_bus(btv
->vbi_even
));
3286 btv
->risc_jmp
[9]=cpu_to_le32(virt_to_bus(btv
->vbi_even
));
3288 if (debug
) printk(" -----------");
3289 btv
->risc_jmp
[9]=cpu_to_le32(virt_to_bus(btv
->risc_jmp
+10));
3292 /* Jump to even sub */
3293 btv
->risc_jmp
[10]=cpu_to_le32(BT848_RISC_JUMP
|(8<<20));
3294 if (0 != btv
->risc_cap_even
) {
3295 if (debug
) printk(" o%d=%08x",btv
->gq_grab
,btv
->risc_cap_even
);
3297 btv
->risc_jmp
[11]=cpu_to_le32(btv
->risc_cap_even
);
3298 } else if (flags
&1) {
3299 if (debug
) printk(" oo=%08lx",virt_to_bus(btv
->risc_scr_even
));
3300 btv
->risc_jmp
[11]=cpu_to_le32(virt_to_bus(btv
->risc_scr_even
));
3302 if (debug
) printk(" -----------");
3303 btv
->risc_jmp
[11]=cpu_to_le32(virt_to_bus(btv
->risc_jmp
+12));
3306 if (btv
->gq_start
) {
3307 btv
->risc_jmp
[12]=cpu_to_le32(BT848_RISC_JUMP
|(0x8<<16)|BT848_RISC_IRQ
);
3309 btv
->risc_jmp
[12]=cpu_to_le32(BT848_RISC_JUMP
);
3311 btv
->risc_jmp
[13]=cpu_to_le32(virt_to_bus(btv
->risc_jmp
));
3313 /* enable cpaturing and DMA */
3314 if (debug
) printk(" flags=0x%x dma=%s\n",
3315 flags
,(flags
&0x0f) ? "on" : "off");
3316 btaor(flags
, ~0x0f, BT848_CAP_CTL
);
3322 spin_unlock_irqrestore(&btv
->s_lock
, irq_flags
);
3325 static int __init
init_video_dev(struct bttv
*btv
)
3327 memcpy(&btv
->video_dev
,&bttv_template
, sizeof(bttv_template
));
3328 memcpy(&btv
->vbi_dev
,&vbi_template
, sizeof(vbi_template
));
3329 memcpy(&btv
->radio_dev
,&radio_template
,sizeof(radio_template
));
3333 if(video_register_device(&btv
->video_dev
,VFL_TYPE_GRABBER
)<0)
3335 if(video_register_device(&btv
->vbi_dev
,VFL_TYPE_VBI
)<0)
3337 video_unregister_device(&btv
->video_dev
);
3342 if(video_register_device(&btv
->radio_dev
, VFL_TYPE_RADIO
)<0)
3344 video_unregister_device(&btv
->vbi_dev
);
3345 video_unregister_device(&btv
->video_dev
);
3352 static int __init
init_bt848(struct bttv
*btv
)
3357 init_MUTEX(&btv
->lock
);
3359 /* dump current state of the gpio registers before changing them,
3360 * might help to make a new card work */
3362 printk("bttv%d: gpio: out_enable=0x%x, data=0x%x, in=0x%x\n",
3364 btread(BT848_GPIO_OUT_EN
),
3365 btread(BT848_GPIO_DATA
),
3366 btread(BT848_GPIO_REG_INP
));
3368 /* reset the bt848 */
3369 btwrite(0, BT848_SRESET
);
3370 DEBUG(printk(KERN_DEBUG
"bttv%d: bt848_mem: 0x%lx\n", btv
->nr
, (unsigned long) btv
->bt848_mem
));
3372 /* not registered yet */
3373 btv
->video_dev
.minor
= -1;
3374 btv
->radio_dev
.minor
= -1;
3375 btv
->vbi_dev
.minor
= -1;
3377 /* default setup for max. PAL size in a 1024xXXX hicolor framebuffer */
3378 btv
->win
.norm
=0; /* change this to 1 for NTSC, 2 for SECAM */
3379 btv
->win
.interlace
=1;
3382 btv
->win
.width
=768; /* 640 */
3383 btv
->win
.height
=576; /* 480 */
3386 btv
->win
.color_fmt
=BT848_COLOR_FMT_RGB16
;
3387 btv
->win
.bpl
=1024*btv
->win
.bpp
;
3388 btv
->win
.swidth
=1024;
3389 btv
->win
.sheight
=768;
3394 btv
->risc_scr_odd
=0;
3395 btv
->risc_scr_even
=0;
3396 btv
->risc_cap_odd
=0;
3397 btv
->risc_cap_even
=0;
3400 btv
->field
=btv
->last_field
=0;
3403 btv
->needs_restart
=0;
3409 if (!(btv
->risc_scr_odd
=(unsigned int *) kmalloc(RISCMEM_LEN
/2, GFP_KERNEL
)))
3411 if (!(btv
->risc_scr_even
=(unsigned int *) kmalloc(RISCMEM_LEN
/2, GFP_KERNEL
)))
3413 if (!(btv
->risc_jmp
=(unsigned int *) kmalloc(2048, GFP_KERNEL
)))
3415 DEBUG(printk(KERN_DEBUG
"risc_jmp: %p\n",btv
->risc_jmp
));
3416 btv
->vbi_odd
=btv
->risc_jmp
+16;
3417 btv
->vbi_even
=btv
->vbi_odd
+256;
3418 btv
->bus_vbi_odd
=virt_to_bus(btv
->risc_jmp
+12);
3419 btv
->bus_vbi_even
=virt_to_bus(btv
->risc_jmp
+6);
3421 btwrite(virt_to_bus(btv
->risc_jmp
+2), BT848_RISC_STRT_ADD
);
3422 btv
->vbibuf
=(unsigned char *) vmalloc(VBIBUF_SIZE
);
3425 if (!(btv
->gbuf
= kmalloc(sizeof(struct bttv_gbuf
)*gbuffers
,GFP_KERNEL
)))
3427 for (j
= 0; j
< gbuffers
; j
++) {
3428 if (!(btv
->gbuf
[j
].risc
= kmalloc(16384,GFP_KERNEL
)))
3432 memset(btv
->vbibuf
, 0, VBIBUF_SIZE
); /* We don't want to return random
3433 memory to the user */
3437 bt848_muxsel(btv
, 1);
3438 bt848_set_winsize(btv
);
3440 /* btwrite(0, BT848_TDEC); */
3441 btwrite(0x10, BT848_COLOR_CTL
);
3442 btwrite(0x00, BT848_CAP_CTL
);
3443 /* set planar and packed mode trigger points and */
3444 /* set rising edge of inverted GPINTR pin as irq trigger */
3445 btwrite(BT848_GPIO_DMA_CTL_PKTP_32
|
3446 BT848_GPIO_DMA_CTL_PLTP1_16
|
3447 BT848_GPIO_DMA_CTL_PLTP23_16
|
3448 BT848_GPIO_DMA_CTL_GPINTC
|
3449 BT848_GPIO_DMA_CTL_GPINTI
,
3450 BT848_GPIO_DMA_CTL
);
3452 /* select direct input */
3453 btwrite(0x00, BT848_GPIO_REG_INP
);
3455 btwrite(BT848_IFORM_MUX1
| BT848_IFORM_XTAUTO
| BT848_IFORM_AUTO
,
3458 btwrite(0xd8, BT848_CONTRAST_LO
);
3459 bt848_bright(btv
, 0x10);
3461 btwrite(0x20, BT848_E_VSCALE_HI
);
3462 btwrite(0x20, BT848_O_VSCALE_HI
);
3463 btwrite(/*BT848_ADC_SYNC_T|*/
3464 BT848_ADC_RESERVED
|BT848_ADC_CRUSH
, BT848_ADC
);
3466 btwrite(BT848_CONTROL_LDEC
, BT848_E_CONTROL
);
3467 btwrite(BT848_CONTROL_LDEC
, BT848_O_CONTROL
);
3469 btv
->picture
.colour
=254<<7;
3470 btv
->picture
.brightness
=128<<8;
3471 btv
->picture
.hue
=128<<8;
3472 btv
->picture
.contrast
=0xd8<<7;
3474 btwrite(0x00, BT848_E_SCLOOP
);
3475 btwrite(0x00, BT848_O_SCLOOP
);
3477 /* clear interrupt status */
3478 btwrite(~0x0UL
, BT848_INT_STAT
);
3480 /* set interrupt mask */
3481 btwrite(btv
->triton1
|
3482 /*BT848_INT_PABORT|BT848_INT_RIPERR|BT848_INT_PPERR|
3483 BT848_INT_FDSR|BT848_INT_FTRGT|BT848_INT_FBUS|*/
3484 (fieldnr
? BT848_INT_VSYNC
: 0)|
3487 BT848_INT_RISCI
|BT848_INT_OCERR
|BT848_INT_VPRES
|
3488 BT848_INT_FMTCHG
|BT848_INT_HLOCK
,
3492 bt848_set_risc_jmps(btv
,-1);
3495 * Now add the template and register the device unit.
3497 init_video_dev(btv
);
3502 static void bttv_irq(int irq
, void *dev_id
, struct pt_regs
* regs
)
3509 btv
=(struct bttv
*)dev_id
;
3513 /* get/clear interrupt status bits */
3514 stat
=btread(BT848_INT_STAT
);
3515 astat
=stat
&btread(BT848_INT_MASK
);
3518 IDEBUG(printk ("bttv%d: astat=%08x\n", btv
->nr
, astat
));
3519 IDEBUG(printk ("bttv%d: stat=%08x\n", btv
->nr
, stat
));
3521 /* get device status bits */
3522 dstat
=btread(BT848_DSTATUS
);
3524 if (astat
&BT848_INT_GPINT
) {
3525 IDEBUG(printk ("bttv%d: IRQ_GPINT\n", btv
->nr
));
3526 wake_up_interruptible(&btv
->gpioq
);
3529 if (astat
&BT848_INT_FMTCHG
)
3531 IDEBUG(printk ("bttv%d: IRQ_FMTCHG\n", btv
->nr
));
3533 (dstat&BT848_DSTATUS_NUML) ? (~1) : (~0); */
3535 if (astat
&BT848_INT_VPRES
)
3537 IDEBUG(printk ("bttv%d: IRQ_VPRES\n", btv
->nr
));
3539 if (astat
&BT848_INT_VSYNC
)
3541 IDEBUG(printk ("bttv%d: IRQ_VSYNC\n", btv
->nr
));
3544 if (astat
&(BT848_INT_SCERR
|BT848_INT_OCERR
)) {
3546 printk("bttv%d: irq:%s%s risc_count=%08x\n",
3548 (astat
&BT848_INT_SCERR
) ? " SCERR" : "",
3549 (astat
&BT848_INT_OCERR
) ? " OCERR" : "",
3550 btread(BT848_RISC_COUNT
));
3552 if (btv
->errors
< BTTV_ERRORS
) {
3553 btand(~15, BT848_GPIO_DMA_CTL
);
3554 btwrite(virt_to_bus(btv
->risc_jmp
+2),
3555 BT848_RISC_STRT_ADD
);
3556 bt848_set_geo(btv
,0);
3557 bt848_set_risc_jmps(btv
,-1);
3560 printk("bttv%d: aiee: error loops\n",btv
->nr
);
3561 /* cancel all outstanding grab requests */
3565 for (i
= 0; i
< gbuffers
; i
++)
3566 if (btv
->gbuf
[i
].stat
== GBUFFER_GRABBING
)
3567 btv
->gbuf
[i
].stat
= GBUFFER_ERROR
;
3569 btv
->risc_cap_odd
= 0;
3570 btv
->risc_cap_even
= 0;
3571 bt848_set_risc_jmps(btv
,0);
3573 btv
->needs_restart
= 1;
3574 wake_up_interruptible(&btv
->vbiq
);
3575 wake_up_interruptible(&btv
->capq
);
3578 if (astat
&BT848_INT_RISCI
)
3581 printk("bttv%d: IRQ_RISCI\n",btv
->nr
);
3583 /* captured VBI frame */
3587 /* inc vbi frame count for detecting drops */
3588 (*(u32
*)&(btv
->vbibuf
[VBIBUF_SIZE
- 4]))++;
3589 wake_up_interruptible(&btv
->vbiq
);
3592 /* captured full frame */
3593 if (stat
&(2<<28) && btv
->gq_grab
!= -1)
3595 btv
->last_field
=btv
->field
;
3597 printk("bttv%d: cap irq: done %d\n",btv
->nr
,btv
->gq_grab
);
3598 do_gettimeofday(&btv
->gbuf
[btv
->gq_grab
].tv
);
3599 btv
->gbuf
[btv
->gq_grab
].stat
= GBUFFER_DONE
;
3601 if (btv
->gq_in
!= btv
->gq_out
)
3603 btv
->gq_grab
= btv
->gqueue
[btv
->gq_out
++];
3604 btv
->gq_out
= btv
->gq_out
% MAX_GBUFFERS
;
3606 printk("bttv%d: cap irq: capture %d\n",btv
->nr
,btv
->gq_grab
);
3607 btv
->risc_cap_odd
= btv
->gbuf
[btv
->gq_grab
].ro
;
3608 btv
->risc_cap_even
= btv
->gbuf
[btv
->gq_grab
].re
;
3609 bt848_set_risc_jmps(btv
,-1);
3610 bt848_set_geo(btv
,0);
3611 btwrite(BT848_COLOR_CTL_GAMMA
,
3614 btv
->risc_cap_odd
= 0;
3615 btv
->risc_cap_even
= 0;
3616 bt848_set_risc_jmps(btv
,-1);
3617 bt848_set_geo(btv
,0);
3618 btwrite(btv
->fb_color_ctl
| BT848_COLOR_CTL_GAMMA
,
3621 wake_up_interruptible(&btv
->capq
);
3627 btv
->gq_grab
= btv
->gqueue
[btv
->gq_out
++];
3628 btv
->gq_out
= btv
->gq_out
% MAX_GBUFFERS
;
3630 printk("bttv%d: cap irq: capture %d\n",btv
->nr
,btv
->gq_grab
);
3631 btv
->risc_cap_odd
= btv
->gbuf
[btv
->gq_grab
].ro
;
3632 btv
->risc_cap_even
= btv
->gbuf
[btv
->gq_grab
].re
;
3633 bt848_set_risc_jmps(btv
,-1);
3634 bt848_set_geo(btv
,0);
3635 btwrite(BT848_COLOR_CTL_GAMMA
,
3639 if (astat
&BT848_INT_OCERR
)
3641 IDEBUG(printk ("bttv%d: IRQ_OCERR\n", btv
->nr
));
3643 if (astat
&BT848_INT_PABORT
)
3645 IDEBUG(printk ("bttv%d: IRQ_PABORT\n", btv
->nr
));
3647 if (astat
&BT848_INT_RIPERR
)
3649 IDEBUG(printk ("bttv%d: IRQ_RIPERR\n", btv
->nr
));
3651 if (astat
&BT848_INT_PPERR
)
3653 IDEBUG(printk ("bttv%d: IRQ_PPERR\n", btv
->nr
));
3655 if (astat
&BT848_INT_FDSR
)
3657 IDEBUG(printk ("bttv%d: IRQ_FDSR\n", btv
->nr
));
3659 if (astat
&BT848_INT_FTRGT
)
3661 IDEBUG(printk ("bttv%d: IRQ_FTRGT\n", btv
->nr
));
3663 if (astat
&BT848_INT_FBUS
)
3665 IDEBUG(printk ("bttv%d: IRQ_FBUS\n", btv
->nr
));
3667 if (astat
&BT848_INT_HLOCK
)
3669 if ((dstat
&BT848_DSTATUS_HLOC
) || (btv
->radio
))
3670 audio(btv
, AUDIO_ON
,0);
3672 audio(btv
, AUDIO_OFF
,0);
3675 if (astat
&BT848_INT_I2CDONE
)
3677 IDEBUG(printk ("bttv%d: IRQ_I2CDONE\n", btv
->nr
));
3680 btwrite(astat
,BT848_INT_STAT
);
3684 printk (KERN_WARNING
"bttv%d: irq loop %d\n",
3688 btwrite(0, BT848_INT_MASK
);
3690 "bttv%d: IRQ lockup, cleared int mask\n", btv
->nr
);
3698 * Scan for a Bt848 card, request the irq and map the io memory
3701 static void __init
bttv_remove(struct pci_dev
*pci_dev
)
3705 struct bttv
*btv
= pci_dev
->driver_data
;
3707 /* unregister i2c_bus */
3708 i2c_bit_del_bus(&btv
->i2c_adap
);
3710 /* turn off all capturing, DMA and IRQs */
3711 btand(~15, BT848_GPIO_DMA_CTL
);
3713 /* first disable interrupts before unmapping the memory! */
3714 btwrite(0, BT848_INT_MASK
);
3715 btwrite(~0x0UL
,BT848_INT_STAT
);
3716 btwrite(0x0, BT848_GPIO_OUT_EN
);
3718 /* disable PCI bus-mastering */
3719 pci_read_config_byte(btv
->dev
, PCI_COMMAND
, &command
);
3720 /* Should this be &=~ ?? */
3721 command
&=~PCI_COMMAND_MASTER
;
3722 pci_write_config_byte(btv
->dev
, PCI_COMMAND
, command
);
3724 /* unmap and free memory */
3725 for (j
= 0; j
< gbuffers
; j
++)
3726 if (btv
->gbuf
[j
].risc
)
3727 kfree(btv
->gbuf
[j
].risc
);
3729 kfree((void *) btv
->gbuf
);
3731 if (btv
->risc_scr_odd
)
3732 kfree((void *) btv
->risc_scr_odd
);
3734 if (btv
->risc_scr_even
)
3735 kfree((void *) btv
->risc_scr_even
);
3737 DEBUG(printk(KERN_DEBUG
"free: risc_jmp: 0x%p.\n", btv
->risc_jmp
));
3739 kfree((void *) btv
->risc_jmp
);
3741 DEBUG(printk(KERN_DEBUG
"bt848_vbibuf: 0x%p.\n", btv
->vbibuf
));
3743 vfree((void *) btv
->vbibuf
);
3745 free_irq(btv
->irq
,btv
);
3746 DEBUG(printk(KERN_DEBUG
"bt848_mem: 0x%p.\n", btv
->bt848_mem
));
3748 iounmap(btv
->bt848_mem
);
3750 if(btv
->video_dev
.minor
!=-1)
3751 video_unregister_device(&btv
->video_dev
);
3752 if(btv
->vbi_dev
.minor
!=-1)
3753 video_unregister_device(&btv
->vbi_dev
);
3754 if (radio
[btv
->nr
] && btv
->radio_dev
.minor
!= -1)
3755 video_unregister_device(&btv
->radio_dev
);
3757 release_mem_region(btv
->bt848_adr
,
3758 pci_resource_len(btv
->dev
,0));
3759 /* wake up any waiting processes
3760 because shutdown flag is set, no new processes (in this queue)
3764 wake_up(&btv
->gpioq
);
3770 static int __init
bttv_probe(struct pci_dev
*dev
, const struct pci_device_id
*pci_id
)
3773 unsigned char command
;
3775 #if defined(__powerpc__)
3779 printk(KERN_INFO
"bttv: Bt8xx card found (%d).\n", bttv_num
);
3781 btv
=&bttvs
[bttv_num
];
3784 btv
->bt848_mem
=NULL
;
3789 init_waitqueue_head(&btv
->vbiq
);
3790 init_waitqueue_head(&btv
->capq
);
3791 init_waitqueue_head(&btv
->capqo
);
3792 init_waitqueue_head(&btv
->capqe
);
3793 btv
->vbip
=VBIBUF_SIZE
;
3795 init_waitqueue_head(&btv
->gpioq
);
3796 btv
->s_lock
= SPIN_LOCK_UNLOCKED
;
3799 btv
->id
=dev
->device
;
3801 btv
->bt848_adr
=pci_resource_start(dev
, 0);
3802 if (pci_enable_device(dev
))
3804 if (!request_mem_region(btv
->bt848_adr
,
3805 pci_resource_len(dev
,0),
3810 btv
->i2c_command
= 0x83;
3812 btv
->i2c_command
=(I2C_TIMING
| BT848_I2C_SCL
| BT848_I2C_SDA
);
3814 pci_read_config_byte(dev
, PCI_CLASS_REVISION
, &btv
->revision
);
3815 printk(KERN_INFO
"bttv%d: Brooktree Bt%d (rev %d) ",
3816 bttv_num
,btv
->id
, btv
->revision
);
3817 printk("bus: %d, devfn: %d, ",dev
->bus
->number
, dev
->devfn
);
3818 printk("irq: %d, ",btv
->irq
);
3819 printk("memory: 0x%lx.\n", btv
->bt848_adr
);
3821 #if defined(__powerpc__)
3822 /* on OpenFirmware machines (PowerMac at least), PCI memory cycle */
3823 /* response on cards with no firmware is not enabled by OF */
3824 pci_read_config_dword(dev
, PCI_COMMAND
, &cmd
);
3825 cmd
= (cmd
| PCI_COMMAND_MEMORY
);
3826 pci_write_config_dword(dev
, PCI_COMMAND
, cmd
);
3830 btv
->bt848_mem
=(unsigned char *)btv
->bt848_adr
;
3832 btv
->bt848_mem
=ioremap(btv
->bt848_adr
, 0x1000);
3835 /* clear interrupt mask */
3836 btwrite(0, BT848_INT_MASK
);
3838 result
= request_irq(btv
->irq
, bttv_irq
,
3839 SA_SHIRQ
| SA_INTERRUPT
,"bttv",(void *)btv
);
3840 if (result
==-EINVAL
)
3842 printk(KERN_ERR
"bttv%d: Bad irq number or handler\n",
3848 printk(KERN_ERR
"bttv%d: IRQ %d busy, change your PnP config in BIOS\n",bttv_num
,btv
->irq
);
3854 pci_set_master(dev
);
3856 btv
->triton1
=triton1
? BT848_INT_ETBF
: 0;
3857 if (triton1
&& btv
->id
>= 878)
3860 printk("bttv: Enabling 430FX compatibilty for bt878\n");
3861 pci_read_config_byte(dev
, BT878_DEVCTRL
, &command
);
3862 command
|=BT878_EN_TBFX
;
3863 pci_write_config_byte(dev
, BT878_DEVCTRL
, command
);
3864 pci_read_config_byte(dev
, BT878_DEVCTRL
, &command
);
3865 if (!(command
&BT878_EN_TBFX
))
3867 printk("bttv: 430FX compatibility could not be enabled\n");
3868 free_irq(btv
->irq
,btv
);
3874 dev
->driver_data
= btv
;
3876 if(init_bt848(btv
) < 0) {
3886 release_mem_region(btv
->bt848_adr
,
3887 pci_resource_len(btv
->dev
,0));
3891 static struct pci_device_id bttv_pci_tbl
[] __initdata
= {
3892 {PCI_VENDOR_ID_BROOKTREE
, PCI_DEVICE_ID_BT848
,
3893 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
3894 {PCI_VENDOR_ID_BROOKTREE
, PCI_DEVICE_ID_BT849
,
3895 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
3896 {PCI_VENDOR_ID_BROOKTREE
, PCI_DEVICE_ID_BT878
,
3897 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
3898 {PCI_VENDOR_ID_BROOKTREE
, PCI_DEVICE_ID_BT879
,
3899 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
3903 MODULE_DEVICE_TABLE(pci
, bttv_pci_tbl
);
3905 static struct pci_driver bttv_pci_driver
= {
3907 id_table
:bttv_pci_tbl
,
3912 static int __init
bttv_init_module(void)
3916 printk(KERN_INFO
"bttv: driver version %d.%d.%d loaded\n",
3917 (BTTV_VERSION_CODE
>> 16) & 0xff,
3918 (BTTV_VERSION_CODE
>> 8) & 0xff,
3919 BTTV_VERSION_CODE
& 0xff);
3920 if (gbuffers
< 2 || gbuffers
> MAX_GBUFFERS
)
3922 if (gbufsize
< 0 || gbufsize
> BTTV_MAX_FBUF
)
3923 gbufsize
= BTTV_MAX_FBUF
;
3925 printk(KERN_INFO
"bttv: using %d buffers with %dk (%dk total) for capture\n",
3926 gbuffers
,gbufsize
/1024,gbuffers
*gbufsize
/1024);
3930 return pci_module_init(&bttv_pci_driver
);
3933 static void __exit
bttv_cleanup_module(void)
3935 pci_unregister_driver(&bttv_pci_driver
);
3939 module_init(bttv_init_module
);
3940 module_exit(bttv_cleanup_module
);