iio: imu: nvi v.329 Fix ICM DMP period
Erik Lilliebjerg [Sun, 29 May 2016 12:16:55 +0000 (05:16 -0700)]
- Fix batch period calls that were getting dropped if the ICM DMP was enabled.

Bug 200199302

Change-Id: Iec7f9e4a8488890409d916bfecdaa98d12ac19f8
Signed-off-by: Erik Lilliebjerg <elilliebjerg@nvidia.com>
Reviewed-on: http://git-master/r/1155678
(cherry picked from commit f137e7d5218a2f2bd11479e3308eb701cdbe6a5b)
Reviewed-on: http://git-master/r/1185049
GVS: Gerrit_Virtual_Submit
Tested-by: Robert Collins <rcollins@nvidia.com>
Reviewed-by: Robert Collins <rcollins@nvidia.com>

drivers/iio/imu/nvi_mpu/nvi.c

index 1f75e16..b37b0d5 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "nvi.h"
 
-#define NVI_DRIVER_VERSION             (328)
+#define NVI_DRIVER_VERSION             (329)
 #define NVI_VENDOR                     "Invensense"
 #define NVI_NAME                       "mpu6xxx"
 #define NVI_NAME_MPU6050               "mpu6050"
@@ -3051,21 +3051,30 @@ static int nvi_batch(void *client, int snsr_id, int flags,
        if (snsr_id == DEV_TMP)
                return 0;
 
+       if (period == st->snsr[snsr_id].period_us &&
+                                      timeout == st->snsr[snsr_id].timeout_us)
+               return 0;
+
        st->snsr[snsr_id].period_us = period;
        st->snsr[snsr_id].timeout_us = timeout;
-       if (st->snsr[snsr_id].enable) {
-               ret = nvi_timeout(st);
-               if (st->en_msk & (1 << DEV_DMP) && st->hal->dmp->fn_dev_batch)
+       if (!st->snsr[snsr_id].enable)
+               return 0;
+
+       ret = nvi_timeout(st);
+       if (st->en_msk & (1 << DEV_DMP)) {
+               if (st->hal->dmp->fn_dev_batch)
                        /* batch can be done in real-time with the DMP on */
                        /* nvi_dd_batch */
-                       return st->hal->dmp->fn_dev_batch(st, snsr_id, -1);
-
+                       ret = st->hal->dmp->fn_dev_batch(st, snsr_id, -1);
+               else
+                       ret = nvi_en(st);
+       } else {
                ret |= nvi_period_src(st, st->hal->dev[snsr_id]->src);
                if (ret > 0)
-                       nvi_en(st);
+                       ret = nvi_en(st);
        }
 
-       return 0;
+       return ret;
 }
 
 static int nvi_flush(void *client, int snsr_id)