2 $Id: bttv-vbi.c,v 1.9 2005/01/13 17:22:33 kraxel Exp $
4 bttv - Bt848 frame grabber driver
7 (c) 2002 Gerd Knorr <kraxel@bytesex.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/errno.h>
28 #include <linux/kernel.h>
29 #include <linux/sched.h>
30 #include <linux/interrupt.h>
31 #include <linux/kdev_t.h>
35 #define VBI_DEFLINES 16
36 #define VBI_MAXLINES 32
38 static unsigned int vbibufs
= 4;
39 static unsigned int vbi_debug
= 0;
41 module_param(vbibufs
, int, 0444);
42 module_param(vbi_debug
, int, 0644);
43 MODULE_PARM_DESC(vbibufs
,"number of vbi buffers, range 2-32, default 4");
44 MODULE_PARM_DESC(vbi_debug
,"vbi code debug messages, default is 0 (no)");
49 #define dprintk(fmt, arg...) if (vbi_debug) \
50 printk(KERN_DEBUG "bttv%d/vbi: " fmt, btv->c.nr , ## arg)
52 /* ----------------------------------------------------------------------- */
53 /* vbi risc code + mm */
56 vbi_buffer_risc(struct bttv
*btv
, struct bttv_buffer
*buf
, int lines
)
60 bttv_risc_packed(btv
, &buf
->top
, buf
->vb
.dma
.sglist
,
62 bttv_risc_packed(btv
, &buf
->bottom
, buf
->vb
.dma
.sglist
,
63 lines
* bpl
, bpl
-4, 4, lines
);
67 static int vbi_buffer_setup(struct videobuf_queue
*q
,
68 unsigned int *count
, unsigned int *size
)
70 struct bttv_fh
*fh
= q
->priv_data
;
71 struct bttv
*btv
= fh
->btv
;
75 *size
= fh
->lines
* 2 * 2048;
76 dprintk("setup: lines=%d\n",fh
->lines
);
80 static int vbi_buffer_prepare(struct videobuf_queue
*q
,
81 struct videobuf_buffer
*vb
,
82 enum v4l2_field field
)
84 struct bttv_fh
*fh
= q
->priv_data
;
85 struct bttv
*btv
= fh
->btv
;
86 struct bttv_buffer
*buf
= container_of(vb
,struct bttv_buffer
,vb
);
89 buf
->vb
.size
= fh
->lines
* 2 * 2048;
90 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< buf
->vb
.size
)
93 if (STATE_NEEDS_INIT
== buf
->vb
.state
) {
94 if (0 != (rc
= videobuf_iolock(btv
->c
.pci
, &buf
->vb
, NULL
)))
96 if (0 != (rc
= vbi_buffer_risc(btv
,buf
,fh
->lines
)))
99 buf
->vb
.state
= STATE_PREPARED
;
100 buf
->vb
.field
= field
;
101 dprintk("buf prepare %p: top=%p bottom=%p field=%s\n",
102 vb
, &buf
->top
, &buf
->bottom
,
103 v4l2_field_names
[buf
->vb
.field
]);
107 bttv_dma_free(btv
,buf
);
112 vbi_buffer_queue(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
114 struct bttv_fh
*fh
= q
->priv_data
;
115 struct bttv
*btv
= fh
->btv
;
116 struct bttv_buffer
*buf
= container_of(vb
,struct bttv_buffer
,vb
);
118 dprintk("queue %p\n",vb
);
119 buf
->vb
.state
= STATE_QUEUED
;
120 list_add_tail(&buf
->vb
.queue
,&btv
->vcapture
);
121 if (NULL
== btv
->cvbi
) {
122 fh
->btv
->loop_irq
|= 4;
123 bttv_set_dma(btv
,0x0c);
127 static void vbi_buffer_release(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
129 struct bttv_fh
*fh
= q
->priv_data
;
130 struct bttv
*btv
= fh
->btv
;
131 struct bttv_buffer
*buf
= container_of(vb
,struct bttv_buffer
,vb
);
133 dprintk("free %p\n",vb
);
134 bttv_dma_free(fh
->btv
,buf
);
137 struct videobuf_queue_ops bttv_vbi_qops
= {
138 .buf_setup
= vbi_buffer_setup
,
139 .buf_prepare
= vbi_buffer_prepare
,
140 .buf_queue
= vbi_buffer_queue
,
141 .buf_release
= vbi_buffer_release
,
144 /* ----------------------------------------------------------------------- */
146 void bttv_vbi_setlines(struct bttv_fh
*fh
, struct bttv
*btv
, int lines
)
152 if (lines
> VBI_MAXLINES
)
153 lines
= VBI_MAXLINES
;
156 vdelay
= btread(BT848_E_VDELAY_LO
);
157 if (vdelay
< lines
*2) {
159 btwrite(vdelay
,BT848_E_VDELAY_LO
);
160 btwrite(vdelay
,BT848_O_VDELAY_LO
);
164 void bttv_vbi_try_fmt(struct bttv_fh
*fh
, struct v4l2_format
*f
)
166 const struct bttv_tvnorm
*tvnorm
;
168 s32 count0
,count1
,count
;
170 tvnorm
= &bttv_tvnorms
[fh
->btv
->tvnorm
];
171 f
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
172 f
->fmt
.vbi
.sampling_rate
= tvnorm
->Fsc
;
173 f
->fmt
.vbi
.samples_per_line
= 2048;
174 f
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
175 f
->fmt
.vbi
.offset
= 244;
176 f
->fmt
.vbi
.flags
= 0;
177 switch (fh
->btv
->tvnorm
) {
189 count0
= (f
->fmt
.vbi
.start
[0] + f
->fmt
.vbi
.count
[0]) - start0
;
190 count1
= (f
->fmt
.vbi
.start
[1] + f
->fmt
.vbi
.count
[1]) - start1
;
191 count
= max(count0
,count1
);
192 if (count
> VBI_MAXLINES
)
193 count
= VBI_MAXLINES
;
197 f
->fmt
.vbi
.start
[0] = start0
;
198 f
->fmt
.vbi
.start
[1] = start1
;
199 f
->fmt
.vbi
.count
[0] = count
;
200 f
->fmt
.vbi
.count
[1] = count
;
203 void bttv_vbi_get_fmt(struct bttv_fh
*fh
, struct v4l2_format
*f
)
205 const struct bttv_tvnorm
*tvnorm
;
207 tvnorm
= &bttv_tvnorms
[fh
->btv
->tvnorm
];
208 memset(f
,0,sizeof(*f
));
209 f
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
210 f
->fmt
.vbi
.sampling_rate
= tvnorm
->Fsc
;
211 f
->fmt
.vbi
.samples_per_line
= 2048;
212 f
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
213 f
->fmt
.vbi
.offset
= 244;
214 f
->fmt
.vbi
.count
[0] = fh
->lines
;
215 f
->fmt
.vbi
.count
[1] = fh
->lines
;
216 f
->fmt
.vbi
.flags
= 0;
217 switch (fh
->btv
->tvnorm
) {
219 f
->fmt
.vbi
.start
[0] = 10;
220 f
->fmt
.vbi
.start
[1] = 273;
225 f
->fmt
.vbi
.start
[0] = 7;
226 f
->fmt
.vbi
.start
[1] = 319;
230 /* ----------------------------------------------------------------------- */