blob: 6a48d5879c5621b9a27944bb238132362c00f4a9 [file] [log] [blame]
Laurent Pinchartad614ac2011-02-12 18:05:06 -03001/*
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.
Laurent Pinchartad614ac2011-02-12 18:05:06 -030014 */
15
16#ifndef OMAP3_ISP_VIDEO_H
17#define OMAP3_ISP_VIDEO_H
18
19#include <linux/v4l2-mediabus.h>
Laurent Pinchartad614ac2011-02-12 18:05:06 -030020#include <media/media-entity.h>
21#include <media/v4l2-dev.h>
22#include <media/v4l2-fh.h>
Junghak Sungc1399902015-09-22 10:30:29 -030023#include <media/videobuf2-v4l2.h>
Laurent Pinchartad614ac2011-02-12 18:05:06 -030024
25#define ISP_VIDEO_DRIVER_NAME "ispvideo"
Mauro Carvalho Chehab64dc3c12011-06-25 11:28:37 -030026#define ISP_VIDEO_DRIVER_VERSION "0.0.2"
Laurent Pinchartad614ac2011-02-12 18:05:06 -030027
28struct isp_device;
29struct isp_video;
30struct v4l2_mbus_framefmt;
31struct v4l2_pix_format;
32
33/*
34 * struct isp_format_info - ISP media bus format information
35 * @code: V4L2 media bus format code
36 * @truncated: V4L2 media bus format code for the same format truncated to 10
37 * bits. Identical to @code if the format is 10 bits wide or less.
38 * @uncompressed: V4L2 media bus format code for the corresponding uncompressed
39 * format. Identical to @code if the format is not DPCM compressed.
Michael Jonesc09af042011-03-29 05:19:09 -030040 * @flavor: V4L2 media bus format code for the same pixel layout but
41 * shifted to be 8 bits per pixel. =0 if format is not shiftable.
Laurent Pinchartad614ac2011-02-12 18:05:06 -030042 * @pixelformat: V4L2 pixel format FCC identifier
Laurent Pinchart1697e492011-08-31 11:57:12 -030043 * @width: Bits per pixel (when transferred over a bus)
44 * @bpp: Bytes per pixel (when stored in memory)
Laurent Pinchartad614ac2011-02-12 18:05:06 -030045 */
46struct isp_format_info {
Boris BREZILLON27ffaeb2014-11-10 14:28:31 -030047 u32 code;
48 u32 truncated;
49 u32 uncompressed;
50 u32 flavor;
Laurent Pinchartad614ac2011-02-12 18:05:06 -030051 u32 pixelformat;
Laurent Pinchart1697e492011-08-31 11:57:12 -030052 unsigned int width;
Laurent Pinchartad614ac2011-02-12 18:05:06 -030053 unsigned int bpp;
54};
55
56enum isp_pipeline_stream_state {
57 ISP_PIPELINE_STREAM_STOPPED = 0,
58 ISP_PIPELINE_STREAM_CONTINUOUS = 1,
59 ISP_PIPELINE_STREAM_SINGLESHOT = 2,
60};
61
62enum isp_pipeline_state {
63 /* The stream has been started on the input video node. */
64 ISP_PIPELINE_STREAM_INPUT = 1,
65 /* The stream has been started on the output video node. */
66 ISP_PIPELINE_STREAM_OUTPUT = 2,
67 /* At least one buffer is queued on the input video node. */
68 ISP_PIPELINE_QUEUE_INPUT = 4,
69 /* At least one buffer is queued on the output video node. */
70 ISP_PIPELINE_QUEUE_OUTPUT = 8,
71 /* The input entity is idle, ready to be started. */
72 ISP_PIPELINE_IDLE_INPUT = 16,
73 /* The output entity is idle, ready to be started. */
74 ISP_PIPELINE_IDLE_OUTPUT = 32,
75 /* The pipeline is currently streaming. */
76 ISP_PIPELINE_STREAM = 64,
77};
78
Laurent Pinchart875e2e32011-12-07 08:34:50 -030079/*
80 * struct isp_pipeline - An ISP hardware pipeline
Laurent Pinchart9a36d8e2014-05-19 16:37:38 -030081 * @field: The field being processed by the pipeline
Laurent Pinchart875e2e32011-12-07 08:34:50 -030082 * @error: A hardware error occurred during capture
Sakari Ailus17d3d402015-12-16 11:32:30 -020083 * @ent_enum: Entities in the pipeline
Laurent Pinchart875e2e32011-12-07 08:34:50 -030084 */
Laurent Pinchartad614ac2011-02-12 18:05:06 -030085struct isp_pipeline {
86 struct media_pipeline pipe;
87 spinlock_t lock; /* Pipeline state and queue flags */
88 unsigned int state;
89 enum isp_pipeline_stream_state stream_state;
90 struct isp_video *input;
91 struct isp_video *output;
Sakari Ailus17d3d402015-12-16 11:32:30 -020092 struct media_entity_enum ent_enum;
Laurent Pinchartad614ac2011-02-12 18:05:06 -030093 unsigned long l3_ick;
94 unsigned int max_rate;
Laurent Pinchart9a36d8e2014-05-19 16:37:38 -030095 enum v4l2_field field;
Laurent Pinchartad614ac2011-02-12 18:05:06 -030096 atomic_t frame_number;
97 bool do_propagation; /* of frame number */
Laurent Pinchart875e2e32011-12-07 08:34:50 -030098 bool error;
Laurent Pinchartad614ac2011-02-12 18:05:06 -030099 struct v4l2_fract max_timeperframe;
Sakari Ailus80b37e72012-01-16 18:58:01 -0300100 struct v4l2_subdev *external;
101 unsigned int external_rate;
Laurent Pinchart1697e492011-08-31 11:57:12 -0300102 unsigned int external_width;
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300103};
104
105#define to_isp_pipeline(__e) \
106 container_of((__e)->pipe, struct isp_pipeline, pipe)
107
108static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
109{
110 return pipe->state == (ISP_PIPELINE_STREAM_INPUT |
111 ISP_PIPELINE_STREAM_OUTPUT |
112 ISP_PIPELINE_QUEUE_INPUT |
113 ISP_PIPELINE_QUEUE_OUTPUT |
114 ISP_PIPELINE_IDLE_INPUT |
115 ISP_PIPELINE_IDLE_OUTPUT);
116}
117
Laurent Pinchartfbac1402014-03-09 20:36:15 -0300118/**
119 * struct isp_buffer - ISP video buffer
120 * @vb: videobuf2 buffer
Laurent Pincharteb2c00d2014-03-09 20:57:53 -0300121 * @irqlist: List head for insertion into IRQ queue
Laurent Pinchart21d85822014-03-09 20:17:12 -0300122 * @dma: DMA address
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300123 */
124struct isp_buffer {
Junghak Sung2d700712015-09-22 10:30:30 -0300125 struct vb2_v4l2_buffer vb;
Laurent Pincharteb2c00d2014-03-09 20:57:53 -0300126 struct list_head irqlist;
Laurent Pinchart21d85822014-03-09 20:17:12 -0300127 dma_addr_t dma;
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300128};
129
Laurent Pinchartfbac1402014-03-09 20:36:15 -0300130#define to_isp_buffer(buf) container_of(buf, struct isp_buffer, vb)
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300131
132enum isp_video_dmaqueue_flags {
133 /* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */
134 ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
135 /* Set when queuing buffer to an empty DMA queue */
136 ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
137};
138
139#define isp_video_dmaqueue_flags_clr(video) \
140 ({ (video)->dmaqueue_flags = 0; })
141
142/*
143 * struct isp_video_operations - ISP video operations
144 * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
145 * if there was no buffer previously queued.
146 */
147struct isp_video_operations {
148 int(*queue)(struct isp_video *video, struct isp_buffer *buffer);
149};
150
151struct isp_video {
152 struct video_device video;
153 enum v4l2_buf_type type;
154 struct media_pad pad;
155
156 struct mutex mutex; /* format and crop settings */
157 atomic_t active;
158
159 struct isp_device *isp;
160
161 unsigned int capture_mem;
162 unsigned int bpl_alignment; /* alignment value */
163 unsigned int bpl_zero_padding; /* whether the alignment is optional */
164 unsigned int bpl_max; /* maximum bytes per line value */
165 unsigned int bpl_value; /* bytes per line value */
166 unsigned int bpl_padding; /* padding at end of line */
167
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300168 /* Pipeline state */
169 struct isp_pipeline pipe;
170 struct mutex stream_lock; /* pipeline and stream states */
Laurent Pinchart661112c2013-12-09 11:36:51 -0300171 bool error;
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300172
173 /* Video buffers queue */
Laurent Pinchartfbac1402014-03-09 20:36:15 -0300174 void *alloc_ctx;
175 struct vb2_queue *queue;
Laurent Pinchart988d54c2014-03-09 20:57:53 -0300176 struct mutex queue_lock; /* protects the queue */
Laurent Pincharte8feb872014-03-09 20:57:53 -0300177 spinlock_t irqlock; /* protects dmaqueue */
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300178 struct list_head dmaqueue;
179 enum isp_video_dmaqueue_flags dmaqueue_flags;
180
181 const struct isp_video_operations *ops;
182};
183
184#define to_isp_video(vdev) container_of(vdev, struct isp_video, video)
185
186struct isp_video_fh {
187 struct v4l2_fh vfh;
188 struct isp_video *video;
Laurent Pinchartfbac1402014-03-09 20:36:15 -0300189 struct vb2_queue queue;
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300190 struct v4l2_format format;
191 struct v4l2_fract timeperframe;
192};
193
194#define to_isp_video_fh(fh) container_of(fh, struct isp_video_fh, vfh)
195#define isp_video_queue_to_isp_video_fh(q) \
196 container_of(q, struct isp_video_fh, queue)
197
198int omap3isp_video_init(struct isp_video *video, const char *name);
Laurent Pinchart63b4ca22011-09-22 16:54:34 -0300199void omap3isp_video_cleanup(struct isp_video *video);
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300200int omap3isp_video_register(struct isp_video *video,
201 struct v4l2_device *vdev);
202void omap3isp_video_unregister(struct isp_video *video);
Laurent Pinchart875e2e32011-12-07 08:34:50 -0300203struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video);
Laurent Pinchart661112c2013-12-09 11:36:51 -0300204void omap3isp_video_cancel_stream(struct isp_video *video);
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300205void omap3isp_video_resume(struct isp_video *video, int continuous);
206struct media_pad *omap3isp_video_remote_pad(struct isp_video *video);
207
208const struct isp_format_info *
Boris BREZILLON27ffaeb2014-11-10 14:28:31 -0300209omap3isp_video_format_info(u32 code);
Laurent Pinchartad614ac2011-02-12 18:05:06 -0300210
211#endif /* OMAP3_ISP_VIDEO_H */