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" |
Mauro Carvalho Chehab | 01c2819 | 2013-12-22 13:27:02 -0300 | [diff] [blame] | 30 | #include "em28xx-v4l.h" |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 31 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 32 | /* ------------------------------------------------------------------ */ |
| 33 | |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 34 | static int vbi_queue_setup(struct vb2_queue *vq, |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 35 | unsigned int *nbuffers, unsigned int *nplanes, |
Hans Verkuil | 36c0f8b | 2016-04-15 09:15:05 -0300 | [diff] [blame^] | 36 | unsigned int sizes[], struct device *alloc_devs[]) |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 37 | { |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 38 | struct em28xx *dev = vb2_get_drv_priv(vq); |
Frank Schaefer | 753aee7 | 2014-03-24 16:33:14 -0300 | [diff] [blame] | 39 | struct em28xx_v4l2 *v4l2 = dev->v4l2; |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 40 | unsigned long size = v4l2->vbi_width * v4l2->vbi_height * 2; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 41 | |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 42 | if (*nbuffers < 2) |
| 43 | *nbuffers = 2; |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 44 | |
| 45 | if (*nplanes) { |
| 46 | if (sizes[0] < size) |
| 47 | return -EINVAL; |
| 48 | size = sizes[0]; |
| 49 | } |
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 | *nplanes = 1; |
| 52 | sizes[0] = size; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 53 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 54 | return 0; |
| 55 | } |
| 56 | |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 57 | static int vbi_buffer_prepare(struct vb2_buffer *vb) |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 58 | { |
Frank Schaefer | 753aee7 | 2014-03-24 16:33:14 -0300 | [diff] [blame] | 59 | struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue); |
| 60 | struct em28xx_v4l2 *v4l2 = dev->v4l2; |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 61 | unsigned long size; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 62 | |
Frank Schaefer | 753aee7 | 2014-03-24 16:33:14 -0300 | [diff] [blame] | 63 | size = v4l2->vbi_width * v4l2->vbi_height * 2; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 64 | |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 65 | if (vb2_plane_size(vb, 0) < size) { |
| 66 | printk(KERN_INFO "%s data will not fit into plane (%lu < %lu)\n", |
| 67 | __func__, vb2_plane_size(vb, 0), size); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 68 | return -EINVAL; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 69 | } |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 70 | vb2_set_plane_payload(vb, 0, size); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 71 | |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 72 | return 0; |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static void |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 76 | vbi_buffer_queue(struct vb2_buffer *vb) |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 77 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 78 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 79 | struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 80 | struct em28xx_buffer *buf = |
| 81 | container_of(vbuf, struct em28xx_buffer, vb); |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 82 | struct em28xx_dmaqueue *vbiq = &dev->vbiq; |
| 83 | unsigned long flags = 0; |
| 84 | |
| 85 | buf->mem = vb2_plane_vaddr(vb, 0); |
| 86 | buf->length = vb2_plane_size(vb, 0); |
| 87 | |
| 88 | spin_lock_irqsave(&dev->slock, flags); |
| 89 | list_add_tail(&buf->list, &vbiq->active); |
| 90 | spin_unlock_irqrestore(&dev->slock, flags); |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 91 | } |
| 92 | |
Devin Heitmueller | d3829fa | 2013-01-04 16:16:24 -0300 | [diff] [blame] | 93 | struct vb2_ops em28xx_vbi_qops = { |
| 94 | .queue_setup = vbi_queue_setup, |
| 95 | .buf_prepare = vbi_buffer_prepare, |
| 96 | .buf_queue = vbi_buffer_queue, |
| 97 | .start_streaming = em28xx_start_analog_streaming, |
| 98 | .stop_streaming = em28xx_stop_vbi_streaming, |
| 99 | .wait_prepare = vb2_ops_wait_prepare, |
| 100 | .wait_finish = vb2_ops_wait_finish, |
Devin Heitmueller | 28abf083 | 2009-09-01 01:54:54 -0300 | [diff] [blame] | 101 | }; |