All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add startup time for each chip using inv_mpu6050 driver
@ 2021-06-21  8:57 Baptiste Mansuy
  2021-06-21  9:16 ` --[[SPOOF or PHISHING]]--[PATCH] " Jean-Baptiste Maneyrol
  0 siblings, 1 reply; 5+ messages in thread
From: Baptiste Mansuy @ 2021-06-21  8:57 UTC (permalink / raw)
  To: linux-iio; +Cc: Baptiste Mansuy

Add startup time for each chip familly. This allows a better behaviour of 
the gyro and the accel. The gyro has now the time to stabilise itself 
thus making initial data discarding for gyro irrelevant.

Signed-off-by: Baptiste Mansuy <bmansuy@invensense.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    | 22 +++++++++++++++----
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h     | 18 +++++++++++++--
 drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 15 ++-----------
 3 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 6244a07048df..50be32b60f19 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -143,6 +143,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6050,
 		.fifo_size = 1024,
 		.temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
+		.startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
 	},
 	{
 		.whoami = INV_MPU6500_WHOAMI_VALUE,
@@ -151,6 +152,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6500,
 		.fifo_size = 512,
 		.temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+		.startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
 	},
 	{
 		.whoami = INV_MPU6515_WHOAMI_VALUE,
@@ -159,6 +161,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6500,
 		.fifo_size = 512,
 		.temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+		.startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
 	},
 	{
 		.whoami = INV_MPU6880_WHOAMI_VALUE,
@@ -167,6 +170,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6500,
 		.fifo_size = 4096,
 		.temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+		.startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
 	},
 	{
 		.whoami = INV_MPU6000_WHOAMI_VALUE,
@@ -175,6 +179,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6050,
 		.fifo_size = 1024,
 		.temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
+		.startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
 	},
 	{
 		.whoami = INV_MPU9150_WHOAMI_VALUE,
@@ -183,6 +188,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6050,
 		.fifo_size = 1024,
 		.temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
+		.startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
 	},
 	{
 		.whoami = INV_MPU9250_WHOAMI_VALUE,
@@ -191,6 +197,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6500,
 		.fifo_size = 512,
 		.temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+		.startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
 	},
 	{
 		.whoami = INV_MPU9255_WHOAMI_VALUE,
@@ -199,6 +206,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6500,
 		.fifo_size = 512,
 		.temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+		.startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
 	},
 	{
 		.whoami = INV_ICM20608_WHOAMI_VALUE,
@@ -207,6 +215,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6500,
 		.fifo_size = 512,
 		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+		.startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
 	},
 	{
 		.whoami = INV_ICM20609_WHOAMI_VALUE,
@@ -215,6 +224,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6500,
 		.fifo_size = 4 * 1024,
 		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+		.startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
 	},
 	{
 		.whoami = INV_ICM20689_WHOAMI_VALUE,
@@ -223,6 +233,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6500,
 		.fifo_size = 4 * 1024,
 		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+		.startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
 	},
 	{
 		.whoami = INV_ICM20602_WHOAMI_VALUE,
@@ -231,6 +242,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6500,
 		.fifo_size = 1008,
 		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+		.startup_time = {INV_ICM20602_GYRO_STARTUP_TIME, INV_ICM20602_ACCEL_STARTUP_TIME},
 	},
 	{
 		.whoami = INV_ICM20690_WHOAMI_VALUE,
@@ -239,6 +251,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6500,
 		.fifo_size = 1024,
 		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+		.startup_time = {INV_ICM20690_GYRO_STARTUP_TIME, INV_ICM20690_ACCEL_STARTUP_TIME},
 	},
 	{
 		.whoami = INV_IAM20680_WHOAMI_VALUE,
@@ -247,6 +260,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.config = &chip_config_6500,
 		.fifo_size = 512,
 		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+		.startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
 	},
 };
 
@@ -379,12 +393,12 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en,
 		sleep = 0;
 		if (en) {
 			if (mask & INV_MPU6050_SENSOR_ACCL) {
-				if (sleep < INV_MPU6050_ACCEL_UP_TIME)
-					sleep = INV_MPU6050_ACCEL_UP_TIME;
+				if (sleep < st->hw->startup_time.accel)
+					sleep = st->hw->startup_time.accel;
 			}
 			if (mask & INV_MPU6050_SENSOR_GYRO) {
-				if (sleep < INV_MPU6050_GYRO_UP_TIME)
-					sleep = INV_MPU6050_GYRO_UP_TIME;
+				if (sleep < st->hw->startup_time.gyro)
+					sleep = st->hw->startup_time.gyro;
 			}
 		} else {
 			if (mask & INV_MPU6050_SENSOR_GYRO) {
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index 58188dc0dd13..c6aa36ee966a 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -149,6 +149,10 @@ struct inv_mpu6050_hw {
 		int offset;
 		int scale;
 	} temp;
+	struct {
+		unsigned int accel;
+		unsigned int gyro;
+	} startup_time;
 };
 
 /*
@@ -320,11 +324,21 @@ struct inv_mpu6050_state {
 /* delay time in milliseconds */
 #define INV_MPU6050_POWER_UP_TIME            100
 #define INV_MPU6050_TEMP_UP_TIME             100
-#define INV_MPU6050_ACCEL_UP_TIME            20
-#define INV_MPU6050_GYRO_UP_TIME             35
+#define INV_MPU6050_ACCEL_STARTUP_TIME       20
+#define INV_MPU6050_GYRO_STARTUP_TIME        60
 #define INV_MPU6050_GYRO_DOWN_TIME           150
 #define INV_MPU6050_SUSPEND_DELAY_MS         2000
 
+#define INV_MPU6500_GYRO_STARTUP_TIME        70
+#define INV_MPU6500_ACCEL_STARTUP_TIME       30
+
+#define INV_ICM20602_GYRO_STARTUP_TIME       100
+#define INV_ICM20602_ACCEL_STARTUP_TIME      20
+
+#define INV_ICM20690_GYRO_STARTUP_TIME       80
+#define INV_ICM20690_ACCEL_STARTUP_TIME      10
+
+
 /* delay time in microseconds */
 #define INV_MPU6050_REG_UP_TIME_MIN          5000
 #define INV_MPU6050_REG_UP_TIME_MAX          10000
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
index e21ba778595a..28416a09c462 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
@@ -91,22 +91,11 @@ static unsigned int inv_scan_query(struct iio_dev *indio_dev)
 
 static unsigned int inv_compute_skip_samples(const struct inv_mpu6050_state *st)
 {
-	unsigned int gyro_skip = 0;
-	unsigned int magn_skip = 0;
-	unsigned int skip_samples;
-
-	/* gyro first sample is out of specs, skip it */
-	if (st->chip_config.gyro_fifo_enable)
-		gyro_skip = 1;
+	unsigned int skip_samples = 0;
 
 	/* mag first sample is always not ready, skip it */
 	if (st->chip_config.magn_fifo_enable)
-		magn_skip = 1;
-
-	/* compute first samples to skip */
-	skip_samples = gyro_skip;
-	if (magn_skip > skip_samples)
-		skip_samples = magn_skip;
+		skip_samples = 1;
 
 	return skip_samples;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: --[[SPOOF or PHISHING]]--[PATCH] Add startup time for each chip using inv_mpu6050 driver
  2021-06-21  8:57 [PATCH] Add startup time for each chip using inv_mpu6050 driver Baptiste Mansuy
@ 2021-06-21  9:16 ` Jean-Baptiste Maneyrol
  2021-07-01  7:43   ` --[[SPOOF or PHISHING]]--Re: " Jean-Baptiste Maneyrol
  0 siblings, 1 reply; 5+ messages in thread
From: Jean-Baptiste Maneyrol @ 2021-06-21  9:16 UTC (permalink / raw)
  To: Baptiste Mansuy, linux-iio

Hello,

looks good for me, thanks for the patch.

Acked-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>

Thanks,
JB

From: Baptiste Mansuy <bmansuy@invensense.com>
Sent: Monday, June 21, 2021 10:57
To: linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>
Cc: Baptiste Mansuy <bmansuy@invensense.com>
Subject: --[[SPOOF or PHISHING]]--[PATCH] Add startup time for each chip using inv_mpu6050 driver 
 
 CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.

Add startup time for each chip familly. This allows a better behaviour of 
the gyro and the accel. The gyro has now the time to stabilise itself 
thus making initial data discarding for gyro irrelevant.

Signed-off-by: Baptiste Mansuy <bmansuy@invensense.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    | 22 +++++++++++++++----
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h     | 18 +++++++++++++--
 drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 15 ++-----------
 3 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 6244a07048df..50be32b60f19 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -143,6 +143,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6050,
                 .fifo_size = 1024,
                 .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
+               .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU6500_WHOAMI_VALUE,
@@ -151,6 +152,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 512,
                 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU6515_WHOAMI_VALUE,
@@ -159,6 +161,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 512,
                 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU6880_WHOAMI_VALUE,
@@ -167,6 +170,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 4096,
                 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU6000_WHOAMI_VALUE,
@@ -175,6 +179,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6050,
                 .fifo_size = 1024,
                 .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
+               .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU9150_WHOAMI_VALUE,
@@ -183,6 +188,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6050,
                 .fifo_size = 1024,
                 .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
+               .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU9250_WHOAMI_VALUE,
@@ -191,6 +197,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 512,
                 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU9255_WHOAMI_VALUE,
@@ -199,6 +206,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 512,
                 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_ICM20608_WHOAMI_VALUE,
@@ -207,6 +215,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 512,
                 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_ICM20609_WHOAMI_VALUE,
@@ -215,6 +224,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 4 * 1024,
                 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_ICM20689_WHOAMI_VALUE,
@@ -223,6 +233,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 4 * 1024,
                 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_ICM20602_WHOAMI_VALUE,
@@ -231,6 +242,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 1008,
                 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+               .startup_time = {INV_ICM20602_GYRO_STARTUP_TIME, INV_ICM20602_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_ICM20690_WHOAMI_VALUE,
@@ -239,6 +251,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 1024,
                 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+               .startup_time = {INV_ICM20690_GYRO_STARTUP_TIME, INV_ICM20690_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_IAM20680_WHOAMI_VALUE,
@@ -247,6 +260,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 512,
                 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
 };
 
@@ -379,12 +393,12 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en,
                 sleep = 0;
                 if (en) {
                         if (mask & INV_MPU6050_SENSOR_ACCL) {
-                               if (sleep < INV_MPU6050_ACCEL_UP_TIME)
-                                       sleep = INV_MPU6050_ACCEL_UP_TIME;
+                               if (sleep < st->hw->startup_time.accel)
+                                       sleep = st->hw->startup_time.accel;
                         }
                         if (mask & INV_MPU6050_SENSOR_GYRO) {
-                               if (sleep < INV_MPU6050_GYRO_UP_TIME)
-                                       sleep = INV_MPU6050_GYRO_UP_TIME;
+                               if (sleep < st->hw->startup_time.gyro)
+                                       sleep = st->hw->startup_time.gyro;
                         }
                 } else {
                         if (mask & INV_MPU6050_SENSOR_GYRO) {
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index 58188dc0dd13..c6aa36ee966a 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -149,6 +149,10 @@ struct inv_mpu6050_hw {
                 int offset;
                 int scale;
         } temp;
+       struct {
+               unsigned int accel;
+               unsigned int gyro;
+       } startup_time;
 };
 
 /*
@@ -320,11 +324,21 @@ struct inv_mpu6050_state {
 /* delay time in milliseconds */
 #define INV_MPU6050_POWER_UP_TIME            100
 #define INV_MPU6050_TEMP_UP_TIME             100
-#define INV_MPU6050_ACCEL_UP_TIME            20
-#define INV_MPU6050_GYRO_UP_TIME             35
+#define INV_MPU6050_ACCEL_STARTUP_TIME       20
+#define INV_MPU6050_GYRO_STARTUP_TIME        60
 #define INV_MPU6050_GYRO_DOWN_TIME           150
 #define INV_MPU6050_SUSPEND_DELAY_MS         2000
 
+#define INV_MPU6500_GYRO_STARTUP_TIME        70
+#define INV_MPU6500_ACCEL_STARTUP_TIME       30
+
+#define INV_ICM20602_GYRO_STARTUP_TIME       100
+#define INV_ICM20602_ACCEL_STARTUP_TIME      20
+
+#define INV_ICM20690_GYRO_STARTUP_TIME       80
+#define INV_ICM20690_ACCEL_STARTUP_TIME      10
+
+
 /* delay time in microseconds */
 #define INV_MPU6050_REG_UP_TIME_MIN          5000
 #define INV_MPU6050_REG_UP_TIME_MAX          10000
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
index e21ba778595a..28416a09c462 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
@@ -91,22 +91,11 @@ static unsigned int inv_scan_query(struct iio_dev *indio_dev)
 
 static unsigned int inv_compute_skip_samples(const struct inv_mpu6050_state *st)
 {
-       unsigned int gyro_skip = 0;
-       unsigned int magn_skip = 0;
-       unsigned int skip_samples;
-
-       /* gyro first sample is out of specs, skip it */
-       if (st->chip_config.gyro_fifo_enable)
-               gyro_skip = 1;
+       unsigned int skip_samples = 0;
 
         /* mag first sample is always not ready, skip it */
         if (st->chip_config.magn_fifo_enable)
-               magn_skip = 1;
-
-       /* compute first samples to skip */
-       skip_samples = gyro_skip;
-       if (magn_skip > skip_samples)
-               skip_samples = magn_skip;
+               skip_samples = 1;
 
         return skip_samples;
 }
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: --[[SPOOF or PHISHING]]--Re: --[[SPOOF or PHISHING]]--[PATCH] Add startup time for each chip using inv_mpu6050 driver
  2021-06-21  9:16 ` --[[SPOOF or PHISHING]]--[PATCH] " Jean-Baptiste Maneyrol
@ 2021-07-01  7:43   ` Jean-Baptiste Maneyrol
  2021-07-04 17:32     ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Jean-Baptiste Maneyrol @ 2021-07-01  7:43 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Baptiste Mansuy, linux-iio

Hello Jonathan,

any news about this patch?

Thanks for your feedback,
JB


From: Jean-Baptiste Maneyrol <JManeyrol@invensense.com>
Sent: Monday, June 21, 2021 11:16
To: Baptiste Mansuy <bmansuy@invensense.com>; linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>
Subject: --[[SPOOF or PHISHING]]--Re: --[[SPOOF or PHISHING]]--[PATCH] Add startup time for each chip using inv_mpu6050 driver 
 
 CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.

Hello,

looks good for me, thanks for the patch.

Acked-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>

Thanks,
JB

From: Baptiste Mansuy <bmansuy@invensense.com>
Sent: Monday, June 21, 2021 10:57
To: linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>
Cc: Baptiste Mansuy <bmansuy@invensense.com>
Subject: --[[SPOOF or PHISHING]]--[PATCH] Add startup time for each chip using inv_mpu6050 driver 
 
 CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.

Add startup time for each chip familly. This allows a better behaviour of 
the gyro and the accel. The gyro has now the time to stabilise itself 
thus making initial data discarding for gyro irrelevant.

Signed-off-by: Baptiste Mansuy <bmansuy@invensense.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    | 22 +++++++++++++++----
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h     | 18 +++++++++++++--
 drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 15 ++-----------
 3 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 6244a07048df..50be32b60f19 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -143,6 +143,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6050,
                 .fifo_size = 1024,
                 .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
+               .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU6500_WHOAMI_VALUE,
@@ -151,6 +152,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 512,
                 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU6515_WHOAMI_VALUE,
@@ -159,6 +161,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 512,
                 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU6880_WHOAMI_VALUE,
@@ -167,6 +170,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 4096,
                 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU6000_WHOAMI_VALUE,
@@ -175,6 +179,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6050,
                 .fifo_size = 1024,
                 .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
+               .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU9150_WHOAMI_VALUE,
@@ -183,6 +188,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6050,
                 .fifo_size = 1024,
                 .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
+               .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU9250_WHOAMI_VALUE,
@@ -191,6 +197,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 512,
                 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_MPU9255_WHOAMI_VALUE,
@@ -199,6 +206,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 512,
                 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_ICM20608_WHOAMI_VALUE,
@@ -207,6 +215,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 512,
                 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_ICM20609_WHOAMI_VALUE,
@@ -215,6 +224,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 4 * 1024,
                 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_ICM20689_WHOAMI_VALUE,
@@ -223,6 +233,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 4 * 1024,
                 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_ICM20602_WHOAMI_VALUE,
@@ -231,6 +242,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 1008,
                 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+               .startup_time = {INV_ICM20602_GYRO_STARTUP_TIME, INV_ICM20602_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_ICM20690_WHOAMI_VALUE,
@@ -239,6 +251,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 1024,
                 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+               .startup_time = {INV_ICM20690_GYRO_STARTUP_TIME, INV_ICM20690_ACCEL_STARTUP_TIME},
         },
         {
                 .whoami = INV_IAM20680_WHOAMI_VALUE,
@@ -247,6 +260,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
                 .config = &chip_config_6500,
                 .fifo_size = 512,
                 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
+               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
         },
 };
 
@@ -379,12 +393,12 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en,
                 sleep = 0;
                 if (en) {
                         if (mask & INV_MPU6050_SENSOR_ACCL) {
-                               if (sleep < INV_MPU6050_ACCEL_UP_TIME)
-                                       sleep = INV_MPU6050_ACCEL_UP_TIME;
+                               if (sleep < st->hw->startup_time.accel)
+                                       sleep = st->hw->startup_time.accel;
                         }
                         if (mask & INV_MPU6050_SENSOR_GYRO) {
-                               if (sleep < INV_MPU6050_GYRO_UP_TIME)
-                                       sleep = INV_MPU6050_GYRO_UP_TIME;
+                               if (sleep < st->hw->startup_time.gyro)
+                                       sleep = st->hw->startup_time.gyro;
                         }
                 } else {
                         if (mask & INV_MPU6050_SENSOR_GYRO) {
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index 58188dc0dd13..c6aa36ee966a 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -149,6 +149,10 @@ struct inv_mpu6050_hw {
                 int offset;
                 int scale;
         } temp;
+       struct {
+               unsigned int accel;
+               unsigned int gyro;
+       } startup_time;
 };
 
 /*
@@ -320,11 +324,21 @@ struct inv_mpu6050_state {
 /* delay time in milliseconds */
 #define INV_MPU6050_POWER_UP_TIME            100
 #define INV_MPU6050_TEMP_UP_TIME             100
-#define INV_MPU6050_ACCEL_UP_TIME            20
-#define INV_MPU6050_GYRO_UP_TIME             35
+#define INV_MPU6050_ACCEL_STARTUP_TIME       20
+#define INV_MPU6050_GYRO_STARTUP_TIME        60
 #define INV_MPU6050_GYRO_DOWN_TIME           150
 #define INV_MPU6050_SUSPEND_DELAY_MS         2000
 
+#define INV_MPU6500_GYRO_STARTUP_TIME        70
+#define INV_MPU6500_ACCEL_STARTUP_TIME       30
+
+#define INV_ICM20602_GYRO_STARTUP_TIME       100
+#define INV_ICM20602_ACCEL_STARTUP_TIME      20
+
+#define INV_ICM20690_GYRO_STARTUP_TIME       80
+#define INV_ICM20690_ACCEL_STARTUP_TIME      10
+
+
 /* delay time in microseconds */
 #define INV_MPU6050_REG_UP_TIME_MIN          5000
 #define INV_MPU6050_REG_UP_TIME_MAX          10000
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
index e21ba778595a..28416a09c462 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
@@ -91,22 +91,11 @@ static unsigned int inv_scan_query(struct iio_dev *indio_dev)
 
 static unsigned int inv_compute_skip_samples(const struct inv_mpu6050_state *st)
 {
-       unsigned int gyro_skip = 0;
-       unsigned int magn_skip = 0;
-       unsigned int skip_samples;
-
-       /* gyro first sample is out of specs, skip it */
-       if (st->chip_config.gyro_fifo_enable)
-               gyro_skip = 1;
+       unsigned int skip_samples = 0;
 
         /* mag first sample is always not ready, skip it */
         if (st->chip_config.magn_fifo_enable)
-               magn_skip = 1;
-
-       /* compute first samples to skip */
-       skip_samples = gyro_skip;
-       if (magn_skip > skip_samples)
-               skip_samples = magn_skip;
+               skip_samples = 1;
 
         return skip_samples;
 }
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: --[[SPOOF or PHISHING]]--Re: --[[SPOOF or PHISHING]]--[PATCH] Add startup time for each chip using inv_mpu6050 driver
  2021-07-01  7:43   ` --[[SPOOF or PHISHING]]--Re: " Jean-Baptiste Maneyrol
@ 2021-07-04 17:32     ` Jonathan Cameron
  2021-07-18 14:41       ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2021-07-04 17:32 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: Baptiste Mansuy, linux-iio

On Thu, 1 Jul 2021 07:43:15 +0000
Jean-Baptiste Maneyrol <JManeyrol@invensense.com> wrote:

> Hello Jonathan,
> 
> any news about this patch?
> 
> Thanks for your feedback,

Looks fine to me, but we were very close to the merge window so I wasn't
taking anything new.  I'll hopefully pick this up soon; just waiting for rc1
so I have a nice place to rebase to.

Thanks,

Jonathan

> JB
> 
> 
> From: Jean-Baptiste Maneyrol <JManeyrol@invensense.com>
> Sent: Monday, June 21, 2021 11:16
> To: Baptiste Mansuy <bmansuy@invensense.com>; linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>
> Subject: --[[SPOOF or PHISHING]]--Re: --[[SPOOF or PHISHING]]--[PATCH] Add startup time for each chip using inv_mpu6050 driver 
>  
>  CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.
> 
> Hello,
> 
> looks good for me, thanks for the patch.
> 
> Acked-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
> 
> Thanks,
> JB
> 
> From: Baptiste Mansuy <bmansuy@invensense.com>
> Sent: Monday, June 21, 2021 10:57
> To: linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>
> Cc: Baptiste Mansuy <bmansuy@invensense.com>
> Subject: --[[SPOOF or PHISHING]]--[PATCH] Add startup time for each chip using inv_mpu6050 driver 
>  
>  CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.
> 
> Add startup time for each chip familly. This allows a better behaviour of 
> the gyro and the accel. The gyro has now the time to stabilise itself 
> thus making initial data discarding for gyro irrelevant.
> 
> Signed-off-by: Baptiste Mansuy <bmansuy@invensense.com>
> ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    | 22 +++++++++++++++----
>  drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h     | 18 +++++++++++++--
>  drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 15 ++-----------
>  3 files changed, 36 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 6244a07048df..50be32b60f19 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -143,6 +143,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6050,
>                  .fifo_size = 1024,
>                  .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
> +               .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
>          },
>          {
>                  .whoami = INV_MPU6500_WHOAMI_VALUE,
> @@ -151,6 +152,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6500,
>                  .fifo_size = 512,
>                  .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
> +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
>          },
>          {
>                  .whoami = INV_MPU6515_WHOAMI_VALUE,
> @@ -159,6 +161,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6500,
>                  .fifo_size = 512,
>                  .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
> +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
>          },
>          {
>                  .whoami = INV_MPU6880_WHOAMI_VALUE,
> @@ -167,6 +170,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6500,
>                  .fifo_size = 4096,
>                  .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
> +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
>          },
>          {
>                  .whoami = INV_MPU6000_WHOAMI_VALUE,
> @@ -175,6 +179,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6050,
>                  .fifo_size = 1024,
>                  .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
> +               .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
>          },
>          {
>                  .whoami = INV_MPU9150_WHOAMI_VALUE,
> @@ -183,6 +188,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6050,
>                  .fifo_size = 1024,
>                  .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
> +               .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
>          },
>          {
>                  .whoami = INV_MPU9250_WHOAMI_VALUE,
> @@ -191,6 +197,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6500,
>                  .fifo_size = 512,
>                  .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
> +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
>          },
>          {
>                  .whoami = INV_MPU9255_WHOAMI_VALUE,
> @@ -199,6 +206,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6500,
>                  .fifo_size = 512,
>                  .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
> +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
>          },
>          {
>                  .whoami = INV_ICM20608_WHOAMI_VALUE,
> @@ -207,6 +215,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6500,
>                  .fifo_size = 512,
>                  .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
>          },
>          {
>                  .whoami = INV_ICM20609_WHOAMI_VALUE,
> @@ -215,6 +224,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6500,
>                  .fifo_size = 4 * 1024,
>                  .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
>          },
>          {
>                  .whoami = INV_ICM20689_WHOAMI_VALUE,
> @@ -223,6 +233,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6500,
>                  .fifo_size = 4 * 1024,
>                  .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
>          },
>          {
>                  .whoami = INV_ICM20602_WHOAMI_VALUE,
> @@ -231,6 +242,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6500,
>                  .fifo_size = 1008,
>                  .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> +               .startup_time = {INV_ICM20602_GYRO_STARTUP_TIME, INV_ICM20602_ACCEL_STARTUP_TIME},
>          },
>          {
>                  .whoami = INV_ICM20690_WHOAMI_VALUE,
> @@ -239,6 +251,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6500,
>                  .fifo_size = 1024,
>                  .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> +               .startup_time = {INV_ICM20690_GYRO_STARTUP_TIME, INV_ICM20690_ACCEL_STARTUP_TIME},
>          },
>          {
>                  .whoami = INV_IAM20680_WHOAMI_VALUE,
> @@ -247,6 +260,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
>                  .config = &chip_config_6500,
>                  .fifo_size = 512,
>                  .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
>          },
>  };
>  
> @@ -379,12 +393,12 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en,
>                  sleep = 0;
>                  if (en) {
>                          if (mask & INV_MPU6050_SENSOR_ACCL) {
> -                               if (sleep < INV_MPU6050_ACCEL_UP_TIME)
> -                                       sleep = INV_MPU6050_ACCEL_UP_TIME;
> +                               if (sleep < st->hw->startup_time.accel)
> +                                       sleep = st->hw->startup_time.accel;
>                          }
>                          if (mask & INV_MPU6050_SENSOR_GYRO) {
> -                               if (sleep < INV_MPU6050_GYRO_UP_TIME)
> -                                       sleep = INV_MPU6050_GYRO_UP_TIME;
> +                               if (sleep < st->hw->startup_time.gyro)
> +                                       sleep = st->hw->startup_time.gyro;
>                          }
>                  } else {
>                          if (mask & INV_MPU6050_SENSOR_GYRO) {
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> index 58188dc0dd13..c6aa36ee966a 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> @@ -149,6 +149,10 @@ struct inv_mpu6050_hw {
>                  int offset;
>                  int scale;
>          } temp;
> +       struct {
> +               unsigned int accel;
> +               unsigned int gyro;
> +       } startup_time;
>  };
>  
>  /*
> @@ -320,11 +324,21 @@ struct inv_mpu6050_state {
>  /* delay time in milliseconds */
>  #define INV_MPU6050_POWER_UP_TIME            100
>  #define INV_MPU6050_TEMP_UP_TIME             100
> -#define INV_MPU6050_ACCEL_UP_TIME            20
> -#define INV_MPU6050_GYRO_UP_TIME             35
> +#define INV_MPU6050_ACCEL_STARTUP_TIME       20
> +#define INV_MPU6050_GYRO_STARTUP_TIME        60
>  #define INV_MPU6050_GYRO_DOWN_TIME           150
>  #define INV_MPU6050_SUSPEND_DELAY_MS         2000
>  
> +#define INV_MPU6500_GYRO_STARTUP_TIME        70
> +#define INV_MPU6500_ACCEL_STARTUP_TIME       30
> +
> +#define INV_ICM20602_GYRO_STARTUP_TIME       100
> +#define INV_ICM20602_ACCEL_STARTUP_TIME      20
> +
> +#define INV_ICM20690_GYRO_STARTUP_TIME       80
> +#define INV_ICM20690_ACCEL_STARTUP_TIME      10
> +
> +
>  /* delay time in microseconds */
>  #define INV_MPU6050_REG_UP_TIME_MIN          5000
>  #define INV_MPU6050_REG_UP_TIME_MAX          10000
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> index e21ba778595a..28416a09c462 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> @@ -91,22 +91,11 @@ static unsigned int inv_scan_query(struct iio_dev *indio_dev)
>  
>  static unsigned int inv_compute_skip_samples(const struct inv_mpu6050_state *st)
>  {
> -       unsigned int gyro_skip = 0;
> -       unsigned int magn_skip = 0;
> -       unsigned int skip_samples;
> -
> -       /* gyro first sample is out of specs, skip it */
> -       if (st->chip_config.gyro_fifo_enable)
> -               gyro_skip = 1;
> +       unsigned int skip_samples = 0;
>  
>          /* mag first sample is always not ready, skip it */
>          if (st->chip_config.magn_fifo_enable)
> -               magn_skip = 1;
> -
> -       /* compute first samples to skip */
> -       skip_samples = gyro_skip;
> -       if (magn_skip > skip_samples)
> -               skip_samples = magn_skip;
> +               skip_samples = 1;
>  
>          return skip_samples;
>  }


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: --[[SPOOF or PHISHING]]--Re: --[[SPOOF or PHISHING]]--[PATCH] Add startup time for each chip using inv_mpu6050 driver
  2021-07-04 17:32     ` Jonathan Cameron
@ 2021-07-18 14:41       ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2021-07-18 14:41 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: Baptiste Mansuy, linux-iio

On Sun, 4 Jul 2021 18:32:06 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> On Thu, 1 Jul 2021 07:43:15 +0000
> Jean-Baptiste Maneyrol <JManeyrol@invensense.com> wrote:
> 
> > Hello Jonathan,
> > 
> > any news about this patch?
> > 
> > Thanks for your feedback,  
> 
> Looks fine to me, but we were very close to the merge window so I wasn't
> taking anything new.  I'll hopefully pick this up soon; just waiting for rc1
> so I have a nice place to rebase to.

Applied to the togreg branch of iio.git which will be pushed out as testing to
let 0-day see if it can find anything we missed before I push it out in a fashion
that I will ideally not rebase.

Thanks,

Jonathan

> 
> Thanks,
> 
> Jonathan
> 
> > JB
> > 
> > 
> > From: Jean-Baptiste Maneyrol <JManeyrol@invensense.com>
> > Sent: Monday, June 21, 2021 11:16
> > To: Baptiste Mansuy <bmansuy@invensense.com>; linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>
> > Subject: --[[SPOOF or PHISHING]]--Re: --[[SPOOF or PHISHING]]--[PATCH] Add startup time for each chip using inv_mpu6050 driver 
> >  
> >  CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.
> > 
> > Hello,
> > 
> > looks good for me, thanks for the patch.
> > 
> > Acked-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
> > 
> > Thanks,
> > JB
> > 
> > From: Baptiste Mansuy <bmansuy@invensense.com>
> > Sent: Monday, June 21, 2021 10:57
> > To: linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>
> > Cc: Baptiste Mansuy <bmansuy@invensense.com>
> > Subject: --[[SPOOF or PHISHING]]--[PATCH] Add startup time for each chip using inv_mpu6050 driver 
> >  
> >  CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.
> > 
> > Add startup time for each chip familly. This allows a better behaviour of 
> > the gyro and the accel. The gyro has now the time to stabilise itself 
> > thus making initial data discarding for gyro irrelevant.
> > 
> > Signed-off-by: Baptiste Mansuy <bmansuy@invensense.com>
> > ---
> >  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    | 22 +++++++++++++++----
> >  drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h     | 18 +++++++++++++--
> >  drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 15 ++-----------
> >  3 files changed, 36 insertions(+), 19 deletions(-)
> > 
> > diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> > index 6244a07048df..50be32b60f19 100644
> > --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> > +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> > @@ -143,6 +143,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6050,
> >                  .fifo_size = 1024,
> >                  .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
> > +               .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
> >          },
> >          {
> >                  .whoami = INV_MPU6500_WHOAMI_VALUE,
> > @@ -151,6 +152,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6500,
> >                  .fifo_size = 512,
> >                  .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
> > +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
> >          },
> >          {
> >                  .whoami = INV_MPU6515_WHOAMI_VALUE,
> > @@ -159,6 +161,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6500,
> >                  .fifo_size = 512,
> >                  .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
> > +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
> >          },
> >          {
> >                  .whoami = INV_MPU6880_WHOAMI_VALUE,
> > @@ -167,6 +170,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6500,
> >                  .fifo_size = 4096,
> >                  .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
> > +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
> >          },
> >          {
> >                  .whoami = INV_MPU6000_WHOAMI_VALUE,
> > @@ -175,6 +179,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6050,
> >                  .fifo_size = 1024,
> >                  .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
> > +               .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
> >          },
> >          {
> >                  .whoami = INV_MPU9150_WHOAMI_VALUE,
> > @@ -183,6 +188,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6050,
> >                  .fifo_size = 1024,
> >                  .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
> > +               .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
> >          },
> >          {
> >                  .whoami = INV_MPU9250_WHOAMI_VALUE,
> > @@ -191,6 +197,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6500,
> >                  .fifo_size = 512,
> >                  .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
> > +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
> >          },
> >          {
> >                  .whoami = INV_MPU9255_WHOAMI_VALUE,
> > @@ -199,6 +206,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6500,
> >                  .fifo_size = 512,
> >                  .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
> > +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
> >          },
> >          {
> >                  .whoami = INV_ICM20608_WHOAMI_VALUE,
> > @@ -207,6 +215,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6500,
> >                  .fifo_size = 512,
> >                  .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> > +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
> >          },
> >          {
> >                  .whoami = INV_ICM20609_WHOAMI_VALUE,
> > @@ -215,6 +224,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6500,
> >                  .fifo_size = 4 * 1024,
> >                  .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> > +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
> >          },
> >          {
> >                  .whoami = INV_ICM20689_WHOAMI_VALUE,
> > @@ -223,6 +233,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6500,
> >                  .fifo_size = 4 * 1024,
> >                  .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> > +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
> >          },
> >          {
> >                  .whoami = INV_ICM20602_WHOAMI_VALUE,
> > @@ -231,6 +242,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6500,
> >                  .fifo_size = 1008,
> >                  .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> > +               .startup_time = {INV_ICM20602_GYRO_STARTUP_TIME, INV_ICM20602_ACCEL_STARTUP_TIME},
> >          },
> >          {
> >                  .whoami = INV_ICM20690_WHOAMI_VALUE,
> > @@ -239,6 +251,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6500,
> >                  .fifo_size = 1024,
> >                  .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> > +               .startup_time = {INV_ICM20690_GYRO_STARTUP_TIME, INV_ICM20690_ACCEL_STARTUP_TIME},
> >          },
> >          {
> >                  .whoami = INV_IAM20680_WHOAMI_VALUE,
> > @@ -247,6 +260,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
> >                  .config = &chip_config_6500,
> >                  .fifo_size = 512,
> >                  .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
> > +               .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
> >          },
> >  };
> >  
> > @@ -379,12 +393,12 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en,
> >                  sleep = 0;
> >                  if (en) {
> >                          if (mask & INV_MPU6050_SENSOR_ACCL) {
> > -                               if (sleep < INV_MPU6050_ACCEL_UP_TIME)
> > -                                       sleep = INV_MPU6050_ACCEL_UP_TIME;
> > +                               if (sleep < st->hw->startup_time.accel)
> > +                                       sleep = st->hw->startup_time.accel;
> >                          }
> >                          if (mask & INV_MPU6050_SENSOR_GYRO) {
> > -                               if (sleep < INV_MPU6050_GYRO_UP_TIME)
> > -                                       sleep = INV_MPU6050_GYRO_UP_TIME;
> > +                               if (sleep < st->hw->startup_time.gyro)
> > +                                       sleep = st->hw->startup_time.gyro;
> >                          }
> >                  } else {
> >                          if (mask & INV_MPU6050_SENSOR_GYRO) {
> > diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> > index 58188dc0dd13..c6aa36ee966a 100644
> > --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> > +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> > @@ -149,6 +149,10 @@ struct inv_mpu6050_hw {
> >                  int offset;
> >                  int scale;
> >          } temp;
> > +       struct {
> > +               unsigned int accel;
> > +               unsigned int gyro;
> > +       } startup_time;
> >  };
> >  
> >  /*
> > @@ -320,11 +324,21 @@ struct inv_mpu6050_state {
> >  /* delay time in milliseconds */
> >  #define INV_MPU6050_POWER_UP_TIME            100
> >  #define INV_MPU6050_TEMP_UP_TIME             100
> > -#define INV_MPU6050_ACCEL_UP_TIME            20
> > -#define INV_MPU6050_GYRO_UP_TIME             35
> > +#define INV_MPU6050_ACCEL_STARTUP_TIME       20
> > +#define INV_MPU6050_GYRO_STARTUP_TIME        60
> >  #define INV_MPU6050_GYRO_DOWN_TIME           150
> >  #define INV_MPU6050_SUSPEND_DELAY_MS         2000
> >  
> > +#define INV_MPU6500_GYRO_STARTUP_TIME        70
> > +#define INV_MPU6500_ACCEL_STARTUP_TIME       30
> > +
> > +#define INV_ICM20602_GYRO_STARTUP_TIME       100
> > +#define INV_ICM20602_ACCEL_STARTUP_TIME      20
> > +
> > +#define INV_ICM20690_GYRO_STARTUP_TIME       80
> > +#define INV_ICM20690_ACCEL_STARTUP_TIME      10
> > +
> > +
> >  /* delay time in microseconds */
> >  #define INV_MPU6050_REG_UP_TIME_MIN          5000
> >  #define INV_MPU6050_REG_UP_TIME_MAX          10000
> > diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> > index e21ba778595a..28416a09c462 100644
> > --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> > +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> > @@ -91,22 +91,11 @@ static unsigned int inv_scan_query(struct iio_dev *indio_dev)
> >  
> >  static unsigned int inv_compute_skip_samples(const struct inv_mpu6050_state *st)
> >  {
> > -       unsigned int gyro_skip = 0;
> > -       unsigned int magn_skip = 0;
> > -       unsigned int skip_samples;
> > -
> > -       /* gyro first sample is out of specs, skip it */
> > -       if (st->chip_config.gyro_fifo_enable)
> > -               gyro_skip = 1;
> > +       unsigned int skip_samples = 0;
> >  
> >          /* mag first sample is always not ready, skip it */
> >          if (st->chip_config.magn_fifo_enable)
> > -               magn_skip = 1;
> > -
> > -       /* compute first samples to skip */
> > -       skip_samples = gyro_skip;
> > -       if (magn_skip > skip_samples)
> > -               skip_samples = magn_skip;
> > +               skip_samples = 1;
> >  
> >          return skip_samples;
> >  }  
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-07-18 14:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21  8:57 [PATCH] Add startup time for each chip using inv_mpu6050 driver Baptiste Mansuy
2021-06-21  9:16 ` --[[SPOOF or PHISHING]]--[PATCH] " Jean-Baptiste Maneyrol
2021-07-01  7:43   ` --[[SPOOF or PHISHING]]--Re: " Jean-Baptiste Maneyrol
2021-07-04 17:32     ` Jonathan Cameron
2021-07-18 14:41       ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.