how to make KEY_POWER work in terminal system

Bas Wijnen wijnen at
Mon Nov 16 06:25:26 EST 2009

On Mon, Nov 16, 2009 at 11:07:36AM +0100, Lars-Peter Clausen wrote:
> >> The gpio-keys driver needs support for irqs which are triggered
> >> on falling and rising edges.
> >
> > I am surprised by that.  While the keyboard handler does work with
> > edge-triggered events, it would AFAICS be hard to avoid a race
> > condition.  If you use level-triggered interrupts, it is
> > automatically avoided.  If you do this: - check state - set up
> > interrupt edges (rising or falling) depending on state - wait for
> > interrupts
> Usually hardware supports triggering on both edges.

I know some hardware does, but according to the datasheet the Jz4720

> In that case you don't have to change the direction of the trigger and
> so there is no chance for an race.

Actually, there still is.  If an event happens between a triggered
interrupt and the ack signal.

> if you are able to press and release your button so fast that you hit
> this race it would have been ignored anyway because of debouncing.
> (And I highly doubt anyone will be able to press and release a button
> faster then it takes the irq handler to run)

Yes, this is the reason that for the power button (which is a one-key
keyboard) this problem is not realistic.  But it can happen that you
press a button while the irq handler is busy with an other button event.
And this is only a problem when the irq handler thinks there is no
button pressed, because otherwise polling is required anyway, so the
event will be picked up by that.

In other words, it's a very rare issue to bump into, but it is wrong to
use edge triggering (unless you check the button state after acking the
old interrupt and setting up the new one).

> > Also, I don't understand why the power button would not work with
> > edge-triggered interrupts.  It would have the race condition I
> > mentioned (so level interrupts are certainly better), but that
> > should hardly ever happen.  I can't imagine that this can result in
> > a "the power button doesn't work properly"-report.
> Well if you only get falling edge irqs were you expect both edges
> you'll only see button down events. So the gpio-keys driver will only
> report button down events to the core and the core will see that the
> button is already down and filter the event.

Ok, but then the problem is not the edge trigger, but the way it is
configured. ;-)  As you wrote, the race is practically irrelevant for
the power button, and there is no other reason why edge triggered
interrupts would not work.  Level triggered interrupts are of course
still the best approach, but the same is true for the normal keyboard

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <>

More information about the discussion mailing list