Linux Audio

Check our new training course

Embedded Linux Audio

Check our new training course
with Creative Commons CC-BY-SA
lecture materials

Bootlin logo

Elixir Cross Referencer

Loading...
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
/*
 * Support for Intel Camera Imaging ISP subsystem.
 * Copyright (c) 2015, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 */

#include "ia_css_pipe_binarydesc.h"
#include "ia_css_frame_format.h"
#include "ia_css_pipe.h"
#include "ia_css_pipe_util.h"
#include "ia_css_util.h"
#include "ia_css_debug.h"
#include "sh_css_params.h"
#include <assert_support.h>
/* HRT_GDC_N */
#include "gdc_device.h"

/* This module provides a binary descriptions to used to find a binary. Since,
 * every stage is associated with a binary, it implicity helps stage
 * description. Apart from providing a binary description, this module also
 * populates the frame info's when required.*/

/* Generic descriptor for offline binaries. Internal function. */
static void pipe_binarydesc_get_offline(
	struct ia_css_pipe const * const pipe,
	const int mode,
	struct ia_css_binary_descr *descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info[],
	struct ia_css_frame_info *vf_info)
{
	unsigned int i;
	/* in_info, out_info, vf_info can be NULL */
	assert(pipe != NULL);
	assert(descr != NULL);
	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
			    "pipe_binarydesc_get_offline() enter:\n");

	descr->mode = mode;
	descr->online = false;
	descr->continuous = pipe->stream->config.continuous;
	descr->striped = false;
	descr->two_ppc = false;
	descr->enable_yuv_ds = false;
	descr->enable_high_speed = false;
	descr->enable_dvs_6axis = false;
	descr->enable_reduced_pipe = false;
	descr->enable_dz = true;
	descr->enable_xnr = false;
	descr->enable_dpc = false;
#ifdef ISP2401
	descr->enable_luma_only = false;
	descr->enable_tnr = false;
#endif
	descr->enable_capture_pp_bli = false;
	descr->enable_fractional_ds = false;
	descr->dvs_env.width = 0;
	descr->dvs_env.height = 0;
	descr->stream_format = pipe->stream->config.input_config.format;
	descr->in_info = in_info;
	descr->bds_out_info = NULL;
	for (i = 0; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		descr->out_info[i] = out_info[i];
	descr->vf_info = vf_info;
	descr->isp_pipe_version = pipe->config.isp_pipe_version;
	descr->required_bds_factor = SH_CSS_BDS_FACTOR_1_00;
	descr->stream_config_left_padding = -1;
}

void ia_css_pipe_get_copy_binarydesc(
	struct ia_css_pipe const * const pipe,
	struct ia_css_binary_descr *copy_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info,
	struct ia_css_frame_info *vf_info)
{
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
	unsigned int i;
	/* out_info can be NULL */
	assert(pipe != NULL);
	assert(in_info != NULL);
	IA_CSS_ENTER_PRIVATE("");

	*in_info = *out_info;
	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;
	pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_COPY,
				    copy_descr, in_info, out_infos, vf_info);
	copy_descr->online = true;
	copy_descr->continuous = false;
	copy_descr->two_ppc = (pipe->stream->config.pixels_per_clock == 2);
	copy_descr->enable_dz = false;
	copy_descr->isp_pipe_version = IA_CSS_PIPE_VERSION_1;
	IA_CSS_LEAVE_PRIVATE("");
}
void ia_css_pipe_get_vfpp_binarydesc(
	struct ia_css_pipe const * const pipe,
	struct ia_css_binary_descr *vf_pp_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info)
{
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
	unsigned int i;
	/* out_info can be NULL ??? */
	assert(pipe != NULL);
	assert(in_info != NULL);
	IA_CSS_ENTER_PRIVATE("");

	in_info->raw_bit_depth = 0;
	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;

	pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_VF_PP,
			       vf_pp_descr, in_info, out_infos, NULL);
	vf_pp_descr->enable_fractional_ds = true;
	IA_CSS_LEAVE_PRIVATE("");
}

static struct sh_css_bds_factor bds_factors_list[] = {
	{1, 1, SH_CSS_BDS_FACTOR_1_00},
	{5, 4, SH_CSS_BDS_FACTOR_1_25},
	{3, 2, SH_CSS_BDS_FACTOR_1_50},
	{2, 1, SH_CSS_BDS_FACTOR_2_00},
	{9, 4, SH_CSS_BDS_FACTOR_2_25},
	{5, 2, SH_CSS_BDS_FACTOR_2_50},
	{3, 1, SH_CSS_BDS_FACTOR_3_00},
	{4, 1, SH_CSS_BDS_FACTOR_4_00},
	{9, 2, SH_CSS_BDS_FACTOR_4_50},
	{5, 1, SH_CSS_BDS_FACTOR_5_00},
	{6, 1, SH_CSS_BDS_FACTOR_6_00},
	{8, 1, SH_CSS_BDS_FACTOR_8_00}
};

enum ia_css_err sh_css_bds_factor_get_numerator_denominator(
	unsigned int bds_factor,
	unsigned int *bds_factor_numerator,
	unsigned int *bds_factor_denominator)
{
	unsigned int i;
	unsigned int bds_list_size = sizeof(bds_factors_list) /
				sizeof(struct sh_css_bds_factor);

	/* Loop over all bds factors until a match is found */
	for (i = 0; i < bds_list_size; i++) {
		if (bds_factors_list[i].bds_factor == bds_factor) {
			*bds_factor_numerator = bds_factors_list[i].numerator;
			*bds_factor_denominator = bds_factors_list[i].denominator;
			return IA_CSS_SUCCESS;
		}
	}

	/* Throw an error since bds_factor cannot be found
	in bds_factors_list */
	return IA_CSS_ERR_INVALID_ARGUMENTS;
}

enum ia_css_err binarydesc_calculate_bds_factor(
	struct ia_css_resolution input_res,
	struct ia_css_resolution output_res,
	unsigned int *bds_factor)
{
	unsigned int i;
	unsigned int bds_list_size = sizeof(bds_factors_list) /
	    sizeof(struct sh_css_bds_factor);
	unsigned int in_w = input_res.width,
	    in_h = input_res.height,
	    out_w = output_res.width, out_h = output_res.height;

	unsigned int max_bds_factor = 8;
	unsigned int max_rounding_margin = 2;
	/* delta in pixels to account for rounding margin in the calculation */
	unsigned int delta = max_bds_factor * max_rounding_margin;

	/* Assert if the resolutions are not set */
	assert(in_w != 0 && in_h != 0);
	assert(out_w != 0 && out_h != 0);

	/* Loop over all bds factors until a match is found */
	for (i = 0; i < bds_list_size; i++) {
		unsigned num = bds_factors_list[i].numerator;
		unsigned den = bds_factors_list[i].denominator;

		/* See width-wise and height-wise if this bds_factor
		 * satisfies the condition */
		bool cond = (out_w * num / den + delta > in_w) &&
		    (out_w * num / den <= in_w) &&
		    (out_h * num / den + delta > in_h) &&
		    (out_h * num / den <= in_h);

		if (cond) {
			*bds_factor = bds_factors_list[i].bds_factor;
			return IA_CSS_SUCCESS;
		}
	}

	/* Throw an error since a suitable bds_factor cannot be found */
	return IA_CSS_ERR_INVALID_ARGUMENTS;
}

enum ia_css_err ia_css_pipe_get_preview_binarydesc(
	struct ia_css_pipe * const pipe,
	struct ia_css_binary_descr *preview_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *bds_out_info,
	struct ia_css_frame_info *out_info,
	struct ia_css_frame_info *vf_info)
{
	enum ia_css_err err;
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
	int mode = IA_CSS_BINARY_MODE_PREVIEW;
	unsigned int i;

	assert(pipe != NULL);
	assert(in_info != NULL);
	assert(out_info != NULL);
	assert(vf_info != NULL);
	IA_CSS_ENTER_PRIVATE("");

	/*
	 * Set up the info of the input frame with
	 * the ISP required resolution
	 */
	in_info->res = pipe->config.input_effective_res;
	in_info->padded_width = in_info->res.width;
	in_info->raw_bit_depth = ia_css_pipe_util_pipe_input_format_bpp(pipe);

	if (ia_css_util_is_input_format_yuv(pipe->stream->config.input_config.format))
		mode = IA_CSS_BINARY_MODE_COPY;
	else
		in_info->format = IA_CSS_FRAME_FORMAT_RAW;

	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;

	pipe_binarydesc_get_offline(pipe, mode,
			       preview_descr, in_info, out_infos, vf_info);
	if (pipe->stream->config.online) {
		preview_descr->online = pipe->stream->config.online;
		preview_descr->two_ppc =
		    (pipe->stream->config.pixels_per_clock == 2);
	}
	preview_descr->stream_format = pipe->stream->config.input_config.format;

	/* TODO: Remove this when bds_out_info is available! */
	*bds_out_info = *in_info;

	if (pipe->extra_config.enable_raw_binning) {
		if (pipe->config.bayer_ds_out_res.width != 0 &&
		    pipe->config.bayer_ds_out_res.height != 0) {
			bds_out_info->res.width =
			    pipe->config.bayer_ds_out_res.width;
			bds_out_info->res.height =
			    pipe->config.bayer_ds_out_res.height;
			bds_out_info->padded_width =
			    pipe->config.bayer_ds_out_res.width;
			err =
			    binarydesc_calculate_bds_factor(in_info->res,
				    bds_out_info->res,
				    &preview_descr->required_bds_factor);
			if (err != IA_CSS_SUCCESS)
				return err;
		} else {
			bds_out_info->res.width = in_info->res.width / 2;
			bds_out_info->res.height = in_info->res.height / 2;
			bds_out_info->padded_width = in_info->padded_width / 2;
			preview_descr->required_bds_factor =
			    SH_CSS_BDS_FACTOR_2_00;
		}
	} else {
		/* TODO: Remove this when bds_out_info->is available! */
		bds_out_info->res.width = in_info->res.width;
		bds_out_info->res.height = in_info->res.height;
		bds_out_info->padded_width = in_info->padded_width;
		preview_descr->required_bds_factor = SH_CSS_BDS_FACTOR_1_00;
	}
	pipe->required_bds_factor = preview_descr->required_bds_factor;

	/* bayer ds and fractional ds cannot be enabled at the same time,
	so we disable bds_out_info when fractional ds is used */
	if (!pipe->extra_config.enable_fractional_ds)
		preview_descr->bds_out_info = bds_out_info;
	else
		preview_descr->bds_out_info = NULL;
	/*
	   ----Preview binary-----
	   --in-->|--out->|vf_veceven|--|--->vf
	   -----------------------
	   * Preview binary normally doesn't have a vf_port but
	   * instead it has an output port. However, the output is
	   * generated by vf_veceven module in which we might have
	   * a downscaling (by 1x, 2x, or 4x). Because the resolution
	   * might change, we need two different info, namely out_info
	   * & vf_info. In fill_binary_info we use out&vf info to
	   * calculate vf decimation factor.
	 */
	*out_info = *vf_info;

	/* In case of preview_ds binary, we can do any fractional amount
	 * of downscale, so there is no DS needed in vf_veceven. Therefore,
	 * out and vf infos will be the same. Otherwise, we set out resolution
	 * equal to in resolution. */
	if (!pipe->extra_config.enable_fractional_ds) {
		/* TODO: Change this when bds_out_info is available! */
		out_info->res.width = bds_out_info->res.width;
		out_info->res.height = bds_out_info->res.height;
		out_info->padded_width = bds_out_info->padded_width;
	}
	preview_descr->enable_fractional_ds =
	    pipe->extra_config.enable_fractional_ds;

	preview_descr->enable_dpc = pipe->config.enable_dpc;

	preview_descr->isp_pipe_version = pipe->config.isp_pipe_version;
	IA_CSS_LEAVE_ERR_PRIVATE(IA_CSS_SUCCESS);
	return IA_CSS_SUCCESS;
}

enum ia_css_err ia_css_pipe_get_video_binarydesc(
	struct ia_css_pipe * const pipe,
	struct ia_css_binary_descr *video_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *bds_out_info,
	struct ia_css_frame_info *out_info,
	struct ia_css_frame_info *vf_info,
	int stream_config_left_padding)
{
	int mode = IA_CSS_BINARY_MODE_VIDEO;
	unsigned int i;
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
	enum ia_css_err err = IA_CSS_SUCCESS;
	bool stream_dz_config = false;

	/* vf_info can be NULL */
	assert(pipe != NULL);
	assert(in_info != NULL);
	/* assert(vf_info != NULL); */
	IA_CSS_ENTER_PRIVATE("");

	/* The solution below is not optimal; we should move to using ia_css_pipe_get_copy_binarydesc()
	 * But for now this fixes things; this code used to be there but was removed
	 * with gerrit 8908 as this was wrong for Skycam; however 240x still needs this
	 */
	if (ia_css_util_is_input_format_yuv(pipe->stream->config.input_config.format))
		mode = IA_CSS_BINARY_MODE_COPY;

	in_info->res = pipe->config.input_effective_res;
	in_info->padded_width = in_info->res.width;
	in_info->format = IA_CSS_FRAME_FORMAT_RAW;
	in_info->raw_bit_depth = ia_css_pipe_util_pipe_input_format_bpp(pipe);
	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;

	pipe_binarydesc_get_offline(pipe, mode,
	       video_descr, in_info, out_infos, vf_info);

	if (pipe->stream->config.online) {
		video_descr->online = pipe->stream->config.online;
		video_descr->two_ppc =
		    (pipe->stream->config.pixels_per_clock == 2);
	}

	if (mode == IA_CSS_BINARY_MODE_VIDEO) {
		stream_dz_config =
		    ((pipe->stream->isp_params_configs->dz_config.dx !=
		      HRT_GDC_N)
		     || (pipe->stream->isp_params_configs->dz_config.dy !=
			 HRT_GDC_N));

		video_descr->enable_dz = pipe->config.enable_dz
		    || stream_dz_config;
		video_descr->dvs_env = pipe->config.dvs_envelope;
		video_descr->enable_yuv_ds = pipe->extra_config.enable_yuv_ds;
		video_descr->enable_high_speed =
		    pipe->extra_config.enable_high_speed;
		video_descr->enable_dvs_6axis =
		    pipe->extra_config.enable_dvs_6axis;
		video_descr->enable_reduced_pipe =
		    pipe->extra_config.enable_reduced_pipe;
		video_descr->isp_pipe_version = pipe->config.isp_pipe_version;
		video_descr->enable_fractional_ds =
		    pipe->extra_config.enable_fractional_ds;
		video_descr->enable_dpc =
			pipe->config.enable_dpc;
#ifdef ISP2401
		video_descr->enable_luma_only =
			pipe->config.enable_luma_only;
		video_descr->enable_tnr =
			pipe->config.enable_tnr;
#endif

		if (pipe->extra_config.enable_raw_binning) {
			if (pipe->config.bayer_ds_out_res.width != 0 &&
			    pipe->config.bayer_ds_out_res.height != 0) {
				bds_out_info->res.width =
				    pipe->config.bayer_ds_out_res.width;
				bds_out_info->res.height =
				    pipe->config.bayer_ds_out_res.height;
				bds_out_info->padded_width =
				    pipe->config.bayer_ds_out_res.width;
				err =
				binarydesc_calculate_bds_factor(
					in_info->res, bds_out_info->res,
					&video_descr->required_bds_factor);
				if (err != IA_CSS_SUCCESS)
					return err;
			} else {
				bds_out_info->res.width =
				    in_info->res.width / 2;
				bds_out_info->res.height =
				    in_info->res.height / 2;
				bds_out_info->padded_width =
				    in_info->padded_width / 2;
				video_descr->required_bds_factor =
				    SH_CSS_BDS_FACTOR_2_00;
			}
		} else {
			bds_out_info->res.width = in_info->res.width;
			bds_out_info->res.height = in_info->res.height;
			bds_out_info->padded_width = in_info->padded_width;
			video_descr->required_bds_factor =
			    SH_CSS_BDS_FACTOR_1_00;
		}

		pipe->required_bds_factor = video_descr->required_bds_factor;

		/* bayer ds and fractional ds cannot be enabled
		at the same time, so we disable bds_out_info when
		fractional ds is used */
		if (!pipe->extra_config.enable_fractional_ds)
			video_descr->bds_out_info = bds_out_info;
		else
			video_descr->bds_out_info = NULL;

		video_descr->enable_fractional_ds =
		    pipe->extra_config.enable_fractional_ds;
		video_descr->stream_config_left_padding = stream_config_left_padding;
	}
	IA_CSS_LEAVE_ERR_PRIVATE(err);
	return err;
}

void ia_css_pipe_get_yuvscaler_binarydesc(
	struct ia_css_pipe const * const pipe,
	struct ia_css_binary_descr *yuv_scaler_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info,
	struct ia_css_frame_info *internal_out_info,
	struct ia_css_frame_info *vf_info)
{
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];
	struct ia_css_frame_info *this_vf_info = NULL;

	assert(pipe != NULL);
	assert(in_info != NULL);
	/* Note: if the following assert fails, the number of ports has been
	 * changed; in that case an additional initializer must be added
	 * a few lines below after which this assert can be updated.
	 */
	assert(IA_CSS_BINARY_MAX_OUTPUT_PORTS == 2);
	IA_CSS_ENTER_PRIVATE("");

	in_info->padded_width = in_info->res.width;
	in_info->raw_bit_depth = 0;
	ia_css_frame_info_set_width(in_info, in_info->res.width, 0);
	out_infos[0] = out_info;
	out_infos[1] = internal_out_info;
	/* add initializers here if
	 * assert(IA_CSS_BINARY_MAX_OUTPUT_PORTS == ...);
	 * fails
	 */

	if (vf_info) {
		this_vf_info = (vf_info->res.width == 0 &&
			vf_info->res.height == 0) ? NULL : vf_info;
	}

	pipe_binarydesc_get_offline(pipe,
			       IA_CSS_BINARY_MODE_CAPTURE_PP,
			       yuv_scaler_descr,
			       in_info, out_infos, this_vf_info);

	yuv_scaler_descr->enable_fractional_ds = true;
	IA_CSS_LEAVE_PRIVATE("");
}

void ia_css_pipe_get_capturepp_binarydesc(
	struct ia_css_pipe * const pipe,
	struct ia_css_binary_descr *capture_pp_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info,
	struct ia_css_frame_info *vf_info)
{
	unsigned int i;
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];

	assert(pipe != NULL);
	assert(in_info != NULL);
	assert(vf_info != NULL);
	IA_CSS_ENTER_PRIVATE("");


	/* the in_info is only used for resolution to enable
	   bayer down scaling. */
	if (pipe->out_yuv_ds_input_info.res.width)
		*in_info = pipe->out_yuv_ds_input_info;
	else
		*in_info = *out_info;
	in_info->format = IA_CSS_FRAME_FORMAT_YUV420;
	in_info->raw_bit_depth = 0;
	ia_css_frame_info_set_width(in_info, in_info->res.width, 0);

	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;

	pipe_binarydesc_get_offline(pipe,
			       IA_CSS_BINARY_MODE_CAPTURE_PP,
			       capture_pp_descr,
			       in_info, out_infos, vf_info);

	capture_pp_descr->enable_capture_pp_bli =
		pipe->config.default_capture_config.enable_capture_pp_bli;
	capture_pp_descr->enable_fractional_ds = true;
	capture_pp_descr->enable_xnr =
		pipe->config.default_capture_config.enable_xnr != 0;
	IA_CSS_LEAVE_PRIVATE("");
}

/* lookup table for high quality primary binaries */
static unsigned int primary_hq_binary_modes[NUM_PRIMARY_HQ_STAGES] =
{
	IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE0,
	IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE1,
	IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE2,
	IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE3,
	IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE4,
	IA_CSS_BINARY_MODE_PRIMARY_HQ_STAGE5
};

void ia_css_pipe_get_primary_binarydesc(
	struct ia_css_pipe const * const pipe,
	struct ia_css_binary_descr *prim_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info,
	struct ia_css_frame_info *vf_info,
	unsigned int stage_idx)
{
	enum ia_css_pipe_version pipe_version = pipe->config.isp_pipe_version;
	int mode;
	unsigned int i;
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];

	assert(pipe != NULL);
	assert(in_info != NULL);
	assert(out_info != NULL);
	assert(stage_idx < NUM_PRIMARY_HQ_STAGES);
	/* vf_info can be NULL - example video_binarydescr */
	/*assert(vf_info != NULL);*/
	IA_CSS_ENTER_PRIVATE("");

	if (pipe_version == IA_CSS_PIPE_VERSION_2_6_1)
		mode = primary_hq_binary_modes[stage_idx];
	else
		mode = IA_CSS_BINARY_MODE_PRIMARY;

	if (ia_css_util_is_input_format_yuv(pipe->stream->config.input_config.format))
		mode = IA_CSS_BINARY_MODE_COPY;

	in_info->res = pipe->config.input_effective_res;
	in_info->padded_width = in_info->res.width;

#if !defined(HAS_NO_PACKED_RAW_PIXELS)
	if (pipe->stream->config.pack_raw_pixels)
		in_info->format = IA_CSS_FRAME_FORMAT_RAW_PACKED;
	else
#endif
		in_info->format = IA_CSS_FRAME_FORMAT_RAW;

	in_info->raw_bit_depth = ia_css_pipe_util_pipe_input_format_bpp(pipe);
	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;

	pipe_binarydesc_get_offline(pipe, mode,
			       prim_descr, in_info, out_infos, vf_info);

	if (pipe->stream->config.online &&
	    pipe->stream->config.mode != IA_CSS_INPUT_MODE_MEMORY) {
		prim_descr->online = true;
		prim_descr->two_ppc =
		    (pipe->stream->config.pixels_per_clock == 2);
		prim_descr->stream_format = pipe->stream->config.input_config.format;
	}
	if (mode == IA_CSS_BINARY_MODE_PRIMARY) {
		prim_descr->isp_pipe_version = pipe->config.isp_pipe_version;
		prim_descr->enable_fractional_ds =
		    pipe->extra_config.enable_fractional_ds;
#ifdef ISP2401
		prim_descr->enable_luma_only =
			pipe->config.enable_luma_only;
#endif
		/* We have both striped and non-striped primary binaries,
		 * if continuous viewfinder is required, then we must select
		 * a striped one. Otherwise we prefer to use a non-striped
		 * since it has better performance. */
		if (pipe_version == IA_CSS_PIPE_VERSION_2_6_1)
			prim_descr->striped = false;
		else
#ifndef ISP2401
			prim_descr->striped = prim_descr->continuous && (!pipe->stream->stop_copy_preview || !pipe->stream->disable_cont_vf);
#else
			prim_descr->striped = prim_descr->continuous && !pipe->stream->disable_cont_vf;

		if ((pipe->config.default_capture_config.enable_xnr != 0) &&
			(pipe->extra_config.enable_dvs_6axis == true))
				prim_descr->enable_xnr = true;
#endif
	}
	IA_CSS_LEAVE_PRIVATE("");
}

void ia_css_pipe_get_pre_gdc_binarydesc(
	struct ia_css_pipe const * const pipe,
	struct ia_css_binary_descr *pre_gdc_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info)
{
	unsigned int i;
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];

	assert(pipe != NULL);
	assert(in_info != NULL);
	assert(out_info != NULL);
	IA_CSS_ENTER_PRIVATE("");

	*in_info = *out_info;
	in_info->format = IA_CSS_FRAME_FORMAT_RAW;
	in_info->raw_bit_depth = ia_css_pipe_util_pipe_input_format_bpp(pipe);
	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;

	pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_PRE_ISP,
			       pre_gdc_descr, in_info, out_infos, NULL);
	pre_gdc_descr->isp_pipe_version = pipe->config.isp_pipe_version;
	IA_CSS_LEAVE_PRIVATE("");
}

void ia_css_pipe_get_gdc_binarydesc(
	struct ia_css_pipe const * const pipe,
	struct ia_css_binary_descr *gdc_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info)
{
	unsigned int i;
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];

	assert(pipe != NULL);
	assert(in_info != NULL);
	assert(out_info != NULL);
	IA_CSS_ENTER_PRIVATE("");

	*in_info = *out_info;
	in_info->format = IA_CSS_FRAME_FORMAT_QPLANE6;
	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;

	pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_GDC,
			       gdc_descr, in_info, out_infos, NULL);
	IA_CSS_LEAVE_PRIVATE("");
}

void ia_css_pipe_get_post_gdc_binarydesc(
	struct ia_css_pipe const * const pipe,
	struct ia_css_binary_descr *post_gdc_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info,
	struct ia_css_frame_info *vf_info)
{
	unsigned int i;
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];

	assert(pipe != NULL);
	assert(in_info != NULL);
	assert(out_info != NULL);
	assert(vf_info != NULL);
	IA_CSS_ENTER_PRIVATE("");

	*in_info = *out_info;
	in_info->format = IA_CSS_FRAME_FORMAT_YUV420_16;
	in_info->raw_bit_depth = 16;
	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;

	pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_POST_ISP,
			       post_gdc_descr, in_info, out_infos, vf_info);

	post_gdc_descr->isp_pipe_version = pipe->config.isp_pipe_version;
	IA_CSS_LEAVE_PRIVATE("");
}

void ia_css_pipe_get_pre_de_binarydesc(
	struct ia_css_pipe const * const pipe,
	struct ia_css_binary_descr *pre_de_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info)
{
	unsigned int i;
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];

	assert(pipe != NULL);
	assert(in_info != NULL);
	assert(out_info != NULL);
	IA_CSS_ENTER_PRIVATE("");

	*in_info = *out_info;
	in_info->format = IA_CSS_FRAME_FORMAT_RAW;
	in_info->raw_bit_depth = ia_css_pipe_util_pipe_input_format_bpp(pipe);
	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;

	if (pipe->config.isp_pipe_version == IA_CSS_PIPE_VERSION_1)
		pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_PRE_ISP,
				       pre_de_descr, in_info, out_infos, NULL);
	else if (pipe->config.isp_pipe_version == IA_CSS_PIPE_VERSION_2_2) {
		pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_PRE_DE,
				       pre_de_descr, in_info, out_infos, NULL);
	}

	if (pipe->stream->config.online) {
		pre_de_descr->online = true;
		pre_de_descr->two_ppc =
		    (pipe->stream->config.pixels_per_clock == 2);
		pre_de_descr->stream_format = pipe->stream->config.input_config.format;
	}
	pre_de_descr->isp_pipe_version = pipe->config.isp_pipe_version;
	IA_CSS_LEAVE_PRIVATE("");
}

void ia_css_pipe_get_pre_anr_binarydesc(
	struct ia_css_pipe const * const pipe,
	struct ia_css_binary_descr *pre_anr_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info)
{
	unsigned int i;
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];

	assert(pipe != NULL);
	assert(in_info != NULL);
	assert(out_info != NULL);
	IA_CSS_ENTER_PRIVATE("");

	*in_info = *out_info;
	in_info->format = IA_CSS_FRAME_FORMAT_RAW;
	in_info->raw_bit_depth = ia_css_pipe_util_pipe_input_format_bpp(pipe);
	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;

	pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_PRE_ISP,
			       pre_anr_descr, in_info, out_infos, NULL);

	if (pipe->stream->config.online) {
		pre_anr_descr->online = true;
		pre_anr_descr->two_ppc =
		    (pipe->stream->config.pixels_per_clock == 2);
		pre_anr_descr->stream_format = pipe->stream->config.input_config.format;
	}
	pre_anr_descr->isp_pipe_version = pipe->config.isp_pipe_version;
	IA_CSS_LEAVE_PRIVATE("");
}

void ia_css_pipe_get_anr_binarydesc(
	struct ia_css_pipe const * const pipe,
	struct ia_css_binary_descr *anr_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info)
{
	unsigned int i;
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];

	assert(pipe != NULL);
	assert(in_info != NULL);
	assert(out_info != NULL);
	IA_CSS_ENTER_PRIVATE("");

	*in_info = *out_info;
	in_info->format = IA_CSS_FRAME_FORMAT_RAW;
	in_info->raw_bit_depth = ANR_ELEMENT_BITS;
	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;

	pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_ANR,
			       anr_descr, in_info, out_infos, NULL);

	anr_descr->isp_pipe_version = pipe->config.isp_pipe_version;
	IA_CSS_LEAVE_PRIVATE("");
}


void ia_css_pipe_get_post_anr_binarydesc(
	struct ia_css_pipe const * const pipe,
	struct ia_css_binary_descr *post_anr_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info,
	struct ia_css_frame_info *vf_info)
{
	unsigned int i;
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];

	assert(pipe != NULL);
	assert(in_info != NULL);
	assert(out_info != NULL);
	assert(vf_info != NULL);
	IA_CSS_ENTER_PRIVATE("");

	*in_info = *out_info;
	in_info->format = IA_CSS_FRAME_FORMAT_RAW;
	in_info->raw_bit_depth = ANR_ELEMENT_BITS;
	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;

	pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_POST_ISP,
			       post_anr_descr, in_info, out_infos, vf_info);

	post_anr_descr->isp_pipe_version = pipe->config.isp_pipe_version;
	IA_CSS_LEAVE_PRIVATE("");
}

void ia_css_pipe_get_ldc_binarydesc(
	struct ia_css_pipe const * const pipe,
	struct ia_css_binary_descr *ldc_descr,
	struct ia_css_frame_info *in_info,
	struct ia_css_frame_info *out_info)
{
	unsigned int i;
	struct ia_css_frame_info *out_infos[IA_CSS_BINARY_MAX_OUTPUT_PORTS];

	assert(pipe != NULL);
	assert(in_info != NULL);
	assert(out_info != NULL);
	IA_CSS_ENTER_PRIVATE("");

#ifndef ISP2401
	*in_info = *out_info;
#else
	if (pipe->out_yuv_ds_input_info.res.width)
		*in_info = pipe->out_yuv_ds_input_info;
	else
		*in_info = *out_info;
#endif
	in_info->format = IA_CSS_FRAME_FORMAT_YUV420;
	in_info->raw_bit_depth = 0;
	ia_css_frame_info_set_width(in_info, in_info->res.width, 0);

	out_infos[0] = out_info;
	for (i = 1; i < IA_CSS_BINARY_MAX_OUTPUT_PORTS; i++)
		out_infos[i] = NULL;

	pipe_binarydesc_get_offline(pipe, IA_CSS_BINARY_MODE_CAPTURE_PP,
			       ldc_descr, in_info, out_infos, NULL);
	ldc_descr->enable_dvs_6axis =
		    pipe->extra_config.enable_dvs_6axis;
	IA_CSS_LEAVE_PRIVATE("");
}