blob: 7d2e82122ecda431d417ae10ba8193b9fb9154ec [file] [log] [blame]
Laurent Pinchartad614ac2011-02-12 18:05:06 -03001/*
2 * ispvideo.h
3 *
4 * TI OMAP3 ISP - Generic video node
5 *
6 * Copyright (C) 2009-2010 Nokia Corporation
7 *
8 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 * Sakari Ailus <sakari.ailus@iki.fi>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 * 02110-1301 USA
24 */
25
26#ifndef OMAP3_ISP_VIDEO_H
27#define OMAP3_ISP_VIDEO_H
28
29#include <linux/v4l2-mediabus.h>
Laurent Pinchartad614ac2011-02-12 18:05:06 -030030#include <media/media-entity.h>
31#include <media/v4l2-dev.h>
32#include <media/v4l2-fh.h>
Laurent Pinchartfbac1402014-03-09 20:36:15 -030033#include <media/videobuf2-core.h>
Laurent Pinchartad614ac2011-02-12 18:05:06 -030034
35#define ISP_VIDEO_DRIVER_NAME "ispvideo"
Mauro Carvalho Chehab64dc3c12011-06-25 11:28:37 -030036#define ISP_VIDEO_DRIVER_VERSION "0.0.2"
Laurent Pinchartad614ac2011-02-12 18:05:06 -030037
38struct isp_device;
39struct isp_video;
40struct v4l2_mbus_framefmt;
41struct v4l2_pix_format;
42
43/*
44 * struct isp_format_info - ISP media bus format information
45 * @code: V4L2 media bus format code
46 * @truncated: V4L2 media bus format code for the same format truncated to 10
47 * bits. Identical to @code if the format is 10 bits wide or less.
48 * @uncompressed: V4L2 media bus format code for the corresponding uncompressed
49 * format. Identical to @code if the format is not DPCM compressed.
Michael Jonesc09af042011-03-29 05:19:09 -030050 * @flavor: V4L2 media bus format code for the same pixel layout but
51 * shifted to be 8 bits per pixel. =0 if format is not shiftable.
Laurent Pinchartad614ac2011-02-12 18:05:06 -030052 * @pixelformat: V4L2 pixel format FCC identifier
Laurent Pinchart1697e492011-08-31 11:57:12 -030053 * @width: Bits per pixel (when transferred over a bus)
54 * @bpp: Bytes per pixel (when stored in memory)
Laurent Pinchartad614ac2011-02-12 18:05:06 -030055 */
56struct isp_format_info {
57 enum v4l2_mbus_pixelcode code;
58 enum v4l2_mbus_pixelcode truncated;
59 enum v4l2_mbus_pixelcode uncompressed;
Michael Jonesc09af042011-03-29 05:19:09 -030060 enum v4l2_mbus_pixelcode flavor;
Laurent Pinchartad614ac2011-02-12 18:05:06 -030061 u32 pixelformat;
Laurent Pinchart1697e492011-08-31 11:57:12 -030062 unsigned int width;
Laurent Pinchartad614ac2011-02-12 18:05:06 -030063 unsigned int bpp;
64};
65
66enum isp_pipeline_stream_state {
67 ISP_PIPELINE_STREAM_STOPPED = 0,
68 ISP_PIPELINE_STREAM_CONTINUOUS = 1,
69 ISP_PIPELINE_STREAM_SINGLESHOT = 2,
70};
71
72enum isp_pipeline_state {
73 /* The stream has been started on the input video node. */
74 ISP_PIPELINE_STREAM_INPUT = 1,
75 /* The stream has been started on the output video node. */
76 ISP_PIPELINE_STREAM_OUTPUT = 2,
77 /* At least one buffer is queued on the input video node. */
78 ISP_PIPELINE_QUEUE_INPUT = 4,
79 /* At least one buffer is queued on the output video node. */
80 ISP_PIPELINE_QUEUE_OUTPUT = 8,
81 /* The input entity is idle, ready to be started. */
82 ISP_PIPELINE_IDLE_INPUT = 16,
83 /* The output entity is idle, ready to be started. */
84 ISP_PIPELINE_IDLE_OUTPUT = 32,
85 /* The pipeline is currently streaming. */
86 ISP_PIPELINE_STREAM = 64,
87};
88
Laurent Pinchart875e2e32011-12-07 08:34:50 -030089/*
90 * struct isp_pipeline - An ISP hardware pipeline
91 * @error: A hardware error occurred during capture
Laurent Pinchart1567bb72011-11-18 11:28:24 -030092 * @entities: Bitmask of entities in the pipeline (indexed by entity ID)
Laurent Pinchart875e2e32011-12-07 08:34:50 -030093 */
Laurent Pinchartad614ac2011-02-12 18:05:06 -030094struct isp_pipeline {
95 struct media_pipeline pipe;
96 spinlock_t lock; /* Pipeline state and queue flags */
97 unsigned int state;
98 enum isp_pipeline_stream_state stream_state;
99 struct isp_video *input;
100 struct isp_video *output;
Laurent Pinchart1567bb72011-11-18 11:28:24 -0300101 u32 entities;
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300102 unsigned long l3_ick;
103 unsigned int max_rate;
104 atomic_t frame_number;
105 bool do_propagation; /* of frame number */
Laurent Pinchart875e2e32011-12-07 08:34:50 -0300106 bool error;
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300107 struct v4l2_fract max_timeperframe;
Sakari Ailus80b37e72012-01-16 18:58:01 -0300108 struct v4l2_subdev *external;
109 unsigned int external_rate;
Laurent Pinchart1697e492011-08-31 11:57:12 -0300110 unsigned int external_width;
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300111};
112
113#define to_isp_pipeline(__e) \
114 container_of((__e)->pipe, struct isp_pipeline, pipe)
115
116static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
117{
118 return pipe->state == (ISP_PIPELINE_STREAM_INPUT |
119 ISP_PIPELINE_STREAM_OUTPUT |
120 ISP_PIPELINE_QUEUE_INPUT |
121 ISP_PIPELINE_QUEUE_OUTPUT |
122 ISP_PIPELINE_IDLE_INPUT |
123 ISP_PIPELINE_IDLE_OUTPUT);
124}
125
Laurent Pinchartfbac1402014-03-09 20:36:15 -0300126/**
127 * struct isp_buffer - ISP video buffer
128 * @vb: videobuf2 buffer
Laurent Pincharteb2c00d2014-03-09 20:57:53 -0300129 * @irqlist: List head for insertion into IRQ queue
Laurent Pinchart21d85822014-03-09 20:17:12 -0300130 * @dma: DMA address
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300131 */
132struct isp_buffer {
Laurent Pinchartfbac1402014-03-09 20:36:15 -0300133 struct vb2_buffer vb;
Laurent Pincharteb2c00d2014-03-09 20:57:53 -0300134 struct list_head irqlist;
Laurent Pinchart21d85822014-03-09 20:17:12 -0300135 dma_addr_t dma;
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300136};
137
Laurent Pinchartfbac1402014-03-09 20:36:15 -0300138#define to_isp_buffer(buf) container_of(buf, struct isp_buffer, vb)
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300139
140enum isp_video_dmaqueue_flags {
141 /* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */
142 ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
143 /* Set when queuing buffer to an empty DMA queue */
144 ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
145};
146
147#define isp_video_dmaqueue_flags_clr(video) \
148 ({ (video)->dmaqueue_flags = 0; })
149
150/*
151 * struct isp_video_operations - ISP video operations
152 * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
153 * if there was no buffer previously queued.
154 */
155struct isp_video_operations {
156 int(*queue)(struct isp_video *video, struct isp_buffer *buffer);
157};
158
159struct isp_video {
160 struct video_device video;
161 enum v4l2_buf_type type;
162 struct media_pad pad;
163
164 struct mutex mutex; /* format and crop settings */
165 atomic_t active;
166
167 struct isp_device *isp;
168
169 unsigned int capture_mem;
170 unsigned int bpl_alignment; /* alignment value */
171 unsigned int bpl_zero_padding; /* whether the alignment is optional */
172 unsigned int bpl_max; /* maximum bytes per line value */
173 unsigned int bpl_value; /* bytes per line value */
174 unsigned int bpl_padding; /* padding at end of line */
175
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300176 /* Pipeline state */
177 struct isp_pipeline pipe;
178 struct mutex stream_lock; /* pipeline and stream states */
Laurent Pinchart661112c2013-12-09 11:36:51 -0300179 bool error;
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300180
181 /* Video buffers queue */
Laurent Pinchartfbac1402014-03-09 20:36:15 -0300182 void *alloc_ctx;
183 struct vb2_queue *queue;
Laurent Pinchart988d54c2014-03-09 20:57:53 -0300184 struct mutex queue_lock; /* protects the queue */
Laurent Pincharte8feb872014-03-09 20:57:53 -0300185 spinlock_t irqlock; /* protects dmaqueue */
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300186 struct list_head dmaqueue;
187 enum isp_video_dmaqueue_flags dmaqueue_flags;
188
189 const struct isp_video_operations *ops;
190};
191
192#define to_isp_video(vdev) container_of(vdev, struct isp_video, video)
193
194struct isp_video_fh {
195 struct v4l2_fh vfh;
196 struct isp_video *video;
Laurent Pinchartfbac1402014-03-09 20:36:15 -0300197 struct vb2_queue queue;
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300198 struct v4l2_format format;
199 struct v4l2_fract timeperframe;
200};
201
202#define to_isp_video_fh(fh) container_of(fh, struct isp_video_fh, vfh)
203#define isp_video_queue_to_isp_video_fh(q) \
204 container_of(q, struct isp_video_fh, queue)
205
206int omap3isp_video_init(struct isp_video *video, const char *name);
Laurent Pinchart63b4ca22011-09-22 16:54:34 -0300207void omap3isp_video_cleanup(struct isp_video *video);
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300208int omap3isp_video_register(struct isp_video *video,
209 struct v4l2_device *vdev);
210void omap3isp_video_unregister(struct isp_video *video);
Laurent Pinchart875e2e32011-12-07 08:34:50 -0300211struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video);
Laurent Pinchart661112c2013-12-09 11:36:51 -0300212void omap3isp_video_cancel_stream(struct isp_video *video);
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300213void omap3isp_video_resume(struct isp_video *video, int continuous);
214struct media_pad *omap3isp_video_remote_pad(struct isp_video *video);
215
216const struct isp_format_info *
217omap3isp_video_format_info(enum v4l2_mbus_pixelcode code);
218
219#endif /* OMAP3_ISP_VIDEO_H */