Commit ad614acb authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

[media] omap3isp: Video devices and buffers queue

The OMAP3 ISP video devices and buffers queue modules implement the V4L2
API on all the ISP video nodes.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@iki.fi>
Signed-off-by: default avatarDavid Cohen <dacohen@gmail.com>
Signed-off-by: default avatarStanimir Varbanov <svarbanov@mm-sol.com>
Signed-off-by: default avatarVimarsh Zutshi <vimarsh.zutshi@gmail.com>
Signed-off-by: default avatarTuukka Toivonen <tuukkat76@gmail.com>
Signed-off-by: default avatarSergio Aguirre <saaguirre@ti.com>
Signed-off-by: default avatarAntti Koskipaa <akoskipa@gmail.com>
Signed-off-by: default avatarIvan T. Ivanov <iivanov@mm-sol.com>
Signed-off-by: default avatarRaniSuneela <r-m@ti.com>
Signed-off-by: default avatarAtanas Filipov <afilipov@mm-sol.com>
Signed-off-by: default avatarGjorgji Rosikopulos <grosikopulos@mm-sol.com>
Signed-off-by: default avatarHiroshi DOYU <Hiroshi.DOYU@nokia.com>
Signed-off-by: default avatarNayden Kanchev <nkanchev@mm-sol.com>
Signed-off-by: default avatarPhil Carmody <ext-phil.2.carmody@nokia.com>
Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: default avatarDominic Curran <dcurran@ti.com>
Signed-off-by: default avatarIlkka Myllyperkio <ilkka.myllyperkio@sofica.fi>
Signed-off-by: default avatarPallavi Kulkarni <p-kulkarni@ti.com>
Signed-off-by: default avatarVaibhav Hiremath <hvaibhav@ti.com>
Acked-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 448de7e7
This diff is collapsed.
/*
* ispqueue.h
*
* TI OMAP3 ISP - Video buffers queue handling
*
* Copyright (C) 2010 Nokia Corporation
*
* Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
* Sakari Ailus <sakari.ailus@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef OMAP3_ISP_QUEUE_H
#define OMAP3_ISP_QUEUE_H
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/videodev2.h>
#include <linux/wait.h>
struct isp_video_queue;
struct page;
struct scatterlist;
#define ISP_VIDEO_MAX_BUFFERS 16
/**
* enum isp_video_buffer_state - ISP video buffer state
* @ISP_BUF_STATE_IDLE: The buffer is under userspace control (dequeued
* or not queued yet).
* @ISP_BUF_STATE_QUEUED: The buffer has been queued but isn't used by the
* device yet.
* @ISP_BUF_STATE_ACTIVE: The buffer is in use for an active video transfer.
* @ISP_BUF_STATE_ERROR: The device is done with the buffer and an error
* occured. For capture device the buffer likely contains corrupted data or
* no data at all.
* @ISP_BUF_STATE_DONE: The device is done with the buffer and no error occured.
* For capture devices the buffer contains valid data.
*/
enum isp_video_buffer_state {
ISP_BUF_STATE_IDLE,
ISP_BUF_STATE_QUEUED,
ISP_BUF_STATE_ACTIVE,
ISP_BUF_STATE_ERROR,
ISP_BUF_STATE_DONE,
};
/**
* struct isp_video_buffer - ISP video buffer
* @vma_use_count: Number of times the buffer is mmap'ed to userspace
* @stream: List head for insertion into main queue
* @queue: ISP buffers queue this buffer belongs to
* @prepared: Whether the buffer has been prepared
* @skip_cache: Whether to skip cache management operations for this buffer
* @vaddr: Memory virtual address (for kernel buffers)
* @vm_flags: Buffer VMA flags (for userspace buffers)
* @offset: Offset inside the first page (for userspace buffers)
* @npages: Number of pages (for userspace buffers)
* @pages: Pages table (for userspace non-VM_PFNMAP buffers)
* @paddr: Memory physical address (for userspace VM_PFNMAP buffers)
* @sglen: Number of elements in the scatter list (for non-VM_PFNMAP buffers)
* @sglist: Scatter list (for non-VM_PFNMAP buffers)
* @vbuf: V4L2 buffer
* @irqlist: List head for insertion into IRQ queue
* @state: Current buffer state
* @wait: Wait queue to signal buffer completion
*/
struct isp_video_buffer {
unsigned long vma_use_count;
struct list_head stream;
struct isp_video_queue *queue;
unsigned int prepared:1;
bool skip_cache;
/* For kernel buffers. */
void *vaddr;
/* For userspace buffers. */
unsigned long vm_flags;
unsigned long offset;
unsigned int npages;
struct page **pages;
dma_addr_t paddr;
/* For all buffers except VM_PFNMAP. */
unsigned int sglen;
struct scatterlist *sglist;
/* Touched by the interrupt handler. */
struct v4l2_buffer vbuf;
struct list_head irqlist;
enum isp_video_buffer_state state;
wait_queue_head_t wait;
};
#define to_isp_video_buffer(vb) container_of(vb, struct isp_video_buffer, vb)
/**
* struct isp_video_queue_operations - Driver-specific operations
* @queue_prepare: Called before allocating buffers. Drivers should clamp the
* number of buffers according to their requirements, and must return the
* buffer size in bytes.
* @buffer_prepare: Called the first time a buffer is queued, or after changing
* the userspace memory address for a USERPTR buffer, with the queue lock
* held. Drivers should perform device-specific buffer preparation (such as
* mapping the buffer memory in an IOMMU). This operation is optional.
* @buffer_queue: Called when a buffer is being added to the queue with the
* queue irqlock spinlock held.
* @buffer_cleanup: Called before freeing buffers, or before changing the
* userspace memory address for a USERPTR buffer, with the queue lock held.
* Drivers must perform cleanup operations required to undo the
* buffer_prepare call. This operation is optional.
*/
struct isp_video_queue_operations {
void (*queue_prepare)(struct isp_video_queue *queue,
unsigned int *nbuffers, unsigned int *size);
int (*buffer_prepare)(struct isp_video_buffer *buf);
void (*buffer_queue)(struct isp_video_buffer *buf);
void (*buffer_cleanup)(struct isp_video_buffer *buf);
};
/**
* struct isp_video_queue - ISP video buffers queue
* @type: Type of video buffers handled by this queue
* @ops: Queue operations
* @dev: Device used for DMA operations
* @bufsize: Size of a driver-specific buffer object
* @count: Number of currently allocated buffers
* @buffers: ISP video buffers
* @lock: Mutex to protect access to the buffers, main queue and state
* @irqlock: Spinlock to protect access to the IRQ queue
* @streaming: Queue state, indicates whether the queue is streaming
* @queue: List of all queued buffers
*/
struct isp_video_queue {
enum v4l2_buf_type type;
const struct isp_video_queue_operations *ops;
struct device *dev;
unsigned int bufsize;
unsigned int count;
struct isp_video_buffer *buffers[ISP_VIDEO_MAX_BUFFERS];
struct mutex lock;
spinlock_t irqlock;
unsigned int streaming:1;
struct list_head queue;
};
int omap3isp_video_queue_cleanup(struct isp_video_queue *queue);
int omap3isp_video_queue_init(struct isp_video_queue *queue,
enum v4l2_buf_type type,
const struct isp_video_queue_operations *ops,
struct device *dev, unsigned int bufsize);
int omap3isp_video_queue_reqbufs(struct isp_video_queue *queue,
struct v4l2_requestbuffers *rb);
int omap3isp_video_queue_querybuf(struct isp_video_queue *queue,
struct v4l2_buffer *vbuf);
int omap3isp_video_queue_qbuf(struct isp_video_queue *queue,
struct v4l2_buffer *vbuf);
int omap3isp_video_queue_dqbuf(struct isp_video_queue *queue,
struct v4l2_buffer *vbuf, int nonblocking);
int omap3isp_video_queue_streamon(struct isp_video_queue *queue);
void omap3isp_video_queue_streamoff(struct isp_video_queue *queue);
void omap3isp_video_queue_discard_done(struct isp_video_queue *queue);
int omap3isp_video_queue_mmap(struct isp_video_queue *queue,
struct vm_area_struct *vma);
unsigned int omap3isp_video_queue_poll(struct isp_video_queue *queue,
struct file *file, poll_table *wait);
#endif /* OMAP3_ISP_QUEUE_H */
This diff is collapsed.
/*
* ispvideo.h
*
* TI OMAP3 ISP - Generic video node
*
* Copyright (C) 2009-2010 Nokia Corporation
*
* Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
* Sakari Ailus <sakari.ailus@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef OMAP3_ISP_VIDEO_H
#define OMAP3_ISP_VIDEO_H
#include <linux/v4l2-mediabus.h>
#include <linux/version.h>
#include <media/media-entity.h>
#include <media/v4l2-dev.h>
#include <media/v4l2-fh.h>
#include "ispqueue.h"
#define ISP_VIDEO_DRIVER_NAME "ispvideo"
#define ISP_VIDEO_DRIVER_VERSION KERNEL_VERSION(0, 0, 1)
struct isp_device;
struct isp_video;
struct v4l2_mbus_framefmt;
struct v4l2_pix_format;
/*
* struct isp_format_info - ISP media bus format information
* @code: V4L2 media bus format code
* @truncated: V4L2 media bus format code for the same format truncated to 10
* bits. Identical to @code if the format is 10 bits wide or less.
* @uncompressed: V4L2 media bus format code for the corresponding uncompressed
* format. Identical to @code if the format is not DPCM compressed.
* @pixelformat: V4L2 pixel format FCC identifier
* @bpp: Bits per pixel
*/
struct isp_format_info {
enum v4l2_mbus_pixelcode code;
enum v4l2_mbus_pixelcode truncated;
enum v4l2_mbus_pixelcode uncompressed;
u32 pixelformat;
unsigned int bpp;
};
enum isp_pipeline_stream_state {
ISP_PIPELINE_STREAM_STOPPED = 0,
ISP_PIPELINE_STREAM_CONTINUOUS = 1,
ISP_PIPELINE_STREAM_SINGLESHOT = 2,
};
enum isp_pipeline_state {
/* The stream has been started on the input video node. */
ISP_PIPELINE_STREAM_INPUT = 1,
/* The stream has been started on the output video node. */
ISP_PIPELINE_STREAM_OUTPUT = 2,
/* At least one buffer is queued on the input video node. */
ISP_PIPELINE_QUEUE_INPUT = 4,
/* At least one buffer is queued on the output video node. */
ISP_PIPELINE_QUEUE_OUTPUT = 8,
/* The input entity is idle, ready to be started. */
ISP_PIPELINE_IDLE_INPUT = 16,
/* The output entity is idle, ready to be started. */
ISP_PIPELINE_IDLE_OUTPUT = 32,
/* The pipeline is currently streaming. */
ISP_PIPELINE_STREAM = 64,
};
struct isp_pipeline {
struct media_pipeline pipe;
spinlock_t lock; /* Pipeline state and queue flags */
unsigned int state;
enum isp_pipeline_stream_state stream_state;
struct isp_video *input;
struct isp_video *output;
unsigned long l3_ick;
unsigned int max_rate;
atomic_t frame_number;
bool do_propagation; /* of frame number */
struct v4l2_fract max_timeperframe;
};
#define to_isp_pipeline(__e) \
container_of((__e)->pipe, struct isp_pipeline, pipe)
static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
{
return pipe->state == (ISP_PIPELINE_STREAM_INPUT |
ISP_PIPELINE_STREAM_OUTPUT |
ISP_PIPELINE_QUEUE_INPUT |
ISP_PIPELINE_QUEUE_OUTPUT |
ISP_PIPELINE_IDLE_INPUT |
ISP_PIPELINE_IDLE_OUTPUT);
}
/*
* struct isp_buffer - ISP buffer
* @buffer: ISP video buffer
* @isp_addr: MMU mapped address (a.k.a. device address) of the buffer.
*/
struct isp_buffer {
struct isp_video_buffer buffer;
dma_addr_t isp_addr;
};
#define to_isp_buffer(buf) container_of(buf, struct isp_buffer, buffer)
enum isp_video_dmaqueue_flags {
/* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */
ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
/* Set when queuing buffer to an empty DMA queue */
ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
};
#define isp_video_dmaqueue_flags_clr(video) \
({ (video)->dmaqueue_flags = 0; })
/*
* struct isp_video_operations - ISP video operations
* @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
* if there was no buffer previously queued.
*/
struct isp_video_operations {
int(*queue)(struct isp_video *video, struct isp_buffer *buffer);
};
struct isp_video {
struct video_device video;
enum v4l2_buf_type type;
struct media_pad pad;
struct mutex mutex; /* format and crop settings */
atomic_t active;
struct isp_device *isp;
unsigned int capture_mem;
unsigned int bpl_alignment; /* alignment value */
unsigned int bpl_zero_padding; /* whether the alignment is optional */
unsigned int bpl_max; /* maximum bytes per line value */
unsigned int bpl_value; /* bytes per line value */
unsigned int bpl_padding; /* padding at end of line */
/* Entity video node streaming */
unsigned int streaming:1;
/* Pipeline state */
struct isp_pipeline pipe;
struct mutex stream_lock; /* pipeline and stream states */
/* Video buffers queue */
struct isp_video_queue *queue;
struct list_head dmaqueue;
enum isp_video_dmaqueue_flags dmaqueue_flags;
const struct isp_video_operations *ops;
};
#define to_isp_video(vdev) container_of(vdev, struct isp_video, video)
struct isp_video_fh {
struct v4l2_fh vfh;
struct isp_video *video;
struct isp_video_queue queue;
struct v4l2_format format;
struct v4l2_fract timeperframe;
};
#define to_isp_video_fh(fh) container_of(fh, struct isp_video_fh, vfh)
#define isp_video_queue_to_isp_video_fh(q) \
container_of(q, struct isp_video_fh, queue)
int omap3isp_video_init(struct isp_video *video, const char *name);
int omap3isp_video_register(struct isp_video *video,
struct v4l2_device *vdev);
void omap3isp_video_unregister(struct isp_video *video);
struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video,
unsigned int error);
void omap3isp_video_resume(struct isp_video *video, int continuous);
struct media_pad *omap3isp_video_remote_pad(struct isp_video *video);
const struct isp_format_info *
omap3isp_video_format_info(enum v4l2_mbus_pixelcode code);
#endif /* OMAP3_ISP_VIDEO_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment