162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2012-2016 Mentor Graphics Inc.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * i.MX Queued image conversion support, with tiling and rotation.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci#ifndef __IMX_IPU_IMAGE_CONVERT_H__
862306a36Sopenharmony_ci#define __IMX_IPU_IMAGE_CONVERT_H__
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <video/imx-ipu-v3.h>
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_cistruct ipu_image_convert_ctx;
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/**
1562306a36Sopenharmony_ci * struct ipu_image_convert_run - image conversion run request struct
1662306a36Sopenharmony_ci *
1762306a36Sopenharmony_ci * @ctx:	the conversion context
1862306a36Sopenharmony_ci * @in_phys:	dma addr of input image buffer for this run
1962306a36Sopenharmony_ci * @out_phys:	dma addr of output image buffer for this run
2062306a36Sopenharmony_ci * @status:	completion status of this run
2162306a36Sopenharmony_ci */
2262306a36Sopenharmony_cistruct ipu_image_convert_run {
2362306a36Sopenharmony_ci	struct ipu_image_convert_ctx *ctx;
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci	dma_addr_t in_phys;
2662306a36Sopenharmony_ci	dma_addr_t out_phys;
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci	int status;
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci	/* internal to image converter, callers don't touch */
3162306a36Sopenharmony_ci	struct list_head list;
3262306a36Sopenharmony_ci};
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/**
3562306a36Sopenharmony_ci * ipu_image_convert_cb_t - conversion callback function prototype
3662306a36Sopenharmony_ci *
3762306a36Sopenharmony_ci * @run:	the completed conversion run pointer
3862306a36Sopenharmony_ci * @ctx:	a private context pointer for the callback
3962306a36Sopenharmony_ci */
4062306a36Sopenharmony_citypedef void (*ipu_image_convert_cb_t)(struct ipu_image_convert_run *run,
4162306a36Sopenharmony_ci				       void *ctx);
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/**
4462306a36Sopenharmony_ci * ipu_image_convert_enum_format() - enumerate the image converter's
4562306a36Sopenharmony_ci *	supported input and output pixel formats.
4662306a36Sopenharmony_ci *
4762306a36Sopenharmony_ci * @index:	pixel format index
4862306a36Sopenharmony_ci * @fourcc:	v4l2 fourcc for this index
4962306a36Sopenharmony_ci *
5062306a36Sopenharmony_ci * Returns 0 with a valid index and fills in v4l2 fourcc, -EINVAL otherwise.
5162306a36Sopenharmony_ci *
5262306a36Sopenharmony_ci * In V4L2, drivers can call ipu_image_enum_format() in .enum_fmt.
5362306a36Sopenharmony_ci */
5462306a36Sopenharmony_ciint ipu_image_convert_enum_format(int index, u32 *fourcc);
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci/**
5762306a36Sopenharmony_ci * ipu_image_convert_adjust() - adjust input/output images to IPU restrictions.
5862306a36Sopenharmony_ci *
5962306a36Sopenharmony_ci * @in:		input image format, adjusted on return
6062306a36Sopenharmony_ci * @out:	output image format, adjusted on return
6162306a36Sopenharmony_ci * @rot_mode:	rotation mode
6262306a36Sopenharmony_ci *
6362306a36Sopenharmony_ci * In V4L2, drivers can call ipu_image_convert_adjust() in .try_fmt.
6462306a36Sopenharmony_ci */
6562306a36Sopenharmony_civoid ipu_image_convert_adjust(struct ipu_image *in, struct ipu_image *out,
6662306a36Sopenharmony_ci			      enum ipu_rotate_mode rot_mode);
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/**
6962306a36Sopenharmony_ci * ipu_image_convert_verify() - verify that input/output image formats
7062306a36Sopenharmony_ci *         and rotation mode meet IPU restrictions.
7162306a36Sopenharmony_ci *
7262306a36Sopenharmony_ci * @in:		input image format
7362306a36Sopenharmony_ci * @out:	output image format
7462306a36Sopenharmony_ci * @rot_mode:	rotation mode
7562306a36Sopenharmony_ci *
7662306a36Sopenharmony_ci * Returns 0 if the formats and rotation mode meet IPU restrictions,
7762306a36Sopenharmony_ci * -EINVAL otherwise.
7862306a36Sopenharmony_ci */
7962306a36Sopenharmony_ciint ipu_image_convert_verify(struct ipu_image *in, struct ipu_image *out,
8062306a36Sopenharmony_ci			     enum ipu_rotate_mode rot_mode);
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci/**
8362306a36Sopenharmony_ci * ipu_image_convert_prepare() - prepare a conversion context.
8462306a36Sopenharmony_ci *
8562306a36Sopenharmony_ci * @ipu:	the IPU handle to use for the conversions
8662306a36Sopenharmony_ci * @ic_task:	the IC task to use for the conversions
8762306a36Sopenharmony_ci * @in:		input image format
8862306a36Sopenharmony_ci * @out:	output image format
8962306a36Sopenharmony_ci * @rot_mode:	rotation mode
9062306a36Sopenharmony_ci * @complete:	run completion callback
9162306a36Sopenharmony_ci * @complete_context:	a context pointer for the completion callback
9262306a36Sopenharmony_ci *
9362306a36Sopenharmony_ci * Returns an opaque conversion context pointer on success, error pointer
9462306a36Sopenharmony_ci * on failure. The input/output formats and rotation mode must already meet
9562306a36Sopenharmony_ci * IPU retrictions.
9662306a36Sopenharmony_ci *
9762306a36Sopenharmony_ci * In V4L2, drivers should call ipu_image_convert_prepare() at streamon.
9862306a36Sopenharmony_ci */
9962306a36Sopenharmony_cistruct ipu_image_convert_ctx *
10062306a36Sopenharmony_ciipu_image_convert_prepare(struct ipu_soc *ipu, enum ipu_ic_task ic_task,
10162306a36Sopenharmony_ci			  struct ipu_image *in, struct ipu_image *out,
10262306a36Sopenharmony_ci			  enum ipu_rotate_mode rot_mode,
10362306a36Sopenharmony_ci			  ipu_image_convert_cb_t complete,
10462306a36Sopenharmony_ci			  void *complete_context);
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci/**
10762306a36Sopenharmony_ci * ipu_image_convert_unprepare() - unprepare a conversion context.
10862306a36Sopenharmony_ci *
10962306a36Sopenharmony_ci * @ctx: the conversion context pointer to unprepare
11062306a36Sopenharmony_ci *
11162306a36Sopenharmony_ci * Aborts any active or pending conversions for this context and
11262306a36Sopenharmony_ci * frees the context. Any currently active or pending runs belonging
11362306a36Sopenharmony_ci * to this context are returned via the completion callback with an
11462306a36Sopenharmony_ci * error run status.
11562306a36Sopenharmony_ci *
11662306a36Sopenharmony_ci * In V4L2, drivers should call ipu_image_convert_unprepare() at
11762306a36Sopenharmony_ci * streamoff.
11862306a36Sopenharmony_ci */
11962306a36Sopenharmony_civoid ipu_image_convert_unprepare(struct ipu_image_convert_ctx *ctx);
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci/**
12262306a36Sopenharmony_ci * ipu_image_convert_queue() - queue a conversion run
12362306a36Sopenharmony_ci *
12462306a36Sopenharmony_ci * @run: the run request pointer
12562306a36Sopenharmony_ci *
12662306a36Sopenharmony_ci * ipu_image_convert_run must be dynamically allocated (_not_ as a local
12762306a36Sopenharmony_ci * var) by callers and filled in with a previously prepared conversion
12862306a36Sopenharmony_ci * context handle and the dma addr's of the input and output image buffers
12962306a36Sopenharmony_ci * for this conversion run.
13062306a36Sopenharmony_ci *
13162306a36Sopenharmony_ci * When this conversion completes, the run pointer is returned via the
13262306a36Sopenharmony_ci * completion callback. The caller is responsible for freeing the run
13362306a36Sopenharmony_ci * object after it completes.
13462306a36Sopenharmony_ci *
13562306a36Sopenharmony_ci * In V4L2, drivers should call ipu_image_convert_queue() while
13662306a36Sopenharmony_ci * streaming to queue the conversion of a received input buffer.
13762306a36Sopenharmony_ci * For example mem2mem devices this would be called in .device_run.
13862306a36Sopenharmony_ci */
13962306a36Sopenharmony_ciint ipu_image_convert_queue(struct ipu_image_convert_run *run);
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci/**
14262306a36Sopenharmony_ci * ipu_image_convert_abort() - abort conversions
14362306a36Sopenharmony_ci *
14462306a36Sopenharmony_ci * @ctx: the conversion context pointer
14562306a36Sopenharmony_ci *
14662306a36Sopenharmony_ci * This will abort any active or pending conversions for this context.
14762306a36Sopenharmony_ci * Any currently active or pending runs belonging to this context are
14862306a36Sopenharmony_ci * returned via the completion callback with an error run status.
14962306a36Sopenharmony_ci */
15062306a36Sopenharmony_civoid ipu_image_convert_abort(struct ipu_image_convert_ctx *ctx);
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci/**
15362306a36Sopenharmony_ci * ipu_image_convert() - asynchronous image conversion request
15462306a36Sopenharmony_ci *
15562306a36Sopenharmony_ci * @ipu:	the IPU handle to use for the conversion
15662306a36Sopenharmony_ci * @ic_task:	the IC task to use for the conversion
15762306a36Sopenharmony_ci * @in:		input image format
15862306a36Sopenharmony_ci * @out:	output image format
15962306a36Sopenharmony_ci * @rot_mode:	rotation mode
16062306a36Sopenharmony_ci * @complete:	run completion callback
16162306a36Sopenharmony_ci * @complete_context:	a context pointer for the completion callback
16262306a36Sopenharmony_ci *
16362306a36Sopenharmony_ci * Request a single image conversion. Returns the run that has been queued.
16462306a36Sopenharmony_ci * A conversion context is automatically created and is available in run->ctx.
16562306a36Sopenharmony_ci * As with ipu_image_convert_prepare(), the input/output formats and rotation
16662306a36Sopenharmony_ci * mode must already meet IPU retrictions.
16762306a36Sopenharmony_ci *
16862306a36Sopenharmony_ci * On successful return the caller can queue more run requests if needed, using
16962306a36Sopenharmony_ci * the prepared context in run->ctx. The caller is responsible for unpreparing
17062306a36Sopenharmony_ci * the context when no more conversion requests are needed.
17162306a36Sopenharmony_ci */
17262306a36Sopenharmony_cistruct ipu_image_convert_run *
17362306a36Sopenharmony_ciipu_image_convert(struct ipu_soc *ipu, enum ipu_ic_task ic_task,
17462306a36Sopenharmony_ci		  struct ipu_image *in, struct ipu_image *out,
17562306a36Sopenharmony_ci		  enum ipu_rotate_mode rot_mode,
17662306a36Sopenharmony_ci		  ipu_image_convert_cb_t complete,
17762306a36Sopenharmony_ci		  void *complete_context);
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci/**
18062306a36Sopenharmony_ci * ipu_image_convert_sync() - synchronous single image conversion request
18162306a36Sopenharmony_ci *
18262306a36Sopenharmony_ci * @ipu:	the IPU handle to use for the conversion
18362306a36Sopenharmony_ci * @ic_task:	the IC task to use for the conversion
18462306a36Sopenharmony_ci * @in:		input image format
18562306a36Sopenharmony_ci * @out:	output image format
18662306a36Sopenharmony_ci * @rot_mode:	rotation mode
18762306a36Sopenharmony_ci *
18862306a36Sopenharmony_ci * Carry out a single image conversion. Returns when the conversion
18962306a36Sopenharmony_ci * completes. The input/output formats and rotation mode must already
19062306a36Sopenharmony_ci * meet IPU retrictions. The created context is automatically unprepared
19162306a36Sopenharmony_ci * and the run freed on return.
19262306a36Sopenharmony_ci */
19362306a36Sopenharmony_ciint ipu_image_convert_sync(struct ipu_soc *ipu, enum ipu_ic_task ic_task,
19462306a36Sopenharmony_ci			   struct ipu_image *in, struct ipu_image *out,
19562306a36Sopenharmony_ci			   enum ipu_rotate_mode rot_mode);
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci#endif /* __IMX_IPU_IMAGE_CONVERT_H__ */
199