3 bttv - Bt848 frame grabber driver
6 (c) 2002 Gerd Knorr <kraxel@bytesex.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/errno.h>
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/interrupt.h>
30 #include <linux/kdev_t.h>
34 #define VBI_DEFLINES 16
35 #define VBI_MAXLINES 32
37 static unsigned int vbibufs
= 4;
38 static unsigned int vbi_debug
= 0;
40 module_param(vbibufs
, int, 0444);
41 module_param(vbi_debug
, int, 0644);
42 MODULE_PARM_DESC(vbibufs
,"number of vbi buffers, range 2-32, default 4");
43 MODULE_PARM_DESC(vbi_debug
,"vbi code debug messages, default is 0 (no)");
48 #define dprintk(fmt, arg...) if (vbi_debug) \
49 printk(KERN_DEBUG "bttv%d/vbi: " fmt, btv->c.nr , ## arg)
51 /* ----------------------------------------------------------------------- */
52 /* vbi risc code + mm */
55 vbi_buffer_risc(struct bttv
*btv
, struct bttv_buffer
*buf
, int lines
)
59 bttv_risc_packed(btv
, &buf
->top
, buf
->vb
.dma
.sglist
,
61 bttv_risc_packed(btv
, &buf
->bottom
, buf
->vb
.dma
.sglist
,
62 lines
* bpl
, bpl
-4, 4, lines
);
66 static int vbi_buffer_setup(struct videobuf_queue
*q
,
67 unsigned int *count
, unsigned int *size
)
69 struct bttv_fh
*fh
= q
->priv_data
;
70 struct bttv
*btv
= fh
->btv
;
74 *size
= fh
->lines
* 2 * 2048;
75 dprintk("setup: lines=%d\n",fh
->lines
);
79 static int vbi_buffer_prepare(struct videobuf_queue
*q
,
80 struct videobuf_buffer
*vb
,
81 enum v4l2_field field
)
83 struct bttv_fh
*fh
= q
->priv_data
;
84 struct bttv
*btv
= fh
->btv
;
85 struct bttv_buffer
*buf
= container_of(vb
,struct bttv_buffer
,vb
);
88 buf
->vb
.size
= fh
->lines
* 2 * 2048;
89 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< buf
->vb
.size
)
92 if (STATE_NEEDS_INIT
== buf
->vb
.state
) {
93 if (0 != (rc
= videobuf_iolock(btv
->c
.pci
, &buf
->vb
, NULL
)))
95 if (0 != (rc
= vbi_buffer_risc(btv
,buf
,fh
->lines
)))
98 buf
->vb
.state
= STATE_PREPARED
;
99 buf
->vb
.field
= field
;
100 dprintk("buf prepare %p: top=%p bottom=%p field=%s\n",
101 vb
, &buf
->top
, &buf
->bottom
,
102 v4l2_field_names
[buf
->vb
.field
]);
106 bttv_dma_free(btv
,buf
);
111 vbi_buffer_queue(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
113 struct bttv_fh
*fh
= q
->priv_data
;
114 struct bttv
*btv
= fh
->btv
;
115 struct bttv_buffer
*buf
= container_of(vb
,struct bttv_buffer
,vb
);
117 dprintk("queue %p\n",vb
);
118 buf
->vb
.state
= STATE_QUEUED
;
119 list_add_tail(&buf
->vb
.queue
,&btv
->vcapture
);
120 if (NULL
== btv
->cvbi
) {
121 fh
->btv
->loop_irq
|= 4;
122 bttv_set_dma(btv
,0x0c);
126 static void vbi_buffer_release(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
128 struct bttv_fh
*fh
= q
->priv_data
;
129 struct bttv
*btv
= fh
->btv
;
130 struct bttv_buffer
*buf
= container_of(vb
,struct bttv_buffer
,vb
);
132 dprintk("free %p\n",vb
);
133 bttv_dma_free(fh
->btv
,buf
);
136 struct videobuf_queue_ops bttv_vbi_qops
= {
137 .buf_setup
= vbi_buffer_setup
,
138 .buf_prepare
= vbi_buffer_prepare
,
139 .buf_queue
= vbi_buffer_queue
,
140 .buf_release
= vbi_buffer_release
,
143 /* ----------------------------------------------------------------------- */
145 void bttv_vbi_setlines(struct bttv_fh
*fh
, struct bttv
*btv
, int lines
)
151 if (lines
> VBI_MAXLINES
)
152 lines
= VBI_MAXLINES
;
155 vdelay
= btread(BT848_E_VDELAY_LO
);
156 if (vdelay
< lines
*2) {
158 btwrite(vdelay
,BT848_E_VDELAY_LO
);
159 btwrite(vdelay
,BT848_O_VDELAY_LO
);
163 void bttv_vbi_try_fmt(struct bttv_fh
*fh
, struct v4l2_format
*f
)
165 const struct bttv_tvnorm
*tvnorm
;
167 s32 count0
,count1
,count
;
169 tvnorm
= &bttv_tvnorms
[fh
->btv
->tvnorm
];
170 f
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
171 f
->fmt
.vbi
.sampling_rate
= tvnorm
->Fsc
;
172 f
->fmt
.vbi
.samples_per_line
= 2048;
173 f
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
174 f
->fmt
.vbi
.offset
= 244;
175 f
->fmt
.vbi
.flags
= 0;
176 switch (fh
->btv
->tvnorm
) {
188 count0
= (f
->fmt
.vbi
.start
[0] + f
->fmt
.vbi
.count
[0]) - start0
;
189 count1
= (f
->fmt
.vbi
.start
[1] + f
->fmt
.vbi
.count
[1]) - start1
;
190 count
= max(count0
,count1
);
191 if (count
> VBI_MAXLINES
)
192 count
= VBI_MAXLINES
;
196 f
->fmt
.vbi
.start
[0] = start0
;
197 f
->fmt
.vbi
.start
[1] = start1
;
198 f
->fmt
.vbi
.count
[0] = count
;
199 f
->fmt
.vbi
.count
[1] = count
;
202 void bttv_vbi_get_fmt(struct bttv_fh
*fh
, struct v4l2_format
*f
)
204 const struct bttv_tvnorm
*tvnorm
;
206 tvnorm
= &bttv_tvnorms
[fh
->btv
->tvnorm
];
207 memset(f
,0,sizeof(*f
));
208 f
->type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
209 f
->fmt
.vbi
.sampling_rate
= tvnorm
->Fsc
;
210 f
->fmt
.vbi
.samples_per_line
= 2048;
211 f
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
212 f
->fmt
.vbi
.offset
= 244;
213 f
->fmt
.vbi
.count
[0] = fh
->lines
;
214 f
->fmt
.vbi
.count
[1] = fh
->lines
;
215 f
->fmt
.vbi
.flags
= 0;
216 switch (fh
->btv
->tvnorm
) {
218 f
->fmt
.vbi
.start
[0] = 10;
219 f
->fmt
.vbi
.start
[1] = 273;
224 f
->fmt
.vbi
.start
[0] = 7;
225 f
->fmt
.vbi
.start
[1] = 319;
229 /* ----------------------------------------------------------------------- */