imx-ipu-image-convert.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright (C) 2012-2016 Mentor Graphics Inc.
  3. *
  4. * i.MX Queued image conversion support, with tiling and rotation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  13. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * for more details.
  15. */
  16. #ifndef __IMX_IPU_IMAGE_CONVERT_H__
  17. #define __IMX_IPU_IMAGE_CONVERT_H__
  18. #include <video/imx-ipu-v3.h>
  19. struct ipu_image_convert_ctx;
  20. /**
  21. * struct ipu_image_convert_run - image conversion run request struct
  22. *
  23. * @ctx: the conversion context
  24. * @in_phys: dma addr of input image buffer for this run
  25. * @out_phys: dma addr of output image buffer for this run
  26. * @status: completion status of this run
  27. */
  28. struct ipu_image_convert_run {
  29. struct ipu_image_convert_ctx *ctx;
  30. dma_addr_t in_phys;
  31. dma_addr_t out_phys;
  32. int status;
  33. /* internal to image converter, callers don't touch */
  34. struct list_head list;
  35. };
  36. /**
  37. * ipu_image_convert_cb_t - conversion callback function prototype
  38. *
  39. * @run: the completed conversion run pointer
  40. * @ctx: a private context pointer for the callback
  41. */
  42. typedef void (*ipu_image_convert_cb_t)(struct ipu_image_convert_run *run,
  43. void *ctx);
  44. /**
  45. * ipu_image_convert_enum_format() - enumerate the image converter's
  46. * supported input and output pixel formats.
  47. *
  48. * @index: pixel format index
  49. * @fourcc: v4l2 fourcc for this index
  50. *
  51. * Returns 0 with a valid index and fills in v4l2 fourcc, -EINVAL otherwise.
  52. *
  53. * In V4L2, drivers can call ipu_image_enum_format() in .enum_fmt.
  54. */
  55. int ipu_image_convert_enum_format(int index, u32 *fourcc);
  56. /**
  57. * ipu_image_convert_adjust() - adjust input/output images to IPU restrictions.
  58. *
  59. * @in: input image format, adjusted on return
  60. * @out: output image format, adjusted on return
  61. * @rot_mode: rotation mode
  62. *
  63. * In V4L2, drivers can call ipu_image_convert_adjust() in .try_fmt.
  64. */
  65. void ipu_image_convert_adjust(struct ipu_image *in, struct ipu_image *out,
  66. enum ipu_rotate_mode rot_mode);
  67. /**
  68. * ipu_image_convert_verify() - verify that input/output image formats
  69. * and rotation mode meet IPU restrictions.
  70. *
  71. * @in: input image format
  72. * @out: output image format
  73. * @rot_mode: rotation mode
  74. *
  75. * Returns 0 if the formats and rotation mode meet IPU restrictions,
  76. * -EINVAL otherwise.
  77. */
  78. int ipu_image_convert_verify(struct ipu_image *in, struct ipu_image *out,
  79. enum ipu_rotate_mode rot_mode);
  80. /**
  81. * ipu_image_convert_prepare() - prepare a conversion context.
  82. *
  83. * @ipu: the IPU handle to use for the conversions
  84. * @ic_task: the IC task to use for the conversions
  85. * @in: input image format
  86. * @out: output image format
  87. * @rot_mode: rotation mode
  88. * @complete: run completion callback
  89. * @complete_context: a context pointer for the completion callback
  90. *
  91. * Returns an opaque conversion context pointer on success, error pointer
  92. * on failure. The input/output formats and rotation mode must already meet
  93. * IPU retrictions.
  94. *
  95. * In V4L2, drivers should call ipu_image_convert_prepare() at streamon.
  96. */
  97. struct ipu_image_convert_ctx *
  98. ipu_image_convert_prepare(struct ipu_soc *ipu, enum ipu_ic_task ic_task,
  99. struct ipu_image *in, struct ipu_image *out,
  100. enum ipu_rotate_mode rot_mode,
  101. ipu_image_convert_cb_t complete,
  102. void *complete_context);
  103. /**
  104. * ipu_image_convert_unprepare() - unprepare a conversion context.
  105. *
  106. * @ctx: the conversion context pointer to unprepare
  107. *
  108. * Aborts any active or pending conversions for this context and
  109. * frees the context. Any currently active or pending runs belonging
  110. * to this context are returned via the completion callback with an
  111. * error run status.
  112. *
  113. * In V4L2, drivers should call ipu_image_convert_unprepare() at
  114. * streamoff.
  115. */
  116. void ipu_image_convert_unprepare(struct ipu_image_convert_ctx *ctx);
  117. /**
  118. * ipu_image_convert_queue() - queue a conversion run
  119. *
  120. * @run: the run request pointer
  121. *
  122. * ipu_image_convert_run must be dynamically allocated (_not_ as a local
  123. * var) by callers and filled in with a previously prepared conversion
  124. * context handle and the dma addr's of the input and output image buffers
  125. * for this conversion run.
  126. *
  127. * When this conversion completes, the run pointer is returned via the
  128. * completion callback. The caller is responsible for freeing the run
  129. * object after it completes.
  130. *
  131. * In V4L2, drivers should call ipu_image_convert_queue() while
  132. * streaming to queue the conversion of a received input buffer.
  133. * For example mem2mem devices this would be called in .device_run.
  134. */
  135. int ipu_image_convert_queue(struct ipu_image_convert_run *run);
  136. /**
  137. * ipu_image_convert_abort() - abort conversions
  138. *
  139. * @ctx: the conversion context pointer
  140. *
  141. * This will abort any active or pending conversions for this context.
  142. * Any currently active or pending runs belonging to this context are
  143. * returned via the completion callback with an error run status.
  144. */
  145. void ipu_image_convert_abort(struct ipu_image_convert_ctx *ctx);
  146. /**
  147. * ipu_image_convert() - asynchronous image conversion request
  148. *
  149. * @ipu: the IPU handle to use for the conversion
  150. * @ic_task: the IC task to use for the conversion
  151. * @in: input image format
  152. * @out: output image format
  153. * @rot_mode: rotation mode
  154. * @complete: run completion callback
  155. * @complete_context: a context pointer for the completion callback
  156. *
  157. * Request a single image conversion. Returns the run that has been queued.
  158. * A conversion context is automatically created and is available in run->ctx.
  159. * As with ipu_image_convert_prepare(), the input/output formats and rotation
  160. * mode must already meet IPU retrictions.
  161. *
  162. * On successful return the caller can queue more run requests if needed, using
  163. * the prepared context in run->ctx. The caller is responsible for unpreparing
  164. * the context when no more conversion requests are needed.
  165. */
  166. struct ipu_image_convert_run *
  167. ipu_image_convert(struct ipu_soc *ipu, enum ipu_ic_task ic_task,
  168. struct ipu_image *in, struct ipu_image *out,
  169. enum ipu_rotate_mode rot_mode,
  170. ipu_image_convert_cb_t complete,
  171. void *complete_context);
  172. /**
  173. * ipu_image_convert_sync() - synchronous single image conversion request
  174. *
  175. * @ipu: the IPU handle to use for the conversion
  176. * @ic_task: the IC task to use for the conversion
  177. * @in: input image format
  178. * @out: output image format
  179. * @rot_mode: rotation mode
  180. *
  181. * Carry out a single image conversion. Returns when the conversion
  182. * completes. The input/output formats and rotation mode must already
  183. * meet IPU retrictions. The created context is automatically unprepared
  184. * and the run freed on return.
  185. */
  186. int ipu_image_convert_sync(struct ipu_soc *ipu, enum ipu_ic_task ic_task,
  187. struct ipu_image *in, struct ipu_image *out,
  188. enum ipu_rotate_mode rot_mode);
  189. #endif /* __IMX_IPU_IMAGE_CONVERT_H__ */