]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.37/iio-cros_ec-fix-the-maths-for-gyro-scale-calculation.patch
Linux 4.14.114
[thirdparty/kernel/stable-queue.git] / releases / 4.19.37 / iio-cros_ec-fix-the-maths-for-gyro-scale-calculation.patch
1 From 3d02d7082e5823598090530c3988a35f69689943 Mon Sep 17 00:00:00 2001
2 From: Gwendal Grignou <gwendal@chromium.org>
3 Date: Wed, 13 Mar 2019 12:40:02 +0100
4 Subject: iio: cros_ec: Fix the maths for gyro scale calculation
5
6 From: Gwendal Grignou <gwendal@chromium.org>
7
8 commit 3d02d7082e5823598090530c3988a35f69689943 upstream.
9
10 Calculation did not use IIO_DEGREE_TO_RAD and implemented a variant to
11 avoid precision loss as we aim a nano value. The offset added to avoid
12 rounding error, though, doesn't give us a close result to the expected
13 value. E.g.
14
15 For 1000dps, the result should be:
16
17 (1000 * pi ) / 180 >> 15 ~= 0.000532632218
18
19 But with current calculation we get
20
21 $ cat scale
22 0.000547890
23
24 Fix the calculation by just doing the maths involved for a nano value
25
26 val * pi * 10e12 / (180 * 2^15)
27
28 so we get a closer result.
29
30 $ cat scale
31 0.000532632
32
33 Fixes: c14dca07a31d ("iio: cros_ec_sensors: add ChromeOS EC Contiguous Sensors driver")
34 Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
35 Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
36 Cc: <Stable@vger.kernel.org>
37 Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
38 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
39
40 ---
41 drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c | 7 ++++---
42 1 file changed, 4 insertions(+), 3 deletions(-)
43
44 --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
45 +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
46 @@ -103,9 +103,10 @@ static int cros_ec_sensors_read(struct i
47 * Do not use IIO_DEGREE_TO_RAD to avoid precision
48 * loss. Round to the nearest integer.
49 */
50 - *val = div_s64(val64 * 314159 + 9000000ULL, 1000);
51 - *val2 = 18000 << (CROS_EC_SENSOR_BITS - 1);
52 - ret = IIO_VAL_FRACTIONAL;
53 + *val = 0;
54 + *val2 = div_s64(val64 * 3141592653ULL,
55 + 180 << (CROS_EC_SENSOR_BITS - 1));
56 + ret = IIO_VAL_INT_PLUS_NANO;
57 break;
58 case MOTIONSENSE_TYPE_MAG:
59 /*