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 12 struct ipu_image_convert_ctx; 13 14 /** 15 * struct ipu_image_convert_run - image conversion run request struct 16 * 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 21 */ 22 struct 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 /* private: */ 31 /* internal to image converter, callers don't touch */ 32 struct list_head list; 33 }; 34 35 /** 36 * typedef ipu_image_convert_cb_t - conversion callback function prototype 37 * 38 * @run: the completed conversion run pointer 39 * @ctx: a private context pointer for the callback 40 */ 41 typedef void (*ipu_image_convert_cb_t)(struct ipu_image_convert_run *run, 42 void *ctx); 43 44 /** 45 * ipu_image_convert_adjust() - adjust input/output images to IPU restrictions. 46 * 47 * @in: input image format, adjusted on return 48 * @out: output image format, adjusted on return 49 * @rot_mode: rotation mode 50 * 51 * In V4L2, drivers can call ipu_image_convert_adjust() in .try_fmt. 52 */ 53 void ipu_image_convert_adjust(struct ipu_image *in, struct ipu_image *out, 54 enum ipu_rotate_mode rot_mode); 55 56 /** 57 * ipu_image_convert_verify() - verify that input/output image formats 58 * and rotation mode meet IPU restrictions. 59 * 60 * @in: input image format 61 * @out: output image format 62 * @rot_mode: rotation mode 63 * 64 * Returns: 0 if the formats and rotation mode meet IPU restrictions, 65 * -EINVAL otherwise. 66 */ 67 int ipu_image_convert_verify(struct ipu_image *in, struct ipu_image *out, 68 enum ipu_rotate_mode rot_mode); 69 70 /** 71 * ipu_image_convert_prepare() - prepare a conversion context. 72 * 73 * @ipu: the IPU handle to use for the conversions 74 * @ic_task: the IC task to use for the conversions 75 * @in: input image format 76 * @out: output image format 77 * @rot_mode: rotation mode 78 * @complete: run completion callback 79 * @complete_context: a context pointer for the completion callback 80 * 81 * In V4L2, drivers should call ipu_image_convert_prepare() at streamon. 82 * 83 * Returns: an opaque conversion context pointer on success, error pointer 84 * on failure. The input/output formats and rotation mode must already meet 85 * IPU retrictions. 86 */ 87 struct ipu_image_convert_ctx * 88 ipu_image_convert_prepare(struct ipu_soc *ipu, enum ipu_ic_task ic_task, 89 struct ipu_image *in, struct ipu_image *out, 90 enum ipu_rotate_mode rot_mode, 91 ipu_image_convert_cb_t complete, 92 void *complete_context); 93 94 /** 95 * ipu_image_convert_unprepare() - unprepare a conversion context. 96 * 97 * @ctx: the conversion context pointer to unprepare 98 * 99 * Aborts any active or pending conversions for this context and 100 * frees the context. Any currently active or pending runs belonging 101 * to this context are returned via the completion callback with an 102 * error run status. 103 * 104 * In V4L2, drivers should call ipu_image_convert_unprepare() at 105 * streamoff. 106 */ 107 void ipu_image_convert_unprepare(struct ipu_image_convert_ctx *ctx); 108 109 /** 110 * ipu_image_convert_queue() - queue a conversion run 111 * 112 * @run: the run request pointer 113 * 114 * ipu_image_convert_run must be dynamically allocated (_not_ as a local 115 * var) by callers and filled in with a previously prepared conversion 116 * context handle and the dma addr's of the input and output image buffers 117 * for this conversion run. 118 * 119 * When this conversion completes, the run pointer is returned via the 120 * completion callback. The caller is responsible for freeing the run 121 * object after it completes. 122 * 123 * In V4L2, drivers should call ipu_image_convert_queue() while 124 * streaming to queue the conversion of a received input buffer. 125 * For example mem2mem devices this would be called in .device_run. 126 * 127 * Returns: 0 on success or -errno on error. 128 */ 129 int ipu_image_convert_queue(struct ipu_image_convert_run *run); 130 131 /** 132 * ipu_image_convert_abort() - abort conversions 133 * 134 * @ctx: the conversion context pointer 135 * 136 * This will abort any active or pending conversions for this context. 137 * Any currently active or pending runs belonging to this context are 138 * returned via the completion callback with an error run status. 139 */ 140 void ipu_image_convert_abort(struct ipu_image_convert_ctx *ctx); 141 142 /** 143 * ipu_image_convert() - asynchronous image conversion request 144 * 145 * @ipu: the IPU handle to use for the conversion 146 * @ic_task: the IC task to use for the conversion 147 * @in: input image format 148 * @out: output image format 149 * @rot_mode: rotation mode 150 * @complete: run completion callback 151 * @complete_context: a context pointer for the completion callback 152 * 153 * Request a single image conversion. Returns the run that has been queued. 154 * A conversion context is automatically created and is available in run->ctx. 155 * As with ipu_image_convert_prepare(), the input/output formats and rotation 156 * mode must already meet IPU retrictions. 157 * 158 * On successful return the caller can queue more run requests if needed, using 159 * the prepared context in run->ctx. The caller is responsible for unpreparing 160 * the context when no more conversion requests are needed. 161 * 162 * Returns: pointer to the created &struct ipu_image_convert_run that has 163 * been queued on success; an ERR_PTR(errno) on error. 164 */ 165 struct ipu_image_convert_run * 166 ipu_image_convert(struct ipu_soc *ipu, enum ipu_ic_task ic_task, 167 struct ipu_image *in, struct ipu_image *out, 168 enum ipu_rotate_mode rot_mode, 169 ipu_image_convert_cb_t complete, 170 void *complete_context); 171 172 #endif /* __IMX_IPU_IMAGE_CONVERT_H__ */ 173