2020-01-04 16:45:34

by Michał Mirosław

[permalink] [raw]
Subject: [PATCH] iio: imu/mpu6050: support dual-edge IRQ

Make mpu6050 usable on platforms which provide only any-edge interrupts.

Signed-off-by: Michał Mirosław <[email protected]>
---
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 3 ++-
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 1 +
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 6 ++++--
3 files changed, 7 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 0686e41bb8a1..36b6a3922d15 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -1239,9 +1239,10 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
}

irq_type = irqd_get_trigger_type(desc);
+ st->irq_ignore_spurious = irq_type == (IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING);
if (!irq_type)
irq_type = IRQF_TRIGGER_RISING;
- if (irq_type == IRQF_TRIGGER_RISING)
+ if (irq_type == IRQF_TRIGGER_RISING || st->irq_ignore_spurious)
st->irq_mask = INV_MPU6050_ACTIVE_HIGH;
else if (irq_type == IRQF_TRIGGER_FALLING)
st->irq_mask = INV_MPU6050_ACTIVE_LOW;
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index b096e010d4ee..94ee7b18b198 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -158,6 +158,7 @@ struct inv_mpu6050_state {
struct regmap *map;
int irq;
u8 irq_mask;
+ u8 irq_ignore_spurious;
unsigned skip_samples;
s64 chip_period;
s64 it_timestamp;
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
index 10d16ec5104b..52f02de3d9b0 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
@@ -184,8 +184,10 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
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);
+ if (!st->irq_ignore_spurious)
+ dev_warn(regmap_get_device(st->map),
+ "spurious interrupt with status 0x%x\n",
+ int_status);
goto end_session;
}

--
2.20.1


2020-01-06 09:43:29

by Jean-Baptiste Maneyrol

[permalink] [raw]
Subject: Re: [PATCH] iio: imu/mpu6050: support dual-edge IRQ

Hello Michal,

interesting, thanks a lot.

It would be far better to simply delete the warning log for spurious interrupt. I was thinking that it would only be triggered by a real bug somewhere. I wasn't thinking about systems with any-edge trigger like yours.

So just delete the warn message and no need to add the irq_ignore_spurious logic and variable.

Thanks,
JB

From: [email protected] <[email protected]> on behalf of Micha? Miros?aw <[email protected]>

Sent: Saturday, January 4, 2020 17:44

To: Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[email protected]>; Peter Meerwald-Stadler <[email protected]>

Cc: [email protected] <[email protected]>; [email protected] <[email protected]>

Subject: [PATCH] iio: imu/mpu6050: support dual-edge IRQ

?


?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.



Make mpu6050 usable on platforms which provide only any-edge interrupts.



Signed-off-by: Micha? Miros?aw <[email protected]>

---

?drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 3 ++-

?drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h? | 1 +

?drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 6 ++++--

?3 files changed, 7 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 0686e41bb8a1..36b6a3922d15 100644

--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c

+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c

@@ -1239,9 +1239,10 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,

???????? }

?

???????? irq_type = irqd_get_trigger_type(desc);

+?????? st->irq_ignore_spurious = irq_type == (IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING);

???????? if (!irq_type)

???????????????? irq_type = IRQF_TRIGGER_RISING;

-?????? if (irq_type == IRQF_TRIGGER_RISING)

+?????? if (irq_type == IRQF_TRIGGER_RISING || st->irq_ignore_spurious)

???????????????? st->irq_mask = INV_MPU6050_ACTIVE_HIGH;

???????? else if (irq_type == IRQF_TRIGGER_FALLING)

???????????????? st->irq_mask = INV_MPU6050_ACTIVE_LOW;

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h

index b096e010d4ee..94ee7b18b198 100644

--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h

+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h

@@ -158,6 +158,7 @@ struct inv_mpu6050_state {

???????? struct regmap *map;

???????? int irq;

???????? u8 irq_mask;

+?????? u8 irq_ignore_spurious;

???????? unsigned skip_samples;

???????? s64 chip_period;

???????? s64 it_timestamp;

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c

index 10d16ec5104b..52f02de3d9b0 100644

--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c

+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c

@@ -184,8 +184,10 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)

???????????????? 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);

+?????????????? if (!st->irq_ignore_spurious)

+?????????????????????? dev_warn(regmap_get_device(st->map),

+??????????????????????????????? "spurious interrupt with status 0x%x\n",

+??????????????????????????????? int_status);

???????????????? goto end_session;

???????? }

?

--

2.20.1



2020-01-06 11:19:16

by Michał Mirosław

[permalink] [raw]
Subject: [PATCH v2] iio: imu/mpu6050: support dual-edge IRQ

Make mpu6050 usable on platforms which provide only any-edge interrupts.
This also covers shared interrupt case.

Signed-off-by: Michał Mirosław <[email protected]>

---
v2:
just remove the dev_warn() message

Signed-off-by: Michał Mirosław <[email protected]>
---
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 2 +-
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 5 +----
2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 0686e41bb8a1..b3d138091f89 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -1241,7 +1241,7 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
irq_type = irqd_get_trigger_type(desc);
if (!irq_type)
irq_type = IRQF_TRIGGER_RISING;
- if (irq_type == IRQF_TRIGGER_RISING)
+ if (irq_type & IRQF_TRIGGER_RISING) // rising or both-edge
st->irq_mask = INV_MPU6050_ACTIVE_HIGH;
else if (irq_type == IRQF_TRIGGER_FALLING)
st->irq_mask = INV_MPU6050_ACTIVE_LOW;
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
index 10d16ec5104b..a4dc2c4a3ca5 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
@@ -183,11 +183,8 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
"failed to ack interrupt\n");
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);
+ if (!(int_status & INV_MPU6050_BIT_RAW_DATA_RDY_INT))
goto end_session;
- }

if (!(st->chip_config.accl_fifo_enable |
st->chip_config.gyro_fifo_enable |
--
2.20.1

2020-01-06 16:15:11

by Jean-Baptiste Maneyrol

[permalink] [raw]
Subject: Re: [PATCH v2] iio: imu/mpu6050: support dual-edge IRQ

Hello,

looks good for me.

Acked-by: Jean-Baptiste Maneyrol <[email protected]>

Thanks,
JB



From: [email protected] <[email protected]> on behalf of Micha? Miros?aw <[email protected]>

Sent: Monday, January 6, 2020 12:17

To: Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[email protected]>; Peter Meerwald-Stadler <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>

Cc: [email protected] <[email protected]>; [email protected] <[email protected]>

Subject: [PATCH v2] iio: imu/mpu6050: support dual-edge IRQ

?


?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.



Make mpu6050 usable on platforms which provide only any-edge interrupts.

This also covers shared interrupt case.



Signed-off-by: Micha? Miros?aw <[email protected]>



---

v2:

?? just remove the dev_warn() message



Signed-off-by: Micha? Miros?aw <[email protected]>

---

?drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 2 +-

?drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 5 +----

?2 files changed, 2 insertions(+), 5 deletions(-)



diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c

index 0686e41bb8a1..b3d138091f89 100644

--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c

+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c

@@ -1241,7 +1241,7 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,

???????? irq_type = irqd_get_trigger_type(desc);

???????? if (!irq_type)

???????????????? irq_type = IRQF_TRIGGER_RISING;

-?????? if (irq_type == IRQF_TRIGGER_RISING)

+?????? if (irq_type & IRQF_TRIGGER_RISING)???? // rising or both-edge

???????????????? st->irq_mask = INV_MPU6050_ACTIVE_HIGH;

???????? else if (irq_type == IRQF_TRIGGER_FALLING)

???????????????? st->irq_mask = INV_MPU6050_ACTIVE_LOW;

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c

index 10d16ec5104b..a4dc2c4a3ca5 100644

--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c

+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c

@@ -183,11 +183,8 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)

???????????????????????? "failed to ack interrupt\n");

???????????????? 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);

+?????? if (!(int_status & INV_MPU6050_BIT_RAW_DATA_RDY_INT))

???????????????? goto end_session;

-?????? }

?

???????? if (!(st->chip_config.accl_fifo_enable |

???????????????? st->chip_config.gyro_fifo_enable |

--

2.20.1



2020-01-11 12:11:57

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2] iio: imu/mpu6050: support dual-edge IRQ

On Mon, 06 Jan 2020 12:17:54 +0100
Michał Mirosław <[email protected]> wrote:

> Make mpu6050 usable on platforms which provide only any-edge interrupts.
> This also covers shared interrupt case.

So this had me confused for a bit because I assumed we were trying to make
a level interrupt providing device work with edge interrupts. Seems
device supports a pulsed mode and the driver supports this.

Why do we want to detect on both edges? Do you have a crazy board
with this shared and some devices using the rising edge and some the falling one?

For shared case it should return that it did not handle the interrupt
to allow spurious interrupt detection to work...

Jonathan

>
> Signed-off-by: Michał Mirosław <[email protected]>

>
> ---
> v2:
> just remove the dev_warn() message
>
> Signed-off-by: Michał Mirosław <[email protected]>
> ---
> drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 2 +-
> drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 5 +----
> 2 files changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 0686e41bb8a1..b3d138091f89 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -1241,7 +1241,7 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
> irq_type = irqd_get_trigger_type(desc);
> if (!irq_type)
> irq_type = IRQF_TRIGGER_RISING;
> - if (irq_type == IRQF_TRIGGER_RISING)
> + if (irq_type & IRQF_TRIGGER_RISING) // rising or both-edge
> st->irq_mask = INV_MPU6050_ACTIVE_HIGH;
> else if (irq_type == IRQF_TRIGGER_FALLING)
> st->irq_mask = INV_MPU6050_ACTIVE_LOW;
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> index 10d16ec5104b..a4dc2c4a3ca5 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> @@ -183,11 +183,8 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
> "failed to ack interrupt\n");
> 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);
> + if (!(int_status & INV_MPU6050_BIT_RAW_DATA_RDY_INT))
> goto end_session;
> - }
>
> if (!(st->chip_config.accl_fifo_enable |
> st->chip_config.gyro_fifo_enable |

2020-01-11 15:08:55

by Michał Mirosław

[permalink] [raw]
Subject: Re: [PATCH v2] iio: imu/mpu6050: support dual-edge IRQ

On Sat, Jan 11, 2020 at 12:10:47PM +0000, Jonathan Cameron wrote:
> On Mon, 06 Jan 2020 12:17:54 +0100
> Micha? Miros?aw <[email protected]> wrote:
>
> > Make mpu6050 usable on platforms which provide only any-edge interrupts.
> > This also covers shared interrupt case.
>
> So this had me confused for a bit because I assumed we were trying to make
> a level interrupt providing device work with edge interrupts. Seems
> device supports a pulsed mode and the driver supports this.
>
> Why do we want to detect on both edges? Do you have a crazy board
> with this shared and some devices using the rising edge and some the falling one?
>
> For shared case it should return that it did not handle the interrupt
> to allow spurious interrupt detection to work...

Hmm. The shared interrupt is a red herring. I'll remove the sentence
from commitmsg as it looks like the driver needs a few more fixups
to be able to share the interrupt line.

The patch is required on platforms that support only dual-edge
interrupts, like eg. AT91SAM9G45-based one I have.

Best Regards,
Micha? Miros?aw

2020-01-13 22:17:50

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2] iio: imu/mpu6050: support dual-edge IRQ

On Sat, 11 Jan 2020 16:07:35 +0100
Michał Mirosław <[email protected]> wrote:

> On Sat, Jan 11, 2020 at 12:10:47PM +0000, Jonathan Cameron wrote:
> > On Mon, 06 Jan 2020 12:17:54 +0100
> > Michał Mirosław <[email protected]> wrote:
> >
> > > Make mpu6050 usable on platforms which provide only any-edge interrupts.
> > > This also covers shared interrupt case.
> >
> > So this had me confused for a bit because I assumed we were trying to make
> > a level interrupt providing device work with edge interrupts. Seems
> > device supports a pulsed mode and the driver supports this.
> >
> > Why do we want to detect on both edges? Do you have a crazy board
> > with this shared and some devices using the rising edge and some the falling one?
> >
> > For shared case it should return that it did not handle the interrupt
> > to allow spurious interrupt detection to work...
>
> Hmm. The shared interrupt is a red herring. I'll remove the sentence
> from commitmsg as it looks like the driver needs a few more fixups
> to be able to share the interrupt line.
>
> The patch is required on platforms that support only dual-edge
> interrupts, like eg. AT91SAM9G45-based one I have.

Yikes. That's a new one to me. You have my sympathies.
Hmm. Normally I'd just call that a broken platform and ignore
it but I suppose this change isn't too harmful.

I'll aim to pick up v2, with the adjusted message. If you haven't
done it yet, state the example platform as well.

Thanks,

Jonathan

>
> Best Regards,
> Michał Mirosław