Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | |
| 3 | bttv - Bt848 frame grabber driver |
| 4 | vbi interface |
| 5 | |
| 6 | (c) 2002 Gerd Knorr <kraxel@bytesex.org> |
| 7 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 8 | Copyright (C) 2005, 2006 Michael H. Schimek <mschimek@gmx.at> |
| 9 | Sponsored by OPQ Systems AB |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | This program is free software; you can redistribute it and/or modify |
| 12 | it under the terms of the GNU General Public License as published by |
| 13 | the Free Software Foundation; either version 2 of the License, or |
| 14 | (at your option) any later version. |
| 15 | |
| 16 | This program is distributed in the hope that it will be useful, |
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | GNU General Public License for more details. |
| 20 | |
| 21 | You should have received a copy of the GNU General Public License |
| 22 | along with this program; if not, write to the Free Software |
| 23 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/errno.h> |
| 28 | #include <linux/fs.h> |
| 29 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/interrupt.h> |
| 31 | #include <linux/kdev_t.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 32 | #include <media/v4l2-ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/io.h> |
| 34 | #include "bttvp.h" |
| 35 | |
Trent Piepho | ddecbe1 | 2006-07-26 17:08:29 -0300 | [diff] [blame] | 36 | /* Offset from line sync pulse leading edge (0H) to start of VBI capture, |
| 37 | in fCLKx2 pixels. According to the datasheet, VBI capture starts |
| 38 | VBI_HDELAY fCLKx1 pixels from the tailing edgeof /HRESET, and /HRESET |
| 39 | is 64 fCLKx1 pixels wide. VBI_HDELAY is set to 0, so this should be |
| 40 | (64 + 0) * 2 = 128 fCLKx2 pixels. But it's not! The datasheet is |
| 41 | Just Plain Wrong. The real value appears to be different for |
| 42 | different revisions of the bt8x8 chips, and to be affected by the |
| 43 | horizontal scaling factor. Experimentally, the value is measured |
| 44 | to be about 244. */ |
| 45 | #define VBI_OFFSET 244 |
Michael H. Schimek | 67f1570 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 46 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 47 | /* 2048 for compatibility with earlier driver versions. The driver |
| 48 | really stores 1024 + tvnorm->vbipack * 4 samples per line in the |
| 49 | buffer. Note tvnorm->vbipack is <= 0xFF (limit of VBIPACK_LO + HI |
| 50 | is 0x1FF DWORDs) and VBI read()s store a frame counter in the last |
| 51 | four bytes of the VBI image. */ |
| 52 | #define VBI_BPL 2048 |
| 53 | |
| 54 | /* Compatibility. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #define VBI_DEFLINES 16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | static unsigned int vbibufs = 4; |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 58 | static unsigned int vbi_debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | module_param(vbibufs, int, 0444); |
| 61 | module_param(vbi_debug, int, 0644); |
| 62 | MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32, default 4"); |
| 63 | MODULE_PARM_DESC(vbi_debug,"vbi code debug messages, default is 0 (no)"); |
| 64 | |
| 65 | #ifdef dprintk |
| 66 | # undef dprintk |
| 67 | #endif |
| 68 | #define dprintk(fmt, arg...) if (vbi_debug) \ |
| 69 | printk(KERN_DEBUG "bttv%d/vbi: " fmt, btv->c.nr , ## arg) |
| 70 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 71 | #define IMAGE_SIZE(fmt) \ |
| 72 | (((fmt)->count[0] + (fmt)->count[1]) * (fmt)->samples_per_line) |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | /* ----------------------------------------------------------------------- */ |
| 75 | /* vbi risc code + mm */ |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | static int vbi_buffer_setup(struct videobuf_queue *q, |
| 78 | unsigned int *count, unsigned int *size) |
| 79 | { |
| 80 | struct bttv_fh *fh = q->priv_data; |
| 81 | struct bttv *btv = fh->btv; |
| 82 | |
| 83 | if (0 == *count) |
| 84 | *count = vbibufs; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 85 | |
| 86 | *size = IMAGE_SIZE(&fh->vbi_fmt.fmt); |
| 87 | |
| 88 | dprintk("setup: samples=%u start=%d,%d count=%u,%u\n", |
| 89 | fh->vbi_fmt.fmt.samples_per_line, |
| 90 | fh->vbi_fmt.fmt.start[0], |
| 91 | fh->vbi_fmt.fmt.start[1], |
| 92 | fh->vbi_fmt.fmt.count[0], |
| 93 | fh->vbi_fmt.fmt.count[1]); |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static int vbi_buffer_prepare(struct videobuf_queue *q, |
| 99 | struct videobuf_buffer *vb, |
| 100 | enum v4l2_field field) |
| 101 | { |
| 102 | struct bttv_fh *fh = q->priv_data; |
| 103 | struct bttv *btv = fh->btv; |
| 104 | struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 105 | const struct bttv_tvnorm *tvnorm; |
| 106 | unsigned int skip_lines0, skip_lines1, min_vdelay; |
| 107 | int redo_dma_risc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | int rc; |
| 109 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 110 | buf->vb.size = IMAGE_SIZE(&fh->vbi_fmt.fmt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 112 | return -EINVAL; |
| 113 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 114 | tvnorm = fh->vbi_fmt.tvnorm; |
| 115 | |
| 116 | /* There's no VBI_VDELAY register, RISC must skip the lines |
| 117 | we don't want. With default parameters we skip zero lines |
| 118 | as earlier driver versions did. The driver permits video |
| 119 | standard changes while capturing, so we use vbi_fmt.tvnorm |
| 120 | instead of btv->tvnorm to skip zero lines after video |
| 121 | standard changes as well. */ |
| 122 | |
| 123 | skip_lines0 = 0; |
| 124 | skip_lines1 = 0; |
| 125 | |
| 126 | if (fh->vbi_fmt.fmt.count[0] > 0) |
| 127 | skip_lines0 = max(0, (fh->vbi_fmt.fmt.start[0] |
| 128 | - tvnorm->vbistart[0])); |
| 129 | if (fh->vbi_fmt.fmt.count[1] > 0) |
| 130 | skip_lines1 = max(0, (fh->vbi_fmt.fmt.start[1] |
| 131 | - tvnorm->vbistart[1])); |
| 132 | |
| 133 | redo_dma_risc = 0; |
| 134 | |
| 135 | if (buf->vbi_skip[0] != skip_lines0 || |
| 136 | buf->vbi_skip[1] != skip_lines1 || |
| 137 | buf->vbi_count[0] != fh->vbi_fmt.fmt.count[0] || |
| 138 | buf->vbi_count[1] != fh->vbi_fmt.fmt.count[1]) { |
| 139 | buf->vbi_skip[0] = skip_lines0; |
| 140 | buf->vbi_skip[1] = skip_lines1; |
| 141 | buf->vbi_count[0] = fh->vbi_fmt.fmt.count[0]; |
| 142 | buf->vbi_count[1] = fh->vbi_fmt.fmt.count[1]; |
| 143 | redo_dma_risc = 1; |
| 144 | } |
| 145 | |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 146 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 147 | redo_dma_risc = 1; |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 148 | if (0 != (rc = videobuf_iolock(q, &buf->vb, NULL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 151 | |
| 152 | if (redo_dma_risc) { |
| 153 | unsigned int bpl, padding, offset; |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 154 | struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 155 | |
| 156 | bpl = 2044; /* max. vbipack */ |
| 157 | padding = VBI_BPL - bpl; |
| 158 | |
| 159 | if (fh->vbi_fmt.fmt.count[0] > 0) { |
| 160 | rc = bttv_risc_packed(btv, &buf->top, |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 161 | dma->sglist, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 162 | /* offset */ 0, bpl, |
| 163 | padding, skip_lines0, |
| 164 | fh->vbi_fmt.fmt.count[0]); |
| 165 | if (0 != rc) |
| 166 | goto fail; |
| 167 | } |
| 168 | |
| 169 | if (fh->vbi_fmt.fmt.count[1] > 0) { |
| 170 | offset = fh->vbi_fmt.fmt.count[0] * VBI_BPL; |
| 171 | |
| 172 | rc = bttv_risc_packed(btv, &buf->bottom, |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 173 | dma->sglist, |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 174 | offset, bpl, |
| 175 | padding, skip_lines1, |
| 176 | fh->vbi_fmt.fmt.count[1]); |
| 177 | if (0 != rc) |
| 178 | goto fail; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | /* VBI capturing ends at VDELAY, start of video capturing, |
| 183 | no matter where the RISC program ends. VDELAY minimum is 2, |
| 184 | bounds.top is the corresponding first field line number |
| 185 | times two. VDELAY counts half field lines. */ |
| 186 | min_vdelay = MIN_VDELAY; |
| 187 | if (fh->vbi_fmt.end >= tvnorm->cropcap.bounds.top) |
| 188 | min_vdelay += fh->vbi_fmt.end - tvnorm->cropcap.bounds.top; |
| 189 | |
| 190 | /* For bttv_buffer_activate_vbi(). */ |
| 191 | buf->geo.vdelay = min_vdelay; |
| 192 | |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 193 | buf->vb.state = VIDEOBUF_PREPARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | buf->vb.field = field; |
| 195 | dprintk("buf prepare %p: top=%p bottom=%p field=%s\n", |
| 196 | vb, &buf->top, &buf->bottom, |
| 197 | v4l2_field_names[buf->vb.field]); |
| 198 | return 0; |
| 199 | |
| 200 | fail: |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 201 | bttv_dma_free(q,btv,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | return rc; |
| 203 | } |
| 204 | |
| 205 | static void |
| 206 | vbi_buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) |
| 207 | { |
| 208 | struct bttv_fh *fh = q->priv_data; |
| 209 | struct bttv *btv = fh->btv; |
| 210 | struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); |
| 211 | |
| 212 | dprintk("queue %p\n",vb); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 213 | buf->vb.state = VIDEOBUF_QUEUED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | list_add_tail(&buf->vb.queue,&btv->vcapture); |
| 215 | if (NULL == btv->cvbi) { |
| 216 | fh->btv->loop_irq |= 4; |
| 217 | bttv_set_dma(btv,0x0c); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | static void vbi_buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) |
| 222 | { |
| 223 | struct bttv_fh *fh = q->priv_data; |
| 224 | struct bttv *btv = fh->btv; |
| 225 | struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); |
| 226 | |
| 227 | dprintk("free %p\n",vb); |
Michael Schimek | feaba7a | 2007-01-26 08:30:05 -0300 | [diff] [blame] | 228 | bttv_dma_free(q,fh->btv,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | struct videobuf_queue_ops bttv_vbi_qops = { |
| 232 | .buf_setup = vbi_buffer_setup, |
| 233 | .buf_prepare = vbi_buffer_prepare, |
| 234 | .buf_queue = vbi_buffer_queue, |
| 235 | .buf_release = vbi_buffer_release, |
| 236 | }; |
| 237 | |
| 238 | /* ----------------------------------------------------------------------- */ |
| 239 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 240 | static int try_fmt(struct v4l2_vbi_format *f, const struct bttv_tvnorm *tvnorm, |
| 241 | __s32 crop_start) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 243 | __s32 min_start, max_start, max_end, f2_offset; |
| 244 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 246 | /* For compatibility with earlier driver versions we must pretend |
| 247 | the VBI and video capture window may overlap. In reality RISC |
| 248 | magic aborts VBI capturing at the first line of video capturing, |
| 249 | leaving the rest of the buffer unchanged, usually all zero. |
| 250 | VBI capturing must always start before video capturing. >> 1 |
| 251 | because cropping counts field lines times two. */ |
| 252 | min_start = tvnorm->vbistart[0]; |
| 253 | max_start = (crop_start >> 1) - 1; |
| 254 | max_end = (tvnorm->cropcap.bounds.top |
| 255 | + tvnorm->cropcap.bounds.height) >> 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 257 | if (min_start > max_start) |
| 258 | return -EBUSY; |
| 259 | |
| 260 | BUG_ON(max_start >= max_end); |
| 261 | |
| 262 | f->sampling_rate = tvnorm->Fsc; |
| 263 | f->samples_per_line = VBI_BPL; |
| 264 | f->sample_format = V4L2_PIX_FMT_GREY; |
| 265 | f->offset = VBI_OFFSET; |
| 266 | |
| 267 | f2_offset = tvnorm->vbistart[1] - tvnorm->vbistart[0]; |
| 268 | |
| 269 | for (i = 0; i < 2; ++i) { |
| 270 | if (0 == f->count[i]) { |
| 271 | /* No data from this field. We leave f->start[i] |
| 272 | alone because VIDIOCSVBIFMT is w/o and EINVALs |
| 273 | when a driver does not support exactly the |
| 274 | requested parameters. */ |
| 275 | } else { |
| 276 | s64 start, count; |
| 277 | |
| 278 | start = clamp(f->start[i], min_start, max_start); |
| 279 | /* s64 to prevent overflow. */ |
| 280 | count = (s64) f->start[i] + f->count[i] - start; |
| 281 | f->start[i] = start; |
| 282 | f->count[i] = clamp(count, (s64) 1, |
| 283 | max_end - start); |
| 284 | } |
| 285 | |
| 286 | min_start += f2_offset; |
| 287 | max_start += f2_offset; |
| 288 | max_end += f2_offset; |
| 289 | } |
| 290 | |
| 291 | if (0 == (f->count[0] | f->count[1])) { |
| 292 | /* As in earlier driver versions. */ |
| 293 | f->start[0] = tvnorm->vbistart[0]; |
| 294 | f->start[1] = tvnorm->vbistart[1]; |
| 295 | f->count[0] = 1; |
| 296 | f->count[1] = 1; |
| 297 | } |
| 298 | |
| 299 | f->flags = 0; |
| 300 | |
| 301 | f->reserved[0] = 0; |
| 302 | f->reserved[1] = 0; |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 307 | int bttv_try_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt) |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 308 | { |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 309 | struct bttv_fh *fh = f; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 310 | struct bttv *btv = fh->btv; |
| 311 | const struct bttv_tvnorm *tvnorm; |
| 312 | __s32 crop_start; |
| 313 | |
| 314 | mutex_lock(&btv->lock); |
| 315 | |
| 316 | tvnorm = &bttv_tvnorms[btv->tvnorm]; |
| 317 | crop_start = btv->crop_start; |
| 318 | |
| 319 | mutex_unlock(&btv->lock); |
| 320 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 321 | return try_fmt(&frt->fmt.vbi, tvnorm, crop_start); |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 322 | } |
| 323 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 324 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 325 | int bttv_s_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt) |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 326 | { |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 327 | struct bttv_fh *fh = f; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 328 | struct bttv *btv = fh->btv; |
| 329 | const struct bttv_tvnorm *tvnorm; |
| 330 | __s32 start1, end; |
| 331 | int rc; |
| 332 | |
| 333 | mutex_lock(&btv->lock); |
| 334 | |
| 335 | rc = -EBUSY; |
| 336 | if (fh->resources & RESOURCE_VBI) |
| 337 | goto fail; |
| 338 | |
| 339 | tvnorm = &bttv_tvnorms[btv->tvnorm]; |
| 340 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 341 | rc = try_fmt(&frt->fmt.vbi, tvnorm, btv->crop_start); |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 342 | if (0 != rc) |
| 343 | goto fail; |
| 344 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 345 | start1 = frt->fmt.vbi.start[1] - tvnorm->vbistart[1] + |
| 346 | tvnorm->vbistart[0]; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 347 | |
| 348 | /* First possible line of video capturing. Should be |
| 349 | max(f->start[0] + f->count[0], start1 + f->count[1]) * 2 |
| 350 | when capturing both fields. But for compatibility we must |
| 351 | pretend the VBI and video capture window may overlap, |
| 352 | so end = start + 1, the lowest possible value, times two |
| 353 | because vbi_fmt.end counts field lines times two. */ |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 354 | end = max(frt->fmt.vbi.start[0], start1) * 2 + 2; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 355 | |
Mauro Carvalho Chehab | 64f9477 | 2008-01-31 13:57:53 -0300 | [diff] [blame] | 356 | mutex_lock(&fh->vbi.vb_lock); |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 357 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 358 | fh->vbi_fmt.fmt = frt->fmt.vbi; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 359 | fh->vbi_fmt.tvnorm = tvnorm; |
| 360 | fh->vbi_fmt.end = end; |
| 361 | |
Mauro Carvalho Chehab | 64f9477 | 2008-01-31 13:57:53 -0300 | [diff] [blame] | 362 | mutex_unlock(&fh->vbi.vb_lock); |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 363 | |
| 364 | rc = 0; |
| 365 | |
| 366 | fail: |
| 367 | mutex_unlock(&btv->lock); |
| 368 | |
| 369 | return rc; |
| 370 | } |
| 371 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 372 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 373 | int bttv_g_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt) |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 374 | { |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 375 | struct bttv_fh *fh = f; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 376 | const struct bttv_tvnorm *tvnorm; |
| 377 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 378 | frt->fmt.vbi = fh->vbi_fmt.fmt; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 379 | |
| 380 | tvnorm = &bttv_tvnorms[fh->btv->tvnorm]; |
| 381 | |
| 382 | if (tvnorm != fh->vbi_fmt.tvnorm) { |
| 383 | __s32 max_end; |
| 384 | unsigned int i; |
| 385 | |
| 386 | /* As in vbi_buffer_prepare() this imitates the |
| 387 | behaviour of earlier driver versions after video |
| 388 | standard changes, with default parameters anyway. */ |
| 389 | |
| 390 | max_end = (tvnorm->cropcap.bounds.top |
| 391 | + tvnorm->cropcap.bounds.height) >> 1; |
| 392 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 393 | frt->fmt.vbi.sampling_rate = tvnorm->Fsc; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 394 | |
| 395 | for (i = 0; i < 2; ++i) { |
| 396 | __s32 new_start; |
| 397 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 398 | new_start = frt->fmt.vbi.start[i] |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 399 | + tvnorm->vbistart[i] |
| 400 | - fh->vbi_fmt.tvnorm->vbistart[i]; |
| 401 | |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 402 | frt->fmt.vbi.start[i] = min(new_start, max_end - 1); |
| 403 | frt->fmt.vbi.count[i] = |
| 404 | min((__s32) frt->fmt.vbi.count[i], |
| 405 | max_end - frt->fmt.vbi.start[i]); |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 406 | |
| 407 | max_end += tvnorm->vbistart[1] |
| 408 | - tvnorm->vbistart[0]; |
| 409 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
Douglas Schilling Landgraf | 402aa76 | 2007-12-27 22:20:58 -0300 | [diff] [blame] | 411 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Trent Piepho | 4ef2ccc | 2009-01-28 21:32:58 -0300 | [diff] [blame^] | 414 | void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
| 416 | const struct bttv_tvnorm *tvnorm; |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 417 | unsigned int real_samples_per_line; |
| 418 | unsigned int real_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 420 | tvnorm = &bttv_tvnorms[norm]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 422 | f->fmt.sampling_rate = tvnorm->Fsc; |
| 423 | f->fmt.samples_per_line = VBI_BPL; |
| 424 | f->fmt.sample_format = V4L2_PIX_FMT_GREY; |
| 425 | f->fmt.offset = VBI_OFFSET; |
| 426 | f->fmt.start[0] = tvnorm->vbistart[0]; |
| 427 | f->fmt.start[1] = tvnorm->vbistart[1]; |
| 428 | f->fmt.count[0] = VBI_DEFLINES; |
| 429 | f->fmt.count[1] = VBI_DEFLINES; |
| 430 | f->fmt.flags = 0; |
| 431 | f->fmt.reserved[0] = 0; |
| 432 | f->fmt.reserved[1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 434 | /* For compatibility the buffer size must be 2 * VBI_DEFLINES * |
| 435 | VBI_BPL regardless of the current video standard. */ |
| 436 | real_samples_per_line = 1024 + tvnorm->vbipack * 4; |
| 437 | real_count = ((tvnorm->cropcap.defrect.top >> 1) |
| 438 | - tvnorm->vbistart[0]); |
Michael H. Schimek | 67f1570 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 439 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 440 | BUG_ON(real_samples_per_line > VBI_BPL); |
| 441 | BUG_ON(real_count > VBI_DEFLINES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 443 | f->tvnorm = tvnorm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
Michael Schimek | e5bd026 | 2007-01-18 16:17:39 -0300 | [diff] [blame] | 445 | /* See bttv_vbi_fmt_set(). */ |
| 446 | f->end = tvnorm->vbistart[0] * 2 + 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | /* ----------------------------------------------------------------------- */ |
| 450 | /* |
| 451 | * Local variables: |
| 452 | * c-basic-offset: 8 |
| 453 | * End: |
| 454 | */ |