Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 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> |
Randy Dunlap | c59a9bf | 2010-12-07 15:50:09 -0300 | [diff] [blame] | 26 | #include <linux/hardirq.h> |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 27 | #include <linux/init.h> |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 28 | |
| 29 | #include "em28xx.h" |
| 30 | |
| 31 | static unsigned int vbibufs = 5; |
Devin Heitmueller | cb0409f | 2009-09-15 00:10:15 -0300 | [diff] [blame] | 32 | module_param(vbibufs, int, 0644); |
| 33 | MODULE_PARM_DESC(vbibufs, "number of vbi buffers, range 2-32"); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 34 | |
| 35 | static unsigned int vbi_debug; |
Devin Heitmueller | cb0409f | 2009-09-15 00:10:15 -0300 | [diff] [blame] | 36 | module_param(vbi_debug, int, 0644); |
| 37 | MODULE_PARM_DESC(vbi_debug, "enable debug messages [vbi]"); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 38 | |
Devin Heitmueller | cb0409f | 2009-09-15 00:10:15 -0300 | [diff] [blame] | 39 | #define dprintk(level, fmt, arg...) if (vbi_debug >= level) \ |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 40 | printk(KERN_DEBUG "%s: " fmt, dev->core->name , ## arg) |
| 41 | |
| 42 | /* ------------------------------------------------------------------ */ |
| 43 | |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 44 | static int vbi_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt, |
| 45 | unsigned int *nbuffers, unsigned int *nplanes, |
| 46 | unsigned int sizes[], void *alloc_ctxs[]) |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 47 | { |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 48 | struct em28xx *dev = vb2_get_drv_priv(vq); |
| 49 | unsigned long size; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 50 | |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 51 | if (fmt) |
| 52 | size = fmt->fmt.pix.sizeimage; |
| 53 | else |
| 54 | size = dev->vbi_width * dev->vbi_height * 2; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 55 | |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 56 | if (0 == *nbuffers) |
| 57 | *nbuffers = 32; |
| 58 | if (*nbuffers < 2) |
| 59 | *nbuffers = 2; |
| 60 | if (*nbuffers > 32) |
| 61 | *nbuffers = 32; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 62 | |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 63 | *nplanes = 1; |
| 64 | sizes[0] = size; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 65 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 69 | static int vbi_buffer_prepare(struct vb2_buffer *vb) |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 70 | { |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 71 | struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 72 | struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 73 | unsigned long size; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 74 | |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 75 | size = dev->vbi_width * dev->vbi_height * 2; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 76 | |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 77 | if (vb2_plane_size(vb, 0) < size) { |
| 78 | printk(KERN_INFO "%s data will not fit into plane (%lu < %lu)\n", |
| 79 | __func__, vb2_plane_size(vb, 0), size); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 80 | return -EINVAL; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 81 | } |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 82 | vb2_set_plane_payload(&buf->vb, 0, size); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 83 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 84 | return 0; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static void |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 88 | vbi_buffer_queue(struct vb2_buffer *vb) |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 89 | { |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 90 | struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 91 | struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 92 | struct em28xx_dmaqueue *vbiq = &dev->vbiq; |
| 93 | unsigned long flags = 0; |
| 94 | |
| 95 | buf->mem = vb2_plane_vaddr(vb, 0); |
| 96 | buf->length = vb2_plane_size(vb, 0); |
| 97 | |
| 98 | spin_lock_irqsave(&dev->slock, flags); |
| 99 | list_add_tail(&buf->list, &vbiq->active); |
| 100 | spin_unlock_irqrestore(&dev->slock, flags); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 101 | } |
| 102 | |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 103 | |
| 104 | struct vb2_ops em28xx_vbi_qops = { |
| 105 | .queue_setup = vbi_queue_setup, |
| 106 | .buf_prepare = vbi_buffer_prepare, |
| 107 | .buf_queue = vbi_buffer_queue, |
| 108 | .start_streaming = em28xx_start_analog_streaming, |
| 109 | .stop_streaming = em28xx_stop_vbi_streaming, |
| 110 | .wait_prepare = vb2_ops_wait_prepare, |
| 111 | .wait_finish = vb2_ops_wait_finish, |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 112 | }; |