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)
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/module.h>
23 #include <linux/version.h>
24 #include <linux/delay.h>
25 #include <linux/errno.h>
27 #include <linux/kernel.h>
28 #include <linux/major.h>
29 #include <linux/malloc.h>
31 #if LINUX_VERSION_CODE >= 0x020100
32 #include <linux/poll.h>
34 #include <linux/pci.h>
35 #include <linux/signal.h>
37 #include <linux/ioport.h>
38 #include <asm/pgtable.h>
40 #include <linux/sched.h>
41 #include <asm/segment.h>
42 #include <linux/types.h>
43 #include <linux/wrapper.h>
44 #include <linux/interrupt.h>
45 #include <linux/version.h>
47 #if LINUX_VERSION_CODE >= 0x020100
48 #include <asm/uaccess.h>
49 #include <linux/vmalloc.h>
51 #include <linux/bios32.h>
52 #define mdelay(x) udelay((x)*1000)
53 #define signal_pending(current) (current->signal & ~current->blocked)
54 #define sigfillset(set)
56 static inline int time_before(unsigned long a
, unsigned long b
)
58 return((long)((a
) - (b
)) < 0L);
61 static inline unsigned long
62 copy_to_user(void *to
, const void *from
, unsigned long n
)
64 memcpy_tofs(to
,from
,n
);
68 static inline unsigned long
69 copy_from_user(void *to
, const void *from
, unsigned long n
)
71 memcpy_fromfs(to
,from
,n
);
74 #define ioremap vremap
78 #include <linux/videodev.h>
79 #include <linux/i2c.h>
83 #define DEBUG(x) /* Debug driver */
84 #define IDEBUG(x) /* Debug interrupt handler */
86 #if LINUX_VERSION_CODE >= 0x020117
87 MODULE_PARM(vidmem
,"i");
88 MODULE_PARM(triton1
,"i");
89 MODULE_PARM(remap
,"1-4i");
90 MODULE_PARM(radio
,"1-4i");
91 MODULE_PARM(card
,"1-4i");
92 MODULE_PARM(pll
,"1-4i");
95 /* Anybody who uses more than four? */
98 static int find_vga(void);
99 static void bt848_set_risc_jmps(struct bttv
*btv
);
101 static unsigned int vidmem
=0; /* manually set video mem address */
102 static int triton1
=0;
104 /* 0=no pll, 1=28MHz, 2=34MHz */
108 /* card type (see bttv.h) 0=autodetect */
109 #define CARD_DEFAULT 0
112 static unsigned int remap
[BTTV_MAX
]; /* remap Bt848 */
113 static unsigned int radio
[BTTV_MAX
];
114 static unsigned int card
[BTTV_MAX
] = { CARD_DEFAULT
, CARD_DEFAULT
,
115 CARD_DEFAULT
, CARD_DEFAULT
};
116 static unsigned int pll
[BTTV_MAX
] = { USE_PLL
, USE_PLL
, USE_PLL
, USE_PLL
};
118 static int bttv_num
; /* number of Bt848s in use */
119 static struct bttv bttvs
[BTTV_MAX
];
121 #define I2C_TIMING (0x7<<4)
124 #define I2C_SET(CTRL,DATA) \
125 { btwrite((CTRL<<1)|(DATA), BT848_I2C); udelay(I2C_DELAY); }
126 #define I2C_GET() (btread(BT848_I2C)&1)
128 #define EEPROM_WRITE_DELAY 20000
129 #define BURSTOFFSET 76
133 /*******************************/
134 /* Memory management functions */
135 /*******************************/
137 /* convert virtual user memory address to physical address */
138 /* (virt_to_phys only works for kmalloced kernel memory) */
140 static inline unsigned long uvirt_to_phys(unsigned long adr
)
146 pgd
= pgd_offset(current
->mm
, adr
);
149 pmd
= pmd_offset(pgd
, adr
);
152 ptep
= pte_offset(pmd
, adr
/*&(~PGDIR_MASK)*/);
156 virt_to_phys((void *)(pte_page(pte
)|(adr
&(PAGE_SIZE
-1))));
160 static inline unsigned long uvirt_to_bus(unsigned long adr
)
162 return virt_to_bus(phys_to_virt(uvirt_to_phys(adr
)));
165 /* convert virtual kernel memory address to physical address */
166 /* (virt_to_phys only works for kmalloced kernel memory) */
168 static inline unsigned long kvirt_to_phys(unsigned long adr
)
170 return uvirt_to_phys(VMALLOC_VMADDR(adr
));
173 static inline unsigned long kvirt_to_bus(unsigned long adr
)
175 return uvirt_to_bus(VMALLOC_VMADDR(adr
));
178 static void * rvmalloc(unsigned long size
)
181 unsigned long adr
, page
;
186 memset(mem
, 0, size
); /* Clear the ram out, no junk to the user */
187 adr
=(unsigned long) mem
;
190 page
= kvirt_to_phys(adr
);
191 mem_map_reserve(MAP_NR(phys_to_virt(page
)));
199 static void rvfree(void * mem
, unsigned long size
)
201 unsigned long adr
, page
;
205 adr
=(unsigned long) mem
;
208 page
= kvirt_to_phys(adr
);
209 mem_map_unreserve(MAP_NR(phys_to_virt(page
)));
220 * Create the giant waste of buffer space we need for now
221 * until we get DMA to user space sorted out (probably 2.3.x)
223 * We only create this as and when someone uses mmap
226 static int fbuffer_alloc(struct bttv
*btv
)
229 btv
->fbuffer
=(unsigned char *) rvmalloc(2*BTTV_MAX_FBUF
);
231 printk(KERN_ERR
"bttv%d: Double alloc of fbuffer!\n",
239 /* ----------------------------------------------------------------------- */
242 /* software I2C functions */
244 static void i2c_setlines(struct i2c_bus
*bus
,int ctrl
,int data
)
246 struct bttv
*btv
= (struct bttv
*)bus
->data
;
247 btwrite((ctrl
<<1)|data
, BT848_I2C
);
248 btread(BT848_I2C
); /* flush buffers */
252 static int i2c_getdataline(struct i2c_bus
*bus
)
254 struct bttv
*btv
= (struct bttv
*)bus
->data
;
255 return btread(BT848_I2C
)&1;
258 /* hardware I2C functions */
261 static int I2CRead(struct i2c_bus
*bus
, unsigned char addr
)
265 struct bttv
*btv
= (struct bttv
*)bus
->data
;
267 /* clear status bit ; BT848_INT_RACK is ro */
268 btwrite(BT848_INT_I2CDONE
, BT848_INT_STAT
);
270 btwrite(((addr
& 0xff) << 24) | btv
->i2c_command
, BT848_I2C
);
273 * Timeout for I2CRead is 1 second (this should be enough, really!)
277 stat
=btread(BT848_INT_STAT
);
278 if (stat
& BT848_INT_I2CDONE
)
285 printk(KERN_DEBUG
"bttv%d: I2CRead timeout\n",
289 if (!(stat
& BT848_INT_RACK
))
292 i
=(btread(BT848_I2C
)>>8)&0xff;
296 /* set both to write both bytes, reset it to write only b1 */
298 static int I2CWrite(struct i2c_bus
*bus
, unsigned char addr
, unsigned char b1
,
299 unsigned char b2
, int both
)
304 struct bttv
*btv
= (struct bttv
*)bus
->data
;
306 /* clear status bit; BT848_INT_RACK is ro */
307 btwrite(BT848_INT_I2CDONE
, BT848_INT_STAT
);
309 data
=((addr
& 0xff) << 24) | ((b1
& 0xff) << 16) | btv
->i2c_command
;
312 data
|=((b2
& 0xff) << 8);
316 btwrite(data
, BT848_I2C
);
318 for (i
=0x1000; i
; i
--)
320 stat
=btread(BT848_INT_STAT
);
321 if (stat
& BT848_INT_I2CDONE
)
328 printk(KERN_DEBUG
"bttv%d: I2CWrite timeout\n",
332 if (!(stat
& BT848_INT_RACK
))
339 static void readee(struct i2c_bus
*bus
, unsigned char *eedata
)
343 if (I2CWrite(bus
, 0xa0, 0, -1, 0)<0)
345 printk(KERN_WARNING
"bttv: readee error\n");
349 for (i
=0; i
<256; i
++)
351 k
=I2CRead(bus
, 0xa1);
354 printk(KERN_WARNING
"bttv: readee error\n");
362 static void writeee(struct i2c_bus
*bus
, unsigned char *eedata
)
366 for (i
=0; i
<256; i
++)
368 if (I2CWrite(bus
, 0xa0, i
, eedata
[i
], 1)<0)
370 printk(KERN_WARNING
"bttv: writeee error (%d)\n", i
);
373 udelay(EEPROM_WRITE_DELAY
);
377 void attach_inform(struct i2c_bus
*bus
, int id
)
379 struct bttv
*btv
= (struct bttv
*)bus
->data
;
383 case I2C_DRIVERID_MSP3400
:
384 btv
->have_msp3400
= 1;
386 case I2C_DRIVERID_TUNER
:
388 if (btv
->tuner_type
!= -1)
389 i2c_control_device(&(btv
->i2c
),
391 TUNER_SET_TYPE
,&btv
->tuner_type
);
396 void detach_inform(struct i2c_bus
*bus
, int id
)
398 struct bttv
*btv
= (struct bttv
*)bus
->data
;
402 case I2C_DRIVERID_MSP3400
:
403 btv
->have_msp3400
= 0;
405 case I2C_DRIVERID_TUNER
:
411 static struct i2c_bus bttv_i2c_bus_template
=
417 #if LINUX_VERSION_CODE >= 0x020100
430 /* ----------------------------------------------------------------------- */
431 /* some hauppauge specific stuff */
433 static unsigned char eeprom_data
[256];
434 static struct HAUPPAUGE_TUNER
441 { TUNER_ABSENT
, "" },
442 { TUNER_ABSENT
, "External" },
443 { TUNER_ABSENT
, "Unspecified" },
444 { TUNER_ABSENT
, "Philips FI1216" },
445 { TUNER_ABSENT
, "Philips FI1216MF" },
446 { TUNER_PHILIPS_NTSC
, "Philips FI1236" },
447 { TUNER_ABSENT
, "Philips FI1246" },
448 { TUNER_ABSENT
, "Philips FI1256" },
449 { TUNER_PHILIPS_PAL
, "Philips FI1216 MK2" },
450 { TUNER_PHILIPS_SECAM
, "Philips FI1216MF MK2" },
451 { TUNER_PHILIPS_NTSC
, "Philips FI1236 MK2" },
452 { TUNER_PHILIPS_PAL_I
, "Philips FI1246 MK2" },
453 { TUNER_ABSENT
, "Philips FI1256 MK2" },
454 { TUNER_ABSENT
, "Temic 4032FY5" },
455 { TUNER_TEMIC_PAL
, "Temic 4002FH5" },
456 { TUNER_TEMIC_PAL_I
, "Temic 4062FY5" },
457 { TUNER_ABSENT
, "Philips FR1216 MK2" },
458 { TUNER_PHILIPS_SECAM
, "Philips FR1216MF MK2" },
459 { TUNER_PHILIPS_NTSC
, "Philips FR1236 MK2" },
460 { TUNER_PHILIPS_PAL_I
, "Philips FR1246 MK2" },
461 { TUNER_ABSENT
, "Philips FR1256 MK2" },
462 { TUNER_PHILIPS_PAL
, "Philips FM1216" },
463 { TUNER_ABSENT
, "Philips FM1216MF" },
464 { TUNER_PHILIPS_NTSC
, "Philips FM1236" },
468 hauppauge_eeprom(struct i2c_bus
*bus
)
470 struct bttv
*btv
= (struct bttv
*)bus
->data
;
472 readee(bus
, eeprom_data
);
473 if (eeprom_data
[9] < sizeof(hauppauge_tuner
)/sizeof(struct HAUPPAUGE_TUNER
))
475 btv
->tuner_type
= hauppauge_tuner
[eeprom_data
[9]].id
;
476 printk("bttv%d: Hauppauge eeprom: tuner=%s (%d)\n",btv
->nr
,
477 hauppauge_tuner
[eeprom_data
[9]].name
,btv
->tuner_type
);
482 hauppauge_msp_reset(struct bttv
*btv
)
484 /* Reset the MSP on some Hauppauge cards */
485 /* Thanks to Kyösti Mälkki (kmalkki@cc.hut.fi)! */
486 /* Can this hurt cards without one? What about Miros with MSP? */
487 btaor(32, ~32, BT848_GPIO_OUT_EN
);
488 btaor(0, ~32, BT848_GPIO_DATA
);
490 btaor(32, ~32, BT848_GPIO_DATA
);
491 /* btaor(0, ~32, BT848_GPIO_OUT_EN); */
494 /* ----------------------------------------------------------------------- */
505 u32 audiomux
[6]; /* Tuner, Radio, internal, external, mute, stereo */
506 u32 gpiomask2
; /* GPIO MUX mask */
509 static struct tvcard tvcards
[] =
512 { 3, 1, 0, 2, 0, { 2, 3, 1, 1}, { 0, 0, 0, 0, 0}},
514 { 4, 1, 0, 2,15, { 2, 3, 1, 1}, { 2, 0, 0, 0,10}},
516 { 3, 1, 0, 2, 7, { 2, 3, 1, 1}, { 0, 1, 2, 3, 4}},
518 { 3, 1, 0, 2, 7, { 2, 3, 1, 1}, { 4, 0, 2, 3, 1}},
520 { 3, 1, 0, 2, 7, { 2, 3, 1, 1}, { 0, 1, 2, 3, 4}},
521 /* Diamond DTV2000 */
522 { 3, 1, 0, 2, 3, { 2, 3, 1, 1}, { 0, 1, 0, 1, 3}},
523 /* AVerMedia TVPhone */
524 { 3, 1, 0, 3,15, { 2, 3, 1, 1}, {12, 0,11,11, 0}},
525 /* Matrix Vision MV-Delta */
526 { 5, 1, -1, 3, 0, { 2, 3, 1, 0, 0}},
528 { 3, 1, 0, 2, 0xc00, { 2, 3, 1, 1},
529 {0, 0xc00, 0x800, 0x400, 0xc00, 0}},
531 { 3, 1, 0, 2, 3, { 2, 3, 1, 1}, { 1, 1, 2, 3, 0}},
532 /* Newer Hauppauge (bt878) */
533 { 3, 1, 0, 2, 7, { 2, 0, 1, 1}, { 0, 1, 2, 3, 4}},
535 { 3, 1, 0, 2, 65551, { 2, 3, 1, 1}, {1,65537, 0, 0,10}},
536 /* ADS Technologies Channel Surfer TV (and maybe TV+FM) */
537 { 3, 4, 0, 2, 15, { 2, 3, 1, 1}, { 13, 14, 11, 7, 0, 0}, 0},
538 /* AVerMedia TVCapture 98 */
539 { 3, 4, 0, 2, 15, { 2, 3, 1, 1}, { 13, 14, 11, 7, 0, 0}, 0},
541 { 3, 1, 0, 2, 7, { 2, 3, 1, 1}, { 0, 1, 2, 3, 4}},
543 { 3, 1, 0, 2,15, { 2, 3, 1, 1}, { 0, 0, 0, 0, 0}},
544 /* Pixelview PlayTV (bt878) */
545 { 3, 4, 0, 2, 0x01e000, { 2, 0, 1, 1}, {0x01c000, 0, 0x018000, 0x014000, 0x002000, 0 }},
546 /* "Leadtek WinView 601", */
547 { 3, 1, 0, 2, 0x8300f8, { 2, 3, 1, 1,0}, {0x4fa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007}},
549 #define TVCARDS (sizeof(tvcards)/sizeof(tvcard))
551 static void audio(struct bttv
*btv
, int mode
)
553 btaor(tvcards
[btv
->type
].gpiomask
, ~tvcards
[btv
->type
].gpiomask
,
559 btv
->audio
|=AUDIO_MUTE
;
562 btv
->audio
&=~AUDIO_MUTE
;
572 btv
->audio
&=AUDIO_MUTE
;
576 /* if audio mute or not in H-lock, turn audio off */
577 if ((btv
->audio
&AUDIO_MUTE
)
580 (!btv
->radio
&& !(btread(BT848_DSTATUS
)&BT848_DSTATUS_HLOC
))
584 if ((mode
== 0) && (btv
->radio
))
586 btaor(tvcards
[btv
->type
].audiomux
[mode
],
587 ~tvcards
[btv
->type
].gpiomask
, BT848_GPIO_DATA
);
591 extern inline void bt848_dma(struct bttv
*btv
, uint state
)
594 btor(3, BT848_GPIO_DMA_CTL
);
596 btand(~3, BT848_GPIO_DMA_CTL
);
600 static void bt848_cap(struct bttv
*btv
, uint state
)
605 bt848_set_risc_jmps(btv
);
610 bt848_set_risc_jmps(btv
);
615 /* If Bt848a or Bt849, use PLL for PAL/SECAM and crystal for NTSC*/
617 /* Frequency = (F_input / PLL_X) * PLL_I.PLL_F/PLL_C
618 PLL_X = Reference pre-divider (0=1, 1=2)
619 PLL_C = Post divider (0=6, 1=4)
620 PLL_I = Integer input
621 PLL_F = Fractional input
623 F_input = 28.636363 MHz:
624 PAL (CLKx2 = 35.46895 MHz): PLL_X = 1, PLL_I = 0x0E, PLL_F = 0xDCF9, PLL_C = 0
627 static void set_pll_freq(struct bttv
*btv
, unsigned int fin
, unsigned int fout
)
629 unsigned char fl
, fh
, fi
;
631 /* prevent overflows */
644 /*printk("0x%02x 0x%02x 0x%02x\n", fi, fh, fl);*/
645 btwrite(fl
, BT848_PLL_F_LO
);
646 btwrite(fh
, BT848_PLL_F_HI
);
647 btwrite(fi
|BT848_PLL_X
, BT848_PLL_XCI
);
650 static int set_pll(struct bttv
*btv
)
655 if (!btv
->pll
.pll_crystal
)
658 if (btv
->pll
.pll_ifreq
== btv
->pll
.pll_ofreq
) {
660 if (btv
->pll
.pll_current
== 0) {
661 /* printk ("bttv%d: PLL: is off\n",btv->nr); */
664 printk ("bttv%d: PLL: switching off\n",btv
->nr
);
665 btwrite(0x00,BT848_TGCTRL
);
666 btwrite(0x00,BT848_PLL_XCI
);
667 btv
->pll
.pll_current
= 0;
671 if (btv
->pll
.pll_ofreq
== btv
->pll
.pll_current
) {
672 /* printk("bttv%d: PLL: no change required\n",btv->nr); */
676 printk("bttv%d: PLL: %d => %d ... ",btv
->nr
,
677 btv
->pll
.pll_ifreq
, btv
->pll
.pll_ofreq
);
679 set_pll_freq(btv
, btv
->pll
.pll_ifreq
, btv
->pll
.pll_ofreq
);
681 /* Let other people run while the PLL stabilizes */
682 tv
=jiffies
+HZ
/10; /* .1 seconds */
687 while(time_before(jiffies
,tv
));
691 if ((btread(BT848_DSTATUS
)&BT848_DSTATUS_PLOCK
))
692 btwrite(0,BT848_DSTATUS
);
695 btwrite(0x08,BT848_TGCTRL
);
696 btv
->pll
.pll_current
= btv
->pll
.pll_ofreq
;
702 btv
->pll
.pll_current
= 0;
707 static void bt848_muxsel(struct bttv
*btv
, unsigned int input
)
709 btaor(tvcards
[btv
->type
].gpiomask2
,~tvcards
[btv
->type
].gpiomask2
,
712 /* This seems to get rid of some synchronization problems */
713 btand(~(3<<5), BT848_IFORM
);
717 input
%= tvcards
[btv
->type
].video_inputs
;
718 if (input
==tvcards
[btv
->type
].svhs
)
720 btor(BT848_CONTROL_COMP
, BT848_E_CONTROL
);
721 btor(BT848_CONTROL_COMP
, BT848_O_CONTROL
);
725 btand(~BT848_CONTROL_COMP
, BT848_E_CONTROL
);
726 btand(~BT848_CONTROL_COMP
, BT848_O_CONTROL
);
728 btaor((tvcards
[btv
->type
].muxsel
[input
&7]&3)<<5, ~(3<<5), BT848_IFORM
);
729 audio(btv
, (input
!=tvcards
[btv
->type
].tuner
) ?
730 AUDIO_EXTERN
: AUDIO_TUNER
);
731 btaor(tvcards
[btv
->type
].muxsel
[input
]>>4,
732 ~tvcards
[btv
->type
].gpiomask2
, BT848_GPIO_DATA
);
736 * Set the registers for the size we have specified. Don't bother
737 * trying to understand this without the BT848 manual in front of
740 * PS: The manual is free for download in .pdf format from
741 * www.brooktree.com - nicely done those folks.
747 u16 swidth
, sheight
; /* scaled standard width, height */
749 u8 adelay
, bdelay
, iform
;
751 u16 hdelayx1
, hactivex1
;
756 static struct tvnorm tvnorms
[] = {
758 /* max. active video is actually 922, but 924 is divisible by 4 and 3! */
759 /* actually, max active PAL with HSCALE=0 is 948, NTSC is 768 - nil */
762 924, 576, 1135, 0x7f, 0x72, (BT848_IFORM_PAL_BDGHI
|BT848_IFORM_XT1
),
763 1135, 186, 924, 0x20, 255},
766 924, 576, 1135, 0x7f, 0x72, (BT848_IFORM_PAL_BDGHI
|BT848_IFORM_XT1
),
767 1135, 186, 924, 0x20, 255},
771 768, 576, 1135, 0x7f, 0x72, (BT848_IFORM_PAL_BDGHI|BT848_IFORM_XT1),
772 944, 186, 922, 0x20, 255},
776 768, 480, 910, 0x68, 0x5d, (BT848_IFORM_NTSC
|BT848_IFORM_XT0
),
777 910, 128, 910, 0x1a, 144},
780 640, 480, 910, 0x68, 0x5d, (BT848_IFORM_NTSC|BT848_IFORM_XT0),
781 780, 122, 754, 0x1a, 144},
786 768, 576, 1135, 0x7f, 0xb0, (BT848_IFORM_SECAM
|BT848_IFORM_XT1
),
787 944, 186, 922, 0x20, 255},
791 924, 576, 1135, 0x7f, 0xb0, (BT848_IFORM_SECAM
|BT848_IFORM_XT1
),
792 1135, 186, 922, 0x20, 255},
796 640, 576, 910, 0x68, 0x5d, (BT848_IFORM_PAL_NC
|BT848_IFORM_XT0
),
797 780, 130, 734, 0x1a, 144},
800 640, 480, 910, 0x68, 0x5d, (BT848_IFORM_PAL_M
|BT848_IFORM_XT0
),
801 780, 135, 754, 0x1a, 144},
804 768, 576, 1135, 0x7f, 0x72, (BT848_IFORM_PAL_N
|BT848_IFORM_XT1
),
805 944, 186, 922, 0x20, 144},
808 640, 480, 910, 0x68, 0x5d, (BT848_IFORM_NTSC_J
|BT848_IFORM_XT0
),
809 780, 135, 754, 0x16, 144},
811 #define TVNORMS (sizeof(tvnorms)/sizeof(tvnorm))
814 /* RISC command to write one VBI data line */
815 #define VBI_RISC BT848_RISC_WRITE|VBI_SPL|BT848_RISC_EOL|BT848_RISC_SOL
817 static void make_vbitab(struct bttv
*btv
)
820 unsigned int *po
=(unsigned int *) btv
->vbi_odd
;
821 unsigned int *pe
=(unsigned int *) btv
->vbi_even
;
823 DEBUG(printk(KERN_DEBUG
"vbiodd: 0x%08x\n",(int)btv
->vbi_odd
));
824 DEBUG(printk(KERN_DEBUG
"vbievn: 0x%08x\n",(int)btv
->vbi_even
));
825 DEBUG(printk(KERN_DEBUG
"po: 0x%08x\n",(int)po
));
826 DEBUG(printk(KERN_DEBUG
"pe: 0x%08x\n",(int)pe
));
828 *(po
++)=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
; *(po
++)=0;
832 *(po
++)=kvirt_to_bus((unsigned long)btv
->vbibuf
+i
*2048);
834 *(po
++)=BT848_RISC_JUMP
;
835 *(po
++)=virt_to_bus(btv
->risc_jmp
+4);
837 *(pe
++)=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
; *(pe
++)=0;
838 for (i
=16; i
<32; i
++)
841 *(pe
++)=kvirt_to_bus((unsigned long)btv
->vbibuf
+i
*2048);
843 *(pe
++)=BT848_RISC_JUMP
|BT848_RISC_IRQ
|(0x01<<16);
844 *(pe
++)=virt_to_bus(btv
->risc_jmp
+10);
845 DEBUG(printk(KERN_DEBUG
"po: 0x%08x\n",(int)po
));
846 DEBUG(printk(KERN_DEBUG
"pe: 0x%08x\n",(int)pe
));
850 8, 6, 4, 4, 4, 3, 2, 2, 4, 3, 0, 0, 0, 0, 2, 0
853 int palette2fmt
[] = {
856 BT848_COLOR_FMT_RGB8
,
857 BT848_COLOR_FMT_RGB16
,
858 BT848_COLOR_FMT_RGB24
,
859 BT848_COLOR_FMT_RGB32
,
860 BT848_COLOR_FMT_RGB15
,
861 BT848_COLOR_FMT_YUY2
,
862 BT848_COLOR_FMT_BtYUV
,
867 BT848_COLOR_FMT_YCrCb422
,
868 BT848_COLOR_FMT_YCrCb411
,
869 BT848_COLOR_FMT_YCrCb422
,
870 BT848_COLOR_FMT_YCrCb411
,
872 #define PALETTEFMT_MAX (sizeof(palette2fmt)/sizeof(int))
874 static int make_rawrisctab(struct bttv
*btv
, unsigned int *ro
,
875 unsigned int *re
, unsigned int *vbuf
)
878 unsigned long bpl
=1024; /* bytes per line */
879 unsigned long vadr
=(unsigned long) vbuf
;
881 *(ro
++)=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
; *(ro
++)=0;
882 *(re
++)=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
; *(re
++)=0;
884 /* In PAL 650 blocks of 256 DWORDs are sampled, but only if VDELAY
885 is 2 and without separate VBI grabbing.
886 We'll have to handle this inside the IRQ handler ... */
888 for (line
=0; line
< 640; line
++)
890 *(ro
++)=BT848_RISC_WRITE
|bpl
|BT848_RISC_SOL
|BT848_RISC_EOL
;
891 *(ro
++)=kvirt_to_bus(vadr
);
892 *(re
++)=BT848_RISC_WRITE
|bpl
|BT848_RISC_SOL
|BT848_RISC_EOL
;
893 *(re
++)=kvirt_to_bus(vadr
+BTTV_MAX_FBUF
/2);
897 *(ro
++)=BT848_RISC_JUMP
;
898 *(ro
++)=btv
->bus_vbi_even
;
899 *(re
++)=BT848_RISC_JUMP
|BT848_RISC_IRQ
|(2<<16);
900 *(re
++)=btv
->bus_vbi_odd
;
906 static int make_prisctab(struct bttv
*btv
, unsigned int *ro
,
908 unsigned int *vbuf
, unsigned short width
,
909 unsigned short height
, unsigned short fmt
)
911 unsigned long line
, lmask
;
912 unsigned long bl
, blcr
, blcb
, rcmd
;
916 unsigned long cbadr
, cradr
;
917 unsigned long vadr
=(unsigned long) vbuf
;
923 case VIDEO_PALETTE_YUV422P
:
924 csize
=(width
*height
)>>1;
929 case VIDEO_PALETTE_YUV411P
:
930 csize
=(width
*height
)>>2;
935 case VIDEO_PALETTE_YUV420P
:
936 csize
=(width
*height
)>>2;
941 case VIDEO_PALETTE_YUV410P
:
942 csize
=(width
*height
)>>4;
950 cbadr
=vadr
+(width
*height
);
952 inter
= (height
>btv
->win
.cropheight
/2) ? 1 : 0;
954 *(ro
++)=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM3
; *(ro
++)=0;
955 *(re
++)=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM3
; *(re
++)=0;
957 for (line
=0; line
< (height
<<(1^inter
)); line
++)
962 cbadr
=vadr
+(width
*height
);
966 rp
= (line
&1) ? &re
: &ro
;
968 rp
= (line
>=height
) ? &re
: &ro
;
972 rcmd
=BT848_RISC_WRITE1S23
|BT848_RISC_SOL
;
974 rcmd
=BT848_RISC_WRITE123
|BT848_RISC_SOL
;
979 bl
=PAGE_SIZE
-((PAGE_SIZE
-1)&vadr
);
980 blcr
=(PAGE_SIZE
-((PAGE_SIZE
-1)&cradr
))<<shift
;
981 blcb
=(PAGE_SIZE
-((PAGE_SIZE
-1)&cbadr
))<<shift
;
982 bl
=(blcr
<bl
) ? blcr
: bl
;
983 bl
=(blcb
<bl
) ? blcb
: bl
;
984 bl
=(bl
>todo
) ? todo
: bl
;
987 /* bl now containts the longest row that can be written */
989 if(!todo
) rcmd
|=BT848_RISC_EOL
; /* if this is the last EOL */
992 *((*rp
)++)=blcb
|(blcr
<<16);
993 *((*rp
)++)=kvirt_to_bus(vadr
);
995 if((rcmd
&(15<<28))==BT848_RISC_WRITE123
)
997 *((*rp
)++)=kvirt_to_bus(cbadr
);
999 *((*rp
)++)=kvirt_to_bus(cradr
);
1003 rcmd
&=~BT848_RISC_SOL
; /* only the first has SOL */
1007 *(ro
++)=BT848_RISC_JUMP
;
1008 *(ro
++)=btv
->bus_vbi_even
;
1009 *(re
++)=BT848_RISC_JUMP
|BT848_RISC_IRQ
|(2<<16);
1010 *(re
++)=btv
->bus_vbi_odd
;
1015 static int make_vrisctab(struct bttv
*btv
, unsigned int *ro
,
1017 unsigned int *vbuf
, unsigned short width
,
1018 unsigned short height
, unsigned short palette
)
1021 unsigned long bpl
; /* bytes per line */
1026 unsigned long vadr
=(unsigned long) vbuf
;
1028 if (palette
==VIDEO_PALETTE_RAW
)
1029 return make_rawrisctab(btv
, ro
, re
, vbuf
);
1030 if (palette
>=VIDEO_PALETTE_PLANAR
)
1031 return make_prisctab(btv
, ro
, re
, vbuf
, width
, height
, palette
);
1034 inter
= (height
>btv
->win
.cropheight
/2) ? 1 : 0;
1035 bpl
=width
*fmtbppx2
[palette2fmt
[palette
]&0xf]/2;
1037 *(ro
++)=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
; *(ro
++)=0;
1038 *(re
++)=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
; *(re
++)=0;
1040 for (line
=0; line
< (height
<<(1^inter
)); line
++)
1043 rp
= (line
&1) ? &re
: &ro
;
1045 rp
= (line
>=height
) ? &re
: &ro
;
1047 bl
=PAGE_SIZE
-((PAGE_SIZE
-1)&vadr
);
1050 *((*rp
)++)=BT848_RISC_WRITE
|BT848_RISC_SOL
|
1052 *((*rp
)++)=kvirt_to_bus(vadr
);
1058 *((*rp
)++)=BT848_RISC_WRITE
|BT848_RISC_SOL
|bl
;
1059 *((*rp
)++)=kvirt_to_bus(vadr
);
1062 while (todo
>PAGE_SIZE
)
1064 *((*rp
)++)=BT848_RISC_WRITE
|PAGE_SIZE
;
1065 *((*rp
)++)=kvirt_to_bus(vadr
);
1069 *((*rp
)++)=BT848_RISC_WRITE
|BT848_RISC_EOL
|todo
;
1070 *((*rp
)++)=kvirt_to_bus(vadr
);
1075 *(ro
++)=BT848_RISC_JUMP
;
1076 *(ro
++)=btv
->bus_vbi_even
;
1077 *(re
++)=BT848_RISC_JUMP
|BT848_RISC_IRQ
|(2<<16);
1078 *(re
++)=btv
->bus_vbi_odd
;
1083 static unsigned char lmaskt
[8] =
1084 { 0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80};
1085 static unsigned char rmaskt
[8] =
1086 { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
1088 static void clip_draw_rectangle(unsigned char *clipmap
, int x
, int y
, int w
, int h
)
1090 unsigned char lmask
, rmask
, *p
;
1093 /* bitmap is fixed width, 128 bytes (1024 pixels represented) */
1104 if (w
< 0 || h
< 0) /* catch bad clips */
1106 /* out of range data should just fall through */
1116 rmask
=rmaskt
[(x
+w
)&7];
1121 for (i
=0; i
<h
; i
++, p
+=128)
1124 memset(p
+1, 0xff, W
);
1128 for (i
=0; i
<h
; i
++, p
+=128)
1134 for (i
=0; i
<h
; i
++, p
+=128)
1141 static void make_clip_tab(struct bttv
*btv
, struct video_clip
*cr
, int ncr
)
1143 int i
, line
, x
, y
, bpl
, width
, height
, inter
;
1144 unsigned int bpp
, dx
, sx
, **rp
, *ro
, *re
, flags
, len
;
1146 unsigned char *clipmap
, cbit
, lastbit
, outofmem
;
1148 inter
=(btv
->win
.interlace
&1)^1;
1150 if (bpp
==15) /* handle 15bpp as 16bpp in calculations */
1155 if((width
=btv
->win
.width
)>1023)
1156 width
= 1023; /* sanity check */
1157 if((height
=btv
->win
.height
)>625)
1158 height
= 625; /* sanity check */
1159 adr
=btv
->win
.vidadr
+btv
->win
.x
*bpp
+btv
->win
.y
*bpl
;
1160 if ((clipmap
=vmalloc(VIDEO_CLIPMAP_SIZE
))==NULL
) {
1161 /* can't clip, don't generate any risc code */
1162 *(ro
++)=BT848_RISC_JUMP
;
1163 *(ro
++)=btv
->bus_vbi_even
;
1164 *(re
++)=BT848_RISC_JUMP
;
1165 *(re
++)=btv
->bus_vbi_odd
;
1167 if (ncr
< 0) { /* bitmap was pased */
1168 memcpy(clipmap
, (unsigned char *)cr
, VIDEO_CLIPMAP_SIZE
);
1169 } else { /* convert rectangular clips to a bitmap */
1170 memset(clipmap
, 0, VIDEO_CLIPMAP_SIZE
); /* clear map */
1171 for (i
=0; i
<ncr
; i
++)
1172 clip_draw_rectangle(clipmap
, cr
[i
].x
, cr
[i
].y
,
1173 cr
[i
].width
, cr
[i
].height
);
1175 /* clip against viewing window AND screen
1176 so we do not have to rely on the user program
1178 clip_draw_rectangle(clipmap
,(btv
->win
.x
+width
>btv
->win
.swidth
) ?
1179 (btv
->win
.swidth
-btv
->win
.x
) : width
, 0, 1024, 768);
1180 clip_draw_rectangle(clipmap
,0,(btv
->win
.y
+height
>btv
->win
.sheight
) ?
1181 (btv
->win
.sheight
-btv
->win
.y
) : height
,1024,768);
1183 clip_draw_rectangle(clipmap
, 0, 0, -(btv
->win
.x
), 768);
1185 clip_draw_rectangle(clipmap
, 0, 0, 1024, -(btv
->win
.y
));
1187 *(ro
++)=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
; *(ro
++)=0;
1188 *(re
++)=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
; *(re
++)=0;
1190 /* translate bitmap to risc code */
1191 for (line
=outofmem
=0; line
< (height
<<inter
) && !outofmem
; line
++)
1194 rp
= (line
&1) ? &re
: &ro
;
1195 lastbit
=(clipmap
[y
<<7]&1);
1196 for(x
=dx
=1,sx
=0; x
<=width
&& !outofmem
; x
++) {
1197 cbit
= (clipmap
[(y
<<7)+(x
>>3)] & (1<<(x
&7)));
1198 if (x
< width
&& !lastbit
== !cbit
)
1200 else { /* generate the dma controller code */
1202 flags
= ((bpp
==4) ? BT848_RISC_BYTE3
: 0);
1203 flags
|= ((!sx
) ? BT848_RISC_SOL
: 0);
1204 flags
|= ((sx
+ dx
== width
) ? BT848_RISC_EOL
: 0);
1206 *((*rp
)++)=BT848_RISC_WRITE
|flags
|len
;
1207 *((*rp
)++)=adr
+ bpp
* sx
;
1209 *((*rp
)++)=BT848_RISC_SKIP
|flags
|len
;
1213 if (ro
- btv
->risc_odd
> RISCMEM_LEN
/2 - 16)
1215 if (re
- btv
->risc_even
> RISCMEM_LEN
/2 - 16)
1219 if ((!inter
)||(line
&1))
1223 /* outofmem flag relies on the following code to discard extra data */
1224 *(ro
++)=BT848_RISC_JUMP
;
1225 *(ro
++)=btv
->bus_vbi_even
;
1226 *(re
++)=BT848_RISC_JUMP
;
1227 *(re
++)=btv
->bus_vbi_odd
;
1230 /* set geometry for even/odd frames
1231 just if you are wondering:
1232 handling of even and odd frames will be separated, e.g. for grabbing
1233 the even ones as RGB into videomem and the others as YUV in main memory for
1234 compressing and sending to the video conferencing partner.
1237 static inline void bt848_set_eogeo(struct bttv
*btv
, int odd
, u8 vtc
,
1238 u16 hscale
, u16 vscale
,
1239 u16 hactive
, u16 vactive
,
1240 u16 hdelay
, u16 vdelay
,
1243 int off
= odd
? 0x80 : 0x00;
1245 btwrite(vtc
, BT848_E_VTC
+off
);
1246 btwrite(hscale
>>8, BT848_E_HSCALE_HI
+off
);
1247 btwrite(hscale
&0xff, BT848_E_HSCALE_LO
+off
);
1248 btaor((vscale
>>8), 0xe0, BT848_E_VSCALE_HI
+off
);
1249 btwrite(vscale
&0xff, BT848_E_VSCALE_LO
+off
);
1250 btwrite(hactive
&0xff, BT848_E_HACTIVE_LO
+off
);
1251 btwrite(hdelay
&0xff, BT848_E_HDELAY_LO
+off
);
1252 btwrite(vactive
&0xff, BT848_E_VACTIVE_LO
+off
);
1253 btwrite(vdelay
&0xff, BT848_E_VDELAY_LO
+off
);
1254 btwrite(crop
, BT848_E_CROP
+off
);
1258 static void bt848_set_geo(struct bttv
*btv
, u16 width
, u16 height
, u16 fmt
)
1263 u16 hactive
, vactive
;
1268 if (!width
|| !height
)
1271 tvn
=&tvnorms
[btv
->win
.norm
];
1273 btv
->win
.cropheight
=tvn
->sheight
;
1274 btv
->win
.cropwidth
=tvn
->swidth
;
1277 if (btv->win.cropwidth>tvn->cropwidth)
1278 btv->win.cropwidth=tvn->cropwidth;
1279 if (btv->win.cropheight>tvn->cropheight)
1280 btv->win.cropheight=tvn->cropheight;
1282 if (width>btv->win.cropwidth)
1283 width=btv->win.cropwidth;
1284 if (height>btv->win.cropheight)
1285 height=btv->win.cropheight;
1287 btwrite(tvn
->adelay
, BT848_ADELAY
);
1288 btwrite(tvn
->bdelay
, BT848_BDELAY
);
1289 btaor(tvn
->iform
,~(BT848_IFORM_NORM
|BT848_IFORM_XTBOTH
), BT848_IFORM
);
1290 btwrite(tvn
->vbipack
, BT848_VBI_PACK_SIZE
);
1291 btwrite(1, BT848_VBI_PACK_DEL
);
1293 btv
->pll
.pll_ofreq
= tvn
->Fsc
;
1296 btwrite(fmt
, BT848_COLOR_FMT
);
1300 /* Some people say interpolation looks bad ... */
1301 /* vtc = (hactive < 193) ? 2 : ((hactive < 385) ? 1 : 0); */
1303 btv
->win
.interlace
= (height
>btv
->win
.cropheight
/2) ? 1 : 0;
1304 inter
=(btv
->win
.interlace
&1)^1;
1305 vdelay
=btv
->win
.cropy
+tvn
->vdelay
;
1307 xsf
= (hactive
*tvn
->scaledtwidth
)/btv
->win
.cropwidth
;
1308 hscale
= ((tvn
->totalwidth
*4096UL)/xsf
-4096);
1310 hdelay
=tvn
->hdelayx1
+btv
->win
.cropx
;
1311 hdelay
=(hdelay
*hactive
)/btv
->win
.cropwidth
;
1314 sr
=((btv
->win
.cropheight
>>inter
)*512)/height
-512;
1315 vscale
=(0x10000UL
-sr
)&0x1fff;
1316 vactive
=btv
->win
.cropheight
;
1317 crop
=((hactive
>>8)&0x03)|((hdelay
>>6)&0x0c)|
1318 ((vactive
>>4)&0x30)|((vdelay
>>2)&0xc0);
1319 vscale
|= btv
->win
.interlace
? (BT848_VSCALE_INT
<<8) : 0;
1321 bt848_set_eogeo(btv
, 0, vtc
, hscale
, vscale
, hactive
, vactive
,
1322 hdelay
, vdelay
, crop
);
1323 bt848_set_eogeo(btv
, 1, vtc
, hscale
, vscale
, hactive
, vactive
,
1324 hdelay
, vdelay
, crop
);
1329 BT848_COLOR_FMT_RGB8
, BT848_COLOR_FMT_RGB16
,
1330 BT848_COLOR_FMT_RGB24
, BT848_COLOR_FMT_RGB32
1333 static void bt848_set_winsize(struct bttv
*btv
)
1335 unsigned short format
;
1337 btv
->win
.color_fmt
= format
=
1338 (btv
->win
.depth
==15) ? BT848_COLOR_FMT_RGB15
:
1339 bpp2fmt
[(btv
->win
.bpp
-1)&3];
1341 /* RGB8 seems to be a 9x5x5 GRB color cube starting at
1342 * color 16. Why the h... can't they even mention this in the
1343 * data sheet? [AC - because it's a standard format so I guess
1344 * it never occurred to them]
1345 * Enable dithering in this mode.
1348 if (format
==BT848_COLOR_FMT_RGB8
)
1349 btand(~BT848_CAP_CTL_DITH_FRAME
, BT848_CAP_CTL
);
1351 btor(BT848_CAP_CTL_DITH_FRAME
, BT848_CAP_CTL
);
1353 bt848_set_geo(btv
, btv
->win
.width
, btv
->win
.height
, format
);
1357 * Set TSA5522 synthesizer frequency in 1/16 Mhz steps
1360 static void set_freq(struct bttv
*btv
, unsigned short freq
)
1362 int fixme
= freq
; /* XXX */
1365 if (btv
->have_msp3400
)
1366 i2c_control_device(&(btv
->i2c
),I2C_DRIVERID_MSP3400
,
1369 /* switch channel */
1370 if (btv
->have_tuner
) {
1372 i2c_control_device(&(btv
->i2c
), I2C_DRIVERID_TUNER
,
1373 TUNER_SET_RADIOFREQ
,&fixme
);
1375 i2c_control_device(&(btv
->i2c
), I2C_DRIVERID_TUNER
,
1376 TUNER_SET_TVFREQ
,&fixme
);
1380 if (btv
->have_msp3400
) {
1382 i2c_control_device(&(btv
->i2c
),I2C_DRIVERID_MSP3400
,
1385 i2c_control_device(&(btv
->i2c
),I2C_DRIVERID_MSP3400
,
1386 MSP_SET_TVNORM
,&(btv
->win
.norm
));
1387 i2c_control_device(&(btv
->i2c
),I2C_DRIVERID_MSP3400
,
1394 * Grab into virtual memory.
1395 * Currently only does double buffering. Do we need more?
1398 static int vgrab(struct bttv
*btv
, struct video_mmap
*mp
)
1400 unsigned int *ro
, *re
;
1403 if(btv
->fbuffer
==NULL
)
1405 if(fbuffer_alloc(btv
))
1408 if(btv
->grabbing
>= MAX_GBUFFERS
)
1412 * No grabbing past the end of the buffer!
1415 if(mp
->frame
>1 || mp
->frame
<0)
1418 if(mp
->height
<0 || mp
->width
<0)
1421 /* This doesn´t work like this for NTSC anyway.
1422 So, better check the total image size ...
1425 if(mp->height>576 || mp->width>768+BURSTOFFSET)
1428 if (mp
->format
>= PALETTEFMT_MAX
)
1430 if (mp
->height
*mp
->width
*fmtbppx2
[palette2fmt
[mp
->format
]&0x0f]/2
1433 if(-1 == palette2fmt
[mp
->format
])
1437 * FIXME: Check the format of the grab here. This is probably
1438 * also less restrictive than the normal overlay grabs. Stuff
1439 * like QCIF has meaning as a capture.
1443 * Ok load up the BT848
1446 vbuf
=(unsigned int *)(btv
->fbuffer
+BTTV_MAX_FBUF
*mp
->frame
);
1447 /* if (!(btread(BT848_DSTATUS)&BT848_DSTATUS_HLOC))
1449 ro
=btv
->grisc
+(((btv
->grabcount
++)&1) ? 4096 :0);
1451 make_vrisctab(btv
, ro
, re
, vbuf
, mp
->width
, mp
->height
, mp
->format
);
1452 /* bt848_set_risc_jmps(btv); */
1453 btv
->frame_stat
[mp
->frame
] = GBUFFER_GRABBING
;
1454 if (btv
->grabbing
) {
1455 btv
->gfmt_next
=palette2fmt
[mp
->format
];
1456 btv
->gwidth_next
=mp
->width
;
1457 btv
->gheight_next
=mp
->height
;
1458 btv
->gro_next
=virt_to_bus(ro
);
1459 btv
->gre_next
=virt_to_bus(re
);
1460 btv
->grf_next
=mp
->frame
;
1462 btv
->gfmt
=palette2fmt
[mp
->format
];
1463 btv
->gwidth
=mp
->width
;
1464 btv
->gheight
=mp
->height
;
1465 btv
->gro
=virt_to_bus(ro
);
1466 btv
->gre
=virt_to_bus(re
);
1469 if (!(btv
->grabbing
++)) {
1470 if(mp
->format
>=VIDEO_PALETTE_COMPONENT
) {
1471 btor(BT848_VSCALE_COMB
, BT848_E_VSCALE_HI
);
1472 btor(BT848_VSCALE_COMB
, BT848_O_VSCALE_HI
);
1474 btv
->risc_jmp
[12]=BT848_RISC_JUMP
|(0x8<<16)|BT848_RISC_IRQ
;
1476 btor(3, BT848_CAP_CTL
);
1477 btor(3, BT848_GPIO_DMA_CTL
);
1478 /* interruptible_sleep_on(&btv->capq); */
1482 static long bttv_write(struct video_device
*v
, const char *buf
, unsigned long count
, int nonblock
)
1487 static long bttv_read(struct video_device
*v
, char *buf
, unsigned long count
, int nonblock
)
1489 struct bttv
*btv
= (struct bttv
*)v
;
1491 /* BROKEN: RETURNS VBI WHEN IT SHOULD RETURN GRABBED VIDEO FRAME */
1493 while (todo
&& todo
>(q
=VBIBUF_SIZE
-btv
->vbip
))
1495 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, q
))
1501 if (todo
&& q
==VBIBUF_SIZE
-btv
->vbip
)
1507 return -EWOULDBLOCK
;
1510 interruptible_sleep_on(&btv
->vbiq
);
1512 if(signal_pending(current
))
1523 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, todo
))
1531 * Open a bttv card. Right now the flags stuff is just playing
1534 static int bttv_open(struct video_device
*dev
, int flags
)
1536 struct bttv
*btv
= (struct bttv
*)dev
;
1541 audio(btv
, AUDIO_UNMUTE
);
1542 for (i
=users
=0; i
<bttv_num
; i
++)
1543 users
+=bttvs
[i
].user
;
1548 btv
->fbuffer
=(unsigned char *) rvmalloc(2*BTTV_MAX_FBUF
);
1554 for (i
= 0; i
< MAX_GBUFFERS
; i
++)
1555 btv
->frame_stat
[i
] = GBUFFER_UNUSED
;
1562 static void bttv_close(struct video_device
*dev
)
1564 struct bttv
*btv
=(struct bttv
*)dev
;
1567 audio(btv
, AUDIO_INTERN
);
1569 bt848_set_risc_jmps(btv
);
1572 * A word of warning. At this point the chip
1573 * is still capturing because its FIFO hasn't emptied
1574 * and the DMA control operations are posted PCI
1578 btread(BT848_I2C
); /* This fixes the PCI posting delay */
1581 * This is sucky but right now I can't find a good way to
1582 * be sure its safe to free the buffer. We wait 5-6 fields
1583 * which is more than sufficient to be sure.
1586 current
->state
= TASK_UNINTERRUPTIBLE
;
1587 schedule_timeout(HZ
/10); /* Wait 1/10th of a second */
1590 * We have allowed it to drain.
1593 rvfree((void *) btv
->fbuffer
, 2*BTTV_MAX_FBUF
);
1599 /***********************************/
1600 /* ioctls and supporting functions */
1601 /***********************************/
1603 extern inline void bt848_bright(struct bttv
*btv
, uint bright
)
1605 btwrite(bright
&0xff, BT848_BRIGHT
);
1608 extern inline void bt848_hue(struct bttv
*btv
, uint hue
)
1610 btwrite(hue
&0xff, BT848_HUE
);
1613 extern inline void bt848_contrast(struct bttv
*btv
, uint cont
)
1615 unsigned int conthi
;
1618 btwrite(cont
&0xff, BT848_CONTRAST_LO
);
1619 btaor(conthi
, ~4, BT848_E_CONTROL
);
1620 btaor(conthi
, ~4, BT848_O_CONTROL
);
1623 extern inline void bt848_sat_u(struct bttv
*btv
, unsigned long data
)
1628 btwrite(data
&0xff, BT848_SAT_U_LO
);
1629 btaor(datahi
, ~2, BT848_E_CONTROL
);
1630 btaor(datahi
, ~2, BT848_O_CONTROL
);
1633 static inline void bt848_sat_v(struct bttv
*btv
, unsigned long data
)
1638 btwrite(data
&0xff, BT848_SAT_V_LO
);
1639 btaor(datahi
, ~1, BT848_E_CONTROL
);
1640 btaor(datahi
, ~1, BT848_O_CONTROL
);
1648 static int bttv_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
1650 unsigned char eedata
[256];
1651 struct bttv
*btv
=(struct bttv
*)dev
;
1658 struct video_capability b
;
1659 strcpy(b
.name
,btv
->video_dev
.name
);
1660 b
.type
= VID_TYPE_CAPTURE
|
1667 b
.channels
= tvcards
[btv
->type
].video_inputs
;
1668 b
.audios
= tvcards
[btv
->type
].audio_inputs
;
1669 b
.maxwidth
= tvnorms
[btv
->win
.norm
].swidth
;
1670 b
.maxheight
= tvnorms
[btv
->win
.norm
].sheight
;
1673 if(copy_to_user(arg
,&b
,sizeof(b
)))
1679 struct video_channel v
;
1680 if(copy_from_user(&v
, arg
,sizeof(v
)))
1682 v
.flags
=VIDEO_VC_AUDIO
;
1684 v
.type
=VIDEO_TYPE_CAMERA
;
1685 v
.norm
= btv
->win
.norm
;
1686 if (v
.channel
>=tvcards
[btv
->type
].video_inputs
)
1688 if(v
.channel
==tvcards
[btv
->type
].tuner
)
1690 strcpy(v
.name
,"Television");
1691 v
.flags
|=VIDEO_VC_TUNER
;
1692 v
.type
=VIDEO_TYPE_TV
;
1695 else if(v
.channel
==tvcards
[btv
->type
].svhs
)
1696 strcpy(v
.name
,"S-Video");
1698 sprintf(v
.name
,"Composite%d",v
.channel
);
1700 if(copy_to_user(arg
,&v
,sizeof(v
)))
1705 * Each channel has 1 tuner
1709 struct video_channel v
;
1710 if(copy_from_user(&v
, arg
,sizeof(v
)))
1713 if (v
.channel
>tvcards
[btv
->type
].video_inputs
)
1715 bt848_muxsel(btv
, v
.channel
);
1716 if(v
.norm
!=VIDEO_MODE_PAL
&&v
.norm
!=VIDEO_MODE_NTSC
1717 &&v
.norm
!=VIDEO_MODE_SECAM
)
1719 btv
->win
.norm
= v
.norm
;
1721 bt848_set_winsize(btv
);
1722 btv
->channel
=v
.channel
;
1727 struct video_tuner v
;
1728 if(copy_from_user(&v
,arg
,sizeof(v
))!=0)
1730 if(v
.tuner
||btv
->channel
) /* Only tuner 0 */
1732 strcpy(v
.name
, "Television");
1734 v
.rangehigh
=0xFFFFFFFF;
1735 v
.flags
=VIDEO_TUNER_PAL
|VIDEO_TUNER_NTSC
|VIDEO_TUNER_SECAM
;
1736 if (btv
->audio_chip
== TDA9840
) {
1737 v
.flags
|= VIDEO_AUDIO_VOLUME
;
1738 v
.mode
= VIDEO_SOUND_MONO
|VIDEO_SOUND_STEREO
;
1739 v
.mode
|= VIDEO_SOUND_LANG1
|VIDEO_SOUND_LANG2
;
1741 if (btv
->audio_chip
== TDA9850
) {
1743 ALR1
= I2CRead(&(btv
->i2c
), I2C_TDA9850
|1);
1745 v
.flags
|= VIDEO_TUNER_STEREO_ON
;
1747 v
.mode
= btv
->win
.norm
;
1748 v
.signal
= (btread(BT848_DSTATUS
)&BT848_DSTATUS_HLOC
) ? 0xFFFF : 0;
1749 if(copy_to_user(arg
,&v
,sizeof(v
)))
1753 /* We have but one tuner */
1756 struct video_tuner v
;
1757 if(copy_from_user(&v
, arg
, sizeof(v
)))
1759 /* Only one channel has a tuner */
1760 if(v
.tuner
!=tvcards
[btv
->type
].tuner
)
1763 if(v
.mode
!=VIDEO_MODE_PAL
&&v
.mode
!=VIDEO_MODE_NTSC
1764 &&v
.mode
!=VIDEO_MODE_SECAM
)
1766 btv
->win
.norm
= v
.mode
;
1767 bt848_set_winsize(btv
);
1772 struct video_picture p
=btv
->picture
;
1773 if(btv
->win
.depth
==8)
1774 p
.palette
=VIDEO_PALETTE_HI240
;
1775 if(btv
->win
.depth
==15)
1776 p
.palette
=VIDEO_PALETTE_RGB555
;
1777 if(btv
->win
.depth
==16)
1778 p
.palette
=VIDEO_PALETTE_RGB565
;
1779 if(btv
->win
.depth
==24)
1780 p
.palette
=VIDEO_PALETTE_RGB24
;
1781 if(btv
->win
.depth
==32)
1782 p
.palette
=VIDEO_PALETTE_RGB32
;
1784 if(copy_to_user(arg
, &p
, sizeof(p
)))
1790 struct video_picture p
;
1792 if(copy_from_user(&p
, arg
,sizeof(p
)))
1794 /* We want -128 to 127 we get 0-65535 */
1795 bt848_bright(btv
, (p
.brightness
>>8)-128);
1796 /* 0-511 for the colour */
1797 bt848_sat_u(btv
, p
.colour
>>7);
1798 bt848_sat_v(btv
, ((p
.colour
>>7)*201L)/237);
1800 bt848_hue(btv
, (p
.hue
>>8)-128);
1802 bt848_contrast(btv
, p
.contrast
>>7);
1805 /* set palette if bpp matches */
1806 if (p
.palette
< sizeof(palette2fmt
)/sizeof(int)) {
1807 format
= palette2fmt
[p
.palette
];
1808 if (fmtbppx2
[format
&0x0f]/2 == btv
->win
.bpp
)
1809 btv
->win
.color_fmt
= format
;
1815 struct video_window vw
;
1816 struct video_clip
*vcp
= NULL
;
1819 if(copy_from_user(&vw
,arg
,sizeof(vw
)))
1822 if(vw
.flags
|| vw
.width
< 16 || vw
.height
< 16)
1827 if (btv
->win
.bpp
< 4)
1828 { /* 32-bit align start and adjust width */
1830 vw
.x
= (vw
.x
+ 3) & ~3;
1836 btv
->win
.width
=vw
.width
;
1837 btv
->win
.height
=vw
.height
;
1839 if(btv
->win
.height
>btv
->win
.cropheight
/2)
1840 btv
->win
.interlace
=1;
1842 btv
->win
.interlace
=0;
1847 bt848_set_winsize(btv
);
1852 if(vw
.clipcount
<0) {
1853 if((vcp
=vmalloc(VIDEO_CLIPMAP_SIZE
))==NULL
)
1855 if(copy_from_user(vcp
, vw
.clips
,
1856 VIDEO_CLIPMAP_SIZE
)) {
1860 } else if (vw
.clipcount
) {
1861 if((vcp
=vmalloc(sizeof(struct video_clip
)*
1862 (vw
.clipcount
))) == NULL
)
1864 if(copy_from_user(vcp
,vw
.clips
,
1865 sizeof(struct video_clip
)*
1871 make_clip_tab(btv
, vcp
, vw
.clipcount
);
1872 if (vw
.clipcount
!= 0)
1874 if(on
&& btv
->win
.vidadr
!=0)
1880 struct video_window vw
;
1881 /* Oh for a COBOL move corresponding .. */
1884 vw
.width
=btv
->win
.width
;
1885 vw
.height
=btv
->win
.height
;
1888 if(btv
->win
.interlace
)
1889 vw
.flags
|=VIDEO_WINDOW_INTERLACE
;
1890 if(copy_to_user(arg
,&vw
,sizeof(vw
)))
1897 if(copy_from_user(&v
, arg
,sizeof(v
)))
1905 if(btv
->win
.vidadr
==0 || btv
->win
.width
==0
1906 || btv
->win
.height
==0)
1914 struct video_buffer v
;
1915 v
.base
=(void *)btv
->win
.vidadr
;
1916 v
.height
=btv
->win
.sheight
;
1917 v
.width
=btv
->win
.swidth
;
1918 v
.depth
=btv
->win
.depth
;
1919 v
.bytesperline
=btv
->win
.bpl
;
1920 if(copy_to_user(arg
, &v
,sizeof(v
)))
1927 struct video_buffer v
;
1928 #if LINUX_VERSION_CODE >= 0x020100
1929 if(!capable(CAP_SYS_ADMIN
))
1934 if(copy_from_user(&v
, arg
,sizeof(v
)))
1936 if(v
.depth
!=8 && v
.depth
!=15 && v
.depth
!=16 &&
1937 v
.depth
!=24 && v
.depth
!=32 && v
.width
> 16 &&
1938 v
.height
> 16 && v
.bytesperline
> 16)
1942 if ((unsigned long)v
.base
&1)
1943 btv
->win
.vidadr
=(unsigned long)(PAGE_OFFSET
|uvirt_to_bus((unsigned long)v
.base
));
1945 btv
->win
.vidadr
=(unsigned long)v
.base
;
1947 btv
->win
.sheight
=v
.height
;
1948 btv
->win
.swidth
=v
.width
;
1949 btv
->win
.bpp
=((v
.depth
+7)&0x38)/8;
1950 btv
->win
.depth
=v
.depth
;
1951 btv
->win
.bpl
=v
.bytesperline
;
1953 DEBUG(printk("Display at %p is %d by %d, bytedepth %d, bpl %d\n",
1954 v
.base
, v
.width
,v
.height
, btv
->win
.bpp
, btv
->win
.bpl
));
1955 bt848_set_winsize(btv
);
1960 /* Will be handled higher up .. */
1965 unsigned long v
=btv
->win
.freq
;
1966 if(copy_to_user(arg
,&v
,sizeof(v
)))
1973 if(copy_from_user(&v
, arg
, sizeof(v
)))
1976 set_freq(btv
, btv
->win
.freq
);
1982 struct video_audio v
;
1984 v
.flags
&=~(VIDEO_AUDIO_MUTE
|VIDEO_AUDIO_MUTABLE
);
1985 v
.flags
|=VIDEO_AUDIO_MUTABLE
;
1986 strcpy(v
.name
,"TV");
1987 if (btv
->audio_chip
== TDA9850
) {
1989 ALR1
= I2CRead(&(btv
->i2c
), I2C_TDA9850
|1);
1990 v
.mode
= VIDEO_SOUND_MONO
;
1991 v
.mode
|= (ALR1
& 32) ? VIDEO_SOUND_STEREO
:0;
1992 v
.mode
|= (ALR1
& 64) ? VIDEO_SOUND_LANG1
:0;
1994 if (btv
->have_msp3400
)
1996 v
.flags
|=VIDEO_AUDIO_VOLUME
|
1999 i2c_control_device(&(btv
->i2c
),
2000 I2C_DRIVERID_MSP3400
,
2001 MSP_GET_VOLUME
,&(v
.volume
));
2002 i2c_control_device(&(btv
->i2c
),
2003 I2C_DRIVERID_MSP3400
,
2004 MSP_GET_BASS
,&(v
.bass
));
2005 i2c_control_device(&(btv
->i2c
),
2006 I2C_DRIVERID_MSP3400
,
2007 MSP_GET_TREBLE
,&(v
.treble
));
2008 i2c_control_device(&(btv
->i2c
),
2009 I2C_DRIVERID_MSP3400
,
2010 MSP_GET_STEREO
,&(v
.mode
));
2012 else v
.mode
= VIDEO_SOUND_MONO
;
2013 if(copy_to_user(arg
,&v
,sizeof(v
)))
2019 struct video_audio v
;
2020 if(copy_from_user(&v
,arg
, sizeof(v
)))
2022 if(v
.flags
&VIDEO_AUDIO_MUTE
)
2023 audio(btv
, AUDIO_MUTE
);
2024 /* One audio source per tuner */
2025 /* if(v.audio!=0) */
2026 /* ADSTech TV card has more than one */
2027 if(v
.audio
<0 || v
.audio
>= tvcards
[btv
->type
].audio_inputs
)
2029 bt848_muxsel(btv
,v
.audio
);
2030 if(!(v
.flags
&VIDEO_AUDIO_MUTE
))
2031 audio(btv
, AUDIO_UNMUTE
);
2032 if (btv
->audio_chip
== TDA9850
) {
2033 unsigned char con3
= 0;
2034 if (v
.mode
& VIDEO_SOUND_LANG1
)
2035 con3
= 0x80; /* sap */
2036 if (v
.mode
& VIDEO_SOUND_STEREO
)
2037 con3
= 0x40; /* stereo */
2038 I2CWrite(&(btv
->i2c
), I2C_TDA9850
,
2039 TDA9850_CON3
, con3
, 1);
2042 /* PT2254A programming Jon Tombs, jon@gte.esi.us.es */
2043 if (btv
->type
== BTTV_WINVIEW_601
) {
2044 int bits_out
, loops
, vol
, data
;
2046 /* 32 levels logarithmic */
2047 vol
= 32 - ((v
.volume
>>11));
2049 bits_out
= (PT2254_DBS_IN_2
>>(vol
%5));
2051 bits_out
|= (PT2254_DBS_IN_10
>>(vol
/5));
2052 bits_out
|= PT2254_L_CHANEL
| PT2254_R_CHANEL
;
2053 data
= btread(BT848_GPIO_DATA
);
2054 data
&= ~(WINVIEW_PT2254_CLK
| WINVIEW_PT2254_DATA
|
2055 WINVIEW_PT2254_STROBE
);
2056 for (loops
= 17; loops
>= 0 ; loops
--) {
2057 if (bits_out
& (1<<loops
))
2058 data
|= WINVIEW_PT2254_DATA
;
2060 data
&= ~WINVIEW_PT2254_DATA
;
2061 btwrite(data
, BT848_GPIO_DATA
);
2063 data
|= WINVIEW_PT2254_CLK
;
2064 btwrite(data
, BT848_GPIO_DATA
);
2066 data
&= ~WINVIEW_PT2254_CLK
;
2067 btwrite(data
, BT848_GPIO_DATA
);
2069 data
|= WINVIEW_PT2254_STROBE
;
2070 data
&= ~WINVIEW_PT2254_DATA
;
2071 btwrite(data
, BT848_GPIO_DATA
);
2073 data
&= ~WINVIEW_PT2254_STROBE
;
2074 btwrite(data
, BT848_GPIO_DATA
);
2076 if (btv
->have_msp3400
)
2078 i2c_control_device(&(btv
->i2c
),
2079 I2C_DRIVERID_MSP3400
,
2080 MSP_SET_VOLUME
,&(v
.volume
));
2081 i2c_control_device(&(btv
->i2c
),
2082 I2C_DRIVERID_MSP3400
,
2083 MSP_SET_BASS
,&(v
.bass
));
2084 i2c_control_device(&(btv
->i2c
),
2085 I2C_DRIVERID_MSP3400
,
2086 MSP_SET_TREBLE
,&(v
.treble
));
2087 i2c_control_device(&(btv
->i2c
),
2088 I2C_DRIVERID_MSP3400
,
2089 MSP_SET_STEREO
,&(v
.mode
));
2096 if(copy_from_user((void *)&i
,arg
,sizeof(int)))
2101 switch (btv
->frame_stat
[i
]) {
2102 case GBUFFER_UNUSED
:
2104 case GBUFFER_GRABBING
:
2105 while(btv
->frame_stat
[i
]==GBUFFER_GRABBING
) {
2106 interruptible_sleep_on(&btv
->capq
);
2107 if(signal_pending(current
))
2112 btv
->frame_stat
[i
] = GBUFFER_UNUSED
;
2118 #if LINUX_VERSION_CODE >= 0x020100
2119 if(!capable(CAP_SYS_ADMIN
))
2124 if(copy_from_user((void *) eedata
, (void *) arg
, 256))
2126 writeee(&(btv
->i2c
), eedata
);
2130 #if LINUX_VERSION_CODE >= 0x020100
2131 if(!capable(CAP_SYS_ADMIN
))
2136 readee(&(btv
->i2c
), eedata
);
2137 if(copy_to_user((void *) arg
, (void *) eedata
, 256))
2142 if(copy_to_user((void *) arg
, (void *) &btv
->last_field
,
2143 sizeof(btv
->last_field
)))
2148 struct bttv_pll_info p
;
2149 #if LINUX_VERSION_CODE >= 0x020100
2150 if(!capable(CAP_SYS_ADMIN
))
2155 if(copy_from_user(&p
, (void *) arg
, sizeof(btv
->pll
)))
2157 btv
->pll
.pll_ifreq
= p
.pll_ifreq
;
2158 btv
->pll
.pll_ofreq
= p
.pll_ofreq
;
2159 btv
->pll
.pll_crystal
= p
.pll_crystal
;
2163 case VIDIOCMCAPTURE
:
2165 struct video_mmap vm
;
2166 if(copy_from_user((void *) &vm
, (void *) arg
, sizeof(vm
)))
2168 if (btv
->frame_stat
[vm
.frame
] == GBUFFER_GRABBING
)
2170 return vgrab(btv
, &vm
);
2175 struct video_mbuf vm
;
2176 memset(&vm
, 0 , sizeof(vm
));
2177 vm
.size
=BTTV_MAX_FBUF
*2;
2180 vm
.offsets
[1]=BTTV_MAX_FBUF
;
2181 if(copy_to_user((void *)arg
, (void *)&vm
, sizeof(vm
)))
2188 struct video_unit vu
;
2189 vu
.video
=btv
->video_dev
.minor
;
2190 vu
.vbi
=btv
->vbi_dev
.minor
;
2191 if(btv
->radio_dev
.minor
!=-1)
2192 vu
.radio
=btv
->radio_dev
.minor
;
2194 vu
.radio
=VIDEO_NO_UNIT
;
2195 vu
.audio
=VIDEO_NO_UNIT
;
2196 if(btv
->have_msp3400
)
2198 i2c_control_device(&(btv
->i2c
), I2C_DRIVERID_MSP3400
,
2199 MSP_GET_UNIT
, &vu
.audio
);
2201 vu
.teletext
=VIDEO_NO_UNIT
;
2202 if(copy_to_user((void *)arg
, (void *)&vu
, sizeof(vu
)))
2209 tvnorms
[0].scaledtwidth
=1135-BURSTOFFSET
-2;
2210 tvnorms
[0].hdelayx1
=186-BURSTOFFSET
;
2214 case BTTV_BURST_OFF
:
2216 tvnorms
[0].scaledtwidth
=1135;
2217 tvnorms
[0].hdelayx1
=186;
2223 return BTTV_VERSION_CODE
;
2228 /* return picture;*/
2233 return -ENOIOCTLCMD
;
2238 static int bttv_init_done(struct video_device
*dev
)
2244 * This maps the vmalloced and reserved fbuffer to user space.
2247 * - PAGE_READONLY should suffice!?
2248 * - remap_page_range is kind of inefficient for page by page remapping.
2249 * But e.g. pte_alloc() does not work in modules ... :-(
2252 static int bttv_mmap(struct video_device
*dev
, const char *adr
, unsigned long size
)
2254 struct bttv
*btv
=(struct bttv
*)dev
;
2255 unsigned long start
=(unsigned long) adr
;
2256 unsigned long page
,pos
;
2258 if (size
>2*BTTV_MAX_FBUF
)
2262 if(fbuffer_alloc(btv
))
2265 pos
=(unsigned long) btv
->fbuffer
;
2268 page
= kvirt_to_phys(pos
);
2269 if (remap_page_range(start
, page
, PAGE_SIZE
, PAGE_SHARED
))
2278 static struct video_device bttv_template
=
2281 VID_TYPE_TUNER
|VID_TYPE_CAPTURE
|VID_TYPE_OVERLAY
|VID_TYPE_TELETEXT
,
2287 #if LINUX_VERSION_CODE >= 0x020100
2299 static long vbi_read(struct video_device
*v
, char *buf
, unsigned long count
,
2302 struct bttv
*btv
=(struct bttv
*)(v
-2);
2306 while (todo
&& todo
>(q
=VBIBUF_SIZE
-btv
->vbip
))
2308 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, q
))
2314 if (todo
&& q
==VBIBUF_SIZE
-btv
->vbip
)
2320 return -EWOULDBLOCK
;
2323 interruptible_sleep_on(&btv
->vbiq
);
2325 if(signal_pending(current
))
2336 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, todo
))
2343 #if LINUX_VERSION_CODE >= 0x020100
2344 static unsigned int vbi_poll(struct video_device
*dev
, struct file
*file
,
2347 struct bttv
*btv
=(struct bttv
*)(dev
-2);
2348 unsigned int mask
= 0;
2350 poll_wait(file
, &btv
->vbiq
, wait
);
2352 if (btv
->vbip
< VBIBUF_SIZE
)
2353 mask
|= (POLLIN
| POLLRDNORM
);
2359 static int vbi_open(struct video_device
*dev
, int flags
)
2361 struct bttv
*btv
=(struct bttv
*)(dev
-2);
2363 btv
->vbip
=VBIBUF_SIZE
;
2365 bt848_set_risc_jmps(btv
);
2371 static void vbi_close(struct video_device
*dev
)
2373 struct bttv
*btv
=(struct bttv
*)(dev
-2);
2376 bt848_set_risc_jmps(btv
);
2382 static int vbi_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
2387 static struct video_device vbi_template
=
2390 VID_TYPE_CAPTURE
|VID_TYPE_TELETEXT
,
2396 #if LINUX_VERSION_CODE >= 0x020100
2400 NULL
, /* no mmap yet */
2408 static int radio_open(struct video_device
*dev
, int flags
)
2410 struct bttv
*btv
= (struct bttv
*)(dev
-1);
2415 set_freq(btv
,400*16);
2417 bt848_muxsel(btv
,0);
2418 audio(btv
, AUDIO_UNMUTE
);
2424 static void radio_close(struct video_device
*dev
)
2426 struct bttv
*btv
=(struct bttv
*)(dev
-1);
2430 /*audio(btv, AUDIO_MUTE);*/
2434 static long radio_read(struct video_device
*v
, char *buf
, unsigned long count
, int nonblock
)
2439 static int radio_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
2441 struct bttv
*btv
=(struct bttv
*)(dev
-1);
2445 struct video_capability v
;
2446 strcpy(v
.name
,btv
->video_dev
.name
);
2447 v
.type
= VID_TYPE_TUNER
;
2450 /* No we don't do pictures */
2455 if (copy_to_user(arg
, &v
, sizeof(v
)))
2462 struct video_tuner v
;
2463 if(copy_from_user(&v
,arg
,sizeof(v
))!=0)
2465 if(v
.tuner
||btv
->channel
) /* Only tuner 0 */
2467 strcpy(v
.name
, "Radio");
2468 v
.rangelow
=(int)(87.5*16);
2469 v
.rangehigh
=(int)(108*16);
2470 v
.flags
= 0; /* XXX */
2471 v
.mode
= 0; /* XXX */
2472 if(copy_to_user(arg
,&v
,sizeof(v
)))
2478 struct video_tuner v
;
2479 if(copy_from_user(&v
, arg
, sizeof(v
)))
2481 /* Only channel 0 has a tuner */
2482 if(v
.tuner
!=0 || btv
->channel
)
2484 /* XXX anything to do ??? */
2491 bttv_ioctl((struct video_device
*)btv
,cmd
,arg
);
2494 return -ENOIOCTLCMD
;
2499 static struct video_device radio_template
=
2506 radio_read
, /* just returns -EINVAL */
2507 bttv_write
, /* just returns -EINVAL */
2508 #if LINUX_VERSION_CODE >= 0x020100
2513 bttv_init_done
, /* just returns 0 */
2522 unsigned short vendor
, device
;
2527 static struct vidbases vbs
[] = {
2528 { PCI_VENDOR_ID_ALLIANCE
, PCI_DEVICE_ID_ALLIANCE_AT3D
,
2529 "Alliance AT3D", PCI_BASE_ADDRESS_0
},
2530 { PCI_VENDOR_ID_ATI
, PCI_DEVICE_ID_ATI_215CT222
,
2531 "ATI MACH64 CT", PCI_BASE_ADDRESS_0
},
2532 { PCI_VENDOR_ID_ATI
, PCI_DEVICE_ID_ATI_210888GX
,
2533 "ATI MACH64 Winturbo", PCI_BASE_ADDRESS_0
},
2534 { PCI_VENDOR_ID_ATI
, PCI_DEVICE_ID_ATI_215GT
,
2535 "ATI MACH64 GT", PCI_BASE_ADDRESS_0
},
2536 { PCI_VENDOR_ID_CIRRUS
, 0, "Cirrus Logic", PCI_BASE_ADDRESS_0
},
2537 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TGA
,
2538 "DEC DC21030", PCI_BASE_ADDRESS_0
},
2539 { PCI_VENDOR_ID_MATROX
, PCI_DEVICE_ID_MATROX_MIL
,
2540 "Matrox Millennium", PCI_BASE_ADDRESS_1
},
2541 { PCI_VENDOR_ID_MATROX
, PCI_DEVICE_ID_MATROX_MIL_2
,
2542 "Matrox Millennium II", PCI_BASE_ADDRESS_0
},
2543 { PCI_VENDOR_ID_MATROX
, PCI_DEVICE_ID_MATROX_MIL_2_AGP
,
2544 "Matrox Millennium II AGP", PCI_BASE_ADDRESS_0
},
2545 { PCI_VENDOR_ID_MATROX
, 0x051a, "Matrox Mystique", PCI_BASE_ADDRESS_1
},
2546 { PCI_VENDOR_ID_MATROX
, 0x0521, "Matrox G200", PCI_BASE_ADDRESS_0
},
2547 { PCI_VENDOR_ID_N9
, PCI_DEVICE_ID_N9_I128
,
2548 "Number Nine Imagine 128", PCI_BASE_ADDRESS_0
},
2549 { PCI_VENDOR_ID_N9
, PCI_DEVICE_ID_N9_I128_2
,
2550 "Number Nine Imagine 128 Series 2", PCI_BASE_ADDRESS_0
},
2551 { PCI_VENDOR_ID_S3
, 0, "S3", PCI_BASE_ADDRESS_0
},
2552 { PCI_VENDOR_ID_TSENG
, 0, "TSENG", PCI_BASE_ADDRESS_0
},
2553 { PCI_VENDOR_ID_NVIDIA_SGS
, PCI_DEVICE_ID_NVIDIA_SGS_RIVA128
,
2554 "Riva128", PCI_BASE_ADDRESS_1
},
2558 /* DEC TGA offsets stolen from XFree-3.2 */
2560 static uint dec_offsets
[4] = {
2567 #define NR_CARDS (sizeof(vbs)/sizeof(struct vidbases))
2569 /* Scan for PCI display adapter
2570 if more than one card is present the last one is used for now */
2572 #if LINUX_VERSION_CODE >= 0x020100
2574 static int find_vga(void)
2576 unsigned short badr
;
2577 int found
= 0, i
, tga_type
;
2578 unsigned int vidadr
=0;
2579 struct pci_dev
*dev
;
2582 for (dev
= pci_devices
; dev
!= NULL
; dev
= dev
->next
)
2584 if (dev
->class != PCI_CLASS_NOT_DEFINED_VGA
&&
2585 ((dev
->class) >> 16 != PCI_BASE_CLASS_DISPLAY
))
2589 if (PCI_FUNC(dev
->devfn
) != 0)
2593 printk(KERN_INFO
"bttv: PCI display adapter: ");
2594 for (i
=0; i
<NR_CARDS
; i
++)
2596 if (dev
->vendor
== vbs
[i
].vendor
)
2599 if (vbs
[i
].device
!=dev
->device
)
2601 printk("%s.\n", vbs
[i
].name
);
2608 printk(KERN_ERR
"bttv: Unknown video memory base address.\n");
2611 pci_read_config_dword(dev
, badr
, &vidadr
);
2612 if (vidadr
& PCI_BASE_ADDRESS_SPACE_IO
)
2614 printk(KERN_ERR
"bttv: Memory seems to be I/O memory.\n");
2615 printk(KERN_ERR
"bttv: Check entry for your card type in bttv.c vidbases struct.\n");
2618 vidadr
&= PCI_BASE_ADDRESS_MEM_MASK
;
2621 printk(KERN_ERR
"bttv: Memory @ 0, must be something wrong!");
2625 if (dev
->vendor
== PCI_VENDOR_ID_DEC
&&
2626 dev
->device
== PCI_DEVICE_ID_DEC_TGA
)
2628 tga_type
= (readl((unsigned long)vidadr
) >> 12) & 0x0f;
2629 if (tga_type
!= 0 && tga_type
!= 1 && tga_type
!= 3)
2631 printk(KERN_ERR
"bttv: TGA type (0x%x) unrecognized!\n", tga_type
);
2634 vidadr
+=dec_offsets
[tga_type
];
2636 DEBUG(printk(KERN_DEBUG
"bttv: memory @ 0x%08x, ", vidadr
));
2637 DEBUG(printk(KERN_DEBUG
"devfn: 0x%04x.\n", dev
->devfn
));
2644 printk(KERN_INFO
"bttv: Video memory override: 0x%08x\n", vidadr
);
2647 for (i
=0; i
<BTTV_MAX
; i
++)
2648 bttvs
[i
].win
.vidadr
=vidadr
;
2654 static int find_vga(void)
2656 unsigned int devfn
, class, vendev
;
2657 unsigned short vendor
, device
, badr
;
2658 int found
=0, bus
=0, i
, tga_type
;
2659 unsigned int vidadr
=0;
2662 for (devfn
= 0; devfn
< 0xff; devfn
++)
2664 if (PCI_FUNC(devfn
) != 0)
2666 pcibios_read_config_dword(bus
, devfn
, PCI_VENDOR_ID
, &vendev
);
2667 if (vendev
== 0xffffffff || vendev
== 0x00000000)
2669 pcibios_read_config_word(bus
, devfn
, PCI_VENDOR_ID
, &vendor
);
2670 pcibios_read_config_word(bus
, devfn
, PCI_DEVICE_ID
, &device
);
2671 pcibios_read_config_dword(bus
, devfn
, PCI_CLASS_REVISION
, &class);
2672 class = class >> 16;
2673 /* if (class == PCI_CLASS_DISPLAY_VGA) {*/
2674 if ((class>>8) == PCI_BASE_CLASS_DISPLAY
||
2675 /* Number 9 GXE64Pro needs this */
2676 class == PCI_CLASS_NOT_DEFINED_VGA
)
2679 printk(KERN_INFO
"bttv: PCI display adapter: ");
2680 for (i
=0; i
<NR_CARDS
; i
++)
2682 if (vendor
==vbs
[i
].vendor
)
2685 if (vbs
[i
].device
!=device
)
2687 printk("%s.\n", vbs
[i
].name
);
2693 printk("UNKNOWN.\n");
2696 printk(KERN_ERR
"bttv: Unknown video memory base address.\n");
2699 pcibios_read_config_dword(bus
, devfn
, badr
, &vidadr
);
2700 if (vidadr
& PCI_BASE_ADDRESS_SPACE_IO
)
2702 printk(KERN_ERR
"bttv: Memory seems to be I/O memory.\n");
2703 printk(KERN_ERR
"bttv: Check entry for your card type in bttv.c vidbases struct.\n");
2706 vidadr
&= PCI_BASE_ADDRESS_MEM_MASK
;
2709 printk(KERN_ERR
"bttv: Memory @ 0, must be something wrong!\n");
2713 if (vendor
==PCI_VENDOR_ID_DEC
)
2714 if (device
==PCI_DEVICE_ID_DEC_TGA
)
2716 tga_type
= (readl((unsigned long)vidadr
) >> 12) & 0x0f;
2717 if (tga_type
!= 0 && tga_type
!= 1 && tga_type
!= 3)
2719 printk(KERN_ERR
"bttv: TGA type (0x%x) unrecognized!\n", tga_type
);
2722 vidadr
+=dec_offsets
[tga_type
];
2725 DEBUG(printk(KERN_DEBUG
"bttv: memory @ 0x%08x, ", vidadr
));
2726 DEBUG(printk(KERN_DEBUG
"devfn: 0x%04x.\n", devfn
));
2733 if (vidmem
< 0x1000)
2737 printk(KERN_INFO
"bttv: Video memory override: 0x%08x\n", vidadr
);
2740 for (i
=0; i
<BTTV_MAX
; i
++)
2741 bttvs
[i
].win
.vidadr
=vidadr
;
2748 #define TRITON_PCON 0x50
2749 #define TRITON_BUS_CONCURRENCY (1<<0)
2750 #define TRITON_STREAMING (1<<1)
2751 #define TRITON_WRITE_BURST (1<<2)
2752 #define TRITON_PEER_CONCURRENCY (1<<3)
2755 #if LINUX_VERSION_CODE >= 0x020100
2757 static void handle_chipset(void)
2759 struct pci_dev
*dev
= NULL
;
2761 /* Just in case some nut set this to something dangerous */
2763 triton1
=BT848_INT_ETBF
;
2765 while ((dev
= pci_find_device(PCI_VENDOR_ID_SI
, PCI_DEVICE_ID_SI_496
, dev
)))
2767 /* Beware the SiS 85C496 my friend - rev 49 don't work with a bttv */
2768 printk(KERN_WARNING
"BT848 and SIS 85C496 chipset don't always work together.\n");
2773 while ((dev
= pci_find_device(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82441
, dev
)))
2776 pci_read_config_byte(dev
, 0x53, &b
);
2777 DEBUG(printk(KERN_INFO
"bttv: Host bridge: 82441FX Natoma, "));
2778 DEBUG(printk("bufcon=0x%02x\n",b
));
2781 while ((dev
= pci_find_device(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82437
, dev
)))
2786 printk(KERN_INFO
"bttv: Host bridge 82437FX Triton PIIX\n");
2787 triton1
=BT848_INT_ETBF
;
2790 /* The ETBF bit SHOULD make all this unnecessary */
2791 /* 430FX (Triton I) freezes with bus concurrency on -> switch it off */
2793 pci_read_config_byte(dev
, TRITON_PCON
, &b
);
2795 DEBUG(printk(KERN_DEBUG
"bttv: 82437FX: PCON: 0x%x\n",b
));
2796 if(!(b
& TRITON_BUS_CONCURRENCY
))
2798 printk(KERN_WARNING
"bttv: 82437FX: disabling bus concurrency\n");
2799 b
|= TRITON_BUS_CONCURRENCY
;
2801 if(b
& TRITON_PEER_CONCURRENCY
)
2803 printk(KERN_WARNING
"bttv: 82437FX: disabling peer concurrency\n");
2804 b
&= ~TRITON_PEER_CONCURRENCY
;
2806 if(!(b
& TRITON_STREAMING
))
2808 printk(KERN_WARNING
"bttv: 82437FX: disabling streaming\n");
2809 b
|= TRITON_STREAMING
;
2814 pci_write_config_byte(dev
, TRITON_PCON
, b
);
2815 printk(KERN_DEBUG
"bttv: 82437FX: PCON changed to: 0x%x\n",b
);
2821 static void handle_chipset(void)
2825 for (index
= 0; index
< 8; index
++)
2827 unsigned char bus
, devfn
;
2830 /* Beware the SiS 85C496 my friend - rev 49 don't work with a bttv */
2832 if (!pcibios_find_device(PCI_VENDOR_ID_SI
,
2833 PCI_DEVICE_ID_SI_496
,
2834 index
, &bus
, &devfn
))
2836 printk(KERN_WARNING
"BT848 and SIS 85C496 chipset don't always work together.\n");
2839 if (!pcibios_find_device(PCI_VENDOR_ID_INTEL
,
2840 PCI_DEVICE_ID_INTEL_82441
,
2841 index
, &bus
, &devfn
))
2843 pcibios_read_config_byte(bus
, devfn
, 0x53, &b
);
2844 DEBUG(printk(KERN_INFO
"bttv: Host bridge: 82441FX Natoma, "));
2845 DEBUG(printk("bufcon=0x%02x\n",b
));
2848 if (!pcibios_find_device(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82437
,
2849 index
, &bus
, &devfn
))
2851 printk(KERN_INFO
"bttv: Host bridge 82437FX Triton PIIX\n");
2852 triton1
=BT848_INT_ETBF
;
2855 /* The ETBF bit SHOULD make all this unnecessary */
2856 /* 430FX (Triton I) freezes with bus concurrency on -> switch it off */
2860 pcibios_read_config_byte(bus
, devfn
, TRITON_PCON
, &b
);
2862 DEBUG(printk(KERN_DEBUG
"bttv: 82437FX: PCON: 0x%x\n",b
));
2864 if(!(b
& TRITON_BUS_CONCURRENCY
))
2866 printk(KERN_WARNING
"bttv: 82437FX: disabling bus concurrency\n");
2867 b
|= TRITON_BUS_CONCURRENCY
;
2870 if(b
& TRITON_PEER_CONCURRENCY
)
2872 printk(KERN_WARNING
"bttv: 82437FX: disabling peer concurrency\n");
2873 b
&= ~TRITON_PEER_CONCURRENCY
;
2875 if(!(b
& TRITON_STREAMING
))
2877 printk(KERN_WARNING
"bttv: 82437FX: disabling streaming\n");
2878 b
|= TRITON_STREAMING
;
2883 pcibios_write_config_byte(bus
, devfn
, TRITON_PCON
, b
);
2884 printk(KERN_DEBUG
"bttv: 82437FX: PCON changed to: 0x%x\n",b
);
2893 static void init_tea6300(struct i2c_bus
*bus
)
2895 I2CWrite(bus
, I2C_TEA6300
, TEA6300_VL
, 0x35, 1); /* volume left 0dB */
2896 I2CWrite(bus
, I2C_TEA6300
, TEA6300_VR
, 0x35, 1); /* volume right 0dB */
2897 I2CWrite(bus
, I2C_TEA6300
, TEA6300_BA
, 0x07, 1); /* bass 0dB */
2898 I2CWrite(bus
, I2C_TEA6300
, TEA6300_TR
, 0x07, 1); /* treble 0dB */
2899 I2CWrite(bus
, I2C_TEA6300
, TEA6300_FA
, 0x0f, 1); /* fader off */
2900 I2CWrite(bus
, I2C_TEA6300
, TEA6300_SW
, 0x01, 1); /* mute off input A */
2903 static void init_tda8425(struct i2c_bus
*bus
)
2905 I2CWrite(bus
, I2C_TDA8425
, TDA8425_VL
, 0xFC, 1); /* volume left 0dB */
2906 I2CWrite(bus
, I2C_TDA8425
, TDA8425_VR
, 0xFC, 1); /* volume right 0dB */
2907 I2CWrite(bus
, I2C_TDA8425
, TDA8425_BA
, 0xF6, 1); /* bass 0dB */
2908 I2CWrite(bus
, I2C_TDA8425
, TDA8425_TR
, 0xF6, 1); /* treble 0dB */
2909 I2CWrite(bus
, I2C_TDA8425
, TDA8425_S1
, 0xCE, 1); /* mute off */
2912 static void init_tda9840(struct i2c_bus
*bus
)
2914 I2CWrite(bus
, I2C_TDA9840
, TDA9840_SW
, 0x2A, 1); /* Sound mode switching */
2917 static void init_tda9850(struct i2c_bus
*bus
)
2919 I2CWrite(bus
, I2C_TDA9850
, TDA9850_CON1
, 0x08, 1); /* noise threshold st */
2920 I2CWrite(bus
, I2C_TDA9850
, TDA9850_CON2
, 0x08, 1); /* noise threshold sap */
2921 I2CWrite(bus
, I2C_TDA9850
, TDA9850_CON3
, 0x40, 1); /* stereo mode */
2922 I2CWrite(bus
, I2C_TDA9850
, TDA9850_CON4
, 0x07, 1); /* 0 dB input gain?*/
2923 I2CWrite(bus
, I2C_TDA9850
, TDA9850_ALI1
, 0x10, 1); /* wideband alignment? */
2924 I2CWrite(bus
, I2C_TDA9850
, TDA9850_ALI2
, 0x10, 1); /* spectral alignment? */
2925 I2CWrite(bus
, I2C_TDA9850
, TDA9850_ALI3
, 0x03, 1);
2930 /* Figure out card and tuner type */
2932 static void idcard(int i
)
2934 struct bttv
*btv
= &bttvs
[i
];
2936 btwrite(0, BT848_GPIO_OUT_EN
);
2937 DEBUG(printk(KERN_DEBUG
"bttv%d: GPIO: 0x%08x\n", i
, btread(BT848_GPIO_DATA
)));
2939 /* Default the card to the user-selected one. */
2941 btv
->tuner_type
=-1; /* use default tuner type */
2943 /* If we were asked to auto-detect, then do so!
2944 Right now this will only recognize Miro, Hauppauge or STB
2946 if (btv
->type
== BTTV_UNKNOWN
)
2948 if (I2CRead(&(btv
->i2c
), I2C_HAUPEE
)>=0)
2951 btv
->type
=BTTV_HAUPPAUGE878
;
2953 btv
->type
=BTTV_HAUPPAUGE
;
2955 } else if (I2CRead(&(btv
->i2c
), I2C_STBEE
)>=0) {
2958 if (I2CRead(&(btv
->i2c
), 0x80)>=0) /* check for msp34xx */
2959 btv
->type
= BTTV_MIROPRO
;
2961 btv
->type
=BTTV_MIRO
;
2965 /* board specific initialisations */
2966 if (btv
->type
== BTTV_MIRO
|| btv
->type
== BTTV_MIROPRO
) {
2967 /* auto detect tuner for MIRO cards */
2968 btv
->tuner_type
=((btread(BT848_GPIO_DATA
)>>10)-1)&7;
2970 if (btv
->type
== BTTV_HAUPPAUGE
|| btv
->type
== BTTV_HAUPPAUGE878
) {
2971 hauppauge_msp_reset(btv
);
2972 hauppauge_eeprom(&(btv
->i2c
));
2973 if (btv
->type
== BTTV_HAUPPAUGE878
) {
2974 /* all bt878 hauppauge boards use this ... */
2975 btv
->pll
.pll_ifreq
=28636363;
2976 btv
->pll
.pll_crystal
=BT848_IFORM_XT0
;
2980 if (btv
->type
== BTTV_PIXVIEWPLAYTV
) {
2981 btv
->pll
.pll_ifreq
=28636363;
2982 btv
->pll
.pll_crystal
=BT848_IFORM_XT0
;
2985 if(btv
->type
==BTTV_AVERMEDIA98
)
2987 btv
->pll
.pll_ifreq
=28636363;
2988 btv
->pll
.pll_crystal
=BT848_IFORM_XT0
;
2991 if (btv
->have_tuner
&& btv
->tuner_type
!= -1)
2992 i2c_control_device(&(btv
->i2c
),
2994 TUNER_SET_TYPE
,&btv
->tuner_type
);
2997 if (I2CRead(&(btv
->i2c
), I2C_TDA9840
) >=0)
2999 btv
->audio_chip
= TDA9840
;
3000 printk(KERN_INFO
"bttv%d: audio chip: TDA9840\n", btv
->nr
);
3003 if (I2CRead(&(btv
->i2c
), I2C_TDA9850
) >=0)
3005 btv
->audio_chip
= TDA9850
;
3006 printk(KERN_INFO
"bttv%d: audio chip: TDA9850\n",btv
->nr
);
3009 if (I2CRead(&(btv
->i2c
), I2C_TDA8425
) >=0)
3011 btv
->audio_chip
= TDA8425
;
3012 printk(KERN_INFO
"bttv%d: audio chip: TDA8425\n",btv
->nr
);
3015 switch(btv
->audio_chip
)
3018 init_tda9850(&(btv
->i2c
));
3021 init_tda9840(&(btv
->i2c
));
3024 init_tda8425(&(btv
->i2c
));
3028 if (I2CRead(&(btv
->i2c
), I2C_TEA6300
) >=0)
3030 printk(KERN_INFO
"bttv%d: fader chip: TEA6300\n",btv
->nr
);
3031 btv
->audio_chip
= TEA6300
;
3032 init_tea6300(&(btv
->i2c
));
3034 printk(KERN_INFO
"bttv%d: NO fader chip: TEA6300\n",btv
->nr
);
3036 printk(KERN_INFO
"bttv%d: model: ",btv
->nr
);
3038 sprintf(btv
->video_dev
.name
,"BT%d",btv
->id
);
3043 strcat(btv
->video_dev
.name
,
3044 (btv
->type
== BTTV_MIRO
) ? "(Miro)" : "(Miro pro)");
3046 case BTTV_HAUPPAUGE
:
3047 strcat(btv
->video_dev
.name
,"(Hauppauge old)");
3049 case BTTV_HAUPPAUGE878
:
3050 strcat(btv
->video_dev
.name
,"(Hauppauge new)");
3053 strcat(btv
->video_dev
.name
,"(STB)");
3056 strcat(btv
->video_dev
.name
,"(Intel)");
3059 strcat(btv
->video_dev
.name
,"(Diamond)");
3061 case BTTV_AVERMEDIA
:
3062 strcat(btv
->video_dev
.name
,"(AVerMedia)");
3064 case BTTV_MATRIX_VISION
:
3065 strcat(btv
->video_dev
.name
,"(MATRIX-Vision)");
3067 case BTTV_AVERMEDIA98
:
3068 strcat(btv
->video_dev
.name
,"(AVerMedia TVCapture 98)");
3071 strcpy(btv
->video_dev
.name
,"BT848(Aimslab-VHX)");
3073 case BTTV_WINVIEW_601
:
3074 strcpy(btv
->video_dev
.name
,"BT848(Leadtek WinView 601)");
3077 printk("%s\n",btv
->video_dev
.name
);
3078 audio(btv
, AUDIO_MUTE
);
3083 static void bt848_set_risc_jmps(struct bttv
*btv
)
3087 /* Sync to start of odd field */
3088 btv
->risc_jmp
[0]=BT848_RISC_SYNC
|BT848_RISC_RESYNC
|BT848_FIFO_STATUS_VRE
;
3091 /* Jump to odd vbi sub */
3092 btv
->risc_jmp
[2]=BT848_RISC_JUMP
|(0x5<<20);
3094 btv
->risc_jmp
[3]=virt_to_bus(btv
->vbi_odd
);
3096 btv
->risc_jmp
[3]=virt_to_bus(btv
->risc_jmp
+4);
3098 /* Jump to odd sub */
3099 btv
->risc_jmp
[4]=BT848_RISC_JUMP
|(0x6<<20);
3101 btv
->risc_jmp
[5]=virt_to_bus(btv
->risc_odd
);
3103 btv
->risc_jmp
[5]=virt_to_bus(btv
->risc_jmp
+6);
3106 /* Sync to start of even field */
3107 btv
->risc_jmp
[6]=BT848_RISC_SYNC
|BT848_RISC_RESYNC
|BT848_FIFO_STATUS_VRO
;
3110 /* Jump to even vbi sub */
3111 btv
->risc_jmp
[8]=BT848_RISC_JUMP
;
3113 btv
->risc_jmp
[9]=virt_to_bus(btv
->vbi_even
);
3115 btv
->risc_jmp
[9]=virt_to_bus(btv
->risc_jmp
+10);
3117 /* Jump to even sub */
3118 btv
->risc_jmp
[10]=BT848_RISC_JUMP
|(8<<20);
3120 btv
->risc_jmp
[11]=virt_to_bus(btv
->risc_even
);
3122 btv
->risc_jmp
[11]=virt_to_bus(btv
->risc_jmp
+12);
3124 btv
->risc_jmp
[12]=BT848_RISC_JUMP
;
3125 btv
->risc_jmp
[13]=virt_to_bus(btv
->risc_jmp
);
3127 /* enable capturing */
3128 btaor(flags
, ~0x0f, BT848_CAP_CTL
);
3135 static int init_bt848(int i
)
3137 struct bttv
*btv
= &bttvs
[i
];
3141 /* reset the bt848 */
3142 btwrite(0, BT848_SRESET
);
3143 DEBUG(printk(KERN_DEBUG
"bttv%d: bt848_mem: 0x%08x\n",i
,(unsigned int) btv
->bt848_mem
));
3145 /* default setup for max. PAL size in a 1024xXXX hicolor framebuffer */
3146 btv
->win
.norm
=0; /* change this to 1 for NTSC, 2 for SECAM */
3147 btv
->win
.interlace
=1;
3150 btv
->win
.width
=768; /* 640 */
3151 btv
->win
.height
=576; /* 480 */
3152 btv
->win
.cropwidth
=768; /* 640 */
3153 btv
->win
.cropheight
=576; /* 480 */
3158 btv
->win
.color_fmt
=BT848_COLOR_FMT_RGB16
;
3159 btv
->win
.bpl
=1024*btv
->win
.bpp
;
3160 btv
->win
.swidth
=1024;
3161 btv
->win
.sheight
=768;
3174 btv
->field
=btv
->last_field
=0;
3175 /* cevans - prevents panic if initialization bails due to memory
3178 btv
->video_dev
.minor
= -1;
3179 btv
->vbi_dev
.minor
= -1;
3180 btv
->radio_dev
.minor
= -1;
3183 memcpy(&(btv
->i2c
),&bttv_i2c_bus_template
,sizeof(struct i2c_bus
));
3184 sprintf(btv
->i2c
.name
,"bt848-%d",i
);
3185 btv
->i2c
.data
= btv
;
3187 if (!(btv
->risc_odd
=(unsigned int *) kmalloc(RISCMEM_LEN
/2, GFP_KERNEL
)))
3189 if (!(btv
->risc_even
=(unsigned int *) kmalloc(RISCMEM_LEN
/2, GFP_KERNEL
)))
3191 if (!(btv
->risc_jmp
=(unsigned int *) kmalloc(2048, GFP_KERNEL
)))
3193 DEBUG(printk(KERN_DEBUG
"risc_jmp: %p\n",btv
->risc_jmp
));
3194 btv
->vbi_odd
=btv
->risc_jmp
+16;
3195 btv
->vbi_even
=btv
->vbi_odd
+256;
3196 btv
->bus_vbi_odd
=virt_to_bus(btv
->risc_jmp
+12);
3197 btv
->bus_vbi_even
=virt_to_bus(btv
->risc_jmp
+6);
3199 btwrite(virt_to_bus(btv
->risc_jmp
+2), BT848_RISC_STRT_ADD
);
3200 btv
->vbibuf
=(unsigned char *) vmalloc(VBIBUF_SIZE
);
3203 if (!(btv
->grisc
=(unsigned int *) kmalloc(32768, GFP_KERNEL
)))
3206 memset(btv
->vbibuf
, 0, VBIBUF_SIZE
); /* We don't want to return random
3207 memory to the user */
3211 bt848_muxsel(btv
, 1);
3212 bt848_set_winsize(btv
);
3214 /* btwrite(0, BT848_TDEC); */
3215 btwrite(0x10, BT848_COLOR_CTL
);
3216 btwrite(0x00, BT848_CAP_CTL
);
3217 btwrite(0xac, BT848_GPIO_DMA_CTL
);
3219 /* select direct input */
3220 btwrite(0x00, BT848_GPIO_REG_INP
);
3222 btwrite(BT848_IFORM_MUX1
| BT848_IFORM_XTAUTO
| BT848_IFORM_PAL_BDGHI
,
3225 btwrite(0xd8, BT848_CONTRAST_LO
);
3226 bt848_bright(btv
, 0x10);
3228 btwrite(0x20, BT848_E_VSCALE_HI
);
3229 btwrite(0x20, BT848_O_VSCALE_HI
);
3230 btwrite(/*BT848_ADC_SYNC_T|*/
3231 BT848_ADC_RESERVED
|BT848_ADC_CRUSH
, BT848_ADC
);
3233 btwrite(BT848_CONTROL_LDEC
, BT848_E_CONTROL
);
3234 btwrite(BT848_CONTROL_LDEC
, BT848_O_CONTROL
);
3236 btv
->picture
.colour
=254<<7;
3237 btv
->picture
.brightness
=128<<8;
3238 btv
->picture
.hue
=128<<8;
3239 btv
->picture
.contrast
=0xd8<<7;
3241 btwrite(0x00, BT848_E_SCLOOP
);
3242 btwrite(0x00, BT848_O_SCLOOP
);
3244 /* clear interrupt status */
3245 btwrite(0xfffffUL
, BT848_INT_STAT
);
3247 /* set interrupt mask */
3248 btwrite(btv
->triton1
|
3249 /*BT848_INT_PABORT|BT848_INT_RIPERR|BT848_INT_PPERR|
3250 BT848_INT_FDSR|BT848_INT_FTRGT|BT848_INT_FBUS|*/
3253 BT848_INT_RISCI
|BT848_INT_OCERR
|BT848_INT_VPRES
|
3254 BT848_INT_FMTCHG
|BT848_INT_HLOCK
,
3258 bt848_set_risc_jmps(btv
);
3261 * Now add the template and register the device unit.
3264 memcpy(&btv
->video_dev
,&bttv_template
, sizeof(bttv_template
));
3265 memcpy(&btv
->vbi_dev
,&vbi_template
, sizeof(vbi_template
));
3266 memcpy(&btv
->radio_dev
,&radio_template
,sizeof(radio_template
));
3270 if(video_register_device(&btv
->video_dev
,VFL_TYPE_GRABBER
)<0)
3272 if(video_register_device(&btv
->vbi_dev
,VFL_TYPE_VBI
)<0)
3274 video_unregister_device(&btv
->video_dev
);
3279 if(video_register_device(&btv
->radio_dev
, VFL_TYPE_RADIO
)<0)
3281 video_unregister_device(&btv
->vbi_dev
);
3282 video_unregister_device(&btv
->video_dev
);
3286 i2c_register_bus(&btv
->i2c
);
3291 static void bttv_irq(int irq
, void *dev_id
, struct pt_regs
* regs
)
3298 btv
=(struct bttv
*)dev_id
;
3302 /* get/clear interrupt status bits */
3303 stat
=btread(BT848_INT_STAT
);
3304 astat
=stat
&btread(BT848_INT_MASK
);
3307 btwrite(astat
,BT848_INT_STAT
);
3308 IDEBUG(printk ("bttv%d: astat %08x\n", btv
->nr
, astat
));
3309 IDEBUG(printk ("bttv%d: stat %08x\n", btv
->nr
, stat
));
3311 /* get device status bits */
3312 dstat
=btread(BT848_DSTATUS
);
3314 if (astat
&BT848_INT_FMTCHG
)
3316 IDEBUG(printk ("bttv%d: IRQ_FMTCHG\n", btv
->nr
));
3318 (dstat&BT848_DSTATUS_NUML) ? (~1) : (~0); */
3320 if (astat
&BT848_INT_VPRES
)
3322 IDEBUG(printk ("bttv%d: IRQ_VPRES\n", btv
->nr
));
3324 if (astat
&BT848_INT_VSYNC
)
3326 IDEBUG(printk ("bttv%d: IRQ_VSYNC\n", btv
->nr
));
3329 if (astat
&BT848_INT_SCERR
) {
3330 IDEBUG(printk ("bttv%d: IRQ_SCERR\n", btv
->nr
));
3333 wake_up_interruptible(&btv
->vbiq
);
3334 wake_up_interruptible(&btv
->capq
);
3337 if (astat
&BT848_INT_RISCI
)
3339 IDEBUG(printk ("bttv%d: IRQ_RISCI\n", btv
->nr
));
3341 /* captured VBI frame */
3345 /* inc vbi frame count for detecting drops */
3346 (*(u32
*)&(btv
->vbibuf
[VBIBUF_SIZE
- 4]))++;
3347 wake_up_interruptible(&btv
->vbiq
);
3350 /* captured full frame */
3353 wake_up_interruptible(&btv
->capq
);
3354 btv
->last_field
=btv
->field
;
3356 btv
->frame_stat
[btv
->grf
] = GBUFFER_DONE
;
3357 if ((--btv
->grabbing
))
3359 btv
->gfmt
= btv
->gfmt_next
;
3360 btv
->gwidth
= btv
->gwidth_next
;
3361 btv
->gheight
= btv
->gheight_next
;
3362 btv
->gro
= btv
->gro_next
;
3363 btv
->gre
= btv
->gre_next
;
3364 btv
->grf
= btv
->grf_next
;
3365 btv
->risc_jmp
[5]=btv
->gro
;
3366 btv
->risc_jmp
[11]=btv
->gre
;
3367 bt848_set_geo(btv
, btv
->gwidth
,
3371 bt848_set_risc_jmps(btv
);
3372 btand(~BT848_VSCALE_COMB
, BT848_E_VSCALE_HI
);
3373 btand(~BT848_VSCALE_COMB
, BT848_O_VSCALE_HI
);
3374 bt848_set_geo(btv
, btv
->win
.width
,
3376 btv
->win
.color_fmt
);
3378 wake_up_interruptible(&btv
->capq
);
3383 btv
->risc_jmp
[5]=btv
->gro
;
3384 btv
->risc_jmp
[11]=btv
->gre
;
3385 btv
->risc_jmp
[12]=BT848_RISC_JUMP
;
3386 bt848_set_geo(btv
, btv
->gwidth
, btv
->gheight
,
3390 if (astat
&BT848_INT_OCERR
)
3392 IDEBUG(printk ("bttv%d: IRQ_OCERR\n", btv
->nr
));
3394 if (astat
&BT848_INT_PABORT
)
3396 IDEBUG(printk ("bttv%d: IRQ_PABORT\n", btv
->nr
));
3398 if (astat
&BT848_INT_RIPERR
)
3400 IDEBUG(printk ("bttv%d: IRQ_RIPERR\n", btv
->nr
));
3402 if (astat
&BT848_INT_PPERR
)
3404 IDEBUG(printk ("bttv%d: IRQ_PPERR\n", btv
->nr
));
3406 if (astat
&BT848_INT_FDSR
)
3408 IDEBUG(printk ("bttv%d: IRQ_FDSR\n", btv
->nr
));
3410 if (astat
&BT848_INT_FTRGT
)
3412 IDEBUG(printk ("bttv%d: IRQ_FTRGT\n", btv
->nr
));
3414 if (astat
&BT848_INT_FBUS
)
3416 IDEBUG(printk ("bttv%d: IRQ_FBUS\n", btv
->nr
));
3418 if (astat
&BT848_INT_HLOCK
)
3420 if ((dstat
&BT848_DSTATUS_HLOC
) || (btv
->radio
))
3421 audio(btv
, AUDIO_ON
);
3423 audio(btv
, AUDIO_OFF
);
3426 if (astat
&BT848_INT_I2CDONE
)
3432 printk (KERN_WARNING
"bttv%d: irq loop %d\n",
3436 btwrite(0, BT848_INT_MASK
);
3438 "bttv%d: IRQ lockup, cleared int mask\n", btv
->nr
);
3446 * Scan for a Bt848 card, request the irq and map the io memory
3449 #if LINUX_VERSION_CODE >= 0x020100
3450 int configure_bt848(struct pci_dev
*dev
, int bttv_num
)
3453 unsigned char command
;
3456 btv
=&bttvs
[bttv_num
];
3459 btv
->bt848_mem
=NULL
;
3464 init_waitqueue_head(&btv
->vbiq
);
3465 init_waitqueue_head(&btv
->capq
);
3466 init_waitqueue_head(&btv
->capqo
);
3467 init_waitqueue_head(&btv
->capqe
);
3468 btv
->vbip
=VBIBUF_SIZE
;
3470 btv
->id
=dev
->device
;
3472 btv
->bt848_adr
=dev
->base_address
[0];
3474 btv
->i2c_command
= 0x83;
3476 btv
->i2c_command
=(I2C_TIMING
| BT848_I2C_SCL
| BT848_I2C_SDA
);
3478 if (remap
[bttv_num
])
3480 if (remap
[bttv_num
] < 0x1000)
3481 remap
[bttv_num
]<<=20;
3482 remap
[bttv_num
]&=PCI_BASE_ADDRESS_MEM_MASK
;
3483 printk(KERN_INFO
"bttv%d: remapping to : 0x%08x.\n",
3484 bttv_num
,remap
[bttv_num
]);
3485 remap
[bttv_num
]|=btv
->bt848_adr
&(~PCI_BASE_ADDRESS_MEM_MASK
);
3486 pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
, remap
[bttv_num
]);
3487 pci_read_config_dword(dev
, PCI_BASE_ADDRESS_0
, &btv
->bt848_adr
);
3488 btv
->dev
->base_address
[0] = btv
->bt848_adr
;
3490 btv
->bt848_adr
&=PCI_BASE_ADDRESS_MEM_MASK
;
3491 pci_read_config_byte(dev
, PCI_CLASS_REVISION
, &btv
->revision
);
3492 printk(KERN_INFO
"bttv%d: Brooktree Bt%d (rev %d) ",
3493 bttv_num
,btv
->id
, btv
->revision
);
3494 printk("bus: %d, devfn: %d, ",dev
->bus
->number
, dev
->devfn
);
3495 printk("irq: %d, ",btv
->irq
);
3496 printk("memory: 0x%08x.\n", btv
->bt848_adr
);
3498 btv
->pll
.pll_crystal
= 0;
3499 btv
->pll
.pll_ifreq
= 0;
3500 btv
->pll
.pll_ofreq
= 0;
3501 btv
->pll
.pll_current
= 0;
3502 if (!(btv
->id
==848 && btv
->revision
==0x11)) {
3503 switch (pll
[btv
->nr
]) {
3508 /* 28 MHz crystal installed */
3509 btv
->pll
.pll_ifreq
=28636363;
3510 btv
->pll
.pll_crystal
=BT848_IFORM_XT0
;
3513 /* 35 MHz crystal installed */
3514 btv
->pll
.pll_ifreq
=35468950;
3515 btv
->pll
.pll_crystal
=BT848_IFORM_XT1
;
3520 btv
->bt848_mem
=ioremap(btv
->bt848_adr
, 0x1000);
3522 /* clear interrupt mask */
3523 btwrite(0, BT848_INT_MASK
);
3525 result
= request_irq(btv
->irq
, bttv_irq
,
3526 SA_SHIRQ
| SA_INTERRUPT
,"bttv",(void *)btv
);
3527 if (result
==-EINVAL
)
3529 printk(KERN_ERR
"bttv%d: Bad irq number or handler\n",
3535 printk(KERN_ERR
"bttv%d: IRQ %d busy, change your PnP config in BIOS\n",bttv_num
,btv
->irq
);
3541 pci_set_master(dev
);
3543 btv
->triton1
=triton1
? BT848_INT_ETBF
: 0;
3544 if (triton1
&& btv
->id
>= 878)
3547 printk("bttv: Enabling 430FX compatibilty for bt878\n");
3548 pci_read_config_byte(dev
, BT878_DEVCTRL
, &command
);
3549 command
|=BT878_EN_TBFX
;
3550 pci_write_config_byte(dev
, BT878_DEVCTRL
, command
);
3551 pci_read_config_byte(dev
, BT878_DEVCTRL
, &command
);
3552 if (!(command
&BT878_EN_TBFX
))
3554 printk("bttv: 430FX compatibility could not be enabled\n");
3562 static int find_bt848(void)
3564 struct pci_dev
*dev
= pci_devices
;
3571 if (dev
->vendor
== PCI_VENDOR_ID_BROOKTREE
)
3572 if ((dev
->device
== PCI_DEVICE_ID_BT848
)||
3573 (dev
->device
== PCI_DEVICE_ID_BT849
)||
3574 (dev
->device
== PCI_DEVICE_ID_BT878
)||
3575 (dev
->device
== PCI_DEVICE_ID_BT879
))
3576 result
=configure_bt848(dev
,bttv_num
++);
3582 printk(KERN_INFO
"bttv: %d Bt8xx card(s) found.\n", bttv_num
);
3586 static int find_bt848(void)
3589 unsigned char command
, latency
;
3591 unsigned char bus
, devfn
;
3596 if (!pcibios_present())
3598 DEBUG(printk(KERN_DEBUG
"bttv%d: PCI-BIOS not present or not accessable!\n",bttv_num
));
3603 !pcibios_find_device(PCI_VENDOR_ID_BROOKTREE
, PCI_DEVICE_ID_BT849
,
3604 pci_index
, &bus
, &devfn
)
3605 ||!pcibios_find_device(PCI_VENDOR_ID_BROOKTREE
, PCI_DEVICE_ID_BT848
,
3606 pci_index
, &bus
, &devfn
)
3607 ||!pcibios_find_device(PCI_VENDOR_ID_BROOKTREE
, PCI_DEVICE_ID_BT878
,
3608 pci_index
, &bus
, &devfn
)
3609 ||!pcibios_find_device(PCI_VENDOR_ID_BROOKTREE
, PCI_DEVICE_ID_BT879
,
3610 pci_index
, &bus
, &devfn
);
3613 btv
=&bttvs
[bttv_num
];
3617 btv
->bt848_mem
=NULL
;
3627 btv
->vbip
=VBIBUF_SIZE
;
3629 pcibios_read_config_word(btv
->bus
, btv
->devfn
, PCI_DEVICE_ID
,
3631 pcibios_read_config_byte(btv
->bus
, btv
->devfn
,
3632 PCI_INTERRUPT_LINE
, &btv
->irq
);
3633 pcibios_read_config_dword(btv
->bus
, btv
->devfn
, PCI_BASE_ADDRESS_0
,
3636 btv
->i2c_command
= 0x83;
3639 (I2C_TIMING
| BT848_I2C_SCL
| BT848_I2C_SDA
);
3641 if (remap
[bttv_num
])
3643 if (remap
[bttv_num
] < 0x1000)
3644 remap
[bttv_num
]<<=20;
3645 remap
[bttv_num
]&=PCI_BASE_ADDRESS_MEM_MASK
;
3646 printk(KERN_INFO
"bttv%d: remapping to : 0x%08x.\n",
3647 bttv_num
,remap
[bttv_num
]);
3648 remap
[bttv_num
]|=btv
->bt848_adr
&(~PCI_BASE_ADDRESS_MEM_MASK
);
3649 pcibios_write_config_dword(btv
->bus
, btv
->devfn
, PCI_BASE_ADDRESS_0
,
3651 pcibios_read_config_dword(btv
->bus
, btv
->devfn
, PCI_BASE_ADDRESS_0
,
3655 btv
->bt848_adr
&=PCI_BASE_ADDRESS_MEM_MASK
;
3656 pcibios_read_config_byte(btv
->bus
, btv
->devfn
, PCI_CLASS_REVISION
,
3658 printk(KERN_INFO
"bttv%d: Brooktree Bt%d (rev %d) ",
3659 bttv_num
,btv
->id
, btv
->revision
);
3660 printk("bus: %d, devfn: %d, ",
3661 btv
->bus
, btv
->devfn
);
3662 printk("irq: %d, ",btv
->irq
);
3663 printk("memory: 0x%08x.\n", btv
->bt848_adr
);
3665 btv
->pll
.pll_crystal
= 0;
3666 btv
->pll
.pll_ifreq
= 0;
3667 btv
->pll
.pll_ofreq
= 0;
3668 btv
->pll
.pll_current
= 0;
3669 if (!(btv
->id
==848 && btv
->revision
==0x11)) {
3670 switch (pll
[btv
->nr
]) {
3675 /* 28 MHz crystal installed */
3676 btv
->pll
.pll_ifreq
=28636363;
3677 btv
->pll
.pll_crystal
=BT848_IFORM_XT0
;
3680 /* 35 MHz crystal installed */
3681 btv
->pll
.pll_ifreq
=35468950;
3682 btv
->pll
.pll_crystal
=BT848_IFORM_XT1
;
3687 btv
->bt848_mem
=ioremap(btv
->bt848_adr
, 0x1000);
3689 result
= request_irq(btv
->irq
, bttv_irq
,
3690 SA_SHIRQ
| SA_INTERRUPT
,"bttv",(void *)btv
);
3691 if (result
==-EINVAL
)
3693 printk(KERN_ERR
"bttv%d: Bad irq number or handler\n",
3699 printk(KERN_ERR
"bttv%d: IRQ %d busy, change your PnP config in BIOS\n",bttv_num
,btv
->irq
);
3705 /* Enable bus-mastering */
3706 pcibios_read_config_byte(btv
->bus
, btv
->devfn
, PCI_COMMAND
, &command
);
3707 command
|=PCI_COMMAND_MASTER
;
3708 pcibios_write_config_byte(btv
->bus
, btv
->devfn
, PCI_COMMAND
, command
);
3709 pcibios_read_config_byte(btv
->bus
, btv
->devfn
, PCI_COMMAND
, &command
);
3710 if (!(command
&PCI_COMMAND_MASTER
))
3712 printk(KERN_ERR
"bttv%d: PCI bus-mastering could not be enabled\n",bttv_num
);
3715 pcibios_read_config_byte(btv
->bus
, btv
->devfn
, PCI_LATENCY_TIMER
,
3720 pcibios_write_config_byte(btv
->bus
, btv
->devfn
,
3721 PCI_LATENCY_TIMER
, latency
);
3723 DEBUG(printk(KERN_DEBUG
"bttv%d: latency: %02x\n",
3724 bttv_num
, latency
));
3726 btv
->triton1
=triton1
? BT848_INT_ETBF
: 0;
3727 if (triton1
&& btv
->id
>= 878)
3730 printk("bttv: Enabling 430FX compatibilty for bt878\n");
3731 pcibios_read_config_byte(btv
->bus
, btv
->devfn
, BT878_DEVCTRL
, &command
);
3732 command
|=BT878_EN_TBFX
;
3733 pcibios_write_config_byte(btv
->bus
, btv
->devfn
, BT878_DEVCTRL
, command
);
3734 pcibios_read_config_byte(btv
->bus
, btv
->devfn
, BT878_DEVCTRL
, &command
);
3735 if (!(command
&BT878_EN_TBFX
))
3737 printk("bttv: 430FX compatibility could not be enabled\n");
3745 printk(KERN_INFO
"bttv: %d Bt8xx card(s) found.\n", bttv_num
);
3750 static void release_bttv(void)
3756 for (i
=0;i
<bttv_num
; i
++)
3760 /* turn off all capturing, DMA and IRQs */
3762 btand(~15, BT848_GPIO_DMA_CTL
);
3764 /* first disable interrupts before unmapping the memory! */
3765 btwrite(0, BT848_INT_MASK
);
3766 btwrite(0xffffffffUL
,BT848_INT_STAT
);
3767 btwrite(0x0, BT848_GPIO_OUT_EN
);
3769 /* unregister i2c_bus */
3770 i2c_unregister_bus((&btv
->i2c
));
3772 /* disable PCI bus-mastering */
3773 #if LINUX_VERSION_CODE >= 0x020100
3774 pci_read_config_byte(btv
->dev
, PCI_COMMAND
, &command
);
3775 /* Should this be &=~ ?? */
3776 command
&=~PCI_COMMAND_MASTER
;
3777 pci_write_config_byte(btv
->dev
, PCI_COMMAND
, command
);
3779 pcibios_read_config_byte(btv
->bus
, btv
->devfn
, PCI_COMMAND
, &command
);
3780 command
&=~PCI_COMMAND_MASTER
;
3781 pcibios_write_config_byte(btv
->bus
, btv
->devfn
, PCI_COMMAND
, command
);
3785 /* unmap and free memory */
3787 kfree((void *) btv
->grisc
);
3790 kfree((void *) btv
->risc_odd
);
3793 kfree((void *) btv
->risc_even
);
3795 DEBUG(printk(KERN_DEBUG
"free: risc_jmp: 0x%08x.\n", btv
->risc_jmp
));
3797 kfree((void *) btv
->risc_jmp
);
3799 DEBUG(printk(KERN_DEBUG
"bt848_vbibuf: 0x%08x.\n", btv
->vbibuf
));
3801 vfree((void *) btv
->vbibuf
);
3804 free_irq(btv
->irq
,btv
);
3805 DEBUG(printk(KERN_DEBUG
"bt848_mem: 0x%08x.\n", btv
->bt848_mem
));
3807 iounmap(btv
->bt848_mem
);
3809 if(btv
->video_dev
.minor
!=-1)
3810 video_unregister_device(&btv
->video_dev
);
3811 if(btv
->vbi_dev
.minor
!=-1)
3812 video_unregister_device(&btv
->vbi_dev
);
3813 if (radio
[btv
->nr
] && btv
->radio_dev
.minor
!= -1)
3814 video_unregister_device(&btv
->radio_dev
);
3822 int init_module(void)
3825 int init_bttv_cards(struct video_init
*unused
)
3834 /* initialize Bt848s */
3835 for (i
=0; i
<bttv_num
; i
++)
3837 if (init_bt848(i
)<0)
3851 void cleanup_module(void)
3861 * c-brace-imaginary-offset: 0
3862 * c-brace-offset: -8
3863 * c-argdecl-indent: 8
3864 * c-label-offset: -8
3865 * c-continued-statement-offset: 8
3866 * c-continued-brace-offset: 0
3867 * indent-tabs-mode: nil