LKML Archive on
help / color / mirror / Atom feed
From: "Uwe Kleine-König" <>
To: Andrew Lunn <>
Cc: "Linus Walleij" <>,
	"Thomas Petazzoni" <>,
	"Jason Cooper" <>,
	"Hua Jing" <>, "Ken Ma" <>,
	"Antoine Tenart" <>,
	"" <>,
	"Nadav Haklai" <>,
	"" <>,
	"Victor Gu" <>,
	"Neta Zur Hershkovits" <>,
	"Miquèl Raynal" <>,
	"Gregory CLEMENT" <>,
	"Marcin Wojtas" <>,
	"Wilson Ding" <>,
	"Sebastian Hesselbarth" <>
Subject: Re: [PATCH] pinctrl: armada-37xx: Add edge both type gpio irq support
Date: Tue, 20 Mar 2018 22:56:15 +0100	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

On Tue, Oct 31, 2017 at 02:16:17PM +0100, Andrew Lunn wrote:
> > Patch applied.
> > 
> > The discussion here is interesting, it is customary for GPIO drivers
> > to implement double-edge detection emulation by swapping the
> > edge detector around like this.
> Hi Linus
> I was not aware this was customary.
> > It might be possible to collect some generic information about
> > this in the Documentation/gpio/driver.txt document.
> Yes, i think it should be documented somewhere. Even in the use case
> here, detecting an SD card being inserted/removed, you could get some
> bounce on the microswitch, miss an edge, and be in the wrong state.

Maybe I'm wrong, but I wonder if there could be a set of helper
functions provided by the gpio core that helps implementing this
software simulation of IRQ_TYPE_EDGE_BOTH reliably (i.e. as good as
possible in software) to prevent common mistakes.

First draft:

		level = gpio_get(...);
		if (level)
		postlevel = gpio_get(...);

		if (level != postlevel) {
			mark_irq_pending(); /* something like desc->istate |= IRQS_PENDING */
			level = postlevel;
			goto retry;

		enable_irq(...); /* this resends the irq */

I think this only looses an event if there is an edge between gpio_get
and the configure_for_${some}_edge and another before postlevel = ...
that make the two events invisible. But I think this is okish, as a
short spike might also be missed by a hw-edge-detector. And compared to
the current code there should be no way to end in a state where we
configured for raising edge and the level is already high.

When the gpio toggles quickly this might keep the cpu busy in an endless
loop, but such a sequence would also block a controller that can trigger
on both edges in hardware. Not sure if breaking the loop at some point
is sensible anyhow. Also calling the irq handlers would be beneficial,
but I don't know if/how this works without (more) racing.

A similar approach would be great to have to "simulate" level sensitive
irqs if the hardware only implements edge logic (which affects
armada-37xx, too, which annoys me).

Best regards

Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 |  |

  parent reply	other threads:[~2018-03-20 21:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-19 13:10 Gregory CLEMENT
2017-10-19 13:38 ` Andrew Lunn
2017-10-27 12:57   ` Gregory CLEMENT
2017-10-27 19:39     ` Andrew Lunn
2017-10-31 12:07 ` Linus Walleij
2017-10-31 13:16   ` Andrew Lunn
2017-10-31 13:27     ` Linus Walleij
2018-03-20 21:56     ` Uwe Kleine-König [this message]
2018-03-21  8:02       ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
    --subject='Re: [PATCH] pinctrl: armada-37xx: Add edge both type gpio irq support' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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