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