2 * TI OMAP4 ISS V4L2 Driver - Generic video node
4 * Copyright (C) 2012 Texas Instruments, Inc.
6 * Author: Sergio Aguirre <sergio.a.aguirre@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #ifndef OMAP4_ISS_VIDEO_H
15 #define OMAP4_ISS_VIDEO_H
17 #include <linux/v4l2-mediabus.h>
18 #include <media/media-entity.h>
19 #include <media/v4l2-dev.h>
20 #include <media/v4l2-fh.h>
21 #include <media/videobuf2-core.h>
22 #include <media/videobuf2-dma-contig.h>
24 #define ISS_VIDEO_DRIVER_NAME "issvideo"
25 #define ISS_VIDEO_DRIVER_VERSION "0.0.2"
29 struct v4l2_mbus_framefmt;
30 struct v4l2_pix_format;
33 * struct iss_format_info - ISS media bus format information
34 * @code: V4L2 media bus format code
35 * @truncated: V4L2 media bus format code for the same format truncated to 10
36 * bits. Identical to @code if the format is 10 bits wide or less.
37 * @uncompressed: V4L2 media bus format code for the corresponding uncompressed
38 * format. Identical to @code if the format is not DPCM compressed.
39 * @flavor: V4L2 media bus format code for the same pixel layout but
40 * shifted to be 8 bits per pixel. =0 if format is not shiftable.
41 * @pixelformat: V4L2 pixel format FCC identifier
42 * @bpp: Bits per pixel
43 * @description: Human-readable format description
45 struct iss_format_info {
52 const char *description;
55 enum iss_pipeline_stream_state {
56 ISS_PIPELINE_STREAM_STOPPED = 0,
57 ISS_PIPELINE_STREAM_CONTINUOUS = 1,
58 ISS_PIPELINE_STREAM_SINGLESHOT = 2,
61 enum iss_pipeline_state {
62 /* The stream has been started on the input video node. */
63 ISS_PIPELINE_STREAM_INPUT = 1,
64 /* The stream has been started on the output video node. */
65 ISS_PIPELINE_STREAM_OUTPUT = (1 << 1),
66 /* At least one buffer is queued on the input video node. */
67 ISS_PIPELINE_QUEUE_INPUT = (1 << 2),
68 /* At least one buffer is queued on the output video node. */
69 ISS_PIPELINE_QUEUE_OUTPUT = (1 << 3),
70 /* The input entity is idle, ready to be started. */
71 ISS_PIPELINE_IDLE_INPUT = (1 << 4),
72 /* The output entity is idle, ready to be started. */
73 ISS_PIPELINE_IDLE_OUTPUT = (1 << 5),
74 /* The pipeline is currently streaming. */
75 ISS_PIPELINE_STREAM = (1 << 6),
79 * struct iss_pipeline - An OMAP4 ISS hardware pipeline
80 * @entities: Bitmask of entities in the pipeline (indexed by entity ID)
81 * @error: A hardware error occurred during capture
84 struct media_pipeline pipe;
85 spinlock_t lock; /* Pipeline state and queue flags */
87 enum iss_pipeline_stream_state stream_state;
88 struct iss_video *input;
89 struct iss_video *output;
90 unsigned int entities;
91 atomic_t frame_number;
92 bool do_propagation; /* of frame number */
94 struct v4l2_fract max_timeperframe;
95 struct v4l2_subdev *external;
96 unsigned int external_rate;
100 #define to_iss_pipeline(__e) \
101 container_of((__e)->pipe, struct iss_pipeline, pipe)
103 static inline int iss_pipeline_ready(struct iss_pipeline *pipe)
105 return pipe->state == (ISS_PIPELINE_STREAM_INPUT |
106 ISS_PIPELINE_STREAM_OUTPUT |
107 ISS_PIPELINE_QUEUE_INPUT |
108 ISS_PIPELINE_QUEUE_OUTPUT |
109 ISS_PIPELINE_IDLE_INPUT |
110 ISS_PIPELINE_IDLE_OUTPUT);
114 * struct iss_buffer - ISS buffer
115 * @buffer: ISS video buffer
116 * @iss_addr: Physical address of the buffer.
119 /* common v4l buffer stuff -- must be first */
120 struct vb2_buffer vb;
121 struct list_head list;
125 #define to_iss_buffer(buf) container_of(buf, struct iss_buffer, buffer)
127 enum iss_video_dmaqueue_flags {
128 /* Set if DMA queue becomes empty when ISS_PIPELINE_STREAM_CONTINUOUS */
129 ISS_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
130 /* Set when queuing buffer to an empty DMA queue */
131 ISS_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
134 #define iss_video_dmaqueue_flags_clr(video) \
135 ({ (video)->dmaqueue_flags = 0; })
138 * struct iss_video_operations - ISS video operations
139 * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
140 * if there was no buffer previously queued.
142 struct iss_video_operations {
143 int (*queue)(struct iss_video *video, struct iss_buffer *buffer);
147 struct video_device video;
148 enum v4l2_buf_type type;
149 struct media_pad pad;
151 struct mutex mutex; /* format and crop settings */
154 struct iss_device *iss;
156 unsigned int capture_mem;
157 unsigned int bpl_alignment; /* alignment value */
158 unsigned int bpl_zero_padding; /* whether the alignment is optional */
159 unsigned int bpl_max; /* maximum bytes per line value */
160 unsigned int bpl_value; /* bytes per line value */
161 unsigned int bpl_padding; /* padding at end of line */
164 struct iss_pipeline pipe;
165 struct mutex stream_lock; /* pipeline and stream states */
168 /* Video buffers queue */
169 struct vb2_queue *queue;
170 spinlock_t qlock; /* protects dmaqueue and error */
171 struct list_head dmaqueue;
172 enum iss_video_dmaqueue_flags dmaqueue_flags;
173 struct vb2_alloc_ctx *alloc_ctx;
175 const struct iss_video_operations *ops;
178 #define to_iss_video(vdev) container_of(vdev, struct iss_video, video)
180 struct iss_video_fh {
182 struct iss_video *video;
183 struct vb2_queue queue;
184 struct v4l2_format format;
185 struct v4l2_fract timeperframe;
188 #define to_iss_video_fh(fh) container_of(fh, struct iss_video_fh, vfh)
189 #define iss_video_queue_to_iss_video_fh(q) \
190 container_of(q, struct iss_video_fh, queue)
192 int omap4iss_video_init(struct iss_video *video, const char *name);
193 void omap4iss_video_cleanup(struct iss_video *video);
194 int omap4iss_video_register(struct iss_video *video,
195 struct v4l2_device *vdev);
196 void omap4iss_video_unregister(struct iss_video *video);
197 struct iss_buffer *omap4iss_video_buffer_next(struct iss_video *video);
198 void omap4iss_video_cancel_stream(struct iss_video *video);
199 struct media_pad *omap4iss_video_remote_pad(struct iss_video *video);
201 const struct iss_format_info *
202 omap4iss_video_format_info(u32 code);
204 #endif /* OMAP4_ISS_VIDEO_H */