2009-09-16 17:31:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 Texas Instruments Inc
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* TODO : add support for VBI & HBI data service
|
|
|
|
* add static buffer allocation
|
|
|
|
*/
|
2013-04-19 08:53:29 +00:00
|
|
|
|
2009-09-16 17:31:10 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/platform_device.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2013-04-19 08:53:29 +00:00
|
|
|
|
|
|
|
#include <media/v4l2-ioctl.h>
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
#include "vpif.h"
|
2013-04-19 08:53:29 +00:00
|
|
|
#include "vpif_capture.h"
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("TI DaVinci VPIF Capture driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2011-06-25 14:28:37 +00:00
|
|
|
MODULE_VERSION(VPIF_CAPTURE_VERSION);
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
#define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg)
|
|
|
|
#define vpif_dbg(level, debug, fmt, arg...) \
|
|
|
|
v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg)
|
|
|
|
|
|
|
|
static int debug = 1;
|
|
|
|
static u32 ch0_numbuffers = 3;
|
|
|
|
static u32 ch1_numbuffers = 3;
|
|
|
|
static u32 ch0_bufsize = 1920 * 1080 * 2;
|
|
|
|
static u32 ch1_bufsize = 720 * 576 * 2;
|
|
|
|
|
|
|
|
module_param(debug, int, 0644);
|
|
|
|
module_param(ch0_numbuffers, uint, S_IRUGO);
|
|
|
|
module_param(ch1_numbuffers, uint, S_IRUGO);
|
|
|
|
module_param(ch0_bufsize, uint, S_IRUGO);
|
|
|
|
module_param(ch1_bufsize, uint, S_IRUGO);
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(debug, "Debug level 0-1");
|
|
|
|
MODULE_PARM_DESC(ch2_numbuffers, "Channel0 buffer count (default:3)");
|
|
|
|
MODULE_PARM_DESC(ch3_numbuffers, "Channel1 buffer count (default:3)");
|
|
|
|
MODULE_PARM_DESC(ch2_bufsize, "Channel0 buffer size (default:1920 x 1080 x 2)");
|
|
|
|
MODULE_PARM_DESC(ch3_bufsize, "Channel1 buffer size (default:720 x 576 x 2)");
|
|
|
|
|
|
|
|
static struct vpif_config_params config_params = {
|
|
|
|
.min_numbuffers = 3,
|
|
|
|
.numbuffers[0] = 3,
|
|
|
|
.numbuffers[1] = 3,
|
|
|
|
.min_bufsize[0] = 720 * 480 * 2,
|
|
|
|
.min_bufsize[1] = 720 * 480 * 2,
|
|
|
|
.channel_bufsize[0] = 1920 * 1080 * 2,
|
|
|
|
.channel_bufsize[1] = 720 * 576 * 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* global variables */
|
|
|
|
static struct vpif_device vpif_obj = { {NULL} };
|
|
|
|
static struct device *vpif_dev;
|
2012-06-28 12:28:05 +00:00
|
|
|
static void vpif_calculate_offsets(struct channel_obj *ch);
|
|
|
|
static void vpif_config_addr(struct channel_obj *ch, int muxmode);
|
2009-09-16 17:31:10 +00:00
|
|
|
|
2014-05-16 13:33:31 +00:00
|
|
|
static u8 channel_first_int[VPIF_NUMBER_OF_OBJECTS][2] = { {1, 1} };
|
|
|
|
|
|
|
|
static inline struct vpif_cap_buffer *to_vpif_buffer(struct vb2_buffer *vb)
|
|
|
|
{
|
|
|
|
return container_of(vb, struct vpif_cap_buffer, vb);
|
|
|
|
}
|
|
|
|
|
2009-09-16 17:31:10 +00:00
|
|
|
/**
|
2014-05-16 13:33:37 +00:00
|
|
|
* vpif_buffer_prepare : callback function for buffer prepare
|
2012-06-28 12:28:05 +00:00
|
|
|
* @vb: ptr to vb2_buffer
|
2009-09-16 17:31:10 +00:00
|
|
|
*
|
2012-06-28 12:28:05 +00:00
|
|
|
* This is the callback function for buffer prepare when vb2_qbuf()
|
2009-09-16 17:31:10 +00:00
|
|
|
* function is called. The buffer is prepared and user space virtual address
|
|
|
|
* or user address is converted into physical address
|
|
|
|
*/
|
2012-06-28 12:28:05 +00:00
|
|
|
static int vpif_buffer_prepare(struct vb2_buffer *vb)
|
2009-09-16 17:31:10 +00:00
|
|
|
{
|
2012-06-28 12:28:05 +00:00
|
|
|
struct vb2_queue *q = vb->vb2_queue;
|
2014-05-16 13:33:31 +00:00
|
|
|
struct channel_obj *ch = vb2_get_drv_priv(q);
|
2009-09-16 17:31:10 +00:00
|
|
|
struct common_obj *common;
|
|
|
|
unsigned long addr;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_buffer_prepare\n");
|
|
|
|
|
|
|
|
common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
|
2014-05-16 13:33:37 +00:00
|
|
|
vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage);
|
|
|
|
if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
vb->v4l2_buf.field = common->fmt.fmt.pix.field;
|
|
|
|
|
|
|
|
addr = vb2_dma_contig_plane_dma_addr(vb, 0);
|
|
|
|
if (!IS_ALIGNED((addr + common->ytop_off), 8) ||
|
|
|
|
!IS_ALIGNED((addr + common->ybtm_off), 8) ||
|
|
|
|
!IS_ALIGNED((addr + common->ctop_off), 8) ||
|
|
|
|
!IS_ALIGNED((addr + common->cbtm_off), 8)) {
|
|
|
|
vpif_dbg(1, debug, "offset is not aligned\n");
|
|
|
|
return -EINVAL;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
2014-05-16 13:33:37 +00:00
|
|
|
|
2009-09-16 17:31:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-28 12:28:05 +00:00
|
|
|
* vpif_buffer_queue_setup : Callback function for buffer setup.
|
|
|
|
* @vq: vb2_queue ptr
|
|
|
|
* @fmt: v4l2 format
|
|
|
|
* @nbuffers: ptr to number of buffers requested by application
|
|
|
|
* @nplanes:: contains number of distinct video planes needed to hold a frame
|
|
|
|
* @sizes[]: contains the size (in bytes) of each plane.
|
|
|
|
* @alloc_ctxs: ptr to allocation context
|
2009-09-16 17:31:10 +00:00
|
|
|
*
|
|
|
|
* This callback function is called when reqbuf() is called to adjust
|
|
|
|
* the buffer count and buffer size
|
|
|
|
*/
|
2012-06-28 12:28:05 +00:00
|
|
|
static int vpif_buffer_queue_setup(struct vb2_queue *vq,
|
|
|
|
const struct v4l2_format *fmt,
|
|
|
|
unsigned int *nbuffers, unsigned int *nplanes,
|
|
|
|
unsigned int sizes[], void *alloc_ctxs[])
|
2009-09-16 17:31:10 +00:00
|
|
|
{
|
2014-05-16 13:33:31 +00:00
|
|
|
struct channel_obj *ch = vb2_get_drv_priv(vq);
|
2009-09-16 17:31:10 +00:00
|
|
|
struct common_obj *common;
|
|
|
|
|
|
|
|
common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_buffer_setup\n");
|
|
|
|
|
2014-05-16 13:33:38 +00:00
|
|
|
if (fmt && fmt->fmt.pix.sizeimage < common->fmt.fmt.pix.sizeimage)
|
|
|
|
return -EINVAL;
|
2012-04-13 07:49:34 +00:00
|
|
|
|
2014-05-16 13:33:38 +00:00
|
|
|
if (vq->num_buffers + *nbuffers < 3)
|
|
|
|
*nbuffers = 3 - vq->num_buffers;
|
2012-06-28 12:28:05 +00:00
|
|
|
|
|
|
|
*nplanes = 1;
|
2014-05-16 13:33:38 +00:00
|
|
|
sizes[0] = fmt ? fmt->fmt.pix.sizeimage : common->fmt.fmt.pix.sizeimage;
|
2012-06-28 12:28:05 +00:00
|
|
|
alloc_ctxs[0] = common->alloc_ctx;
|
|
|
|
|
2014-05-16 13:33:38 +00:00
|
|
|
/* Calculate the offset for Y and C data in the buffer */
|
|
|
|
vpif_calculate_offsets(ch);
|
|
|
|
|
2009-09-16 17:31:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_buffer_queue : Callback function to add buffer to DMA queue
|
2012-06-28 12:28:05 +00:00
|
|
|
* @vb: ptr to vb2_buffer
|
2009-09-16 17:31:10 +00:00
|
|
|
*/
|
2012-06-28 12:28:05 +00:00
|
|
|
static void vpif_buffer_queue(struct vb2_buffer *vb)
|
2009-09-16 17:31:10 +00:00
|
|
|
{
|
2014-05-16 13:33:31 +00:00
|
|
|
struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue);
|
|
|
|
struct vpif_cap_buffer *buf = to_vpif_buffer(vb);
|
2009-09-16 17:31:10 +00:00
|
|
|
struct common_obj *common;
|
2012-11-16 15:03:06 +00:00
|
|
|
unsigned long flags;
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_buffer_queue\n");
|
|
|
|
|
2012-11-16 15:03:06 +00:00
|
|
|
spin_lock_irqsave(&common->irqlock, flags);
|
2009-09-16 17:31:10 +00:00
|
|
|
/* add the buffer to the DMA queue */
|
2012-06-28 12:28:05 +00:00
|
|
|
list_add_tail(&buf->list, &common->dma_queue);
|
2012-11-16 15:03:06 +00:00
|
|
|
spin_unlock_irqrestore(&common->irqlock, flags);
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 13:33:39 +00:00
|
|
|
/**
|
|
|
|
* vpif_start_streaming : Starts the DMA engine for streaming
|
|
|
|
* @vb: ptr to vb2_buffer
|
|
|
|
* @count: number of buffers
|
|
|
|
*/
|
2012-06-28 12:28:05 +00:00
|
|
|
static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
|
|
|
|
{
|
|
|
|
struct vpif_capture_config *vpif_config_data =
|
|
|
|
vpif_dev->platform_data;
|
2014-05-16 13:33:31 +00:00
|
|
|
struct channel_obj *ch = vb2_get_drv_priv(vq);
|
2012-06-28 12:28:05 +00:00
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
struct vpif_params *vpif = &ch->vpifparams;
|
2014-05-16 13:33:35 +00:00
|
|
|
struct vpif_cap_buffer *buf, *tmp;
|
|
|
|
unsigned long addr, flags;
|
2012-06-28 12:28:05 +00:00
|
|
|
int ret;
|
|
|
|
|
2012-11-16 15:03:06 +00:00
|
|
|
spin_lock_irqsave(&common->irqlock, flags);
|
2012-06-28 12:28:05 +00:00
|
|
|
|
|
|
|
/* Initialize field_id and started member */
|
|
|
|
ch->field_id = 0;
|
|
|
|
common->started = 1;
|
|
|
|
|
|
|
|
/* configure 1 or 2 channel mode */
|
2012-09-27 05:33:12 +00:00
|
|
|
if (vpif_config_data->setup_input_channel_mode) {
|
|
|
|
ret = vpif_config_data->
|
|
|
|
setup_input_channel_mode(vpif->std_info.ycmux_mode);
|
|
|
|
if (ret < 0) {
|
|
|
|
vpif_dbg(1, debug, "can't set vpif channel mode\n");
|
2014-05-16 13:33:35 +00:00
|
|
|
goto err;
|
2012-09-27 05:33:12 +00:00
|
|
|
}
|
2012-06-28 12:28:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Call vpif_set_params function to set the parameters and addresses */
|
|
|
|
ret = vpif_set_video_params(vpif, ch->channel_id);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
vpif_dbg(1, debug, "can't set video params\n");
|
2014-05-16 13:33:35 +00:00
|
|
|
goto err;
|
2012-06-28 12:28:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
common->started = ret;
|
|
|
|
vpif_config_addr(ch, ret);
|
|
|
|
|
2014-05-16 13:33:35 +00:00
|
|
|
/* Get the next frame from the buffer queue */
|
|
|
|
common->cur_frm = common->next_frm = list_entry(common->dma_queue.next,
|
|
|
|
struct vpif_cap_buffer, list);
|
|
|
|
/* Remove buffer from the buffer queue */
|
|
|
|
list_del(&common->cur_frm->list);
|
|
|
|
spin_unlock_irqrestore(&common->irqlock, flags);
|
|
|
|
/* Mark state of the current frame to active */
|
|
|
|
common->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE;
|
|
|
|
|
|
|
|
addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0);
|
|
|
|
|
2012-06-28 12:28:05 +00:00
|
|
|
common->set_addr(addr + common->ytop_off,
|
|
|
|
addr + common->ybtm_off,
|
|
|
|
addr + common->ctop_off,
|
|
|
|
addr + common->cbtm_off);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set interrupt for both the fields in VPIF Register enable channel in
|
|
|
|
* VPIF register
|
|
|
|
*/
|
2012-09-14 13:22:24 +00:00
|
|
|
channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1;
|
2014-05-16 13:33:39 +00:00
|
|
|
if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
|
2012-06-28 12:28:05 +00:00
|
|
|
channel0_intr_assert();
|
|
|
|
channel0_intr_enable(1);
|
|
|
|
enable_channel0(1);
|
|
|
|
}
|
2014-05-16 13:33:39 +00:00
|
|
|
if (VPIF_CHANNEL1_VIDEO == ch->channel_id ||
|
|
|
|
common->started == 2) {
|
2012-06-28 12:28:05 +00:00
|
|
|
channel1_intr_assert();
|
|
|
|
channel1_intr_enable(1);
|
|
|
|
enable_channel1(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-05-16 13:33:35 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
list_for_each_entry_safe(buf, tmp, &common->dma_queue, list) {
|
|
|
|
list_del(&buf->list);
|
|
|
|
vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2012-06-28 12:28:05 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 13:33:39 +00:00
|
|
|
/**
|
|
|
|
* vpif_stop_streaming : Stop the DMA engine
|
|
|
|
* @vq: ptr to vb2_queue
|
|
|
|
*
|
|
|
|
* This callback stops the DMA engine and any remaining buffers
|
|
|
|
* in the DMA queue are released.
|
|
|
|
*/
|
2014-04-17 05:47:21 +00:00
|
|
|
static void vpif_stop_streaming(struct vb2_queue *vq)
|
2012-06-28 12:28:05 +00:00
|
|
|
{
|
2014-05-16 13:33:31 +00:00
|
|
|
struct channel_obj *ch = vb2_get_drv_priv(vq);
|
2012-06-28 12:28:05 +00:00
|
|
|
struct common_obj *common;
|
2012-11-16 15:03:06 +00:00
|
|
|
unsigned long flags;
|
2012-06-28 12:28:05 +00:00
|
|
|
|
|
|
|
common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
|
2014-03-22 11:03:07 +00:00
|
|
|
/* Disable channel as per its device type and channel id */
|
|
|
|
if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
|
|
|
|
enable_channel0(0);
|
|
|
|
channel0_intr_enable(0);
|
|
|
|
}
|
2014-05-16 13:33:39 +00:00
|
|
|
if (VPIF_CHANNEL1_VIDEO == ch->channel_id ||
|
|
|
|
2 == common->started) {
|
2014-03-22 11:03:07 +00:00
|
|
|
enable_channel1(0);
|
|
|
|
channel1_intr_enable(0);
|
|
|
|
}
|
|
|
|
common->started = 0;
|
|
|
|
|
2012-06-28 12:28:05 +00:00
|
|
|
/* release all active buffers */
|
2012-11-16 15:03:06 +00:00
|
|
|
spin_lock_irqsave(&common->irqlock, flags);
|
2014-03-22 11:03:07 +00:00
|
|
|
if (common->cur_frm == common->next_frm) {
|
|
|
|
vb2_buffer_done(&common->cur_frm->vb, VB2_BUF_STATE_ERROR);
|
|
|
|
} else {
|
|
|
|
if (common->cur_frm != NULL)
|
|
|
|
vb2_buffer_done(&common->cur_frm->vb,
|
|
|
|
VB2_BUF_STATE_ERROR);
|
|
|
|
if (common->next_frm != NULL)
|
|
|
|
vb2_buffer_done(&common->next_frm->vb,
|
|
|
|
VB2_BUF_STATE_ERROR);
|
|
|
|
}
|
|
|
|
|
2012-06-28 12:28:05 +00:00
|
|
|
while (!list_empty(&common->dma_queue)) {
|
|
|
|
common->next_frm = list_entry(common->dma_queue.next,
|
|
|
|
struct vpif_cap_buffer, list);
|
|
|
|
list_del(&common->next_frm->list);
|
|
|
|
vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR);
|
|
|
|
}
|
2012-11-16 15:03:06 +00:00
|
|
|
spin_unlock_irqrestore(&common->irqlock, flags);
|
2012-06-28 12:28:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct vb2_ops video_qops = {
|
|
|
|
.queue_setup = vpif_buffer_queue_setup,
|
|
|
|
.buf_prepare = vpif_buffer_prepare,
|
|
|
|
.start_streaming = vpif_start_streaming,
|
|
|
|
.stop_streaming = vpif_stop_streaming,
|
|
|
|
.buf_queue = vpif_buffer_queue,
|
|
|
|
};
|
|
|
|
|
2009-09-16 17:31:10 +00:00
|
|
|
/**
|
|
|
|
* vpif_process_buffer_complete: process a completed buffer
|
|
|
|
* @common: ptr to common channel object
|
|
|
|
*
|
|
|
|
* This function time stamp the buffer and mark it as DONE. It also
|
|
|
|
* wake up any process waiting on the QUEUE and set the next buffer
|
|
|
|
* as current
|
|
|
|
*/
|
|
|
|
static void vpif_process_buffer_complete(struct common_obj *common)
|
|
|
|
{
|
2012-09-15 18:14:42 +00:00
|
|
|
v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp);
|
2012-06-28 12:28:05 +00:00
|
|
|
vb2_buffer_done(&common->cur_frm->vb,
|
|
|
|
VB2_BUF_STATE_DONE);
|
2009-09-16 17:31:10 +00:00
|
|
|
/* Make curFrm pointing to nextFrm */
|
|
|
|
common->cur_frm = common->next_frm;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_schedule_next_buffer: set next buffer address for capture
|
|
|
|
* @common : ptr to common channel object
|
|
|
|
*
|
|
|
|
* This function will get next buffer from the dma queue and
|
|
|
|
* set the buffer address in the vpif register for capture.
|
|
|
|
* the buffer is marked active
|
|
|
|
*/
|
|
|
|
static void vpif_schedule_next_buffer(struct common_obj *common)
|
|
|
|
{
|
|
|
|
unsigned long addr = 0;
|
|
|
|
|
2012-11-16 15:03:06 +00:00
|
|
|
spin_lock(&common->irqlock);
|
2009-09-16 17:31:10 +00:00
|
|
|
common->next_frm = list_entry(common->dma_queue.next,
|
2012-06-28 12:28:05 +00:00
|
|
|
struct vpif_cap_buffer, list);
|
2009-09-16 17:31:10 +00:00
|
|
|
/* Remove that buffer from the buffer queue */
|
2012-06-28 12:28:05 +00:00
|
|
|
list_del(&common->next_frm->list);
|
2012-11-16 15:03:06 +00:00
|
|
|
spin_unlock(&common->irqlock);
|
2012-06-28 12:28:05 +00:00
|
|
|
common->next_frm->vb.state = VB2_BUF_STATE_ACTIVE;
|
|
|
|
addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0);
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
/* Set top and bottom field addresses in VPIF registers */
|
|
|
|
common->set_addr(addr + common->ytop_off,
|
|
|
|
addr + common->ybtm_off,
|
|
|
|
addr + common->ctop_off,
|
|
|
|
addr + common->cbtm_off);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_channel_isr : ISR handler for vpif capture
|
|
|
|
* @irq: irq number
|
|
|
|
* @dev_id: dev_id ptr
|
|
|
|
*
|
|
|
|
* It changes status of the captured buffer, takes next buffer from the queue
|
2010-12-16 15:17:45 +00:00
|
|
|
* and sets its address in VPIF registers
|
2009-09-16 17:31:10 +00:00
|
|
|
*/
|
|
|
|
static irqreturn_t vpif_channel_isr(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct vpif_device *dev = &vpif_obj;
|
|
|
|
struct common_obj *common;
|
|
|
|
struct channel_obj *ch;
|
|
|
|
enum v4l2_field field;
|
|
|
|
int channel_id = 0;
|
|
|
|
int fid = -1, i;
|
|
|
|
|
|
|
|
channel_id = *(int *)(dev_id);
|
2012-04-13 07:43:10 +00:00
|
|
|
if (!vpif_intr_status(channel_id))
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
2009-09-16 17:31:10 +00:00
|
|
|
ch = dev->dev[channel_id];
|
|
|
|
|
|
|
|
field = ch->common[VPIF_VIDEO_INDEX].fmt.fmt.pix.field;
|
|
|
|
|
|
|
|
for (i = 0; i < VPIF_NUMBER_OF_OBJECTS; i++) {
|
|
|
|
common = &ch->common[i];
|
|
|
|
/* skip If streaming is not started in this channel */
|
|
|
|
if (0 == common->started)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Check the field format */
|
|
|
|
if (1 == ch->vpifparams.std_info.frm_fmt) {
|
|
|
|
/* Progressive mode */
|
2012-11-16 15:03:06 +00:00
|
|
|
spin_lock(&common->irqlock);
|
|
|
|
if (list_empty(&common->dma_queue)) {
|
|
|
|
spin_unlock(&common->irqlock);
|
2009-09-16 17:31:10 +00:00
|
|
|
continue;
|
2012-11-16 15:03:06 +00:00
|
|
|
}
|
|
|
|
spin_unlock(&common->irqlock);
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
if (!channel_first_int[i][channel_id])
|
|
|
|
vpif_process_buffer_complete(common);
|
|
|
|
|
|
|
|
channel_first_int[i][channel_id] = 0;
|
|
|
|
|
|
|
|
vpif_schedule_next_buffer(common);
|
|
|
|
|
|
|
|
|
|
|
|
channel_first_int[i][channel_id] = 0;
|
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
* Interlaced mode. If it is first interrupt, ignore
|
|
|
|
* it
|
|
|
|
*/
|
|
|
|
if (channel_first_int[i][channel_id]) {
|
|
|
|
channel_first_int[i][channel_id] = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (0 == i) {
|
|
|
|
ch->field_id ^= 1;
|
|
|
|
/* Get field id from VPIF registers */
|
|
|
|
fid = vpif_channel_getfid(ch->channel_id);
|
|
|
|
if (fid != ch->field_id) {
|
|
|
|
/**
|
|
|
|
* If field id does not match stored
|
|
|
|
* field id, make them in sync
|
|
|
|
*/
|
|
|
|
if (0 == fid)
|
|
|
|
ch->field_id = fid;
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* device field id and local field id are in sync */
|
|
|
|
if (0 == fid) {
|
|
|
|
/* this is even field */
|
|
|
|
if (common->cur_frm == common->next_frm)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* mark the current buffer as done */
|
|
|
|
vpif_process_buffer_complete(common);
|
|
|
|
} else if (1 == fid) {
|
|
|
|
/* odd field */
|
2012-11-16 15:03:06 +00:00
|
|
|
spin_lock(&common->irqlock);
|
2009-09-16 17:31:10 +00:00
|
|
|
if (list_empty(&common->dma_queue) ||
|
2012-11-16 15:03:06 +00:00
|
|
|
(common->cur_frm != common->next_frm)) {
|
|
|
|
spin_unlock(&common->irqlock);
|
2009-09-16 17:31:10 +00:00
|
|
|
continue;
|
2012-11-16 15:03:06 +00:00
|
|
|
}
|
|
|
|
spin_unlock(&common->irqlock);
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
vpif_schedule_next_buffer(common);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_update_std_info() - update standard related info
|
|
|
|
* @ch: ptr to channel object
|
|
|
|
*
|
|
|
|
* For a given standard selected by application, update values
|
|
|
|
* in the device data structures
|
|
|
|
*/
|
|
|
|
static int vpif_update_std_info(struct channel_obj *ch)
|
|
|
|
{
|
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
struct vpif_params *vpifparams = &ch->vpifparams;
|
|
|
|
const struct vpif_channel_config_params *config;
|
2010-12-16 15:17:45 +00:00
|
|
|
struct vpif_channel_config_params *std_info = &vpifparams->std_info;
|
2009-09-16 17:31:10 +00:00
|
|
|
struct video_obj *vid_ch = &ch->video;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_update_std_info\n");
|
|
|
|
|
2010-12-16 15:17:42 +00:00
|
|
|
for (index = 0; index < vpif_ch_params_count; index++) {
|
2013-03-20 04:28:27 +00:00
|
|
|
config = &vpif_ch_params[index];
|
2010-12-16 15:17:43 +00:00
|
|
|
if (config->hd_sd == 0) {
|
|
|
|
vpif_dbg(2, debug, "SD format\n");
|
|
|
|
if (config->stdid & vid_ch->stdid) {
|
|
|
|
memcpy(std_info, config, sizeof(*config));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vpif_dbg(2, debug, "HD format\n");
|
2012-09-18 10:18:47 +00:00
|
|
|
if (!memcmp(&config->dv_timings, &vid_ch->dv_timings,
|
|
|
|
sizeof(vid_ch->dv_timings))) {
|
2010-12-16 15:17:43 +00:00
|
|
|
memcpy(std_info, config, sizeof(*config));
|
|
|
|
break;
|
|
|
|
}
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* standard not found */
|
2010-12-16 15:17:42 +00:00
|
|
|
if (index == vpif_ch_params_count)
|
2009-09-16 17:31:10 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
common->fmt.fmt.pix.width = std_info->width;
|
|
|
|
common->width = std_info->width;
|
|
|
|
common->fmt.fmt.pix.height = std_info->height;
|
|
|
|
common->height = std_info->height;
|
|
|
|
common->fmt.fmt.pix.bytesperline = std_info->width;
|
|
|
|
vpifparams->video_params.hpitch = std_info->width;
|
|
|
|
vpifparams->video_params.storage_mode = std_info->frm_fmt;
|
2010-12-16 15:17:45 +00:00
|
|
|
|
2009-09-16 17:31:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_calculate_offsets : This function calculates buffers offsets
|
|
|
|
* @ch : ptr to channel object
|
|
|
|
*
|
|
|
|
* This function calculates buffer offsets for Y and C in the top and
|
|
|
|
* bottom field
|
|
|
|
*/
|
|
|
|
static void vpif_calculate_offsets(struct channel_obj *ch)
|
|
|
|
{
|
|
|
|
unsigned int hpitch, vpitch, sizeimage;
|
|
|
|
struct video_obj *vid_ch = &(ch->video);
|
|
|
|
struct vpif_params *vpifparams = &ch->vpifparams;
|
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
enum v4l2_field field = common->fmt.fmt.pix.field;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_calculate_offsets\n");
|
|
|
|
|
|
|
|
if (V4L2_FIELD_ANY == field) {
|
|
|
|
if (vpifparams->std_info.frm_fmt)
|
|
|
|
vid_ch->buf_field = V4L2_FIELD_NONE;
|
|
|
|
else
|
|
|
|
vid_ch->buf_field = V4L2_FIELD_INTERLACED;
|
|
|
|
} else
|
|
|
|
vid_ch->buf_field = common->fmt.fmt.pix.field;
|
|
|
|
|
2012-06-28 12:28:05 +00:00
|
|
|
sizeimage = common->fmt.fmt.pix.sizeimage;
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
hpitch = common->fmt.fmt.pix.bytesperline;
|
|
|
|
vpitch = sizeimage / (hpitch * 2);
|
|
|
|
|
|
|
|
if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
|
|
|
|
(V4L2_FIELD_INTERLACED == vid_ch->buf_field)) {
|
|
|
|
/* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
|
|
|
|
common->ytop_off = 0;
|
|
|
|
common->ybtm_off = hpitch;
|
|
|
|
common->ctop_off = sizeimage / 2;
|
|
|
|
common->cbtm_off = sizeimage / 2 + hpitch;
|
|
|
|
} else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) {
|
|
|
|
/* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
|
|
|
|
common->ytop_off = 0;
|
|
|
|
common->ybtm_off = sizeimage / 4;
|
|
|
|
common->ctop_off = sizeimage / 2;
|
|
|
|
common->cbtm_off = common->ctop_off + sizeimage / 4;
|
|
|
|
} else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) {
|
|
|
|
/* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
|
|
|
|
common->ybtm_off = 0;
|
|
|
|
common->ytop_off = sizeimage / 4;
|
|
|
|
common->cbtm_off = sizeimage / 2;
|
|
|
|
common->ctop_off = common->cbtm_off + sizeimage / 4;
|
|
|
|
}
|
|
|
|
if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
|
|
|
|
(V4L2_FIELD_INTERLACED == vid_ch->buf_field))
|
|
|
|
vpifparams->video_params.storage_mode = 1;
|
|
|
|
else
|
|
|
|
vpifparams->video_params.storage_mode = 0;
|
|
|
|
|
|
|
|
if (1 == vpifparams->std_info.frm_fmt)
|
|
|
|
vpifparams->video_params.hpitch =
|
|
|
|
common->fmt.fmt.pix.bytesperline;
|
|
|
|
else {
|
|
|
|
if ((field == V4L2_FIELD_ANY)
|
|
|
|
|| (field == V4L2_FIELD_INTERLACED))
|
|
|
|
vpifparams->video_params.hpitch =
|
|
|
|
common->fmt.fmt.pix.bytesperline * 2;
|
|
|
|
else
|
|
|
|
vpifparams->video_params.hpitch =
|
|
|
|
common->fmt.fmt.pix.bytesperline;
|
|
|
|
}
|
|
|
|
|
|
|
|
ch->vpifparams.video_params.stdid = vpifparams->std_info.stdid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_config_format: configure default frame format in the device
|
|
|
|
* ch : ptr to channel object
|
|
|
|
*/
|
|
|
|
static void vpif_config_format(struct channel_obj *ch)
|
|
|
|
{
|
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_config_format\n");
|
|
|
|
|
|
|
|
common->fmt.fmt.pix.field = V4L2_FIELD_ANY;
|
|
|
|
if (config_params.numbuffers[ch->channel_id] == 0)
|
|
|
|
common->memory = V4L2_MEMORY_USERPTR;
|
|
|
|
else
|
|
|
|
common->memory = V4L2_MEMORY_MMAP;
|
|
|
|
|
|
|
|
common->fmt.fmt.pix.sizeimage
|
|
|
|
= config_params.channel_bufsize[ch->channel_id];
|
|
|
|
|
|
|
|
if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER)
|
|
|
|
common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8;
|
|
|
|
else
|
|
|
|
common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P;
|
|
|
|
common->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_get_default_field() - Get default field type based on interface
|
|
|
|
* @vpif_params - ptr to vpif params
|
|
|
|
*/
|
|
|
|
static inline enum v4l2_field vpif_get_default_field(
|
|
|
|
struct vpif_interface *iface)
|
|
|
|
{
|
|
|
|
return (iface->if_type == VPIF_IF_RAW_BAYER) ? V4L2_FIELD_NONE :
|
|
|
|
V4L2_FIELD_INTERLACED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_check_format() - check given pixel format for compatibility
|
|
|
|
* @ch - channel ptr
|
|
|
|
* @pixfmt - Given pixel format
|
|
|
|
* @update - update the values as per hardware requirement
|
|
|
|
*
|
|
|
|
* Check the application pixel format for S_FMT and update the input
|
|
|
|
* values as per hardware limits for TRY_FMT. The default pixel and
|
|
|
|
* field format is selected based on interface type.
|
|
|
|
*/
|
|
|
|
static int vpif_check_format(struct channel_obj *ch,
|
|
|
|
struct v4l2_pix_format *pixfmt,
|
|
|
|
int update)
|
|
|
|
{
|
|
|
|
struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]);
|
|
|
|
struct vpif_params *vpif_params = &ch->vpifparams;
|
|
|
|
enum v4l2_field field = pixfmt->field;
|
|
|
|
u32 sizeimage, hpitch, vpitch;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_check_format\n");
|
|
|
|
/**
|
|
|
|
* first check for the pixel format. If if_type is Raw bayer,
|
|
|
|
* only V4L2_PIX_FMT_SBGGR8 format is supported. Otherwise only
|
|
|
|
* V4L2_PIX_FMT_YUV422P is supported
|
|
|
|
*/
|
|
|
|
if (vpif_params->iface.if_type == VPIF_IF_RAW_BAYER) {
|
|
|
|
if (pixfmt->pixelformat != V4L2_PIX_FMT_SBGGR8) {
|
|
|
|
if (!update) {
|
|
|
|
vpif_dbg(2, debug, "invalid pix format\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
pixfmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P) {
|
|
|
|
if (!update) {
|
|
|
|
vpif_dbg(2, debug, "invalid pixel format\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
pixfmt->pixelformat = V4L2_PIX_FMT_YUV422P;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(VPIF_VALID_FIELD(field))) {
|
|
|
|
if (!update) {
|
|
|
|
vpif_dbg(2, debug, "invalid field format\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* By default use FIELD_NONE for RAW Bayer capture
|
|
|
|
* and FIELD_INTERLACED for other interfaces
|
|
|
|
*/
|
|
|
|
field = vpif_get_default_field(&vpif_params->iface);
|
|
|
|
} else if (field == V4L2_FIELD_ANY)
|
|
|
|
/* unsupported field. Use default */
|
|
|
|
field = vpif_get_default_field(&vpif_params->iface);
|
|
|
|
|
|
|
|
/* validate the hpitch */
|
|
|
|
hpitch = pixfmt->bytesperline;
|
|
|
|
if (hpitch < vpif_params->std_info.width) {
|
|
|
|
if (!update) {
|
|
|
|
vpif_dbg(2, debug, "invalid hpitch\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
hpitch = vpif_params->std_info.width;
|
|
|
|
}
|
|
|
|
|
2012-06-28 12:28:05 +00:00
|
|
|
sizeimage = pixfmt->sizeimage;
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
vpitch = sizeimage / (hpitch * 2);
|
|
|
|
|
|
|
|
/* validate the vpitch */
|
|
|
|
if (vpitch < vpif_params->std_info.height) {
|
|
|
|
if (!update) {
|
|
|
|
vpif_dbg(2, debug, "Invalid vpitch\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
vpitch = vpif_params->std_info.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for 8 byte alignment */
|
|
|
|
if (!ALIGN(hpitch, 8)) {
|
|
|
|
if (!update) {
|
|
|
|
vpif_dbg(2, debug, "invalid pitch alignment\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
/* adjust to next 8 byte boundary */
|
|
|
|
hpitch = (((hpitch + 7) / 8) * 8);
|
|
|
|
}
|
|
|
|
/* if update is set, modify the bytesperline and sizeimage */
|
|
|
|
if (update) {
|
|
|
|
pixfmt->bytesperline = hpitch;
|
|
|
|
pixfmt->sizeimage = hpitch * vpitch * 2;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Image width and height is always based on current standard width and
|
|
|
|
* height
|
|
|
|
*/
|
|
|
|
pixfmt->width = common->fmt.fmt.pix.width;
|
|
|
|
pixfmt->height = common->fmt.fmt.pix.height;
|
|
|
|
return 0;
|
|
|
|
exit:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_config_addr() - function to configure buffer address in vpif
|
|
|
|
* @ch - channel ptr
|
|
|
|
* @muxmode - channel mux mode
|
|
|
|
*/
|
|
|
|
static void vpif_config_addr(struct channel_obj *ch, int muxmode)
|
|
|
|
{
|
|
|
|
struct common_obj *common;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_config_addr\n");
|
|
|
|
|
|
|
|
common = &(ch->common[VPIF_VIDEO_INDEX]);
|
|
|
|
|
|
|
|
if (VPIF_CHANNEL1_VIDEO == ch->channel_id)
|
|
|
|
common->set_addr = ch1_set_videobuf_addr;
|
|
|
|
else if (2 == muxmode)
|
|
|
|
common->set_addr = ch0_set_videobuf_addr_yc_nmux;
|
|
|
|
else
|
|
|
|
common->set_addr = ch0_set_videobuf_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_open : vpif open handler
|
|
|
|
* @filep: file ptr
|
|
|
|
*
|
|
|
|
* It creates object of file handle structure and stores it in private_data
|
|
|
|
* member of filepointer
|
|
|
|
*/
|
|
|
|
static int vpif_open(struct file *filep)
|
|
|
|
{
|
|
|
|
struct video_device *vdev = video_devdata(filep);
|
|
|
|
struct common_obj *common;
|
|
|
|
struct video_obj *vid_ch;
|
|
|
|
struct channel_obj *ch;
|
|
|
|
struct vpif_fh *fh;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_open\n");
|
|
|
|
|
|
|
|
ch = video_get_drvdata(vdev);
|
|
|
|
|
|
|
|
vid_ch = &ch->video;
|
|
|
|
common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
|
|
|
|
/* Allocate memory for the file handle object */
|
2010-08-30 13:30:37 +00:00
|
|
|
fh = kzalloc(sizeof(struct vpif_fh), GFP_KERNEL);
|
2009-09-16 17:31:10 +00:00
|
|
|
if (NULL == fh) {
|
|
|
|
vpif_err("unable to allocate memory for file handle object\n");
|
2011-01-04 09:51:35 +00:00
|
|
|
return -ENOMEM;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
2012-07-31 06:48:31 +00:00
|
|
|
if (mutex_lock_interruptible(&common->lock)) {
|
|
|
|
kfree(fh);
|
|
|
|
return -ERESTARTSYS;
|
|
|
|
}
|
2009-09-16 17:31:10 +00:00
|
|
|
/* store pointer to fh in private_data member of filep */
|
|
|
|
filep->private_data = fh;
|
|
|
|
fh->channel = ch;
|
|
|
|
fh->initialized = 0;
|
|
|
|
/* If decoder is not initialized. initialize it */
|
|
|
|
if (!ch->initialized) {
|
|
|
|
fh->initialized = 1;
|
|
|
|
ch->initialized = 1;
|
|
|
|
memset(&(ch->vpifparams), 0, sizeof(struct vpif_params));
|
|
|
|
}
|
|
|
|
/* Increment channel usrs counter */
|
|
|
|
ch->usrs++;
|
|
|
|
/* Set io_allowed member to false */
|
|
|
|
fh->io_allowed[VPIF_VIDEO_INDEX] = 0;
|
|
|
|
/* Initialize priority of this instance to default priority */
|
|
|
|
fh->prio = V4L2_PRIORITY_UNSET;
|
|
|
|
v4l2_prio_open(&ch->prio, &fh->prio);
|
2012-07-31 06:48:31 +00:00
|
|
|
mutex_unlock(&common->lock);
|
2011-01-04 09:51:35 +00:00
|
|
|
return 0;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_release : function to clean up file close
|
|
|
|
* @filep: file pointer
|
|
|
|
*
|
2012-07-10 08:43:22 +00:00
|
|
|
* This function deletes buffer queue, frees the buffers and the vpif file
|
2009-09-16 17:31:10 +00:00
|
|
|
* handle
|
|
|
|
*/
|
|
|
|
static int vpif_release(struct file *filep)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = filep->private_data;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct common_obj *common;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_release\n");
|
|
|
|
|
|
|
|
common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
|
2012-07-31 06:48:31 +00:00
|
|
|
mutex_lock(&common->lock);
|
2009-09-16 17:31:10 +00:00
|
|
|
/* if this instance is doing IO */
|
2014-05-16 13:33:31 +00:00
|
|
|
if (fh->io_allowed[VPIF_VIDEO_INDEX])
|
2009-09-16 17:31:10 +00:00
|
|
|
/* Reset io_usrs member of channel object */
|
|
|
|
common->io_usrs = 0;
|
|
|
|
|
|
|
|
/* Decrement channel usrs counter */
|
|
|
|
ch->usrs--;
|
|
|
|
|
|
|
|
/* Close the priority */
|
2010-05-01 11:03:24 +00:00
|
|
|
v4l2_prio_close(&ch->prio, fh->prio);
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
if (fh->initialized)
|
|
|
|
ch->initialized = 0;
|
|
|
|
|
2012-07-31 06:48:31 +00:00
|
|
|
mutex_unlock(&common->lock);
|
2009-09-16 17:31:10 +00:00
|
|
|
filep->private_data = NULL;
|
|
|
|
kfree(fh);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_reqbufs() - request buffer handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @reqbuf: request buffer structure ptr
|
|
|
|
*/
|
|
|
|
static int vpif_reqbufs(struct file *file, void *priv,
|
|
|
|
struct v4l2_requestbuffers *reqbuf)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct common_obj *common;
|
|
|
|
u8 index = 0;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_reqbufs\n");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file handle has not initialized the channel,
|
|
|
|
* It is not allowed to do settings
|
|
|
|
*/
|
|
|
|
if ((VPIF_CHANNEL0_VIDEO == ch->channel_id)
|
|
|
|
|| (VPIF_CHANNEL1_VIDEO == ch->channel_id)) {
|
|
|
|
if (!fh->initialized) {
|
|
|
|
vpif_dbg(1, debug, "Channel Busy\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-13 07:49:34 +00:00
|
|
|
if (V4L2_BUF_TYPE_VIDEO_CAPTURE != reqbuf->type || !vpif_dev)
|
2009-09-16 17:31:10 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
index = VPIF_VIDEO_INDEX;
|
|
|
|
|
|
|
|
common = &ch->common[index];
|
|
|
|
|
2011-01-04 09:51:35 +00:00
|
|
|
if (0 != common->io_usrs)
|
|
|
|
return -EBUSY;
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
/* Set io allowed member of file handle to TRUE */
|
|
|
|
fh->io_allowed[index] = 1;
|
|
|
|
/* Increment io usrs member of channel object to 1 */
|
|
|
|
common->io_usrs = 1;
|
|
|
|
/* Store type of memory requested in channel object */
|
|
|
|
common->memory = reqbuf->memory;
|
|
|
|
|
|
|
|
/* Allocate buffers */
|
2012-06-28 12:28:05 +00:00
|
|
|
return vb2_reqbufs(&common->buffer_queue, reqbuf);
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_querybuf() - query buffer handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @buf: v4l2 buffer structure ptr
|
|
|
|
*/
|
|
|
|
static int vpif_querybuf(struct file *file, void *priv,
|
|
|
|
struct v4l2_buffer *buf)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_querybuf\n");
|
|
|
|
|
|
|
|
if (common->fmt.type != buf->type)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (common->memory != V4L2_MEMORY_MMAP) {
|
|
|
|
vpif_dbg(1, debug, "Invalid memory\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-06-28 12:28:05 +00:00
|
|
|
return vb2_querybuf(&common->buffer_queue, buf);
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_qbuf() - query buffer handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @buf: v4l2 buffer structure ptr
|
|
|
|
*/
|
|
|
|
static int vpif_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
struct v4l2_buffer tbuf = *buf;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_qbuf\n");
|
|
|
|
|
|
|
|
if (common->fmt.type != tbuf.type) {
|
|
|
|
vpif_err("invalid buffer type\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fh->io_allowed[VPIF_VIDEO_INDEX]) {
|
2012-06-28 12:28:05 +00:00
|
|
|
vpif_err("fh io not allowed\n");
|
2009-09-16 17:31:10 +00:00
|
|
|
return -EACCES;
|
|
|
|
}
|
|
|
|
|
2012-06-28 12:28:05 +00:00
|
|
|
return vb2_qbuf(&common->buffer_queue, buf);
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_dqbuf() - query buffer handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @buf: v4l2 buffer structure ptr
|
|
|
|
*/
|
|
|
|
static int vpif_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_dqbuf\n");
|
|
|
|
|
2012-06-28 12:28:05 +00:00
|
|
|
return vb2_dqbuf(&common->buffer_queue, buf,
|
|
|
|
(file->f_flags & O_NONBLOCK));
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_streamon() - streamon handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @buftype: v4l2 buffer type
|
|
|
|
*/
|
|
|
|
static int vpif_streamon(struct file *file, void *priv,
|
|
|
|
enum v4l2_buf_type buftype)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
struct channel_obj *oth_ch = vpif_obj.dev[!ch->channel_id];
|
|
|
|
struct vpif_params *vpif;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_streamon\n");
|
|
|
|
|
|
|
|
vpif = &ch->vpifparams;
|
|
|
|
|
|
|
|
if (buftype != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
|
|
|
|
vpif_dbg(1, debug, "buffer type not supported\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If file handle is not allowed IO, return error */
|
|
|
|
if (!fh->io_allowed[VPIF_VIDEO_INDEX]) {
|
|
|
|
vpif_dbg(1, debug, "io not allowed\n");
|
|
|
|
return -EACCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If Streaming is already started, return error */
|
|
|
|
if (common->started) {
|
|
|
|
vpif_dbg(1, debug, "channel->started\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ch->channel_id == VPIF_CHANNEL0_VIDEO &&
|
|
|
|
oth_ch->common[VPIF_VIDEO_INDEX].started &&
|
|
|
|
vpif->std_info.ycmux_mode == 0) ||
|
|
|
|
((ch->channel_id == VPIF_CHANNEL1_VIDEO) &&
|
|
|
|
(2 == oth_ch->common[VPIF_VIDEO_INDEX].started))) {
|
|
|
|
vpif_dbg(1, debug, "other channel is being used\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = vpif_check_format(ch, &common->fmt.fmt.pix, 0);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Enable streamon on the sub device */
|
2012-09-20 12:06:30 +00:00
|
|
|
ret = v4l2_subdev_call(ch->sd, video, s_stream, 1);
|
2009-09-16 17:31:10 +00:00
|
|
|
|
2012-09-20 12:06:30 +00:00
|
|
|
if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
|
2009-09-16 17:31:10 +00:00
|
|
|
vpif_dbg(1, debug, "stream on failed in subdev\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-28 12:28:05 +00:00
|
|
|
/* Call vb2_streamon to start streaming in videobuf2 */
|
|
|
|
ret = vb2_streamon(&common->buffer_queue, buftype);
|
2009-09-16 17:31:10 +00:00
|
|
|
if (ret) {
|
2012-06-28 12:28:05 +00:00
|
|
|
vpif_dbg(1, debug, "vb2_streamon\n");
|
2009-09-16 17:31:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_streamoff() - streamoff handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @buftype: v4l2 buffer type
|
|
|
|
*/
|
|
|
|
static int vpif_streamoff(struct file *file, void *priv,
|
|
|
|
enum v4l2_buf_type buftype)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_streamoff\n");
|
|
|
|
|
|
|
|
if (buftype != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
|
|
|
|
vpif_dbg(1, debug, "buffer type not supported\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If io is allowed for this file handle, return error */
|
|
|
|
if (!fh->io_allowed[VPIF_VIDEO_INDEX]) {
|
|
|
|
vpif_dbg(1, debug, "io not allowed\n");
|
|
|
|
return -EACCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If streaming is not started, return error */
|
|
|
|
if (!common->started) {
|
|
|
|
vpif_dbg(1, debug, "channel->started\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* disable channel */
|
|
|
|
if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
|
|
|
|
enable_channel0(0);
|
|
|
|
channel0_intr_enable(0);
|
|
|
|
} else {
|
|
|
|
enable_channel1(0);
|
|
|
|
channel1_intr_enable(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
common->started = 0;
|
|
|
|
|
2012-09-20 12:06:30 +00:00
|
|
|
ret = v4l2_subdev_call(ch->sd, video, s_stream, 0);
|
2009-09-16 17:31:10 +00:00
|
|
|
|
2012-09-20 12:06:30 +00:00
|
|
|
if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
|
2009-09-16 17:31:10 +00:00
|
|
|
vpif_dbg(1, debug, "stream off failed in subdev\n");
|
|
|
|
|
2012-06-28 12:28:05 +00:00
|
|
|
return vb2_streamoff(&common->buffer_queue, buftype);
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-09-20 12:06:30 +00:00
|
|
|
* vpif_input_to_subdev() - Maps input to sub device
|
|
|
|
* @vpif_cfg - global config ptr
|
|
|
|
* @chan_cfg - channel config ptr
|
2009-09-16 17:31:10 +00:00
|
|
|
* @input_index - Given input index from application
|
|
|
|
*
|
|
|
|
* lookup the sub device information for a given input index.
|
|
|
|
* we report all the inputs to application. inputs table also
|
|
|
|
* has sub device name for the each input
|
|
|
|
*/
|
2012-09-20 12:06:30 +00:00
|
|
|
static int vpif_input_to_subdev(
|
|
|
|
struct vpif_capture_config *vpif_cfg,
|
|
|
|
struct vpif_capture_chan_config *chan_cfg,
|
|
|
|
int input_index)
|
2009-09-16 17:31:10 +00:00
|
|
|
{
|
2012-09-20 12:06:30 +00:00
|
|
|
struct vpif_subdev_info *subdev_info;
|
|
|
|
const char *subdev_name;
|
2009-09-16 17:31:10 +00:00
|
|
|
int i;
|
|
|
|
|
2012-09-20 12:06:30 +00:00
|
|
|
vpif_dbg(2, debug, "vpif_input_to_subdev\n");
|
2009-09-16 17:31:10 +00:00
|
|
|
|
2012-09-20 12:06:30 +00:00
|
|
|
subdev_name = chan_cfg->inputs[input_index].subdev_name;
|
|
|
|
if (subdev_name == NULL)
|
|
|
|
return -1;
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
/* loop through the sub device list to get the sub device info */
|
|
|
|
for (i = 0; i < vpif_cfg->subdev_count; i++) {
|
|
|
|
subdev_info = &vpif_cfg->subdev_info[i];
|
|
|
|
if (!strcmp(subdev_info->name, subdev_name))
|
2012-09-20 12:06:30 +00:00
|
|
|
return i;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
2012-09-20 12:06:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-09-16 17:31:10 +00:00
|
|
|
|
2012-09-20 12:06:30 +00:00
|
|
|
/**
|
|
|
|
* vpif_set_input() - Select an input
|
|
|
|
* @vpif_cfg - global config ptr
|
|
|
|
* @ch - channel
|
|
|
|
* @_index - Given input index from application
|
|
|
|
*
|
|
|
|
* Select the given input.
|
|
|
|
*/
|
|
|
|
static int vpif_set_input(
|
|
|
|
struct vpif_capture_config *vpif_cfg,
|
|
|
|
struct channel_obj *ch,
|
|
|
|
int index)
|
|
|
|
{
|
|
|
|
struct vpif_capture_chan_config *chan_cfg =
|
|
|
|
&vpif_cfg->chan_config[ch->channel_id];
|
|
|
|
struct vpif_subdev_info *subdev_info = NULL;
|
|
|
|
struct v4l2_subdev *sd = NULL;
|
|
|
|
u32 input = 0, output = 0;
|
|
|
|
int sd_index;
|
|
|
|
int ret;
|
2009-09-16 17:31:10 +00:00
|
|
|
|
2012-09-20 12:06:30 +00:00
|
|
|
sd_index = vpif_input_to_subdev(vpif_cfg, chan_cfg, index);
|
|
|
|
if (sd_index >= 0) {
|
|
|
|
sd = vpif_obj.sd[sd_index];
|
|
|
|
subdev_info = &vpif_cfg->subdev_info[sd_index];
|
|
|
|
}
|
2009-09-16 17:31:10 +00:00
|
|
|
|
2012-09-20 12:06:30 +00:00
|
|
|
/* first setup input path from sub device to vpif */
|
|
|
|
if (sd && vpif_cfg->setup_input_path) {
|
|
|
|
ret = vpif_cfg->setup_input_path(ch->channel_id,
|
|
|
|
subdev_info->name);
|
|
|
|
if (ret < 0) {
|
|
|
|
vpif_dbg(1, debug, "couldn't setup input path for the" \
|
|
|
|
" sub device %s, for input index %d\n",
|
|
|
|
subdev_info->name, index);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sd) {
|
|
|
|
input = chan_cfg->inputs[index].input_route;
|
|
|
|
output = chan_cfg->inputs[index].output_route;
|
|
|
|
ret = v4l2_subdev_call(sd, video, s_routing,
|
|
|
|
input, output, 0);
|
|
|
|
if (ret < 0 && ret != -ENOIOCTLCMD) {
|
|
|
|
vpif_dbg(1, debug, "Failed to set input\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ch->input_idx = index;
|
|
|
|
ch->sd = sd;
|
|
|
|
/* copy interface parameters to vpif */
|
2012-09-20 12:06:32 +00:00
|
|
|
ch->vpifparams.iface = chan_cfg->vpif_if;
|
2012-09-20 12:06:30 +00:00
|
|
|
|
|
|
|
/* update tvnorms from the sub device input info */
|
|
|
|
ch->video_dev->tvnorms = chan_cfg->inputs[index].input.std;
|
|
|
|
return 0;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_querystd() - querystd handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @std_id: ptr to std id
|
|
|
|
*
|
|
|
|
* This function is called to detect standard at the selected input
|
|
|
|
*/
|
|
|
|
static int vpif_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_querystd\n");
|
|
|
|
|
|
|
|
/* Call querystd function of decoder device */
|
2012-09-20 12:06:30 +00:00
|
|
|
ret = v4l2_subdev_call(ch->sd, video, querystd, std_id);
|
2009-09-16 17:31:10 +00:00
|
|
|
|
2012-09-20 12:06:30 +00:00
|
|
|
if (ret == -ENOIOCTLCMD || ret == -ENODEV)
|
|
|
|
return -ENODATA;
|
|
|
|
if (ret) {
|
|
|
|
vpif_dbg(1, debug, "Failed to query standard for sub devices\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_g_std() - get STD handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @std_id: ptr to std id
|
|
|
|
*/
|
|
|
|
static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_g_std\n");
|
|
|
|
|
|
|
|
*std = ch->video.stdid;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_s_std() - set STD handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @std_id: ptr to std id
|
|
|
|
*/
|
2013-03-15 09:10:40 +00:00
|
|
|
static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id)
|
2009-09-16 17:31:10 +00:00
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
vpif_dbg(2, debug, "vpif_s_std\n");
|
|
|
|
|
|
|
|
if (common->started) {
|
|
|
|
vpif_err("streaming in progress\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((VPIF_CHANNEL0_VIDEO == ch->channel_id) ||
|
|
|
|
(VPIF_CHANNEL1_VIDEO == ch->channel_id)) {
|
|
|
|
if (!fh->initialized) {
|
|
|
|
vpif_dbg(1, debug, "Channel Busy\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 11:03:24 +00:00
|
|
|
ret = v4l2_prio_check(&ch->prio, fh->prio);
|
2009-09-16 17:31:10 +00:00
|
|
|
if (0 != ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
fh->initialized = 1;
|
|
|
|
|
|
|
|
/* Call encoder subdevice function to set the standard */
|
2013-03-15 09:10:40 +00:00
|
|
|
ch->video.stdid = std_id;
|
2012-09-18 10:18:47 +00:00
|
|
|
memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
/* Get the information about the standard */
|
|
|
|
if (vpif_update_std_info(ch)) {
|
|
|
|
vpif_err("Error getting the standard info\n");
|
2011-01-04 09:51:35 +00:00
|
|
|
return -EINVAL;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure the default format information */
|
|
|
|
vpif_config_format(ch);
|
|
|
|
|
|
|
|
/* set standard in the sub device */
|
2013-03-15 09:10:40 +00:00
|
|
|
ret = v4l2_subdev_call(ch->sd, core, s_std, std_id);
|
2012-09-20 12:06:30 +00:00
|
|
|
if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
|
2009-09-16 17:31:10 +00:00
|
|
|
vpif_dbg(1, debug, "Failed to set standard for sub devices\n");
|
2012-09-20 12:06:30 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_enum_input() - ENUMINPUT handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @input: ptr to input structure
|
|
|
|
*/
|
|
|
|
static int vpif_enum_input(struct file *file, void *priv,
|
|
|
|
struct v4l2_input *input)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct vpif_capture_config *config = vpif_dev->platform_data;
|
|
|
|
struct vpif_capture_chan_config *chan_cfg;
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
|
|
|
|
chan_cfg = &config->chan_config[ch->channel_id];
|
|
|
|
|
|
|
|
if (input->index >= chan_cfg->input_count) {
|
|
|
|
vpif_dbg(1, debug, "Invalid input index\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(input, &chan_cfg->inputs[input->index].input,
|
|
|
|
sizeof(*input));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_g_input() - Get INPUT handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @index: ptr to input index
|
|
|
|
*/
|
|
|
|
static int vpif_g_input(struct file *file, void *priv, unsigned int *index)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
|
2012-09-20 12:06:22 +00:00
|
|
|
*index = ch->input_idx;
|
2009-09-16 17:31:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_s_input() - Set INPUT handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @index: input index
|
|
|
|
*/
|
|
|
|
static int vpif_s_input(struct file *file, void *priv, unsigned int index)
|
|
|
|
{
|
|
|
|
struct vpif_capture_config *config = vpif_dev->platform_data;
|
|
|
|
struct vpif_capture_chan_config *chan_cfg;
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
2012-09-20 12:06:30 +00:00
|
|
|
int ret;
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
chan_cfg = &config->chan_config[ch->channel_id];
|
|
|
|
|
2012-09-20 12:06:25 +00:00
|
|
|
if (index >= chan_cfg->input_count)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-09-16 17:31:10 +00:00
|
|
|
if (common->started) {
|
|
|
|
vpif_err("Streaming in progress\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((VPIF_CHANNEL0_VIDEO == ch->channel_id) ||
|
|
|
|
(VPIF_CHANNEL1_VIDEO == ch->channel_id)) {
|
|
|
|
if (!fh->initialized) {
|
|
|
|
vpif_dbg(1, debug, "Channel Busy\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 11:03:24 +00:00
|
|
|
ret = v4l2_prio_check(&ch->prio, fh->prio);
|
2009-09-16 17:31:10 +00:00
|
|
|
if (0 != ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
fh->initialized = 1;
|
2012-09-20 12:06:30 +00:00
|
|
|
return vpif_set_input(config, ch, index);
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_enum_fmt_vid_cap() - ENUM_FMT handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @index: input index
|
|
|
|
*/
|
|
|
|
static int vpif_enum_fmt_vid_cap(struct file *file, void *priv,
|
|
|
|
struct v4l2_fmtdesc *fmt)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
|
|
|
|
if (fmt->index != 0) {
|
|
|
|
vpif_dbg(1, debug, "Invalid format index\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in the information about format */
|
|
|
|
if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) {
|
|
|
|
fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
strcpy(fmt->description, "Raw Mode -Bayer Pattern GrRBGb");
|
|
|
|
fmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
|
|
|
|
} else {
|
|
|
|
fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
strcpy(fmt->description, "YCbCr4:2:2 YC Planar");
|
|
|
|
fmt->pixelformat = V4L2_PIX_FMT_YUV422P;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_try_fmt_vid_cap() - TRY_FMT handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @fmt: ptr to v4l2 format structure
|
|
|
|
*/
|
|
|
|
static int vpif_try_fmt_vid_cap(struct file *file, void *priv,
|
|
|
|
struct v4l2_format *fmt)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
|
|
|
|
|
|
|
|
return vpif_check_format(ch, pixfmt, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_g_fmt_vid_cap() - Set INPUT handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @fmt: ptr to v4l2 format structure
|
|
|
|
*/
|
|
|
|
static int vpif_g_fmt_vid_cap(struct file *file, void *priv,
|
|
|
|
struct v4l2_format *fmt)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
|
|
|
|
/* Check the validity of the buffer type */
|
|
|
|
if (common->fmt.type != fmt->type)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Fill in the information about format */
|
|
|
|
*fmt = common->fmt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_s_fmt_vid_cap() - Set FMT handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @fmt: ptr to v4l2 format structure
|
|
|
|
*/
|
|
|
|
static int vpif_s_fmt_vid_cap(struct file *file, void *priv,
|
|
|
|
struct v4l2_format *fmt)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
struct v4l2_pix_format *pixfmt;
|
|
|
|
int ret = 0;
|
|
|
|
|
2010-12-16 15:17:45 +00:00
|
|
|
vpif_dbg(2, debug, "%s\n", __func__);
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
/* If streaming is started, return error */
|
|
|
|
if (common->started) {
|
|
|
|
vpif_dbg(1, debug, "Streaming is started\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((VPIF_CHANNEL0_VIDEO == ch->channel_id) ||
|
|
|
|
(VPIF_CHANNEL1_VIDEO == ch->channel_id)) {
|
|
|
|
if (!fh->initialized) {
|
|
|
|
vpif_dbg(1, debug, "Channel Busy\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 11:03:24 +00:00
|
|
|
ret = v4l2_prio_check(&ch->prio, fh->prio);
|
2009-09-16 17:31:10 +00:00
|
|
|
if (0 != ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
fh->initialized = 1;
|
|
|
|
|
|
|
|
pixfmt = &fmt->fmt.pix;
|
|
|
|
/* Check for valid field format */
|
|
|
|
ret = vpif_check_format(ch, pixfmt, 0);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
/* store the format in the channel object */
|
|
|
|
common->fmt = *fmt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_querycap() - QUERYCAP handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @cap: ptr to v4l2_capability structure
|
|
|
|
*/
|
|
|
|
static int vpif_querycap(struct file *file, void *priv,
|
|
|
|
struct v4l2_capability *cap)
|
|
|
|
{
|
|
|
|
struct vpif_capture_config *config = vpif_dev->platform_data;
|
|
|
|
|
2012-09-25 14:21:55 +00:00
|
|
|
cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
|
|
|
|
cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
|
|
|
|
snprintf(cap->driver, sizeof(cap->driver), "%s", dev_name(vpif_dev));
|
|
|
|
snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
|
|
|
|
dev_name(vpif_dev));
|
2009-09-16 17:31:10 +00:00
|
|
|
strlcpy(cap->card, config->card_name, sizeof(cap->card));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_g_priority() - get priority handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @prio: ptr to v4l2_priority structure
|
|
|
|
*/
|
|
|
|
static int vpif_g_priority(struct file *file, void *priv,
|
|
|
|
enum v4l2_priority *prio)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
|
|
|
|
*prio = v4l2_prio_max(&ch->prio);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_s_priority() - set priority handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @prio: ptr to v4l2_priority structure
|
|
|
|
*/
|
|
|
|
static int vpif_s_priority(struct file *file, void *priv, enum v4l2_priority p)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
|
|
|
|
return v4l2_prio_change(&ch->prio, &fh->prio, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_cropcap() - cropcap handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @crop: ptr to v4l2_cropcap structure
|
|
|
|
*/
|
|
|
|
static int vpif_cropcap(struct file *file, void *priv,
|
|
|
|
struct v4l2_cropcap *crop)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
|
|
|
|
if (V4L2_BUF_TYPE_VIDEO_CAPTURE != crop->type)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
crop->bounds.left = 0;
|
|
|
|
crop->bounds.top = 0;
|
|
|
|
crop->bounds.height = common->height;
|
|
|
|
crop->bounds.width = common->width;
|
|
|
|
crop->defrect = crop->bounds;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-16 15:17:43 +00:00
|
|
|
/**
|
2012-09-18 10:18:47 +00:00
|
|
|
* vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler
|
2010-12-16 15:17:43 +00:00
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
2012-09-18 10:18:47 +00:00
|
|
|
* @timings: input timings
|
2010-12-16 15:17:43 +00:00
|
|
|
*/
|
2012-09-18 10:18:47 +00:00
|
|
|
static int
|
|
|
|
vpif_enum_dv_timings(struct file *file, void *priv,
|
|
|
|
struct v4l2_enum_dv_timings *timings)
|
2010-12-16 15:17:43 +00:00
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
2012-09-20 12:06:30 +00:00
|
|
|
int ret;
|
2010-12-16 15:17:43 +00:00
|
|
|
|
2012-09-20 12:06:30 +00:00
|
|
|
ret = v4l2_subdev_call(ch->sd, video, enum_dv_timings, timings);
|
2012-10-30 12:45:00 +00:00
|
|
|
if (ret == -ENOIOCTLCMD || ret == -ENODEV)
|
2012-09-20 12:06:30 +00:00
|
|
|
return -EINVAL;
|
|
|
|
return ret;
|
2010-12-16 15:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-09-18 10:18:47 +00:00
|
|
|
* vpif_query_dv_timings() - QUERY_DV_TIMINGS handler
|
2010-12-16 15:17:43 +00:00
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
2012-09-18 10:18:47 +00:00
|
|
|
* @timings: input timings
|
2010-12-16 15:17:43 +00:00
|
|
|
*/
|
2012-09-18 10:18:47 +00:00
|
|
|
static int
|
|
|
|
vpif_query_dv_timings(struct file *file, void *priv,
|
|
|
|
struct v4l2_dv_timings *timings)
|
2010-12-16 15:17:43 +00:00
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
2012-09-20 12:06:30 +00:00
|
|
|
int ret;
|
2010-12-16 15:17:43 +00:00
|
|
|
|
2012-09-20 12:06:30 +00:00
|
|
|
ret = v4l2_subdev_call(ch->sd, video, query_dv_timings, timings);
|
2012-10-30 12:45:00 +00:00
|
|
|
if (ret == -ENOIOCTLCMD || ret == -ENODEV)
|
2012-09-20 12:06:30 +00:00
|
|
|
return -ENODATA;
|
|
|
|
return ret;
|
2010-12-16 15:17:43 +00:00
|
|
|
}
|
|
|
|
|
2010-12-16 15:17:44 +00:00
|
|
|
/**
|
|
|
|
* vpif_s_dv_timings() - S_DV_TIMINGS handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @timings: digital video timings
|
|
|
|
*/
|
|
|
|
static int vpif_s_dv_timings(struct file *file, void *priv,
|
|
|
|
struct v4l2_dv_timings *timings)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct vpif_params *vpifparams = &ch->vpifparams;
|
|
|
|
struct vpif_channel_config_params *std_info = &vpifparams->std_info;
|
|
|
|
struct video_obj *vid_ch = &ch->video;
|
2012-09-18 10:18:47 +00:00
|
|
|
struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt;
|
2010-12-16 15:17:44 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (timings->type != V4L2_DV_BT_656_1120) {
|
|
|
|
vpif_dbg(2, debug, "Timing type not defined\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure subdevice timings, if any */
|
2012-09-20 12:06:30 +00:00
|
|
|
ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings);
|
|
|
|
if (ret == -ENOIOCTLCMD || ret == -ENODEV)
|
|
|
|
ret = 0;
|
2010-12-16 15:17:44 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
vpif_dbg(2, debug, "Error setting custom DV timings\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(timings->bt.width && timings->bt.height &&
|
|
|
|
(timings->bt.hbackporch ||
|
|
|
|
timings->bt.hfrontporch ||
|
|
|
|
timings->bt.hsync) &&
|
|
|
|
timings->bt.vfrontporch &&
|
|
|
|
(timings->bt.vbackporch ||
|
|
|
|
timings->bt.vsync))) {
|
|
|
|
vpif_dbg(2, debug, "Timings for width, height, "
|
|
|
|
"horizontal back porch, horizontal sync, "
|
|
|
|
"horizontal front porch, vertical back porch, "
|
|
|
|
"vertical sync and vertical back porch "
|
|
|
|
"must be defined\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-09-18 10:18:47 +00:00
|
|
|
vid_ch->dv_timings = *timings;
|
2010-12-16 15:17:44 +00:00
|
|
|
|
|
|
|
/* Configure video port timings */
|
|
|
|
|
2013-07-29 11:41:00 +00:00
|
|
|
std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8;
|
2010-12-16 15:17:44 +00:00
|
|
|
std_info->sav2eav = bt->width;
|
|
|
|
|
|
|
|
std_info->l1 = 1;
|
|
|
|
std_info->l3 = bt->vsync + bt->vbackporch + 1;
|
|
|
|
|
2013-07-29 11:41:00 +00:00
|
|
|
std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt);
|
2010-12-16 15:17:44 +00:00
|
|
|
if (bt->interlaced) {
|
|
|
|
if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) {
|
|
|
|
std_info->l5 = std_info->vsize/2 -
|
|
|
|
(bt->vfrontporch - 1);
|
|
|
|
std_info->l7 = std_info->vsize/2 + 1;
|
|
|
|
std_info->l9 = std_info->l7 + bt->il_vsync +
|
|
|
|
bt->il_vbackporch + 1;
|
|
|
|
std_info->l11 = std_info->vsize -
|
|
|
|
(bt->il_vfrontporch - 1);
|
|
|
|
} else {
|
|
|
|
vpif_dbg(2, debug, "Required timing values for "
|
|
|
|
"interlaced BT format missing\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
std_info->l5 = std_info->vsize - (bt->vfrontporch - 1);
|
|
|
|
}
|
|
|
|
strncpy(std_info->name, "Custom timings BT656/1120", VPIF_MAX_NAME);
|
|
|
|
std_info->width = bt->width;
|
|
|
|
std_info->height = bt->height;
|
|
|
|
std_info->frm_fmt = bt->interlaced ? 0 : 1;
|
|
|
|
std_info->ycmux_mode = 0;
|
|
|
|
std_info->capture_format = 0;
|
|
|
|
std_info->vbi_supported = 0;
|
|
|
|
std_info->hd_sd = 1;
|
|
|
|
std_info->stdid = 0;
|
|
|
|
|
|
|
|
vid_ch->stdid = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_g_dv_timings() - G_DV_TIMINGS handler
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
* @timings: digital video timings
|
|
|
|
*/
|
|
|
|
static int vpif_g_dv_timings(struct file *file, void *priv,
|
|
|
|
struct v4l2_dv_timings *timings)
|
|
|
|
{
|
|
|
|
struct vpif_fh *fh = priv;
|
|
|
|
struct channel_obj *ch = fh->channel;
|
|
|
|
struct video_obj *vid_ch = &ch->video;
|
|
|
|
|
2012-09-18 10:18:47 +00:00
|
|
|
*timings = vid_ch->dv_timings;
|
2010-12-16 15:17:44 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-16 15:17:41 +00:00
|
|
|
/*
|
|
|
|
* vpif_log_status() - Status information
|
|
|
|
* @file: file ptr
|
|
|
|
* @priv: file handle
|
|
|
|
*
|
|
|
|
* Returns zero.
|
|
|
|
*/
|
|
|
|
static int vpif_log_status(struct file *filep, void *priv)
|
|
|
|
{
|
|
|
|
/* status for sub devices */
|
|
|
|
v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-16 17:31:10 +00:00
|
|
|
/* vpif capture ioctl operations */
|
|
|
|
static const struct v4l2_ioctl_ops vpif_ioctl_ops = {
|
|
|
|
.vidioc_querycap = vpif_querycap,
|
|
|
|
.vidioc_g_priority = vpif_g_priority,
|
|
|
|
.vidioc_s_priority = vpif_s_priority,
|
|
|
|
.vidioc_enum_fmt_vid_cap = vpif_enum_fmt_vid_cap,
|
|
|
|
.vidioc_g_fmt_vid_cap = vpif_g_fmt_vid_cap,
|
|
|
|
.vidioc_s_fmt_vid_cap = vpif_s_fmt_vid_cap,
|
|
|
|
.vidioc_try_fmt_vid_cap = vpif_try_fmt_vid_cap,
|
|
|
|
.vidioc_enum_input = vpif_enum_input,
|
|
|
|
.vidioc_s_input = vpif_s_input,
|
|
|
|
.vidioc_g_input = vpif_g_input,
|
|
|
|
.vidioc_reqbufs = vpif_reqbufs,
|
|
|
|
.vidioc_querybuf = vpif_querybuf,
|
|
|
|
.vidioc_querystd = vpif_querystd,
|
|
|
|
.vidioc_s_std = vpif_s_std,
|
|
|
|
.vidioc_g_std = vpif_g_std,
|
|
|
|
.vidioc_qbuf = vpif_qbuf,
|
|
|
|
.vidioc_dqbuf = vpif_dqbuf,
|
|
|
|
.vidioc_streamon = vpif_streamon,
|
|
|
|
.vidioc_streamoff = vpif_streamoff,
|
|
|
|
.vidioc_cropcap = vpif_cropcap,
|
2012-09-18 10:18:47 +00:00
|
|
|
.vidioc_enum_dv_timings = vpif_enum_dv_timings,
|
|
|
|
.vidioc_query_dv_timings = vpif_query_dv_timings,
|
2010-12-16 15:17:44 +00:00
|
|
|
.vidioc_s_dv_timings = vpif_s_dv_timings,
|
|
|
|
.vidioc_g_dv_timings = vpif_g_dv_timings,
|
2010-12-16 15:17:41 +00:00
|
|
|
.vidioc_log_status = vpif_log_status,
|
2009-09-16 17:31:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* vpif file operations */
|
|
|
|
static struct v4l2_file_operations vpif_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = vpif_open,
|
|
|
|
.release = vpif_release,
|
2011-01-04 09:51:35 +00:00
|
|
|
.unlocked_ioctl = video_ioctl2,
|
2014-05-16 13:33:40 +00:00
|
|
|
.mmap = vb2_fop_mmap,
|
|
|
|
.poll = vb2_fop_poll
|
2009-09-16 17:31:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* vpif video template */
|
|
|
|
static struct video_device vpif_video_template = {
|
|
|
|
.name = "vpif",
|
|
|
|
.fops = &vpif_fops,
|
|
|
|
.minor = -1,
|
|
|
|
.ioctl_ops = &vpif_ioctl_ops,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* initialize_vpif() - Initialize vpif data structures
|
|
|
|
*
|
|
|
|
* Allocate memory for data structures and initialize them
|
|
|
|
*/
|
|
|
|
static int initialize_vpif(void)
|
|
|
|
{
|
|
|
|
int err = 0, i, j;
|
|
|
|
int free_channel_objects_index;
|
|
|
|
|
|
|
|
/* Default number of buffers should be 3 */
|
|
|
|
if ((ch0_numbuffers > 0) &&
|
|
|
|
(ch0_numbuffers < config_params.min_numbuffers))
|
|
|
|
ch0_numbuffers = config_params.min_numbuffers;
|
|
|
|
if ((ch1_numbuffers > 0) &&
|
|
|
|
(ch1_numbuffers < config_params.min_numbuffers))
|
|
|
|
ch1_numbuffers = config_params.min_numbuffers;
|
|
|
|
|
|
|
|
/* Set buffer size to min buffers size if it is invalid */
|
|
|
|
if (ch0_bufsize < config_params.min_bufsize[VPIF_CHANNEL0_VIDEO])
|
|
|
|
ch0_bufsize =
|
|
|
|
config_params.min_bufsize[VPIF_CHANNEL0_VIDEO];
|
|
|
|
if (ch1_bufsize < config_params.min_bufsize[VPIF_CHANNEL1_VIDEO])
|
|
|
|
ch1_bufsize =
|
|
|
|
config_params.min_bufsize[VPIF_CHANNEL1_VIDEO];
|
|
|
|
|
|
|
|
config_params.numbuffers[VPIF_CHANNEL0_VIDEO] = ch0_numbuffers;
|
|
|
|
config_params.numbuffers[VPIF_CHANNEL1_VIDEO] = ch1_numbuffers;
|
|
|
|
if (ch0_numbuffers) {
|
|
|
|
config_params.channel_bufsize[VPIF_CHANNEL0_VIDEO]
|
|
|
|
= ch0_bufsize;
|
|
|
|
}
|
|
|
|
if (ch1_numbuffers) {
|
|
|
|
config_params.channel_bufsize[VPIF_CHANNEL1_VIDEO]
|
|
|
|
= ch1_bufsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate memory for six channel objects */
|
|
|
|
for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
|
|
|
|
vpif_obj.dev[i] =
|
|
|
|
kzalloc(sizeof(*vpif_obj.dev[i]), GFP_KERNEL);
|
|
|
|
/* If memory allocation fails, return error */
|
|
|
|
if (!vpif_obj.dev[i]) {
|
|
|
|
free_channel_objects_index = i;
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto vpif_init_free_channel_objects;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
vpif_init_free_channel_objects:
|
|
|
|
for (j = 0; j < free_channel_objects_index; j++)
|
|
|
|
kfree(vpif_obj.dev[j]);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-06-25 14:17:34 +00:00
|
|
|
static int vpif_async_bound(struct v4l2_async_notifier *notifier,
|
|
|
|
struct v4l2_subdev *subdev,
|
|
|
|
struct v4l2_async_subdev *asd)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < vpif_obj.config->subdev_count; i++)
|
|
|
|
if (!strcmp(vpif_obj.config->subdev_info[i].name,
|
|
|
|
subdev->name)) {
|
|
|
|
vpif_obj.sd[i] = subdev;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vpif_probe_complete(void)
|
|
|
|
{
|
|
|
|
struct common_obj *common;
|
2014-05-16 13:33:40 +00:00
|
|
|
struct video_device *vdev;
|
2013-06-25 14:17:34 +00:00
|
|
|
struct channel_obj *ch;
|
2014-05-16 13:33:31 +00:00
|
|
|
struct vb2_queue *q;
|
2013-06-25 14:17:34 +00:00
|
|
|
int i, j, err, k;
|
|
|
|
|
|
|
|
for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
|
|
|
|
ch = vpif_obj.dev[j];
|
|
|
|
ch->channel_id = j;
|
|
|
|
common = &(ch->common[VPIF_VIDEO_INDEX]);
|
|
|
|
spin_lock_init(&common->irqlock);
|
|
|
|
mutex_init(&common->lock);
|
|
|
|
ch->video_dev->lock = &common->lock;
|
|
|
|
/* Initialize prio member of channel object */
|
|
|
|
v4l2_prio_init(&ch->prio);
|
|
|
|
video_set_drvdata(ch->video_dev, ch);
|
|
|
|
|
|
|
|
/* select input 0 */
|
|
|
|
err = vpif_set_input(vpif_obj.config, ch, 0);
|
|
|
|
if (err)
|
|
|
|
goto probe_out;
|
|
|
|
|
2014-05-16 13:33:31 +00:00
|
|
|
/* Initialize vb2 queue */
|
|
|
|
q = &common->buffer_queue;
|
|
|
|
q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
|
|
|
|
q->drv_priv = ch;
|
|
|
|
q->ops = &video_qops;
|
|
|
|
q->mem_ops = &vb2_dma_contig_memops;
|
|
|
|
q->buf_struct_size = sizeof(struct vpif_cap_buffer);
|
|
|
|
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
|
|
|
|
q->min_buffers_needed = 1;
|
2014-05-16 13:33:33 +00:00
|
|
|
q->lock = &common->lock;
|
2014-05-16 13:33:31 +00:00
|
|
|
|
|
|
|
err = vb2_queue_init(q);
|
|
|
|
if (err) {
|
|
|
|
vpif_err("vpif_capture: vb2_queue_init() failed\n");
|
|
|
|
goto probe_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev);
|
|
|
|
if (IS_ERR(common->alloc_ctx)) {
|
|
|
|
vpif_err("Failed to get the context\n");
|
|
|
|
err = PTR_ERR(common->alloc_ctx);
|
|
|
|
goto probe_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&common->dma_queue);
|
|
|
|
|
2014-05-16 13:33:40 +00:00
|
|
|
vdev = ch->video_dev;
|
|
|
|
vdev->queue = q;
|
|
|
|
err = video_register_device(vdev,
|
2013-06-25 14:17:34 +00:00
|
|
|
VFL_TYPE_GRABBER, (j ? 1 : 0));
|
|
|
|
if (err)
|
|
|
|
goto probe_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
v4l2_info(&vpif_obj.v4l2_dev, "VPIF capture driver initialized\n");
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
probe_out:
|
|
|
|
for (k = 0; k < j; k++) {
|
|
|
|
/* Get the pointer to the channel object */
|
|
|
|
ch = vpif_obj.dev[k];
|
2014-05-16 13:33:31 +00:00
|
|
|
common = &ch->common[k];
|
|
|
|
vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
|
2013-06-25 14:17:34 +00:00
|
|
|
/* Unregister video device */
|
|
|
|
video_unregister_device(ch->video_dev);
|
|
|
|
}
|
|
|
|
kfree(vpif_obj.sd);
|
|
|
|
for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
|
|
|
|
ch = vpif_obj.dev[i];
|
|
|
|
/* Note: does nothing if ch->video_dev == NULL */
|
|
|
|
video_device_release(ch->video_dev);
|
|
|
|
}
|
|
|
|
v4l2_device_unregister(&vpif_obj.v4l2_dev);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vpif_async_complete(struct v4l2_async_notifier *notifier)
|
|
|
|
{
|
|
|
|
return vpif_probe_complete();
|
|
|
|
}
|
|
|
|
|
2009-09-16 17:31:10 +00:00
|
|
|
/**
|
|
|
|
* vpif_probe : This function probes the vpif capture driver
|
|
|
|
* @pdev: platform device pointer
|
|
|
|
*
|
|
|
|
* This creates device entries by register itself to the V4L2 driver and
|
|
|
|
* initializes fields of each channel objects
|
|
|
|
*/
|
|
|
|
static __init int vpif_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct vpif_subdev_info *subdevdata;
|
2013-06-25 14:17:34 +00:00
|
|
|
int i, j, err;
|
2012-09-20 12:06:29 +00:00
|
|
|
int res_idx = 0;
|
2009-09-16 17:31:10 +00:00
|
|
|
struct i2c_adapter *i2c_adap;
|
|
|
|
struct channel_obj *ch;
|
|
|
|
struct video_device *vfd;
|
|
|
|
struct resource *res;
|
|
|
|
int subdev_count;
|
2012-04-13 07:49:34 +00:00
|
|
|
size_t size;
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
vpif_dev = &pdev->dev;
|
|
|
|
|
|
|
|
err = initialize_vpif();
|
|
|
|
if (err) {
|
|
|
|
v4l2_err(vpif_dev->driver, "Error initializing vpif\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-12-13 08:44:42 +00:00
|
|
|
err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
|
|
|
|
if (err) {
|
|
|
|
v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-09-20 12:06:29 +00:00
|
|
|
while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
|
2013-06-17 14:20:47 +00:00
|
|
|
err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
|
|
|
|
IRQF_SHARED, "VPIF_Capture",
|
|
|
|
(void *)(&vpif_obj.dev[res_idx]->
|
|
|
|
channel_id));
|
|
|
|
if (err) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto vpif_unregister;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
2012-09-20 12:06:29 +00:00
|
|
|
res_idx++;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
|
|
|
|
/* Get the pointer to the channel object */
|
|
|
|
ch = vpif_obj.dev[i];
|
|
|
|
/* Allocate memory for video device */
|
|
|
|
vfd = video_device_alloc();
|
|
|
|
if (NULL == vfd) {
|
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
ch = vpif_obj.dev[j];
|
|
|
|
video_device_release(ch->video_dev);
|
|
|
|
}
|
|
|
|
err = -ENOMEM;
|
2013-06-17 14:20:46 +00:00
|
|
|
goto vpif_unregister;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize field of video device */
|
|
|
|
*vfd = vpif_video_template;
|
|
|
|
vfd->v4l2_dev = &vpif_obj.v4l2_dev;
|
|
|
|
vfd->release = video_device_release;
|
|
|
|
snprintf(vfd->name, sizeof(vfd->name),
|
2012-04-13 07:44:00 +00:00
|
|
|
"VPIF_Capture_DRIVER_V%s",
|
2011-06-25 14:28:37 +00:00
|
|
|
VPIF_CAPTURE_VERSION);
|
2009-09-16 17:31:10 +00:00
|
|
|
/* Set video_dev to the video device */
|
|
|
|
ch->video_dev = vfd;
|
|
|
|
}
|
|
|
|
|
2012-04-13 07:49:34 +00:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (res) {
|
|
|
|
size = resource_size(res);
|
|
|
|
/* The resources are divided into two equal memory and when we
|
|
|
|
* have HD output we can add them together
|
|
|
|
*/
|
|
|
|
for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
|
|
|
|
ch = vpif_obj.dev[j];
|
|
|
|
ch->channel_id = j;
|
|
|
|
/* only enabled if second resource exists */
|
|
|
|
config_params.video_limit[ch->channel_id] = 0;
|
|
|
|
if (size)
|
|
|
|
config_params.video_limit[ch->channel_id] =
|
|
|
|
size/2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-25 14:17:34 +00:00
|
|
|
vpif_obj.config = pdev->dev.platform_data;
|
2009-09-16 17:31:10 +00:00
|
|
|
|
2013-06-25 14:17:34 +00:00
|
|
|
subdev_count = vpif_obj.config->subdev_count;
|
2010-08-30 13:30:37 +00:00
|
|
|
vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count,
|
2009-09-16 17:31:10 +00:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (vpif_obj.sd == NULL) {
|
|
|
|
vpif_err("unable to allocate memory for subdevice pointers\n");
|
|
|
|
err = -ENOMEM;
|
2012-09-20 12:06:29 +00:00
|
|
|
goto vpif_sd_error;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 14:17:34 +00:00
|
|
|
if (!vpif_obj.config->asd_sizes) {
|
|
|
|
i2c_adap = i2c_get_adapter(1);
|
|
|
|
for (i = 0; i < subdev_count; i++) {
|
|
|
|
subdevdata = &vpif_obj.config->subdev_info[i];
|
|
|
|
vpif_obj.sd[i] =
|
|
|
|
v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
|
|
|
|
i2c_adap,
|
|
|
|
&subdevdata->
|
|
|
|
board_info,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (!vpif_obj.sd[i]) {
|
|
|
|
vpif_err("Error registering v4l2 subdevice\n");
|
2013-09-02 08:06:10 +00:00
|
|
|
err = -ENODEV;
|
2013-06-25 14:17:34 +00:00
|
|
|
goto probe_subdev_out;
|
|
|
|
}
|
|
|
|
v4l2_info(&vpif_obj.v4l2_dev,
|
|
|
|
"registered sub device %s\n",
|
|
|
|
subdevdata->name);
|
|
|
|
}
|
|
|
|
vpif_probe_complete();
|
|
|
|
} else {
|
2013-07-19 15:31:10 +00:00
|
|
|
vpif_obj.notifier.subdevs = vpif_obj.config->asd;
|
2013-06-25 14:17:34 +00:00
|
|
|
vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0];
|
|
|
|
vpif_obj.notifier.bound = vpif_async_bound;
|
|
|
|
vpif_obj.notifier.complete = vpif_async_complete;
|
|
|
|
err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev,
|
|
|
|
&vpif_obj.notifier);
|
|
|
|
if (err) {
|
|
|
|
vpif_err("Error registering async notifier\n");
|
|
|
|
err = -EINVAL;
|
2009-09-16 17:31:10 +00:00
|
|
|
goto probe_subdev_out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2012-09-20 12:06:26 +00:00
|
|
|
probe_subdev_out:
|
|
|
|
/* free sub devices memory */
|
|
|
|
kfree(vpif_obj.sd);
|
2009-09-16 17:31:10 +00:00
|
|
|
|
2012-09-20 12:06:29 +00:00
|
|
|
vpif_sd_error:
|
|
|
|
for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
|
|
|
|
ch = vpif_obj.dev[i];
|
|
|
|
/* Note: does nothing if ch->video_dev == NULL */
|
|
|
|
video_device_release(ch->video_dev);
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
2013-06-17 14:20:46 +00:00
|
|
|
vpif_unregister:
|
2011-12-13 08:44:42 +00:00
|
|
|
v4l2_device_unregister(&vpif_obj.v4l2_dev);
|
2013-06-17 14:20:46 +00:00
|
|
|
|
2009-09-16 17:31:10 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vpif_remove() - driver remove handler
|
|
|
|
* @device: ptr to platform device structure
|
|
|
|
*
|
|
|
|
* The vidoe device is unregistered
|
|
|
|
*/
|
|
|
|
static int vpif_remove(struct platform_device *device)
|
|
|
|
{
|
2014-05-16 13:33:31 +00:00
|
|
|
struct common_obj *common;
|
2009-09-16 17:31:10 +00:00
|
|
|
struct channel_obj *ch;
|
2013-06-17 14:20:46 +00:00
|
|
|
int i;
|
2009-09-16 17:31:10 +00:00
|
|
|
|
|
|
|
v4l2_device_unregister(&vpif_obj.v4l2_dev);
|
|
|
|
|
2013-06-17 14:20:44 +00:00
|
|
|
kfree(vpif_obj.sd);
|
2009-09-16 17:31:10 +00:00
|
|
|
/* un-register device */
|
|
|
|
for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
|
|
|
|
/* Get the pointer to the channel object */
|
|
|
|
ch = vpif_obj.dev[i];
|
2014-05-16 13:33:31 +00:00
|
|
|
common = &ch->common[i];
|
|
|
|
vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
|
2009-09-16 17:31:10 +00:00
|
|
|
/* Unregister video device */
|
|
|
|
video_unregister_device(ch->video_dev);
|
2013-06-17 14:20:44 +00:00
|
|
|
kfree(vpif_obj.dev[i]);
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-13 07:50:55 +00:00
|
|
|
#ifdef CONFIG_PM
|
2009-09-16 17:31:10 +00:00
|
|
|
/**
|
|
|
|
* vpif_suspend: vpif device suspend
|
|
|
|
*/
|
2012-04-13 07:50:55 +00:00
|
|
|
static int vpif_suspend(struct device *dev)
|
2009-09-16 17:31:10 +00:00
|
|
|
{
|
2012-04-13 07:50:55 +00:00
|
|
|
|
|
|
|
struct common_obj *common;
|
|
|
|
struct channel_obj *ch;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
|
|
|
|
/* Get the pointer to the channel object */
|
|
|
|
ch = vpif_obj.dev[i];
|
|
|
|
common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
mutex_lock(&common->lock);
|
|
|
|
if (ch->usrs && common->io_usrs) {
|
|
|
|
/* Disable channel */
|
|
|
|
if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
|
|
|
|
enable_channel0(0);
|
|
|
|
channel0_intr_enable(0);
|
|
|
|
}
|
|
|
|
if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
|
|
|
|
common->started == 2) {
|
|
|
|
enable_channel1(0);
|
|
|
|
channel1_intr_enable(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&common->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
2012-04-13 07:50:55 +00:00
|
|
|
/*
|
2009-09-16 17:31:10 +00:00
|
|
|
* vpif_resume: vpif device suspend
|
|
|
|
*/
|
2012-04-13 07:50:55 +00:00
|
|
|
static int vpif_resume(struct device *dev)
|
2009-09-16 17:31:10 +00:00
|
|
|
{
|
2012-04-13 07:50:55 +00:00
|
|
|
struct common_obj *common;
|
|
|
|
struct channel_obj *ch;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
|
|
|
|
/* Get the pointer to the channel object */
|
|
|
|
ch = vpif_obj.dev[i];
|
|
|
|
common = &ch->common[VPIF_VIDEO_INDEX];
|
|
|
|
mutex_lock(&common->lock);
|
|
|
|
if (ch->usrs && common->io_usrs) {
|
|
|
|
/* Disable channel */
|
|
|
|
if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
|
|
|
|
enable_channel0(1);
|
|
|
|
channel0_intr_enable(1);
|
|
|
|
}
|
|
|
|
if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
|
|
|
|
common->started == 2) {
|
|
|
|
enable_channel1(1);
|
|
|
|
channel1_intr_enable(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&common->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-09-16 17:31:10 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 02:00:08 +00:00
|
|
|
static const struct dev_pm_ops vpif_dev_pm_ops = {
|
2009-09-16 17:31:10 +00:00
|
|
|
.suspend = vpif_suspend,
|
|
|
|
.resume = vpif_resume,
|
|
|
|
};
|
|
|
|
|
2012-04-13 07:50:55 +00:00
|
|
|
#define vpif_pm_ops (&vpif_dev_pm_ops)
|
|
|
|
#else
|
|
|
|
#define vpif_pm_ops NULL
|
|
|
|
#endif
|
|
|
|
|
2010-08-30 13:30:36 +00:00
|
|
|
static __refdata struct platform_driver vpif_driver = {
|
2009-09-16 17:31:10 +00:00
|
|
|
.driver = {
|
|
|
|
.name = "vpif_capture",
|
|
|
|
.owner = THIS_MODULE,
|
2012-04-13 07:50:55 +00:00
|
|
|
.pm = vpif_pm_ops,
|
2009-09-16 17:31:10 +00:00
|
|
|
},
|
|
|
|
.probe = vpif_probe,
|
|
|
|
.remove = vpif_remove,
|
|
|
|
};
|
|
|
|
|
2013-06-17 14:20:45 +00:00
|
|
|
module_platform_driver(vpif_driver);
|