iio: imu: inv_mpu6050: update LPF bandwidth settings
authorJean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Thu, 6 Feb 2020 10:31:04 +0000 (11:31 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Fri, 14 Feb 2020 15:06:25 +0000 (15:06 +0000)
As every chip has some little variant in LPF bandwidth values,
use common values that are working for all chips.
Simplify the LPF setting function.

Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h

index 9ecc667debbe8992be510788fef151f69bc76962..c4db9086775ce1ceda49eba0b475450e4ece45e4 100644 (file)
@@ -707,30 +707,32 @@ error_write_raw_unlock:
 /**
  *  inv_mpu6050_set_lpf() - set low pass filer based on fifo rate.
  *
- *                  Based on the Nyquist principle, the sampling rate must
- *                  exceed twice of the bandwidth of the signal, or there
- *                  would be alising. This function basically search for the
- *                  correct low pass parameters based on the fifo rate, e.g,
- *                  sampling frequency.
+ *                  Based on the Nyquist principle, the bandwidth of the low
+ *                  pass filter must not exceed the signal sampling rate divided
+ *                  by 2, or there would be aliasing.
+ *                  This function basically search for the correct low pass
+ *                  parameters based on the fifo rate, e.g, sampling frequency.
  *
  *  lpf is set automatically when setting sampling rate to avoid any aliases.
  */
 static int inv_mpu6050_set_lpf(struct inv_mpu6050_state *st, int rate)
 {
-       static const int hz[] = {188, 98, 42, 20, 10, 5};
+       static const int hz[] = {400, 200, 90, 40, 20, 10};
        static const int d[] = {
-               INV_MPU6050_FILTER_188HZ, INV_MPU6050_FILTER_98HZ,
-               INV_MPU6050_FILTER_42HZ, INV_MPU6050_FILTER_20HZ,
+               INV_MPU6050_FILTER_200HZ, INV_MPU6050_FILTER_100HZ,
+               INV_MPU6050_FILTER_45HZ, INV_MPU6050_FILTER_20HZ,
                INV_MPU6050_FILTER_10HZ, INV_MPU6050_FILTER_5HZ
        };
-       int i, h, result;
+       int i, result;
        u8 data;
 
-       h = (rate >> 1);
-       i = 0;
-       while ((h < hz[i]) && (i < ARRAY_SIZE(d) - 1))
-               i++;
-       data = d[i];
+       data = INV_MPU6050_FILTER_5HZ;
+       for (i = 0; i < ARRAY_SIZE(hz); ++i) {
+               if (rate >= hz[i]) {
+                       data = d[i];
+                       break;
+               }
+       }
        result = inv_mpu6050_set_lpf_regs(st, data);
        if (result)
                return result;
index 7ae614052210a8522e04f4ffb595d3e104bf06bc..9a81098a8b4df64a16c114402bb2e3c3aa566f1d 100644 (file)
@@ -370,14 +370,14 @@ enum inv_mpu6050_scan {
 };
 
 enum inv_mpu6050_filter_e {
-       INV_MPU6050_FILTER_256HZ_NOLPF2 = 0,
-       INV_MPU6050_FILTER_188HZ,
-       INV_MPU6050_FILTER_98HZ,
-       INV_MPU6050_FILTER_42HZ,
+       INV_MPU6050_FILTER_NOLPF2 = 0,
+       INV_MPU6050_FILTER_200HZ,
+       INV_MPU6050_FILTER_100HZ,
+       INV_MPU6050_FILTER_45HZ,
        INV_MPU6050_FILTER_20HZ,
        INV_MPU6050_FILTER_10HZ,
        INV_MPU6050_FILTER_5HZ,
-       INV_MPU6050_FILTER_2100HZ_NOLPF,
+       INV_MPU6050_FILTER_NOLPF,
        NUM_MPU6050_FILTER
 };