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