diff mbox series

[v2,4/9] iio: adc: qcom-vadc-common: use fixp_linear_interpolate

Message ID 20200903132109.1914011-5-dmitry.baryshkov@linaro.org
State Superseded
Headers show
Series None | expand

Commit Message

Dmitry Baryshkov Sept. 3, 2020, 1:21 p.m. UTC
Use new function fixp_linear_interpolate() instead of hand-coding the
linar interpolation.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

---
 drivers/iio/adc/qcom-vadc-common.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

-- 
2.28.0

Comments

Andy Shevchenko Sept. 3, 2020, 7:38 p.m. UTC | #1
On Thu, Sep 3, 2020 at 5:33 PM Dmitry Baryshkov
<dmitry.baryshkov@linaro.org> wrote:
>

> Use new function fixp_linear_interpolate() instead of hand-coding the

> linar interpolation.


...

>                 /* result is between search_index and search_index-1 */

>                 /* interpolate linearly */

> -               *output = (((s32)((pts[i].y - pts[i - 1].y) *

> -                       (input - pts[i - 1].x)) /

> -                       (pts[i].x - pts[i - 1].x)) +

> -                       pts[i - 1].y);

> +               *output = fixp_linear_interpolate(pts[i - 1].x, pts[i - 1].y,

> +                                                 pts[i].x, pts[i].y,

> +                                                 input);


I'm wondering if it's related to linear_range.h API
https://elixir.bootlin.com/linux/latest/source/include/linux/linear_range.h


>         }

>

>         return 0;



-- 
With Best Regards,
Andy Shevchenko
diff mbox series

Patch

diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c
index d11f3343ad52..40d77b3af1bb 100644
--- a/drivers/iio/adc/qcom-vadc-common.c
+++ b/drivers/iio/adc/qcom-vadc-common.c
@@ -2,6 +2,7 @@ 
 #include <linux/bug.h>
 #include <linux/kernel.h>
 #include <linux/bitops.h>
+#include <linux/fixp-arith.h>
 #include <linux/math64.h>
 #include <linux/log2.h>
 #include <linux/err.h>
@@ -368,10 +369,9 @@  static int qcom_vadc_map_voltage_temp(const struct vadc_map_pt *pts,
 	} else {
 		/* result is between search_index and search_index-1 */
 		/* interpolate linearly */
-		*output = (((s32)((pts[i].y - pts[i - 1].y) *
-			(input - pts[i - 1].x)) /
-			(pts[i].x - pts[i - 1].x)) +
-			pts[i - 1].y);
+		*output = fixp_linear_interpolate(pts[i - 1].x, pts[i - 1].y,
+						  pts[i].x, pts[i].y,
+						  input);
 	}
 
 	return 0;