Subversion Repositories shark

Rev

Rev 428 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
428 giacomo 1
/*
2
    bttv - Bt848 frame grabber driver
3
    vbi interface
4
 
5
    (c) 2002 Gerd Knorr <kraxel@bytesex.org>
6
 
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.
11
 
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.
16
 
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.
20
*/
21
 
22
#include <linuxcomp.h>
23
 
24
#include <linux/module.h>
25
#include <linux/errno.h>
26
#include <linux/fs.h>
27
#include <linux/kernel.h>
28
#include <linux/sched.h>
29
#include <linux/interrupt.h>
30
#include <linux/kdev_t.h>
31
#include <asm/io.h>
32
#include "drivers/bttvp.h"
33
 
34
#define VBI_DEFLINES 16
35
#define VBI_MAXLINES 32
36
 
37
static unsigned int vbibufs = 4;
463 giacomo 38
static unsigned int vbi_debug = 1;
428 giacomo 39
 
40
MODULE_PARM(vbibufs,"i");
41
MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32, default 4");
42
MODULE_PARM(vbi_debug,"i");
43
MODULE_PARM_DESC(vbi_debug,"vbi code debug messages, default is 0 (no)");
44
 
45
#ifdef dprintk
46
# undef dprintk
47
#endif
48
#define dprintk(fmt, arg...)    if (vbi_debug) \
49
        printk(KERN_DEBUG "bttv%d/vbi: " fmt, btv->nr, ## arg)
50
 
51
/* ----------------------------------------------------------------------- */
52
/* vbi risc code + mm                                                      */
53
 
54
static int
55
vbi_buffer_risc(struct bttv *btv, struct bttv_buffer *buf, int lines)
56
{
57
        int bpl = 2048;
58
 
59
        bttv_risc_packed(btv, &buf->top, buf->vb.dma.sglist,
60
                         0, bpl-4, 4, lines);
61
        bttv_risc_packed(btv, &buf->bottom, buf->vb.dma.sglist,
62
                         lines * bpl, bpl-4, 4, lines);
63
        return 0;
64
}
65
 
66
static int vbi_buffer_setup(struct file *file,
67
                            unsigned int *count, unsigned int *size)
68
{
69
        struct bttv_fh *fh = file->private_data;
70
        struct bttv *btv = fh->btv;
71
 
72
        if (0 == *count)
73
                *count = vbibufs;
74
        *size = fh->lines * 2 * 2048;
75
        dprintk("setup: lines=%d\n",fh->lines);
76
        return 0;
77
}
78
 
79
static int vbi_buffer_prepare(struct file *file, struct videobuf_buffer *vb,
80
                              enum v4l2_field field)
81
{
82
        struct bttv_fh *fh = file->private_data;
83
        struct bttv *btv = fh->btv;
84
        struct bttv_buffer *buf = (struct bttv_buffer*)vb;
85
        int rc;
86
 
87
        buf->vb.size = fh->lines * 2 * 2048;
88
        if (0 != buf->vb.baddr  &&  buf->vb.bsize < buf->vb.size)
89
                return -EINVAL;
90
 
91
        if (STATE_NEEDS_INIT == buf->vb.state) {
92
                if (0 != (rc = videobuf_iolock(btv->dev, &buf->vb, NULL)))
93
                        goto fail;
94
                if (0 != (rc = vbi_buffer_risc(btv,buf,fh->lines)))
95
                        goto fail;
96
        }
97
        buf->vb.state = STATE_PREPARED;
98
        buf->vb.field = field;
99
        dprintk("buf prepare %p: top=%p bottom=%p field=%s\n",
100
                vb, &buf->top, &buf->bottom,
101
                v4l2_field_names[buf->vb.field]);
102
        return 0;
103
 
104
 fail:
105
        bttv_dma_free(btv,buf);
106
        return rc;
107
}
108
 
109
static void
110
vbi_buffer_queue(struct file *file, struct videobuf_buffer *vb)
111
{
112
        struct bttv_fh *fh = file->private_data;
113
        struct bttv *btv = fh->btv;
114
        struct bttv_buffer *buf = (struct bttv_buffer*)vb;
115
 
116
        dprintk("queue %p\n",vb);
117
        buf->vb.state = STATE_QUEUED;
118
        list_add_tail(&buf->vb.queue,&btv->vcapture);
119
        bttv_set_dma(btv,0x0c,1);
120
}
121
 
122
static void vbi_buffer_release(struct file *file, struct videobuf_buffer *vb)
123
{
124
        struct bttv_fh *fh = file->private_data;
125
        struct bttv *btv = fh->btv;
126
        struct bttv_buffer *buf = (struct bttv_buffer*)vb;
127
 
128
        dprintk("free %p\n",vb);
129
        bttv_dma_free(fh->btv,buf);
130
}
131
 
132
struct videobuf_queue_ops bttv_vbi_qops = {
133
        .buf_setup    = vbi_buffer_setup,
134
        .buf_prepare  = vbi_buffer_prepare,
135
        .buf_queue    = vbi_buffer_queue,
136
        .buf_release  = vbi_buffer_release,
137
};
138
 
139
/* ----------------------------------------------------------------------- */
140
 
141
void bttv_vbi_setlines(struct bttv_fh *fh, struct bttv *btv, int lines)
142
{
143
        int vdelay;
144
 
145
        if (lines < 1)
146
                lines = 1;
147
        if (lines > VBI_MAXLINES)
148
                lines = VBI_MAXLINES;
149
        fh->lines = lines;
150
 
151
        vdelay = btread(BT848_E_VDELAY_LO);
152
        if (vdelay < lines*2) {
153
                vdelay = lines*2;
154
                btwrite(vdelay,BT848_E_VDELAY_LO);
155
                btwrite(vdelay,BT848_O_VDELAY_LO);
156
        }
157
}
158
 
159
void bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_format *f)
160
{
161
        const struct bttv_tvnorm *tvnorm;
162
        u32 start0,start1;
163
        s32 count0,count1,count;
164
 
165
        tvnorm = &bttv_tvnorms[fh->btv->tvnorm];
166
        f->type = V4L2_BUF_TYPE_VBI_CAPTURE;
167
        f->fmt.vbi.sampling_rate    = tvnorm->Fsc;
168
        f->fmt.vbi.samples_per_line = 2048;
169
        f->fmt.vbi.sample_format    = V4L2_PIX_FMT_GREY;
170
        f->fmt.vbi.offset           = 244;
171
        f->fmt.vbi.flags            = 0;
172
        switch (fh->btv->tvnorm) {
173
        case 1: /* NTSC */
174
                start0 = 10;
175
                start1 = 273;
176
                break;
177
        case 0: /* PAL */
178
        case 2: /* SECAM */
179
        default:
180
                start0 = 7;
181
                start1 = 319;
182
        }
183
 
184
        count0 = (f->fmt.vbi.start[0] + f->fmt.vbi.count[0]) - start0;
185
        count1 = (f->fmt.vbi.start[1] + f->fmt.vbi.count[1]) - start1;
186
        count  = max(count0,count1);
187
        if (count > VBI_MAXLINES)
188
                count = VBI_MAXLINES;
189
        if (count < 1)
190
                count = 1;
191
 
192
        f->fmt.vbi.start[0] = start0;
193
        f->fmt.vbi.start[1] = start1;
194
        f->fmt.vbi.count[0] = count;
195
        f->fmt.vbi.count[1] = count;
196
}
197
 
198
void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_format *f)
199
{
200
        const struct bttv_tvnorm *tvnorm;
201
 
202
        tvnorm = &bttv_tvnorms[fh->btv->tvnorm];
203
        memset(f,0,sizeof(*f));
204
        f->type = V4L2_BUF_TYPE_VBI_CAPTURE;
205
        f->fmt.vbi.sampling_rate    = tvnorm->Fsc;
206
        f->fmt.vbi.samples_per_line = 2048;
207
        f->fmt.vbi.sample_format    = V4L2_PIX_FMT_GREY;
208
        f->fmt.vbi.offset           = 244;
209
        f->fmt.vbi.count[0]         = fh->lines;
210
        f->fmt.vbi.count[1]         = fh->lines;
211
        f->fmt.vbi.flags            = 0;
212
        switch (fh->btv->tvnorm) {
213
        case 1: /* NTSC */
214
                f->fmt.vbi.start[0] = 10;
215
                f->fmt.vbi.start[1] = 273;
216
                break;
217
        case 0: /* PAL */
218
        case 2: /* SECAM */
219
        default:
220
                f->fmt.vbi.start[0] = 7;
221
                f->fmt.vbi.start[1] = 319;
222
        }
223
}
224
 
225
/* ----------------------------------------------------------------------- */
226
/*
227
 * Local variables:
228
 * c-basic-offset: 8
229
 * End:
230
 */