linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: imu: inv_mpu6050: fix no data on MPU6050
@ 2019-10-16 14:43 Jean-Baptiste Maneyrol
       [not found] ` <20191017143142.489CF21848@mail.kernel.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Jean-Baptiste Maneyrol @ 2019-10-16 14:43 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Jean-Baptiste Maneyrol, stable

Some chips have a fifo overflow bit issue where the bit is always
set. The result is that every data is dropped.

Change fifo overflow management by checking fifo count against
a maximum value.

Add fifo size in chip hardware set of values.

Fixes: f5057e7b2dba ("iio: imu: inv_mpu6050: better fifo overflow handling")
Cc: stable@vger.kernel.org
Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c |  9 +++++++++
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h  |  2 ++
 drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 15 ++++++++++++---
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 354030e9bed5..9f9acde229c8 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -116,54 +116,63 @@ static const struct inv_mpu6050_hw hw_info[] = {
 		.name = "MPU6050",
 		.reg = &reg_set_6050,
 		.config = &chip_config_6050,
+		.fifo_size = 1024,
 	},
 	{
 		.whoami = INV_MPU6500_WHOAMI_VALUE,
 		.name = "MPU6500",
 		.reg = &reg_set_6500,
 		.config = &chip_config_6050,
+		.fifo_size = 512,
 	},
 	{
 		.whoami = INV_MPU6515_WHOAMI_VALUE,
 		.name = "MPU6515",
 		.reg = &reg_set_6500,
 		.config = &chip_config_6050,
+		.fifo_size = 512,
 	},
 	{
 		.whoami = INV_MPU6000_WHOAMI_VALUE,
 		.name = "MPU6000",
 		.reg = &reg_set_6050,
 		.config = &chip_config_6050,
+		.fifo_size = 1024,
 	},
 	{
 		.whoami = INV_MPU9150_WHOAMI_VALUE,
 		.name = "MPU9150",
 		.reg = &reg_set_6050,
 		.config = &chip_config_6050,
+		.fifo_size = 1024,
 	},
 	{
 		.whoami = INV_MPU9250_WHOAMI_VALUE,
 		.name = "MPU9250",
 		.reg = &reg_set_6500,
 		.config = &chip_config_6050,
+		.fifo_size = 512,
 	},
 	{
 		.whoami = INV_MPU9255_WHOAMI_VALUE,
 		.name = "MPU9255",
 		.reg = &reg_set_6500,
 		.config = &chip_config_6050,
+		.fifo_size = 512,
 	},
 	{
 		.whoami = INV_ICM20608_WHOAMI_VALUE,
 		.name = "ICM20608",
 		.reg = &reg_set_6500,
 		.config = &chip_config_6050,
+		.fifo_size = 512,
 	},
 	{
 		.whoami = INV_ICM20602_WHOAMI_VALUE,
 		.name = "ICM20602",
 		.reg = &reg_set_icm20602,
 		.config = &chip_config_6050,
+		.fifo_size = 1008,
 	},
 };
 
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index 52fcf45050a5..5f6bbe880d78 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -106,12 +106,14 @@ struct inv_mpu6050_chip_config {
  *  @name:      name of the chip.
  *  @reg:   register map of the chip.
  *  @config:    configuration of the chip.
+ *  @fifo_size:	size of the FIFO in bytes.
  */
 struct inv_mpu6050_hw {
 	u8 whoami;
 	u8 *name;
 	const struct inv_mpu6050_reg_map *reg;
 	const struct inv_mpu6050_chip_config *config;
+	size_t fifo_size;
 };
 
 /*
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
index bbf68b474556..8d1b162e4f64 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
@@ -183,9 +183,6 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
 			"failed to ack interrupt\n");
 		goto flush_fifo;
 	}
-	/* handle fifo overflow by reseting fifo */
-	if (int_status & INV_MPU6050_BIT_FIFO_OVERFLOW_INT)
-		goto flush_fifo;
 	if (!(int_status & INV_MPU6050_BIT_RAW_DATA_RDY_INT)) {
 		dev_warn(regmap_get_device(st->map),
 			"spurious interrupt with status 0x%x\n", int_status);
@@ -218,6 +215,18 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
 	if (result)
 		goto end_session;
 	fifo_count = get_unaligned_be16(&data[0]);
+
+	/*
+	 * Handle fifo overflow by resetting fifo.
+	 * Reset if there is only 3 data set free remaining to mitigate
+	 * possible delay between reading fifo count and fifo data.
+	 */
+	nb = 3 * bytes_per_datum;
+	if (fifo_count >= st->hw->fifo_size - nb) {
+		dev_warn(regmap_get_device(st->map), "fifo overflow reset\n");
+		goto flush_fifo;
+	}
+
 	/* compute and process all complete datum */
 	nb = fifo_count / bytes_per_datum;
 	inv_mpu6050_update_period(st, pf->timestamp, nb);
-- 
2.17.1


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

* Re: [PATCH] iio: imu: inv_mpu6050: fix no data on MPU6050
       [not found] ` <20191017143142.489CF21848@mail.kernel.org>
@ 2019-10-17 14:43   ` Jean-Baptiste Maneyrol
  2019-10-17 18:11     ` Sasha Levin
  0 siblings, 1 reply; 4+ messages in thread
From: Jean-Baptiste Maneyrol @ 2019-10-17 14:43 UTC (permalink / raw)
  To: Sasha Levin, jic23; +Cc: linux-iio, stable

Hello Sacha,

I can do a specific patch for backporting to kernel 4.19 and older ones if needed.
This is really simple.

Tell me if this is OK for you and how to proceed.

Thanks.

Best regards,
JB






From: Sasha Levin <sashal@kernel.org>

Sent: Thursday, October 17, 2019 16:31

To: Sasha Levin <sashal@kernel.org>; Jean-Baptiste Maneyrol <JManeyrol@invensense.com>; jic23@kernel.org <jic23@kernel.org>

Cc: linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>; stable@vger.kernel.org <stable@vger.kernel.org>; stable@vger.kernel.org <stable@vger.kernel.org>

Subject: Re: [PATCH] iio: imu: inv_mpu6050: fix no data on MPU6050

 


 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.



Hi,



[This is an automated email]



This commit has been processed because it contains a "Fixes:" tag,

fixing commit: f5057e7b2dba4 iio: imu: inv_mpu6050: better fifo overflow handling.



The bot has tested the following trees: v5.3.6, v4.19.79.



v5.3.6: Build OK!

v4.19.79: Failed to apply! Possible dependencies:

    22904bdff9783 ("iio: imu: mpu6050: Add support for the ICM 20602 IMU")





NOTE: The patch will not be queued to stable trees until it is upstream.



How should we proceed with this patch?



-- 

Thanks,

Sasha


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

* Re: [PATCH] iio: imu: inv_mpu6050: fix no data on MPU6050
  2019-10-17 14:43   ` Jean-Baptiste Maneyrol
@ 2019-10-17 18:11     ` Sasha Levin
  2019-10-22 11:44       ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2019-10-17 18:11 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: jic23, linux-iio, stable

On Thu, Oct 17, 2019 at 02:43:55PM +0000, Jean-Baptiste Maneyrol wrote:
>Hello Sacha,
>
>I can do a specific patch for backporting to kernel 4.19 and older ones if needed.
>This is really simple.
>
>Tell me if this is OK for you and how to proceed.

If you do end up doing a backport, just send it either as a reply to
this mail, or add a "4.19" tag and send it over to
stable@vger.kernel.org.

-- 
Thanks,
Sasha

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

* Re: [PATCH] iio: imu: inv_mpu6050: fix no data on MPU6050
  2019-10-17 18:11     ` Sasha Levin
@ 2019-10-22 11:44       ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2019-10-22 11:44 UTC (permalink / raw)
  To: Sasha Levin; +Cc: Jean-Baptiste Maneyrol, linux-iio, stable

On Thu, 17 Oct 2019 14:11:28 -0400
Sasha Levin <sashal@kernel.org> wrote:

> On Thu, Oct 17, 2019 at 02:43:55PM +0000, Jean-Baptiste Maneyrol wrote:
> >Hello Sacha,
> >
> >I can do a specific patch for backporting to kernel 4.19 and older ones if needed.
> >This is really simple.
> >
> >Tell me if this is OK for you and how to proceed.  
> 
> If you do end up doing a backport, just send it either as a reply to
> this mail, or add a "4.19" tag and send it over to
> stable@vger.kernel.org.
> 

I've applied this to the fixes-togreg branch of iio.git.  Hopefully
will a pull request out to Greg sometime in the next few days and
from him it'll work it's way into Linus' tree.

Thanks,

Jonathan

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

end of thread, other threads:[~2019-10-22 11:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-16 14:43 [PATCH] iio: imu: inv_mpu6050: fix no data on MPU6050 Jean-Baptiste Maneyrol
     [not found] ` <20191017143142.489CF21848@mail.kernel.org>
2019-10-17 14:43   ` Jean-Baptiste Maneyrol
2019-10-17 18:11     ` Sasha Levin
2019-10-22 11:44       ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).