1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Support for Intel Camera Imaging ISP subsystem. 4 * Copyright (c) 2015, Intel Corporation. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms and conditions of the GNU General Public License, 8 * version 2, as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 */ 15 16 #ifndef __IA_CSS_PIPE_PUBLIC_H 17 #define __IA_CSS_PIPE_PUBLIC_H 18 19 /* @file 20 * This file contains the public interface for CSS pipes. 21 */ 22 23 #include <type_support.h> 24 #include <ia_css_err.h> 25 #include <ia_css_types.h> 26 #include <ia_css_frame_public.h> 27 #include <ia_css_buffer.h> 28 /* ISP2401 */ 29 #include <ia_css_acc_types.h> 30 31 enum { 32 IA_CSS_PIPE_OUTPUT_STAGE_0 = 0, 33 IA_CSS_PIPE_OUTPUT_STAGE_1, 34 IA_CSS_PIPE_MAX_OUTPUT_STAGE, 35 }; 36 37 /* Enumeration of pipe modes. This mode can be used to create 38 * an image pipe for this mode. These pipes can be combined 39 * to configure and run streams on the ISP. 40 * 41 * For example, one can create a preview and capture pipe to 42 * create a continuous capture stream. 43 */ 44 enum ia_css_pipe_mode { 45 IA_CSS_PIPE_MODE_PREVIEW, /** Preview pipe */ 46 IA_CSS_PIPE_MODE_VIDEO, /** Video pipe */ 47 IA_CSS_PIPE_MODE_CAPTURE, /** Still capture pipe */ 48 IA_CSS_PIPE_MODE_COPY, /** Copy pipe, only used for embedded/image data copying */ 49 IA_CSS_PIPE_MODE_YUVPP, /** YUV post processing pipe, used for all use cases with YUV input, 50 for SoC sensor and external ISP */ 51 }; 52 53 /* Temporary define */ 54 #define IA_CSS_PIPE_MODE_NUM (IA_CSS_PIPE_MODE_YUVPP + 1) 55 56 /** 57 * Enumeration of pipe versions. 58 * the order should match with definition in sh_css_defs.h 59 */ 60 enum ia_css_pipe_version { 61 IA_CSS_PIPE_VERSION_1 = 1, /** ISP1.0 pipe */ 62 IA_CSS_PIPE_VERSION_2_2 = 2, /** ISP2.2 pipe */ 63 IA_CSS_PIPE_VERSION_2_6_1 = 3, /** ISP2.6.1 pipe */ 64 IA_CSS_PIPE_VERSION_2_7 = 4 /** ISP2.7 pipe */ 65 }; 66 67 /** 68 * Pipe configuration structure. 69 * Resolution properties are filled by Driver, kernel configurations are 70 * set by AIC 71 */ 72 struct ia_css_pipe_config { 73 enum ia_css_pipe_mode mode; 74 /** mode, indicates which mode the pipe should use. */ 75 enum ia_css_pipe_version isp_pipe_version; 76 /** pipe version, indicates which imaging pipeline the pipe should use. */ 77 struct ia_css_resolution input_effective_res; 78 /** input effective resolution */ 79 struct ia_css_resolution bayer_ds_out_res; 80 /** bayer down scaling */ 81 struct ia_css_resolution capt_pp_in_res; 82 /** capture post processing input resolution */ 83 struct ia_css_resolution vf_pp_in_res; 84 85 /** ISP2401: view finder post processing input resolution */ 86 struct ia_css_resolution output_system_in_res; 87 /** For IPU3 only: use output_system_in_res to specify what input resolution 88 will OSYS receive, this resolution is equal to the output resolution of GDC 89 if not determined CSS will set output_system_in_res with main osys output pin resolution 90 All other IPUs may ignore this property */ 91 struct ia_css_resolution dvs_crop_out_res; 92 /** dvs crop, video only, not in use yet. Use dvs_envelope below. */ 93 struct ia_css_frame_info output_info[IA_CSS_PIPE_MAX_OUTPUT_STAGE]; 94 /** output of YUV scaling */ 95 struct ia_css_frame_info vf_output_info[IA_CSS_PIPE_MAX_OUTPUT_STAGE]; 96 /** output of VF YUV scaling */ 97 struct ia_css_capture_config default_capture_config; 98 /** Default capture config for initial capture pipe configuration. */ 99 struct ia_css_resolution dvs_envelope; /** temporary */ 100 enum ia_css_frame_delay dvs_frame_delay; 101 /** indicates the DVS loop delay in frame periods */ 102 bool enable_dz; 103 /** Disabling digital zoom for a pipeline, if this is set to false, 104 then setting a zoom factor will have no effect. 105 In some use cases this provides better performance. */ 106 bool enable_dpc; 107 /** Disabling "Defect Pixel Correction" for a pipeline, if this is set 108 to false. In some use cases this provides better performance. */ 109 bool enable_vfpp_bci; 110 /** Enabling BCI mode will cause yuv_scale binary to be picked up 111 instead of vf_pp. This only applies to viewfinder post 112 processing stages. */ 113 114 /* ISP2401 */ 115 bool enable_tnr; 116 /** Enabling of TNR (temporal noise reduction). This is only applicable to video 117 pipes. Non video-pipes should always set this parameter to false. */ 118 119 struct ia_css_isp_config *p_isp_config; 120 /** Pointer to ISP configuration */ 121 struct ia_css_resolution gdc_in_buffer_res; 122 /** GDC in buffer resolution. */ 123 struct ia_css_point gdc_in_buffer_offset; 124 /** GDC in buffer offset - indicates the pixel coordinates of the first valid pixel inside the buffer */ 125 126 /* ISP2401 */ 127 struct ia_css_coordinate internal_frame_origin_bqs_on_sctbl; 128 /** Origin of internal frame positioned on shading table at shading correction in ISP. 129 NOTE: Shading table is larger than or equal to internal frame. 130 Shading table has shading gains and internal frame has bayer data. 131 The origin of internal frame is used in shading correction in ISP 132 to retrieve shading gains which correspond to bayer data. */ 133 }; 134 135 /** 136 * Default settings for newly created pipe configurations. 137 */ 138 #define DEFAULT_PIPE_CONFIG { \ 139 .mode = IA_CSS_PIPE_MODE_PREVIEW, \ 140 .isp_pipe_version = 1, \ 141 .output_info = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \ 142 .vf_output_info = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \ 143 .default_capture_config = DEFAULT_CAPTURE_CONFIG, \ 144 .dvs_frame_delay = IA_CSS_FRAME_DELAY_1, \ 145 } 146 147 /* Pipe info, this struct describes properties of a pipe after it's stream has 148 * been created. 149 * ~~~** DO NOT ADD NEW FIELD **~~~ This structure will be deprecated. 150 * - On the Behalf of CSS-API Committee. 151 */ 152 struct ia_css_pipe_info { 153 struct ia_css_frame_info output_info[IA_CSS_PIPE_MAX_OUTPUT_STAGE]; 154 /** Info about output resolution. This contains the stride which 155 should be used for memory allocation. */ 156 struct ia_css_frame_info vf_output_info[IA_CSS_PIPE_MAX_OUTPUT_STAGE]; 157 /** Info about viewfinder output resolution (optional). This contains 158 the stride that should be used for memory allocation. */ 159 struct ia_css_frame_info raw_output_info; 160 /** Raw output resolution. This indicates the resolution of the 161 RAW bayer output for pipes that support this. Currently, only the 162 still capture pipes support this feature. When this resolution is 163 smaller than the input resolution, cropping will be performed by 164 the ISP. The first cropping that will be performed is on the upper 165 left corner where we crop 8 lines and 8 columns to remove the 166 pixels normally used to initialize the ISP filters. 167 This is why the raw output resolution should normally be set to 168 the input resolution - 8x8. */ 169 /* ISP2401 */ 170 struct ia_css_resolution output_system_in_res_info; 171 /** For IPU3 only. Info about output system in resolution which is considered 172 as gdc out resolution. */ 173 struct ia_css_shading_info shading_info; 174 /** After an image pipe is created, this field will contain the info 175 for the shading correction. */ 176 struct ia_css_grid_info grid_info; 177 /** After an image pipe is created, this field will contain the grid 178 info for 3A and DVS. */ 179 int num_invalid_frames; 180 /** The very first frames in a started stream do not contain valid data. 181 In this field, the CSS-firmware communicates to the host-driver how 182 many initial frames will contain invalid data; this allows the 183 host-driver to discard those initial invalid frames and start it's 184 output at the first valid frame. */ 185 }; 186 187 /** 188 * Defaults for ia_css_pipe_info structs. 189 */ 190 #define DEFAULT_PIPE_INFO {\ 191 .output_info = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \ 192 .vf_output_info = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \ 193 .raw_output_info = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \ 194 .shading_info = DEFAULT_SHADING_INFO, \ 195 .grid_info = DEFAULT_GRID_INFO, \ 196 } 197 198 /* @brief Load default pipe configuration 199 * @param[out] pipe_config The pipe configuration. 200 * @return None 201 * 202 * This function will load the default pipe configuration: 203 @code 204 struct ia_css_pipe_config def_config = { 205 IA_CSS_PIPE_MODE_PREVIEW, // mode 206 1, // isp_pipe_version 207 {0, 0}, // bayer_ds_out_res 208 {0, 0}, // capt_pp_in_res 209 {0, 0}, // vf_pp_in_res 210 {0, 0}, // dvs_crop_out_res 211 {{0, 0}, 0, 0, 0, 0}, // output_info 212 {{0, 0}, 0, 0, 0, 0}, // second_output_info 213 {{0, 0}, 0, 0, 0, 0}, // vf_output_info 214 {{0, 0}, 0, 0, 0, 0}, // second_vf_output_info 215 { 216 IA_CSS_CAPTURE_MODE_RAW, // mode 217 false, // enable_xnr 218 false // enable_raw_output 219 }, // default_capture_config 220 {0, 0}, // dvs_envelope 221 1, // dvs_frame_delay 222 true, // enable_dz 223 NULL, // p_isp_config 224 }; 225 @endcode 226 */ 227 void ia_css_pipe_config_defaults(struct ia_css_pipe_config *pipe_config); 228 229 /* @brief Create a pipe 230 * @param[in] config The pipe configuration. 231 * @param[out] pipe The pipe. 232 * @return 0 or the error code. 233 * 234 * This function will create a pipe with the given 235 * configuration. 236 */ 237 int 238 ia_css_pipe_create(const struct ia_css_pipe_config *config, 239 struct ia_css_pipe **pipe); 240 241 /* @brief Destroy a pipe 242 * @param[in] pipe The pipe. 243 * @return 0 or the error code. 244 * 245 * This function will destroy a given pipe. 246 */ 247 int 248 ia_css_pipe_destroy(struct ia_css_pipe *pipe); 249 250 /* @brief Provides information about a pipe 251 * @param[in] pipe The pipe. 252 * @param[out] pipe_info The pipe information. 253 * @return 0 or -EINVAL. 254 * 255 * This function will provide information about a given pipe. 256 */ 257 int 258 ia_css_pipe_get_info(const struct ia_css_pipe *pipe, 259 struct ia_css_pipe_info *pipe_info); 260 261 /* @brief Configure a pipe with filter coefficients. 262 * @param[in] pipe The pipe. 263 * @param[in] config The pointer to ISP configuration. 264 * @return 0 or error code upon error. 265 * 266 * This function configures the filter coefficients for an image 267 * pipe. 268 */ 269 int 270 ia_css_pipe_set_isp_config(struct ia_css_pipe *pipe, 271 struct ia_css_isp_config *config); 272 273 /* @brief Controls when the Event generator raises an IRQ to the Host. 274 * 275 * @param[in] pipe The pipe. 276 * @param[in] or_mask Binary or of enum ia_css_event_irq_mask_type. Each pipe 277 related event that is part of this mask will directly 278 raise an IRQ to the Host when the event occurs in the 279 CSS. 280 * @param[in] and_mask Binary or of enum ia_css_event_irq_mask_type. An event 281 IRQ for the Host is only raised after all pipe related 282 events have occurred at least once for all the active 283 pipes. Events are remembered and don't need to occurred 284 at the same moment in time. There is no control over 285 the order of these events. Once an IRQ has been raised 286 all remembered events are reset. 287 * @return 0. 288 * 289 Controls when the Event generator in the CSS raises an IRQ to the Host. 290 The main purpose of this function is to reduce the amount of interrupts 291 between the CSS and the Host. This will help saving power as it wakes up the 292 Host less often. In case both or_mask and and_mask are 293 IA_CSS_EVENT_TYPE_NONE for all pipes, no event IRQ's will be raised. An 294 exception holds for IA_CSS_EVENT_TYPE_PORT_EOF, for this event an IRQ is always 295 raised. 296 Note that events are still queued and the Host can poll for them. The 297 or_mask and and_mask may be active at the same time\n 298 \n 299 Default values, for all pipe id's, after ia_css_init:\n 300 or_mask = IA_CSS_EVENT_TYPE_ALL\n 301 and_mask = IA_CSS_EVENT_TYPE_NONE\n 302 \n 303 Examples\n 304 \code 305 ia_css_pipe_set_irq_mask(h_pipe, 306 IA_CSS_EVENT_TYPE_3A_STATISTICS_DONE | 307 IA_CSS_EVENT_TYPE_DIS_STATISTICS_DONE , 308 IA_CSS_EVENT_TYPE_NONE); 309 \endcode 310 The event generator will only raise an interrupt to the Host when there are 311 3A or DIS statistics available from the preview pipe. It will not generate 312 an interrupt for any other event of the preview pipe e.g when there is an 313 output frame available. 314 315 \code 316 ia_css_pipe_set_irq_mask(h_pipe_preview, 317 IA_CSS_EVENT_TYPE_NONE, 318 IA_CSS_EVENT_TYPE_OUTPUT_FRAME_DONE | 319 IA_CSS_EVENT_TYPE_3A_STATISTICS_DONE ); 320 321 ia_css_pipe_set_irq_mask(h_pipe_capture, 322 IA_CSS_EVENT_TYPE_NONE, 323 IA_CSS_EVENT_TYPE_OUTPUT_FRAME_DONE ); 324 \endcode 325 The event generator will only raise an interrupt to the Host when there is 326 both a frame done and 3A event available from the preview pipe AND when there 327 is a frame done available from the capture pipe. Note that these events 328 may occur at different moments in time. Also the order of the events is not 329 relevant. 330 331 \code 332 ia_css_pipe_set_irq_mask(h_pipe_preview, 333 IA_CSS_EVENT_TYPE_OUTPUT_FRAME_DONE, 334 IA_CSS_EVENT_TYPE_ALL ); 335 336 ia_css_pipe_set_irq_mask(h_pipe_capture, 337 IA_CSS_EVENT_TYPE_OUTPUT_FRAME_DONE, 338 IA_CSS_EVENT_TYPE_ALL ); 339 \endcode 340 The event generator will only raise an interrupt to the Host when there is an 341 output frame from the preview pipe OR an output frame from the capture pipe. 342 All other events (3A, VF output, pipeline done) will not raise an interrupt 343 to the Host. These events are not lost but always stored in the event queue. 344 */ 345 int 346 ia_css_pipe_set_irq_mask(struct ia_css_pipe *pipe, 347 unsigned int or_mask, 348 unsigned int and_mask); 349 350 /* @brief Reads the current event IRQ mask from the CSS. 351 * 352 * @param[in] pipe The pipe. 353 * @param[out] or_mask Current or_mask. The bits in this mask are a binary or 354 of enum ia_css_event_irq_mask_type. Pointer may be NULL. 355 * @param[out] and_mask Current and_mask.The bits in this mask are a binary or 356 of enum ia_css_event_irq_mask_type. Pointer may be NULL. 357 * @return 0. 358 * 359 Reads the current event IRQ mask from the CSS. Reading returns the actual 360 values as used by the SP and not any mirrored values stored at the Host.\n 361 \n 362 Precondition:\n 363 SP must be running.\n 364 365 */ 366 int 367 ia_css_event_get_irq_mask(const struct ia_css_pipe *pipe, 368 unsigned int *or_mask, 369 unsigned int *and_mask); 370 371 /* @brief Queue a buffer for an image pipe. 372 * 373 * @param[in] pipe The pipe that will own the buffer. 374 * @param[in] buffer Pointer to the buffer. 375 * Note that the caller remains owner of the buffer 376 * structure. Only the data pointer within it will 377 * be passed into the internal queues. 378 * @return IA_CSS_INTERNAL_ERROR in case of unexpected errors, 379 * 0 otherwise. 380 * 381 * This function adds a buffer (which has a certain buffer type) to the queue 382 * for this type. This queue is owned by the image pipe. After this function 383 * completes successfully, the buffer is now owned by the image pipe and should 384 * no longer be accessed by any other code until it gets dequeued. The image 385 * pipe will dequeue buffers from this queue, use them and return them to the 386 * host code via an interrupt. Buffers will be consumed in the same order they 387 * get queued, but may be returned to the host out of order. 388 */ 389 int 390 ia_css_pipe_enqueue_buffer(struct ia_css_pipe *pipe, 391 const struct ia_css_buffer *buffer); 392 393 /* @brief Dequeue a buffer from an image pipe. 394 * 395 * @param[in] pipe The pipeline that the buffer queue belongs to. 396 * @param[in,out] buffer The buffer is used to lookup the type which determines 397 * which internal queue to use. 398 * The resulting buffer pointer is written into the dta 399 * field. 400 * @return IA_CSS_ERR_NO_BUFFER if the queue is empty or 401 * 0 otherwise. 402 * 403 * This function dequeues a buffer from a buffer queue. The queue is indicated 404 * by the buffer type argument. This function can be called after an interrupt 405 * has been generated that signalled that a new buffer was available and can 406 * be used in a polling-like situation where the NO_BUFFER return value is used 407 * to determine whether a buffer was available or not. 408 */ 409 int 410 ia_css_pipe_dequeue_buffer(struct ia_css_pipe *pipe, 411 struct ia_css_buffer *buffer); 412 413 /* @brief Get selected configuration settings 414 * @param[in] pipe The pipe. 415 * @param[out] config Configuration settings. 416 * @return None 417 */ 418 void 419 ia_css_pipe_get_isp_config(struct ia_css_pipe *pipe, 420 struct ia_css_isp_config *config); 421 422 /* @brief Set the scaler lut on this pipe. A copy of lut is made in the inuit 423 * address space. So the LUT can be freed by caller. 424 * @param[in] pipe Pipe handle. 425 * @param[in] lut Look up tabel 426 * 427 * @return 428 * 0 : Success 429 * -EINVAL : Invalid Parameters 430 * 431 * Note: 432 * 1) Note that both GDC's are programmed with the same table. 433 * 2) Current implementation ignores the pipe and overrides the 434 * global lut. This will be fixed in the future 435 * 3) This function must be called before stream start 436 * 437 */ 438 int 439 ia_css_pipe_set_bci_scaler_lut(struct ia_css_pipe *pipe, 440 const void *lut); 441 /* @brief Checking of DVS statistics ability 442 * @param[in] pipe_info The pipe info. 443 * @return true - has DVS statistics ability 444 * false - otherwise 445 */ 446 bool ia_css_pipe_has_dvs_stats(struct ia_css_pipe_info *pipe_info); 447 448 /* ISP2401 */ 449 /* @brief Override the frameformat set on the output pins. 450 * @param[in] pipe Pipe handle. 451 * @param[in] output_pin Pin index to set the format on 452 * 0 - main output pin 453 * 1 - display output pin 454 * @param[in] format Format to set 455 * 456 * @return 457 * 0 : Success 458 * -EINVAL : Invalid Parameters 459 * -EINVAL : Pipe misses binary info 460 * 461 * Note: 462 * 1) This is an optional function to override the formats set in the pipe. 463 * 2) Only overriding with IA_CSS_FRAME_FORMAT_NV12_TILEY is currently allowed. 464 * 3) This function is only to be used on pipes that use the output system. 465 * 4) If this function is used, it MUST be called after ia_css_pipe_create. 466 * 5) If this function is used, this function MUST be called before ia_css_stream_start. 467 */ 468 int 469 ia_css_pipe_override_frame_format(struct ia_css_pipe *pipe, 470 int output_pin, 471 enum ia_css_frame_format format); 472 473 #endif /* __IA_CSS_PIPE_PUBLIC_H */ 474