2 bttv - Bt848 frame grabber driver
5 (c) 2002 Gerd Knorr <kraxel@bytesex.org>
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/errno.h>
25 #include <linux/kernel.h>
26 #include <linux/sched.h>
27 #include <linux/interrupt.h>
28 #include <linux/kdev_t.h>
32 #define VBI_DEFLINES 16
33 #define VBI_MAXLINES 32
35 static unsigned int vbibufs = 4;
36 static unsigned int vbi_debug = 0;
38 MODULE_PARM(vbibufs,"i");
39 MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32, default 4");
40 MODULE_PARM(vbi_debug,"i");
41 MODULE_PARM_DESC(vbi_debug,"vbi code debug messages, default is 0 (no)");
46 #define dprintk(fmt, arg...) if (vbi_debug) \
47 printk(KERN_DEBUG "bttv%d/vbi: " fmt, btv->c.nr , ## arg)
49 /* ----------------------------------------------------------------------- */
50 /* vbi risc code + mm */
53 vbi_buffer_risc(struct bttv *btv, struct bttv_buffer *buf, int lines)
57 bttv_risc_packed(btv, &buf->top, buf->vb.dma.sglist,
59 bttv_risc_packed(btv, &buf->bottom, buf->vb.dma.sglist,
60 lines * bpl, bpl-4, 4, lines);
64 static int vbi_buffer_setup(struct file *file,
65 unsigned int *count, unsigned int *size)
67 struct bttv_fh *fh = file->private_data;
68 struct bttv *btv = fh->btv;
72 *size = fh->lines * 2 * 2048;
73 dprintk("setup: lines=%d\n",fh->lines);
77 static int vbi_buffer_prepare(struct file *file, struct videobuf_buffer *vb,
78 enum v4l2_field field)
80 struct bttv_fh *fh = file->private_data;
81 struct bttv *btv = fh->btv;
82 struct bttv_buffer *buf = (struct bttv_buffer*)vb;
85 buf->vb.size = fh->lines * 2 * 2048;
86 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
89 if (STATE_NEEDS_INIT == buf->vb.state) {
90 if (0 != (rc = videobuf_iolock(btv->c.pci, &buf->vb, NULL)))
92 if (0 != (rc = vbi_buffer_risc(btv,buf,fh->lines)))
95 buf->vb.state = STATE_PREPARED;
96 buf->vb.field = field;
97 dprintk("buf prepare %p: top=%p bottom=%p field=%s\n",
98 vb, &buf->top, &buf->bottom,
99 v4l2_field_names[buf->vb.field]);
103 bttv_dma_free(btv,buf);
108 vbi_buffer_queue(struct file *file, struct videobuf_buffer *vb)
110 struct bttv_fh *fh = file->private_data;
111 struct bttv *btv = fh->btv;
112 struct bttv_buffer *buf = (struct bttv_buffer*)vb;
114 dprintk("queue %p\n",vb);
115 buf->vb.state = STATE_QUEUED;
116 list_add_tail(&buf->vb.queue,&btv->vcapture);
117 if (NULL == btv->cvbi) {
118 fh->btv->curr.irqflags |= 4;
119 bttv_set_dma(btv,0x0c,fh->btv->curr.irqflags);
123 static void vbi_buffer_release(struct file *file, struct videobuf_buffer *vb)
125 struct bttv_fh *fh = file->private_data;
126 struct bttv *btv = fh->btv;
127 struct bttv_buffer *buf = (struct bttv_buffer*)vb;
129 dprintk("free %p\n",vb);
130 bttv_dma_free(fh->btv,buf);
133 struct videobuf_queue_ops bttv_vbi_qops = {
134 .buf_setup = vbi_buffer_setup,
135 .buf_prepare = vbi_buffer_prepare,
136 .buf_queue = vbi_buffer_queue,
137 .buf_release = vbi_buffer_release,
140 /* ----------------------------------------------------------------------- */
142 void bttv_vbi_setlines(struct bttv_fh *fh, struct bttv *btv, int lines)
148 if (lines > VBI_MAXLINES)
149 lines = VBI_MAXLINES;
152 vdelay = btread(BT848_E_VDELAY_LO);
153 if (vdelay < lines*2) {
155 btwrite(vdelay,BT848_E_VDELAY_LO);
156 btwrite(vdelay,BT848_O_VDELAY_LO);
160 void bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_format *f)
162 const struct bttv_tvnorm *tvnorm;
164 s32 count0,count1,count;
166 tvnorm = &bttv_tvnorms[fh->btv->tvnorm];
167 f->type = V4L2_BUF_TYPE_VBI_CAPTURE;
168 f->fmt.vbi.sampling_rate = tvnorm->Fsc;
169 f->fmt.vbi.samples_per_line = 2048;
170 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
171 f->fmt.vbi.offset = 244;
172 f->fmt.vbi.flags = 0;
173 switch (fh->btv->tvnorm) {
185 count0 = (f->fmt.vbi.start[0] + f->fmt.vbi.count[0]) - start0;
186 count1 = (f->fmt.vbi.start[1] + f->fmt.vbi.count[1]) - start1;
187 count = max(count0,count1);
188 if (count > VBI_MAXLINES)
189 count = VBI_MAXLINES;
193 f->fmt.vbi.start[0] = start0;
194 f->fmt.vbi.start[1] = start1;
195 f->fmt.vbi.count[0] = count;
196 f->fmt.vbi.count[1] = count;
199 void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_format *f)
201 const struct bttv_tvnorm *tvnorm;
203 tvnorm = &bttv_tvnorms[fh->btv->tvnorm];
204 memset(f,0,sizeof(*f));
205 f->type = V4L2_BUF_TYPE_VBI_CAPTURE;
206 f->fmt.vbi.sampling_rate = tvnorm->Fsc;
207 f->fmt.vbi.samples_per_line = 2048;
208 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
209 f->fmt.vbi.offset = 244;
210 f->fmt.vbi.count[0] = fh->lines;
211 f->fmt.vbi.count[1] = fh->lines;
212 f->fmt.vbi.flags = 0;
213 switch (fh->btv->tvnorm) {
215 f->fmt.vbi.start[0] = 10;
216 f->fmt.vbi.start[1] = 273;
221 f->fmt.vbi.start[0] = 7;
222 f->fmt.vbi.start[1] = 319;
226 /* ----------------------------------------------------------------------- */