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