1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2012-2016 Mentor Graphics Inc.
5 * i.MX Queued image conversion support, with tiling and rotation.
7 #ifndef __IMX_IPU_IMAGE_CONVERT_H__
8 #define __IMX_IPU_IMAGE_CONVERT_H__
10 #include <video/imx-ipu-v3.h>
12 struct ipu_image_convert_ctx
;
15 * struct ipu_image_convert_run - image conversion run request struct
17 * @ctx: the conversion context
18 * @in_phys: dma addr of input image buffer for this run
19 * @out_phys: dma addr of output image buffer for this run
20 * @status: completion status of this run
22 struct ipu_image_convert_run
{
23 struct ipu_image_convert_ctx
*ctx
;
30 /* internal to image converter, callers don't touch */
31 struct list_head list
;
35 * ipu_image_convert_cb_t - conversion callback function prototype
37 * @run: the completed conversion run pointer
38 * @ctx: a private context pointer for the callback
40 typedef void (*ipu_image_convert_cb_t
)(struct ipu_image_convert_run
*run
,
44 * ipu_image_convert_enum_format() - enumerate the image converter's
45 * supported input and output pixel formats.
47 * @index: pixel format index
48 * @fourcc: v4l2 fourcc for this index
50 * Returns 0 with a valid index and fills in v4l2 fourcc, -EINVAL otherwise.
52 * In V4L2, drivers can call ipu_image_enum_format() in .enum_fmt.
54 int ipu_image_convert_enum_format(int index
, u32
*fourcc
);
57 * ipu_image_convert_adjust() - adjust input/output images to IPU restrictions.
59 * @in: input image format, adjusted on return
60 * @out: output image format, adjusted on return
61 * @rot_mode: rotation mode
63 * In V4L2, drivers can call ipu_image_convert_adjust() in .try_fmt.
65 void ipu_image_convert_adjust(struct ipu_image
*in
, struct ipu_image
*out
,
66 enum ipu_rotate_mode rot_mode
);
69 * ipu_image_convert_verify() - verify that input/output image formats
70 * and rotation mode meet IPU restrictions.
72 * @in: input image format
73 * @out: output image format
74 * @rot_mode: rotation mode
76 * Returns 0 if the formats and rotation mode meet IPU restrictions,
79 int ipu_image_convert_verify(struct ipu_image
*in
, struct ipu_image
*out
,
80 enum ipu_rotate_mode rot_mode
);
83 * ipu_image_convert_prepare() - prepare a conversion context.
85 * @ipu: the IPU handle to use for the conversions
86 * @ic_task: the IC task to use for the conversions
87 * @in: input image format
88 * @out: output image format
89 * @rot_mode: rotation mode
90 * @complete: run completion callback
91 * @complete_context: a context pointer for the completion callback
93 * Returns an opaque conversion context pointer on success, error pointer
94 * on failure. The input/output formats and rotation mode must already meet
97 * In V4L2, drivers should call ipu_image_convert_prepare() at streamon.
99 struct ipu_image_convert_ctx
*
100 ipu_image_convert_prepare(struct ipu_soc
*ipu
, enum ipu_ic_task ic_task
,
101 struct ipu_image
*in
, struct ipu_image
*out
,
102 enum ipu_rotate_mode rot_mode
,
103 ipu_image_convert_cb_t complete
,
104 void *complete_context
);
107 * ipu_image_convert_unprepare() - unprepare a conversion context.
109 * @ctx: the conversion context pointer to unprepare
111 * Aborts any active or pending conversions for this context and
112 * frees the context. Any currently active or pending runs belonging
113 * to this context are returned via the completion callback with an
116 * In V4L2, drivers should call ipu_image_convert_unprepare() at
119 void ipu_image_convert_unprepare(struct ipu_image_convert_ctx
*ctx
);
122 * ipu_image_convert_queue() - queue a conversion run
124 * @run: the run request pointer
126 * ipu_image_convert_run must be dynamically allocated (_not_ as a local
127 * var) by callers and filled in with a previously prepared conversion
128 * context handle and the dma addr's of the input and output image buffers
129 * for this conversion run.
131 * When this conversion completes, the run pointer is returned via the
132 * completion callback. The caller is responsible for freeing the run
133 * object after it completes.
135 * In V4L2, drivers should call ipu_image_convert_queue() while
136 * streaming to queue the conversion of a received input buffer.
137 * For example mem2mem devices this would be called in .device_run.
139 int ipu_image_convert_queue(struct ipu_image_convert_run
*run
);
142 * ipu_image_convert_abort() - abort conversions
144 * @ctx: the conversion context pointer
146 * This will abort any active or pending conversions for this context.
147 * Any currently active or pending runs belonging to this context are
148 * returned via the completion callback with an error run status.
150 void ipu_image_convert_abort(struct ipu_image_convert_ctx
*ctx
);
153 * ipu_image_convert() - asynchronous image conversion request
155 * @ipu: the IPU handle to use for the conversion
156 * @ic_task: the IC task to use for the conversion
157 * @in: input image format
158 * @out: output image format
159 * @rot_mode: rotation mode
160 * @complete: run completion callback
161 * @complete_context: a context pointer for the completion callback
163 * Request a single image conversion. Returns the run that has been queued.
164 * A conversion context is automatically created and is available in run->ctx.
165 * As with ipu_image_convert_prepare(), the input/output formats and rotation
166 * mode must already meet IPU retrictions.
168 * On successful return the caller can queue more run requests if needed, using
169 * the prepared context in run->ctx. The caller is responsible for unpreparing
170 * the context when no more conversion requests are needed.
172 struct ipu_image_convert_run
*
173 ipu_image_convert(struct ipu_soc
*ipu
, enum ipu_ic_task ic_task
,
174 struct ipu_image
*in
, struct ipu_image
*out
,
175 enum ipu_rotate_mode rot_mode
,
176 ipu_image_convert_cb_t complete
,
177 void *complete_context
);
180 * ipu_image_convert_sync() - synchronous single image conversion request
182 * @ipu: the IPU handle to use for the conversion
183 * @ic_task: the IC task to use for the conversion
184 * @in: input image format
185 * @out: output image format
186 * @rot_mode: rotation mode
188 * Carry out a single image conversion. Returns when the conversion
189 * completes. The input/output formats and rotation mode must already
190 * meet IPU retrictions. The created context is automatically unprepared
191 * and the run freed on return.
193 int ipu_image_convert_sync(struct ipu_soc
*ipu
, enum ipu_ic_task ic_task
,
194 struct ipu_image
*in
, struct ipu_image
*out
,
195 enum ipu_rotate_mode rot_mode
);
198 #endif /* __IMX_IPU_IMAGE_CONVERT_H__ */