Commit 387210ed authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Mauro Carvalho Chehab

media: atomisp: Make bds_factors_list be type of struct u32_fract

The list contains the Bayer scale index, and rational fraction of it.
The struct u32_fract is suitable type to hold that. Convert the driver
to use latter instead of former.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent 6f5c0baf
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#ifndef __IA_CSS_PIPE_BINARYDESC_H__ #ifndef __IA_CSS_PIPE_BINARYDESC_H__
#define __IA_CSS_PIPE_BINARYDESC_H__ #define __IA_CSS_PIPE_BINARYDESC_H__
#include <linux/math.h>
#include <ia_css_types.h> /* ia_css_pipe */ #include <ia_css_types.h> /* ia_css_pipe */
#include <ia_css_frame_public.h> /* ia_css_frame_info */ #include <ia_css_frame_public.h> /* ia_css_frame_info */
#include <ia_css_binary.h> /* ia_css_binary_descr */ #include <ia_css_binary.h> /* ia_css_binary_descr */
...@@ -56,17 +58,12 @@ void ia_css_pipe_get_vfpp_binarydesc( ...@@ -56,17 +58,12 @@ void ia_css_pipe_get_vfpp_binarydesc(
* *
* @param[in] bds_factor: The bayer downscaling factor. * @param[in] bds_factor: The bayer downscaling factor.
* (= The bds_factor member in the sh_css_bds_factor structure.) * (= The bds_factor member in the sh_css_bds_factor structure.)
* @param[out] bds_factor_numerator: The numerator of the bayer downscaling factor. * @param[out] bds: The rational fraction of the bayer downscaling factor.
* (= The numerator member in the sh_css_bds_factor structure.) * (= The respective member in the sh_css_bds_factor structure.)
* @param[out] bds_factor_denominator: The denominator of the bayer downscaling factor.
* (= The denominator member in the sh_css_bds_factor structure.)
* @return 0 or error code upon error. * @return 0 or error code upon error.
* *
*/ */
int sh_css_bds_factor_get_numerator_denominator( int sh_css_bds_factor_get_fract(unsigned int bds_factor, struct u32_fract *bds);
unsigned int bds_factor,
unsigned int *bds_factor_numerator,
unsigned int *bds_factor_denominator);
/* @brief Get a binary descriptor for preview stage. /* @brief Get a binary descriptor for preview stage.
* *
......
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
* more details. * more details.
*/ */
#include <linux/kernel.h>
#include <linux/math.h>
#include "ia_css_pipe_binarydesc.h" #include "ia_css_pipe_binarydesc.h"
#include "ia_css_frame_format.h" #include "ia_css_frame_format.h"
#include "ia_css_pipe.h" #include "ia_css_pipe.h"
...@@ -23,7 +26,6 @@ ...@@ -23,7 +26,6 @@
#include <assert_support.h> #include <assert_support.h>
/* HRT_GDC_N */ /* HRT_GDC_N */
#include "gdc_device.h" #include "gdc_device.h"
#include <linux/kernel.h>
/* This module provides a binary descriptions to used to find a binary. Since, /* This module provides a binary descriptions to used to find a binary. Since,
* every stage is associated with a binary, it implicity helps stage * every stage is associated with a binary, it implicity helps stage
...@@ -126,40 +128,29 @@ void ia_css_pipe_get_vfpp_binarydesc( ...@@ -126,40 +128,29 @@ void ia_css_pipe_get_vfpp_binarydesc(
IA_CSS_LEAVE_PRIVATE(""); IA_CSS_LEAVE_PRIVATE("");
} }
static struct sh_css_bds_factor bds_factors_list[] = { static struct u32_fract bds_factors_list[] = {
{1, 1, SH_CSS_BDS_FACTOR_1_00}, [SH_CSS_BDS_FACTOR_1_00] = {1, 1},
{5, 4, SH_CSS_BDS_FACTOR_1_25}, [SH_CSS_BDS_FACTOR_1_25] = {5, 4},
{3, 2, SH_CSS_BDS_FACTOR_1_50}, [SH_CSS_BDS_FACTOR_1_50] = {3, 2},
{2, 1, SH_CSS_BDS_FACTOR_2_00}, [SH_CSS_BDS_FACTOR_2_00] = {2, 1},
{9, 4, SH_CSS_BDS_FACTOR_2_25}, [SH_CSS_BDS_FACTOR_2_25] = {9, 4},
{5, 2, SH_CSS_BDS_FACTOR_2_50}, [SH_CSS_BDS_FACTOR_2_50] = {5, 2},
{3, 1, SH_CSS_BDS_FACTOR_3_00}, [SH_CSS_BDS_FACTOR_3_00] = {3, 1},
{4, 1, SH_CSS_BDS_FACTOR_4_00}, [SH_CSS_BDS_FACTOR_4_00] = {4, 1},
{9, 2, SH_CSS_BDS_FACTOR_4_50}, [SH_CSS_BDS_FACTOR_4_50] = {9, 2},
{5, 1, SH_CSS_BDS_FACTOR_5_00}, [SH_CSS_BDS_FACTOR_5_00] = {5, 1},
{6, 1, SH_CSS_BDS_FACTOR_6_00}, [SH_CSS_BDS_FACTOR_6_00] = {6, 1},
{8, 1, SH_CSS_BDS_FACTOR_8_00} [SH_CSS_BDS_FACTOR_8_00] = {8, 1},
}; };
int sh_css_bds_factor_get_numerator_denominator( int sh_css_bds_factor_get_fract(unsigned int bds_factor, struct u32_fract *bds)
unsigned int bds_factor,
unsigned int *bds_factor_numerator,
unsigned int *bds_factor_denominator)
{ {
unsigned int i; /* Throw an error since bds_factor cannot be found in bds_factors_list */
if (bds_factor >= ARRAY_SIZE(bds_factors_list))
/* Loop over all bds factors until a match is found */ return -EINVAL;
for (i = 0; i < ARRAY_SIZE(bds_factors_list); 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 0;
}
}
/* Throw an error since bds_factor cannot be found *bds = bds_factors_list[bds_factor];
in bds_factors_list */ return 0;
return -EINVAL;
} }
int binarydesc_calculate_bds_factor( int binarydesc_calculate_bds_factor(
...@@ -194,7 +185,7 @@ int binarydesc_calculate_bds_factor( ...@@ -194,7 +185,7 @@ int binarydesc_calculate_bds_factor(
(out_h * num / den <= in_h); (out_h * num / den <= in_h);
if (cond) { if (cond) {
*bds_factor = bds_factors_list[i].bds_factor; *bds_factor = i;
return 0; return 0;
} }
} }
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
* more details. * more details.
*/ */
#include <linux/math.h>
#include <math_support.h> #include <math_support.h>
#include <gdc_device.h> /* HR_GDC_N */ #include <gdc_device.h> /* HR_GDC_N */
...@@ -128,16 +130,8 @@ ia_css_binary_compute_shading_table_bayer_origin( ...@@ -128,16 +130,8 @@ ia_css_binary_compute_shading_table_bayer_origin(
{ {
int err; int err;
/* Numerator and denominator of the fixed bayer downscaling factor. /* Rational fraction of the fixed bayer downscaling factor. */
(numerator >= denominator) */ struct u32_fract bds;
unsigned int bds_num, bds_den;
/* Horizontal/Vertical ratio of bayer scaling
between input area and output area. */
unsigned int bs_hor_ratio_in;
unsigned int bs_hor_ratio_out;
unsigned int bs_ver_ratio_in;
unsigned int bs_ver_ratio_out;
/* Left padding set by InputFormatter. */ /* Left padding set by InputFormatter. */
unsigned int left_padding_bqs; /* in bqs */ unsigned int left_padding_bqs; /* in bqs */
...@@ -158,19 +152,11 @@ ia_css_binary_compute_shading_table_bayer_origin( ...@@ -158,19 +152,11 @@ ia_css_binary_compute_shading_table_bayer_origin(
unsigned int bad_bqs_on_top_before_bs; /* in bqs */ unsigned int bad_bqs_on_top_before_bs; /* in bqs */
unsigned int bad_bqs_on_top_after_bs; /* in bqs */ unsigned int bad_bqs_on_top_after_bs; /* in bqs */
/* Get the numerator and denominator of bayer downscaling factor. */ /* Get the rational fraction of bayer downscaling factor. */
err = sh_css_bds_factor_get_numerator_denominator err = sh_css_bds_factor_get_fract(required_bds_factor, &bds);
(required_bds_factor, &bds_num, &bds_den);
if (err) if (err)
return err; return err;
/* Set the horizontal/vertical ratio of bayer scaling
between input area and output area. */
bs_hor_ratio_in = bds_num;
bs_hor_ratio_out = bds_den;
bs_ver_ratio_in = bds_num;
bs_ver_ratio_out = bds_den;
/* Set the left padding set by InputFormatter. (ifmtr.c) */ /* Set the left padding set by InputFormatter. (ifmtr.c) */
if (stream_config->left_padding == -1) if (stream_config->left_padding == -1)
left_padding_bqs = _ISP_BQS(binary->left_padding); left_padding_bqs = _ISP_BQS(binary->left_padding);
...@@ -228,18 +214,18 @@ ia_css_binary_compute_shading_table_bayer_origin( ...@@ -228,18 +214,18 @@ ia_css_binary_compute_shading_table_bayer_origin(
located on the shading table during the shading correction. */ located on the shading table during the shading correction. */
res->sc_bayer_origin_x_bqs_on_shading_table = res->sc_bayer_origin_x_bqs_on_shading_table =
((left_padding_adjusted_bqs + bad_bqs_on_left_before_bs) ((left_padding_adjusted_bqs + bad_bqs_on_left_before_bs)
* bs_hor_ratio_out + bs_hor_ratio_in / 2) / bs_hor_ratio_in * bds.denominator + bds.numerator / 2) / bds.numerator
+ bad_bqs_on_left_after_bs; + bad_bqs_on_left_after_bs;
/* "+ bs_hor_ratio_in/2": rounding for division by bs_hor_ratio_in */ /* "+ bds.numerator / 2": rounding for division by bds.numerator */
res->sc_bayer_origin_y_bqs_on_shading_table = res->sc_bayer_origin_y_bqs_on_shading_table =
(bad_bqs_on_top_before_bs * bs_ver_ratio_out + bs_ver_ratio_in / 2) / bs_ver_ratio_in (bad_bqs_on_top_before_bs * bds.denominator + bds.numerator / 2) / bds.numerator
+ bad_bqs_on_top_after_bs; + bad_bqs_on_top_after_bs;
/* "+ bs_ver_ratio_in/2": rounding for division by bs_ver_ratio_in */ /* "+ bds.numerator / 2": rounding for division by bds.numerator */
res->bayer_scale_hor_ratio_in = (uint32_t)bs_hor_ratio_in; res->bayer_scale_hor_ratio_in = bds.numerator;
res->bayer_scale_hor_ratio_out = (uint32_t)bs_hor_ratio_out; res->bayer_scale_hor_ratio_out = bds.denominator;
res->bayer_scale_ver_ratio_in = (uint32_t)bs_ver_ratio_in; res->bayer_scale_ver_ratio_in = bds.numerator;
res->bayer_scale_ver_ratio_out = (uint32_t)bs_ver_ratio_out; res->bayer_scale_ver_ratio_out = bds.denominator;
return err; return err;
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* more details. * more details.
*/ */
#include <linux/math.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <math_support.h> #include <math_support.h>
...@@ -239,10 +240,9 @@ prepare_shading_table(const struct ia_css_shading_table *in_table, ...@@ -239,10 +240,9 @@ prepare_shading_table(const struct ia_css_shading_table *in_table,
{ {
unsigned int input_width, input_height, table_width, table_height, i; unsigned int input_width, input_height, table_width, table_height, i;
unsigned int left_padding, top_padding, left_cropping; unsigned int left_padding, top_padding, left_cropping;
unsigned int bds_numerator, bds_denominator;
int right_padding;
struct ia_css_shading_table *result; struct ia_css_shading_table *result;
struct u32_fract bds;
int right_padding;
assert(target_table); assert(target_table);
assert(binary); assert(binary);
...@@ -265,17 +265,16 @@ prepare_shading_table(const struct ia_css_shading_table *in_table, ...@@ -265,17 +265,16 @@ prepare_shading_table(const struct ia_css_shading_table *in_table,
left_cropping = (binary->info->sp.pipeline.left_cropping == 0) ? left_cropping = (binary->info->sp.pipeline.left_cropping == 0) ?
binary->dvs_envelope.width : 2 * ISP_VEC_NELEMS; binary->dvs_envelope.width : 2 * ISP_VEC_NELEMS;
sh_css_bds_factor_get_numerator_denominator sh_css_bds_factor_get_fract(bds_factor, &bds);
(bds_factor, &bds_numerator, &bds_denominator);
left_padding = (left_padding + binary->info->sp.pipeline.left_cropping) * left_padding = (left_padding + binary->info->sp.pipeline.left_cropping) *
bds_numerator / bds_denominator - bds.numerator / bds.denominator -
binary->info->sp.pipeline.left_cropping; binary->info->sp.pipeline.left_cropping;
right_padding = (binary->internal_frame_info.res.width - right_padding = (binary->internal_frame_info.res.width -
binary->effective_in_frame_res.width * bds_denominator / binary->effective_in_frame_res.width * bds.denominator /
bds_numerator - left_cropping) * bds_numerator / bds_denominator; bds.numerator - left_cropping) * bds.numerator / bds.denominator;
top_padding = binary->info->sp.pipeline.top_cropping * bds_numerator / top_padding = binary->info->sp.pipeline.top_cropping * bds.numerator /
bds_denominator - bds.denominator -
binary->info->sp.pipeline.top_cropping; binary->info->sp.pipeline.top_cropping;
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment