vsp1.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * vsp1.h -- R-Car VSP1 API
  4. *
  5. * Copyright (C) 2015 Renesas Electronics Corporation
  6. *
  7. * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  8. */
  9. #ifndef __MEDIA_VSP1_H__
  10. #define __MEDIA_VSP1_H__
  11. #include <linux/scatterlist.h>
  12. #include <linux/types.h>
  13. #include <linux/videodev2.h>
  14. struct device;
  15. struct vsp1_dl_list;
  16. /* -----------------------------------------------------------------------------
  17. * VSP1 DU interface
  18. */
  19. int vsp1_du_init(struct device *dev);
  20. #define VSP1_DU_STATUS_COMPLETE BIT(0)
  21. #define VSP1_DU_STATUS_WRITEBACK BIT(1)
  22. /**
  23. * struct vsp1_du_lif_config - VSP LIF configuration
  24. * @width: output frame width
  25. * @height: output frame height
  26. * @interlaced: true for interlaced pipelines
  27. * @callback: frame completion callback function (optional). When a callback
  28. * is provided, the VSP driver guarantees that it will be called once
  29. * and only once for each vsp1_du_atomic_flush() call.
  30. * @callback_data: data to be passed to the frame completion callback
  31. */
  32. struct vsp1_du_lif_config {
  33. unsigned int width;
  34. unsigned int height;
  35. bool interlaced;
  36. void (*callback)(void *data, unsigned int status, u32 crc);
  37. void *callback_data;
  38. };
  39. int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,
  40. const struct vsp1_du_lif_config *cfg);
  41. /**
  42. * struct vsp1_du_atomic_config - VSP atomic configuration parameters
  43. * @pixelformat: plane pixel format (V4L2 4CC)
  44. * @pitch: line pitch in bytes for the first plane
  45. * @mem: DMA memory address for each plane of the frame buffer
  46. * @src: source rectangle in the frame buffer (integer coordinates)
  47. * @dst: destination rectangle on the display (integer coordinates)
  48. * @alpha: alpha value (0: fully transparent, 255: fully opaque)
  49. * @zpos: Z position of the plane (from 0 to number of planes minus 1)
  50. * @premult: true for premultiplied alpha
  51. * @color_encoding: color encoding (valid for YUV formats only)
  52. * @color_range: color range (valid for YUV formats only)
  53. */
  54. struct vsp1_du_atomic_config {
  55. u32 pixelformat;
  56. unsigned int pitch;
  57. dma_addr_t mem[3];
  58. struct v4l2_rect src;
  59. struct v4l2_rect dst;
  60. unsigned int alpha;
  61. unsigned int zpos;
  62. bool premult;
  63. enum v4l2_ycbcr_encoding color_encoding;
  64. enum v4l2_quantization color_range;
  65. };
  66. /**
  67. * enum vsp1_du_crc_source - Source used for CRC calculation
  68. * @VSP1_DU_CRC_NONE: CRC calculation disabled
  69. * @VSP1_DU_CRC_PLANE: Perform CRC calculation on an input plane
  70. * @VSP1_DU_CRC_OUTPUT: Perform CRC calculation on the composed output
  71. */
  72. enum vsp1_du_crc_source {
  73. VSP1_DU_CRC_NONE,
  74. VSP1_DU_CRC_PLANE,
  75. VSP1_DU_CRC_OUTPUT,
  76. };
  77. /**
  78. * struct vsp1_du_crc_config - VSP CRC computation configuration parameters
  79. * @source: source for CRC calculation
  80. * @index: index of the CRC source plane (when source is set to plane)
  81. */
  82. struct vsp1_du_crc_config {
  83. enum vsp1_du_crc_source source;
  84. unsigned int index;
  85. };
  86. /**
  87. * struct vsp1_du_writeback_config - VSP writeback configuration parameters
  88. * @pixelformat: plane pixel format (V4L2 4CC)
  89. * @pitch: line pitch in bytes for the first plane
  90. * @mem: DMA memory address for each plane of the frame buffer
  91. */
  92. struct vsp1_du_writeback_config {
  93. u32 pixelformat;
  94. unsigned int pitch;
  95. dma_addr_t mem[3];
  96. };
  97. /**
  98. * struct vsp1_du_atomic_pipe_config - VSP atomic pipe configuration parameters
  99. * @crc: CRC computation configuration
  100. * @writeback: writeback configuration
  101. */
  102. struct vsp1_du_atomic_pipe_config {
  103. struct vsp1_du_crc_config crc;
  104. struct vsp1_du_writeback_config writeback;
  105. };
  106. void vsp1_du_atomic_begin(struct device *dev, unsigned int pipe_index);
  107. int vsp1_du_atomic_update(struct device *dev, unsigned int pipe_index,
  108. unsigned int rpf,
  109. const struct vsp1_du_atomic_config *cfg);
  110. void vsp1_du_atomic_flush(struct device *dev, unsigned int pipe_index,
  111. const struct vsp1_du_atomic_pipe_config *cfg);
  112. int vsp1_du_map_sg(struct device *dev, struct sg_table *sgt);
  113. void vsp1_du_unmap_sg(struct device *dev, struct sg_table *sgt);
  114. /* -----------------------------------------------------------------------------
  115. * VSP1 ISP interface
  116. */
  117. /**
  118. * struct vsp1_isp_buffer_desc - Describe a buffer allocated by VSPX
  119. * @size: Byte size of the buffer allocated by VSPX
  120. * @cpu_addr: CPU-mapped address of a buffer allocated by VSPX
  121. * @dma_addr: bus address of a buffer allocated by VSPX
  122. */
  123. struct vsp1_isp_buffer_desc {
  124. size_t size;
  125. void *cpu_addr;
  126. dma_addr_t dma_addr;
  127. };
  128. /**
  129. * struct vsp1_isp_job_desc - Describe a VSPX buffer transfer request
  130. * @config: ConfigDMA buffer descriptor
  131. * @config.pairs: number of reg-value pairs in the ConfigDMA buffer
  132. * @config.mem: bus address of the ConfigDMA buffer
  133. * @img: RAW image buffer descriptor
  134. * @img.fmt: RAW image format
  135. * @img.mem: bus address of the RAW image buffer
  136. * @dl: pointer to the display list populated by the VSPX driver in the
  137. * vsp1_isp_job_prepare() function
  138. *
  139. * Describe a transfer request for the VSPX to perform on behalf of the ISP.
  140. * The job descriptor contains an optional ConfigDMA buffer and one RAW image
  141. * buffer. Set config.pairs to 0 if no ConfigDMA buffer should be transferred.
  142. * The minimum number of config.pairs that can be written using ConfigDMA is 17.
  143. * A number of pairs < 16 corrupts the output image. A number of pairs == 16
  144. * freezes the VSPX operation. If the ISP driver has to write less than 17 pairs
  145. * it shall pad the buffer with writes directed to registers that have no effect
  146. * or avoid using ConfigDMA at all for such small write sequences.
  147. *
  148. * The ISP driver shall pass an instance this type to the vsp1_isp_job_prepare()
  149. * function that will populate the display list pointer @dl using the @config
  150. * and @img descriptors. When the job has to be run on the VSPX, the descriptor
  151. * shall be passed to vsp1_isp_job_run() which consumes the display list.
  152. *
  153. * Job descriptors not yet run shall be released with a call to
  154. * vsp1_isp_job_release() when stopping the streaming in order to properly
  155. * release the resources acquired by vsp1_isp_job_prepare().
  156. */
  157. struct vsp1_isp_job_desc {
  158. struct {
  159. unsigned int pairs;
  160. dma_addr_t mem;
  161. } config;
  162. struct {
  163. struct v4l2_pix_format_mplane fmt;
  164. dma_addr_t mem;
  165. } img;
  166. struct vsp1_dl_list *dl;
  167. };
  168. /**
  169. * struct vsp1_vspx_frame_end - VSPX frame end callback data
  170. * @vspx_frame_end: Frame end callback. Called after a transfer job has been
  171. * completed. If the job includes both a ConfigDMA and a
  172. * RAW image, the callback is called after both have been
  173. * transferred
  174. * @frame_end_data: Frame end callback data, passed to vspx_frame_end
  175. */
  176. struct vsp1_vspx_frame_end {
  177. void (*vspx_frame_end)(void *data);
  178. void *frame_end_data;
  179. };
  180. int vsp1_isp_init(struct device *dev);
  181. struct device *vsp1_isp_get_bus_master(struct device *dev);
  182. int vsp1_isp_alloc_buffer(struct device *dev, size_t size,
  183. struct vsp1_isp_buffer_desc *buffer_desc);
  184. void vsp1_isp_free_buffer(struct device *dev,
  185. struct vsp1_isp_buffer_desc *buffer_desc);
  186. int vsp1_isp_start_streaming(struct device *dev,
  187. struct vsp1_vspx_frame_end *frame_end);
  188. void vsp1_isp_stop_streaming(struct device *dev);
  189. int vsp1_isp_job_prepare(struct device *dev,
  190. struct vsp1_isp_job_desc *job);
  191. int vsp1_isp_job_run(struct device *dev, struct vsp1_isp_job_desc *job);
  192. void vsp1_isp_job_release(struct device *dev, struct vsp1_isp_job_desc *job);
  193. #endif /* __MEDIA_VSP1_H__ */