2 bttv - Bt848 frame grabber driver
4 Copyright (C) 1996,97 Ralph Metzler (rjkm@thp.uni-koeln.de)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 Modified to put the RISC code writer in the kernel and to fit a
21 common (and I hope safe) kernel interface. When we have an X extension
22 all will now be really sweet.
25 #include <linux/module.h>
26 #include <linux/bios32.h>
27 #include <linux/config.h>
28 #include <linux/delay.h>
29 #include <linux/errno.h>
31 #include <linux/kernel.h>
32 #include <linux/major.h>
33 #include <linux/malloc.h>
35 #include <linux/pci.h>
36 #include <linux/signal.h>
38 #include <asm/pgtable.h>
40 #include <linux/sched.h>
41 #include <asm/segment.h>
42 #include <linux/types.h>
43 #include <linux/videodev.h>
45 #include <linux/version.h>
46 #include <asm/uaccess.h>
51 #define DEBUG(x) /* Debug driver */
52 #define IDEBUG(x) /* Debug interrupt handler */
54 static unsigned int remap
=0;
55 static unsigned int vidmem
=0;
56 static unsigned int tuner
=0; /* Default tuner */
57 MODULE_PARM(tuner
,"i");
59 static int find_vga(void);
60 static void bt848_set_risc_jmps(struct bttv
*btv
);
62 /* Anybody who uses more than four? */
66 static struct bttv bttvs
[BTTV_MAX
];
68 #define I2C_TIMING (0x7<<4)
69 #define I2C_COMMAND (I2C_TIMING | BT848_I2C_SCL | BT848_I2C_SDA)
71 #define AUDIO_MUTE_DELAY 10000
72 #define FREQ_CHANGE_DELAY 20000
73 #define EEPROM_WRITE_DELAY 20000
76 /*******************************/
77 /* Memory management functions */
78 /*******************************/
80 /* convert virtual user memory address to physical address */
81 /* (virt_to_phys only works for kmalloced kernel memory) */
83 static inline ulong
uvirt_to_phys(ulong adr
)
89 /* printk("adr: 0x%08x\n",adr);*/
90 pgd
= pgd_offset(current
->mm
, adr
);
91 /* printk("pgd: 0x%08x\n",pgd);*/
94 pmd
= pmd_offset(pgd
, adr
);
95 /* printk("pmd: 0x%08x\n",pmd); */
98 ptep
= pte_offset(pmd
, adr
&(~PGDIR_MASK
));
101 return (pte_page(pte
)|(adr
&(PAGE_SIZE
-1)));
105 /* convert virtual kernel memory address to physical address */
106 /* (virt_to_phys only works for kmalloced kernel memory) */
108 static inline ulong
kvirt_to_phys(ulong adr
)
110 return uvirt_to_phys(VMALLOC_VMADDR(adr
));
113 static inline ulong
kvirt_to_bus(ulong adr
)
115 return virt_to_bus(phys_to_virt(kvirt_to_phys(adr
)));
123 static int I2CRead(struct bttv
*btv
, int addr
)
128 /* clear status bit ; BT848_INT_RACK is ro */
129 btwrite(BT848_INT_I2CDONE
, BT848_INT_STAT
);
131 btwrite(((addr
& 0xff) << 24) | I2C_COMMAND
, BT848_I2C
);
134 * Timeout for I2CRead is 1 second (this should be enough, really!)
138 stat
=btread(BT848_INT_STAT
);
139 if (stat
& BT848_INT_I2CDONE
)
141 udelay(1000); /* 1ms, as I2C is 1kHz (?) */
145 printk(KERN_DEBUG
"bttv: I2CRead timeout\n");
148 if (!(stat
& BT848_INT_RACK
))
151 i
=(btread(BT848_I2C
)>>8)&0xff;
155 /* set both to write both bytes, reset it to write only b1 */
157 static int I2CWrite(struct bttv
*btv
, unchar addr
, unchar b1
,
164 /* clear status bit; BT848_INT_RACK is ro */
165 btwrite(BT848_INT_I2CDONE
, BT848_INT_STAT
);
167 data
=((addr
& 0xff) << 24) | ((b1
& 0xff) << 16) | I2C_COMMAND
;
170 data
|=((b2
& 0xff) << 8);
174 btwrite(data
, BT848_I2C
);
178 stat
=btread(BT848_INT_STAT
);
179 if (stat
& BT848_INT_I2CDONE
)
185 printk(KERN_DEBUG
"bttv: I2CWrite timeout\n");
188 if (!(stat
& BT848_INT_RACK
))
194 static void readee(struct bttv
*btv
, unchar
*eedata
)
198 if (I2CWrite(btv
, 0xa0, 0, -1, 0)<0)
200 printk(KERN_WARNING
"bttv: readee error\n");
204 for (i
=0; i
<256; i
++)
206 k
=I2CRead(btv
, 0xa1);
209 printk(KERN_WARNING
"bttv: readee error\n");
216 static void writeee(struct bttv
*btv
, unchar
*eedata
)
220 for (i
=0; i
<256; i
++)
222 if (I2CWrite(btv
, 0xa0, i
, eedata
[i
], 1)<0)
224 printk(KERN_WARNING
"bttv: writeee error (%d)\n", i
);
227 udelay(EEPROM_WRITE_DELAY
);
232 * Tuner, internal, external and mute
235 static unchar audiomuxs
[][4] =
237 { 0x00, 0x00, 0x00, 0x00}, /* unknown */
238 { 0x02, 0x00, 0x00, 0x0a}, /* MIRO */
239 { 0x00, 0x02, 0x03, 0x04}, /* Hauppauge */
240 { 0x04, 0x02, 0x03, 0x01}, /* STB */
241 { 0x01, 0x02, 0x03, 0x04}, /* Intel??? */
242 { 0x01, 0x02, 0x03, 0x04}, /* Diamond DTV2000??? */
245 static void audio(struct bttv
*btv
, int mode
)
247 btwrite(0x0f, BT848_GPIO_OUT_EN
);
248 btwrite(0x00, BT848_GPIO_REG_INP
);
253 btv
->audio
&=~AUDIO_MUTE
;
263 btv
->audio
&=AUDIO_MUTE
;
267 if ((btv
->audio
&AUDIO_MUTE
) || !(btread(BT848_DSTATUS
)&BT848_DSTATUS_HLOC
))
269 btaor(audiomuxs
[btv
->type
][mode
] , ~0x0f, BT848_GPIO_DATA
);
273 extern inline void bt848_dma(struct bttv
*btv
, uint state
)
276 btor(3, BT848_GPIO_DMA_CTL
);
278 btand(~3, BT848_GPIO_DMA_CTL
);
282 static void bt848_cap(struct bttv
*btv
, uint state
)
287 bt848_set_risc_jmps(btv
);
292 bt848_set_risc_jmps(btv
);
296 static void bt848_muxsel(struct bttv
*btv
, uint input
)
300 /* This seems to get rid of some synchronization problems */
301 btand(~(3<<5), BT848_IFORM
);
306 btor(BT848_CONTROL_COMP
, BT848_E_CONTROL
);
307 btor(BT848_CONTROL_COMP
, BT848_O_CONTROL
);
311 btand(~BT848_CONTROL_COMP
, BT848_E_CONTROL
);
312 btand(~BT848_CONTROL_COMP
, BT848_O_CONTROL
);
316 btaor(((input
+2)&3)<<5, ~(3<<5), BT848_IFORM
);
317 audio(btv
, input
? AUDIO_EXTERN
: AUDIO_TUNER
);
321 #define VBIBUF_SIZE 65536
323 static void make_vbitab(struct bttv
*btv
)
326 dword
*po
=(dword
*) btv
->vbi_odd
;
327 dword
*pe
=(dword
*) btv
->vbi_even
;
329 DEBUG(printk(KERN_DEBUG
"vbiodd: 0x%08x\n",(int)btv
->vbi_odd
));
330 DEBUG(printk(KERN_DEBUG
"vbievn: 0x%08x\n",(int)btv
->vbi_even
));
331 DEBUG(printk(KERN_DEBUG
"po: 0x%08x\n",(int)po
));
332 DEBUG(printk(KERN_DEBUG
"pe: 0x%08x\n",(int)pe
));
334 *(po
++)=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
; *(po
++)=0;
337 *(po
++)=BT848_RISC_WRITE
|2044|BT848_RISC_EOL
|BT848_RISC_SOL
|(13<<20);
338 *(po
++)=kvirt_to_bus((ulong
)btv
->vbibuf
+i
*2048);
340 *(po
++)=BT848_RISC_JUMP
;
341 *(po
++)=virt_to_bus(btv
->risc_jmp
+4);
343 *(pe
++)=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
; *(pe
++)=0;
344 for (i
=16; i
<32; i
++)
346 *(pe
++)=BT848_RISC_WRITE
|2044|BT848_RISC_EOL
|BT848_RISC_SOL
;
347 *(pe
++)=kvirt_to_bus((ulong
)btv
->vbibuf
+i
*2048);
349 *(pe
++)=BT848_RISC_JUMP
|BT848_RISC_IRQ
|(0x01<<16);
350 *(pe
++)=virt_to_bus(btv
->risc_jmp
+10);
354 * Set the registers for the size we have specified. Don't bother
355 * trying to understand this without the BT848 manual in front of
358 * PS: The manual is free for download in .pdf format from
359 * www.brooktree.com - nicely done those folks.
362 static void bt848_set_size(struct bttv
*btv
)
367 u16 hactive
, vactive
;
372 * No window , no try...
377 if (!btv
->win
.height
)
380 inter
=(btv
->win
.interlace
&1)^1;
382 switch (btv
->win
.bpp
)
385 * RGB8 seems to be a 9x5x5 GRB color cube starting at color 16
386 * Why the h... can't they even mention this in the datasheet???
389 btwrite(BT848_COLOR_FMT_RGB8
, BT848_COLOR_FMT
);
390 btand(~0x10, BT848_CAP_CTL
); /* Dithering looks much better in this mode */
393 btwrite(BT848_COLOR_FMT_RGB16
, BT848_COLOR_FMT
);
394 btor(0x10, BT848_CAP_CTL
);
397 btwrite(BT848_COLOR_FMT_RGB24
, BT848_COLOR_FMT
);
398 btor(0x10, BT848_CAP_CTL
);
401 btwrite(BT848_COLOR_FMT_RGB32
, BT848_COLOR_FMT
);
402 btor(0x10, BT848_CAP_CTL
);
407 * Set things up according to the final picture width.
410 hactive
=btv
->win
.width
;
413 btwrite (2, BT848_E_VTC
);
414 btwrite (2, BT848_O_VTC
);
416 else if (hactive
< 385)
418 btwrite (1, BT848_E_VTC
);
419 btwrite (1, BT848_O_VTC
);
423 btwrite (0, BT848_E_VTC
);
424 btwrite (0, BT848_O_VTC
);
428 * Ok are we doing Never The Same Color or PAL ?
431 if (btv
->win
.norm
==1)
433 btv
->win
.cropwidth
=640;
434 btv
->win
.cropheight
=480;
435 btwrite(0x68, BT848_ADELAY
);
436 btwrite(0x5d, BT848_BDELAY
);
437 btaor(BT848_IFORM_NTSC
, ~7, BT848_IFORM
);
438 btaor(BT848_IFORM_XT0
, ~0x18, BT848_IFORM
);
439 xsf
= (btv
->win
.width
*365625UL)/300000UL;
440 hscale
= ((910UL*4096UL)/xsf
-4096);
441 vdelay
=btv
->win
.cropy
+0x16;
442 hdelay
=((hactive
*135)/754+btv
->win
.cropx
)&0x3fe;
446 btv
->win
.cropwidth
=768;
447 btv
->win
.cropheight
=576;
448 if (btv
->win
.norm
==0)
450 btwrite(0x7f, BT848_ADELAY
);
451 btwrite(0x72, BT848_BDELAY
);
452 btaor(BT848_IFORM_PAL_BDGHI
, ~BT848_IFORM_NORM
, BT848_IFORM
);
456 btwrite(0x7f, BT848_ADELAY
);
457 btwrite(0x00, BT848_BDELAY
);
458 btaor(BT848_IFORM_SECAM
, ~BT848_IFORM_NORM
, BT848_IFORM
);
460 btaor(BT848_IFORM_XT1
, ~0x18, BT848_IFORM
);
461 xsf
= (btv
->win
.width
*36875UL)/30000UL;
462 hscale
= ((1135UL*4096UL)/xsf
-4096);
463 vdelay
=btv
->win
.cropy
+0x20;
464 hdelay
=((hactive
*186)/922+btv
->win
.cropx
)&0x3fe;
466 sr
=((btv
->win
.cropheight
>>inter
)*512)/btv
->win
.height
-512;
467 vscale
=(0x10000UL
-sr
)&0x1fff;
468 vactive
=btv
->win
.cropheight
;
471 printk("bttv: hscale=0x%04x, ",hscale
);
472 printk("bttv: vscale=0x%04x\n",vscale
);
474 printk("bttv: hdelay =0x%04x\n",hdelay
);
475 printk("bttv: hactive=0x%04x\n",hactive
);
476 printk("bttv: vdelay =0x%04x\n",vdelay
);
477 printk("bttv: vactive=0x%04x\n",vactive
);
481 * Interlace is set elsewhere according to the final image
485 if (btv
->win
.interlace
)
487 btor(BT848_VSCALE_INT
, BT848_E_VSCALE_HI
);
488 btor(BT848_VSCALE_INT
, BT848_O_VSCALE_HI
);
492 btand(~BT848_VSCALE_INT
, BT848_E_VSCALE_HI
);
493 btand(~BT848_VSCALE_INT
, BT848_O_VSCALE_HI
);
500 btwrite(hscale
>>8, BT848_E_HSCALE_HI
);
501 btwrite(hscale
>>8, BT848_O_HSCALE_HI
);
502 btwrite(hscale
&0xff, BT848_E_HSCALE_LO
);
503 btwrite(hscale
&0xff, BT848_O_HSCALE_LO
);
505 btwrite((vscale
>>8)|(btread(BT848_E_VSCALE_HI
)&0xe0), BT848_E_VSCALE_HI
);
506 btwrite((vscale
>>8)|(btread(BT848_O_VSCALE_HI
)&0xe0), BT848_O_VSCALE_HI
);
507 btwrite(vscale
&0xff, BT848_E_VSCALE_LO
);
508 btwrite(vscale
&0xff, BT848_O_VSCALE_LO
);
510 btwrite(hactive
&0xff, BT848_E_HACTIVE_LO
);
511 btwrite(hactive
&0xff, BT848_O_HACTIVE_LO
);
512 btwrite(hdelay
&0xff, BT848_E_HDELAY_LO
);
513 btwrite(hdelay
&0xff, BT848_O_HDELAY_LO
);
515 btwrite(vactive
&0xff, BT848_E_VACTIVE_LO
);
516 btwrite(vactive
&0xff, BT848_O_VACTIVE_LO
);
517 btwrite(vdelay
&0xff, BT848_E_VDELAY_LO
);
518 btwrite(vdelay
&0xff, BT848_O_VDELAY_LO
);
520 crop
=((hactive
>>8)&0x03)|((hdelay
>>6)&0x0c)|
521 ((vactive
>>4)&0x30)|((vdelay
>>2)&0xc0);
522 btwrite(crop
, BT848_E_CROP
);
523 btwrite(crop
, BT848_O_CROP
);
528 * The floats in the tuner struct are computed at compile time
529 * by gcc and cast back to integers. Thus we don't violate the
530 * "no float in kernel" rule.
533 static struct tunertype tuners
[] = {
534 {"Temic PAL", TEMIC
, PAL
,
535 16*140.25,16*463.25,0x02,0x04,0x01,0x8e,0xc2, 623},
536 {"Philips PAL_I", Philips
, PAL_I
,
537 16*140.25,16*463.25,0x00,0x00,0x00,0x00,0x00, 623},
538 {"Philips NTSC", Philips
, NTSC
,
539 16*157.25,16*451.25,0xA0,0x90,0x30,0x8e,0xc0, 732},
540 {"Philips SECAM", Philips
, SECAM
,
541 16*168.25,16*447.25,0xA3,0x93,0x33,0x8e,0xc0, 623},
542 {"NoTuner", NoTuner
, NOTUNER
,
543 0 ,0 ,0x00,0x00,0x00,0x00,0x00, 0},
544 {"Philips PAL", Philips
, PAL
,
545 16*168.25,16*447.25,0xA0,0x90,0x30,0x8e,0xc0, 623},
546 {"Temic NTSC", TEMIC
, NTSC
,
547 16*157.25,16*463.25,0x02,0x04,0x01,0x8e,0xc2, 732},
548 {"TEMIC PAL_I", TEMIC
, PAL_I
,
549 0 ,0 ,0x00,0x00,0x00,0x00,0xc2, 623},
553 * Set TSA5522 synthesizer frequency in 1/16 Mhz steps
556 static void set_freq(struct bttv
*btv
, ushort freq
)
560 struct tunertype
*tun
=&tuners
[btv
->tuner
];
561 int oldAudio
= btv
->audio
;
563 audio(btv
, AUDIO_MUTE
);
564 udelay(AUDIO_MUTE_DELAY
);
566 if (freq
< tun
->thresh1
)
568 else if (freq
< tun
->thresh2
)
573 if(freq
< tun
->thresh1
)
575 else if(freq
< tun
->thresh2
)
580 div
=freq
+tun
->IFPCoff
;
584 if (I2CWrite(btv
, btv
->tuneradr
, (div
>>8)&0x7f, div
&0xff, 1)<0)
586 I2CWrite(btv
, btv
->tuneradr
, tun
->config
, config
, 1);
587 if (!(oldAudio
& AUDIO_MUTE
))
589 udelay(FREQ_CHANGE_DELAY
);
590 audio(btv
, AUDIO_UNMUTE
);
594 static long bttv_write(struct video_device
*v
, const char *buf
, unsigned long count
, int nonblock
)
599 static long bttv_read(struct video_device
*v
, char *buf
, unsigned long count
, int nonblock
)
601 struct bttv
*btv
= (struct bttv
*)v
;
605 while (todo
&& todo
>(q
=VBIBUF_SIZE
-btv
->vbip
))
607 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, q
))
614 if (todo
&& q
==VBIBUF_SIZE
-btv
->vbip
)
623 interruptible_sleep_on(&btv
->vbiq
);
625 if(signal_pending(current
))
636 if(copy_to_user((void *) buf
, (void *) btv
->vbibuf
+btv
->vbip
, todo
))
644 * Open a bttv card. Right now the flags stuff is just playing
647 static int bttv_open(struct video_device
*dev
, int flags
)
649 struct bttv
*btv
= (struct bttv
*)dev
;
658 audio(btv
, AUDIO_UNMUTE
);
659 for (i
=users
=0; i
<bttv_num
; i
++)
660 users
+=bttvs
[i
].user
;
667 btv
->vbip
=VBIBUF_SIZE
;
669 bt848_set_risc_jmps(btv
);
676 static void bttv_close(struct video_device
*dev
)
678 struct bttv
*btv
=(struct bttv
*)dev
;
681 audio(btv
, AUDIO_MUTE
);
689 bt848_set_risc_jmps(btv
);
694 /***********************************/
695 /* ioctls and supporting functions */
696 /***********************************/
698 extern inline void bt848_bright(struct bttv
*btv
, uint bright
)
700 btwrite(bright
&0xff, BT848_BRIGHT
);
703 extern inline void bt848_hue(struct bttv
*btv
, uint hue
)
705 btwrite(hue
&0xff, BT848_HUE
);
708 extern inline void bt848_contrast(struct bttv
*btv
, uint cont
)
713 btwrite(cont
&0xff, BT848_CONTRAST_LO
);
714 btaor(conthi
, ~4, BT848_E_CONTROL
);
715 btaor(conthi
, ~4, BT848_O_CONTROL
);
718 extern inline void bt848_sat_u(struct bttv
*btv
, ulong data
)
723 btwrite(data
&0xff, BT848_SAT_U_LO
);
724 btaor(datahi
, ~2, BT848_E_CONTROL
);
725 btaor(datahi
, ~2, BT848_O_CONTROL
);
728 static inline void bt848_sat_v(struct bttv
*btv
, ulong data
)
733 btwrite(data
&0xff, BT848_SAT_V_LO
);
734 btaor(datahi
, ~1, BT848_E_CONTROL
);
735 btaor(datahi
, ~1, BT848_O_CONTROL
);
739 * Cliprect -> risc table.
741 * FIXME: This is generating wrong code when we have some kinds of
742 * rectangle lists. If you generate overlapped rectangles then it
743 * gets a bit confused. Since we add the frame buffer clip rectangles
744 * we need to fix this. Better yet to rewrite this function.
747 static void write_risc_data(struct bttv
*btv
, struct video_clip
*vp
, int count
)
750 u32 yy
, y
, x
, dx
, ox
;
752 struct video_clip first
, *cur
, *cur2
, *nx
, first2
, *prev
, *nx2
;
753 u32
*rp
, rpo
=0, rpe
=0, p
, bpsl
;
759 rmem
=(u32
*)btv
->risc_odd
;
760 rmem2
=(u32
*)btv
->risc_even
;
763 /* create y-sorted list */
766 for (i
=0; i
<count
; i
++)
769 while ((nx
=cur
->next
) && (vp
[i
].y
> cur
->next
->y
))
776 rmem
[rpo
++]=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
; rmem
[rpo
++]=0;
778 rmem2
[rpe
++]=BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
; rmem2
[rpe
++]=0;
782 * 32bit depth frame buffers need extra flags setting
786 mask
=BT848_RISC_BYTE3
;
790 bpsl
=btv
->win
.width
*btv
->win
.bpp
;
791 p
=btv
->win
.vidadr
+btv
->win
.x
*btv
->win
.bpp
+
792 btv
->win
.y
*btv
->win
.bpl
;
794 interlace
=btv
->win
.interlace
;
797 * Loop through all lines
800 for (yy
=0; yy
<(btv
->win
.height
<<(1^interlace
)); yy
++)
805 * Even or odd frame generation. We have to
806 * write the RISC instructions to the right stream.
822 * first2 is the header of a list of "active" rectangles. We add
823 * rectangles as we hit their top and remove them as they fall off
827 /* remove rects with y2 > y */
828 if ((cur
=first2
.next
))
833 if (cur
->y
+cur
->height
< y
)
834 prev
->next
=cur
->next
;
838 while ((cur
=cur
->next
));
842 * Fixme - we have to handle overlapped rectangles
843 * here, but the overlap might be partial
846 /* add rect to second (x-sorted) list if rect.y == y */
847 if ((cur
=first
.next
))
849 while ((cur
) && (cur
->y
== y
))
851 first
.next
=cur
->next
;
853 while ((nx2
=cur2
->next
) && (cur
->x
> cur2
->next
->x
))
863 * Begin writing the RISC script
869 * Starting at x position 0 on a new scan line
870 * write to location p, don't yet write the number
871 * of pixels for the instruction
874 rpp
[(*rp
)++]=BT848_RISC_WRITE
|BT848_RISC_SOL
;
878 * For each rectangle we have in the "active" list - sorted left to
882 for (cur2
=first2
.next
; cur2
; cur2
=cur2
->next
)
885 * If we are to the left of the first drawing area
890 /* Bytes pending ? */
893 /* For a delta away from the start we need to write a SKIP */
895 rpp
[(*rp
)++]=BT848_RISC_SKIP
|(dx
*depth
);
897 /* Rewrite the start of line WRITE to a SKIP */
898 rpp
[(*rp
)-2]|=BT848_RISC_BYTE_ALL
|(dx
*depth
);
899 /* Move X to the next point (drawing start) */
902 /* Ok how far are we from the start of the next rectangle ? */
904 /* dx is now the size of data to write */
906 /* If this isnt the left edge generate a "write continue" */
908 rpp
[(*rp
)++]=BT848_RISC_WRITEC
|(dx
*depth
)|mask
;
910 /* Fill in the byte count on the initial WRITE */
911 rpp
[(*rp
)-2]|=(dx
*depth
)|mask
;
912 /* Move to the start of the rectangle */
914 /* x is our left dx is byte size of hole */
918 /* Already in a clip zone.. set dx */
919 if (x
+dx
< cur2
->x
+cur2
->width
)
920 dx
=cur2
->x
+cur2
->width
-x
+1;
922 /* now treat the rest of the line */
926 /* Complete the SKIP to eat to the end of the gap */
928 rpp
[(*rp
)++]=BT848_RISC_SKIP
|(dx
*depth
);
930 /* Rewrite to SKIP start to this point */
931 rpp
[(*rp
)-2]|=BT848_RISC_BYTE_ALL
|(dx
*depth
);
936 * Not at the right hand edge ?
939 if ((dx
=btv
->win
.width
-x
)!=0)
941 /* Write to edge of display */
943 rpp
[(*rp
)++]=BT848_RISC_WRITEC
|(dx
*depth
)|BT848_RISC_EOL
|mask
;
945 /* Entire frame is a write - patch first order */
946 rpp
[(*rp
)-2]|=(dx
*depth
)|BT848_RISC_EOL
|mask
;
950 /* End of line if needed */
952 rpp
[(*rp
)-1]|=BT848_RISC_EOL
|mask
;
955 /* Skip the line : write a SKIP + start/end of line marks */
957 rpp
[(*rp
)-1]=BT848_RISC_SKIP
|(btv
->win
.width
*depth
)|
958 BT848_RISC_EOL
|BT848_RISC_SOL
;
962 * Move the video render pointer on a line
964 if (interlace
||(y
&1))
969 * Attach the interframe jumps
972 rmem
[rpo
++]=BT848_RISC_JUMP
;
973 rmem
[rpo
++]=btv
->bus_vbi_even
;
975 rmem2
[rpe
++]=BT848_RISC_JUMP
;
976 rmem2
[rpe
++]=btv
->bus_vbi_odd
;
980 * Helper for adding clips.
983 static void new_risc_clip(struct video_window
*vw
, struct video_clip
*vcp
, int x
, int y
, int w
, int h
)
985 vcp
[vw
->clipcount
].x
=x
;
986 vcp
[vw
->clipcount
].y
=y
;
987 vcp
[vw
->clipcount
].width
=w
;
988 vcp
[vw
->clipcount
].height
=h
;
996 static int bttv_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
998 unsigned char eedata
[256];
999 /* unsigned long data;*/
1000 /* static ushort creg;*/
1001 struct bttv
*btv
=(struct bttv
*)dev
;
1002 static int lastchan
=0;
1008 struct video_capability b
;
1009 strcpy(b
.name
,btv
->video_dev
.name
);
1010 b
.type
= VID_TYPE_CAPTURE
|
1017 b
.channels
= 4; /* tv , input, svhs */
1018 b
.audios
= 4; /* tv, input, svhs */
1023 if(copy_to_user(arg
,&b
,sizeof(b
)))
1029 struct video_channel v
;
1030 if(copy_from_user(&v
, arg
,sizeof(v
)))
1032 v
.flags
=VIDEO_VC_AUDIO
;
1034 v
.type
=VIDEO_TYPE_CAMERA
;
1038 strcpy(v
.name
,"Television");
1039 v
.flags
|=VIDEO_VC_TUNER
;
1040 v
.type
=VIDEO_TYPE_TV
;
1044 strcpy(v
.name
,"Composite1");
1047 strcpy(v
.name
,"Composite2");
1050 strcpy(v
.name
,"SVHS");
1055 if(copy_to_user(arg
,&v
,sizeof(v
)))
1060 * Each channel has 1 tuner
1065 if(copy_from_user(&v
, arg
, sizeof(v
)))
1067 bt848_muxsel(btv
, v
);
1073 struct video_tuner v
;
1074 if(copy_from_user(&v
,arg
,sizeof(v
))!=0)
1076 if(v
.tuner
||lastchan
) /* Only tuner 0 */
1078 strcpy(v
.name
, "Television");
1080 v
.rangehigh
=0xFFFFFFFF;
1081 v
.flags
=VIDEO_TUNER_PAL
|VIDEO_TUNER_NTSC
;
1082 v
.mode
= btv
->win
.norm
;
1083 if(copy_to_user(arg
,&v
,sizeof(v
)))
1087 /* We have but tuner 0 */
1090 struct video_tuner v
;
1091 if(copy_from_user(&v
, arg
, sizeof(v
)))
1093 /* Only channel 0 has a tuner */
1094 if(v
.tuner
!=0 || lastchan
)
1096 if(v
.mode
!=VIDEO_MODE_PAL
&&v
.mode
!=VIDEO_MODE_NTSC
)
1098 btv
->win
.norm
= v
.mode
;
1099 bt848_set_size(btv
);
1104 struct video_picture p
=btv
->picture
;
1106 p
.palette
=VIDEO_PALETTE_HI240
;
1108 p
.palette
=VIDEO_PALETTE_RGB565
;
1110 p
.palette
=VIDEO_PALETTE_RGB24
;
1112 p
.palette
=VIDEO_PALETTE_RGB32
;
1113 if(copy_to_user(arg
, &p
, sizeof(p
)))
1119 struct video_picture p
;
1120 if(copy_from_user(&p
, arg
,sizeof(p
)))
1122 /* We want -128 to 127 we get 0-65535 */
1123 bt848_bright(btv
, (p
.brightness
>>8)-128);
1124 /* 0-511 for the colour */
1125 bt848_sat_u(btv
, p
.colour
>>7);
1126 bt848_sat_v(btv
, ((p
.colour
>>7)*201L)/237);
1128 bt848_hue(btv
, (p
.hue
>>8)-128);
1130 bt848_contrast(btv
, p
.contrast
>>7);
1136 struct video_window vw
;
1137 struct video_clip
*vcp
;
1140 if(copy_from_user(&vw
,arg
,sizeof(vw
)))
1148 btv
->win
.width
=vw
.width
;
1149 btv
->win
.height
=vw
.height
;
1151 if(btv
->win
.height
>btv
->win
.cropheight
/2)
1152 btv
->win
.interlace
=1;
1154 btv
->win
.interlace
=0;
1156 on
=(btv
->cap
&3)?1:0;
1159 bt848_set_size(btv
);
1161 if(vw
.clipcount
>256)
1162 return -EDOM
; /* Too many! */
1168 vcp
=vmalloc(sizeof(struct video_clip
)*(vw
.clipcount
+4));
1171 if(vw
.clipcount
&& copy_from_user(vcp
,vw
.clips
,sizeof(struct video_clip
)*vw
.clipcount
))
1174 * Impose display clips
1177 new_risc_clip(&vw
, vcp
, 0, 0, -btv
->win
.x
, btv
->win
.height
-1);
1179 new_risc_clip(&vw
, vcp
, 0, 0, btv
->win
.width
-1,-btv
->win
.y
);
1180 if(btv
->win
.x
+btv
->win
.width
> btv
->win
.swidth
)
1181 new_risc_clip(&vw
, vcp
, btv
->win
.swidth
-btv
->win
.x
, 0, btv
->win
.width
-1, btv
->win
.height
-1);
1182 if(btv
->win
.y
+btv
->win
.height
> btv
->win
.sheight
)
1183 new_risc_clip(&vw
, vcp
, 0, btv
->win
.sheight
-btv
->win
.y
, btv
->win
.width
-1, btv
->win
.height
-1);
1185 * Question: Do we need to walk the clip list
1186 * and saw off any clips outside the window
1187 * frame or will write_risc_tab do the right
1190 write_risc_data(btv
,vcp
, vw
.clipcount
);
1198 struct video_window vw
;
1199 /* Oh for a COBOL move corresponding .. */
1202 vw
.width
=btv
->win
.width
;
1203 vw
.height
=btv
->win
.height
;
1206 if(btv
->win
.interlace
)
1207 vw
.flags
|=VIDEO_WINDOW_INTERLACE
;
1208 if(copy_to_user(arg
,&vw
,sizeof(vw
)))
1215 if(copy_from_user(&v
, arg
,sizeof(v
)))
1217 if(btv
->win
.vidadr
==0 || btv
->win
.width
==0 || btv
->win
.height
==0)
1231 struct video_buffer v
;
1232 v
.base
=(void *)btv
->win
.vidadr
;
1233 v
.height
=btv
->win
.sheight
;
1234 v
.width
=btv
->win
.swidth
;
1235 v
.depth
=btv
->win
.bpp
*8;
1236 v
.bytesperline
=btv
->win
.bpl
;
1237 if(copy_to_user(arg
, &v
,sizeof(v
)))
1244 struct video_buffer v
;
1247 if(copy_from_user(&v
, arg
,sizeof(v
)))
1249 if(v
.depth
!=8 && v
.depth
!=16 && v
.depth
!=24 && v
.depth
!=32)
1251 btv
->win
.vidadr
=(int)v
.base
;
1252 btv
->win
.sheight
=v
.height
;
1253 btv
->win
.swidth
=v
.width
;
1254 btv
->win
.bpp
=v
.depth
/8;
1255 btv
->win
.bpl
=v
.bytesperline
;
1257 DEBUG(printk("Display at %p is %d by %d, bytedepth %d, bpl %d\n",
1258 v
.base
, v
.width
,v
.height
, btv
->win
.bpp
, btv
->win
.bpl
));
1259 bt848_set_size(btv
);
1264 /* Will be handled higher up .. */
1269 unsigned long v
=btv
->win
.freq
;
1270 if(copy_to_user(arg
,&v
,sizeof(v
)))
1277 if(copy_from_user(&v
, arg
, sizeof(v
)))
1280 set_freq(btv
, btv
->win
.freq
);
1286 struct video_audio v
;
1288 v
.flags
&=~(VIDEO_AUDIO_MUTE
|VIDEO_AUDIO_MUTABLE
);
1289 v
.flags
|=VIDEO_AUDIO_MUTABLE
;
1290 strcpy(v
.name
,"TV");
1291 if(copy_to_user(arg
,&v
,sizeof(v
)))
1297 struct video_audio v
;
1298 if(copy_from_user(&v
,arg
, sizeof(v
)))
1300 if(v
.flags
&VIDEO_AUDIO_MUTE
)
1301 audio(btv
, AUDIO_MUTE
);
1302 if(v
.audio
<0||v
.audio
>2)
1304 bt848_muxsel(btv
,v
.audio
);
1305 if(!(v
.flags
&VIDEO_AUDIO_MUTE
))
1306 audio(btv
, AUDIO_UNMUTE
);
1312 if(copy_from_user((void *) eedata
, (void *) arg
, 256))
1314 writeee(btv
, eedata
);
1318 readee(btv
, eedata
);
1319 if(copy_to_user((void *) arg
, (void *) eedata
, 256))
1324 return -ENOIOCTLCMD
;
1329 static int bttv_init_done(struct video_device
*dev
)
1334 static struct video_device bttv_template
=
1337 VID_TYPE_TUNER
|VID_TYPE_CAPTURE
|VID_TYPE_OVERLAY
|VID_TYPE_TELETEXT
,
1344 NULL
, /* no mmap yet */
1353 ushort vendor
, device
;
1358 static struct vidbases vbs
[] = {
1359 { PCI_VENDOR_ID_TSENG
, 0, "TSENG", PCI_BASE_ADDRESS_0
},
1360 { PCI_VENDOR_ID_MATROX
, PCI_DEVICE_ID_MATROX_MIL
,
1361 "Matrox Millennium", PCI_BASE_ADDRESS_1
},
1362 { PCI_VENDOR_ID_MATROX
, 0x051a, "Matrox Mystique", PCI_BASE_ADDRESS_1
},
1363 { PCI_VENDOR_ID_S3
, 0, "S3", PCI_BASE_ADDRESS_0
},
1364 { PCI_VENDOR_ID_ATI
, PCI_DEVICE_ID_ATI_210888GX
,
1365 "ATI MACH64 Winturbo", PCI_BASE_ADDRESS_0
},
1366 { PCI_VENDOR_ID_CIRRUS
, 0, "Cirrus Logic", PCI_BASE_ADDRESS_0
},
1367 { PCI_VENDOR_ID_N9
, PCI_DEVICE_ID_N9_I128
,
1368 "Number Nine Imagine 128", PCI_BASE_ADDRESS_0
},
1369 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_TGA
,
1370 "DEC DC21030", PCI_BASE_ADDRESS_0
},
1374 /* DEC TGA offsets stolen from XFree-3.2 */
1376 static uint dec_offsets
[4] = {
1383 #define NR_CARDS (sizeof(vbs)/sizeof(struct vidbases))
1385 /* Scan for PCI display adapter
1386 if more than one card is present the last one is used for now */
1388 static int find_vga(void)
1390 unsigned int devfn
, class, vendev
;
1391 ushort vendor
, device
, badr
;
1392 int found
=0, bus
=0, i
, tga_type
;
1393 unsigned int vidadr
=0;
1396 for (devfn
= 0; devfn
< 0xff; devfn
++)
1398 if (PCI_FUNC(devfn
) != 0)
1400 pcibios_read_config_dword(bus
, devfn
, PCI_VENDOR_ID
, &vendev
);
1401 if (vendev
== 0xffffffff || vendev
== 0x00000000)
1403 pcibios_read_config_word(bus
, devfn
, PCI_VENDOR_ID
, &vendor
);
1404 pcibios_read_config_word(bus
, devfn
, PCI_DEVICE_ID
, &device
);
1405 pcibios_read_config_dword(bus
, devfn
, PCI_CLASS_REVISION
, &class);
1406 class = class >> 16;
1407 /* if (class == PCI_CLASS_DISPLAY_VGA) {*/
1408 if ((class>>8) == PCI_BASE_CLASS_DISPLAY
||
1409 /* Number 9 GXE64Pro needs this */
1410 class == PCI_CLASS_NOT_DEFINED_VGA
)
1413 printk(KERN_INFO
"bttv: PCI display adapter: ");
1414 for (i
=0; i
<NR_CARDS
; i
++)
1416 if (vendor
==vbs
[i
].vendor
)
1419 if (vbs
[i
].device
!=device
)
1421 printk("%s.\n", vbs
[i
].name
);
1428 printk(KERN_ERR
"bttv: Unknown video memory base address.\n");
1431 pcibios_read_config_dword(bus
, devfn
, badr
, &vidadr
);
1432 if (vidadr
& PCI_BASE_ADDRESS_SPACE_IO
)
1434 printk(KERN_ERR
"bttv: Memory seems to be I/O memory.\n");
1435 printk(KERN_ERR
"bttv: Check entry for your card type in bttv.c vidbases struct.\n");
1438 vidadr
&= PCI_BASE_ADDRESS_MEM_MASK
;
1441 printk(KERN_ERR
"bttv: Memory @ 0, must be something wrong!");
1445 if (vendor
==PCI_VENDOR_ID_DEC
)
1446 if (device
==PCI_DEVICE_ID_DEC_TGA
)
1448 tga_type
= (readl((unsigned long)vidadr
) >> 12) & 0x0f;
1449 if (tga_type
!= 0 && tga_type
!= 1 && tga_type
!= 3)
1451 printk(KERN_ERR
"bttv: TGA type (0x%x) unrecognized!\n", tga_type
);
1454 vidadr
+=dec_offsets
[tga_type
];
1457 DEBUG(printk(KERN_DEBUG
"bttv: memory @ 0x%08x, ", vidadr
));
1458 DEBUG(printk(KERN_DEBUG
"devfn: 0x%04x.\n", devfn
));
1466 printk(KERN_INFO
"bttv: Video memory override: 0x%08x\n", vidadr
);
1469 for (i
=0; i
<BTTV_MAX
; i
++)
1470 bttvs
[i
].win
.vidadr
=vidadr
;
1475 #define TRITON_PCON 0x50
1476 #define TRITON_BUS_CONCURRENCY (1<<0)
1477 #define TRITON_STREAMING (1<<1)
1478 #define TRITON_WRITE_BURST (1<<2)
1479 #define TRITON_PEER_CONCURRENCY (1<<3)
1481 static void handle_chipset(void)
1485 for (index
= 0; index
< 8; index
++)
1487 unsigned char bus
, devfn
;
1488 unsigned char b
, bo
;
1490 /* Beware the SiS 85C496 my friend - rev 49 don't work with a bttv */
1492 if (!pcibios_find_device(PCI_VENDOR_ID_SI
, PCI_DEVICE_ID_SI_496
, index
, &bus
, &devfn
))
1494 printk(KERN_WARNING
"BT848 and SIS 85C496 chipset don't always work together.\n");
1497 if (!pcibios_find_device(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82441
,
1498 index
, &bus
, &devfn
))
1500 pcibios_read_config_byte(bus
, devfn
, 0x53, &b
);
1501 DEBUG(printk(KERN_INFO
"bttv: Host bridge: 82441FX Natoma, "));
1502 DEBUG(printk("bufcon=0x%02x\n",b
));
1505 if (!pcibios_find_device(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82441
,
1506 index
, &bus
, &devfn
))
1508 pcibios_read_config_byte(bus
, devfn
, 0x53, &b
);
1509 DEBUG(printk(KERN_INFO
"bttv: Host bridge: 82441FX Natoma, "));
1510 DEBUG(printk("bufcon=0x%02x\n",b
));
1513 if (!pcibios_find_device(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82437
,
1514 index
, &bus
, &devfn
))
1516 printk(KERN_INFO
"bttv: Host bridge 82437FX Triton PIIX\n");
1517 pcibios_read_config_byte(bus
, devfn
, TRITON_PCON
, &b
);
1519 DEBUG(printk(KERN_DEBUG
"bttv: 82437FX: PCON: 0x%x\n",b
));
1521 /* 430FX (Triton I) freezes with bus concurrency on -> switch it off */
1522 if(!(b
& TRITON_BUS_CONCURRENCY
))
1524 printk(KERN_WARNING
"bttv: 82437FX: disabling bus concurrency\n");
1525 b
|= TRITON_BUS_CONCURRENCY
;
1528 /* still freezes on other boards -> switch off even more */
1529 if(b
& TRITON_PEER_CONCURRENCY
)
1531 printk(KERN_WARNING
"bttv: 82437FX: disabling peer concurrency\n");
1532 b
&= ~TRITON_PEER_CONCURRENCY
;
1534 if(!(b
& TRITON_STREAMING
))
1536 printk(KERN_WARNING
"bttv: 82437FX: disabling streaming\n");
1537 b
|= TRITON_STREAMING
;
1542 pcibios_write_config_byte(bus
, devfn
, TRITON_PCON
, b
);
1543 printk(KERN_DEBUG
"bttv: 82437FX: PCON changed to: 0x%x\n",b
);
1549 static void init_tda9850(struct bttv
*btv
)
1551 I2CWrite(btv
, I2C_TDA9850
, TDA9850_CON3
, 0, 1);
1554 /* Figure out card and tuner type */
1556 static void idcard(struct bttv
*btv
)
1560 btwrite(0, BT848_GPIO_OUT_EN
);
1561 DEBUG(printk(KERN_DEBUG
"bttv: GPIO: 0x%08x\n", btread(BT848_GPIO_DATA
)));
1563 btv
->type
=BTTV_MIRO
;
1566 if (I2CRead(btv
, I2C_HAUPEE
)>=0)
1567 btv
->type
=BTTV_HAUPPAUGE
;
1568 else if (I2CRead(btv
, I2C_STBEE
)>=0)
1571 for (i
=0xc0; i
<0xd0; i
+=2)
1573 if (I2CRead(btv
, i
)>=0)
1580 btv
->dbx
= I2CRead(btv
, I2C_TDA9850
) ? 0 : 1;
1585 /* How do I detect the tuner type for other cards but Miro ??? */
1586 printk(KERN_INFO
"bttv: model: ");
1590 btv
->tuner
=((btread(BT848_GPIO_DATA
)>>10)-1)&7;
1592 strcpy(btv
->video_dev
.name
,"BT848(Miro)");
1594 case BTTV_HAUPPAUGE
:
1595 printk("HAUPPAUGE");
1596 strcpy(btv
->video_dev
.name
,"BT848(Hauppauge)");
1600 strcpy(btv
->video_dev
.name
,"BT848(STB)");
1604 strcpy(btv
->video_dev
.name
,"BT848(Intel)");
1608 strcpy(btv
->video_dev
.name
,"BT848(Diamond)");
1611 printk(" (%s @ 0x%02x)\n", tuners
[btv
->tuner
].name
, btv
->tuneradr
);
1612 audio(btv
, AUDIO_MUTE
);
1616 static void bt848_set_risc_jmps(struct bttv
*btv
)
1620 btv
->risc_jmp
[0]=BT848_RISC_SYNC
|BT848_RISC_RESYNC
|BT848_FIFO_STATUS_VRE
;
1623 btv
->risc_jmp
[2]=BT848_RISC_JUMP
;
1625 btv
->risc_jmp
[3]=virt_to_bus(btv
->vbi_odd
);
1627 btv
->risc_jmp
[3]=virt_to_bus(btv
->risc_jmp
+4);
1629 btv
->risc_jmp
[4]=BT848_RISC_JUMP
;
1631 btv
->risc_jmp
[5]=virt_to_bus(btv
->risc_odd
);
1633 btv
->risc_jmp
[5]=virt_to_bus(btv
->risc_jmp
+6);
1635 btv
->risc_jmp
[6]=BT848_RISC_SYNC
|BT848_RISC_RESYNC
|BT848_FIFO_STATUS_VRO
;
1638 btv
->risc_jmp
[8]=BT848_RISC_JUMP
;
1640 btv
->risc_jmp
[9]=virt_to_bus(btv
->vbi_even
);
1642 btv
->risc_jmp
[9]=virt_to_bus(btv
->risc_jmp
+10);
1644 btv
->risc_jmp
[10]=BT848_RISC_JUMP
;
1646 btv
->risc_jmp
[11]=virt_to_bus(btv
->risc_even
);
1648 btv
->risc_jmp
[11]=virt_to_bus(btv
->risc_jmp
);
1650 btaor(flags
, ~0x0f, BT848_CAP_CTL
);
1658 static int init_bt848(struct bttv
*btv
)
1660 /* reset the bt848 */
1661 btwrite(0,BT848_SRESET
);
1664 DEBUG(printk(KERN_DEBUG
"bttv: bt848_mem: 0x%08x\n",(unsigned int) btv
->bt848_mem
));
1666 /* default setup for max. PAL size in a 1024xXXX hicolor framebuffer */
1668 btv
->win
.norm
=0; /* change this to 1 for NTSC, 2 for SECAM */
1669 btv
->win
.interlace
=1;
1672 btv
->win
.width
=768; /* 640 */
1673 btv
->win
.height
=576; /* 480 */
1674 btv
->win
.cropwidth
=768; /* 640 */
1675 btv
->win
.cropheight
=576; /* 480 */
1679 btv
->win
.bpl
=1024*btv
->win
.bpp
;
1680 btv
->win
.swidth
=1024;
1681 btv
->win
.sheight
=768;
1684 if (!(btv
->risc_odd
=(dword
*) kmalloc(RISCMEM_LEN
/2, GFP_KERNEL
)))
1686 if (!(btv
->risc_even
=(dword
*) kmalloc(RISCMEM_LEN
/2, GFP_KERNEL
)))
1688 if (!(btv
->risc_jmp
=(dword
*) kmalloc(1024, GFP_KERNEL
)))
1690 btv
->vbi_odd
=btv
->risc_jmp
+12;
1691 btv
->vbi_even
=btv
->vbi_odd
+256;
1692 btv
->bus_vbi_odd
=virt_to_bus(btv
->risc_jmp
);
1693 btv
->bus_vbi_even
=virt_to_bus(btv
->risc_jmp
+6);
1695 btwrite(virt_to_bus(btv
->risc_jmp
+2), BT848_RISC_STRT_ADD
);
1696 btv
->vbibuf
=(unchar
*) vmalloc(VBIBUF_SIZE
);
1700 bt848_muxsel(btv
, 1);
1701 bt848_set_size(btv
);
1703 /* btwrite(0, BT848_TDEC); */
1704 btwrite(0x10, BT848_COLOR_CTL
);
1705 btwrite(0x00, BT848_CAP_CTL
);
1707 btwrite(0x0ff, BT848_VBI_PACK_SIZE
);
1708 btwrite(1, BT848_VBI_PACK_DEL
);
1710 btwrite(0xfc, BT848_GPIO_DMA_CTL
);
1711 btwrite(BT848_IFORM_MUX1
| BT848_IFORM_XTAUTO
| BT848_IFORM_PAL_BDGHI
,
1714 bt848_bright(btv
, 0x10);
1715 btwrite(0xd8, BT848_CONTRAST_LO
);
1717 btwrite(0x60, BT848_E_VSCALE_HI
);
1718 btwrite(0x60, BT848_O_VSCALE_HI
);
1719 btwrite(/*BT848_ADC_SYNC_T|*/
1720 BT848_ADC_RESERVED
|BT848_ADC_CRUSH
, BT848_ADC
);
1722 btwrite(BT848_CONTROL_LDEC
, BT848_E_CONTROL
);
1723 btwrite(BT848_CONTROL_LDEC
, BT848_O_CONTROL
);
1724 btwrite(0x00, BT848_E_SCLOOP
);
1725 btwrite(0x00, BT848_O_SCLOOP
);
1727 btwrite(0xffffffUL
,BT848_INT_STAT
);
1728 /* BT848_INT_PABORT|BT848_INT_RIPERR|BT848_INT_PPERR|BT848_INT_FDSR|
1729 BT848_INT_FTRGT|BT848_INT_FBUS|*/
1730 btwrite(BT848_INT_ETBF
|
1732 BT848_INT_RISCI
|BT848_INT_OCERR
|BT848_INT_VPRES
|
1733 BT848_INT_FMTCHG
|BT848_INT_HLOCK
,
1736 /* make_risctab(btv); */
1738 bt848_set_risc_jmps(btv
);
1741 * Now add the template and register the device unit.
1744 memcpy(&btv
->video_dev
,&bttv_template
,sizeof(bttv_template
));
1747 btv
->picture
.brightness
=0x90<<8;
1748 btv
->picture
.contrast
= 0x70 << 8;
1749 btv
->picture
.colour
= 0x70<<8;
1750 btv
->picture
.hue
= 0x8000;
1752 if(video_register_device(&btv
->video_dev
)<0)
1758 static void bttv_irq(int irq
, void *dev_id
, struct pt_regs
* regs
)
1765 btv
=(struct bttv
*)dev_id
;
1769 /* get/clear interrupt status bits */
1770 stat
=btread(BT848_INT_STAT
);
1771 astat
=stat
&btread(BT848_INT_MASK
);
1774 btwrite(astat
,BT848_INT_STAT
);
1775 IDEBUG(printk ("bttv: astat %08x\n",astat
));
1776 IDEBUG(printk ("bttv: stat %08x\n",stat
));
1778 /* get device status bits */
1779 dstat
=btread(BT848_DSTATUS
);
1781 if (astat
&BT848_INT_FMTCHG
)
1783 IDEBUG(printk ("bttv: IRQ_FMTCHG\n"));
1784 /* btv->win.norm&=(dstat&BT848_DSTATUS_NUML) ? (~1) : (~0); */
1786 if (astat
&BT848_INT_VPRES
)
1788 IDEBUG(printk ("bttv: IRQ_VPRES\n"));
1790 if (astat
&BT848_INT_VSYNC
)
1792 IDEBUG(printk ("bttv: IRQ_VSYNC\n"));
1794 if (astat
&BT848_INT_SCERR
) {
1795 IDEBUG(printk ("bttv: IRQ_SCERR\n"));
1798 wake_up_interruptible(&btv
->vbiq
);
1799 wake_up_interruptible(&btv
->capq
);
1801 if (astat
&BT848_INT_RISCI
)
1803 IDEBUG(printk ("bttv: IRQ_RISCI\n"));
1804 /* printk ("bttv: IRQ_RISCI%d\n",stat>>28); */
1808 wake_up_interruptible(&btv
->vbiq
);
1812 bt848_set_risc_jmps(btv
);
1813 wake_up_interruptible(&btv
->capq
);
1817 if (astat
&BT848_INT_OCERR
)
1819 IDEBUG(printk ("bttv: IRQ_OCERR\n"));
1821 if (astat
&BT848_INT_PABORT
)
1823 IDEBUG(printk ("bttv: IRQ_PABORT\n"));
1825 if (astat
&BT848_INT_RIPERR
)
1827 IDEBUG(printk ("bttv: IRQ_RIPERR\n"));
1829 if (astat
&BT848_INT_PPERR
)
1831 IDEBUG(printk ("bttv: IRQ_PPERR\n"));
1833 if (astat
&BT848_INT_FDSR
)
1835 IDEBUG(printk ("bttv: IRQ_FDSR\n"));
1837 if (astat
&BT848_INT_FTRGT
)
1839 IDEBUG(printk ("bttv: IRQ_FTRGT\n"));
1841 if (astat
&BT848_INT_FBUS
)
1843 IDEBUG(printk ("bttv: IRQ_FBUS\n"));
1845 if (astat
&BT848_INT_HLOCK
)
1847 if (dstat
&BT848_DSTATUS_HLOC
)
1848 audio(btv
, AUDIO_ON
);
1850 audio(btv
, AUDIO_OFF
);
1853 if (astat
&BT848_INT_I2CDONE
)
1859 printk (KERN_WARNING
"bttv: irq loop %d\n", count
);
1862 btwrite(0, BT848_INT_MASK
);
1863 printk(KERN_ERR
"bttv: IRQ lockup, cleared int mask\n");
1870 * Scan for a Bt848 card, request the irq and map the io memory
1873 static int find_bt848(void)
1876 unsigned char command
, latency
;
1878 unsigned char bus
, devfn
;
1883 if (!pcibios_present())
1885 DEBUG(printk(KERN_DEBUG
"bttv: PCI-BIOS not present or not accessable!\n"));
1890 !pcibios_find_device(PCI_VENDOR_ID_BROOKTREE
, PCI_DEVICE_ID_BT848
,
1891 pci_index
, &bus
, &devfn
);
1894 btv
=&bttvs
[bttv_num
];
1897 btv
->bt848_mem
=NULL
;
1904 btv
->vbip
=VBIBUF_SIZE
;
1906 pcibios_read_config_byte(btv
->bus
, btv
->devfn
,
1907 PCI_INTERRUPT_LINE
, &btv
->irq
);
1908 pcibios_read_config_dword(btv
->bus
, btv
->devfn
, PCI_BASE_ADDRESS_0
,
1911 if (remap
&&(!bttv_num
))
1914 remap
&=PCI_BASE_ADDRESS_MEM_MASK
;
1915 printk(KERN_INFO
"Remapping to : 0x%08x.\n", remap
);
1916 remap
|=btv
->bt848_adr
&(~PCI_BASE_ADDRESS_MEM_MASK
);
1917 pcibios_write_config_dword(btv
->bus
, btv
->devfn
, PCI_BASE_ADDRESS_0
,
1919 pcibios_read_config_dword(btv
->bus
, btv
->devfn
, PCI_BASE_ADDRESS_0
,
1923 btv
->bt848_adr
&=PCI_BASE_ADDRESS_MEM_MASK
;
1924 pcibios_read_config_byte(btv
->bus
, btv
->devfn
, PCI_CLASS_REVISION
,
1926 printk(KERN_INFO
"bttv: Brooktree Bt848 (rev %d) ",btv
->revision
);
1927 printk("bus: %d, devfn: %d, ",
1928 btv
->bus
, btv
->devfn
);
1929 printk("irq: %d, ",btv
->irq
);
1930 printk("memory: 0x%08x.\n", btv
->bt848_adr
);
1932 btv
->bt848_mem
=ioremap(btv
->bt848_adr
, 0x1000);
1934 result
= request_irq(btv
->irq
, bttv_irq
,
1935 SA_SHIRQ
| SA_INTERRUPT
,"bttv",(void *)btv
);
1936 if (result
==-EINVAL
)
1938 printk(KERN_ERR
"bttv: Bad irq number or handler\n");
1943 printk(KERN_ERR
"bttv: IRQ %d busy, change your PnP config in BIOS\n",btv
->irq
);
1949 /* Enable bus-mastering */
1950 pcibios_read_config_byte(btv
->bus
, btv
->devfn
, PCI_COMMAND
, &command
);
1951 command
|=PCI_COMMAND_MASTER
;
1952 pcibios_write_config_byte(btv
->bus
, btv
->devfn
, PCI_COMMAND
, command
);
1953 pcibios_read_config_byte(btv
->bus
, btv
->devfn
, PCI_COMMAND
, &command
);
1954 if (!(command
&PCI_COMMAND_MASTER
))
1956 printk(KERN_ERR
"bttv: PCI bus-mastering could not be enabled\n");
1959 pcibios_read_config_byte(btv
->bus
, btv
->devfn
, PCI_LATENCY_TIMER
,
1964 pcibios_write_config_byte(btv
->bus
, btv
->devfn
, PCI_LATENCY_TIMER
,
1967 DEBUG(printk(KERN_DEBUG
"bttv: latency: %02x\n", latency
));
1971 printk(KERN_INFO
"bttv: %d Bt848 card(s) found.\n", bttv_num
);
1975 static void release_bttv(void)
1981 for (i
=0;i
<bttv_num
; i
++)
1984 /* turn off all capturing, DMA and IRQs */
1986 /* first disable interrupts before unmapping the memory! */
1987 btwrite(0, BT848_INT_MASK
);
1988 btwrite(0xffffffffUL
,BT848_INT_STAT
);
1989 btwrite(0x0, BT848_GPIO_OUT_EN
);
1993 /* disable PCI bus-mastering */
1994 pcibios_read_config_byte(btv
->bus
, btv
->devfn
, PCI_COMMAND
, &command
);
1995 command
|=PCI_COMMAND_MASTER
;
1996 pcibios_write_config_byte(btv
->bus
, btv
->devfn
, PCI_COMMAND
, command
);
1998 /* unmap and free memory */
2000 kfree((void *) btv
->risc_odd
);
2003 kfree((void *) btv
->risc_even
);
2005 DEBUG(printk(KERN_DEBUG
"free: risc_jmp: 0x%08x.\n", btv
->risc_jmp
));
2007 kfree((void *) btv
->risc_jmp
);
2009 DEBUG(printk(KERN_DEBUG
"bt848_vbibuf: 0x%08x.\n", btv
->vbibuf
));
2011 vfree((void *) btv
->vbibuf
);
2012 free_irq(btv
->irq
,btv
);
2013 DEBUG(printk(KERN_DEBUG
"bt848_mem: 0x%08x.\n", btv
->bt848_mem
));
2015 iounmap(btv
->bt848_mem
);
2016 video_unregister_device(&btv
->video_dev
);
2023 int init_module(void)
2026 int init_bttv_cards(struct video_init
*unused
)
2035 for (i
=0; i
<bttv_num
; i
++)
2037 if (init_bt848(&bttvs
[i
])<0)
2048 void cleanup_module(void)