2012-04-21 06:43:14 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Samsung Electronics Co., Ltd.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FIMC_LITE_H_
|
|
|
|
#define FIMC_LITE_H_
|
|
|
|
|
2012-08-17 14:28:26 +08:00
|
|
|
#include <linux/sizes.h>
|
2012-04-21 06:43:14 +08:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/irqreturn.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
|
|
|
|
#include <media/media-entity.h>
|
2015-09-22 21:30:29 +08:00
|
|
|
#include <media/videobuf2-v4l2.h>
|
2013-02-26 00:20:21 +08:00
|
|
|
#include <media/v4l2-ctrls.h>
|
2012-04-21 06:43:14 +08:00
|
|
|
#include <media/v4l2-device.h>
|
|
|
|
#include <media/v4l2-mediabus.h>
|
2014-04-15 19:35:25 +08:00
|
|
|
#include <media/exynos-fimc.h>
|
2012-04-21 06:43:14 +08:00
|
|
|
|
|
|
|
#define FIMC_LITE_DRV_NAME "exynos-fimc-lite"
|
|
|
|
#define FLITE_CLK_NAME "flite"
|
2013-06-14 23:38:15 +08:00
|
|
|
#define FIMC_LITE_MAX_DEVS 3
|
2012-04-21 06:43:14 +08:00
|
|
|
#define FLITE_REQ_BUFS_MIN 2
|
2013-06-18 19:00:42 +08:00
|
|
|
#define FLITE_DEFAULT_WIDTH 640
|
|
|
|
#define FLITE_DEFAULT_HEIGHT 480
|
2012-04-21 06:43:14 +08:00
|
|
|
|
|
|
|
/* Bit index definitions for struct fimc_lite::state */
|
|
|
|
enum {
|
|
|
|
ST_FLITE_LPM,
|
|
|
|
ST_FLITE_PENDING,
|
|
|
|
ST_FLITE_RUN,
|
|
|
|
ST_FLITE_STREAM,
|
|
|
|
ST_FLITE_SUSPENDED,
|
|
|
|
ST_FLITE_OFF,
|
|
|
|
ST_FLITE_IN_USE,
|
|
|
|
ST_FLITE_CONFIG,
|
|
|
|
ST_SENSOR_STREAM,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FLITE_SD_PAD_SINK 0
|
2012-11-29 02:41:01 +08:00
|
|
|
#define FLITE_SD_PAD_SOURCE_DMA 1
|
|
|
|
#define FLITE_SD_PAD_SOURCE_ISP 2
|
|
|
|
#define FLITE_SD_PADS_NUM 3
|
2012-04-21 06:43:14 +08:00
|
|
|
|
2013-06-14 23:38:15 +08:00
|
|
|
/**
|
|
|
|
* struct flite_drvdata - FIMC-LITE IP variant data structure
|
|
|
|
* @max_width: maximum camera interface input width in pixels
|
|
|
|
* @max_height: maximum camera interface input height in pixels
|
|
|
|
* @out_width_align: minimum output width alignment in pixels
|
|
|
|
* @win_hor_offs_align: minimum camera interface crop window horizontal
|
|
|
|
* offset alignment in pixels
|
|
|
|
* @out_hor_offs_align: minimum output DMA compose rectangle horizontal
|
|
|
|
* offset alignment in pixels
|
|
|
|
* @max_dma_bufs: number of output DMA buffer start address registers
|
|
|
|
* @num_instances: total number of FIMC-LITE IP instances available
|
|
|
|
*/
|
2013-03-17 04:35:10 +08:00
|
|
|
struct flite_drvdata {
|
2012-04-21 06:43:14 +08:00
|
|
|
unsigned short max_width;
|
|
|
|
unsigned short max_height;
|
|
|
|
unsigned short out_width_align;
|
|
|
|
unsigned short win_hor_offs_align;
|
|
|
|
unsigned short out_hor_offs_align;
|
2013-06-14 23:38:15 +08:00
|
|
|
unsigned short max_dma_bufs;
|
|
|
|
unsigned short num_instances;
|
2012-04-21 06:43:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct fimc_lite_events {
|
|
|
|
unsigned int data_overflow;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FLITE_MAX_PLANES 1
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct flite_frame - source/target frame properties
|
|
|
|
* @f_width: full pixel width
|
|
|
|
* @f_height: full pixel height
|
|
|
|
* @rect: crop/composition rectangle
|
2013-03-21 02:31:03 +08:00
|
|
|
* @fmt: pointer to pixel format description data structure
|
2012-04-21 06:43:14 +08:00
|
|
|
*/
|
|
|
|
struct flite_frame {
|
|
|
|
u16 f_width;
|
|
|
|
u16 f_height;
|
|
|
|
struct v4l2_rect rect;
|
2013-03-21 02:31:03 +08:00
|
|
|
const struct fimc_fmt *fmt;
|
2012-04-21 06:43:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct flite_buffer - video buffer structure
|
|
|
|
* @vb: vb2 buffer
|
|
|
|
* @list: list head for the buffers queue
|
2013-06-14 23:38:15 +08:00
|
|
|
* @paddr: DMA buffer start address
|
|
|
|
* @index: DMA start address register's index
|
2012-04-21 06:43:14 +08:00
|
|
|
*/
|
|
|
|
struct flite_buffer {
|
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 21:30:30 +08:00
|
|
|
struct vb2_v4l2_buffer vb;
|
2012-04-21 06:43:14 +08:00
|
|
|
struct list_head list;
|
|
|
|
dma_addr_t paddr;
|
2013-06-14 23:38:15 +08:00
|
|
|
unsigned short index;
|
2012-04-21 06:43:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct fimc_lite - fimc lite structure
|
|
|
|
* @pdev: pointer to FIMC-LITE platform device
|
2013-03-17 04:35:10 +08:00
|
|
|
* @dd: SoC specific driver data structure
|
2013-05-31 22:37:18 +08:00
|
|
|
* @ve: exynos video device entity structure
|
2012-04-21 06:43:14 +08:00
|
|
|
* @v4l2_dev: pointer to top the level v4l2_device
|
|
|
|
* @fh: v4l2 file handle
|
|
|
|
* @alloc_ctx: videobuf2 memory allocator context
|
|
|
|
* @subdev: FIMC-LITE subdev
|
|
|
|
* @vd_pad: media (sink) pad for the capture video node
|
|
|
|
* @subdev_pads: the subdev media pads
|
2012-11-29 02:41:01 +08:00
|
|
|
* @sensor: sensor subdev attached to FIMC-LITE directly or through MIPI-CSIS
|
2012-04-21 06:43:14 +08:00
|
|
|
* @ctrl_handler: v4l2 control handler
|
|
|
|
* @test_pattern: test pattern controls
|
|
|
|
* @index: FIMC-LITE platform device index
|
|
|
|
* @pipeline: video capture pipeline data structure
|
2012-08-14 21:46:58 +08:00
|
|
|
* @pipeline_ops: media pipeline ops for the video node driver
|
2012-04-21 06:43:14 +08:00
|
|
|
* @slock: spinlock protecting this data structure and the hw registers
|
|
|
|
* @lock: mutex serializing video device and the subdev operations
|
|
|
|
* @clock: FIMC-LITE gate clock
|
|
|
|
* @regs: memory mapped io registers
|
|
|
|
* @irq_queue: interrupt handler waitqueue
|
|
|
|
* @payload: image size in bytes (w x h x bpp)
|
|
|
|
* @inp_frame: camera input frame structure
|
|
|
|
* @out_frame: DMA output frame structure
|
|
|
|
* @out_path: output data path (DMA or FIFO)
|
|
|
|
* @source_subdev_grp_id: source subdev group id
|
|
|
|
* @state: driver state flags
|
|
|
|
* @pending_buf_q: pending buffers queue head
|
|
|
|
* @active_buf_q: the queue head of buffers scheduled in hardware
|
|
|
|
* @vb_queue: vb2 buffers queue
|
2013-06-14 23:38:15 +08:00
|
|
|
* @buf_index: helps to keep track of the DMA start address register index
|
2012-04-21 06:43:14 +08:00
|
|
|
* @active_buf_count: number of video buffers scheduled in hardware
|
|
|
|
* @frame_count: the captured frames counter
|
|
|
|
* @reqbufs_count: the number of buffers requested with REQBUFS ioctl
|
|
|
|
*/
|
|
|
|
struct fimc_lite {
|
|
|
|
struct platform_device *pdev;
|
2013-03-17 04:35:10 +08:00
|
|
|
struct flite_drvdata *dd;
|
2013-05-31 22:37:18 +08:00
|
|
|
struct exynos_video_entity ve;
|
2012-04-21 06:43:14 +08:00
|
|
|
struct v4l2_device *v4l2_dev;
|
|
|
|
struct v4l2_fh fh;
|
|
|
|
struct vb2_alloc_ctx *alloc_ctx;
|
|
|
|
struct v4l2_subdev subdev;
|
|
|
|
struct media_pad vd_pad;
|
|
|
|
struct media_pad subdev_pads[FLITE_SD_PADS_NUM];
|
2012-11-29 02:41:01 +08:00
|
|
|
struct v4l2_subdev *sensor;
|
2012-04-21 06:43:14 +08:00
|
|
|
struct v4l2_ctrl_handler ctrl_handler;
|
|
|
|
struct v4l2_ctrl *test_pattern;
|
2013-04-16 14:02:20 +08:00
|
|
|
int index;
|
2012-04-21 06:43:14 +08:00
|
|
|
|
|
|
|
struct mutex lock;
|
|
|
|
spinlock_t slock;
|
|
|
|
|
|
|
|
struct clk *clock;
|
|
|
|
void __iomem *regs;
|
|
|
|
wait_queue_head_t irq_queue;
|
|
|
|
|
|
|
|
unsigned long payload[FLITE_MAX_PLANES];
|
|
|
|
struct flite_frame inp_frame;
|
|
|
|
struct flite_frame out_frame;
|
2013-01-18 23:02:32 +08:00
|
|
|
atomic_t out_path;
|
2012-04-21 06:43:14 +08:00
|
|
|
unsigned int source_subdev_grp_id;
|
|
|
|
|
|
|
|
unsigned long state;
|
|
|
|
struct list_head pending_buf_q;
|
|
|
|
struct list_head active_buf_q;
|
|
|
|
struct vb2_queue vb_queue;
|
2013-06-14 23:38:15 +08:00
|
|
|
unsigned short buf_index;
|
2012-04-21 06:43:14 +08:00
|
|
|
unsigned int frame_count;
|
|
|
|
unsigned int reqbufs_count;
|
|
|
|
|
|
|
|
struct fimc_lite_events events;
|
2013-03-26 03:50:50 +08:00
|
|
|
bool streaming;
|
2012-04-21 06:43:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline bool fimc_lite_active(struct fimc_lite *fimc)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&fimc->slock, flags);
|
|
|
|
ret = fimc->state & (1 << ST_FLITE_RUN) ||
|
|
|
|
fimc->state & (1 << ST_FLITE_PENDING);
|
|
|
|
spin_unlock_irqrestore(&fimc->slock, flags);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void fimc_lite_active_queue_add(struct fimc_lite *dev,
|
|
|
|
struct flite_buffer *buf)
|
|
|
|
{
|
|
|
|
list_add_tail(&buf->list, &dev->active_buf_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct flite_buffer *fimc_lite_active_queue_pop(
|
|
|
|
struct fimc_lite *dev)
|
|
|
|
{
|
|
|
|
struct flite_buffer *buf = list_entry(dev->active_buf_q.next,
|
|
|
|
struct flite_buffer, list);
|
|
|
|
list_del(&buf->list);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void fimc_lite_pending_queue_add(struct fimc_lite *dev,
|
|
|
|
struct flite_buffer *buf)
|
|
|
|
{
|
|
|
|
list_add_tail(&buf->list, &dev->pending_buf_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct flite_buffer *fimc_lite_pending_queue_pop(
|
|
|
|
struct fimc_lite *dev)
|
|
|
|
{
|
|
|
|
struct flite_buffer *buf = list_entry(dev->pending_buf_q.next,
|
|
|
|
struct flite_buffer, list);
|
|
|
|
list_del(&buf->list);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* FIMC_LITE_H_ */
|