summaryrefslogtreecommitdiff
path: root/include/linux/fixp-arith.h
diff options
context:
space:
mode:
authorCraig Tatlor <ctatlor97@gmail.com>2020-12-04 05:54:56 +0300
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2021-01-16 18:14:53 +0000
commit8d502ef682fdbe0ddf2274dae903b07baf1140e0 (patch)
tree40975646c1d54a580aa5df8770bc9944dc88e1f5 /include/linux/fixp-arith.h
parent5c8fe583cce542aa0b84adc939ce85293de36e5e (diff)
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>
Diffstat (limited to 'include/linux/fixp-arith.h')
-rw-r--r--include/linux/fixp-arith.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/linux/fixp-arith.h b/include/linux/fixp-arith.h
index 8396013785ef..281cb4f83dbe 100644
--- a/include/linux/fixp-arith.h
+++ b/include/linux/fixp-arith.h
@@ -141,4 +141,23 @@ static inline s32 fixp_sin32_rad(u32 radians, u32 twopi)
#define fixp_cos32_rad(rad, twopi) \
fixp_sin32_rad(rad + twopi / 4, twopi)
+/**
+ * fixp_linear_interpolate() - interpolates a value from two known points
+ *
+ * @x0: x value of point 0
+ * @y0: y value of point 0
+ * @x1: x value of point 1
+ * @y1: y value of point 1
+ * @x: the linear interpolant
+ */
+static inline int fixp_linear_interpolate(int x0, int y0, int x1, int y1, int x)
+{
+ if (y0 == y1 || x == x0)
+ return y0;
+ if (x1 == x0 || x == x1)
+ return y1;
+
+ return y0 + ((y1 - y0) * (x - x0) / (x1 - x0));
+}
+
#endif