Commit | Line | Data |
---|---|---|
ad614acb LP |
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. | |
c09af044 MJ |
52 | * @flavor: V4L2 media bus format code for the same pixel layout but |
53 | * shifted to be 8 bits per pixel. =0 if format is not shiftable. | |
ad614acb LP |
54 | * @pixelformat: V4L2 pixel format FCC identifier |
55 | * @bpp: Bits per pixel | |
56 | */ | |
57 | struct isp_format_info { | |
58 | enum v4l2_mbus_pixelcode code; | |
59 | enum v4l2_mbus_pixelcode truncated; | |
60 | enum v4l2_mbus_pixelcode uncompressed; | |
c09af044 | 61 | enum v4l2_mbus_pixelcode flavor; |
ad614acb LP |
62 | u32 pixelformat; |
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 | struct isp_pipeline { | |
90 | struct media_pipeline pipe; | |
91 | spinlock_t lock; /* Pipeline state and queue flags */ | |
92 | unsigned int state; | |
93 | enum isp_pipeline_stream_state stream_state; | |
94 | struct isp_video *input; | |
95 | struct isp_video *output; | |
96 | unsigned long l3_ick; | |
97 | unsigned int max_rate; | |
98 | atomic_t frame_number; | |
99 | bool do_propagation; /* of frame number */ | |
100 | struct v4l2_fract max_timeperframe; | |
101 | }; | |
102 | ||
103 | #define to_isp_pipeline(__e) \ | |
104 | container_of((__e)->pipe, struct isp_pipeline, pipe) | |
105 | ||
106 | static inline int isp_pipeline_ready(struct isp_pipeline *pipe) | |
107 | { | |
108 | return pipe->state == (ISP_PIPELINE_STREAM_INPUT | | |
109 | ISP_PIPELINE_STREAM_OUTPUT | | |
110 | ISP_PIPELINE_QUEUE_INPUT | | |
111 | ISP_PIPELINE_QUEUE_OUTPUT | | |
112 | ISP_PIPELINE_IDLE_INPUT | | |
113 | ISP_PIPELINE_IDLE_OUTPUT); | |
114 | } | |
115 | ||
116 | /* | |
117 | * struct isp_buffer - ISP buffer | |
118 | * @buffer: ISP video buffer | |
119 | * @isp_addr: MMU mapped address (a.k.a. device address) of the buffer. | |
120 | */ | |
121 | struct isp_buffer { | |
122 | struct isp_video_buffer buffer; | |
123 | dma_addr_t isp_addr; | |
124 | }; | |
125 | ||
126 | #define to_isp_buffer(buf) container_of(buf, struct isp_buffer, buffer) | |
127 | ||
128 | enum isp_video_dmaqueue_flags { | |
129 | /* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */ | |
130 | ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0), | |
131 | /* Set when queuing buffer to an empty DMA queue */ | |
132 | ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1), | |
133 | }; | |
134 | ||
135 | #define isp_video_dmaqueue_flags_clr(video) \ | |
136 | ({ (video)->dmaqueue_flags = 0; }) | |
137 | ||
138 | /* | |
139 | * struct isp_video_operations - ISP video operations | |
140 | * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF | |
141 | * if there was no buffer previously queued. | |
142 | */ | |
143 | struct isp_video_operations { | |
144 | int(*queue)(struct isp_video *video, struct isp_buffer *buffer); | |
145 | }; | |
146 | ||
147 | struct isp_video { | |
148 | struct video_device video; | |
149 | enum v4l2_buf_type type; | |
150 | struct media_pad pad; | |
151 | ||
152 | struct mutex mutex; /* format and crop settings */ | |
153 | atomic_t active; | |
154 | ||
155 | struct isp_device *isp; | |
156 | ||
157 | unsigned int capture_mem; | |
158 | unsigned int bpl_alignment; /* alignment value */ | |
159 | unsigned int bpl_zero_padding; /* whether the alignment is optional */ | |
160 | unsigned int bpl_max; /* maximum bytes per line value */ | |
161 | unsigned int bpl_value; /* bytes per line value */ | |
162 | unsigned int bpl_padding; /* padding at end of line */ | |
163 | ||
164 | /* Entity video node streaming */ | |
165 | unsigned int streaming:1; | |
166 | ||
167 | /* Pipeline state */ | |
168 | struct isp_pipeline pipe; | |
169 | struct mutex stream_lock; /* pipeline and stream states */ | |
170 | ||
171 | /* Video buffers queue */ | |
172 | struct isp_video_queue *queue; | |
173 | struct list_head dmaqueue; | |
174 | enum isp_video_dmaqueue_flags dmaqueue_flags; | |
175 | ||
176 | const struct isp_video_operations *ops; | |
177 | }; | |
178 | ||
179 | #define to_isp_video(vdev) container_of(vdev, struct isp_video, video) | |
180 | ||
181 | struct isp_video_fh { | |
182 | struct v4l2_fh vfh; | |
183 | struct isp_video *video; | |
184 | struct isp_video_queue queue; | |
185 | struct v4l2_format format; | |
186 | struct v4l2_fract timeperframe; | |
187 | }; | |
188 | ||
189 | #define to_isp_video_fh(fh) container_of(fh, struct isp_video_fh, vfh) | |
190 | #define isp_video_queue_to_isp_video_fh(q) \ | |
191 | container_of(q, struct isp_video_fh, queue) | |
192 | ||
193 | int omap3isp_video_init(struct isp_video *video, const char *name); | |
194 | int omap3isp_video_register(struct isp_video *video, | |
195 | struct v4l2_device *vdev); | |
196 | void omap3isp_video_unregister(struct isp_video *video); | |
197 | struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video, | |
198 | unsigned int error); | |
199 | void omap3isp_video_resume(struct isp_video *video, int continuous); | |
200 | struct media_pad *omap3isp_video_remote_pad(struct isp_video *video); | |
201 | ||
202 | const struct isp_format_info * | |
203 | omap3isp_video_format_info(enum v4l2_mbus_pixelcode code); | |
204 | ||
205 | #endif /* OMAP3_ISP_VIDEO_H */ |