]>
Commit | Line | Data |
---|---|---|
28abf083 DH |
1 | /* |
2 | em28xx-vbi.c - VBI driver for em28xx | |
3 | ||
4 | Copyright (C) 2009 Devin Heitmueller <dheitmueller@kernellabs.com> | |
5 | ||
6 | This work was sponsored by EyeMagnet Limited. | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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., 51 Franklin Street, Fifth Floor, Boston, MA | |
21 | 02110-1301, USA. | |
22 | */ | |
23 | ||
24 | #include <linux/kernel.h> | |
25 | #include <linux/module.h> | |
c59a9bfa | 26 | #include <linux/hardirq.h> |
28abf083 | 27 | #include <linux/init.h> |
28abf083 DH |
28 | |
29 | #include "em28xx.h" | |
01c28193 | 30 | #include "em28xx-v4l.h" |
28abf083 | 31 | |
28abf083 DH |
32 | /* ------------------------------------------------------------------ */ |
33 | ||
d3829fad DH |
34 | static int vbi_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt, |
35 | unsigned int *nbuffers, unsigned int *nplanes, | |
36 | unsigned int sizes[], void *alloc_ctxs[]) | |
28abf083 | 37 | { |
d3829fad | 38 | struct em28xx *dev = vb2_get_drv_priv(vq); |
753aee77 | 39 | struct em28xx_v4l2 *v4l2 = dev->v4l2; |
d3829fad | 40 | unsigned long size; |
28abf083 | 41 | |
d3829fad DH |
42 | if (fmt) |
43 | size = fmt->fmt.pix.sizeimage; | |
44 | else | |
753aee77 | 45 | size = v4l2->vbi_width * v4l2->vbi_height * 2; |
28abf083 | 46 | |
d3829fad DH |
47 | if (0 == *nbuffers) |
48 | *nbuffers = 32; | |
49 | if (*nbuffers < 2) | |
50 | *nbuffers = 2; | |
51 | if (*nbuffers > 32) | |
52 | *nbuffers = 32; | |
66d9cbad | 53 | |
d3829fad DH |
54 | *nplanes = 1; |
55 | sizes[0] = size; | |
66d9cbad | 56 | |
28abf083 DH |
57 | return 0; |
58 | } | |
59 | ||
d3829fad | 60 | static int vbi_buffer_prepare(struct vb2_buffer *vb) |
28abf083 | 61 | { |
753aee77 FS |
62 | struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue); |
63 | struct em28xx_v4l2 *v4l2 = dev->v4l2; | |
d3829fad | 64 | unsigned long size; |
28abf083 | 65 | |
753aee77 | 66 | size = v4l2->vbi_width * v4l2->vbi_height * 2; |
28abf083 | 67 | |
d3829fad DH |
68 | if (vb2_plane_size(vb, 0) < size) { |
69 | printk(KERN_INFO "%s data will not fit into plane (%lu < %lu)\n", | |
70 | __func__, vb2_plane_size(vb, 0), size); | |
28abf083 | 71 | return -EINVAL; |
28abf083 | 72 | } |
2d700715 | 73 | vb2_set_plane_payload(vb, 0, size); |
28abf083 | 74 | |
28abf083 | 75 | return 0; |
28abf083 DH |
76 | } |
77 | ||
78 | static void | |
d3829fad | 79 | vbi_buffer_queue(struct vb2_buffer *vb) |
28abf083 | 80 | { |
2d700715 | 81 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
d3829fad | 82 | struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue); |
2d700715 JS |
83 | struct em28xx_buffer *buf = |
84 | container_of(vbuf, struct em28xx_buffer, vb); | |
d3829fad DH |
85 | struct em28xx_dmaqueue *vbiq = &dev->vbiq; |
86 | unsigned long flags = 0; | |
87 | ||
88 | buf->mem = vb2_plane_vaddr(vb, 0); | |
89 | buf->length = vb2_plane_size(vb, 0); | |
90 | ||
91 | spin_lock_irqsave(&dev->slock, flags); | |
92 | list_add_tail(&buf->list, &vbiq->active); | |
93 | spin_unlock_irqrestore(&dev->slock, flags); | |
28abf083 DH |
94 | } |
95 | ||
d3829fad DH |
96 | struct vb2_ops em28xx_vbi_qops = { |
97 | .queue_setup = vbi_queue_setup, | |
98 | .buf_prepare = vbi_buffer_prepare, | |
99 | .buf_queue = vbi_buffer_queue, | |
100 | .start_streaming = em28xx_start_analog_streaming, | |
101 | .stop_streaming = em28xx_stop_vbi_streaming, | |
102 | .wait_prepare = vb2_ops_wait_prepare, | |
103 | .wait_finish = vb2_ops_wait_finish, | |
28abf083 | 104 | }; |