blob: 5acc909500ec0c52db0537201c88d01b2ca612d7 [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>
33
34#include "ispqueue.h"
35
36#define ISP_VIDEO_DRIVER_NAME "ispvideo"
Mauro Carvalho Chehab64dc3c12011-06-25 11:28:37 -030037#define ISP_VIDEO_DRIVER_VERSION "0.0.2"
Laurent Pinchartad614ac2011-02-12 18:05:06 -030038
39struct isp_device;
40struct isp_video;
41struct v4l2_mbus_framefmt;
42struct v4l2_pix_format;
43
44/*
45 * struct isp_format_info - ISP media bus format information
46 * @code: V4L2 media bus format code
47 * @truncated: V4L2 media bus format code for the same format truncated to 10
48 * bits. Identical to @code if the format is 10 bits wide or less.
49 * @uncompressed: V4L2 media bus format code for the corresponding uncompressed
50 * format. Identical to @code if the format is not DPCM compressed.
Michael Jonesc09af042011-03-29 05:19:09 -030051 * @flavor: V4L2 media bus format code for the same pixel layout but
52 * shifted to be 8 bits per pixel. =0 if format is not shiftable.
Laurent Pinchartad614ac2011-02-12 18:05:06 -030053 * @pixelformat: V4L2 pixel format FCC identifier
54 * @bpp: Bits per pixel
55 */
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;
62 unsigned int bpp;
63};
64
65enum isp_pipeline_stream_state {
66 ISP_PIPELINE_STREAM_STOPPED = 0,
67 ISP_PIPELINE_STREAM_CONTINUOUS = 1,
68 ISP_PIPELINE_STREAM_SINGLESHOT = 2,
69};
70
71enum isp_pipeline_state {
72 /* The stream has been started on the input video node. */
73 ISP_PIPELINE_STREAM_INPUT = 1,
74 /* The stream has been started on the output video node. */
75 ISP_PIPELINE_STREAM_OUTPUT = 2,
76 /* At least one buffer is queued on the input video node. */
77 ISP_PIPELINE_QUEUE_INPUT = 4,
78 /* At least one buffer is queued on the output video node. */
79 ISP_PIPELINE_QUEUE_OUTPUT = 8,
80 /* The input entity is idle, ready to be started. */
81 ISP_PIPELINE_IDLE_INPUT = 16,
82 /* The output entity is idle, ready to be started. */
83 ISP_PIPELINE_IDLE_OUTPUT = 32,
84 /* The pipeline is currently streaming. */
85 ISP_PIPELINE_STREAM = 64,
86};
87
Laurent Pinchart875e2e32011-12-07 08:34:50 -030088/*
89 * struct isp_pipeline - An ISP hardware pipeline
90 * @error: A hardware error occurred during capture
Laurent Pinchart1567bb72011-11-18 11:28:24 -030091 * @entities: Bitmask of entities in the pipeline (indexed by entity ID)
Laurent Pinchart875e2e32011-12-07 08:34:50 -030092 */
Laurent Pinchartad614ac2011-02-12 18:05:06 -030093struct isp_pipeline {
94 struct media_pipeline pipe;
95 spinlock_t lock; /* Pipeline state and queue flags */
96 unsigned int state;
97 enum isp_pipeline_stream_state stream_state;
98 struct isp_video *input;
99 struct isp_video *output;
Laurent Pinchart1567bb72011-11-18 11:28:24 -0300100 u32 entities;
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300101 unsigned long l3_ick;
102 unsigned int max_rate;
103 atomic_t frame_number;
104 bool do_propagation; /* of frame number */
Laurent Pinchart875e2e32011-12-07 08:34:50 -0300105 bool error;
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300106 struct v4l2_fract max_timeperframe;
Sakari Ailus80b37e72012-01-16 18:58:01 -0300107 struct v4l2_subdev *external;
108 unsigned int external_rate;
109 unsigned int external_bpp;
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300110};
111
112#define to_isp_pipeline(__e) \
113 container_of((__e)->pipe, struct isp_pipeline, pipe)
114
115static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
116{
117 return pipe->state == (ISP_PIPELINE_STREAM_INPUT |
118 ISP_PIPELINE_STREAM_OUTPUT |
119 ISP_PIPELINE_QUEUE_INPUT |
120 ISP_PIPELINE_QUEUE_OUTPUT |
121 ISP_PIPELINE_IDLE_INPUT |
122 ISP_PIPELINE_IDLE_OUTPUT);
123}
124
125/*
126 * struct isp_buffer - ISP buffer
127 * @buffer: ISP video buffer
128 * @isp_addr: MMU mapped address (a.k.a. device address) of the buffer.
129 */
130struct isp_buffer {
131 struct isp_video_buffer buffer;
132 dma_addr_t isp_addr;
133};
134
135#define to_isp_buffer(buf) container_of(buf, struct isp_buffer, buffer)
136
137enum isp_video_dmaqueue_flags {
138 /* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */
139 ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
140 /* Set when queuing buffer to an empty DMA queue */
141 ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
142};
143
144#define isp_video_dmaqueue_flags_clr(video) \
145 ({ (video)->dmaqueue_flags = 0; })
146
147/*
148 * struct isp_video_operations - ISP video operations
149 * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
150 * if there was no buffer previously queued.
151 */
152struct isp_video_operations {
153 int(*queue)(struct isp_video *video, struct isp_buffer *buffer);
154};
155
156struct isp_video {
157 struct video_device video;
158 enum v4l2_buf_type type;
159 struct media_pad pad;
160
161 struct mutex mutex; /* format and crop settings */
162 atomic_t active;
163
164 struct isp_device *isp;
165
166 unsigned int capture_mem;
167 unsigned int bpl_alignment; /* alignment value */
168 unsigned int bpl_zero_padding; /* whether the alignment is optional */
169 unsigned int bpl_max; /* maximum bytes per line value */
170 unsigned int bpl_value; /* bytes per line value */
171 unsigned int bpl_padding; /* padding at end of line */
172
173 /* Entity video node streaming */
174 unsigned int streaming:1;
175
176 /* Pipeline state */
177 struct isp_pipeline pipe;
178 struct mutex stream_lock; /* pipeline and stream states */
179
180 /* Video buffers queue */
181 struct isp_video_queue *queue;
182 struct list_head dmaqueue;
183 enum isp_video_dmaqueue_flags dmaqueue_flags;
184
185 const struct isp_video_operations *ops;
186};
187
188#define to_isp_video(vdev) container_of(vdev, struct isp_video, video)
189
190struct isp_video_fh {
191 struct v4l2_fh vfh;
192 struct isp_video *video;
193 struct isp_video_queue queue;
194 struct v4l2_format format;
195 struct v4l2_fract timeperframe;
196};
197
198#define to_isp_video_fh(fh) container_of(fh, struct isp_video_fh, vfh)
199#define isp_video_queue_to_isp_video_fh(q) \
200 container_of(q, struct isp_video_fh, queue)
201
202int omap3isp_video_init(struct isp_video *video, const char *name);
Laurent Pinchart63b4ca22011-09-22 16:54:34 -0300203void omap3isp_video_cleanup(struct isp_video *video);
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300204int omap3isp_video_register(struct isp_video *video,
205 struct v4l2_device *vdev);
206void omap3isp_video_unregister(struct isp_video *video);
Laurent Pinchart875e2e32011-12-07 08:34:50 -0300207struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video);
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300208void omap3isp_video_resume(struct isp_video *video, int continuous);
209struct media_pad *omap3isp_video_remote_pad(struct isp_video *video);
210
211const struct isp_format_info *
212omap3isp_video_format_info(enum v4l2_mbus_pixelcode code);
213
214#endif /* OMAP3_ISP_VIDEO_H */