Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
[pandora-kernel.git] / drivers / media / video / omap3isp / ispvideo.h
1 /*
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>
30 #include <linux/version.h>
31 #include <media/media-entity.h>
32 #include <media/v4l2-dev.h>
33 #include <media/v4l2-fh.h>
34
35 #include "ispqueue.h"
36
37 #define ISP_VIDEO_DRIVER_NAME           "ispvideo"
38 #define ISP_VIDEO_DRIVER_VERSION        KERNEL_VERSION(0, 0, 1)
39
40 struct isp_device;
41 struct isp_video;
42 struct v4l2_mbus_framefmt;
43 struct v4l2_pix_format;
44
45 /*
46  * struct isp_format_info - ISP media bus format information
47  * @code: V4L2 media bus format code
48  * @truncated: V4L2 media bus format code for the same format truncated to 10
49  *      bits. Identical to @code if the format is 10 bits wide or less.
50  * @uncompressed: V4L2 media bus format code for the corresponding uncompressed
51  *      format. Identical to @code if the format is not DPCM compressed.
52  * @pixelformat: V4L2 pixel format FCC identifier
53  * @bpp: Bits per pixel
54  */
55 struct isp_format_info {
56         enum v4l2_mbus_pixelcode code;
57         enum v4l2_mbus_pixelcode truncated;
58         enum v4l2_mbus_pixelcode uncompressed;
59         u32 pixelformat;
60         unsigned int bpp;
61 };
62
63 enum isp_pipeline_stream_state {
64         ISP_PIPELINE_STREAM_STOPPED = 0,
65         ISP_PIPELINE_STREAM_CONTINUOUS = 1,
66         ISP_PIPELINE_STREAM_SINGLESHOT = 2,
67 };
68
69 enum isp_pipeline_state {
70         /* The stream has been started on the input video node. */
71         ISP_PIPELINE_STREAM_INPUT = 1,
72         /* The stream has been started on the output video node. */
73         ISP_PIPELINE_STREAM_OUTPUT = 2,
74         /* At least one buffer is queued on the input video node. */
75         ISP_PIPELINE_QUEUE_INPUT = 4,
76         /* At least one buffer is queued on the output video node. */
77         ISP_PIPELINE_QUEUE_OUTPUT = 8,
78         /* The input entity is idle, ready to be started. */
79         ISP_PIPELINE_IDLE_INPUT = 16,
80         /* The output entity is idle, ready to be started. */
81         ISP_PIPELINE_IDLE_OUTPUT = 32,
82         /* The pipeline is currently streaming. */
83         ISP_PIPELINE_STREAM = 64,
84 };
85
86 struct isp_pipeline {
87         struct media_pipeline pipe;
88         spinlock_t lock;                /* Pipeline state and queue flags */
89         unsigned int state;
90         enum isp_pipeline_stream_state stream_state;
91         struct isp_video *input;
92         struct isp_video *output;
93         unsigned long l3_ick;
94         unsigned int max_rate;
95         atomic_t frame_number;
96         bool do_propagation; /* of frame number */
97         struct v4l2_fract max_timeperframe;
98 };
99
100 #define to_isp_pipeline(__e) \
101         container_of((__e)->pipe, struct isp_pipeline, pipe)
102
103 static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
104 {
105         return pipe->state == (ISP_PIPELINE_STREAM_INPUT |
106                                ISP_PIPELINE_STREAM_OUTPUT |
107                                ISP_PIPELINE_QUEUE_INPUT |
108                                ISP_PIPELINE_QUEUE_OUTPUT |
109                                ISP_PIPELINE_IDLE_INPUT |
110                                ISP_PIPELINE_IDLE_OUTPUT);
111 }
112
113 /*
114  * struct isp_buffer - ISP buffer
115  * @buffer: ISP video buffer
116  * @isp_addr: MMU mapped address (a.k.a. device address) of the buffer.
117  */
118 struct isp_buffer {
119         struct isp_video_buffer buffer;
120         dma_addr_t isp_addr;
121 };
122
123 #define to_isp_buffer(buf)      container_of(buf, struct isp_buffer, buffer)
124
125 enum isp_video_dmaqueue_flags {
126         /* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */
127         ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
128         /* Set when queuing buffer to an empty DMA queue */
129         ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
130 };
131
132 #define isp_video_dmaqueue_flags_clr(video)     \
133                         ({ (video)->dmaqueue_flags = 0; })
134
135 /*
136  * struct isp_video_operations - ISP video operations
137  * @queue:      Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
138  *              if there was no buffer previously queued.
139  */
140 struct isp_video_operations {
141         int(*queue)(struct isp_video *video, struct isp_buffer *buffer);
142 };
143
144 struct isp_video {
145         struct video_device video;
146         enum v4l2_buf_type type;
147         struct media_pad pad;
148
149         struct mutex mutex;             /* format and crop settings */
150         atomic_t active;
151
152         struct isp_device *isp;
153
154         unsigned int capture_mem;
155         unsigned int bpl_alignment;     /* alignment value */
156         unsigned int bpl_zero_padding;  /* whether the alignment is optional */
157         unsigned int bpl_max;           /* maximum bytes per line value */
158         unsigned int bpl_value;         /* bytes per line value */
159         unsigned int bpl_padding;       /* padding at end of line */
160
161         /* Entity video node streaming */
162         unsigned int streaming:1;
163
164         /* Pipeline state */
165         struct isp_pipeline pipe;
166         struct mutex stream_lock;       /* pipeline and stream states */
167
168         /* Video buffers queue */
169         struct isp_video_queue *queue;
170         struct list_head dmaqueue;
171         enum isp_video_dmaqueue_flags dmaqueue_flags;
172
173         const struct isp_video_operations *ops;
174 };
175
176 #define to_isp_video(vdev)      container_of(vdev, struct isp_video, video)
177
178 struct isp_video_fh {
179         struct v4l2_fh vfh;
180         struct isp_video *video;
181         struct isp_video_queue queue;
182         struct v4l2_format format;
183         struct v4l2_fract timeperframe;
184 };
185
186 #define to_isp_video_fh(fh)     container_of(fh, struct isp_video_fh, vfh)
187 #define isp_video_queue_to_isp_video_fh(q) \
188                                 container_of(q, struct isp_video_fh, queue)
189
190 int omap3isp_video_init(struct isp_video *video, const char *name);
191 int omap3isp_video_register(struct isp_video *video,
192                             struct v4l2_device *vdev);
193 void omap3isp_video_unregister(struct isp_video *video);
194 struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video,
195                                               unsigned int error);
196 void omap3isp_video_resume(struct isp_video *video, int continuous);
197 struct media_pad *omap3isp_video_remote_pad(struct isp_video *video);
198
199 const struct isp_format_info *
200 omap3isp_video_format_info(enum v4l2_mbus_pixelcode code);
201
202 #endif /* OMAP3_ISP_VIDEO_H */