26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 #include <linux/module.h>
29 #include <linux/errno.h>
31 #include <linux/kernel.h>
33 #include <linux/kdev_t.h>
47 #define VBI_OFFSET 244
57 #define VBI_DEFLINES 16
59 static unsigned int vbibufs = 4;
60 static unsigned int vbi_debug;
70 #define dprintk(fmt, ...) \
73 pr_debug("%d: " fmt, btv->c.nr, ##__VA_ARGS__); \
76 #define IMAGE_SIZE(fmt) \
77 (((fmt)->count[0] + (fmt)->count[1]) * (fmt)->samples_per_line)
86 struct bttv *btv = fh->btv;
93 dprintk(
"setup: samples=%u start=%d,%d count=%u,%u\n",
94 fh->vbi_fmt.fmt.samples_per_line,
95 fh->vbi_fmt.fmt.start[0],
96 fh->vbi_fmt.fmt.start[1],
97 fh->vbi_fmt.fmt.count[0],
98 fh->vbi_fmt.fmt.count[1]);
108 struct bttv *btv = fh->btv;
110 const struct bttv_tvnorm *
tvnorm;
111 unsigned int skip_lines0, skip_lines1, min_vdelay;
116 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
119 tvnorm = fh->vbi_fmt.tvnorm;
131 if (fh->vbi_fmt.fmt.count[0] > 0)
132 skip_lines0 =
max(0, (fh->vbi_fmt.fmt.start[0]
133 - tvnorm->vbistart[0]));
134 if (fh->vbi_fmt.fmt.count[1] > 0)
135 skip_lines1 =
max(0, (fh->vbi_fmt.fmt.start[1]
136 - tvnorm->vbistart[1]));
140 if (buf->vbi_skip[0] != skip_lines0 ||
141 buf->vbi_skip[1] != skip_lines1 ||
142 buf->vbi_count[0] != fh->vbi_fmt.fmt.count[0] ||
143 buf->vbi_count[1] != fh->vbi_fmt.fmt.count[1]) {
144 buf->vbi_skip[0] = skip_lines0;
145 buf->vbi_skip[1] = skip_lines1;
146 buf->vbi_count[0] = fh->vbi_fmt.fmt.count[0];
147 buf->vbi_count[1] = fh->vbi_fmt.fmt.count[1];
164 if (fh->vbi_fmt.fmt.count[0] > 0) {
168 padding, skip_lines0,
169 fh->vbi_fmt.fmt.count[0]);
174 if (fh->vbi_fmt.fmt.count[1] > 0) {
175 offset = fh->vbi_fmt.fmt.count[0] *
VBI_BPL;
180 padding, skip_lines1,
181 fh->vbi_fmt.fmt.count[1]);
191 min_vdelay = MIN_VDELAY;
192 if (fh->vbi_fmt.end >= tvnorm->cropcap.bounds.top)
193 min_vdelay += fh->vbi_fmt.end - tvnorm->cropcap.bounds.top;
196 buf->geo.vdelay = min_vdelay;
199 buf->vb.field =
field;
200 dprintk(
"buf prepare %p: top=%p bottom=%p field=%s\n",
201 vb, &buf->top, &buf->bottom,
214 struct bttv *btv = fh->btv;
215 struct bttv_buffer *buf =
container_of(vb,
struct bttv_buffer,vb);
220 if (
NULL == btv->cvbi) {
221 fh->btv->loop_irq |= 4;
229 struct bttv *btv = fh->btv;
230 struct bttv_buffer *buf =
container_of(vb,
struct bttv_buffer,vb);
237 .buf_setup = vbi_buffer_setup,
238 .buf_prepare = vbi_buffer_prepare,
239 .buf_queue = vbi_buffer_queue,
240 .buf_release = vbi_buffer_release,
245 static int try_fmt(
struct v4l2_vbi_format *
f,
const struct bttv_tvnorm *tvnorm,
248 __s32 min_start, max_start, max_end, f2_offset;
257 min_start = tvnorm->vbistart[0];
258 max_start = (crop_start >> 1) - 1;
259 max_end = (tvnorm->cropcap.bounds.top
260 + tvnorm->cropcap.bounds.height) >> 1;
262 if (min_start > max_start)
265 BUG_ON(max_start >= max_end);
272 f2_offset = tvnorm->vbistart[1] - tvnorm->vbistart[0];
274 for (i = 0; i < 2; ++
i) {
275 if (0 == f->
count[i]) {
283 start =
clamp(f->
start[i], min_start, max_start);
291 min_start += f2_offset;
292 max_start += f2_offset;
293 max_end += f2_offset;
298 f->
start[0] = tvnorm->vbistart[0];
299 f->
start[1] = tvnorm->vbistart[1];
314 struct bttv_fh *fh =
f;
315 struct bttv *btv = fh->btv;
316 const struct bttv_tvnorm *tvnorm;
322 crop_start = btv->crop_start;
326 return try_fmt(&frt->
fmt.
vbi, tvnorm, crop_start);
332 struct bttv_fh *fh =
f;
333 struct bttv *btv = fh->btv;
334 const struct bttv_tvnorm *tvnorm;
346 rc = try_fmt(&frt->
fmt.
vbi, tvnorm, btv->crop_start);
350 start1 = frt->
fmt.
vbi.start[1] - tvnorm->vbistart[1] +
359 end =
max(frt->
fmt.
vbi.start[0], start1) * 2 + 2;
363 fh->vbi_fmt.fmt = frt->
fmt.
vbi;
364 fh->vbi_fmt.tvnorm = tvnorm;
365 fh->vbi_fmt.end =
end;
380 struct bttv_fh *fh =
f;
381 const struct bttv_tvnorm *tvnorm;
383 frt->
fmt.
vbi = fh->vbi_fmt.fmt;
387 if (tvnorm != fh->vbi_fmt.tvnorm) {
395 max_end = (tvnorm->cropcap.bounds.top
396 + tvnorm->cropcap.bounds.height) >> 1;
398 frt->
fmt.
vbi.sampling_rate = tvnorm->Fsc;
400 for (i = 0; i < 2; ++
i) {
403 new_start = frt->
fmt.
vbi.start[
i]
404 + tvnorm->vbistart[
i]
405 - fh->vbi_fmt.tvnorm->vbistart[
i];
407 frt->
fmt.
vbi.start[
i] =
min(new_start, max_end - 1);
410 max_end - frt->
fmt.
vbi.start[i]);
412 max_end += tvnorm->vbistart[1]
413 - tvnorm->vbistart[0];
421 const struct bttv_tvnorm *tvnorm;
422 unsigned int real_samples_per_line;
423 unsigned int real_count;
427 f->fmt.sampling_rate = tvnorm->Fsc;
428 f->fmt.samples_per_line =
VBI_BPL;
431 f->fmt.start[0] = tvnorm->vbistart[0];
432 f->fmt.start[1] = tvnorm->vbistart[1];
436 f->fmt.reserved[0] = 0;
437 f->fmt.reserved[1] = 0;
441 real_samples_per_line = 1024 + tvnorm->vbipack * 4;
442 real_count = ((tvnorm->cropcap.defrect.top >> 1)
443 - tvnorm->vbistart[0]);
451 f->end = tvnorm->vbistart[0] * 2 + 2;