Skip to contentSkip to conversation

Clear timestamp kfifo on trigger enabling

PATCH In review Viorel Suman 2 participants 3 messages Feb 16, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Clear timestamp kfifo on trigger enabling

The timestamp kfifo must be cleared once the hardware fifo is reset, thus are removed timestamps related to unprocessed events from hardware fifo - see "inv_mpu6050_read_fifo" method implementation.

---
 drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 28 +++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +16 -12
index 926fcce..b617920 100644
@@ -42,57 +42,61 @@ static void inv_scan_query(struct iio_dev *indio_dev)
 static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable)
 {
 	struct inv_mpu6050_state *st = iio_priv(indio_dev);
-	int result;
+	int result = 0;
 
+	mutex_lock(&indio_dev->mlock);
 	if (enable) {
 		result = inv_mpu6050_set_power_itg(st, true);
 		if (result)
-			return result;
+			goto write_error;
 		inv_scan_query(indio_dev);
 		if (st->chip_config.gyro_fifo_enable) {
 			result = inv_mpu6050_switch_engine(st, true,
 					INV_MPU6050_BIT_PWR_GYRO_STBY);
 			if (result)
-				return result;
+				goto write_error;
 		}
 		if (st->chip_config.accl_fifo_enable) {
 			result = inv_mpu6050_switch_engine(st, true,
 					INV_MPU6050_BIT_PWR_ACCL_STBY);
 			if (result)
-				return result;
+				goto write_error;
 		}
+		inv_clear_kfifo(st);
 		result = inv_reset_fifo(indio_dev);
 		if (result)
-			return result;
+			goto write_error;
 	} else {
 		result = inv_mpu6050_write_reg(st, st->reg->fifo_en, 0);
 		if (result)
-			return result;
+			goto write_error;
 
 		result = inv_mpu6050_write_reg(st, st->reg->int_enable, 0);
 		if (result)
-			return result;
+			goto write_error;
 
 		result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, 0);
 		if (result)
-			return result;
+			goto write_error;
 
 		result = inv_mpu6050_switch_engine(st, false,
 					INV_MPU6050_BIT_PWR_GYRO_STBY);
 		if (result)
-			return result;
+			goto write_error;
 
 		result = inv_mpu6050_switch_engine(st, false,
 					INV_MPU6050_BIT_PWR_ACCL_STBY);
 		if (result)
-			return result;
+			goto write_error;
 		result = inv_mpu6050_set_power_itg(st, false);
 		if (result)
-			return result;
+			goto write_error;
 	}
 	st->chip_config.enable = enable;
+write_error:
+	mutex_unlock(&indio_dev->mlock);
 
-	return 0;
+	return result;
 }
 
 /**
Signature · 1 line
2.3.0
#1 lore raw
Quoted 6 lines

The timestamp kfifo must be cleared once the hardware fifo is reset, thus are removed timestamps related to unprocessed events from hardware fifo - see "inv_mpu6050_read_fifo" method implementation.

comments below
a prefix iio: in the subject would be nice

Quoted 10 lines
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 28 +++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +0 -0
index 926fcce..b617920 100644

drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c static void inv_scan_query(struct iio_dev *indio_dev) · line 45

Quoted 5 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +1 -1
@@ -42,57 +42,61 @@ static void inv_scan_query(struct iio_dev *indio_dev)
 static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable)
 {
 	struct inv_mpu6050_state *st = iio_priv(indio_dev);
-	int result;
+	int result = 0;

no need to init result

the mutex could be obtained in the caller, i.e. inv_mpu_data_rdy_trigger_set_state(), simplifying the code and drastically reducing the size of this patch

the patch description does not explain a mutex is (now?) needed; probably this should be split out as a separate patch

Quoted 69 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +15 -11
+	mutex_lock(&indio_dev->mlock);
 	if (enable) {
 		result = inv_mpu6050_set_power_itg(st, true);
 		if (result)
-			return result;
+			goto write_error;
 		inv_scan_query(indio_dev);
 		if (st->chip_config.gyro_fifo_enable) {
 			result = inv_mpu6050_switch_engine(st, true,
 					INV_MPU6050_BIT_PWR_GYRO_STBY);
 			if (result)
-				return result;
+				goto write_error;
 		}
 		if (st->chip_config.accl_fifo_enable) {
 			result = inv_mpu6050_switch_engine(st, true,
 					INV_MPU6050_BIT_PWR_ACCL_STBY);
 			if (result)
-				return result;
+				goto write_error;
 		}
+		inv_clear_kfifo(st);
 		result = inv_reset_fifo(indio_dev);
 		if (result)
-			return result;
+			goto write_error;
 	} else {
 		result = inv_mpu6050_write_reg(st, st->reg->fifo_en, 0);
 		if (result)
-			return result;
+			goto write_error;
 
 		result = inv_mpu6050_write_reg(st, st->reg->int_enable, 0);
 		if (result)
-			return result;
+			goto write_error;
 
 		result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, 0);
 		if (result)
-			return result;
+			goto write_error;
 
 		result = inv_mpu6050_switch_engine(st, false,
 					INV_MPU6050_BIT_PWR_GYRO_STBY);
 		if (result)
-			return result;
+			goto write_error;
 
 		result = inv_mpu6050_switch_engine(st, false,
 					INV_MPU6050_BIT_PWR_ACCL_STBY);
 		if (result)
-			return result;
+			goto write_error;
 		result = inv_mpu6050_set_power_itg(st, false);
 		if (result)
-			return result;
+			goto write_error;
 	}
 	st->chip_config.enable = enable;
+write_error:
+	mutex_unlock(&indio_dev->mlock);
 
-	return 0;
+	return result;
 }
 
 /**
 
Signature · 2 lines
Peter Meerwald
+43-664-2444418 (mobile)
#2 lore raw

Hi Peter, All

Thank you for quick review. As an alternative I'm considering calling inv_clear_kfifo(st); from inv_reset_fifo(indio_dev); - it makes more sense to me
now given that the timestaps in kfifo are invalid once the hardware fifo is reset.

I'll upload a new patch shortly.

Thank you,
/Viorel

Quoted 113 lines · Peter Meerwald
Quoted 6 lines

The timestamp kfifo must be cleared once the hardware fifo is reset, thus are removed timestamps related to unprocessed events from hardware fifo - see "inv_mpu6050_read_fifo" method implementation.

comments below
a prefix iio: in the subject would be nice

Quoted 3 lines
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 28

+++++++++++++++------------

Review

Quoted 3 lines
 1 file changed, 16 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c

drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c static void inv_scan_query(struct iio_dev *indio_dev) · line 42

Quoted 5 lines

index 926fcce..b617920 100644

drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +0 -0
@@ -42,57 +42,61 @@ static void inv_scan_query(struct iio_dev *indio_dev)
 static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool

enable)

drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c static void inv_scan_query(struct iio_dev *indio_dev) · line 45

Quoted 4 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +1 -1
 {
      struct inv_mpu6050_state *st = iio_priv(indio_dev);
-     int result;
+     int result = 0;

no need to init result

the mutex could be obtained in the caller, i.e. inv_mpu_data_rdy_trigger_set_state(), simplifying the code and drastically reducing the size of this patch

the patch description does not explain a mutex is (now?) needed; probably this should be split out as a separate patch

Quoted 59 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +12 -10
+     mutex_lock(&indio_dev->mlock);
      if (enable) {
              result = inv_mpu6050_set_power_itg(st, true);
              if (result)
-                     return result;
+                     goto write_error;
              inv_scan_query(indio_dev);
              if (st->chip_config.gyro_fifo_enable) {
                      result = inv_mpu6050_switch_engine(st, true,
                                      INV_MPU6050_BIT_PWR_GYRO_STBY);
                      if (result)
-                             return result;
+                             goto write_error;
              }
              if (st->chip_config.accl_fifo_enable) {
                      result = inv_mpu6050_switch_engine(st, true,
                                      INV_MPU6050_BIT_PWR_ACCL_STBY);
                      if (result)
-                             return result;
+                             goto write_error;
              }
+             inv_clear_kfifo(st);
              result = inv_reset_fifo(indio_dev);
              if (result)
-                     return result;
+                     goto write_error;
      } else {
              result = inv_mpu6050_write_reg(st, st->reg->fifo_en, 0);
              if (result)
-                     return result;
+                     goto write_error;
 
              result = inv_mpu6050_write_reg(st, st->reg->int_enable, 0);
              if (result)
-                     return result;
+                     goto write_error;
 
              result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, 0);
              if (result)
-                     return result;
+                     goto write_error;
 
              result = inv_mpu6050_switch_engine(st, false,
                                      INV_MPU6050_BIT_PWR_GYRO_STBY);
              if (result)
-                     return result;
+                     goto write_error;
 
              result = inv_mpu6050_switch_engine(st, false,
                                      INV_MPU6050_BIT_PWR_ACCL_STBY);
              if (result)
-                     return result;
+                     goto write_error;
              result = inv_mpu6050_set_power_itg(st, false);
              if (result)
-                     return result;
+                     goto write_error;
      }

drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c static void inv_scan_query(struct iio_dev *indio_dev)

Quoted 10 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +3 -1
      st->chip_config.enable = enable;
+write_error:
+     mutex_unlock(&indio_dev->mlock);
 
-     return 0;
+     return result;
 }
 
 /**
 

--

Peter Meerwald
+43-664-2444418 (mobile)