Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 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> |
Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 30 | #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 Chehab | 64dc3c1 | 2011-06-25 11:28:37 -0300 | [diff] [blame] | 37 | #define ISP_VIDEO_DRIVER_VERSION "0.0.2" |
Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 38 | |
| 39 | struct isp_device; |
| 40 | struct isp_video; |
| 41 | struct v4l2_mbus_framefmt; |
| 42 | struct 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 Jones | c09af04 | 2011-03-29 05:19:09 -0300 | [diff] [blame] | 51 | * @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 Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 53 | * @pixelformat: V4L2 pixel format FCC identifier |
Laurent Pinchart | 1697e49 | 2011-08-31 11:57:12 -0300 | [diff] [blame] | 54 | * @width: Bits per pixel (when transferred over a bus) |
| 55 | * @bpp: Bytes per pixel (when stored in memory) |
Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 56 | */ |
| 57 | struct isp_format_info { |
| 58 | enum v4l2_mbus_pixelcode code; |
| 59 | enum v4l2_mbus_pixelcode truncated; |
| 60 | enum v4l2_mbus_pixelcode uncompressed; |
Michael Jones | c09af04 | 2011-03-29 05:19:09 -0300 | [diff] [blame] | 61 | enum v4l2_mbus_pixelcode flavor; |
Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 62 | u32 pixelformat; |
Laurent Pinchart | 1697e49 | 2011-08-31 11:57:12 -0300 | [diff] [blame] | 63 | unsigned int width; |
Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 64 | unsigned int bpp; |
| 65 | }; |
| 66 | |
| 67 | enum isp_pipeline_stream_state { |
| 68 | ISP_PIPELINE_STREAM_STOPPED = 0, |
| 69 | ISP_PIPELINE_STREAM_CONTINUOUS = 1, |
| 70 | ISP_PIPELINE_STREAM_SINGLESHOT = 2, |
| 71 | }; |
| 72 | |
| 73 | enum isp_pipeline_state { |
| 74 | /* The stream has been started on the input video node. */ |
| 75 | ISP_PIPELINE_STREAM_INPUT = 1, |
| 76 | /* The stream has been started on the output video node. */ |
| 77 | ISP_PIPELINE_STREAM_OUTPUT = 2, |
| 78 | /* At least one buffer is queued on the input video node. */ |
| 79 | ISP_PIPELINE_QUEUE_INPUT = 4, |
| 80 | /* At least one buffer is queued on the output video node. */ |
| 81 | ISP_PIPELINE_QUEUE_OUTPUT = 8, |
| 82 | /* The input entity is idle, ready to be started. */ |
| 83 | ISP_PIPELINE_IDLE_INPUT = 16, |
| 84 | /* The output entity is idle, ready to be started. */ |
| 85 | ISP_PIPELINE_IDLE_OUTPUT = 32, |
| 86 | /* The pipeline is currently streaming. */ |
| 87 | ISP_PIPELINE_STREAM = 64, |
| 88 | }; |
| 89 | |
Laurent Pinchart | 875e2e3 | 2011-12-07 08:34:50 -0300 | [diff] [blame] | 90 | /* |
| 91 | * struct isp_pipeline - An ISP hardware pipeline |
| 92 | * @error: A hardware error occurred during capture |
Laurent Pinchart | 1567bb7 | 2011-11-18 11:28:24 -0300 | [diff] [blame] | 93 | * @entities: Bitmask of entities in the pipeline (indexed by entity ID) |
Laurent Pinchart | 875e2e3 | 2011-12-07 08:34:50 -0300 | [diff] [blame] | 94 | */ |
Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 95 | struct isp_pipeline { |
| 96 | struct media_pipeline pipe; |
| 97 | spinlock_t lock; /* Pipeline state and queue flags */ |
| 98 | unsigned int state; |
| 99 | enum isp_pipeline_stream_state stream_state; |
| 100 | struct isp_video *input; |
| 101 | struct isp_video *output; |
Laurent Pinchart | 1567bb7 | 2011-11-18 11:28:24 -0300 | [diff] [blame] | 102 | u32 entities; |
Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 103 | unsigned long l3_ick; |
| 104 | unsigned int max_rate; |
| 105 | atomic_t frame_number; |
| 106 | bool do_propagation; /* of frame number */ |
Laurent Pinchart | 875e2e3 | 2011-12-07 08:34:50 -0300 | [diff] [blame] | 107 | bool error; |
Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 108 | struct v4l2_fract max_timeperframe; |
Sakari Ailus | 80b37e7 | 2012-01-16 18:58:01 -0300 | [diff] [blame] | 109 | struct v4l2_subdev *external; |
| 110 | unsigned int external_rate; |
Laurent Pinchart | 1697e49 | 2011-08-31 11:57:12 -0300 | [diff] [blame] | 111 | unsigned int external_width; |
Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | #define to_isp_pipeline(__e) \ |
| 115 | container_of((__e)->pipe, struct isp_pipeline, pipe) |
| 116 | |
| 117 | static inline int isp_pipeline_ready(struct isp_pipeline *pipe) |
| 118 | { |
| 119 | return pipe->state == (ISP_PIPELINE_STREAM_INPUT | |
| 120 | ISP_PIPELINE_STREAM_OUTPUT | |
| 121 | ISP_PIPELINE_QUEUE_INPUT | |
| 122 | ISP_PIPELINE_QUEUE_OUTPUT | |
| 123 | ISP_PIPELINE_IDLE_INPUT | |
| 124 | ISP_PIPELINE_IDLE_OUTPUT); |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * struct isp_buffer - ISP buffer |
| 129 | * @buffer: ISP video buffer |
| 130 | * @isp_addr: MMU mapped address (a.k.a. device address) of the buffer. |
| 131 | */ |
| 132 | struct isp_buffer { |
| 133 | struct isp_video_buffer buffer; |
| 134 | dma_addr_t isp_addr; |
| 135 | }; |
| 136 | |
| 137 | #define to_isp_buffer(buf) container_of(buf, struct isp_buffer, buffer) |
| 138 | |
| 139 | enum isp_video_dmaqueue_flags { |
| 140 | /* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */ |
| 141 | ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0), |
| 142 | /* Set when queuing buffer to an empty DMA queue */ |
| 143 | ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1), |
| 144 | }; |
| 145 | |
| 146 | #define isp_video_dmaqueue_flags_clr(video) \ |
| 147 | ({ (video)->dmaqueue_flags = 0; }) |
| 148 | |
| 149 | /* |
| 150 | * struct isp_video_operations - ISP video operations |
| 151 | * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF |
| 152 | * if there was no buffer previously queued. |
| 153 | */ |
| 154 | struct isp_video_operations { |
| 155 | int(*queue)(struct isp_video *video, struct isp_buffer *buffer); |
| 156 | }; |
| 157 | |
| 158 | struct isp_video { |
| 159 | struct video_device video; |
| 160 | enum v4l2_buf_type type; |
| 161 | struct media_pad pad; |
| 162 | |
| 163 | struct mutex mutex; /* format and crop settings */ |
| 164 | atomic_t active; |
| 165 | |
| 166 | struct isp_device *isp; |
| 167 | |
| 168 | unsigned int capture_mem; |
| 169 | unsigned int bpl_alignment; /* alignment value */ |
| 170 | unsigned int bpl_zero_padding; /* whether the alignment is optional */ |
| 171 | unsigned int bpl_max; /* maximum bytes per line value */ |
| 172 | unsigned int bpl_value; /* bytes per line value */ |
| 173 | unsigned int bpl_padding; /* padding at end of line */ |
| 174 | |
| 175 | /* Entity video node streaming */ |
| 176 | unsigned int streaming:1; |
| 177 | |
| 178 | /* Pipeline state */ |
| 179 | struct isp_pipeline pipe; |
| 180 | struct mutex stream_lock; /* pipeline and stream states */ |
Laurent Pinchart | 661112c | 2013-12-09 11:36:51 -0300 | [diff] [blame] | 181 | bool error; |
Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 182 | |
| 183 | /* Video buffers queue */ |
| 184 | struct isp_video_queue *queue; |
Laurent Pinchart | 988d54c | 2014-03-09 20:57:53 -0300 | [diff] [blame] | 185 | struct mutex queue_lock; /* protects the queue */ |
Laurent Pinchart | e8feb87 | 2014-03-09 20:57:53 -0300 | [diff] [blame^] | 186 | spinlock_t irqlock; /* protects dmaqueue */ |
Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 187 | struct list_head dmaqueue; |
| 188 | enum isp_video_dmaqueue_flags dmaqueue_flags; |
| 189 | |
| 190 | const struct isp_video_operations *ops; |
| 191 | }; |
| 192 | |
| 193 | #define to_isp_video(vdev) container_of(vdev, struct isp_video, video) |
| 194 | |
| 195 | struct isp_video_fh { |
| 196 | struct v4l2_fh vfh; |
| 197 | struct isp_video *video; |
| 198 | struct isp_video_queue queue; |
| 199 | struct v4l2_format format; |
| 200 | struct v4l2_fract timeperframe; |
| 201 | }; |
| 202 | |
| 203 | #define to_isp_video_fh(fh) container_of(fh, struct isp_video_fh, vfh) |
| 204 | #define isp_video_queue_to_isp_video_fh(q) \ |
| 205 | container_of(q, struct isp_video_fh, queue) |
| 206 | |
| 207 | int omap3isp_video_init(struct isp_video *video, const char *name); |
Laurent Pinchart | 63b4ca2 | 2011-09-22 16:54:34 -0300 | [diff] [blame] | 208 | void omap3isp_video_cleanup(struct isp_video *video); |
Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 209 | int omap3isp_video_register(struct isp_video *video, |
| 210 | struct v4l2_device *vdev); |
| 211 | void omap3isp_video_unregister(struct isp_video *video); |
Laurent Pinchart | 875e2e3 | 2011-12-07 08:34:50 -0300 | [diff] [blame] | 212 | struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video); |
Laurent Pinchart | 661112c | 2013-12-09 11:36:51 -0300 | [diff] [blame] | 213 | void omap3isp_video_cancel_stream(struct isp_video *video); |
Laurent Pinchart | ad614ac | 2011-02-12 18:05:06 -0300 | [diff] [blame] | 214 | void omap3isp_video_resume(struct isp_video *video, int continuous); |
| 215 | struct media_pad *omap3isp_video_remote_pad(struct isp_video *video); |
| 216 | |
| 217 | const struct isp_format_info * |
| 218 | omap3isp_video_format_info(enum v4l2_mbus_pixelcode code); |
| 219 | |
| 220 | #endif /* OMAP3_ISP_VIDEO_H */ |