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