Skip to content

Commit 8d502ef

Browse files
opendata26jic23
authored andcommitted
fixp-arith: add a linear interpolation function
Adds a function to interpolate against two points, this is carried arount as a helper function by tons of drivers. Signed-off-by: Craig Tatlor <ctatlor97@gmail.com> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> Link: https://lore.kernel.org/r/20201204025509.1075506-3-dmitry.baryshkov@linaro.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 5c8fe58 commit 8d502ef

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

include/linux/fixp-arith.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,23 @@ static inline s32 fixp_sin32_rad(u32 radians, u32 twopi)
141141
#define fixp_cos32_rad(rad, twopi) \
142142
fixp_sin32_rad(rad + twopi / 4, twopi)
143143

144+
/**
145+
* fixp_linear_interpolate() - interpolates a value from two known points
146+
*
147+
* @x0: x value of point 0
148+
* @y0: y value of point 0
149+
* @x1: x value of point 1
150+
* @y1: y value of point 1
151+
* @x: the linear interpolant
152+
*/
153+
static inline int fixp_linear_interpolate(int x0, int y0, int x1, int y1, int x)
154+
{
155+
if (y0 == y1 || x == x0)
156+
return y0;
157+
if (x1 == x0 || x == x1)
158+
return y1;
159+
160+
return y0 + ((y1 - y0) * (x - x0) / (x1 - x0));
161+
}
162+
144163
#endif

0 commit comments

Comments
 (0)