1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * TI OMAP4 ISS V4L2 Driver - Generic video node
5 * Copyright (C) 2012 Texas Instruments, Inc.
7 * Author: Sergio Aguirre <sergio.a.aguirre@gmail.com>
10 #ifndef OMAP4_ISS_VIDEO_H
11 #define OMAP4_ISS_VIDEO_H
13 #include <linux/v4l2-mediabus.h>
14 #include <media/media-entity.h>
15 #include <media/v4l2-dev.h>
16 #include <media/v4l2-fh.h>
17 #include <media/videobuf2-v4l2.h>
18 #include <media/videobuf2-dma-contig.h>
20 #define ISS_VIDEO_DRIVER_NAME "issvideo"
21 #define ISS_VIDEO_DRIVER_VERSION "0.0.2"
25 struct v4l2_mbus_framefmt;
26 struct v4l2_pix_format;
29 * struct iss_format_info - ISS media bus format information
30 * @code: V4L2 media bus format code
31 * @truncated: V4L2 media bus format code for the same format truncated to 10
32 * bits. Identical to @code if the format is 10 bits wide or less.
33 * @uncompressed: V4L2 media bus format code for the corresponding uncompressed
34 * format. Identical to @code if the format is not DPCM compressed.
35 * @flavor: V4L2 media bus format code for the same pixel layout but
36 * shifted to be 8 bits per pixel. =0 if format is not shiftable.
37 * @pixelformat: V4L2 pixel format FCC identifier
38 * @bpp: Bits per pixel
39 * @description: Human-readable format description
41 struct iss_format_info {
48 const char *description;
51 enum iss_pipeline_stream_state {
52 ISS_PIPELINE_STREAM_STOPPED = 0,
53 ISS_PIPELINE_STREAM_CONTINUOUS = 1,
54 ISS_PIPELINE_STREAM_SINGLESHOT = 2,
57 enum iss_pipeline_state {
58 /* The stream has been started on the input video node. */
59 ISS_PIPELINE_STREAM_INPUT = 1,
60 /* The stream has been started on the output video node. */
61 ISS_PIPELINE_STREAM_OUTPUT = (1 << 1),
62 /* At least one buffer is queued on the input video node. */
63 ISS_PIPELINE_QUEUE_INPUT = (1 << 2),
64 /* At least one buffer is queued on the output video node. */
65 ISS_PIPELINE_QUEUE_OUTPUT = (1 << 3),
66 /* The input entity is idle, ready to be started. */
67 ISS_PIPELINE_IDLE_INPUT = (1 << 4),
68 /* The output entity is idle, ready to be started. */
69 ISS_PIPELINE_IDLE_OUTPUT = (1 << 5),
70 /* The pipeline is currently streaming. */
71 ISS_PIPELINE_STREAM = (1 << 6),
75 * struct iss_pipeline - An OMAP4 ISS hardware pipeline
76 * @ent_enum: Entities in the pipeline
77 * @error: A hardware error occurred during capture
80 struct media_pipeline pipe;
81 spinlock_t lock; /* Pipeline state and queue flags */
83 enum iss_pipeline_stream_state stream_state;
84 struct iss_video *input;
85 struct iss_video *output;
86 struct media_entity_enum ent_enum;
87 atomic_t frame_number;
88 bool do_propagation; /* of frame number */
90 struct v4l2_fract max_timeperframe;
91 struct v4l2_subdev *external;
92 unsigned int external_rate;
96 #define to_iss_pipeline(__e) \
97 container_of((__e)->pipe, struct iss_pipeline, pipe)
99 static inline int iss_pipeline_ready(struct iss_pipeline *pipe)
101 return pipe->state == (ISS_PIPELINE_STREAM_INPUT |
102 ISS_PIPELINE_STREAM_OUTPUT |
103 ISS_PIPELINE_QUEUE_INPUT |
104 ISS_PIPELINE_QUEUE_OUTPUT |
105 ISS_PIPELINE_IDLE_INPUT |
106 ISS_PIPELINE_IDLE_OUTPUT);
110 * struct iss_buffer - ISS buffer
111 * @buffer: ISS video buffer
112 * @iss_addr: Physical address of the buffer.
115 /* common v4l buffer stuff -- must be first */
116 struct vb2_v4l2_buffer vb;
117 struct list_head list;
121 #define to_iss_buffer(buf) container_of(buf, struct iss_buffer, vb)
123 enum iss_video_dmaqueue_flags {
124 /* Set if DMA queue becomes empty when ISS_PIPELINE_STREAM_CONTINUOUS */
125 ISS_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
126 /* Set when queuing buffer to an empty DMA queue */
127 ISS_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
130 #define iss_video_dmaqueue_flags_clr(video) \
131 ({ (video)->dmaqueue_flags = 0; })
134 * struct iss_video_operations - ISS video operations
135 * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
136 * if there was no buffer previously queued.
138 struct iss_video_operations {
139 int (*queue)(struct iss_video *video, struct iss_buffer *buffer);
143 struct video_device video;
144 enum v4l2_buf_type type;
145 struct media_pad pad;
147 struct mutex mutex; /* format and crop settings */
150 struct iss_device *iss;
152 unsigned int capture_mem;
153 unsigned int bpl_alignment; /* alignment value */
154 unsigned int bpl_zero_padding; /* whether the alignment is optional */
155 unsigned int bpl_max; /* maximum bytes per line value */
156 unsigned int bpl_value; /* bytes per line value */
157 unsigned int bpl_padding; /* padding at end of line */
160 struct iss_pipeline pipe;
161 struct mutex stream_lock; /* pipeline and stream states */
164 /* Video buffers queue */
165 struct vb2_queue *queue;
166 spinlock_t qlock; /* protects dmaqueue and error */
167 struct list_head dmaqueue;
168 enum iss_video_dmaqueue_flags dmaqueue_flags;
170 const struct iss_video_operations *ops;
173 #define to_iss_video(vdev) container_of(vdev, struct iss_video, video)
175 struct iss_video_fh {
177 struct iss_video *video;
178 struct vb2_queue queue;
179 struct v4l2_format format;
180 struct v4l2_fract timeperframe;
183 #define to_iss_video_fh(fh) container_of(fh, struct iss_video_fh, vfh)
184 #define iss_video_queue_to_iss_video_fh(q) \
185 container_of(q, struct iss_video_fh, queue)
187 int omap4iss_video_init(struct iss_video *video, const char *name);
188 void omap4iss_video_cleanup(struct iss_video *video);
189 int omap4iss_video_register(struct iss_video *video,
190 struct v4l2_device *vdev);
191 void omap4iss_video_unregister(struct iss_video *video);
192 struct iss_buffer *omap4iss_video_buffer_next(struct iss_video *video);
193 void omap4iss_video_cancel_stream(struct iss_video *video);
194 struct media_pad *omap4iss_video_remote_pad(struct iss_video *video);
196 const struct iss_format_info *
197 omap4iss_video_format_info(u32 code);
199 #endif /* OMAP4_ISS_VIDEO_H */