199 lines · c
1/* SPDX-License-Identifier: GPL-2.0-or-later */2/*3 * Copyright (C) 2012-2016 Mentor Graphics Inc.4 *5 * i.MX Queued image conversion support, with tiling and rotation.6 */7#ifndef __IMX_IPU_IMAGE_CONVERT_H__8#define __IMX_IPU_IMAGE_CONVERT_H__9 10#include <video/imx-ipu-v3.h>11 12struct ipu_image_convert_ctx;13 14/**15 * struct ipu_image_convert_run - image conversion run request struct16 *17 * @ctx: the conversion context18 * @in_phys: dma addr of input image buffer for this run19 * @out_phys: dma addr of output image buffer for this run20 * @status: completion status of this run21 */22struct ipu_image_convert_run {23 struct ipu_image_convert_ctx *ctx;24 25 dma_addr_t in_phys;26 dma_addr_t out_phys;27 28 int status;29 30 /* internal to image converter, callers don't touch */31 struct list_head list;32};33 34/**35 * ipu_image_convert_cb_t - conversion callback function prototype36 *37 * @run: the completed conversion run pointer38 * @ctx: a private context pointer for the callback39 */40typedef void (*ipu_image_convert_cb_t)(struct ipu_image_convert_run *run,41 void *ctx);42 43/**44 * ipu_image_convert_enum_format() - enumerate the image converter's45 * supported input and output pixel formats.46 *47 * @index: pixel format index48 * @fourcc: v4l2 fourcc for this index49 *50 * Returns 0 with a valid index and fills in v4l2 fourcc, -EINVAL otherwise.51 *52 * In V4L2, drivers can call ipu_image_enum_format() in .enum_fmt.53 */54int ipu_image_convert_enum_format(int index, u32 *fourcc);55 56/**57 * ipu_image_convert_adjust() - adjust input/output images to IPU restrictions.58 *59 * @in: input image format, adjusted on return60 * @out: output image format, adjusted on return61 * @rot_mode: rotation mode62 *63 * In V4L2, drivers can call ipu_image_convert_adjust() in .try_fmt.64 */65void ipu_image_convert_adjust(struct ipu_image *in, struct ipu_image *out,66 enum ipu_rotate_mode rot_mode);67 68/**69 * ipu_image_convert_verify() - verify that input/output image formats70 * and rotation mode meet IPU restrictions.71 *72 * @in: input image format73 * @out: output image format74 * @rot_mode: rotation mode75 *76 * Returns 0 if the formats and rotation mode meet IPU restrictions,77 * -EINVAL otherwise.78 */79int ipu_image_convert_verify(struct ipu_image *in, struct ipu_image *out,80 enum ipu_rotate_mode rot_mode);81 82/**83 * ipu_image_convert_prepare() - prepare a conversion context.84 *85 * @ipu: the IPU handle to use for the conversions86 * @ic_task: the IC task to use for the conversions87 * @in: input image format88 * @out: output image format89 * @rot_mode: rotation mode90 * @complete: run completion callback91 * @complete_context: a context pointer for the completion callback92 *93 * Returns an opaque conversion context pointer on success, error pointer94 * on failure. The input/output formats and rotation mode must already meet95 * IPU retrictions.96 *97 * In V4L2, drivers should call ipu_image_convert_prepare() at streamon.98 */99struct ipu_image_convert_ctx *100ipu_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);105 106/**107 * ipu_image_convert_unprepare() - unprepare a conversion context.108 *109 * @ctx: the conversion context pointer to unprepare110 *111 * Aborts any active or pending conversions for this context and112 * frees the context. Any currently active or pending runs belonging113 * to this context are returned via the completion callback with an114 * error run status.115 *116 * In V4L2, drivers should call ipu_image_convert_unprepare() at117 * streamoff.118 */119void ipu_image_convert_unprepare(struct ipu_image_convert_ctx *ctx);120 121/**122 * ipu_image_convert_queue() - queue a conversion run123 *124 * @run: the run request pointer125 *126 * ipu_image_convert_run must be dynamically allocated (_not_ as a local127 * var) by callers and filled in with a previously prepared conversion128 * context handle and the dma addr's of the input and output image buffers129 * for this conversion run.130 *131 * When this conversion completes, the run pointer is returned via the132 * completion callback. The caller is responsible for freeing the run133 * object after it completes.134 *135 * In V4L2, drivers should call ipu_image_convert_queue() while136 * streaming to queue the conversion of a received input buffer.137 * For example mem2mem devices this would be called in .device_run.138 */139int ipu_image_convert_queue(struct ipu_image_convert_run *run);140 141/**142 * ipu_image_convert_abort() - abort conversions143 *144 * @ctx: the conversion context pointer145 *146 * This will abort any active or pending conversions for this context.147 * Any currently active or pending runs belonging to this context are148 * returned via the completion callback with an error run status.149 */150void ipu_image_convert_abort(struct ipu_image_convert_ctx *ctx);151 152/**153 * ipu_image_convert() - asynchronous image conversion request154 *155 * @ipu: the IPU handle to use for the conversion156 * @ic_task: the IC task to use for the conversion157 * @in: input image format158 * @out: output image format159 * @rot_mode: rotation mode160 * @complete: run completion callback161 * @complete_context: a context pointer for the completion callback162 *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 rotation166 * mode must already meet IPU retrictions.167 *168 * On successful return the caller can queue more run requests if needed, using169 * the prepared context in run->ctx. The caller is responsible for unpreparing170 * the context when no more conversion requests are needed.171 */172struct ipu_image_convert_run *173ipu_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);178 179/**180 * ipu_image_convert_sync() - synchronous single image conversion request181 *182 * @ipu: the IPU handle to use for the conversion183 * @ic_task: the IC task to use for the conversion184 * @in: input image format185 * @out: output image format186 * @rot_mode: rotation mode187 *188 * Carry out a single image conversion. Returns when the conversion189 * completes. The input/output formats and rotation mode must already190 * meet IPU retrictions. The created context is automatically unprepared191 * and the run freed on return.192 */193int 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);196 197 198#endif /* __IMX_IPU_IMAGE_CONVERT_H__ */199