[media] omap3isp: Rename isp_buffer isp_addr field to dma
[sfrench/cifs-2.6.git] / drivers / media / platform / 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 <media/media-entity.h>
31 #include <media/v4l2-dev.h>
32 #include <media/v4l2-fh.h>
33 #include <media/videobuf2-core.h>
34
35 #define ISP_VIDEO_DRIVER_NAME           "ispvideo"
36 #define ISP_VIDEO_DRIVER_VERSION        "0.0.2"
37
38 struct isp_device;
39 struct isp_video;
40 struct v4l2_mbus_framefmt;
41 struct 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.
50  * @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.
52  * @pixelformat: V4L2 pixel format FCC identifier
53  * @width: Bits per pixel (when transferred over a bus)
54  * @bpp: Bytes per pixel (when stored in memory)
55  */
56 struct isp_format_info {
57         enum v4l2_mbus_pixelcode code;
58         enum v4l2_mbus_pixelcode truncated;
59         enum v4l2_mbus_pixelcode uncompressed;
60         enum v4l2_mbus_pixelcode flavor;
61         u32 pixelformat;
62         unsigned int width;
63         unsigned int bpp;
64 };
65
66 enum isp_pipeline_stream_state {
67         ISP_PIPELINE_STREAM_STOPPED = 0,
68         ISP_PIPELINE_STREAM_CONTINUOUS = 1,
69         ISP_PIPELINE_STREAM_SINGLESHOT = 2,
70 };
71
72 enum 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
89 /*
90  * struct isp_pipeline - An ISP hardware pipeline
91  * @error: A hardware error occurred during capture
92  * @entities: Bitmask of entities in the pipeline (indexed by entity ID)
93  */
94 struct 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;
101         u32 entities;
102         unsigned long l3_ick;
103         unsigned int max_rate;
104         atomic_t frame_number;
105         bool do_propagation; /* of frame number */
106         bool error;
107         struct v4l2_fract max_timeperframe;
108         struct v4l2_subdev *external;
109         unsigned int external_rate;
110         unsigned int external_width;
111 };
112
113 #define to_isp_pipeline(__e) \
114         container_of((__e)->pipe, struct isp_pipeline, pipe)
115
116 static 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
126 /**
127  * struct isp_buffer - ISP video buffer
128  * @vb: videobuf2 buffer
129  * @irqlist: List head for insertion into IRQ queue
130  * @dma: DMA address
131  */
132 struct isp_buffer {
133         struct vb2_buffer vb;
134         struct list_head irqlist;
135         dma_addr_t dma;
136 };
137
138 #define to_isp_buffer(buf)      container_of(buf, struct isp_buffer, vb)
139
140 enum 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  */
155 struct isp_video_operations {
156         int(*queue)(struct isp_video *video, struct isp_buffer *buffer);
157 };
158
159 struct 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
176         /* Pipeline state */
177         struct isp_pipeline pipe;
178         struct mutex stream_lock;       /* pipeline and stream states */
179         bool error;
180
181         /* Video buffers queue */
182         void *alloc_ctx;
183         struct vb2_queue *queue;
184         struct mutex queue_lock;        /* protects the queue */
185         spinlock_t irqlock;             /* protects dmaqueue */
186         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
194 struct isp_video_fh {
195         struct v4l2_fh vfh;
196         struct isp_video *video;
197         struct vb2_queue queue;
198         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
206 int omap3isp_video_init(struct isp_video *video, const char *name);
207 void omap3isp_video_cleanup(struct isp_video *video);
208 int omap3isp_video_register(struct isp_video *video,
209                             struct v4l2_device *vdev);
210 void omap3isp_video_unregister(struct isp_video *video);
211 struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video);
212 void omap3isp_video_cancel_stream(struct isp_video *video);
213 void omap3isp_video_resume(struct isp_video *video, int continuous);
214 struct media_pad *omap3isp_video_remote_pad(struct isp_video *video);
215
216 const struct isp_format_info *
217 omap3isp_video_format_info(enum v4l2_mbus_pixelcode code);
218
219 #endif /* OMAP3_ISP_VIDEO_H */