Path: blob/master/drivers/media/video/em28xx/em28xx-vbi.c
17962 views
/*1em28xx-vbi.c - VBI driver for em28xx23Copyright (C) 2009 Devin Heitmueller <[email protected]>45This work was sponsored by EyeMagnet Limited.67This program is free software; you can redistribute it and/or modify8it under the terms of the GNU General Public License as published by9the Free Software Foundation; either version 2 of the License, or10(at your option) any later version.1112This program is distributed in the hope that it will be useful,13but WITHOUT ANY WARRANTY; without even the implied warranty of14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15GNU General Public License for more details.1617You should have received a copy of the GNU General Public License18along with this program; if not, write to the Free Software19Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA2002110-1301, USA.21*/2223#include <linux/kernel.h>24#include <linux/module.h>25#include <linux/hardirq.h>26#include <linux/init.h>2728#include "em28xx.h"2930static unsigned int vbibufs = 5;31module_param(vbibufs, int, 0644);32MODULE_PARM_DESC(vbibufs, "number of vbi buffers, range 2-32");3334static unsigned int vbi_debug;35module_param(vbi_debug, int, 0644);36MODULE_PARM_DESC(vbi_debug, "enable debug messages [vbi]");3738#define dprintk(level, fmt, arg...) if (vbi_debug >= level) \39printk(KERN_DEBUG "%s: " fmt, dev->core->name , ## arg)4041/* ------------------------------------------------------------------ */4243static void44free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf)45{46struct em28xx_fh *fh = vq->priv_data;47struct em28xx *dev = fh->dev;48unsigned long flags = 0;49if (in_interrupt())50BUG();5152/* We used to wait for the buffer to finish here, but this didn't work53because, as we were keeping the state as VIDEOBUF_QUEUED,54videobuf_queue_cancel marked it as finished for us.55(Also, it could wedge forever if the hardware was misconfigured.)5657This should be safe; by the time we get here, the buffer isn't58queued anymore. If we ever start marking the buffers as59VIDEOBUF_ACTIVE, it won't be, though.60*/61spin_lock_irqsave(&dev->slock, flags);62if (dev->isoc_ctl.vbi_buf == buf)63dev->isoc_ctl.vbi_buf = NULL;64spin_unlock_irqrestore(&dev->slock, flags);6566videobuf_vmalloc_free(&buf->vb);67buf->vb.state = VIDEOBUF_NEEDS_INIT;68}6970static int71vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)72{73struct em28xx_fh *fh = q->priv_data;74struct em28xx *dev = fh->dev;7576*size = dev->vbi_width * dev->vbi_height * 2;7778if (0 == *count)79*count = vbibufs;80if (*count < 2)81*count = 2;82if (*count > 32)83*count = 32;84return 0;85}8687static int88vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,89enum v4l2_field field)90{91struct em28xx_fh *fh = q->priv_data;92struct em28xx *dev = fh->dev;93struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);94int rc = 0;9596buf->vb.size = dev->vbi_width * dev->vbi_height * 2;9798if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)99return -EINVAL;100101buf->vb.width = dev->vbi_width;102buf->vb.height = dev->vbi_height;103buf->vb.field = field;104105if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {106rc = videobuf_iolock(q, &buf->vb, NULL);107if (rc < 0)108goto fail;109}110111buf->vb.state = VIDEOBUF_PREPARED;112return 0;113114fail:115free_buffer(q, buf);116return rc;117}118119static void120vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)121{122struct em28xx_buffer *buf = container_of(vb,123struct em28xx_buffer,124vb);125struct em28xx_fh *fh = vq->priv_data;126struct em28xx *dev = fh->dev;127struct em28xx_dmaqueue *vbiq = &dev->vbiq;128129buf->vb.state = VIDEOBUF_QUEUED;130list_add_tail(&buf->vb.queue, &vbiq->active);131}132133static void vbi_release(struct videobuf_queue *q, struct videobuf_buffer *vb)134{135struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);136free_buffer(q, buf);137}138139struct videobuf_queue_ops em28xx_vbi_qops = {140.buf_setup = vbi_setup,141.buf_prepare = vbi_prepare,142.buf_queue = vbi_queue,143.buf_release = vbi_release,144};145146147