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