Skip to content

Commit 143fd8f

Browse files
andy-shevHans Verkuil
authored andcommitted
media: atomisp: Clean up unused macros from math_support.h
Clean up unused macros from math_support.h and replace rarely used by generic ones from Linux kernel headers. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent e323de4 commit 143fd8f

File tree

7 files changed

+20
-139
lines changed

7 files changed

+20
-139
lines changed

drivers/staging/media/atomisp/pci/camera/util/interface/ia_css_util.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,6 @@ bool ia_css_util_res_leq(
100100
bool ia_css_util_resolution_is_zero(
101101
const struct ia_css_resolution resolution);
102102

103-
/* ISP2401 */
104-
/**
105-
* @brief Check if resolution is even
106-
*
107-
* @param[in] resolution The resolution to check
108-
*
109-
* @returns true if resolution is even
110-
*/
111-
bool ia_css_util_resolution_is_even(
112-
const struct ia_css_resolution resolution);
113-
114103
/* @brief check width and height
115104
*
116105
* @param[in] stream_format

drivers/staging/media/atomisp/pci/camera/util/src/util.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,6 @@ int ia_css_util_check_vf_out_info(
119119
return 0;
120120
}
121121

122-
int ia_css_util_check_res(unsigned int width, unsigned int height)
123-
{
124-
/* height can be odd number for jpeg/embedded data from ISYS2401 */
125-
if (((width == 0) ||
126-
(height == 0) ||
127-
IS_ODD(width))) {
128-
return -EINVAL;
129-
}
130-
return 0;
131-
}
132-
133122
/* ISP2401 */
134123
bool ia_css_util_res_leq(struct ia_css_resolution a, struct ia_css_resolution b)
135124
{
@@ -142,10 +131,18 @@ bool ia_css_util_resolution_is_zero(const struct ia_css_resolution resolution)
142131
return (resolution.width == 0) || (resolution.height == 0);
143132
}
144133

145-
/* ISP2401 */
146-
bool ia_css_util_resolution_is_even(const struct ia_css_resolution resolution)
134+
int ia_css_util_check_res(unsigned int width, unsigned int height)
147135
{
148-
return IS_EVEN(resolution.height) && IS_EVEN(resolution.width);
136+
const struct ia_css_resolution resolution = { .width = width, .height = height };
137+
138+
if (ia_css_util_resolution_is_zero(resolution))
139+
return -EINVAL;
140+
141+
/* height can be odd number for jpeg/embedded data from ISYS2401 */
142+
if (width & 1)
143+
return -EINVAL;
144+
145+
return 0;
149146
}
150147

151148
bool ia_css_util_is_input_format_raw(enum atomisp_input_format format)

drivers/staging/media/atomisp/pci/hive_isp_css_include/math_support.h

Lines changed: 2 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -16,133 +16,27 @@
1616
#ifndef __MATH_SUPPORT_H
1717
#define __MATH_SUPPORT_H
1818

19-
#include <linux/kernel.h> /* Override the definition of max/min from linux kernel*/
20-
21-
#define IS_ODD(a) ((a) & 0x1)
22-
#define IS_EVEN(a) (!IS_ODD(a))
19+
/* Override the definition of max/min from Linux kernel */
20+
#include <linux/minmax.h>
2321

2422
/* force a value to a lower even value */
2523
#define EVEN_FLOOR(x) ((x) & ~1)
2624

27-
/* ISP2401 */
28-
/* If the number is odd, find the next even number */
29-
#define EVEN_CEIL(x) ((IS_ODD(x)) ? ((x) + 1) : (x))
30-
31-
/* A => B */
32-
#define IMPLIES(a, b) (!(a) || (b))
33-
3425
/* for preprocessor and array sizing use MIN and MAX
3526
otherwise use min and max */
3627
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
3728
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
3829

39-
#define ROUND_DIV(a, b) (((b) != 0) ? ((a) + ((b) >> 1)) / (b) : 0)
4030
#define CEIL_DIV(a, b) (((b) != 0) ? ((a) + (b) - 1) / (b) : 0)
4131
#define CEIL_MUL(a, b) (CEIL_DIV(a, b) * (b))
4232
#define CEIL_MUL2(a, b) (((a) + (b) - 1) & ~((b) - 1))
4333
#define CEIL_SHIFT(a, b) (((a) + (1 << (b)) - 1) >> (b))
4434
#define CEIL_SHIFT_MUL(a, b) (CEIL_SHIFT(a, b) << (b))
45-
#define ROUND_HALF_DOWN_DIV(a, b) (((b) != 0) ? ((a) + (b / 2) - 1) / (b) : 0)
46-
#define ROUND_HALF_DOWN_MUL(a, b) (ROUND_HALF_DOWN_DIV(a, b) * (b))
47-
48-
/*To Find next power of 2 number from x */
49-
#define bit2(x) ((x) | ((x) >> 1))
50-
#define bit4(x) (bit2(x) | (bit2(x) >> 2))
51-
#define bit8(x) (bit4(x) | (bit4(x) >> 4))
52-
#define bit16(x) (bit8(x) | (bit8(x) >> 8))
53-
#define bit32(x) (bit16(x) | (bit16(x) >> 16))
54-
#define NEXT_POWER_OF_2(x) (bit32(x - 1) + 1)
55-
56-
/* min and max should not be macros as they will evaluate their arguments twice.
57-
if you really need a macro (e.g. for CPP or for initializing an array)
58-
use MIN() and MAX(), otherwise use min() and max().
59-
60-
*/
6135

6236
#if !defined(PIPE_GENERATION)
6337

64-
/*
65-
This macro versions are added back as we are mixing types in usage of inline.
66-
This causes corner cases of calculations to be incorrect due to conversions
67-
between signed and unsigned variables or overflows.
68-
Before the addition of the inline functions, max, min and ceil_div were macros
69-
and therefore adding them back.
70-
71-
Leaving out the other math utility functions as they are newly added
72-
*/
73-
7438
#define ceil_div(a, b) (CEIL_DIV(a, b))
7539

76-
static inline unsigned int ceil_mul(unsigned int a, unsigned int b)
77-
{
78-
return CEIL_MUL(a, b);
79-
}
80-
81-
static inline unsigned int ceil_mul2(unsigned int a, unsigned int b)
82-
{
83-
return CEIL_MUL2(a, b);
84-
}
85-
86-
static inline unsigned int ceil_shift(unsigned int a, unsigned int b)
87-
{
88-
return CEIL_SHIFT(a, b);
89-
}
90-
91-
static inline unsigned int ceil_shift_mul(unsigned int a, unsigned int b)
92-
{
93-
return CEIL_SHIFT_MUL(a, b);
94-
}
95-
96-
/* ISP2401 */
97-
static inline unsigned int round_half_down_div(unsigned int a, unsigned int b)
98-
{
99-
return ROUND_HALF_DOWN_DIV(a, b);
100-
}
101-
102-
/* ISP2401 */
103-
static inline unsigned int round_half_down_mul(unsigned int a, unsigned int b)
104-
{
105-
return ROUND_HALF_DOWN_MUL(a, b);
106-
}
107-
108-
/* @brief Next Power of Two
109-
*
110-
* @param[in] unsigned number
111-
*
112-
* @return next power of two
113-
*
114-
* This function rounds input to the nearest power of 2 (2^x)
115-
* towards infinity
116-
*
117-
* Input Range: 0 .. 2^(8*sizeof(int)-1)
118-
*
119-
* IF input is a power of 2
120-
* out = in
121-
* OTHERWISE
122-
* out = 2^(ceil(log2(in))
123-
*
124-
*/
125-
126-
static inline unsigned int ceil_pow2(unsigned int a)
127-
{
128-
if (a == 0) {
129-
return 1;
130-
}
131-
/* IF input is already a power of two*/
132-
else if ((!((a) & ((a) - 1)))) {
133-
return a;
134-
} else {
135-
unsigned int v = a;
136-
137-
v |= v >> 1;
138-
v |= v >> 2;
139-
v |= v >> 4;
140-
v |= v >> 8;
141-
v |= v >> 16;
142-
return (v + 1);
143-
}
144-
}
145-
14640
#endif /* !defined(PIPE_GENERATION) */
14741

14842
/*

drivers/staging/media/atomisp/pci/ia_css_3a.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* This file contains types used for 3A statistics
2121
*/
2222

23+
#include <math_support.h>
2324
#include <type_support.h>
2425
#include "ia_css_types.h"
2526
#include "ia_css_err.h"

drivers/staging/media/atomisp/pci/isp/kernels/xnr/xnr_3.0/ia_css_xnr3.host.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* more details.
1414
*/
1515

16+
#include <linux/log2.h>
17+
1618
#include "type_support.h"
1719
#include "math_support.h"
1820
#include "sh_css_defs.h"
@@ -137,9 +139,7 @@ ia_css_xnr3_encode(
137139
unsigned int size)
138140
{
139141
int kernel_size = XNR_FILTER_SIZE;
140-
/* The adjust factor is the next power of 2
141-
w.r.t. the kernel size*/
142-
int adjust_factor = ceil_pow2(kernel_size);
142+
int adjust_factor = roundup_pow_of_two(kernel_size);
143143
s32 max_diff = (1 << (ISP_VEC_ELEMBITS - 1)) - 1;
144144
s32 min_diff = -(1 << (ISP_VEC_ELEMBITS - 1));
145145

drivers/staging/media/atomisp/pci/runtime/binary/src/binary.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343

4444
#include "assert_support.h"
4545

46-
#define IMPLIES(a, b) (!(a) || (b)) /* A => B */
47-
4846
static struct ia_css_binary_xinfo *all_binaries; /* ISP binaries only (no SP) */
4947
static struct ia_css_binary_xinfo
5048
*binary_infos[IA_CSS_BINARY_NUM_MODES] = { NULL, };

drivers/staging/media/atomisp/pci/sh_css_frac.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#ifndef __SH_CSS_FRAC_H
1717
#define __SH_CSS_FRAC_H
1818

19-
#include <math_support.h>
19+
#include <linux/minmax.h>
20+
21+
#include "mamoiada_params.h"
2022

2123
#define sISP_REG_BIT ISP_VEC_ELEMBITS
2224
#define uISP_REG_BIT ((unsigned int)(sISP_REG_BIT - 1))

0 commit comments

Comments
 (0)