GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / camera / pipe / src / pipe_binarydesc.c
1 /*
2  * Support for Intel Camera Imaging ISP subsystem.
3  * Copyright (c) 2015, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  */
14
15 #include "ia_css_pipe_binarydesc.h"
16 #include "ia_css_frame_format.h"
17 #include "ia_css_pipe.h"
18 #include "ia_css_pipe_util.h"
19 #include "ia_css_util.h"
20 #include "ia_css_debug.h"
21 #include "sh_css_params.h"
22 #include <assert_support.h>
23 /* HRT_GDC_N */
24 #include "gdc_device.h"
25
26 /* This module provides a binary descriptions to used to find a binary. Since,
27  * every stage is associated with a binary, it implicity helps stage
28  * description. Apart from providing a binary description, this module also
29  * populates the frame info's when required.*/
30
31 /* Generic descriptor for offline binaries. Internal function. */
32 static void pipe_binarydesc_get_offline(
33         struct ia_css_pipe const * const pipe,
34         const int mode,
35         struct ia_css_binary_descr *descr,
36         struct ia_css_frame_info *in_info,
37         struct ia_css_frame_info *out_info[],
38         struct ia_css_frame_info *vf_info)
39 {
40         unsigned int i;
41         /* in_info, out_info, vf_info can be NULL */
42         assert(pipe != NULL);
43         assert(descr != NULL);
44         ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
45                             "pipe_binarydesc_get_offline() enter:\n");
46
47         descr->mode = mode;
48         descr->online = false;
49         descr->continuous = pipe->stream->config.continuous;
50         descr->striped = false;
51         descr->two_ppc = false;
52         descr->enable_yuv_ds = false;
53         descr->enable_high_speed = false;
54         descr->enable_dvs_6axis = false;
55         descr->enable_reduced_pipe = false;
56         descr->enable_dz = true;
57         descr->enable_xnr = false;
58         descr->enable_dpc = false;
59 #ifdef ISP2401
60         descr->enable_luma_only = false;
61         descr->enable_tnr = false;
62 #endif
63         descr->enable_capture_pp_bli = false;
64         descr->enable_fractional_ds = false;
65         descr->dvs_env.width = 0;
66         descr->dvs_env.height = 0;
67         descr->stream_format = pipe->stream->config.input_config.format;
68         descr->in_info = in_info;
69         descr->bds_out_info = NULL;
70         for (i = 0; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
71                 descr->out_info[i] = out_info[i];
72         descr->vf_info = vf_info;
73         descr->isp_pipe_version = pipe->config.isp_pipe_version;
74         descr->required_bds_factor = SH_CSS_BDS_FACTOR_1_00;
75         descr->stream_config_left_padding = -1;
76 }
77
78 void ia_css_pipe_get_copy_binarydesc(
79         struct ia_css_pipe const * const pipe,
80         struct ia_css_binary_descr *copy_descr,
81         struct ia_css_frame_info *in_info,
82         struct ia_css_frame_info *out_info,
83         struct ia_css_frame_info *vf_info)
84 {
85         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
86         unsigned int i;
87         /* out_info can be NULL */
88         assert(pipe != NULL);
89         assert(in_info != NULL);
90         IA_CSS_ENTER_PRIVATE("");
91
92         *in_info = *out_info;
93         out_infos[0] = out_info;
94         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
95                 out_infos[i] = NULL;
96         pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_COPY,
97                                     copy_descr, in_info, out_infos, vf_info);
98         copy_descr->online = true;
99         copy_descr->continuous = false;
100         copy_descr->two_ppc = (pipe->stream->config.pixels_per_clock == 2);
101         copy_descr->enable_dz = false;
102         copy_descr->isp_pipe_version = IA_CSS_PIPE_VERSION_1;
103         IA_CSS_LEAVE_PRIVATE("");
104 }
105 void ia_css_pipe_get_vfpp_binarydesc(
106         struct ia_css_pipe const * const pipe,
107         struct ia_css_binary_descr *vf_pp_descr,
108         struct ia_css_frame_info *in_info,
109         struct ia_css_frame_info *out_info)
110 {
111         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
112         unsigned int i;
113         /* out_info can be NULL ??? */
114         assert(pipe != NULL);
115         assert(in_info != NULL);
116         IA_CSS_ENTER_PRIVATE("");
117
118         in_info->raw_bit_depth = 0;
119         out_infos[0] = out_info;
120         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
121                 out_infos[i] = NULL;
122
123         pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_VF_PP,
124                                vf_pp_descr, in_info, out_infos, NULL);
125         vf_pp_descr->enable_fractional_ds = true;
126         IA_CSS_LEAVE_PRIVATE("");
127 }
128
129 static struct sh_css_bds_factor bds_factors_list[] = {
130         {1, 1, SH_CSS_BDS_FACTOR_1_00},
131         {5, 4, SH_CSS_BDS_FACTOR_1_25},
132         {3, 2, SH_CSS_BDS_FACTOR_1_50},
133         {2, 1, SH_CSS_BDS_FACTOR_2_00},
134         {9, 4, SH_CSS_BDS_FACTOR_2_25},
135         {5, 2, SH_CSS_BDS_FACTOR_2_50},
136         {3, 1, SH_CSS_BDS_FACTOR_3_00},
137         {4, 1, SH_CSS_BDS_FACTOR_4_00},
138         {9, 2, SH_CSS_BDS_FACTOR_4_50},
139         {5, 1, SH_CSS_BDS_FACTOR_5_00},
140         {6, 1, SH_CSS_BDS_FACTOR_6_00},
141         {8, 1, SH_CSS_BDS_FACTOR_8_00}
142 };
143
144 enum ia_css_err sh_css_bds_factor_get_numerator_denominator(
145         unsigned int bds_factor,
146         unsigned int *bds_factor_numerator,
147         unsigned int *bds_factor_denominator)
148 {
149         unsigned int i;
150         unsigned int bds_list_size = sizeof(bds_factors_list) /
151                                 sizeof(struct sh_css_bds_factor);
152
153         /* Loop over all bds factors until a match is found */
154         for (i = 0; i < bds_list_size; i++) {
155                 if (bds_factors_list[i].bds_factor == bds_factor) {
156                         *bds_factor_numerator = bds_factors_list[i].numerator;
157                         *bds_factor_denominator = bds_factors_list[i].denominator;
158                         return IA_CSS_SUCCESS;
159                 }
160         }
161
162         /* Throw an error since bds_factor cannot be found
163         in bds_factors_list */
164         return IA_CSS_ERR_INVALID_ARGUMENTS;
165 }
166
167 enum ia_css_err binarydesc_calculate_bds_factor(
168         struct ia_css_resolution input_res,
169         struct ia_css_resolution output_res,
170         unsigned int *bds_factor)
171 {
172         unsigned int i;
173         unsigned int bds_list_size = sizeof(bds_factors_list) /
174             sizeof(struct sh_css_bds_factor);
175         unsigned int in_w = input_res.width,
176             in_h = input_res.height,
177             out_w = output_res.width, out_h = output_res.height;
178
179         unsigned int max_bds_factor = 8;
180         unsigned int max_rounding_margin = 2;
181         /* delta in pixels to account for rounding margin in the calculation */
182         unsigned int delta = max_bds_factor * max_rounding_margin;
183
184         /* Assert if the resolutions are not set */
185         assert(in_w != 0 && in_h != 0);
186         assert(out_w != 0 && out_h != 0);
187
188         /* Loop over all bds factors until a match is found */
189         for (i = 0; i < bds_list_size; i++) {
190                 unsigned num = bds_factors_list[i].numerator;
191                 unsigned den = bds_factors_list[i].denominator;
192
193                 /* See width-wise and height-wise if this bds_factor
194                  * satisfies the condition */
195                 bool cond = (out_w * num / den + delta > in_w) &&
196                     (out_w * num / den <= in_w) &&
197                     (out_h * num / den + delta > in_h) &&
198                     (out_h * num / den <= in_h);
199
200                 if (cond) {
201                         *bds_factor = bds_factors_list[i].bds_factor;
202                         return IA_CSS_SUCCESS;
203                 }
204         }
205
206         /* Throw an error since a suitable bds_factor cannot be found */
207         return IA_CSS_ERR_INVALID_ARGUMENTS;
208 }
209
210 enum ia_css_err ia_css_pipe_get_preview_binarydesc(
211         struct ia_css_pipe * const pipe,
212         struct ia_css_binary_descr *preview_descr,
213         struct ia_css_frame_info *in_info,
214         struct ia_css_frame_info *bds_out_info,
215         struct ia_css_frame_info *out_info,
216         struct ia_css_frame_info *vf_info)
217 {
218         enum ia_css_err err;
219         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
220         int mode = IA_CSS_BINARY_MODE_PREVIEW;
221         unsigned int i;
222
223         assert(pipe != NULL);
224         assert(in_info != NULL);
225         assert(out_info != NULL);
226         assert(vf_info != NULL);
227         IA_CSS_ENTER_PRIVATE("");
228
229         /*
230          * Set up the info of the input frame with
231          * the ISP required resolution
232          */
233         in_info->res = pipe->config.input_effective_res;
234         in_info->padded_width = in_info->res.width;
235         in_info->raw_bit_depth = ia_css_pipe_util_pipe_input_format_bpp(pipe);
236
237         if (ia_css_util_is_input_format_yuv(pipe->stream->config.input_config.format))
238                 mode = IA_CSS_BINARY_MODE_COPY;
239         else
240                 in_info->format = IA_CSS_FRAME_FORMAT_RAW;
241
242         out_infos[0] = out_info;
243         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
244                 out_infos[i] = NULL;
245
246         pipe_binarydesc_get_offline(pipe, mode,
247                                preview_descr, in_info, out_infos, vf_info);
248         if (pipe->stream->config.online) {
249                 preview_descr->online = pipe->stream->config.online;
250                 preview_descr->two_ppc =
251                     (pipe->stream->config.pixels_per_clock == 2);
252         }
253         preview_descr->stream_format = pipe->stream->config.input_config.format;
254
255         /* TODO: Remove this when bds_out_info is available! */
256         *bds_out_info = *in_info;
257
258         if (pipe->extra_config.enable_raw_binning) {
259                 if (pipe->config.bayer_ds_out_res.width != 0 &&
260                     pipe->config.bayer_ds_out_res.height != 0) {
261                         bds_out_info->res.width =
262                             pipe->config.bayer_ds_out_res.width;
263                         bds_out_info->res.height =
264                             pipe->config.bayer_ds_out_res.height;
265                         bds_out_info->padded_width =
266                             pipe->config.bayer_ds_out_res.width;
267                         err =
268                             binarydesc_calculate_bds_factor(in_info->res,
269                                     bds_out_info->res,
270                                     &preview_descr->required_bds_factor);
271                         if (err != IA_CSS_SUCCESS)
272                                 return err;
273                 } else {
274                         bds_out_info->res.width = in_info->res.width / 2;
275                         bds_out_info->res.height = in_info->res.height / 2;
276                         bds_out_info->padded_width = in_info->padded_width / 2;
277                         preview_descr->required_bds_factor =
278                             SH_CSS_BDS_FACTOR_2_00;
279                 }
280         } else {
281                 /* TODO: Remove this when bds_out_info->is available! */
282                 bds_out_info->res.width = in_info->res.width;
283                 bds_out_info->res.height = in_info->res.height;
284                 bds_out_info->padded_width = in_info->padded_width;
285                 preview_descr->required_bds_factor = SH_CSS_BDS_FACTOR_1_00;
286         }
287         pipe->required_bds_factor = preview_descr->required_bds_factor;
288
289         /* bayer ds and fractional ds cannot be enabled at the same time,
290         so we disable bds_out_info when fractional ds is used */
291         if (!pipe->extra_config.enable_fractional_ds)
292                 preview_descr->bds_out_info = bds_out_info;
293         else
294                 preview_descr->bds_out_info = NULL;
295         /*
296            ----Preview binary-----
297            --in-->|--out->|vf_veceven|--|--->vf
298            -----------------------
299            * Preview binary normally doesn't have a vf_port but
300            * instead it has an output port. However, the output is
301            * generated by vf_veceven module in which we might have
302            * a downscaling (by 1x, 2x, or 4x). Because the resolution
303            * might change, we need two different info, namely out_info
304            * & vf_info. In fill_binary_info we use out&vf info to
305            * calculate vf decimation factor.
306          */
307         *out_info = *vf_info;
308
309         /* In case of preview_ds binary, we can do any fractional amount
310          * of downscale, so there is no DS needed in vf_veceven. Therefore,
311          * out and vf infos will be the same. Otherwise, we set out resolution
312          * equal to in resolution. */
313         if (!pipe->extra_config.enable_fractional_ds) {
314                 /* TODO: Change this when bds_out_info is available! */
315                 out_info->res.width = bds_out_info->res.width;
316                 out_info->res.height = bds_out_info->res.height;
317                 out_info->padded_width = bds_out_info->padded_width;
318         }
319         preview_descr->enable_fractional_ds =
320             pipe->extra_config.enable_fractional_ds;
321
322         preview_descr->enable_dpc = pipe->config.enable_dpc;
323
324         preview_descr->isp_pipe_version = pipe->config.isp_pipe_version;
325         IA_CSS_LEAVE_ERR_PRIVATE(IA_CSS_SUCCESS);
326         return IA_CSS_SUCCESS;
327 }
328
329 enum ia_css_err ia_css_pipe_get_video_binarydesc(
330         struct ia_css_pipe * const pipe,
331         struct ia_css_binary_descr *video_descr,
332         struct ia_css_frame_info *in_info,
333         struct ia_css_frame_info *bds_out_info,
334         struct ia_css_frame_info *out_info,
335         struct ia_css_frame_info *vf_info,
336         int stream_config_left_padding)
337 {
338         int mode = IA_CSS_BINARY_MODE_VIDEO;
339         unsigned int i;
340         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
341         enum ia_css_err err = IA_CSS_SUCCESS;
342         bool stream_dz_config = false;
343
344         /* vf_info can be NULL */
345         assert(pipe != NULL);
346         assert(in_info != NULL);
347         /* assert(vf_info != NULL); */
348         IA_CSS_ENTER_PRIVATE("");
349
350         /* The solution below is not optimal; we should move to using ia_css_pipe_get_copy_binarydesc()
351          * But for now this fixes things; this code used to be there but was removed
352          * with gerrit 8908 as this was wrong for Skycam; however 240x still needs this
353          */
354         if (ia_css_util_is_input_format_yuv(pipe->stream->config.input_config.format))
355                 mode = IA_CSS_BINARY_MODE_COPY;
356
357         in_info->res = pipe->config.input_effective_res;
358         in_info->padded_width = in_info->res.width;
359         in_info->format = IA_CSS_FRAME_FORMAT_RAW;
360         in_info->raw_bit_depth = ia_css_pipe_util_pipe_input_format_bpp(pipe);
361         out_infos[0] = out_info;
362         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
363                 out_infos[i] = NULL;
364
365         pipe_binarydesc_get_offline(pipe, mode,
366                video_descr, in_info, out_infos, vf_info);
367
368         if (pipe->stream->config.online) {
369                 video_descr->online = pipe->stream->config.online;
370                 video_descr->two_ppc =
371                     (pipe->stream->config.pixels_per_clock == 2);
372         }
373
374         if (mode == IA_CSS_BINARY_MODE_VIDEO) {
375                 stream_dz_config =
376                     ((pipe->stream->isp_params_configs->dz_config.dx !=
377                       HRT_GDC_N)
378                      || (pipe->stream->isp_params_configs->dz_config.dy !=
379                          HRT_GDC_N));
380
381                 video_descr->enable_dz = pipe->config.enable_dz
382                     || stream_dz_config;
383                 video_descr->dvs_env = pipe->config.dvs_envelope;
384                 video_descr->enable_yuv_ds = pipe->extra_config.enable_yuv_ds;
385                 video_descr->enable_high_speed =
386                     pipe->extra_config.enable_high_speed;
387                 video_descr->enable_dvs_6axis =
388                     pipe->extra_config.enable_dvs_6axis;
389                 video_descr->enable_reduced_pipe =
390                     pipe->extra_config.enable_reduced_pipe;
391                 video_descr->isp_pipe_version = pipe->config.isp_pipe_version;
392                 video_descr->enable_fractional_ds =
393                     pipe->extra_config.enable_fractional_ds;
394                 video_descr->enable_dpc =
395                         pipe->config.enable_dpc;
396 #ifdef ISP2401
397                 video_descr->enable_luma_only =
398                         pipe->config.enable_luma_only;
399                 video_descr->enable_tnr =
400                         pipe->config.enable_tnr;
401 #endif
402
403                 if (pipe->extra_config.enable_raw_binning) {
404                         if (pipe->config.bayer_ds_out_res.width != 0 &&
405                             pipe->config.bayer_ds_out_res.height != 0) {
406                                 bds_out_info->res.width =
407                                     pipe->config.bayer_ds_out_res.width;
408                                 bds_out_info->res.height =
409                                     pipe->config.bayer_ds_out_res.height;
410                                 bds_out_info->padded_width =
411                                     pipe->config.bayer_ds_out_res.width;
412                                 err =
413                                 binarydesc_calculate_bds_factor(
414                                         in_info->res, bds_out_info->res,
415                                         &video_descr->required_bds_factor);
416                                 if (err != IA_CSS_SUCCESS)
417                                         return err;
418                         } else {
419                                 bds_out_info->res.width =
420                                     in_info->res.width / 2;
421                                 bds_out_info->res.height =
422                                     in_info->res.height / 2;
423                                 bds_out_info->padded_width =
424                                     in_info->padded_width / 2;
425                                 video_descr->required_bds_factor =
426                                     SH_CSS_BDS_FACTOR_2_00;
427                         }
428                 } else {
429                         bds_out_info->res.width = in_info->res.width;
430                         bds_out_info->res.height = in_info->res.height;
431                         bds_out_info->padded_width = in_info->padded_width;
432                         video_descr->required_bds_factor =
433                             SH_CSS_BDS_FACTOR_1_00;
434                 }
435
436                 pipe->required_bds_factor = video_descr->required_bds_factor;
437
438                 /* bayer ds and fractional ds cannot be enabled
439                 at the same time, so we disable bds_out_info when
440                 fractional ds is used */
441                 if (!pipe->extra_config.enable_fractional_ds)
442                         video_descr->bds_out_info = bds_out_info;
443                 else
444                         video_descr->bds_out_info = NULL;
445
446                 video_descr->enable_fractional_ds =
447                     pipe->extra_config.enable_fractional_ds;
448                 video_descr->stream_config_left_padding = stream_config_left_padding;
449         }
450         IA_CSS_LEAVE_ERR_PRIVATE(err);
451         return err;
452 }
453
454 void ia_css_pipe_get_yuvscaler_binarydesc(
455         struct ia_css_pipe const * const pipe,
456         struct ia_css_binary_descr *yuv_scaler_descr,
457         struct ia_css_frame_info *in_info,
458         struct ia_css_frame_info *out_info,
459         struct ia_css_frame_info *internal_out_info,
460         struct ia_css_frame_info *vf_info)
461 {
462         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
463         struct ia_css_frame_info *this_vf_info = NULL;
464
465         assert(pipe != NULL);
466         assert(in_info != NULL);
467         /* Note: if the following assert fails, the number of ports has been
468          * changed; in that case an additional initializer must be added
469          * a few lines below after which this assert can be updated.
470          */
471         assert(IA_CSS_BINARY_MAX_OUTPUT_PORTS == 2);
472         IA_CSS_ENTER_PRIVATE("");
473
474         in_info->padded_width = in_info->res.width;
475         in_info->raw_bit_depth = 0;
476         ia_css_frame_info_set_width(in_info, in_info->res.width, 0);
477         out_infos[0] = out_info;
478         out_infos[1] = internal_out_info;
479         /* add initializers here if
480          * assert(IA_CSS_BINARY_MAX_OUTPUT_PORTS == ...);
481          * fails
482          */
483
484         if (vf_info) {
485                 this_vf_info = (vf_info->res.width == 0 &&
486                         vf_info->res.height == 0) ? NULL : vf_info;
487         }
488
489         pipe_binarydesc_get_offline(pipe,
490                                IA_CSS_BINARY_MODE_CAPTURE_PP,
491                                yuv_scaler_descr,
492                                in_info, out_infos, this_vf_info);
493
494         yuv_scaler_descr->enable_fractional_ds = true;
495         IA_CSS_LEAVE_PRIVATE("");
496 }
497
498 void ia_css_pipe_get_capturepp_binarydesc(
499         struct ia_css_pipe * const pipe,
500         struct ia_css_binary_descr *capture_pp_descr,
501         struct ia_css_frame_info *in_info,
502         struct ia_css_frame_info *out_info,
503         struct ia_css_frame_info *vf_info)
504 {
505         unsigned int i;
506         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
507
508         assert(pipe != NULL);
509         assert(in_info != NULL);
510         assert(vf_info != NULL);
511         IA_CSS_ENTER_PRIVATE("");
512
513
514         /* the in_info is only used for resolution to enable
515            bayer down scaling. */
516         if (pipe->out_yuv_ds_input_info.res.width)
517                 *in_info = pipe->out_yuv_ds_input_info;
518         else
519                 *in_info = *out_info;
520         in_info->format = IA_CSS_FRAME_FORMAT_YUV420;
521         in_info->raw_bit_depth = 0;
522         ia_css_frame_info_set_width(in_info, in_info->res.width, 0);
523
524         out_infos[0] = out_info;
525         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
526                 out_infos[i] = NULL;
527
528         pipe_binarydesc_get_offline(pipe,
529                                IA_CSS_BINARY_MODE_CAPTURE_PP,
530                                capture_pp_descr,
531                                in_info, out_infos, vf_info);
532
533         capture_pp_descr->enable_capture_pp_bli =
534                 pipe->config.default_capture_config.enable_capture_pp_bli;
535         capture_pp_descr->enable_fractional_ds = true;
536         capture_pp_descr->enable_xnr =
537                 pipe->config.default_capture_config.enable_xnr != 0;
538         IA_CSS_LEAVE_PRIVATE("");
539 }
540
541 /* lookup table for high quality primary binaries */
542 static unsigned int primary_hq_binary_modes[NUM_PRIMARY_HQ_STAGES] =
543 {
544         IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE0,
545         IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE1,
546         IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE2,
547         IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE3,
548         IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE4,
549         IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE5
550 };
551
552 void ia_css_pipe_get_primary_binarydesc(
553         struct ia_css_pipe const * const pipe,
554         struct ia_css_binary_descr *prim_descr,
555         struct ia_css_frame_info *in_info,
556         struct ia_css_frame_info *out_info,
557         struct ia_css_frame_info *vf_info,
558         unsigned int stage_idx)
559 {
560         enum ia_css_pipe_version pipe_version = pipe->config.isp_pipe_version;
561         int mode;
562         unsigned int i;
563         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
564
565         assert(pipe != NULL);
566         assert(in_info != NULL);
567         assert(out_info != NULL);
568         assert(stage_idx < NUM_PRIMARY_HQ_STAGES);
569         /* vf_info can be NULL - example video_binarydescr */
570         /*assert(vf_info != NULL);*/
571         IA_CSS_ENTER_PRIVATE("");
572
573         if (pipe_version == IA_CSS_PIPE_VERSION_2_6_1)
574                 mode = primary_hq_binary_modes[stage_idx];
575         else
576                 mode = IA_CSS_BINARY_MODE_PRIMARY;
577
578         if (ia_css_util_is_input_format_yuv(pipe->stream->config.input_config.format))
579                 mode = IA_CSS_BINARY_MODE_COPY;
580
581         in_info->res = pipe->config.input_effective_res;
582         in_info->padded_width = in_info->res.width;
583
584 #if !defined(HAS_NO_PACKED_RAW_PIXELS)
585         if (pipe->stream->config.pack_raw_pixels)
586                 in_info->format = IA_CSS_FRAME_FORMAT_RAW_PACKED;
587         else
588 #endif
589                 in_info->format = IA_CSS_FRAME_FORMAT_RAW;
590
591         in_info->raw_bit_depth = ia_css_pipe_util_pipe_input_format_bpp(pipe);
592         out_infos[0] = out_info;
593         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
594                 out_infos[i] = NULL;
595
596         pipe_binarydesc_get_offline(pipe, mode,
597                                prim_descr, in_info, out_infos, vf_info);
598
599         if (pipe->stream->config.online &&
600             pipe->stream->config.mode != IA_CSS_INPUT_MODE_MEMORY) {
601                 prim_descr->online = true;
602                 prim_descr->two_ppc =
603                     (pipe->stream->config.pixels_per_clock == 2);
604                 prim_descr->stream_format = pipe->stream->config.input_config.format;
605         }
606         if (mode == IA_CSS_BINARY_MODE_PRIMARY) {
607                 prim_descr->isp_pipe_version = pipe->config.isp_pipe_version;
608                 prim_descr->enable_fractional_ds =
609                     pipe->extra_config.enable_fractional_ds;
610 #ifdef ISP2401
611                 prim_descr->enable_luma_only =
612                         pipe->config.enable_luma_only;
613 #endif
614                 /* We have both striped and non-striped primary binaries,
615                  * if continuous viewfinder is required, then we must select
616                  * a striped one. Otherwise we prefer to use a non-striped
617                  * since it has better performance. */
618                 if (pipe_version == IA_CSS_PIPE_VERSION_2_6_1)
619                         prim_descr->striped = false;
620                 else
621 #ifndef ISP2401
622                         prim_descr->striped = prim_descr->continuous && (!pipe->stream->stop_copy_preview || !pipe->stream->disable_cont_vf);
623 #else
624                         prim_descr->striped = prim_descr->continuous && !pipe->stream->disable_cont_vf;
625
626                 if ((pipe->config.default_capture_config.enable_xnr != 0) &&
627                         (pipe->extra_config.enable_dvs_6axis == true))
628                                 prim_descr->enable_xnr = true;
629 #endif
630         }
631         IA_CSS_LEAVE_PRIVATE("");
632 }
633
634 void ia_css_pipe_get_pre_gdc_binarydesc(
635         struct ia_css_pipe const * const pipe,
636         struct ia_css_binary_descr *pre_gdc_descr,
637         struct ia_css_frame_info *in_info,
638         struct ia_css_frame_info *out_info)
639 {
640         unsigned int i;
641         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
642
643         assert(pipe != NULL);
644         assert(in_info != NULL);
645         assert(out_info != NULL);
646         IA_CSS_ENTER_PRIVATE("");
647
648         *in_info = *out_info;
649         in_info->format = IA_CSS_FRAME_FORMAT_RAW;
650         in_info->raw_bit_depth = ia_css_pipe_util_pipe_input_format_bpp(pipe);
651         out_infos[0] = out_info;
652         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
653                 out_infos[i] = NULL;
654
655         pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_PRE_ISP,
656                                pre_gdc_descr, in_info, out_infos, NULL);
657         pre_gdc_descr->isp_pipe_version = pipe->config.isp_pipe_version;
658         IA_CSS_LEAVE_PRIVATE("");
659 }
660
661 void ia_css_pipe_get_gdc_binarydesc(
662         struct ia_css_pipe const * const pipe,
663         struct ia_css_binary_descr *gdc_descr,
664         struct ia_css_frame_info *in_info,
665         struct ia_css_frame_info *out_info)
666 {
667         unsigned int i;
668         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
669
670         assert(pipe != NULL);
671         assert(in_info != NULL);
672         assert(out_info != NULL);
673         IA_CSS_ENTER_PRIVATE("");
674
675         *in_info = *out_info;
676         in_info->format = IA_CSS_FRAME_FORMAT_QPLANE6;
677         out_infos[0] = out_info;
678         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
679                 out_infos[i] = NULL;
680
681         pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_GDC,
682                                gdc_descr, in_info, out_infos, NULL);
683         IA_CSS_LEAVE_PRIVATE("");
684 }
685
686 void ia_css_pipe_get_post_gdc_binarydesc(
687         struct ia_css_pipe const * const pipe,
688         struct ia_css_binary_descr *post_gdc_descr,
689         struct ia_css_frame_info *in_info,
690         struct ia_css_frame_info *out_info,
691         struct ia_css_frame_info *vf_info)
692 {
693         unsigned int i;
694         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
695
696         assert(pipe != NULL);
697         assert(in_info != NULL);
698         assert(out_info != NULL);
699         assert(vf_info != NULL);
700         IA_CSS_ENTER_PRIVATE("");
701
702         *in_info = *out_info;
703         in_info->format = IA_CSS_FRAME_FORMAT_YUV420_16;
704         in_info->raw_bit_depth = 16;
705         out_infos[0] = out_info;
706         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
707                 out_infos[i] = NULL;
708
709         pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_POST_ISP,
710                                post_gdc_descr, in_info, out_infos, vf_info);
711
712         post_gdc_descr->isp_pipe_version = pipe->config.isp_pipe_version;
713         IA_CSS_LEAVE_PRIVATE("");
714 }
715
716 void ia_css_pipe_get_pre_de_binarydesc(
717         struct ia_css_pipe const * const pipe,
718         struct ia_css_binary_descr *pre_de_descr,
719         struct ia_css_frame_info *in_info,
720         struct ia_css_frame_info *out_info)
721 {
722         unsigned int i;
723         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
724
725         assert(pipe != NULL);
726         assert(in_info != NULL);
727         assert(out_info != NULL);
728         IA_CSS_ENTER_PRIVATE("");
729
730         *in_info = *out_info;
731         in_info->format = IA_CSS_FRAME_FORMAT_RAW;
732         in_info->raw_bit_depth = ia_css_pipe_util_pipe_input_format_bpp(pipe);
733         out_infos[0] = out_info;
734         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
735                 out_infos[i] = NULL;
736
737         if (pipe->config.isp_pipe_version == IA_CSS_PIPE_VERSION_1)
738                 pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_PRE_ISP,
739                                        pre_de_descr, in_info, out_infos, NULL);
740         else if (pipe->config.isp_pipe_version == IA_CSS_PIPE_VERSION_2_2) {
741                 pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_PRE_DE,
742                                        pre_de_descr, in_info, out_infos, NULL);
743         }
744
745         if (pipe->stream->config.online) {
746                 pre_de_descr->online = true;
747                 pre_de_descr->two_ppc =
748                     (pipe->stream->config.pixels_per_clock == 2);
749                 pre_de_descr->stream_format = pipe->stream->config.input_config.format;
750         }
751         pre_de_descr->isp_pipe_version = pipe->config.isp_pipe_version;
752         IA_CSS_LEAVE_PRIVATE("");
753 }
754
755 void ia_css_pipe_get_pre_anr_binarydesc(
756         struct ia_css_pipe const * const pipe,
757         struct ia_css_binary_descr *pre_anr_descr,
758         struct ia_css_frame_info *in_info,
759         struct ia_css_frame_info *out_info)
760 {
761         unsigned int i;
762         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
763
764         assert(pipe != NULL);
765         assert(in_info != NULL);
766         assert(out_info != NULL);
767         IA_CSS_ENTER_PRIVATE("");
768
769         *in_info = *out_info;
770         in_info->format = IA_CSS_FRAME_FORMAT_RAW;
771         in_info->raw_bit_depth = ia_css_pipe_util_pipe_input_format_bpp(pipe);
772         out_infos[0] = out_info;
773         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
774                 out_infos[i] = NULL;
775
776         pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_PRE_ISP,
777                                pre_anr_descr, in_info, out_infos, NULL);
778
779         if (pipe->stream->config.online) {
780                 pre_anr_descr->online = true;
781                 pre_anr_descr->two_ppc =
782                     (pipe->stream->config.pixels_per_clock == 2);
783                 pre_anr_descr->stream_format = pipe->stream->config.input_config.format;
784         }
785         pre_anr_descr->isp_pipe_version = pipe->config.isp_pipe_version;
786         IA_CSS_LEAVE_PRIVATE("");
787 }
788
789 void ia_css_pipe_get_anr_binarydesc(
790         struct ia_css_pipe const * const pipe,
791         struct ia_css_binary_descr *anr_descr,
792         struct ia_css_frame_info *in_info,
793         struct ia_css_frame_info *out_info)
794 {
795         unsigned int i;
796         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
797
798         assert(pipe != NULL);
799         assert(in_info != NULL);
800         assert(out_info != NULL);
801         IA_CSS_ENTER_PRIVATE("");
802
803         *in_info = *out_info;
804         in_info->format = IA_CSS_FRAME_FORMAT_RAW;
805         in_info->raw_bit_depth = ANR_ELEMENT_BITS;
806         out_infos[0] = out_info;
807         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
808                 out_infos[i] = NULL;
809
810         pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_ANR,
811                                anr_descr, in_info, out_infos, NULL);
812
813         anr_descr->isp_pipe_version = pipe->config.isp_pipe_version;
814         IA_CSS_LEAVE_PRIVATE("");
815 }
816
817
818 void ia_css_pipe_get_post_anr_binarydesc(
819         struct ia_css_pipe const * const pipe,
820         struct ia_css_binary_descr *post_anr_descr,
821         struct ia_css_frame_info *in_info,
822         struct ia_css_frame_info *out_info,
823         struct ia_css_frame_info *vf_info)
824 {
825         unsigned int i;
826         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
827
828         assert(pipe != NULL);
829         assert(in_info != NULL);
830         assert(out_info != NULL);
831         assert(vf_info != NULL);
832         IA_CSS_ENTER_PRIVATE("");
833
834         *in_info = *out_info;
835         in_info->format = IA_CSS_FRAME_FORMAT_RAW;
836         in_info->raw_bit_depth = ANR_ELEMENT_BITS;
837         out_infos[0] = out_info;
838         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
839                 out_infos[i] = NULL;
840
841         pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_POST_ISP,
842                                post_anr_descr, in_info, out_infos, vf_info);
843
844         post_anr_descr->isp_pipe_version = pipe->config.isp_pipe_version;
845         IA_CSS_LEAVE_PRIVATE("");
846 }
847
848 void ia_css_pipe_get_ldc_binarydesc(
849         struct ia_css_pipe const * const pipe,
850         struct ia_css_binary_descr *ldc_descr,
851         struct ia_css_frame_info *in_info,
852         struct ia_css_frame_info *out_info)
853 {
854         unsigned int i;
855         struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
856
857         assert(pipe != NULL);
858         assert(in_info != NULL);
859         assert(out_info != NULL);
860         IA_CSS_ENTER_PRIVATE("");
861
862 #ifndef ISP2401
863         *in_info = *out_info;
864 #else
865         if (pipe->out_yuv_ds_input_info.res.width)
866                 *in_info = pipe->out_yuv_ds_input_info;
867         else
868                 *in_info = *out_info;
869 #endif
870         in_info->format = IA_CSS_FRAME_FORMAT_YUV420;
871         in_info->raw_bit_depth = 0;
872         ia_css_frame_info_set_width(in_info, in_info->res.width, 0);
873
874         out_infos[0] = out_info;
875         for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
876                 out_infos[i] = NULL;
877
878         pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_CAPTURE_PP,
879                                ldc_descr, in_info, out_infos, NULL);
880         ldc_descr->enable_dvs_6axis =
881                     pipe->extra_config.enable_dvs_6axis;
882         IA_CSS_LEAVE_PRIVATE("");
883 }